lin 4 anni fa
parent
commit
f04f24177d
28 ha cambiato i file con 1187 aggiunte e 125 eliminazioni
  1. 3 2
      smart-city-platform/src/main/java/com/bz/smart_city/controller/DeviceController.java
  2. 1 1
      smart-city-platform/src/main/java/com/bz/smart_city/controller/common/ImportController.java
  3. 87 0
      smart-city-platform/src/main/java/com/bz/smart_city/controller/system/CommandController.java
  4. 17 0
      smart-city-platform/src/main/java/com/bz/smart_city/dao/DeviceCommandMapper.java
  5. 17 0
      smart-city-platform/src/main/java/com/bz/smart_city/dao/DeviceCommandTaskMapper.java
  6. 26 0
      smart-city-platform/src/main/java/com/bz/smart_city/dto/DeviceCommandDto.java
  7. 5 0
      smart-city-platform/src/main/java/com/bz/smart_city/dto/ValveCommandRequestDTO.java
  8. 65 0
      smart-city-platform/src/main/java/com/bz/smart_city/entity/DeviceCommand.java
  9. 34 0
      smart-city-platform/src/main/java/com/bz/smart_city/entity/DeviceCommandTask.java
  10. 67 0
      smart-city-platform/src/main/java/com/bz/smart_city/excel/download/template/CommandDownloadExcelTemplate.java
  11. 202 0
      smart-city-platform/src/main/java/com/bz/smart_city/excel/resolver/CommandResolverExcelService.java
  12. 35 0
      smart-city-platform/src/main/java/com/bz/smart_city/rabbitmq/listener/CommandReceiver.java
  13. 28 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/DeviceCommandService.java
  14. 11 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/DeviceCommandTaskService.java
  15. 2 1
      smart-city-platform/src/main/java/com/bz/smart_city/service/DeviceService.java
  16. 220 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/DeviceCommandServiceImpl.java
  17. 24 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/DeviceCommandTaskServiceImpl.java
  18. 12 111
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/DeviceServiceImpl.java
  19. 3 5
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/DeviceTypeServiceImpl.java
  20. 4 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/ImportServiceImpl.java
  21. 1 1
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/ValveServiceImpl.java
  22. 7 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/importfile/AsyncTaskImportService.java
  23. 1 2
      smart-city-platform/src/main/java/com/bz/smart_city/service/sync/PlatformAapiServiceImpl.java
  24. BIN
      smart-city-platform/src/main/resources/excel/orderDeviceTemplate20210421.xlsx
  25. 196 0
      smart-city-platform/src/main/resources/mapper/DeviceCommandMapper.xml
  26. 117 0
      smart-city-platform/src/main/resources/mapper/DeviceCommandTaskMapper.xml
  27. 1 1
      smart-city-platform/src/main/resources/mapper/DeviceMapper.xml
  28. 1 1
      smart-city-platform/src/main/resources/mapper/DeviceTypeMapper.xml

+ 3 - 2
smart-city-platform/src/main/java/com/bz/smart_city/controller/DeviceController.java

@@ -307,9 +307,10 @@ public class DeviceController {
     @PostMapping("setValve")
     @ApiOperation(value = "开关阀门")
     public AjaxMessage setValve(
-            @ApiParam(value = "设备id", required = true) @RequestParam(required = true) Long deviceId
+            @ApiParam(value = "设备id", required = true) @RequestParam(required = true) Long deviceId,
+            @ApiParam(value = "阀门状态 0:关阀 1:开阀", required = true) @RequestParam(required = true) Integer valveStatus
     ) {
-        deviceService.setValve(deviceId, null);
+        deviceService.setValve(deviceId, valveStatus);
         return new AjaxMessage(ResultStatus.OK);
     }
 

+ 1 - 1
smart-city-platform/src/main/java/com/bz/smart_city/controller/common/ImportController.java

@@ -28,7 +28,7 @@ public class ImportController {
     @ApiOperation(value = "导入Execl", notes = "Execl")
     public AjaxMessage importExcel(
             @ApiParam(value = "系统id", required = false) @RequestParam(required = false) Integer sysId,
-            @ApiParam(value = "导入类型 1:新装水表 2:设备列表 3:建筑 4:批量开户 5:集中器 6:采集器 7:安装计划", required = true) @RequestParam(required = true) Integer importType,
+            @ApiParam(value = "导入类型 1:新装水表 2:设备列表 3:建筑 4:批量开户 5:集中器 6:采集器 7:安装计划 8:指令下发", required = true) @RequestParam(required = true) Integer importType,
             @ApiParam(value = "文件") @RequestParam MultipartFile file,
             HttpServletRequest request, HttpServletResponse response
     ) {

+ 87 - 0
smart-city-platform/src/main/java/com/bz/smart_city/controller/system/CommandController.java

@@ -0,0 +1,87 @@
+package com.bz.smart_city.controller.system;
+
+
+import com.bz.smart_city.commom.model.AjaxMessage;
+import com.bz.smart_city.commom.model.Pagination;
+import com.bz.smart_city.commom.model.ResultStatus;
+import com.bz.smart_city.dto.DeviceCommandDto;
+import com.bz.smart_city.service.DeviceCommandService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+@Controller
+@ResponseBody
+@RequestMapping("system/command")
+@Api(tags = "指令")
+public class CommandController {
+
+    @Autowired
+    private DeviceCommandService deviceCommandService;
+
+    @GetMapping("/getPage")
+    @ApiOperation(value = "查询指令分页")
+    public AjaxMessage<Pagination<DeviceCommandDto>> getPage(
+            @ApiParam(value = "设备id", required = false) @RequestParam(required = false) Long deviceId,
+            @ApiParam(value = "查询日期,YYYYMMDD格式", required = false) @RequestParam Integer startDate,
+            @ApiParam(value = "查询日期,YYYYMMDD格式", required = false) @RequestParam Integer endDate,
+            @ApiParam(value = "页数,非必传,默认第一页", required = false, defaultValue = "1") @RequestParam(required = false, defaultValue = "1") int pageNum,
+            @ApiParam(value = "条数,非必传,默认15条", required = false, defaultValue = "15") @RequestParam(required = false, defaultValue = "15") int pageSize
+    ){
+        Pagination<DeviceCommandDto> pageInfo = deviceCommandService.getPage(deviceId,startDate,endDate, pageNum, pageSize);
+        return new AjaxMessage<>(ResultStatus.OK, pageInfo);
+    }
+
+
+
+    @GetMapping("/task/getPage")
+    @ApiOperation(value = "查询导入指令任务分页")
+    public AjaxMessage<Pagination<DeviceCommandDto>> getTaskPage(
+            @ApiParam(value = "设备编号", required = false) @RequestParam(required = false) String deviceNo,
+            @ApiParam(value = "任务名称", required = false) @RequestParam(required = false) String name,
+            @ApiParam(value = "指令类型", required = false) @RequestParam(required = false) Integer commandType,
+            @ApiParam(value = "指令状态", required = false) @RequestParam(required = false) Integer commandStatus,
+            @ApiParam(value = "页数,非必传,默认第一页", required = false, defaultValue = "1") @RequestParam(required = false, defaultValue = "1") int pageNum,
+            @ApiParam(value = "条数,非必传,默认15条", required = false, defaultValue = "15") @RequestParam(required = false, defaultValue = "15") int pageSize
+    ){
+        Pagination<DeviceCommandDto> pageInfo = deviceCommandService.getTaskPage(
+                deviceNo,name,commandType,commandStatus,
+                pageNum, pageSize);
+        return new AjaxMessage<>(ResultStatus.OK, pageInfo);
+    }
+
+    @ResponseBody
+    @GetMapping("/task/getExcel")
+    @ApiOperation(value = "导出指令任务列表excel")
+    public AjaxMessage getDeviceListExcel(
+            @ApiParam(value = "设备编号", required = false) @RequestParam(required = false) String deviceNo,
+            @ApiParam(value = "任务名称", required = false) @RequestParam(required = false) String name,
+            @ApiParam(value = "指令类型", required = false) @RequestParam(required = false) Integer commandType,
+            @ApiParam(value = "指令状态", required = false) @RequestParam(required = false) Integer commandStatus,
+            @ApiParam(value = "页数,非必传,默认第一页", required = false, defaultValue = "1") @RequestParam(required = false, defaultValue = "1") int pageNum,
+            @ApiParam(value = "条数,非必传,默认15条", required = false, defaultValue = "15") @RequestParam(required = false, defaultValue = "15") int pageSize,
+            HttpServletResponse httpServletResponse
+    ) {
+        deviceCommandService.getExcel(deviceNo,name,commandType,commandStatus, httpServletResponse);
+        return new AjaxMessage<>(ResultStatus.OK,"导出执行成功,请稍后在消息查看导出文件并下载。");
+    }
+
+    @GetMapping("/downTemplate")
+    @ApiOperation(value = "下载Execl模板", notes = "下载Execl模板")
+    public void downTemplate(
+            @ApiParam(value = "系统id", required = true) @RequestParam(required = true) Integer sysId,
+            @ApiParam(value = "token", required = true) @RequestParam(required = true) String token,
+            HttpServletRequest request, HttpServletResponse response
+    ) {
+        deviceCommandService.downTemplate(sysId, response);
+    }
+}

+ 17 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dao/DeviceCommandMapper.java

@@ -0,0 +1,17 @@
+package com.bz.smart_city.dao;
+
+import com.bz.smart_city.dto.DeviceCommandDto;
+import com.bz.smart_city.entity.DeviceCommand;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+@Mapper
+public interface DeviceCommandMapper {
+    int insertSelective(DeviceCommand record);
+
+    int updateByPrimaryKeySelective(DeviceCommand record);
+
+    List<DeviceCommandDto> getList(@Param("siteId") Integer siteId, @Param("deviceId") Long deviceId);
+}

+ 17 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dao/DeviceCommandTaskMapper.java

@@ -0,0 +1,17 @@
+package com.bz.smart_city.dao;
+
+import com.bz.smart_city.dto.DeviceCommandDto;
+import com.bz.smart_city.entity.DeviceCommandTask;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+@Mapper
+public interface DeviceCommandTaskMapper {
+    int insertSelective(DeviceCommandTask record);
+
+    int updateByPrimaryKeySelective(DeviceCommandTask record);
+
+    List<DeviceCommandDto> getList(@Param("siteId") Integer siteId, @Param("deviceNo") String deviceNo, @Param("name") String name, @Param("commandType") Integer commandType, @Param("commandStatus") Integer commandStatus);
+}

+ 26 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dto/DeviceCommandDto.java

@@ -0,0 +1,26 @@
+package com.bz.smart_city.dto;
+
+import com.bz.smart_city.entity.DeviceCommand;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class DeviceCommandDto extends DeviceCommand {
+
+    @ApiModelProperty(value = "任务名称", position = 2)
+    private String name;
+
+    @ApiModelProperty(value = "设备编号", position = 2)
+    private String deviceNo;
+
+    @ApiModelProperty(value = "系列", position = 100)
+    private String equipmentType;
+
+    @ApiModelProperty(value = "型号", position = 101)
+    private String model;
+
+    @ApiModelProperty(value = "厂商名称", position = 102)
+    private String manufacturerName;
+}

+ 5 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dto/ValveCommandRequestDTO.java

@@ -11,4 +11,9 @@ public class ValveCommandRequestDTO {
     String meterCode;
     @ApiModelProperty(name = "阀门状态  0:关阀 1:开阀" , required = true)
     String valveStatus;
+
+    @ApiModelProperty(value="操作类型 1:批量指令下发、2:系统执行指令、3:手动触发指令")
+    private Integer operationType;
+    @ApiModelProperty(value="平台 1:物联网平台 2:缴费系统、 3:计量集抄系统、 4:第三方系统")
+    private Integer platform;
 }

+ 65 - 0
smart-city-platform/src/main/java/com/bz/smart_city/entity/DeviceCommand.java

@@ -0,0 +1,65 @@
+package com.bz.smart_city.entity;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import java.time.LocalDateTime;
+import lombok.Data;
+
+@ApiModel(value="com-bz-smart_city-entity-DeviceCommand")
+@Data
+public class DeviceCommand {
+    @ApiModelProperty(value="")
+    private Integer id;
+
+    private Integer siteId;
+
+    @ApiModelProperty(value="设备id")
+    private Long deviceId;
+
+    @ApiModelProperty(value="指令类型 0:关阀 1:开阀")
+    private Integer commandType;
+
+    @ApiModelProperty(value="指令状态 0:发送、1:已送达、2:超时、3:执行成功、4:执行失败")
+    private Integer commandStatus;
+
+    @ApiModelProperty(value="操作类型 1:批量指令下发、2:系统执行指令、3:手动触发指令")
+    private Integer operationType;
+
+    @ApiModelProperty(value="备注")
+    private String remark;
+
+    @ApiModelProperty(value="指令id")
+    private String commandId;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value="下发时间")
+    private LocalDateTime issueDate;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value="完成时间")
+    private LocalDateTime finishDate;
+
+    @ApiModelProperty(value="参数")
+    private String params;
+
+    @ApiModelProperty(value="平台 1:物联网平台 2:缴费系统、 3:计量集抄系统、 4:第三方系统")
+    private Integer platform;
+
+    @ApiModelProperty(value="状态")
+    private Integer status;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value="创建时间")
+    private LocalDateTime dateCreate;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value="更新时间")
+    private LocalDateTime dateUpdate;
+
+    @ApiModelProperty(value="创建人")
+    private String createBy;
+
+    @ApiModelProperty(value="更新人")
+    private String updateBy;
+}

+ 34 - 0
smart-city-platform/src/main/java/com/bz/smart_city/entity/DeviceCommandTask.java

@@ -0,0 +1,34 @@
+package com.bz.smart_city.entity;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import java.time.LocalDateTime;
+import lombok.Data;
+
+@ApiModel(value="com-bz-smart_city-entity-DeviceCommandTask")
+@Data
+public class DeviceCommandTask {
+    @ApiModelProperty(value="")
+    private Integer id;
+
+    @ApiModelProperty(value="")
+    private Integer deviceCommandId;
+
+    @ApiModelProperty(value="")
+    private String name;
+
+    @ApiModelProperty(value="")
+    private Integer status;
+
+    @ApiModelProperty(value="")
+    private LocalDateTime dateCreate;
+
+    @ApiModelProperty(value="")
+    private LocalDateTime dateUpdate;
+
+    @ApiModelProperty(value="")
+    private String createBy;
+
+    @ApiModelProperty(value="")
+    private String updateBy;
+}

+ 67 - 0
smart-city-platform/src/main/java/com/bz/smart_city/excel/download/template/CommandDownloadExcelTemplate.java

@@ -0,0 +1,67 @@
+package com.bz.smart_city.excel.download.template;
+
+import com.bz.smart_city.commom.util.UserUtil;
+import com.bz.smart_city.commom.util.Util;
+import com.bz.smart_city.dao.BuildingMapper;
+import com.bz.smart_city.dao.ChannelMapper;
+import com.bz.smart_city.dao.DeviceTypeMapper;
+import com.bz.smart_city.dto.DeviceTypeDto;
+import com.bz.smart_city.dto.LoginUser;
+import com.bz.smart_city.entity.Community;
+import com.bz.smart_city.entity.Customer;
+import com.bz.smart_city.excel.AbstractDownloadExcelTemplate;
+import com.bz.smart_city.service.CommunityService;
+import com.bz.smart_city.service.CustomerService;
+import org.jxls.common.Context;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+
+import static com.google.common.collect.Lists.newArrayList;
+
+@Component
+public class CommandDownloadExcelTemplate extends AbstractDownloadExcelTemplate {
+    @Resource
+    private BuildingMapper buildingMapper;
+    @Resource
+    private DeviceTypeMapper deviceTypeMapper;
+    @Resource
+    private ChannelMapper channelMapper;
+    @Autowired
+    private CommunityService communityService;
+    @Autowired
+    private CustomerService customerService;
+
+
+    @Value("${files.path}")
+    private String filesPath;
+
+    private String getFilePath() {
+        String name = Util.createUUIDId();
+        String fullPath = filesPath + "/" + name + ".xlsx";
+        return fullPath;
+    }
+    @Override
+    protected void setParam() {
+        filePath = getFilePath();
+        templatePath = "excel/orderDeviceTemplate20210421.xlsx";
+
+        DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyyMMdd");
+        LocalDateTime date = LocalDateTime.now();
+        downloadName = "批量指令下发导入模板"+ "_" + date.format(f);
+
+
+        //获取设备类型数据
+        List<DeviceTypeDto> deviceTypeList = deviceTypeMapper.getDeviceTypeList(this.sysId, 1);
+
+
+
+        this.context = new Context();
+        this.context.putVar("deviceTypeList", deviceTypeList);
+    }
+}

+ 202 - 0
smart-city-platform/src/main/java/com/bz/smart_city/excel/resolver/CommandResolverExcelService.java

@@ -0,0 +1,202 @@
+package com.bz.smart_city.excel.resolver;
+
+import com.bz.smart_city.commom.util.DateTimeUtil;
+import com.bz.smart_city.commom.util.RedisUtil;
+import com.bz.smart_city.dao.CustomerMapper;
+import com.bz.smart_city.dao.DeviceCommandMapper;
+import com.bz.smart_city.dao.DeviceCommandTaskMapper;
+import com.bz.smart_city.dao.DeviceMapper;
+import com.bz.smart_city.dto.DeviceTypeDto;
+import com.bz.smart_city.dto.ValveCommandRequestDTO;
+import com.bz.smart_city.dto.assistant.InstallListDTO;
+import com.bz.smart_city.entity.*;
+import com.bz.smart_city.excel.ResolverExcelService;
+import com.bz.smart_city.excel.model.ExcelData;
+import com.bz.smart_city.service.BuildingService;
+import com.bz.smart_city.service.CommunityService;
+import com.bz.smart_city.service.DeviceTypeService;
+import com.bz.smart_city.service.assistant.InstallManagerService;
+import com.bz.smart_city.service.DeviceCommandService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.time.LocalDateTime;
+
+@Slf4j
+@Component
+public class CommandResolverExcelService implements ResolverExcelService {
+    @Resource
+    private CustomerMapper customerMapper;
+    @Autowired
+    private CommunityService communityService;
+    @Autowired
+    private BuildingService buildingService;
+    @Autowired
+    private DeviceTypeService deviceTypeService;
+    @Autowired
+    private InstallManagerService installManagerService;
+    @Resource
+    private DeviceMapper deviceMapper;
+    @Resource
+    private DeviceCommandMapper deviceCommandMapper;
+    @Resource
+    private DeviceCommandTaskMapper deviceCommandTaskMapper;
+    @Resource
+    private RedisUtil redisUtil;
+    @Autowired
+    private DeviceCommandService deviceCommandService;
+
+    @Override
+    public void cycleExcel(ExcelData data) {
+        log.info("begin CommandResolverExcelService");
+        String executeSheetName = "批量指令下发导入模板";
+        InstallListDTO dto = new InstallListDTO();
+        dto.setSiteId(data.getRecord().getSiteId());
+        dto.setInstallTime(LocalDateTime.now());
+        // 循环工作表Sheet
+        for (int numSheet = 0; numSheet < data.getWorkbook().getNumberOfSheets(); numSheet++) {
+            Sheet hssfSheet = data.getWorkbook().getSheetAt(numSheet);
+
+            if (hssfSheet == null || !StringUtils.equals(executeSheetName, hssfSheet.getSheetName())) {
+                continue;
+            }
+            data.setInvalidTemplate(true);
+            // 1,处理表头,解设备类型、指令类型
+            Row deviceTypeRow = hssfSheet.getRow(1);
+            Cell deviceTypeCell =  deviceTypeRow.getCell(1);
+
+            String[] deviceType  = StringUtils.split(deviceTypeCell.getStringCellValue().trim(),"/");
+            DeviceTypeDto dt = deviceTypeService.getByName(deviceType[1],deviceType[2]);
+            if (dt == null) {
+                data.getMessageContent().append("导入失败,");
+                data.getMessageContent().append("设备型号不存在");
+                continue;
+            }
+            if(dt.getIsValve()==0){
+                data.getMessageContent().append("导入失败,");
+                data.getMessageContent().append("该设备型号不支持阀控");
+                continue;
+            }
+
+            Row commandTypeRow = hssfSheet.getRow(2);
+            Cell commandTypeCell =  commandTypeRow.getCell(1);
+
+            if(StringUtils.equals("", commandTypeCell.getStringCellValue().trim())) {
+                data.getMessageContent().append("导入失败,");
+                data.getMessageContent().append("指令不能为空");
+                continue;
+            }
+
+            Integer valveStatus =  convertValveStatus(commandTypeCell.getStringCellValue().trim());
+            String taskNo = generateTaskNo();
+
+            // 2,处理明细行数据
+            for (int rowNum = 6; rowNum < 207; rowNum++) {
+                Row row = hssfSheet.getRow(rowNum);
+                if (row != null) {
+
+
+                    Cell deviceNoCell = row.getCell(0);
+                    Cell paramsCell = row.getCell(1);
+                    Cell remarkCell = row.getCell(2);
+                    if(StringUtils.equals("", deviceNoCell.getStringCellValue().trim())) {
+                        continue;
+                    }
+                    log.info("row deviceNo = {},params = {}",deviceNoCell.getStringCellValue(),paramsCell.getStringCellValue());
+
+                    Device device = deviceMapper.findByDeviceNo(deviceNoCell.getStringCellValue().trim());
+                    if (device == null) {
+                        data.getFailTime().incrementAndGet();
+                        remarkCell.setCellValue("设备编号不存在");
+                        continue;
+                    }
+                    if(!device.getDeviceType().equals(dt.getId())){
+                        data.getFailTime().incrementAndGet();
+                        remarkCell.setCellValue("表型不匹配");
+                        continue;
+                    }
+
+                    save(device,paramsCell.getStringCellValue().trim(),valveStatus,taskNo,dt);
+
+
+
+                    hssfSheet.removeRow(row);//成功删除该行
+                    data.getSuccessTime().incrementAndGet();
+                }
+
+
+            }
+
+            //循环为空的行上移
+            if(data.getFailTime().get() > 0){
+                for (int rowNum = hssfSheet.getLastRowNum(); rowNum >= 6 ; rowNum--) {
+                    Row row = hssfSheet.getRow(rowNum);
+                    if (row == null) {
+                        hssfSheet.shiftRows(rowNum+1, 206, -1);
+                    }
+                }
+            }
+
+            data.setIsDownload(true);
+        }
+        log.info("end CommandResolverExcelService");
+    }
+
+    private void save(Device device,String params,Integer valveStatus,String taskNo,DeviceTypeDto deviceTypeDto){
+        //1、执行开关阀门
+        ValveCommandRequestDTO valveCommandRequest = new ValveCommandRequestDTO();
+        valveCommandRequest.setValveStatus(String.valueOf(valveStatus));
+        valveCommandRequest.setOperationType(1);
+        valveCommandRequest.setPlatform(1);
+
+        Integer deviceCommandId = deviceCommandService.executeValveCommand(device,deviceTypeDto,valveCommandRequest);
+
+
+        DeviceCommandTask task = new DeviceCommandTask();
+        task.setDeviceCommandId(deviceCommandId);
+        task.setName(taskNo);
+        task.setStatus(1);
+        task.setDateCreate(LocalDateTime.now());
+        task.setDateUpdate(LocalDateTime.now());
+        task.setCreateBy("系统操作");
+        task.setUpdateBy("系统操作");
+        deviceCommandTaskMapper.insertSelective(task);
+    }
+
+    private synchronized String generateTaskNo() {
+        String taskNo = "";
+        // 1,获取当前日期
+        String todayStr = DateTimeUtil.formatNow("yyyyMMdd");
+        // 3,查找key是否存在
+        String key = "taskIncrement:"+todayStr;
+        long number = 0l;
+        if (redisUtil.exists(key)) {
+            number = redisUtil.incr(key);
+        } else {
+            number = 1l;
+            redisUtil.setExpire(key, String.valueOf(number), 86400l);
+        }
+        String taskIncrement = String.format("%03d", number);
+
+        taskNo = "Task_" + todayStr +  taskIncrement;
+        return taskNo;
+    }
+
+
+    private Integer convertValveStatus(String valve){
+        if("开阀".equals(valve)) {
+            return 1;
+        } else {
+            return 0;
+        }
+    }
+
+
+
+}

+ 35 - 0
smart-city-platform/src/main/java/com/bz/smart_city/rabbitmq/listener/CommandReceiver.java

@@ -0,0 +1,35 @@
+package com.bz.smart_city.rabbitmq.listener;
+
+import com.alibaba.fastjson.JSON;
+import com.bz.smart_city.rabbitmq.model.RabbitDeviceParamData;
+import com.rabbitmq.client.Channel;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+
+
+@Component
+@Slf4j
+public class CommandReceiver {
+    //@RabbitListener(queues = {"${spring.rabbitmq.download-device-queue}"},containerFactory = "platformListenerContainerFactory")
+    public void receiver(Channel channel, Message message) throws IOException {
+        //String str = new String(body);
+        try {
+            String msg = new String(message.getBody());
+            log.info("-----CommandReceiver msg-----,"  +msg);
+            RabbitDeviceParamData data = JSON.parseObject(msg, RabbitDeviceParamData.class);
+            //log.info("-----DownloadDeviceReceiver params-----,"  +JSON.toJSONString(data));
+            // 1,处理消息
+            //deviceService.executeDeviceListExcel(data);
+
+            // 2,确认消息消费成功 
+            //channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
+        } catch (Exception e) {
+            channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
+            log.error("consumer message error !",e);
+        }
+    }
+}

+ 28 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/DeviceCommandService.java

@@ -0,0 +1,28 @@
+package com.bz.smart_city.service;
+
+import com.bz.smart_city.commom.model.Pagination;
+import com.bz.smart_city.dto.DeviceCommandDto;
+import com.bz.smart_city.dto.DeviceTypeDto;
+import com.bz.smart_city.dto.ValveCommandRequestDTO;
+import com.bz.smart_city.entity.Device;
+import com.bz.smart_city.entity.DeviceCommand;
+
+import javax.servlet.http.HttpServletResponse;
+
+public interface DeviceCommandService{
+
+
+    int insertSelective(DeviceCommand record);
+
+    int updateByPrimaryKeySelective(DeviceCommand record);
+
+    void downTemplate(Integer sysId, HttpServletResponse response);
+
+    Pagination<DeviceCommandDto> getTaskPage(String deviceNo, String name, Integer commandType, Integer commandStatus, int pageNum, int pageSize);
+
+    Pagination<DeviceCommandDto> getPage(Long deviceId, Integer startDate, Integer endDate, int pageNum, int pageSize);
+
+    Integer executeValveCommand(Device device, DeviceTypeDto deviceTypeDto, ValveCommandRequestDTO valveCommandRequest);
+
+    void getExcel(String deviceNo, String name, Integer commandType, Integer commandStatus, HttpServletResponse httpServletResponse);
+}

+ 11 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/DeviceCommandTaskService.java

@@ -0,0 +1,11 @@
+package com.bz.smart_city.service;
+
+import com.bz.smart_city.entity.DeviceCommandTask;
+public interface DeviceCommandTaskService{
+
+
+    int insertSelective(DeviceCommandTask record);
+
+    int updateByPrimaryKeySelective(DeviceCommandTask record);
+
+}

+ 2 - 1
smart-city-platform/src/main/java/com/bz/smart_city/service/DeviceService.java

@@ -147,5 +147,6 @@ public interface DeviceService{
 
     void batchSetValve(LoginUser loginUser, Integer valveStatus, InputDeviceDto inputDeviceDto);
 
-    Boolean setValveV2(Long aLong, String valve);
+    Boolean setValveV2(Long aLong, String valve,Integer platform);
+
 }

+ 220 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/DeviceCommandServiceImpl.java

@@ -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();
+    }
+
+
+
+}

+ 24 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/DeviceCommandTaskServiceImpl.java

@@ -0,0 +1,24 @@
+package com.bz.smart_city.service.impl;
+
+import org.springframework.stereotype.Service;
+import javax.annotation.Resource;
+import com.bz.smart_city.entity.DeviceCommandTask;
+import com.bz.smart_city.dao.DeviceCommandTaskMapper;
+import com.bz.smart_city.service.DeviceCommandTaskService;
+@Service
+public class DeviceCommandTaskServiceImpl implements DeviceCommandTaskService{
+
+    @Resource
+    private DeviceCommandTaskMapper deviceCommandTaskMapper;
+
+    @Override
+    public int insertSelective(DeviceCommandTask record) {
+        return deviceCommandTaskMapper.insertSelective(record);
+    }
+
+    @Override
+    public int updateByPrimaryKeySelective(DeviceCommandTask record) {
+        return deviceCommandTaskMapper.updateByPrimaryKeySelective(record);
+    }
+
+}

+ 12 - 111
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/DeviceServiceImpl.java

@@ -1,7 +1,6 @@
 package com.bz.smart_city.service.impl;
 
 import com.alibaba.fastjson.JSON;
-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.model.ResultStatus;
@@ -132,6 +131,8 @@ public  class DeviceServiceImpl implements DeviceService {
     private ChannelDeviceTypeUseMapper channelDeviceTypeUseMapper;
     @Autowired
     private RabbitTemplate rabbitTemplate;
+    @Autowired
+    private DeviceCommandService deviceCommandService;
 
     @Value("${spring.rabbitmq.exchange}")
     private String exchange;
@@ -1428,78 +1429,36 @@ public  class DeviceServiceImpl implements DeviceService {
     public void setValve(Long deviceId, Integer valve) {
         Device device = deviceMapper.findByDeviceId(deviceId);
         DeviceTypeDto deviceTypeDto = deviceTypeMapper.getById(device.getDeviceType());
-        WaterMeterErrorDays waterMeterErrorDays = waterMeterErrorDaysMapper.findByDeviceId(deviceId);
-        String sendValveStatus = "0";
-
-        if (valve != null) {
-            if(valve == 1){
-                sendValveStatus = "1";
-            }
-        }else {
-            if(waterMeterErrorDays != null){
-                if (waterMeterErrorDays.getValveButtonStatus() != null) {
-                    if(waterMeterErrorDays.getValveButtonStatus()== 0){
-                        sendValveStatus = "1";
-                    }
-                }
-            }
-        }
-
-
-        //更新按钮阀门状态
-        WaterMeterErrorDays waterMeterErrorDayUpdate = new WaterMeterErrorDays();
-        waterMeterErrorDayUpdate.setDeviceId(deviceId);
-        if (waterMeterErrorDays != null) {
-            if (waterMeterErrorDays.getValveButtonStatus() != null) {
-                if (valve != null) {
-                    if(waterMeterErrorDays.getValveButtonStatus()==valve){
-                        waterMeterErrorDayUpdate.setValveButtonStatus(waterMeterErrorDays.getValveButtonStatus());
-                    }else {
-                        waterMeterErrorDayUpdate.setValveButtonStatus(valve==1?1:0);
-                    }
-                }else {
-                    waterMeterErrorDayUpdate.setValveButtonStatus(waterMeterErrorDays.getValveButtonStatus()== 1?0:1);
-                }
-            }else {
-                waterMeterErrorDayUpdate.setValveButtonStatus(0);
-            }
-            waterMeterErrorDaysMapper.updateByPrimaryKeySelective(waterMeterErrorDayUpdate);
-        }else {
-            if (valve != null) {
-                //waterMeterErrorDayUpdate.setValveButtonStatus(valve==0?1:0);
-                waterMeterErrorDayUpdate.setValveButtonStatus(valve==1?1:0);
-            }else {
-                waterMeterErrorDayUpdate.setValveButtonStatus(0);
-            }
 
-            waterMeterErrorDayUpdate.setStatus(1);
-            waterMeterErrorDaysMapper.insert(waterMeterErrorDayUpdate);
-        }
 
 
         ValveCommandRequestDTO valveCommandRequest = new ValveCommandRequestDTO();
-        valveCommandRequest.setValveStatus(sendValveStatus);
+        valveCommandRequest.setValveStatus(String.valueOf(valve));
+        valveCommandRequest.setOperationType(3);
+        valveCommandRequest.setPlatform(1);
 
         //1、执行开关阀门
-        executeValveCommand(device,deviceTypeDto,valveCommandRequest);
+        deviceCommandService.executeValveCommand(device,deviceTypeDto,valveCommandRequest);
 
     }
 
-    public Boolean setValveV2(Long deviceId, String valve) {
+    public Boolean setValveV2(Long deviceId, String valve,Integer platform) {
         log.info("setValveV2 deviceId={} valve={}",deviceId,valve);
         Device device = deviceMapper.findByDeviceId(deviceId);
         DeviceTypeDto deviceTypeDto = deviceTypeMapper.getById(device.getDeviceType());
 
         ValveCommandRequestDTO valveCommandRequest = new ValveCommandRequestDTO();
         valveCommandRequest.setValveStatus(valve);
+        valveCommandRequest.setOperationType(2);
+        valveCommandRequest.setPlatform(platform);
 
         //1、执行开关阀门
-        Boolean executeResult = executeValveCommand(device,deviceTypeDto,valveCommandRequest);
+        Integer deviceCommandId = deviceCommandService.executeValveCommand(device,deviceTypeDto,valveCommandRequest);
 
         //2、更换阀门按钮状态
-        if(executeResult) replaceValveButtonStatus(deviceId,valve);
+        //if(deviceCommandId !=null) replaceValveButtonStatus(deviceId,valve);
 
-        return executeResult;
+        return true;
     }
 
     private void replaceValveButtonStatus(Long deviceId, String valve){
@@ -1519,65 +1478,7 @@ public  class DeviceServiceImpl implements DeviceService {
         }
     }
 
-    private Boolean executeValveCommand(Device device,DeviceTypeDto deviceTypeDto,ValveCommandRequestDTO valveCommandRequest){
-
-        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);
-
-        return executeResult;
-    }
 
     @Override
     public String batchRegister(List<Long> deviceIds) {

+ 3 - 5
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/DeviceTypeServiceImpl.java

@@ -165,7 +165,6 @@ public class DeviceTypeServiceImpl implements DeviceTypeService {
         this.updateByPrimaryKeySelective(deviceTypeDto);
 
         //先删除关系
-        //deviceMeasuringPointRelationMapper.deleteByDeviceTypeId(deviceTypeDto.getId(), UserUtil.getCurrentUser().getUsername());
         tplMeasuringDescMapper.deleteByDeviceTypeId(deviceTypeDto.getId(), UserUtil.getCurrentUser().getUsername());
         //保存关系
         if (deviceTypeDto.getMeasuringPointId() != null && deviceTypeDto.getMeasuringPointId().size() > 0) {
@@ -187,10 +186,7 @@ public class DeviceTypeServiceImpl implements DeviceTypeService {
 
     @Override
     public List<TreeDataDto> getTreeData(Integer sysId, Integer type) {
-        /*List<TreeDataDto> list = deviceTypeMapper.getTreeData(sysId, type);
-        list.forEach(treeDataDto -> {
-            treeDataDto.setChildren(deviceTypeMapper.getTreeDataByManufacturerId(sysId, treeDataDto.getId()));
-        });*/
+
         List<DeviceTypeDto> list = deviceTypeMapper.getDeviceTypeList(sysId,type);
 
         List<TreeDataDto> datalist = newArrayList();
@@ -239,6 +235,8 @@ public class DeviceTypeServiceImpl implements DeviceTypeService {
     }
 
 
+
+
     @Override
     @Cacheable(value = "deviceTypeId", key = "#deviceTypeId")
     public DeviceTypeDto findById(Integer deviceTypeId) {

+ 4 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/ImportServiceImpl.java

@@ -125,6 +125,10 @@ public class ImportServiceImpl implements ImportService{
 
             asyncTaskImportService.executeAsyncInstallPlanTask(record);
         }
+        if(importType == 8){
+
+            asyncTaskImportService.executeAsyncCommandTask(record);
+        }
 
         log.info("返回结果");
     }

+ 1 - 1
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/ValveServiceImpl.java

@@ -75,7 +75,7 @@ public class ValveServiceImpl implements ValveService {
         if (list.size() > 1) {
             throw new ServiceException(-900,"该水表表号出现重复");
         }
-        Boolean executeResult = deviceService.setValveV2(list.get(0),result.getValve());
+        Boolean executeResult = deviceService.setValveV2(list.get(0),result.getValve(),4);
         if(!executeResult){
             throw new ServiceException(-900,"执行指令失败");
         }

+ 7 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/importfile/AsyncTaskImportService.java

@@ -86,6 +86,8 @@ public class AsyncTaskImportService {
     @Autowired
     private BuildingResolverExcelService buildingResolverExcelService;
     @Autowired
+    private CommandResolverExcelService commandResolverExcelService;
+    @Autowired
     private HandleExcelService handleExcelService;
 
     @Value("${files.path}")
@@ -584,4 +586,9 @@ public class AsyncTaskImportService {
         ResolverExcelTemplate template = new ResolverExcelTemplate(collectorResolveExcelService,handleExcelService);
         template.resolver(null,null,record,"采集器列表-批量添加");
     }
+
+    public void executeAsyncCommandTask(Import record) {
+        ResolverExcelTemplate template = new ResolverExcelTemplate(commandResolverExcelService,handleExcelService);
+        template.resolver(null,null,record,"批量指令下发-指令导入");
+    }
 }

+ 1 - 2
smart-city-platform/src/main/java/com/bz/smart_city/service/sync/PlatformAapiServiceImpl.java

@@ -37,7 +37,6 @@ public class PlatformAapiServiceImpl implements PlatformAapiService {
         Customer customer = customerMapper.findBySiteIdAndCustomerNo(null, customerNo);
         if(customer!=null){
             installListMapper.updateMeterNo(meterNo,meterCode,customer.getId());
-            //deviceMapper.updateMeterNo(meterNo,meterCode,customer.getId());
         }
 
     }
@@ -48,7 +47,7 @@ public class PlatformAapiServiceImpl implements PlatformAapiService {
             int result=-1;
             Device device = getDevice(meterNo, customerNo);
             if(device!=null){
-                deviceService.setValveV2(device.getId(),type+"");
+                deviceService.setValveV2(device.getId(),type+"",2);
                 OperatingValveRecord operatingValveRecord=new OperatingValveRecord();
                 operatingValveRecord.setCreateBy("system");
                 operatingValveRecord.setCreateDate(new Date());

BIN
smart-city-platform/src/main/resources/excel/orderDeviceTemplate20210421.xlsx


+ 196 - 0
smart-city-platform/src/main/resources/mapper/DeviceCommandMapper.xml

@@ -0,0 +1,196 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.bz.smart_city.dao.DeviceCommandMapper">
+  <resultMap id="BaseResultMap" type="com.bz.smart_city.entity.DeviceCommand">
+    <!--@mbg.generated-->
+    <!--@Table sc_device_command-->
+    <id column="id" property="id" />
+    <result column="site_id" property="siteId" />
+    <result column="device_id" property="deviceId" />
+    <result column="command_type" property="commandType" />
+    <result column="command_status" property="commandStatus" />
+    <result column="operation_type" property="operationType" />
+    <result column="remark" property="remark" />
+    <result column="command_id" property="commandId" />
+    <result column="issue_date" property="issueDate" />
+    <result column="finish_date" property="finishDate" />
+    <result column="params" property="params" />
+    <result column="platform" property="platform" />
+    <result column="status" property="status" />
+    <result column="date_create" property="dateCreate" />
+    <result column="date_update" property="dateUpdate" />
+    <result column="create_by" property="createBy" />
+    <result column="update_by" property="updateBy" />
+  </resultMap>
+  <sql id="Base_Column_List">
+    <!--@mbg.generated-->
+    id, site_id, device_id, command_type, command_status, operation_type, remark, command_id,
+    issue_date, finish_date, params, platform, `status`, date_create, date_update, create_by, 
+    update_by
+  </sql>
+  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.bz.smart_city.entity.DeviceCommand" useGeneratedKeys="true">
+    <!--@mbg.generated-->
+    insert into sc_device_command
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+      <if test="siteId != null">
+        site_id,
+      </if>
+      <if test="deviceId != null">
+        device_id,
+      </if>
+      <if test="commandType != null">
+        command_type,
+      </if>
+      <if test="commandStatus != null">
+        command_status,
+      </if>
+      <if test="operationType != null">
+        operation_type,
+      </if>
+      <if test="remark != null">
+        remark,
+      </if>
+      <if test="commandId != null">
+        command_id,
+      </if>
+      <if test="issueDate != null">
+        issue_date,
+      </if>
+      <if test="finishDate != null">
+        finish_date,
+      </if>
+      <if test="params != null">
+        params,
+      </if>
+      <if test="platform != null">
+        platform,
+      </if>
+      <if test="status != null">
+        `status`,
+      </if>
+      <if test="dateCreate != null">
+        date_create,
+      </if>
+      <if test="dateUpdate != null">
+        date_update,
+      </if>
+      <if test="createBy != null">
+        create_by,
+      </if>
+      <if test="updateBy != null">
+        update_by,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
+      <if test="siteId != null">
+        #{siteId},
+      </if>
+      <if test="deviceId != null">
+        #{deviceId},
+      </if>
+      <if test="commandType != null">
+        #{commandType},
+      </if>
+      <if test="commandStatus != null">
+        #{commandStatus},
+      </if>
+      <if test="operationType != null">
+        #{operationType},
+      </if>
+      <if test="remark != null">
+        #{remark},
+      </if>
+      <if test="commandId != null">
+        #{commandId},
+      </if>
+      <if test="issueDate != null">
+        #{issueDate},
+      </if>
+      <if test="finishDate != null">
+        #{finishDate},
+      </if>
+      <if test="params != null">
+        #{params},
+      </if>
+      <if test="platform != null">
+        #{platform},
+      </if>
+      <if test="status != null">
+        #{status},
+      </if>
+      <if test="dateCreate != null">
+        #{dateCreate},
+      </if>
+      <if test="dateUpdate != null">
+        #{dateUpdate},
+      </if>
+      <if test="createBy != null">
+        #{createBy},
+      </if>
+      <if test="updateBy != null">
+        #{updateBy},
+      </if>
+    </trim>
+  </insert>
+  <update id="updateByPrimaryKeySelective" parameterType="com.bz.smart_city.entity.DeviceCommand">
+    <!--@mbg.generated-->
+    update sc_device_command
+    <set>
+      <if test="siteId != null">
+        site_id = #{siteId},
+      </if>
+      <if test="deviceId != null">
+        device_id = #{deviceId},
+      </if>
+      <if test="commandType != null">
+        command_type = #{commandType},
+      </if>
+      <if test="commandStatus != null">
+        command_status = #{commandStatus},
+      </if>
+      <if test="operationType != null">
+        operation_type = #{operationType},
+      </if>
+      <if test="remark != null">
+        remark = #{remark},
+      </if>
+      <if test="commandId != null">
+        command_id = #{commandId},
+      </if>
+      <if test="issueDate != null">
+        issue_date = #{issueDate},
+      </if>
+      <if test="finishDate != null">
+        finish_date = #{finishDate},
+      </if>
+      <if test="params != null">
+        params = #{params},
+      </if>
+      <if test="platform != null">
+        platform = #{platform},
+      </if>
+      <if test="status != null">
+        `status` = #{status},
+      </if>
+      <if test="dateCreate != null">
+        date_create = #{dateCreate},
+      </if>
+      <if test="dateUpdate != null">
+        date_update = #{dateUpdate},
+      </if>
+      <if test="createBy != null">
+        create_by = #{createBy},
+      </if>
+      <if test="updateBy != null">
+        update_by = #{updateBy},
+      </if>
+    </set>
+    where id = #{id}
+  </update>
+
+  <select id="getList" resultType="com.bz.smart_city.dto.DeviceCommandDto">
+    select * from sc_device_command
+    where status = 1 and device_id = #{deviceId}
+    <if test="siteId != null"> and site_id = #{siteId}</if>
+  </select>
+</mapper>

+ 117 - 0
smart-city-platform/src/main/resources/mapper/DeviceCommandTaskMapper.xml

@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.bz.smart_city.dao.DeviceCommandTaskMapper">
+  <resultMap id="BaseResultMap" type="com.bz.smart_city.entity.DeviceCommandTask">
+    <!--@mbg.generated-->
+    <!--@Table sc_device_command_task-->
+    <id column="id" property="id" />
+    <result column="device_command_id" property="deviceCommandId" />
+    <result column="name" property="name" />
+    <result column="status" property="status" />
+    <result column="date_create" property="dateCreate" />
+    <result column="date_update" property="dateUpdate" />
+    <result column="create_by" property="createBy" />
+    <result column="update_by" property="updateBy" />
+  </resultMap>
+  <sql id="Base_Column_List">
+    <!--@mbg.generated-->
+    id, device_command_id, `name`, `status`, date_create, date_update, create_by, update_by
+  </sql>
+  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.bz.smart_city.entity.DeviceCommandTask" useGeneratedKeys="true">
+    <!--@mbg.generated-->
+    insert into sc_device_command_task
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+      <if test="deviceCommandId != null">
+        device_command_id,
+      </if>
+      <if test="name != null">
+        `name`,
+      </if>
+      <if test="status != null">
+        `status`,
+      </if>
+      <if test="dateCreate != null">
+        date_create,
+      </if>
+      <if test="dateUpdate != null">
+        date_update,
+      </if>
+      <if test="createBy != null">
+        create_by,
+      </if>
+      <if test="updateBy != null">
+        update_by,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
+      <if test="deviceCommandId != null">
+        #{deviceCommandId},
+      </if>
+      <if test="name != null">
+        #{name},
+      </if>
+      <if test="status != null">
+        #{status},
+      </if>
+      <if test="dateCreate != null">
+        #{dateCreate},
+      </if>
+      <if test="dateUpdate != null">
+        #{dateUpdate},
+      </if>
+      <if test="createBy != null">
+        #{createBy},
+      </if>
+      <if test="updateBy != null">
+        #{updateBy},
+      </if>
+    </trim>
+  </insert>
+  <update id="updateByPrimaryKeySelective" parameterType="com.bz.smart_city.entity.DeviceCommandTask">
+    <!--@mbg.generated-->
+    update sc_device_command_task
+    <set>
+      <if test="deviceCommandId != null">
+        device_command_id = #{deviceCommandId},
+      </if>
+      <if test="name != null">
+        `name` = #{name},
+      </if>
+      <if test="status != null">
+        `status` = #{status},
+      </if>
+      <if test="dateCreate != null">
+        date_create = #{dateCreate},
+      </if>
+      <if test="dateUpdate != null">
+        date_update = #{dateUpdate},
+      </if>
+      <if test="createBy != null">
+        create_by = #{createBy},
+      </if>
+      <if test="updateBy != null">
+        update_by = #{updateBy},
+      </if>
+    </set>
+    where id = #{id}
+  </update>
+
+  <select id="getList" resultType="com.bz.smart_city.dto.DeviceCommandDto">
+     select
+    ct.name,c.
+    *,
+    sd.device_no,
+    sdt.equipment_type,sdt.model,sdm.name manufacturer_name
+    from sc_device_command_task ct
+    left join sc_device_command c on(c.id = ct.device_command_id)
+    left join sc_device sd on(sd.id = c.device_id)
+    left join sc_device_type sdt on (sdt.id = sd.device_type)
+    left join sc_device_manufacturer sdm on (sdm.id = sd.manufacturer_id)
+    where ct.status = 1 and sd.status = 1
+    <if test="siteId != null"> and c.site_id = #{siteId}</if>
+    <if test="deviceNo != null and deviceNo != ''"> AND sd.device_no LIKE concat('%',#{deviceNo},'%')</if>
+    <if test="name != null and name != ''"> AND ct.name LIKE concat('%',#{name},'%')</if>
+    <if test="commandType != null"> and c.command_type = #{commandType}</if>
+    <if test="commandStatus != null"> and c.command_status = #{commandStatus}</if>
+  </select>
+</mapper>

+ 1 - 1
smart-city-platform/src/main/resources/mapper/DeviceMapper.xml

@@ -601,7 +601,7 @@
         where status = 1 and sys_id = #{sysId}
     </update>
     <select id="findByDeviceNo" resultMap="BaseResultMap">
-          select id,device_no from sc_device where status = 1 and device_no = #{deviceNo}
+          select * from sc_device where status = 1 and device_no = #{deviceNo}
     </select>
 
     <select id="findDeviceDetail" resultType="com.bz.smart_city.dto.DeviceDto">

+ 1 - 1
smart-city-platform/src/main/resources/mapper/DeviceTypeMapper.xml

@@ -313,7 +313,7 @@
         </if>
     </select>
     <select id="getByName" resultType="com.bz.smart_city.dto.DeviceTypeDto">
-        select id,equipment_type,model,manufacturer_id,device_type from sc_device_type where status = 1
+        select id,equipment_type,model,manufacturer_id,device_type,is_valve,en_equipment_type,en_model from sc_device_type where status = 1
         and equipment_type = #{deviceTypeName} and model =#{deviceTypeModel} limit 1
     </select>