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