Commit 0f376084 authored by ma's avatar ma

完善查询设备列表

parent a9761422
...@@ -11,6 +11,8 @@ import io.swagger.annotations.ApiImplicitParams; ...@@ -11,6 +11,8 @@ import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import iot.sixiang.license.device.DeviceManager; import iot.sixiang.license.device.DeviceManager;
import iot.sixiang.license.entity.DeviceBlack; import iot.sixiang.license.entity.DeviceBlack;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.jwt.UserUtils;
import iot.sixiang.license.log.BusinessType; import iot.sixiang.license.log.BusinessType;
import iot.sixiang.license.log.MyLog; import iot.sixiang.license.log.MyLog;
import iot.sixiang.license.model.BaseResult; import iot.sixiang.license.model.BaseResult;
...@@ -21,6 +23,7 @@ import iot.sixiang.license.model.vo.DeviceVo; ...@@ -21,6 +23,7 @@ import iot.sixiang.license.model.vo.DeviceVo;
import iot.sixiang.license.service.DeviceBlackService; import iot.sixiang.license.service.DeviceBlackService;
import iot.sixiang.license.service.DeviceService; import iot.sixiang.license.service.DeviceService;
import iot.sixiang.license.xss.XssUtil; import iot.sixiang.license.xss.XssUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -108,7 +111,11 @@ public class DeviceController { ...@@ -108,7 +111,11 @@ public class DeviceController {
@RequestParam(value = "status", required = false) Integer status) { @RequestParam(value = "status", required = false) Integer status) {
appName = XssUtil.checkXSS(appName); appName = XssUtil.checkXSS(appName);
userName = XssUtil.checkXSS(userName); userName = XssUtil.checkXSS(userName);
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(pageNo, pageSize, appName, userName, sn, status); String userId = UserUtils.getLoginUserId();
if (StringUtils.isEmpty(userId)) {
throw new IotLicenseException(403, "请重新登录");
}
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(pageNo, pageSize, Integer.parseInt(userId), appName, userName, sn, 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;
......
...@@ -54,7 +54,7 @@ public class DeviceManager { ...@@ -54,7 +54,7 @@ public class DeviceManager {
public void initDevices() { public void initDevices() {
allDevice = new HashMap<>(); allDevice = new HashMap<>();
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(1, 10000, "", "", null, null); PageInfoModel<DeviceVo> records = deviceService.getDeviceList(1, 10000, null, "", "", null, null);
List<DeviceVo> deviceList = records.getResult(); List<DeviceVo> deviceList = records.getResult();
for (DeviceVo deviceVo : deviceList) { for (DeviceVo deviceVo : deviceList) {
...@@ -151,7 +151,7 @@ public class DeviceManager { ...@@ -151,7 +151,7 @@ public class DeviceManager {
} }
public PageInfoModel<DeviceDetailVo> getDeviceDetailList(int pageNo, int pageSize, String appName, String userName) { public PageInfoModel<DeviceDetailVo> getDeviceDetailList(int pageNo, int pageSize, String appName, String userName) {
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(pageNo, pageSize, appName, userName, null, null); PageInfoModel<DeviceVo> records = deviceService.getDeviceList(pageNo, pageSize, null, appName, userName, null, null);
List<DeviceVo> deviceVos = records.getResult(); List<DeviceVo> deviceVos = records.getResult();
PageInfoModel<DeviceDetailVo> detailVoPageInfoModel = new PageInfoModel<>(); PageInfoModel<DeviceDetailVo> detailVoPageInfoModel = new PageInfoModel<>();
List<DeviceDetailVo> detailVos = new ArrayList<>(); List<DeviceDetailVo> detailVos = new ArrayList<>();
......
...@@ -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, String sn, Integer status); List<DeviceVo> getDeviceList(String appName, String userName, Integer userId, String sn, Integer status);
boolean addDevice(String sn, String appId); boolean addDevice(String sn, String appId);
......
...@@ -17,7 +17,7 @@ import iot.sixiang.license.model.vo.DeviceVo; ...@@ -17,7 +17,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, String sn, Integer status); PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, Integer userId, String appName, String userName, String sn, Integer status);
boolean addDevice(String appId, int count); boolean addDevice(String appId, int count);
......
...@@ -40,11 +40,11 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme ...@@ -40,11 +40,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, String sn, Integer status) { public PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, Integer userId, String appName, String userName, String sn, Integer 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, sn, status); List<DeviceVo> deviceTypes = deviceMapper.getDeviceList(appName, userName, userId, sn, 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;
......
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
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
where 1=1 where 1=1
<if test="null != userId">
and us.user_id = #{userId}
</if>
<if test="null != appName and '' != appName"> <if test="null != appName and '' != appName">
and app_name like concat('%',#{appName},'%') and app_name like concat('%',#{appName},'%')
</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