浏览代码

增加阀控记录

oppadmin 4 年之前
父节点
当前提交
aaaf54d787
共有 18 个文件被更改,包括 850 次插入18 次删除
  1. 36 0
      smart-city-platform/src/main/java/com/bz/smart_city/controller/assistant/InstallPlanController.java
  2. 3 1
      smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/PayControlRuleController.java
  3. 2 0
      smart-city-platform/src/main/java/com/bz/smart_city/dao/CommunityMapper.java
  4. 2 0
      smart-city-platform/src/main/java/com/bz/smart_city/dao/CustomerMapper.java
  5. 20 0
      smart-city-platform/src/main/java/com/bz/smart_city/dao/pay/PayControlRecordMapper.java
  6. 62 0
      smart-city-platform/src/main/java/com/bz/smart_city/entity/pay/PayControlRecord.java
  7. 2 2
      smart-city-platform/src/main/java/com/bz/smart_city/entity/pay/PayControlRule.java
  8. 73 0
      smart-city-platform/src/main/java/com/bz/smart_city/excel/AbstractDownloadExcelTemplate.java
  9. 169 0
      smart-city-platform/src/main/java/com/bz/smart_city/excel/AbstractResolverExcelTemplate.java
  10. 89 0
      smart-city-platform/src/main/java/com/bz/smart_city/excel/download/template/InstallPlanDownloadExcelTemplate.java
  11. 252 0
      smart-city-platform/src/main/java/com/bz/smart_city/excel/resolver/InstallPlanResolverExcelTemplate.java
  12. 11 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/assistant/InstallPlanService.java
  13. 27 0
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/assistant/InstallPlanServiceImpl.java
  14. 14 2
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/PayControlRuleServiceImpl.java
  15. 7 0
      smart-city-platform/src/main/resources/mapper/CommunityMapper.xml
  16. 4 0
      smart-city-platform/src/main/resources/mapper/CustomerMapper.xml
  17. 64 0
      smart-city-platform/src/main/resources/mapper/pay/PayControlRecordMapper.xml
  18. 13 13
      smart-city-platform/src/main/resources/mapper/pay/PayControlRuleMapper.xml

+ 36 - 0
smart-city-platform/src/main/java/com/bz/smart_city/controller/assistant/InstallPlanController.java

@@ -0,0 +1,36 @@
+package com.bz.smart_city.controller.assistant;
+
+import com.bz.smart_city.service.assistant.InstallPlanService;
+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;
+
+/**
+ * Created by ZJY on 2021-01-13 11:30
+ */
+@Controller
+@ResponseBody
+@RequestMapping("installPlan")
+@Api(tags = "水表助手-安装计划")
+public class InstallPlanController {
+    @Autowired
+    private InstallPlanService installPlanService;
+
+    @GetMapping("/plan/downTemplate")
+    @ApiOperation(value = "计划模板下载", notes = "计划模板下载")
+    public void planDownTemplate(
+            @ApiParam(value = "token", required = true) @RequestParam(required = true) String token,
+            HttpServletRequest request, HttpServletResponse response
+    ) {
+        installPlanService.planDownTemplate(response);
+    }
+}

+ 3 - 1
smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/PayControlRuleController.java

@@ -22,7 +22,7 @@ import java.util.List;
  */
 @RestController
 @RequestMapping("PayControlRule")
-@Api(tags = "阀门设置")
+@Api(tags = "计费系统-阀门设置")
 public class PayControlRuleController {
 
     @Autowired
@@ -129,4 +129,6 @@ public class PayControlRuleController {
         }
     }
 
+
+
 }

+ 2 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dao/CommunityMapper.java

@@ -37,4 +37,6 @@ public interface CommunityMapper {
     List<CommunityDto> getListByCustomerIds(@Param("siteId") Integer siteId, @Param("customerIds") List<Integer> customerIds, @Param("communityName") String communityName, @Param("province") Integer province, @Param("city") Integer city, @Param("region") Integer region);
 
     Community findByNameV2(@Param("siteId") Integer siteId, @Param("province") Integer province, @Param("city") Integer city, @Param("region") Integer region, @Param("communityName") String communityName);
+
+    Community findByName(@Param("siteId") Integer siteId, @Param("communityName") String communityName);
 }

+ 2 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dao/CustomerMapper.java

@@ -37,4 +37,6 @@ public interface CustomerMapper {
     Integer countChildrenNum(@Param("customerId") Integer customerId);
 
     CustomerDto getCustomerByCustomerno(@Param("customerNo") String customerNo);
+
+    Customer findByName(@Param("siteId") Integer siteId, @Param("name") String name);
 }

+ 20 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dao/pay/PayControlRecordMapper.java

@@ -0,0 +1,20 @@
+package com.bz.smart_city.dao.pay;
+
+import com.bz.smart_city.entity.pay.PayControlRecord;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * Created by ZJY on 2021-01-14 16:01
+ */
+@Mapper
+public interface PayControlRecordMapper {
+
+    //添加
+    Integer add(@Param("payControlRecord")PayControlRecord payControlRecord);
+
+    //查询
+    List<PayControlRecord> findList(@Param("payControlRecord")PayControlRecord payControlRecord);
+}

+ 62 - 0
smart-city-platform/src/main/java/com/bz/smart_city/entity/pay/PayControlRecord.java

@@ -0,0 +1,62 @@
+package com.bz.smart_city.entity.pay;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigInteger;
+import java.time.LocalDateTime;
+
+/**
+ * Created by ZJY on 2021-01-14 15:54
+ */
+@Data
+@ApiModel(value = "阀控记录")
+public class PayControlRecord {
+
+    @ApiModelProperty(example="1",notes = "ID",position = 1)
+    private BigInteger id;
+
+    @ApiModelProperty(example="1",notes = "用户ID",position = 5)
+    private BigInteger accountId;
+
+    @ApiModelProperty(example="1",notes = "水表ID",position = 10)
+    private BigInteger meterId;
+
+    @ApiModelProperty(example="1",notes = "操作类型 0关阀 1开阀",position = 15)
+    private Integer type;
+
+    @ApiModelProperty(example="1",notes = "操作结果 0执行中 1成功 2失败",position = 20)
+    private Integer result;
+
+    @ApiModelProperty(example="1",notes = "阀门状态  0关阀 1开阀 2异常",position = 25)
+    private Integer state;
+
+    @ApiModelProperty(example="1",notes = "阀控规则id",position = 30)
+    private Integer controlRuleId;
+
+    @ApiModelProperty(example="1",notes = "阀控规则名称",position = 31)
+    private String controlRuleIdName;
+
+
+
+    @ApiModelProperty(example = "1",notes = "创建者",hidden = true)
+    private BigInteger createBy;
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(example = "2020-04-17 00:00:00",notes = "创建时间",hidden = true)
+    private LocalDateTime createDate;
+    @ApiModelProperty(example = "1",notes = "修改者",hidden = true)
+    private BigInteger updateBy;
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(example = "2020-04-18 00:00:00",notes = "修改时间",hidden = true)
+    private LocalDateTime updateDate;
+
+    @ApiModelProperty(example = "1",notes = "删除标记",hidden = true)
+    private String delFlag;
+    @ApiModelProperty(example = "1",notes = "站点ID",hidden = true)
+    private BigInteger siteId;
+    @ApiModelProperty(example = "1",notes = "水司ID",hidden = true)
+    private BigInteger customerId;
+
+}

+ 2 - 2
smart-city-platform/src/main/java/com/bz/smart_city/entity/pay/PayControlRule.java

@@ -29,13 +29,13 @@ public class PayControlRule {
     @ApiModelProperty(example="1",notes = "条件值",position = 5)
     private String value;
 
-    @ApiModelProperty(example="1",notes = "执行动作,0关阀 1开阀",position = 6)
+    @ApiModelProperty(example="0",notes = "执行动作,0关阀 1开阀",position = 6)
     private String action;
 
     @ApiModelProperty(example="元", notes="单位",position = 7)
     private String unit;
 
-    @ApiModelProperty(example="1", notes="停用标志 0启用 1停用",position = 8)
+    @ApiModelProperty(example="0", notes="停用标志 0启用 1停用",position = 8)
     private String disable;
 
     @ApiModelProperty(example = "正常",notes = "备注",position = 9)

+ 73 - 0
smart-city-platform/src/main/java/com/bz/smart_city/excel/AbstractDownloadExcelTemplate.java

@@ -0,0 +1,73 @@
+package com.bz.smart_city.excel;
+
+import com.bz.smart_city.commom.util.FileUtil;
+import org.jxls.common.Context;
+import org.jxls.util.JxlsHelper;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.net.URLEncoder;
+
+/**
+ * Created by ZJY on 2021-01-13 11:36
+ */
+/*
+    excel下载模板
+ */
+public abstract class AbstractDownloadExcelTemplate {
+    protected Context context;
+    protected Integer sysId;
+    protected String filePath;
+    protected String templatePath;
+    protected String downloadName;
+    protected HttpServletResponse response;
+
+    public void download(Integer sysId, HttpServletResponse response){
+        this.sysId = sysId;
+        this.response = response;
+        setParam();
+        downloadExcel();
+    }
+
+    /**
+     * 设置参数
+     */
+    protected abstract void setParam();
+
+
+    /**
+     * 下载
+     */
+    private final void downloadExcel(){
+        try {
+            InputStream in = this.getClass().getClassLoader().getResourceAsStream(templatePath);
+            FileOutputStream out = new FileOutputStream(filePath);
+            //将List<Exam>列表数据按照模板文件中的格式生成到scoreOutput.xls文件中
+            JxlsHelper.getInstance().processTemplate(in, out, context);
+
+            //下面步骤为浏览器下载部分
+            //指定数据生成后的文件输入流(将上述out的路径作为文件的输入流)
+            FileInputStream fileInputStream = new FileInputStream(filePath);
+            //导出excel文件,设置文件名
+            String filename = URLEncoder.encode( downloadName+".xlsx", "UTF-8");
+            //设置下载头
+            response.setHeader("Content-Disposition", "attachment;filename=" + filename);
+            ServletOutputStream outputStream = response.getOutputStream();
+
+            //将文件写入浏览器
+            byte[] bys = new byte[fileInputStream.available()];
+            fileInputStream.read(bys);
+            outputStream.write(bys);
+            outputStream.flush();
+            outputStream.close();
+        }catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            FileUtil.deleteFile(filePath);
+        }
+
+    }
+}

+ 169 - 0
smart-city-platform/src/main/java/com/bz/smart_city/excel/AbstractResolverExcelTemplate.java

@@ -0,0 +1,169 @@
+package com.bz.smart_city.excel;
+
+/**
+ * Created by ZJY on 2021-01-13 17:02
+ */
+
+import com.bz.smart_city.commom.util.FileUtil;
+import com.bz.smart_city.commom.util.Util;
+import com.bz.smart_city.entity.Import;
+import com.bz.smart_city.entity.Message;
+import com.bz.smart_city.service.ImportService;
+import com.bz.smart_city.service.MessageService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * excel解析模板
+ */
+@Slf4j
+@Component
+public abstract class AbstractResolverExcelTemplate {
+
+    @Value("${files.path}")
+    private String filesPath;
+
+    @Value("${service.domain}")
+    private String domain;
+
+    protected String getFilePath() {
+        String name = Util.createUUIDId();
+        String fullPath = filesPath + "/import/" + name + ".xlsm";
+        return fullPath;
+    }
+    @Autowired
+    private MessageService messageService;
+    @Autowired
+    private ImportService importService;
+
+    protected Integer customerId;
+    protected Integer sysId;
+    protected Import record;
+    protected Workbook workbook;
+    protected String messageTitle;
+    protected StringBuffer messageContent = new StringBuffer();
+    protected Boolean isDownload = false;
+    protected Boolean invalidTemplate = false;
+    protected AtomicInteger successTime = new AtomicInteger(0);
+    protected AtomicInteger failTime = new AtomicInteger(0);
+
+
+    public void resolver(Integer sysId, Integer customerId, Import record, String messageTitle){
+
+        this.sysId = sysId;
+        this.customerId = customerId;
+        this.record = record;
+        //this.workbook = workbook;
+        this.messageContent = new StringBuffer();
+        this.isDownload = false;
+        this.invalidTemplate = false;
+        this.successTime = new AtomicInteger(0);
+        this.failTime = new AtomicInteger(0);
+        this.messageTitle = messageTitle;
+        messageContent.append(record.getImportFileName());
+        InputStream inputStream = null;
+        try {
+            inputStream = new FileInputStream(record.getImportFilePath());
+            this.workbook = new XSSFWorkbook(inputStream);
+            cycleExcel();
+            failFile();
+            recordMessage();
+        } catch (Exception e) {
+            e.printStackTrace();
+            messageContent.append("导入失败,读取文件错误。");
+            Message message = new Message();
+            message.setSiteId(record.getUserId());
+            message.setUserId(record.getUserId());
+            message.setMessageType(record.getType());
+            message.setMessageTitle(messageTitle);
+            message.setMessageContent(messageContent.toString());
+            message.setObjId(record.getId());
+            message.setRead(0);
+            messageService.insertSelective(message);
+            log.error("read excel error = " + e.getMessage());
+        }finally {
+            FileUtil.deleteFile(record.getImportFilePath());
+            try {
+                if (workbook != null) {
+                    workbook.close();
+                }
+                if (inputStream != null) {
+                    inputStream.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+    /**
+     * 循环Excel
+     */
+    protected abstract void cycleExcel();
+
+    /**
+     * 失败文件
+     */
+    private final void failFile(){
+        if(failTime.get() > 0){
+            try {
+                String FailFilePath = this.getFilePath();
+                FileOutputStream os = new FileOutputStream(FailFilePath);
+                workbook.write(os);
+                os.close();
+                record.setFailFilePath(FailFilePath);
+            }catch (Exception e){
+                e.printStackTrace();
+            }
+
+        }
+    }
+    /**
+     * 记录消息
+     */
+    private final void recordMessage(){
+
+
+        //更新导入记录
+        record.setImportStatus(1);
+        record.setSuccessTime(successTime.get());
+        record.setFailTime(failTime.get());
+        importService.updateByPrimaryKeySelective(record);
+
+
+        if(invalidTemplate){
+            messageContent.append("导入完成,");
+            messageContent.append("导入成功");
+            messageContent.append(successTime);
+            messageContent.append("条");
+            messageContent.append("导入失败");
+            messageContent.append(failTime);
+            messageContent.append("条。");
+        }else {
+            messageContent.append("无效模板");
+        }
+
+        //更新完成生成消息
+        Message message = new Message();
+        message.setSiteId(record.getUserId());
+        message.setUserId(record.getUserId());
+        message.setMessageType(record.getType());
+        message.setMessageTitle(messageTitle);
+        message.setMessageContent(messageContent.toString());
+        if(isDownload && failTime.get() > 0){
+            message.setMessageUrl(domain+"/api/import/downloadFailTemplate?objId="+record.getId());
+        }
+        message.setObjId(record.getId());
+        message.setRead(0);
+        messageService.insertSelective(message);
+    }
+}

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

@@ -0,0 +1,89 @@
+package com.bz.smart_city.excel.download.template;
+
+import com.bz.smart_city.commom.model.AjaxMessage;
+import com.bz.smart_city.commom.util.UserUtil;
+import com.bz.smart_city.commom.util.Util;
+import com.bz.smart_city.dao.ChannelMapper;
+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 com.bz.smart_city.service.pay.PaySyncDataService;
+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 java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+
+import static com.google.common.collect.Lists.newArrayList;
+
+/**
+ * Created by ZJY on 2021-01-13 11:35
+ */
+@Component
+public class InstallPlanDownloadExcelTemplate extends AbstractDownloadExcelTemplate {
+
+
+    @Autowired
+    private CommunityService communityService;
+    @Autowired
+    private CustomerService customerService;
+    @Autowired
+    private PaySyncDataService paySyncDataService;
+
+
+    @Value("${files.path}")
+    private String filesPath;
+
+    private String getFilePath() {
+        String name = Util.createUUIDId();
+        String fullPath = filesPath + "/" + name + ".xlsx";
+        return fullPath;
+    }
+
+    @Override
+    protected void setParam() {
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        filePath = getFilePath();
+        templatePath = "excel/installPlanTemplate_20201208.xlsx";
+
+        DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyyMMdd");
+        LocalDateTime date = LocalDateTime.now();
+        downloadName = "批量创建装表计划模板"+ "_" + date.format(f);
+
+
+        //1、获取小区列表数据
+        List<Community> communityList = communityService.findBySiteId(loginUser.getSiteId());
+
+
+        //2、获取建筑列表数据
+        //List<Building> buildingList = buildingMapper.findBySiteId(loginUser.getSiteId(),null, UserUtil.getCustomerIds());
+
+
+
+        //3、获取客户列表数据
+        List<Customer> customerList = customerService.getCustomerList(loginUser.getSiteId());
+
+
+        //4、获取水表类型数据
+        AjaxMessage<List<DeviceTypeDto>> ajax =  paySyncDataService.queryWaterMeterType(null);
+        if(ajax != null){
+            if(ajax.getStatus() == 0){
+                this.context.putVar("deviceTypeList", ajax.getData());
+            }
+        }
+
+
+        this.context = new Context();
+        this.context.putVar("communityList", communityList);
+        this.context.putVar("buildingList", newArrayList());
+        this.context.putVar("customerList", customerList);
+        //this.context.putVar("deviceTypeList", deviceTypeList);
+    }
+}

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

@@ -0,0 +1,252 @@
+package com.bz.smart_city.excel.resolver;
+
+import com.alibaba.druid.sql.visitor.functions.Trim;
+import com.bz.smart_city.commom.model.AjaxMessage;
+import com.bz.smart_city.commom.model.ResultStatus;
+import com.bz.smart_city.dao.CommunityMapper;
+import com.bz.smart_city.dao.CustomerMapper;
+import com.bz.smart_city.dto.DeviceTypeDto;
+import com.bz.smart_city.dto.pay.InstallPlanDataDTO;
+import com.bz.smart_city.dto.pay.InstallPlanInputDTO;
+import com.bz.smart_city.entity.Community;
+import com.bz.smart_city.entity.Customer;
+import com.bz.smart_city.excel.AbstractResolverExcelTemplate;
+import com.bz.smart_city.service.CommunityService;
+import com.bz.smart_city.service.pay.PaySyncDataService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
+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 org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.util.*;
+
+
+
+/**
+ * Created by ZJY on 2021-01-13 16:55
+ */
+@Slf4j
+@Component
+public class InstallPlanResolverExcelTemplate extends AbstractResolverExcelTemplate {
+    @Resource
+    private CustomerMapper customerMapper;
+
+    @Resource
+    private CommunityMapper communityMapper;
+
+    @Autowired
+    private PaySyncDataService paySyncDataService;
+
+
+    @Override
+    @Transactional
+    protected void cycleExcel(){
+        log.info("begin InstallPlanResolverExcelTemplate");
+        try {
+            Thread.sleep(1000);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+        String executeSheetName = "装表计划模板";
+        //InstallListDTO dto = new InstallListDTO();
+        //dto.setSiteId(record.getSiteId());
+        //dto.setInstallTime(LocalDateTime.now());
+        // 循环工作表Sheet
+        for (int numSheet = 0; numSheet < workbook.getNumberOfSheets(); numSheet++) {
+            Sheet hssfSheet = workbook.getSheetAt(numSheet);
+            if (hssfSheet == null) {
+                continue;
+            }
+            if (!StringUtils.equals(executeSheetName, hssfSheet.getSheetName())) {
+                continue;
+            }
+            invalidTemplate = true;
+            // 1,处理表头,解析客户、小区、户数
+            Cell customerNameCell =  hssfSheet.getRow(1).getCell(4);
+            Cell communityNameCell =  hssfSheet.getRow(2).getCell(4);
+            Cell installGroupNameCell =  hssfSheet.getRow(4).getCell(4);
+            Cell phoneCell =  hssfSheet.getRow(5).getCell(4);
+            customerNameCell.setCellType(CellType.STRING);
+            installGroupNameCell.setCellType(CellType.STRING);
+            phoneCell.setCellType(CellType.STRING);
+            if(StringUtils.equals("", customerNameCell.getStringCellValue().trim())) {
+                messageContent.append("导入失败,");
+                messageContent.append(ResultStatus.CUSTOMER_IS_NOT_EXISTED.getMessage());
+                continue;
+            }
+            Customer customer = customerMapper.findByName(record.getSiteId(),customerNameCell.getStringCellValue().trim());
+            if(customer==null){
+                messageContent.append("导入失败,");
+                messageContent.append(ResultStatus.CUSTOMER_IS_NOT_EXISTED.getMessage());
+                continue;
+            }
+
+            Community community = communityMapper.findByName(record.getSiteId(),communityNameCell.getStringCellValue().trim());
+            if (community == null) {
+                messageContent.append("导入失败,");
+                messageContent.append(ResultStatus.COMMUNITY_IS_NOT_EXISTED.getMessage());
+                continue;
+            }
+
+
+            Cell numberCell = hssfSheet.getRow(3).getCell(4);// 安装数字,只处理指定安装户数的数据
+            numberCell.setCellType(CellType.NUMERIC);
+
+            int number = ((Double)numberCell.getNumericCellValue()).intValue();
+            if(number < 0 || number > 5000) {
+                messageContent.append("导入失败,");
+                messageContent.append(ResultStatus.NUMBER_IS_OUT_RANGE.getMessage());
+                continue;
+            }
+
+            log.info("info = {},{},{},{},{}",customer.getCustomerName(),community.getName(),number,installGroupNameCell.getStringCellValue(),phoneCell.getStringCellValue());
+
+            Integer enableUnit = 0;
+            Integer buildingNum = 0;
+            Integer unitNum = 0;
+            Integer doorNum = 0;
+
+
+            AjaxMessage<List<DeviceTypeDto>> DeviceTypeAjax =  paySyncDataService.queryWaterMeterType(null);
+            if(DeviceTypeAjax == null || DeviceTypeAjax.getStatus() != 0){
+                messageContent.append("导入失败,");
+                messageContent.append(ResultStatus.DEVICE_TYPE_NOT_EXISTED.getMessage());
+                continue;
+            }
+
+            // 2,处理明细行数据
+            for (int rowNum = 9; rowNum < 9+number ; rowNum++) {
+                Row row = hssfSheet.getRow(rowNum);
+                if (row != null) {
+
+                    Cell buildingCell = row.getCell(0) ;
+                    Cell unitCell = row.getCell(1);
+                    Cell floorCell = row.getCell(2);
+                    Cell doorNoCell = row.getCell(3);
+                    Cell deviceTypeCell = row.getCell(4);
+                    Cell fileNoCell = row.getCell(5);
+                    Cell userNameCell = row.getCell(6);
+                    Cell userPhoneCell = row.getCell(7);
+                    Cell idCardCell = row.getCell(8);
+                    Cell remarkCell = row.getCell(9);
+
+                    buildingCell.setCellType(CellType.STRING);
+                    unitCell.setCellType(CellType.STRING);
+                    floorCell.setCellType(CellType.STRING);
+                    doorNoCell.setCellType(CellType.STRING);
+                    deviceTypeCell.setCellType(CellType.STRING);
+                    fileNoCell.setCellType(CellType.STRING);
+                    userNameCell.setCellType(CellType.STRING);
+                    userPhoneCell.setCellType(CellType.STRING);
+                    idCardCell.setCellType(CellType.STRING);
+
+                    if (StringUtils.equals("", buildingCell.getStringCellValue().trim()) &&
+                            StringUtils.equals("", floorCell.getStringCellValue().trim()) &&
+                            StringUtils.equals("", doorNoCell.getStringCellValue()) &&
+                            StringUtils.equals("", deviceTypeCell.getStringCellValue().trim())
+                    ) {
+                        continue;
+                    }
+                    if (StringUtils.equals("", buildingCell.getStringCellValue().trim())){
+                        failTime.incrementAndGet();
+                        continue;
+                    }
+                    if (StringUtils.equals("", floorCell.getStringCellValue().trim())){
+                        failTime.incrementAndGet();
+                        continue;
+                    }
+                    if (StringUtils.equals("", doorNoCell.getStringCellValue().trim())){
+                        failTime.incrementAndGet();
+                        continue;
+                    }
+                    if (StringUtils.equals("", deviceTypeCell.getStringCellValue().trim())){
+                        failTime.incrementAndGet();
+                        continue;
+                    }
+
+                    log.info("Row info = building={},unit={},floor={},doorNo={},deviceType={},fileNo={},userName={},userPhone={},idCard={}",buildingCell.getStringCellValue(),unitCell.getStringCellValue(),floorCell.getStringCellValue(),
+                            doorNoCell.getStringCellValue(),deviceTypeCell.getStringCellValue(),fileNoCell.getStringCellValue(),userNameCell.getStringCellValue(),
+                            userPhoneCell.getStringCellValue(),idCardCell.getStringCellValue());
+                    //deviceTypeSet.add(deviceTypeCell.getStringCellValue().trim());
+
+                    InstallPlanInputDTO installPlanInput = new InstallPlanInputDTO();
+                    installPlanInput.setCustomerId(customerId);
+                    //是否启用单元
+                    if(StringUtils.equals("",unitCell.getStringCellValue().trim())){
+                        installPlanInput.setEnableUnit(0);
+                    }
+                    else
+                        installPlanInput.setEnableUnit(1);
+                    installPlanInput.setCommunityName(communityNameCell.getStringCellValue());//小区
+                    installPlanInput.setPreInstallNumber(1); //报装客户数
+                    //设备类型
+                    String str = deviceTypeCell.getStringCellValue().trim();
+                    String[] deviceType  = StringUtils.split(str,"/");
+                    List<Integer> devieTypeId = new ArrayList();
+                    for (DeviceTypeDto type :DeviceTypeAjax.getData()){
+                        if(type.getEquipmentType().equals(deviceType[1]) && type.getModel().equals(deviceType[2])){
+                            devieTypeId.add(type.getId());
+                            break;
+                        }
+                    }
+                    installPlanInput.setDeviceTypeIds(devieTypeId);
+
+                    //地址
+                    installPlanInput.setAdrress(community.getAddress());
+                    //省市区编码
+                    installPlanInput.setProvince(community.getProvince());
+                    installPlanInput.setCity(community.getCity());
+                    installPlanInput.setRegion(community.getRegion());
+
+                    InstallPlanDataDTO buildDTO = new InstallPlanDataDTO();
+                    InstallPlanDataDTO unitDTO = new InstallPlanDataDTO();
+                    InstallPlanDataDTO floorDTO = new InstallPlanDataDTO();
+                    InstallPlanDataDTO doorNoDTO = new InstallPlanDataDTO();
+
+                    //楼栋 单元 楼层 门牌号
+                    buildDTO.setName(buildingCell.getStringCellValue().trim());
+                    floorDTO.setName(floorCell.getStringCellValue().trim());
+                    doorNoDTO.setName(doorNoCell.getStringCellValue().trim());
+
+                    floorDTO.getChildren().add(doorNoDTO);
+                    if(installPlanInput.getEnableUnit() == 1){
+                        unitDTO.setName(unitCell.getStringCellValue().trim());
+                        unitDTO.getChildren().add(floorDTO);
+                        buildDTO.getChildren().add(unitDTO);
+                    }
+                    else
+                        buildDTO.getChildren().add(floorDTO);
+
+                    AjaxMessage ajax = paySyncDataService.addJF(installPlanInput);
+                    if(ajax != null){
+                        if(ajax.getStatus()==0){
+                            ;//成功
+                        }
+                    }
+                    hssfSheet.removeRow(row);//成功删除该行
+                    doorNum ++;
+                    successTime.incrementAndGet();
+                }
+            }
+
+            //循环为空的行上移
+            if(failTime.get() > 0){
+                for (int rowNum = 9+number-1; rowNum >= 9 ; rowNum--) {
+                    Row row = hssfSheet.getRow(rowNum);
+                    if (row == null) {
+                        hssfSheet.shiftRows(rowNum+1, 5000, -1);
+                    }
+                }
+            }
+
+            isDownload = true;
+        }
+        log.info("end InstallPlanResolverExcelTemplate");
+    }
+}

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

@@ -0,0 +1,11 @@
+package com.bz.smart_city.service.assistant;
+
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Created by ZJY on 2021-01-13 11:32
+ */
+public interface InstallPlanService {
+
+    void planDownTemplate(HttpServletResponse response);
+}

+ 27 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/assistant/InstallPlanServiceImpl.java

@@ -0,0 +1,27 @@
+package com.bz.smart_city.service.impl.assistant;
+
+import com.bz.smart_city.excel.download.template.InstallPlanDownloadExcelTemplate;
+import com.bz.smart_city.service.assistant.InstallPlanService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Created by ZJY on 2021-01-13 11:33
+ */
+@Slf4j
+@Service
+public class InstallPlanServiceImpl implements InstallPlanService {
+
+    @Autowired
+    private InstallPlanDownloadExcelTemplate installPlanDownloadExcelTemplate;
+
+    @Override
+    public void planDownTemplate(HttpServletResponse response) {
+        long startTime = System.currentTimeMillis();   //获取开始时间
+
+        installPlanDownloadExcelTemplate.download(null,response);
+    }
+}

+ 14 - 2
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/PayControlRuleServiceImpl.java

@@ -90,13 +90,13 @@ public class PayControlRuleServiceImpl implements PayControlRuleService {
     public boolean ExitsData(String id,String name,BigInteger customerId){
         if(id != null){
             List<PayControlRule> payControlRules = payControlRuleMapper.ExitsData(id,null,customerId );
-            if(payControlRules != null)
+            if(payControlRules != null && payControlRules.size() >0)
                 return true;
         }
 
         if(name != null){
             List<PayControlRule> payControlRules = payControlRuleMapper.ExitsData(null,name,customerId);
-            if(payControlRules != null)
+            if(payControlRules != null && payControlRules.size() > 0)
                 return true;
         }
 
@@ -377,4 +377,16 @@ public class PayControlRuleServiceImpl implements PayControlRuleService {
         return false;
     }
 
+    /**
+     * 用水量
+     * @param accountId 用户编号
+     * @param condition 条件
+     * @param value 判断值
+     * @return 符合条件返回true
+     */
+    public boolean ConditionUseQuantity(String accountId,String condition,String value){
+
+        return false;
+    }
+
 }

+ 7 - 0
smart-city-platform/src/main/resources/mapper/CommunityMapper.xml

@@ -363,5 +363,12 @@
         and province = #{province} and city = #{city} and region = #{region} and name = #{communityName}
     </select>
 
+    <select id="findByName" resultMap="BaseResultMap">
+        SELECT <include refid="Base_Column_List"></include>
+        from sc_community
+        where status = 1 and name = #{communityName}
+        <if test="siteId != null"> and site_id = #{siteId} </if>
+    </select>
+
 </mapper>
 

+ 4 - 0
smart-city-platform/src/main/resources/mapper/CustomerMapper.xml

@@ -265,5 +265,9 @@
         order by date_create desc
     </select>
 
+    <select id="findByName" resultMap="BaseResultMap">
+        select id,customer_name from sc_customer where status = 1 and site_id = #{siteId} and customer_name = #{name} limit 1
+    </select>
+
 </mapper>
 

+ 64 - 0
smart-city-platform/src/main/resources/mapper/pay/PayControlRecordMapper.xml

@@ -0,0 +1,64 @@
+<?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.pay.PayControlRecordMapper">
+    <select id="findList" resultType="com.bz.smart_city.entity.pay.PayControlRecord">
+        select
+        pcr.id,
+        pcr.account_id,
+        pcr.meter_id,
+        pcr.type,
+        pcr.result,
+        pcr.state,
+        pcr.control_rule_id,
+        pcr.create_by,
+        pcr.create_date,
+        pcr.update_by,
+        pcr.update_date,
+        pcr.remarks,
+        pcrule.name as controlRuleIdName
+        from pay_control_record pcr
+        left join pay_control_rule pcrule on pcr.control_rule_id = pcrule.id
+        <where>
+            del_flag = 0
+            <if test="payControlRecord.id != null"> and pcr.id = #{payControlRecord.id}</if>
+            <if test="payControlRecord.accountId != null"> and pcr.account_id = #{payControlRecord.accountId}</if>
+            <if test="payControlRecord.meterId != null"> and pcr.meter_id = #{payControlRecord.meterId}</if>
+            <if test="payControlRecord.controlRuleId != null"> and pcr.control_rule_id = #{payControlRecord.controlRuleId}</if>
+            <if test="payControlRecord.type != null"> and pcr.type = #{payControlRecord.type}</if>
+            <if test="payControlRecord.result != null"> and pcr.result = #{payControlRecord.result}</if>
+            <if test="payControlRecord.state != null"> and pcr.state = #{payControlRecord.state}</if>
+        </where>
+    </select>
+
+    <insert id="add" useGeneratedKeys="true" keyColumn="id">
+        insert into pay_control_record pcr (
+        pcr.account_id,
+        pcr.meter_id,
+        pcr.type,
+        pcr.result,
+        pcr.state,
+        pcr.control_rule_id,
+        pcr.create_by,
+        pcr.create_date,
+        pcr.update_by,
+        pcr.update_date,
+        pcr.del_flag,
+        pcr.remarks
+        )
+        values(
+        #{payControlRecord.accountId},
+        #{payControlRecord.meterId},
+        #{payControlRecord.type},
+        #{payControlRecord.result},
+        #{payControlRecord.state},
+        #{payControlRecord.controlRuleId},
+        #{payControlRecord.createBy},
+        #{payControlRecord.createDate},
+        #{payControlRecord.createBy},
+        #{payControlRecord.createDate},
+        0,
+        #{payControlRecord.remarks}
+        )
+
+    </insert>
+</mapper>

+ 13 - 13
smart-city-platform/src/main/resources/mapper/pay/PayControlRuleMapper.xml

@@ -5,7 +5,7 @@
         insert into
         pay_control_rule(
         name,
-        condition,
+        `condition`,
         operator,
         value,
         action,
@@ -29,14 +29,14 @@
         #{payControlRule.unit,jdbcType=VARCHAR},
         #{payControlRule.disable,jdbcType=VARCHAR},
 
-        #{paySysDict.createBy,jdbcType=BIGINT},
-        #{paySysDict.createDate,jdbcType=TIMESTAMP},
-        #{paySysDict.updateBy,jdbcType=BIGINT},
-        #{paySysDict.updateDate,jdbcType=TIMESTAMP},
-        #{paySysDict.remarks,jdbcType=VARCHAR},
-        #{paySysDict.delFlag,jdbcType=VARCHAR},
-        #{paySysDict.siteId,jdbcType=BIGINT},
-        #{paySysDict.customerId,jdbcType=BIGINT}
+        #{payControlRule.createBy,jdbcType=BIGINT},
+        #{payControlRule.createDate,jdbcType=TIMESTAMP},
+        #{payControlRule.updateBy,jdbcType=BIGINT},
+        #{payControlRule.updateDate,jdbcType=TIMESTAMP},
+        #{payControlRule.remarks,jdbcType=VARCHAR},
+        #{payControlRule.delFlag,jdbcType=VARCHAR},
+        #{payControlRule.siteId,jdbcType=BIGINT},
+        #{payControlRule.customerId,jdbcType=BIGINT}
         )
     </insert>
 
@@ -44,7 +44,7 @@
         select
             id,
             name,
-            condition,
+            `condition`,
             operator,
             value,
             action,
@@ -69,7 +69,7 @@
         select
             id,
             name,
-            condition,
+            `condition`,
             operator,
             value,
             action,
@@ -97,10 +97,10 @@
     </delete>
 
     <update id="edit">
-        update pay_control_rule
+        update pay_control_rule pcr
         set
             <if test="payControlRule.name != null and  payControlRule.name != ''"> name = #{payControlRule.name},</if>
-            <if test="payControlRule.condition != null and payControlRule.condition != ''"> condition = #{payControlRule.condition},</if>
+            <if test="payControlRule.condition != null and payControlRule.condition != ''"> pcr.condition = #{payControlRule.condition},</if>
             <if test="payControlRule.value != null and payControlRule.value != ''"> value = #{payControlRule.value},</if>
             <if test="payControlRule.operator != null and payControlRule.operator != ''"> operator = #{payControlRule.operator},</if>
             <if test="payControlRule.action != null and payControlRule.action != ''"> action = #{payControlRule.action},</if>