| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.doumee.service.business.impl.hksync.HkSyncPushServiceImpl; |
| | | import com.doumee.tcp.WaterElectricityUtil; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | |
| | | import org.eclipse.paho.client.mqttv3.MqttMessage; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.*; |
| | |
| | | model.setIsdeleted(Constants.ZERO); |
| | | model.setEditDate(new Date()); |
| | | model.setCreateDate(model.getEditDate()); |
| | | if(model.getDoorNameObj()!=null && Constants.equalsInteger(model.getType(),Constants.DEVICE_TYPE.duanluqi)){ |
| | | if(model.getDoorNameObj()!=null && |
| | | (Constants.equalsInteger(model.getType(),Constants.DEVICE_TYPE.duanluqi) |
| | | ||Constants.equalsInteger(model.getType(),Constants.DEVICE_TYPE.dianbiao))){ |
| | | model.setDoorName(JSONObject.toJSONString(model.getDoorNameObj())); |
| | | if(StringUtils.isNotBlank(model.getLevel())){ |
| | | if(getNumberByStr(model.getLevel()) <300){ |
| | |
| | | public void updateById(Device device) { |
| | | device.setEdirot(device.getLoginUserInfo().getId()+""); |
| | | device.setEditDate(new Date()); |
| | | if(device.getDoorNameObj()!=null && Constants.equalsInteger(device.getType(),Constants.DEVICE_TYPE.duanluqi)){ |
| | | if(device.getDoorNameObj()!=null && |
| | | (Constants.equalsInteger(device.getType(),Constants.DEVICE_TYPE.duanluqi) |
| | | ||Constants.equalsInteger(device.getType(),Constants.DEVICE_TYPE.dianbiao))){ |
| | | device.setDoorName(JSONObject.toJSONString(device.getDoorNameObj())); |
| | | } |
| | | Device model = deviceMapper.selectById(device.getId()); |
| | |
| | | IPage<Device> result = deviceMapper.selectPage(page, queryWrapper); |
| | | if(result!=null){ |
| | | for(Device d : result.getRecords()){ |
| | | if(StringUtils.isNotBlank(d.getDoorName()) &&Constants.equalsInteger(d.getType(),Constants.DEVICE_TYPE.duanluqi)){ |
| | | if(StringUtils.isNotBlank(d.getDoorName()) |
| | | && (Constants.equalsInteger(d.getType(),Constants.DEVICE_TYPE.duanluqi)|| |
| | | Constants.equalsInteger(d.getType(),Constants.DEVICE_TYPE.dianbiao))){ |
| | | try { |
| | | //断路器设备参数 |
| | | d.setDoorNameObj(JSONObject.parseObject(d.getDoorName())); |
| | |
| | | dealDuanluqiCmd(model,param,"device_"); |
| | | |
| | | } |
| | | @Override |
| | | public void dianbaoCmd(Device param){ |
| | | Device model = deviceMapper.selectById(param.getId()); |
| | | if(model ==null && Constants.equalsInteger(param.getType(),Constants.DEVICE_TYPE.dianbiao)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | if (param.getStatus() == null || param.getCmdDate() == null |
| | | ||param.getCmdDate().getTime() <= System.currentTimeMillis()) { |
| | | //如果是开闸 |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | |
| | | boolean r ; |
| | | String date = DateUtil.formatDate(new Date(),"yyyyMMddHHmmss"); |
| | | if(Constants.equalsInteger(param.getStatus(),Constants.ONE)) { |
| | | //如果是开闸 |
| | | r = WaterElectricityUtil.electricityAct(param.getIp(),Integer.parseInt(param.getPort()),param.getNo(),0,date); |
| | | }else { |
| | | //如果是合闸 |
| | | r = WaterElectricityUtil.electricityAct(param.getIp(),Integer.parseInt(param.getPort()),param.getNo(),1,date); |
| | | } |
| | | if(!r){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"远程控制电表失败,请稍后重试!"); |
| | | } |
| | | String curremak = "【"+param.getLoginUserInfo().getRealname() |
| | | +"】于"+ DateUtil.getPlusTime2(new Date()) +"进行了"+(Constants.equalsInteger(param.getStatus(),Constants.ONE)?"【合闸】":"【分闸】")+"操作,开关【"+param.getChannelNo()+"】;"; |
| | | deviceMapper.update(null,new UpdateWrapper<Device>().lambda() |
| | | .set(Device::getRemark,curremak) |
| | | .set(Device::getEditDate,new Date()) |
| | | .set(Device::getEdirot,param.getLoginUserInfo().getId()) |
| | | .eq(Device::getId,param.getId())); |
| | | DeviceData data = new DeviceData(); |
| | | data.setCreateDate(new Date()); |
| | | data.setEditDate(new Date()); |
| | | data.setCreator(param.getLoginUserInfo().getId()); |
| | | data.setEditor(param.getLoginUserInfo().getId()); |
| | | data.setDeviceId(param.getId()+""); |
| | | data.setDataType(Constants.ONE);// |
| | | data.setVal1("远程控制"); |
| | | data.setVal2(curremak); |
| | | data.setHappenTime(DateUtil.getPlusTime2(data.getCreateDate())); |
| | | data.setVal3((Constants.equalsInteger(param.getStatus(),Constants.ONE)?"【合闸】":"【分闸】")); |
| | | data.setVal4(param.getLoginUserInfo().getRealname()); |
| | | data.setVal5(param.getChannelNo()); |
| | | deviceDataMapper.insert(data); |
| | | |
| | | } |
| | | @Override |
| | | @Transactional |
| | | public void dianbiaoData(Device param){ |
| | | Device model = deviceMapper.selectById(param.getId()); |
| | | if(model ==null && Constants.equalsInteger(param.getType(),Constants.DEVICE_TYPE.dianbiao)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | try { |
| | | Map<String, Object> readData= WaterElectricityUtil.electricityData(model.getIp(),Integer.parseInt(model.getPort()),model.getNo()); |
| | | if(readData!=null){ |
| | | String curremak = "【"+param.getLoginUserInfo().getRealname() |
| | | +"】于"+ DateUtil.getPlusTime2(new Date()) +"进行了数据读取操作"; |
| | | Date time =(Date) readData.get("time"); |
| | | String total = (Double) readData.get("total")+""; |
| | | String status = (String) readData.get("status"); |
| | | model.setHkDate(new Date());//最近同步时间 |
| | | model.setOnline(Constants.ONE);//标识设备在线 |
| | | model.setRemark(curremak); |
| | | |
| | | DeviceData data = new DeviceData(); |
| | | data.setCreateDate(new Date()); |
| | | data.setEditDate(new Date()); |
| | | data.setCreator(param.getLoginUserInfo().getId()); |
| | | data.setEditor(param.getLoginUserInfo().getId()); |
| | | data.setDeviceId(param.getId()+""); |
| | | data.setDataType(Constants.ZERO);// |
| | | data.setVal1(total); |
| | | data.setVal2(status); |
| | | data.setHappenTime(DateUtil.getPlusTime2(data.getCreateDate())); |
| | | data.setVal3(DateUtil.getPlusTime2(time)); |
| | | data.setVal4(param.getLoginUserInfo().getRealname()); |
| | | data.setVal5(param.getNo());//地址域 |
| | | deviceDataMapper.insert(data); |
| | | deviceMapper.updateById(model); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | log.error("电表数据读取失败,"+e.getMessage()); |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"读取电表数据失败!"); |
| | | } |
| | | } |
| | | |
| | | private void dealDuanluqiCmd(Device model, Device param,String clientIndex) { |
| | | MqttConfig config = getMqttConfigByParam(model,clientIndex); |