Commit 49684035 authored by 马33's avatar 马33

完善设备列表和用户列表相关接口

parent 3648d524
...@@ -24,7 +24,7 @@ import java.util.List; ...@@ -24,7 +24,7 @@ import java.util.List;
/** /**
* <p> * <p>
* 前端控制器 * 前端控制器
* </p> * </p>
* *
* @author m33 * @author m33
...@@ -45,20 +45,21 @@ public class DeviceController { ...@@ -45,20 +45,21 @@ public class DeviceController {
/** /**
* 添加device * 添加device
*
* @param jsonObject * @param jsonObject
* @return * @return
*/ */
@ApiOperation(value = "添加设备接口", notes = "用于添加设备") @ApiOperation(value = "添加设备接口", notes = "用于添加设备")
@PostMapping("add") @PostMapping("add")
@ApiOperationSupport(params = @DynamicParameters(name = "jsonObject",properties = { @ApiOperationSupport(params = @DynamicParameters(name = "jsonObject", properties = {
@DynamicParameter(name = "appId",value = "应用Id",required = true,dataTypeClass = String.class), @DynamicParameter(name = "appId", value = "应用Id", required = true, dataTypeClass = String.class),
@DynamicParameter(name = "count",value = "需要创建的设备数量",required = true,dataTypeClass = Integer.class), @DynamicParameter(name = "count", value = "需要创建的设备数量", required = true, dataTypeClass = Integer.class),
})) }))
@MyLog(title = "添加设备", optParam = "#{jsonObject}", businessType = BusinessType.INSERT) @MyLog(title = "添加设备", optParam = "#{jsonObject}", businessType = BusinessType.INSERT)
public BaseResult addDevice(@RequestBody JSONObject jsonObject) { public BaseResult addDevice(@RequestBody JSONObject jsonObject) {
String appId = jsonObject.getString("appId"); String appId = jsonObject.getString("appId");
int count = jsonObject.getIntValue("count"); int count = jsonObject.getIntValue("count");
boolean res = deviceService.addDevice(appId,count); boolean res = deviceService.addDevice(appId, count);
if (res) { if (res) {
return BaseResult.success(); return BaseResult.success();
} else { } else {
...@@ -68,6 +69,7 @@ public class DeviceController { ...@@ -68,6 +69,7 @@ public class DeviceController {
/** /**
* 可按条件分页查询所有的设备 * 可按条件分页查询所有的设备
*
* @param pageNo * @param pageNo
* @param pageSize * @param pageSize
* @param appName * @param appName
...@@ -76,26 +78,28 @@ public class DeviceController { ...@@ -76,26 +78,28 @@ public class DeviceController {
*/ */
@ApiOperation(value = "获取设备列表接口", notes = "用于获取设备列表") @ApiOperation(value = "获取设备列表接口", notes = "用于获取设备列表")
@GetMapping("list") @GetMapping("list")
@MyLog(title = "获取设备列表", optParam = "#{pageNo},#{pageSize},#{appName},#{userName}", businessType = BusinessType.SELECT) @MyLog(title = "获取设备列表", optParam = "#{pageNo},#{pageSize},#{appName},#{userName},#{status}", businessType = BusinessType.SELECT)
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "pageNo",value = "当前在第几页", required = true, dataType="int"), @ApiImplicitParam(name = "pageNo", value = "当前在第几页", required = true, dataType = "int"),
@ApiImplicitParam(name = "pageSize",value = "每页显示多少页", required = true, dataType="int"), @ApiImplicitParam(name = "pageSize", value = "每页显示多少页", required = true, dataType = "int"),
@ApiImplicitParam(name = "appName",value = "应用名"), @ApiImplicitParam(name = "appName", value = "应用名"),
@ApiImplicitParam(name = "userName",value = "用户名") @ApiImplicitParam(name = "userName", value = "用户名"),
@ApiImplicitParam(name = "status", value = "状态", dataType = "int")
}) })
public PageResult<DeviceVo> getDeviceList(@RequestParam(value = "pageNo", defaultValue = "0") int pageNo, public PageResult<DeviceVo> getDeviceList(@RequestParam(value = "pageNo", defaultValue = "0") int pageNo,
@RequestParam(value = "pageSize", defaultValue = "0") int pageSize, @RequestParam(value = "pageSize", defaultValue = "0") int pageSize,
@RequestParam(value = "appName",required = false) String appName, @RequestParam(value = "appName", required = false) String appName,
@RequestParam(value = "userName",required = false) String userName) { @RequestParam(value = "userName", required = false) String userName,
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(pageNo,pageSize,appName,userName); @RequestParam(value = "status", required = false) int status) {
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(pageNo, pageSize, appName, userName, status);
int total = records.getTotal(); int total = records.getTotal();
int pages = total/pageSize;//pages为总页数 int pages = total / pageSize;//pages为总页数
int mod = total%pageSize; int mod = total % pageSize;
if(mod!=0){ if (mod != 0) {
pages = pages +1; pages = pages + 1;
} }
List<DeviceVo> pageResult = records.getResult(); List<DeviceVo> pageResult = records.getResult();
return new PageResult(200,"查找成功",pageNo,pages,total,pageResult); return new PageResult(200, "查找成功", pageNo, pages, total, pageResult);
} }
@ApiOperation(value = "获取设备详细信息接口", notes = "用于获取设备详细信息列表") @ApiOperation(value = "获取设备详细信息接口", notes = "用于获取设备详细信息列表")
...@@ -108,9 +112,9 @@ public class DeviceController { ...@@ -108,9 +112,9 @@ public class DeviceController {
@ApiImplicitParam(name = "userName", value = "用户名") @ApiImplicitParam(name = "userName", value = "用户名")
}) })
public PageResult<DeviceDetailVo> getDeviceDetailList(@RequestParam(value = "pageNo", defaultValue = "0") int pageNo, public PageResult<DeviceDetailVo> getDeviceDetailList(@RequestParam(value = "pageNo", defaultValue = "0") int pageNo,
@RequestParam(value = "pageSize", defaultValue = "0") int pageSize, @RequestParam(value = "pageSize", defaultValue = "0") int pageSize,
@RequestParam(value = "appName", required = false) String appName, @RequestParam(value = "appName", required = false) String appName,
@RequestParam(value = "userName", required = false) String userName) { @RequestParam(value = "userName", required = false) String userName) {
PageInfoModel<DeviceDetailVo> records = deviceManager.getDeviceDetailList(pageNo, pageSize, appName, userName); PageInfoModel<DeviceDetailVo> records = deviceManager.getDeviceDetailList(pageNo, pageSize, appName, userName);
int total = records.getTotal(); int total = records.getTotal();
...@@ -125,13 +129,14 @@ public class DeviceController { ...@@ -125,13 +129,14 @@ public class DeviceController {
/** /**
* 添加device_black * 添加device_black
*
* @param jsonObject * @param jsonObject
* @return * @return
*/ */
@ApiOperation(value = "添加设备黑名单接口", notes = "用于添加设备黑名单") @ApiOperation(value = "添加设备黑名单接口", notes = "用于添加设备黑名单")
@PostMapping("device_black/add") @PostMapping("device_black/add")
@ApiOperationSupport(params = @DynamicParameters(name = "jsonObject",properties = { @ApiOperationSupport(params = @DynamicParameters(name = "jsonObject", properties = {
@DynamicParameter(name = "deviceId",value = "设备Id",required = true,dataTypeClass = Integer.class) @DynamicParameter(name = "deviceId", value = "设备Id", required = true, dataTypeClass = Integer.class)
})) }))
@MyLog(title = "添加设备黑名单", optParam = "#{jsonObject}", businessType = BusinessType.INSERT) @MyLog(title = "添加设备黑名单", optParam = "#{jsonObject}", businessType = BusinessType.INSERT)
public BaseResult addDeviceBlack(@RequestBody JSONObject jsonObject) { public BaseResult addDeviceBlack(@RequestBody JSONObject jsonObject) {
...@@ -146,13 +151,14 @@ public class DeviceController { ...@@ -146,13 +151,14 @@ public class DeviceController {
/** /**
* 删除device_black * 删除device_black
*
* @param jsonObject * @param jsonObject
* @return * @return
*/ */
@ApiOperation(value = "设备黑名单删除接口", notes = "删除设备黑名单") @ApiOperation(value = "设备黑名单删除接口", notes = "删除设备黑名单")
@PostMapping("device_black/delete") @PostMapping("device_black/delete")
@ApiOperationSupport(params = @DynamicParameters(name = "jsonObject",properties = { @ApiOperationSupport(params = @DynamicParameters(name = "jsonObject", properties = {
@DynamicParameter(name = "deviceId",value = "设备Id",required = true,dataTypeClass = Integer.class) @DynamicParameter(name = "deviceId", value = "设备Id", required = true, dataTypeClass = Integer.class)
})) }))
@MyLog(title = "删除设备黑名单", optParam = "#{deviceId}", businessType = BusinessType.DELETE) @MyLog(title = "删除设备黑名单", optParam = "#{deviceId}", businessType = BusinessType.DELETE)
public BaseResult deleteDeviceBlack(@RequestBody JSONObject jsonObject) { public BaseResult deleteDeviceBlack(@RequestBody JSONObject jsonObject) {
...@@ -167,6 +173,7 @@ public class DeviceController { ...@@ -167,6 +173,7 @@ public class DeviceController {
/** /**
* 分页查询所有黑名单设备 * 分页查询所有黑名单设备
*
* @param pageNo * @param pageNo
* @param pageSize * @param pageSize
* @return * @return
...@@ -175,19 +182,19 @@ public class DeviceController { ...@@ -175,19 +182,19 @@ public class DeviceController {
@GetMapping("device_black/list") @GetMapping("device_black/list")
@MyLog(title = "获取设备黑名单列表", optParam = "#{pageNo},#{pageSize}", businessType = BusinessType.SELECT) @MyLog(title = "获取设备黑名单列表", optParam = "#{pageNo},#{pageSize}", businessType = BusinessType.SELECT)
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "pageNo",value = "当前在第几页", required = true, dataType="int"), @ApiImplicitParam(name = "pageNo", value = "当前在第几页", required = true, dataType = "int"),
@ApiImplicitParam(name = "pageSize",value = "每页显示多少页", required = true, dataType="int") @ApiImplicitParam(name = "pageSize", value = "每页显示多少页", required = true, dataType = "int")
}) })
public PageResult<DeviceBlack> getDeviceBlackList(@RequestParam(value = "pageNo", defaultValue = "0") int pageNo, @RequestParam(value = "pageSize", defaultValue = "0") int pageSize){ public PageResult<DeviceBlack> getDeviceBlackList(@RequestParam(value = "pageNo", defaultValue = "0") int pageNo, @RequestParam(value = "pageSize", defaultValue = "0") int pageSize) {
PageInfoModel<DeviceBlack> records = deviceBlackService.getDeviceBlackList(pageNo,pageSize); PageInfoModel<DeviceBlack> records = deviceBlackService.getDeviceBlackList(pageNo, pageSize);
int total = records.getTotal(); int total = records.getTotal();
int pages = total/pageSize;//pages为总页数 int pages = total / pageSize;//pages为总页数
int mod = total%pageSize; int mod = total % pageSize;
if(mod!=0){ if (mod != 0) {
pages = pages +1; pages = pages + 1;
} }
List<DeviceBlack> pageResult = records.getResult(); List<DeviceBlack> pageResult = records.getResult();
return new PageResult(200,"查找成功",pageNo,pages,total,pageResult); return new PageResult(200, "查找成功", pageNo, pages, total, pageResult);
} }
} }
...@@ -13,7 +13,7 @@ import java.util.List; ...@@ -13,7 +13,7 @@ import java.util.List;
* @since 2022-06-08 * @since 2022-06-08
*/ */
public interface DeviceMapper extends BaseMapper<Device> { public interface DeviceMapper extends BaseMapper<Device> {
List<DeviceVo> getDeviceList(String appName, String userName); List<DeviceVo> getDeviceList(String appName, String userName, int status);
boolean addDevice(String sn, String appId); boolean addDevice(String sn, String appId);
} }
...@@ -28,6 +28,9 @@ public class DeviceVo implements Serializable { ...@@ -28,6 +28,9 @@ public class DeviceVo implements Serializable {
@ApiModelProperty("绑定的设备编号") @ApiModelProperty("绑定的设备编号")
private String snBind; private String snBind;
@ApiModelProperty("状态 0:未使用,1:已使用,2:失效")
private String status;
@ApiModelProperty("设备状态 0:正常 1:禁用") @ApiModelProperty("设备状态 0:正常 1:禁用")
private int blackFlag; private int blackFlag;
......
...@@ -28,6 +28,9 @@ public class ResourceVo { ...@@ -28,6 +28,9 @@ public class ResourceVo {
@ApiModelProperty("设备编号") @ApiModelProperty("设备编号")
private String sn; private String sn;
@ApiModelProperty("设备状态")
private String status;
@ApiModelProperty("应用id") @ApiModelProperty("应用id")
private String appId; private String appId;
} }
\ No newline at end of file
...@@ -10,6 +10,16 @@ import lombok.Data; ...@@ -10,6 +10,16 @@ import lombok.Data;
@Data @Data
public class UserVo extends User { public class UserVo extends User {
@ApiModelProperty("设备数量") @ApiModelProperty("总设备")
public int deviceCount; public int totalDevice;
@ApiModelProperty("已使用设备")
public int inUseDevice;
@ApiModelProperty("未使用设备")
public int unUseDevice;
@ApiModelProperty("失效设备")
public int failedDevice;
} }
...@@ -79,6 +79,10 @@ public class ResourceManager { ...@@ -79,6 +79,10 @@ public class ResourceManager {
cell = row.createCell((short)4); //第五个单元格 cell = row.createCell((short)4); //第五个单元格
cell.setCellValue("sn"); cell.setCellValue("sn");
cell.setCellStyle(styleRow); cell.setCellStyle(styleRow);
cell = row.createCell((short)5); //第六个单元格
cell.setCellValue("状态");
cell.setCellStyle(styleRow);
//第五步插入数据 //第五步插入数据
List<ResourceVo> resourceList = resourceService.getResource(userId); List<ResourceVo> resourceList = resourceService.getResource(userId);
for (int i = 0; i < resourceList.size(); i++) { for (int i = 0; i < resourceList.size(); i++) {
...@@ -106,9 +110,13 @@ public class ResourceManager { ...@@ -106,9 +110,13 @@ public class ResourceManager {
cell = row.createCell((short)4); // 第五个单元格 cell = row.createCell((short)4); // 第五个单元格
cell.setCellValue(resourceVo.getSn()); cell.setCellValue(resourceVo.getSn());
cell.setCellStyle(style); cell.setCellStyle(style);
cell = row.createCell((short)5); // 第六个单元格
cell.setCellValue(resourceVo.getStatus());
cell.setCellStyle(style);
} }
//在填完所有值以后,对每一列设置自适应宽度 //在填完所有值以后,对每一列设置自适应宽度
for (int n = 0; n < 5; n++) { for (int n = 0; n < 6; n++) {
sheet.autoSizeColumn(n); sheet.autoSizeColumn(n);
} }
wb.write(os); wb.write(os);
......
...@@ -12,7 +12,7 @@ import iot.sixiang.license.model.vo.DeviceVo; ...@@ -12,7 +12,7 @@ import iot.sixiang.license.model.vo.DeviceVo;
* @since 2022-06-08 * @since 2022-06-08
*/ */
public interface DeviceService extends IService<Device> { public interface DeviceService extends IService<Device> {
PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName); PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName, int status);
boolean addDevice(String appId, int count); boolean addDevice(String appId, int count);
} }
...@@ -32,11 +32,11 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme ...@@ -32,11 +32,11 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
private DeviceMapper deviceMapper; private DeviceMapper deviceMapper;
@Override @Override
public PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName) { public PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName, int status) {
if (pageNo == 0 || pageSize == 0) { if (pageNo == 0 || pageSize == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg()); throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
} }
List<DeviceVo> deviceTypes = deviceMapper.getDeviceList(appName, userName); List<DeviceVo> deviceTypes = deviceMapper.getDeviceList(appName, userName, status);
deviceTypes = deviceTypes.stream().sorted(Comparator.comparing(DeviceVo::getCreateTime, Comparator.reverseOrder())).collect(Collectors.toList()); deviceTypes = deviceTypes.stream().sorted(Comparator.comparing(DeviceVo::getCreateTime, Comparator.reverseOrder())).collect(Collectors.toList());
List<DeviceVo> result = new ArrayList<>(); List<DeviceVo> result = new ArrayList<>();
int begin = (pageNo - 1) * pageSize; int begin = (pageNo - 1) * pageSize;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<mapper namespace="iot.sixiang.license.mapper.DeviceMapper"> <mapper namespace="iot.sixiang.license.mapper.DeviceMapper">
<select id="getDeviceList" resultType="iot.sixiang.license.model.vo.DeviceVo"> <select id="getDeviceList" resultType="iot.sixiang.license.model.vo.DeviceVo">
SELECT de.device_id,app_name,user_name,sn,sn_bind,de.create_time,de.update_time,de.device_id IN (select SELECT de.device_id,app_name,user_name,sn,sn_bind,de.status,de.create_time,de.update_time,de.device_id IN (select
device_id from device_black) AS blackFlag FROM device AS de device_id from device_black) AS blackFlag FROM device AS de
JOIN apply AS app ON de.app_id = app.app_id JOIN apply AS app ON de.app_id = app.app_id
JOIN USER AS us ON us.user_id = app.user_id JOIN USER AS us ON us.user_id = app.user_id
...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
<if test="null != userName and '' != userName"> <if test="null != userName and '' != userName">
and user_name like concat('%',#{userName},'%') and user_name like concat('%',#{userName},'%')
</if> </if>
<if test="null != status">
and status = #{status}
</if>
</select> </select>
<insert id="addDevice" parameterType="iot.sixiang.license.entity.Device"> <insert id="addDevice" parameterType="iot.sixiang.license.entity.Device">
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
<mapper namespace="iot.sixiang.license.mapper.ResourceMapper"> <mapper namespace="iot.sixiang.license.mapper.ResourceMapper">
<select id="getResource" resultType="iot.sixiang.license.model.vo.ResourceVo"> <select id="getResource" resultType="iot.sixiang.license.model.vo.ResourceVo">
SELECT a.user_name,a.password,a.company,b.app_name,b.app_key,c.sn, b.app_id SELECT a.user_name,a.password,a.company,b.app_name,b.app_key,c.sn, b.app_id,
(CASE c.`status` WHEN 1 THEN '已使用' WHEN 2 THEN '失效' ELSE '未使用' END) `status`
FROM USER a, apply b, device c WHERE a.user_id = b.user_id FROM USER a, apply b, device c WHERE a.user_id = b.user_id
AND b.app_id = c.app_id AND a.user_id = #{userId} AND b.app_id = c.app_id AND a.user_id = #{userId}
</select> </select>
......
...@@ -15,8 +15,15 @@ ...@@ -15,8 +15,15 @@
</update> </update>
<select id="getUserList" resultType="iot.sixiang.license.model.vo.UserVo"> <select id="getUserList" resultType="iot.sixiang.license.model.vo.UserVo">
SELECT user.user_id, user_name, PASSWORD, company, user.create_time, user.update_time ,COUNT(device.`device_id`) deviceCount FROM USER LEFT JOIN apply ON user.user_id = apply.user_id LEFT JOIN device ON apply.app_id = device.app_id SELECT user.user_id, user_name, password, company, user.create_time, user.update_time,
where 1=1 COUNT(device.`device_id`) totalDevice,
COUNT(if(device.device_id is NOT NULL, if (device.`status` = 0 or device.`status` is NULL, 1, NULL), NULL)) unUseDevice,
COUNT(if(device.device_id is NOT NULL and device.`status` = 1, 1, NULL)) inUseDevice,
COUNT(if(device.device_id is NOT NULL and device.`status` = 2, 1, NULL)) failedDevice
FROM USER
LEFT JOIN apply ON user.user_id = apply.user_id
LEFT JOIN device ON apply.app_id = device.app_id
where 1=1
<if test="null != userName and '' != userName"> <if test="null != userName and '' != userName">
and user_name like concat('%',#{userName},'%') and user_name like concat('%',#{userName},'%')
</if> </if>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment