jinpengyong
2023-08-03 4e48dd4711cab4528fba7f2ee01a6191c08b34aa
screen-manage/src/main/java/com/moral/api/controller/DeviceController.java
@@ -6,6 +6,7 @@
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -19,8 +20,10 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moral.api.entity.Device;
import com.moral.api.entity.SpecialDevice;
import com.moral.api.entity.Version;
import com.moral.api.service.DeviceService;
import com.moral.api.service.SpecialDeviceService;
import com.moral.api.service.VersionService;
import com.moral.constant.Constants;
import com.moral.constant.ResponseCodeEnum;
@@ -39,6 +42,9 @@
    @Autowired
    private VersionService versionService;
    @Autowired
    private SpecialDeviceService specialDeviceService;
    @ApiOperation(value = "添加设备", notes = "添加设备")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
@@ -49,14 +55,18 @@
        String mac = device.getMac();
        Integer monitorPointId = device.getMonitorPointId();
        Integer versionId = device.getDeviceVersionId();
        if (name == null || mac == null || monitorPointId == null || versionId == null) {
        if (ObjectUtils.isEmpty(name) || ObjectUtils.isEmpty(mac) || ObjectUtils.isEmpty(monitorPointId) || ObjectUtils.isEmpty(versionId)) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        //判断mac是否已存在
        //判断mac是否已存在,普通设备表和特殊设备表都要判断
        QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("mac", device.getMac());
        if (deviceService.getOne(queryWrapper) != null) {
        queryWrapper.eq("mac", device.getMac()).eq("is_delete", Constants.NOT_DELETE);
        QueryWrapper<SpecialDevice> specialDeviceQueryWrapper = new QueryWrapper<>();
        specialDeviceQueryWrapper.eq("mac", device.getMac()).eq("is_delete", Constants.NOT_DELETE);
        if (deviceService.getOne(queryWrapper) != null || specialDeviceService.getOne(specialDeviceQueryWrapper) != null) {
            return ResultMessage.fail(ResponseCodeEnum.MAC_IS_EXIST.getCode(), ResponseCodeEnum.MAC_IS_EXIST.getMsg());
        }
        deviceService.insert(device);
@@ -88,10 +98,13 @@
                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        if (device.getMac() != null) {
            //判断mac是否已存在
            //判断mac是否已存在,普通设备表和特殊设备表都要判断
            QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("mac", device.getMac());
            if (deviceService.getOne(queryWrapper) != null) {
            queryWrapper.eq("mac", device.getMac()).eq("is_delete", Constants.NOT_DELETE);
            QueryWrapper<SpecialDevice> specialDeviceQueryWrapper = new QueryWrapper<>();
            specialDeviceQueryWrapper.eq("mac", device.getMac()).eq("is_delete", Constants.NOT_DELETE);
            if (deviceService.getOne(queryWrapper) != null || specialDeviceService.getOne(specialDeviceQueryWrapper) != null) {
                return ResultMessage.fail(ResponseCodeEnum.MAC_IS_EXIST.getCode(), ResponseCodeEnum.MAC_IS_EXIST.getMsg());
            }
        }
@@ -108,6 +121,9 @@
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "name", value = "设备名称模糊查询", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "mac", value = "mac模糊查询", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "organizationId", value = "根据组织查询", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "monitorPointId", value = "站点id", required = false, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "select", method = RequestMethod.GET)
    public ResultMessage select(HttpServletRequest request) {
@@ -148,21 +164,41 @@
    @ApiOperation(value = "根据组织查设备", notes = "根据组织查设备")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
            @ApiImplicitParam(name = "page", value = "当前页", required = false, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "size", value = "每页条数", required = false, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "order", value = "排序字段", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "orderType", value = "排序类型,升序:0,降序:1", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "organizationId", value = "组织id", required = false, paramType = "query", dataType = "int"),
    })
    @RequestMapping(value = "devicesByOrgId", method = RequestMethod.GET)
    public ResultMessage selectDevicesByOrg(Integer orgId) {
        List<Map<String, Object>> devices = deviceService.selectDevicesByOrgId(orgId);
    public ResultMessage selectDevicesByOrg(HttpServletRequest request) {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        if (parameters.get("organizationId") == null) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        Map<String, Object> devices = deviceService.selectDevicesByOrgId(parameters);
        return ResultMessage.ok(devices);
    }
    @ApiOperation(value = "根据站点查设备", notes = "根据站点查设备")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
            @ApiImplicitParam(name = "page", value = "当前页", required = false, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "size", value = "每页条数", required = false, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "order", value = "排序字段", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "orderType", value = "排序类型,升序:0,降序:1", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "monitorPointId", value = "站点id", required = false, paramType = "query", dataType = "int"),
    })
    @RequestMapping(value = "devicesByMpId", method = RequestMethod.GET)
    public ResultMessage selectDevicesByMp(Integer mpId) {
        List<Map<String, Object>> devices = deviceService.selectDevicesByMpId(mpId);
    public ResultMessage selectDevicesByMp(HttpServletRequest request) {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        if (parameters.get("monitorPointId") == null) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        Map<String, Object> devices = deviceService.selectDevicesByMpId(parameters);
        return ResultMessage.ok(devices);
    }
@@ -226,4 +262,12 @@
        List<Map<String, Object>> professions = deviceService.selectDeviceDictData(Constants.SYSTEM_DICT_TYPE_PURCHASER);
        return ResultMessage.ok(professions);
    }
    @RequestMapping(value = "selectMonitorPiontAndDeviceByOrgId", method = RequestMethod.GET)
    public ResultMessage selectMonitorPiontAndDeviceByOrgId(HttpServletRequest request){
        Map parames = WebUtils.getParametersStartingWith(request,null);
        int id = Integer.parseInt(parames.get("organization_id").toString());
        List<Map<String, Object>> maps = deviceService.selectMonitorPiontAndDeviceByOrgId(id);
        return ResultMessage.ok(maps);
    }
}