|
@@ -0,0 +1,220 @@
|
|
|
+package com.bz.smart_city.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.bz.smart_city.commom.exception.ServiceException;
|
|
|
+import com.bz.smart_city.commom.model.Pagination;
|
|
|
+import com.bz.smart_city.commom.util.ExcelUtil;
|
|
|
+import com.bz.smart_city.commom.util.UserUtil;
|
|
|
+import com.bz.smart_city.dao.DeviceCommandTaskMapper;
|
|
|
+import com.bz.smart_city.dto.*;
|
|
|
+import com.bz.smart_city.entity.Device;
|
|
|
+import com.bz.smart_city.entity.DeviceValveRecord;
|
|
|
+import com.bz.smart_city.excel.download.template.CommandDownloadExcelTemplate;
|
|
|
+import com.bz.smart_city.service.DeviceCommandService;
|
|
|
+import com.bz.smart_city.service.DeviceValveRecordService;
|
|
|
+import com.bz.smart_city.service.udip.EasylinkinUtils;
|
|
|
+import com.bz.smart_city.service.udip.GdAgentUtils;
|
|
|
+import com.bz.smart_city.service.udip.HlhtService;
|
|
|
+import com.bz.smart_city.service.udip.UdipEtlDataCommandService;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import com.bz.smart_city.dao.DeviceCommandMapper;
|
|
|
+import com.bz.smart_city.entity.DeviceCommand;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import static com.google.common.collect.Lists.newArrayList;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class DeviceCommandServiceImpl implements DeviceCommandService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CommandDownloadExcelTemplate commandDownloadExcelTemplate;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private DeviceCommandMapper deviceCommandMapper;
|
|
|
+ @Resource
|
|
|
+ private DeviceCommandTaskMapper deviceCommandTaskMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GdAgentUtils gdAgentUtils;
|
|
|
+ @Autowired
|
|
|
+ private HlhtService hlhtService;
|
|
|
+ @Value("${sync.customer.linhe.id}")
|
|
|
+ private Integer linheCustomerId;
|
|
|
+ @Autowired
|
|
|
+ private UdipEtlDataCommandService udipEtlDataCommandService;
|
|
|
+ @Autowired
|
|
|
+ private EasylinkinUtils easylinkinUtils;
|
|
|
+ @Autowired
|
|
|
+ private DeviceValveRecordService deviceValveRecordService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int insertSelective(DeviceCommand record) {
|
|
|
+ return deviceCommandMapper.insertSelective(record);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int updateByPrimaryKeySelective(DeviceCommand record) {
|
|
|
+ return deviceCommandMapper.updateByPrimaryKeySelective(record);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void downTemplate(Integer sysId, HttpServletResponse response) {
|
|
|
+ commandDownloadExcelTemplate.download(sysId,response);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Pagination<DeviceCommandDto> getTaskPage(String deviceNo, String name, Integer commandType, Integer commandStatus, int pageNum, int pageSize) {
|
|
|
+ LoginUser loginUser = UserUtil.getCurrentUser();
|
|
|
+ PageHelper.startPage(pageNum,pageSize);
|
|
|
+ List<DeviceCommandDto> list = deviceCommandTaskMapper.getList(loginUser.getSiteId(),deviceNo,name,commandType,commandStatus);
|
|
|
+ return new Pagination<>(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Pagination<DeviceCommandDto> getPage(Long deviceId, Integer startDate, Integer endDate, int pageNum, int pageSize) {
|
|
|
+ LoginUser loginUser = UserUtil.getCurrentUser();
|
|
|
+ PageHelper.startPage(pageNum,pageSize);
|
|
|
+ List<DeviceCommandDto> list = deviceCommandMapper.getList(loginUser.getSiteId(),deviceId);
|
|
|
+ return new Pagination<>(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getExcel(String deviceNo, String name, Integer commandType, Integer commandStatus, HttpServletResponse httpServletResponse) {
|
|
|
+ LoginUser loginUser = UserUtil.getCurrentUser();
|
|
|
+ List<DeviceCommandDto> list = deviceCommandTaskMapper.getList(loginUser.getSiteId(),deviceNo,name,commandType,commandStatus);
|
|
|
+
|
|
|
+ String title = "批量指令下发";
|
|
|
+ String[] rowsName = new String[]{"序号", "设备编号", "设备型号", "任务名称", "指令类型", "指令状态", "下发时间", "完成时间"};
|
|
|
+ List<Object[]> dataList = newArrayList();
|
|
|
+ Object[] objs = null;
|
|
|
+ DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ DeviceCommandDto dto = list.get(i);
|
|
|
+ objs = new Object[rowsName.length];
|
|
|
+ objs[0] = i;
|
|
|
+ objs[1] = dto.getDeviceNo();
|
|
|
+ objs[2] = dto.getManufacturerName()+"/"+dto.getEquipmentType()+"/"+dto.getModel();
|
|
|
+ objs[3] = dto.getName();
|
|
|
+ objs[4] = getCommandTypeName(dto.getCommandType());
|
|
|
+ objs[5] = getCommandStatusName(dto.getCommandStatus());
|
|
|
+ objs[6] = dto.getIssueDate()!=null?dto.getIssueDate().format(df):null;
|
|
|
+ objs[7] = dto.getFinishDate()!=null?dto.getFinishDate().format(df):null;
|
|
|
+ dataList.add(objs);
|
|
|
+ }
|
|
|
+ ExcelUtil excelUtil = new ExcelUtil(title, rowsName, dataList);
|
|
|
+ try {
|
|
|
+ excelUtil.export(httpServletResponse);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ServiceException(-900, "导出异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getCommandStatusName(Integer commandStatus) {
|
|
|
+ if(commandStatus==0) return "发送";
|
|
|
+ if(commandStatus==1) return "已送达";
|
|
|
+ if(commandStatus==2) return "超时";
|
|
|
+ if(commandStatus==3) return "执行成功";
|
|
|
+ if(commandStatus==4) return "执行失败";
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getCommandTypeName(Integer commandType) {
|
|
|
+ if(commandType==0) return "关阀";
|
|
|
+ if(commandType==1) return "开阀";
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer executeValveCommand(Device device, DeviceTypeDto deviceTypeDto, ValveCommandRequestDTO valveCommandRequest){
|
|
|
+ log.info("begin executeValveCommand");
|
|
|
+ String commandId = null;
|
|
|
+ Integer sendValveStatus = Integer.valueOf(valveCommandRequest.getValveStatus());
|
|
|
+ String commandStatus = null;
|
|
|
+ String remark = "";
|
|
|
+ Boolean executeResult = false;
|
|
|
+ JSONObject commandResult = null;
|
|
|
+
|
|
|
+ if(StringUtils.equals("lora188",deviceTypeDto.getEnModel())){
|
|
|
+ valveCommandRequest.setMeterCode(device.getWaterMeterNo());
|
|
|
+ easylinkinUtils.sendDownlink(device.getDeviceNo(),valveCommandRequest);
|
|
|
+ executeResult = true;
|
|
|
+ }else if(StringUtils.equals("hxgd",deviceTypeDto.getEnModel()))
|
|
|
+ {
|
|
|
+ valveCommandRequest.setMeterCode(String.valueOf(device.getId()));
|
|
|
+ gdAgentUtils.setMeterValve(valveCommandRequest);
|
|
|
+ executeResult = true;
|
|
|
+ }
|
|
|
+ else if(StringUtils.equals("hengxin-nb",deviceTypeDto.getEnModel()))
|
|
|
+ {
|
|
|
+ valveCommandRequest.setMeterCode(device.getWaterMeterNo());
|
|
|
+ commandResult = udipEtlDataCommandService.defaultCommandSend(device.getUdipId(),valveCommandRequest);
|
|
|
+ }
|
|
|
+ else if(StringUtils.equals("ningbo-nb",deviceTypeDto.getEnModel()))
|
|
|
+ {
|
|
|
+ valveCommandRequest.setMeterCode(device.getWaterMeterNo());
|
|
|
+ commandResult = udipEtlDataCommandService.defaultCommandSend(device.getUdipId(),valveCommandRequest);
|
|
|
+ }else if(StringUtils.equals("NB-TJ2.0",deviceTypeDto.getEnModel()))
|
|
|
+ {
|
|
|
+ if (device.getUdipId() != null && !"".equals(device.getUdipId())) {
|
|
|
+ valveCommandRequest.setMeterCode(device.getDeviceNo());
|
|
|
+ commandResult = udipEtlDataCommandService.commandSend(device.getUdipId(),valveCommandRequest);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ valveCommandRequest.setMeterCode(device.getWaterMeterNo());
|
|
|
+ commandResult = udipEtlDataCommandService.defaultCommandSend(device.getUdipId(),valveCommandRequest);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (commandResult != null) {
|
|
|
+ commandId = commandResult.getString("commandId");
|
|
|
+ commandStatus = commandResult.getString("status");
|
|
|
+ //判断指令执成功
|
|
|
+ if (commandId != null && !"".equals(commandId)) executeResult = true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //1、插入开关阀门记录
|
|
|
+ DeviceValveRecord deviceValveRecord = new DeviceValveRecord();
|
|
|
+ deviceValveRecord.setDeviceId(device.getId());
|
|
|
+ deviceValveRecord.setSendValveStatus(sendValveStatus);
|
|
|
+ deviceValveRecord.setSendStatus(1);
|
|
|
+ deviceValveRecord.setCommandId(commandId);
|
|
|
+ deviceValveRecord.setCommandStatus(commandStatus);
|
|
|
+ deviceValveRecord.setRemark(remark);
|
|
|
+ deviceValveRecordService.insertSelective(deviceValveRecord);
|
|
|
+
|
|
|
+ //2 插入指令记录
|
|
|
+ DeviceCommand deviceCommand = new DeviceCommand();
|
|
|
+ deviceCommand.setSiteId(device.getSiteId());
|
|
|
+ deviceCommand.setDeviceId(device.getId());
|
|
|
+ deviceCommand.setCommandType(sendValveStatus);
|
|
|
+ deviceCommand.setCommandStatus(executeResult?0:4);
|
|
|
+ deviceCommand.setOperationType(1);
|
|
|
+ deviceCommand.setCommandId(commandId);
|
|
|
+ deviceCommand.setIssueDate(LocalDateTime.now());
|
|
|
+ deviceCommand.setPlatform(1);
|
|
|
+ deviceCommand.setStatus(1);
|
|
|
+ deviceCommand.setDateCreate(LocalDateTime.now());
|
|
|
+ deviceCommand.setDateUpdate(LocalDateTime.now());
|
|
|
+ deviceCommand.setCreateBy("");
|
|
|
+ deviceCommand.setUpdateBy("");
|
|
|
+ deviceCommandMapper.insertSelective(deviceCommand);
|
|
|
+
|
|
|
+ log.info("end executeValveCommand");
|
|
|
+ return deviceCommand.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|