doum
3 天以前 7ae1456345209704248fd184e0218b0c0f677a84
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceServiceImpl.java
@@ -118,7 +118,32 @@
        if(device.getDoorNameObj()!=null && Constants.equalsInteger(device.getType(),Constants.DEVICE_TYPE.duanluqi)){
            device.setDoorName(JSONObject.toJSONString(device.getDoorNameObj()));
        }
        Device model = deviceMapper.selectById(device.getId());
        if(model ==null){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if(Constants.equalsInteger(model.getType(),Constants.DEVICE_TYPE.duanluqi)){
            //如果是斷路器
            if( Constants.equalsInteger(model.getIsUsed(),Constants.ZERO)
                    && StringUtils.equals(device.getDoorName(),model.getDoorName())){
                //如果配置参数发生了变化,设置状态未启用
                device.setIsUsed(Constants.ONE);
                try {
                    MqttClient mqttClient = MqttClientCache.clientMapCache.get("device"+device.getId());
                    if(mqttClient !=null){
                        if(mqttClient.isConnected()){
                            mqttClient.disconnect();
                        }
                        mqttClient.close();
                        MqttClientCache.clientMapCache.remove("device"+device.getId());
                    }
                }catch (Exception e){
                    log.error("==============端口mqtt链接失败:"+model.getName()+e.getMessage());
                }
            }
        }
        deviceMapper.updateById(device);
    }
    @Override
@@ -216,6 +241,12 @@
        }
        if (pageWrap.getModel().getName() != null) {
            queryWrapper.lambda().like(Device::getName, pageWrap.getModel().getName());
        }
        if (pageWrap.getModel().getDoorNo() != null) {
            queryWrapper.lambda().like(Device::getDoorNo, pageWrap.getModel().getDoorNo());
        }
        if (pageWrap.getModel().getNo() != null) {
            queryWrapper.lambda().like(Device::getNo, pageWrap.getModel().getNo());
        }
        if (pageWrap.getModel().getDoorName() != null) {
            queryWrapper.lambda().like(Device::getDoorName, pageWrap.getModel().getDoorName());
@@ -343,11 +374,12 @@
            //如果系统不用了,端口mqtt连接
            try {
                mqttClient = mqttBizService.unsubscribe(mqttClient,config  ,topics);
                if(mqttClient ==null){
                    throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"建立连接失败!");
                }
                if(mqttClient.isConnected()){
                    mqttClient.disconnect();
                if(mqttClient !=null){
                    if(mqttClient.isConnected()){
                        mqttClient.disconnect();
                    }
                    mqttClient.close();
                    MqttClientCache.clientMapCache.remove("device"+param.getId());
                }
            }catch (Exception e){
                log.error("==============端口mqtt链接失败:"+model.getName()+e.getMessage());
@@ -396,7 +428,7 @@
        }
        MqttClientCache.clientMapCache.put("device"+param.getId(),mqttClient);
        String curremak = "【"+param.getLoginUserInfo().getRealname()
                +"】于"+ DateUtil.getPlusTime2(new Date()) +"进行了"+(Constants.equalsInteger(param.getStatus(),Constants.ONE)?"【开闸】":"【关闸】")+"操作,开关【"+param.getChannelNo()+"】;";
                +"】于"+ DateUtil.getPlusTime2(new Date()) +"进行了"+(Constants.equalsInteger(param.getStatus(),Constants.ONE)?"【合闸】":"【分闸】")+"操作,开关【"+param.getChannelNo()+"】;";
        deviceMapper.update(null,new UpdateWrapper<Device>().lambda()
//                        .setSql("remark = concat(ifnull(remark,''),'"+curremak+"','\n')")
                .set(Device::getRemark,curremak)
@@ -414,7 +446,7 @@
        data.setVal1("远程控制");
        data.setVal2(curremak);
        data.setHappenTime(DateUtil.getPlusTime2(data.getCreateDate()));
        data.setVal3((Constants.equalsInteger(param.getStatus(),Constants.ONE)?"【开闸】":"【关闸】"));
        data.setVal3((Constants.equalsInteger(param.getStatus(),Constants.ONE)?"【合闸】":"【分闸】"));
        data.setVal4(param.getLoginUserInfo().getRealname());
        data.setVal5(param.getChannelNo());
        deviceDataMapper.insert(data);