Browse Source

Merge remote-tracking branch 'origin/dev_import' into dev_import

dev
jianjun 4 years ago
parent
commit
f6dc586ffd
  1. 2
      epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java
  2. 19
      epmet-module/epmet-common-service/common-service-server/src/main/resources/db/migration/V0.0.12__createImportTask.sql
  3. 11
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcCommunitySelfOrganizationController.java
  4. 66
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcPartyActivityController.java
  5. 77
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcPartyUnitController.java
  6. 38
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/IcPartyActivityImportFailedExcel.java
  7. 38
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/IcPartyUnitImportFailedExcel.java
  8. 3
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/IcPartyActivityService.java
  9. 3
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/IcPartyUnitService.java
  10. 6
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java
  11. 261
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcPartyActivityServiceImpl.java
  12. 197
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcPartyUnitServiceImpl.java
  13. 30
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/BuildingController.java
  14. 59
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseController.java
  15. 19
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/IcNeighborHoodController.java
  16. 3
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/BuildingService.java
  17. 6
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/HouseService.java
  18. 3
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcNeighborHoodService.java
  19. 14
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/BuildingServiceImpl.java
  20. 45
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/HouseServiceImpl.java
  21. 47
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcNeighborHoodServiceImpl.java
  22. 8
      epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/controller/IcPartymemberStyleController.java
  23. 6
      epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/service/impl/IcPartymemberStyleServiceImpl.java
  24. 48
      epmet-user/epmet-user-server/src/main/java/com/epmet/entity/ImportTaskEntity.java

2
epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java

@ -13,6 +13,8 @@ public interface ImportTaskConstants {
String BIZ_TYPE_HOUSE = "house";
String BIZ_TYPE_PARTY_MEMBER = "party_member";
String BIZ_TYPE_COMMUNITY_SELF_ORG = "community_self_org";
String BIZ_TYPE_PARTY_UNIT = "party_unit";
String BIZ_TYPE_PARTY_ACTIVITY = "party_activity";
/**
* 处理状态处理中

19
epmet-module/epmet-common-service/common-service-server/src/main/resources/db/migration/V0.0.12__createImportTask.sql

@ -0,0 +1,19 @@
CREATE TABLE `import_task` (
`ID` varchar(64) NOT NULL COMMENT 'ID',
`CUSTOMER_ID` varchar(64) NOT NULL COMMENT '客户ID',
`ORIGIN_FILE_NAME` varchar(128) NOT NULL COMMENT '原始文件名',
`BIZ_TYPE` varchar(32) NOT NULL COMMENT '业务类型。【resi:居民;neighborHood:小区;building:楼栋;house:房屋;party_member:党员;society_org:社会组织;community_self_org:社区自组织】依次补充',
`PROCESS_STATUS` varchar(32) NOT NULL COMMENT '处理状态。processing:处理中;finished_success:成功;finished_unsuccess:未完全成功',
`OPERATOR_ID` varchar(64) NOT NULL COMMENT '谁导入的',
`START_TIME` datetime NOT NULL COMMENT '开始导入的时间',
`RESULT_DESC_FILE` varchar(255) DEFAULT NULL COMMENT '导入失败结果描述文件',
`RESULT_DESC` varchar(255) DEFAULT NULL COMMENT '导入结果描述,可以输入任何描述信息',
`DEL_FLAG` tinyint(1) NOT NULL COMMENT '删除标识:0.未删除 1.已删除',
`REVISION` int(11) NOT NULL COMMENT '乐观锁',
`CREATED_BY` varchar(64) NOT NULL COMMENT '创建人',
`CREATED_TIME` datetime NOT NULL COMMENT '创建时间',
`UPDATED_BY` varchar(64) NOT NULL COMMENT '更新人',
`UPDATED_TIME` datetime NOT NULL COMMENT '更新时间',
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

11
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcCommunitySelfOrganizationController.java

@ -17,10 +17,6 @@
package com.epmet.controller;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.hutool.poi.excel.ExcelUtil;
import com.epmet.commons.tools.annotation.LoginUser;
import com.epmet.commons.tools.aop.NoRepeatSubmit;
import com.epmet.commons.tools.exception.RenException;
@ -49,6 +45,7 @@ import com.epmet.service.IcCommunitySelfOrganizationService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@ -143,7 +140,9 @@ public class IcCommunitySelfOrganizationController {
* @date 2021/11/25 9:03 上午
*/
@PostMapping("importcommunityselforganization")
public void importCommunitySelfOrganization(@LoginUser TokenDto tokenDto, HttpServletResponse response, @RequestPart("file") MultipartFile file) throws Exception {
//service方法是异步的,需要事务注解加在被调用方 否则事务不起作用
@Transactional(rollbackFor = Exception.class)
public Result importCommunitySelfOrganization(@LoginUser TokenDto tokenDto, HttpServletResponse response, @RequestPart("file") MultipartFile file) throws Exception {
if (file.isEmpty()) {
throw new RenException("请上传文件");
}
@ -164,6 +163,8 @@ public class IcCommunitySelfOrganizationController {
}
//2.执行导入程序
icCommunitySelfOrganizationService.importCommunitySelfOrganization(tokenDto, response, file, result.getData().getTaskId());
return new Result();
}
/**

66
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcPartyActivityController.java

@ -19,6 +19,8 @@ package com.epmet.controller;
import com.epmet.commons.tools.annotation.LoginUser;
import com.epmet.commons.tools.aop.NoRepeatSubmit;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.DateUtils;
@ -27,20 +29,28 @@ import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.commons.tools.validator.group.AddGroup;
import com.epmet.commons.tools.validator.group.DefaultGroup;
import com.epmet.constants.ImportTaskConstants;
import com.epmet.dto.IcPartyActivityDTO;
import com.epmet.dto.form.ImportTaskCommonFormDTO;
import com.epmet.dto.form.PartyActivityFormDTO;
import com.epmet.dto.result.ImportTaskCommonResultDTO;
import com.epmet.dto.result.demand.OptionDTO;
import com.epmet.excel.IcPartyActivityExcel;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.service.IcPartyActivityService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@ -51,12 +61,15 @@ import java.util.stream.Collectors;
* @author generator generator@elink-cn.com
* @since v1.0.0 2021-11-19
*/
@Slf4j
@RestController
@RequestMapping("icpartyactivity")
public class IcPartyActivityController {
@Autowired
private IcPartyActivityService icPartyActivityService;
@Resource
private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient;
@PostMapping("search")
public Result<PageData<IcPartyActivityDTO>> page(@RequestBody PartyActivityFormDTO formDTO){
@ -116,7 +129,58 @@ public class IcPartyActivityController {
*/
@PostMapping("import")
public Result importData(@LoginUser TokenDto tokenDto, HttpServletResponse response, @RequestPart("file") MultipartFile file) throws IOException {
return icPartyActivityService.importData(tokenDto, response, file);
if (file.isEmpty()) {
throw new RenException("请上传文件");
}
String originalFilename = file.getOriginalFilename();
// 校验文件类型
String extension = FilenameUtils.getExtension(originalFilename);
if (!"xls".equals(extension) && !"xlsx".equals(extension)) {
throw new RenException("文件类型不匹配");
}
//1.查询当前工作人员是否有再导入的党员先锋数据,有则不允许导入,没有则进行新的导入
ImportTaskCommonFormDTO importTaskForm = new ImportTaskCommonFormDTO();
importTaskForm.setOriginFileName(file.getOriginalFilename());
importTaskForm.setOperatorId(tokenDto.getUserId());
importTaskForm.setBizType(ImportTaskConstants.BIZ_TYPE_PARTY_UNIT);
Result<ImportTaskCommonResultDTO> result = commonServiceOpenFeignClient.createImportTask(importTaskForm);
if (!result.success()) {
throw new RenException(result.getInternalMsg());
}
// 异步执行导入
CompletableFuture.runAsync(() -> {
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
submitResiImportTask(tokenDto, response, file, result.getData().getTaskId());
});
return new Result();
}
private void submitResiImportTask(TokenDto tokenDto, HttpServletResponse response, MultipartFile file, String importTaskId) {
try {
icPartyActivityService.importData(tokenDto, response, file, importTaskId);
} catch (Throwable e) {
String errorMsg = ExceptionUtils.getThrowableErrorStackTrace(e);
log.error("【导入联建活动信息失败】导入失败:{}", errorMsg);
ImportTaskCommonFormDTO importTaskForm = new ImportTaskCommonFormDTO();
importTaskForm.setOperatorId(tokenDto.getUserId());
importTaskForm.setBizType(ImportTaskConstants.BIZ_TYPE_PARTY_ACTIVITY);
importTaskForm.setTaskId(importTaskId);
importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL);
importTaskForm.setResultDesc("联建活动信息导入失败,请查看系统日志");
Result result = commonServiceOpenFeignClient.finishImportTask(importTaskForm);
if (!result.success()) {
throw new RenException(result.getInternalMsg());
}
}
}
/**

77
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcPartyUnitController.java

@ -21,6 +21,8 @@ import com.epmet.commons.rocketmq.messages.ServerSatisfactionCalFormDTO;
import com.epmet.commons.tools.annotation.LoginUser;
import com.epmet.commons.tools.aop.NoRepeatSubmit;
import com.epmet.commons.tools.dto.result.OptionDataResultDTO;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.ExcelUtils;
@ -29,23 +31,33 @@ import com.epmet.commons.tools.validator.AssertUtils;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.commons.tools.validator.group.AddGroup;
import com.epmet.commons.tools.validator.group.DefaultGroup;
import com.epmet.constants.ImportTaskConstants;
import com.epmet.dto.IcPartyUnitDTO;
import com.epmet.dto.form.ImportTaskCommonFormDTO;
import com.epmet.dto.form.PartyActivityFormDTO;
import com.epmet.dto.form.PartyUnitFormDTO;
import com.epmet.dto.form.demand.ServiceQueryFormDTO;
import com.epmet.dto.result.ImportTaskCommonResultDTO;
import com.epmet.dto.result.PartyUnitDistributionResultDTO;
import com.epmet.dto.result.demand.OptionDTO;
import com.epmet.excel.IcPartyUnitExcel;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.service.IcPartyUnitService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@ -56,12 +68,21 @@ import java.util.stream.Collectors;
* @author generator generator@elink-cn.com
* @since v1.0.0 2021-11-19
*/
@Slf4j
@RestController
@RequestMapping("icpartyunit")
public class IcPartyUnitController {
@Autowired
private IcPartyUnitService icPartyUnitService;
@Resource
private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient;
/**
* 联建单位上传临时目录
*/
private Path IC_PARTY_UNIT_UPLOAD_DIR;
@PostMapping("list")
public Result<PageData<IcPartyUnitDTO>> search(@LoginUser TokenDto tokenDto, @RequestBody PartyUnitFormDTO formDTO){
@ -151,8 +172,39 @@ public class IcPartyUnitController {
* @Date 2021/11/30 14:42
*/
@PostMapping("import")
public Result importData(@LoginUser TokenDto tokenDto, HttpServletResponse response, @RequestPart("file") MultipartFile file) throws IOException {
return icPartyUnitService.importData(tokenDto, response, file);
public Result importData(@LoginUser TokenDto tokenDto, HttpServletRequest multipartRequest, HttpServletResponse response, @RequestPart("file") MultipartFile file) throws IOException {
if (file.isEmpty()) {
throw new RenException("请上传文件");
}
String originalFilename = file.getOriginalFilename();
// 校验文件类型
String extension = FilenameUtils.getExtension(originalFilename);
if (!"xls".equals(extension) && !"xlsx".equals(extension)) {
throw new RenException("文件类型不匹配");
}
//1.查询当前工作人员是否有再导入的党员先锋数据,有则不允许导入,没有则进行新的导入
ImportTaskCommonFormDTO importTaskForm = new ImportTaskCommonFormDTO();
importTaskForm.setOriginFileName(file.getOriginalFilename());
importTaskForm.setOperatorId(tokenDto.getUserId());
importTaskForm.setBizType(ImportTaskConstants.BIZ_TYPE_PARTY_UNIT);
Result<ImportTaskCommonResultDTO> result = commonServiceOpenFeignClient.createImportTask(importTaskForm);
if (!result.success()) {
throw new RenException(result.getInternalMsg());
}
// 异步执行导入
CompletableFuture.runAsync(() -> {
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
submitResiImportTask(tokenDto, response, file, result.getData().getTaskId());
});
return new Result();
}
/**
@ -194,4 +246,25 @@ public class IcPartyUnitController {
icPartyUnitService.calPartyUnitSatisfation(formDTO);
return new Result();
}
private void submitResiImportTask(TokenDto tokenDto, HttpServletResponse response, MultipartFile file, String importTaskId) {
try {
icPartyUnitService.importData(tokenDto, response, file, importTaskId);
} catch (Throwable e) {
String errorMsg = ExceptionUtils.getThrowableErrorStackTrace(e);
log.error("【导入联建单位信息失败】导入失败:{}", errorMsg);
ImportTaskCommonFormDTO importTaskForm = new ImportTaskCommonFormDTO();
importTaskForm.setOperatorId(tokenDto.getUserId());
importTaskForm.setBizType(ImportTaskConstants.BIZ_TYPE_PARTY_UNIT);
importTaskForm.setTaskId(importTaskId);
importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL);
importTaskForm.setResultDesc("联建单位信息导入失败,请查看系统日志");
Result result = commonServiceOpenFeignClient.finishImportTask(importTaskForm);
if (!result.success()) {
throw new RenException(result.getInternalMsg());
}
}
}
}

38
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/IcPartyActivityImportFailedExcel.java

@ -0,0 +1,38 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.excel;
import cn.afterturn.easypoi.excel.annotation.Excel;
import com.epmet.commons.tools.utils.ExcelVerifyInfo;
import lombok.Data;
/**
* 联建活动
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2021-11-19
*/
@Data
public class IcPartyActivityImportFailedExcel extends ExcelVerifyInfo {
@Excel(name = "活动标题", width = 40)
private String title;
@Excel(name = "错误信息", width = 50)
private String errorInfo;
}

38
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/IcPartyUnitImportFailedExcel.java

@ -0,0 +1,38 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.excel;
import cn.afterturn.easypoi.excel.annotation.Excel;
import com.epmet.commons.tools.utils.ExcelVerifyInfo;
import lombok.Data;
/**
* 联建单位
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2021-11-19
*/
@Data
public class IcPartyUnitImportFailedExcel extends ExcelVerifyInfo {
@Excel(name = "单位名称", width = 40)
private String unitName;
@Excel(name = "错误信息", width = 50)
private String errorInfo;
}

3
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/IcPartyActivityService.java

@ -20,7 +20,6 @@ package com.epmet.service;
import com.epmet.commons.mybatis.service.BaseService;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.IcPartyActivityDTO;
import com.epmet.dto.form.PartyActivityFormDTO;
import com.epmet.dto.result.demand.OptionDTO;
@ -98,7 +97,7 @@ public interface IcPartyActivityService extends BaseService<IcPartyActivityEntit
* @Author zhaoqifeng
* @Date 2021/11/29 11:01
*/
Result importData(TokenDto tokenDto, HttpServletResponse response, MultipartFile file) throws IOException;
void importData(TokenDto tokenDto, HttpServletResponse response, MultipartFile file, String taskId) throws IOException;
/**
* 联建活动统计

3
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/IcPartyUnitService.java

@ -22,7 +22,6 @@ import com.epmet.commons.rocketmq.messages.ServerSatisfactionCalFormDTO;
import com.epmet.commons.tools.dto.result.OptionDataResultDTO;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.IcPartyUnitDTO;
import com.epmet.dto.form.PartyActivityFormDTO;
import com.epmet.dto.form.PartyUnitFormDTO;
@ -132,7 +131,7 @@ public interface IcPartyUnitService extends BaseService<IcPartyUnitEntity> {
* @Author zhaoqifeng
* @Date 2021/11/29 11:01
*/
Result importData(TokenDto tokenDto, HttpServletResponse response, MultipartFile file) throws IOException;
void importData(TokenDto tokenDto, HttpServletResponse response, MultipartFile file, String taskId) throws IOException;
/**
* @Description 按类型统计单位数量

6
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java

@ -57,6 +57,8 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.http.entity.ContentType;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
@ -80,6 +82,7 @@ import static com.epmet.commons.tools.utils.DateUtils.DATE_PATTERN;
*/
@Service
@Slf4j
@EnableAsync
public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCommunitySelfOrganizationDao, IcCommunitySelfOrganizationEntity> implements IcCommunitySelfOrganizationService {
@Autowired
@ -471,7 +474,8 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo
* @author sun
*/
@Override
@Transactional(rollbackFor = Exception.class)
//@Transactional(rollbackFor = Exception.class)
@Async
public void importCommunitySelfOrganization(TokenDto tokenDto, HttpServletResponse response, MultipartFile file, String taskId) throws IOException {
List<CommunitySelfOrgImportExcel> fileList = new ArrayList<>();
CommunitySelfOrgImportExcel excel = null;

261
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcPartyActivityServiceImpl.java

@ -17,13 +17,16 @@
package com.epmet.service.impl;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.redis.common.CustomerStaffRedis;
import com.epmet.commons.tools.security.dto.TokenDto;
@ -31,29 +34,42 @@ import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.commons.tools.utils.ExcelPoiUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.constants.ImportTaskConstants;
import com.epmet.dao.IcPartyActivityDao;
import com.epmet.dto.IcPartyActivityDTO;
import com.epmet.dto.IcPartyUnitDTO;
import com.epmet.dto.form.ImportTaskCommonFormDTO;
import com.epmet.dto.form.PartyActivityFormDTO;
import com.epmet.dto.result.ActivityStatisticsDTO;
import com.epmet.dto.result.UploadImgResultDTO;
import com.epmet.dto.result.demand.OptionDTO;
import com.epmet.entity.IcActivityServiceRelationEntity;
import com.epmet.entity.IcActivityUnitRelationEntity;
import com.epmet.entity.IcPartyActivityEntity;
import com.epmet.excel.IcPartyActivityImportExcel;
import com.epmet.excel.IcPartyActivityImportFailedExcel;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.feign.OssFeignClient;
import com.epmet.service.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.entity.ContentType;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@ -76,7 +92,10 @@ public class IcPartyActivityServiceImpl extends BaseServiceImpl<IcPartyActivityD
private IcActivityUnitRelationService icActivityUnitRelationService;
@Resource
private IcActivityServiceRelationService icActivityServiceRelationService;
@Resource
private OssFeignClient ossFeignClient;
@Resource
private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient;
@Override
@ -233,16 +252,18 @@ public class IcPartyActivityServiceImpl extends BaseServiceImpl<IcPartyActivityD
* @Date 2021/11/29 11:01
*/
@Override
public Result importData(TokenDto tokenDto, HttpServletResponse response, MultipartFile file) throws IOException {
public void importData(TokenDto tokenDto, HttpServletResponse response, MultipartFile file, String taskId) throws IOException {
List<IcPartyActivityImportFailedExcel> fileList = new ArrayList<>();
ExcelImportResult<IcPartyActivityImportExcel> importResult = ExcelPoiUtils.importExcelMore(file, 0, 1, IcPartyActivityImportExcel.class);
List<IcPartyActivityImportExcel> failList = importResult.getFailList();
//存放错误数据行号
List<Integer> numList = new ArrayList<>();
if (!org.springframework.util.CollectionUtils.isEmpty(failList)) {
for (IcPartyActivityImportExcel entity : failList) {
//打印失败的行 和失败的信息
log.warn("第{}行,{}", entity.getRowNum(), entity.getErrorMsg());
numList.add(entity.getRowNum());
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(entity, IcPartyActivityImportFailedExcel.class);
failed.setErrorInfo(entity.getErrorMsg());
fileList.add(failed);
}
}
List<IcPartyActivityImportExcel> result = importResult.getList();
@ -262,14 +283,18 @@ public class IcPartyActivityServiceImpl extends BaseServiceImpl<IcPartyActivityD
IcPartyActivityImportExcel obj = iterator.next();
//单位名称校验
if (StringUtils.isBlank(obj.getUnitName())) {
numList.add(obj.getRowNum());
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class);
failed.setErrorInfo("单位名称为空");
fileList.add(failed);
log.warn(String.format("单位名称为空,行号->%s", obj.getRowNum()));
iterator.remove();
} else {
List<String> unitList = Arrays.asList(obj.getUnitName().split(StrConstant.COMMA));
unitList.forEach(unit -> {
if (null == option.get(unit)) {
numList.add(obj.getRowNum());
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class);
failed.setErrorInfo("单位名称不存在");
fileList.add(failed);
log.warn(String.format("单位名称不存在,行号->%s", obj.getRowNum()));
iterator.remove();
}
@ -277,14 +302,18 @@ public class IcPartyActivityServiceImpl extends BaseServiceImpl<IcPartyActivityD
}
//服务事项校验
if (StringUtils.isBlank(obj.getServiceMatter())) {
numList.add(obj.getRowNum());
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class);
failed.setErrorInfo("服务事项为空");
fileList.add(failed);
log.warn(String.format("服务事项为空,行号->%s", obj.getRowNum()));
iterator.remove();
} else {
List<String> serviceList = Arrays.asList(obj.getServiceMatter().split(StrConstant.SEMICOLON));
serviceList.forEach(service -> {
if (null == categoryMap.get(service)) {
numList.add(obj.getRowNum());
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class);
failed.setErrorInfo("服务事项不存在");
fileList.add(failed);
log.warn(String.format("服务事项不存在,行号->%s", obj.getRowNum()));
iterator.remove();
}
@ -292,79 +321,163 @@ public class IcPartyActivityServiceImpl extends BaseServiceImpl<IcPartyActivityD
}
//活动标题 活动目标 活动内容 活动时间 活动地址 活动地址经度 活动地址纬度 活动结果
if(StringUtils.isBlank(obj.getTitle()) || StringUtils.isBlank(obj.getTarget()) ||
StringUtils.isBlank(obj.getContent()) ||
StringUtils.isBlank(obj.getActivityTime()) ||
StringUtils.isBlank(obj.getAddress()) ||
StringUtils.isBlank(obj.getLatitude()) ||
StringUtils.isBlank(obj.getLongitude()) ||
StringUtils.isBlank(obj.getResult())) {
numList.add(obj.getRowNum());
log.warn(String.format("活动标题、活动目标、活动内容、活动时间、活动地址、活动地址经度、活动地址纬度、活动结果为空,行号->%s", obj.getRowNum()));
if(StringUtils.isBlank(obj.getTitle())) {
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class);
failed.setErrorInfo("活动标题为空");
fileList.add(failed);
log.warn(String.format("活动标题为空,行号->%s", obj.getRowNum()));
iterator.remove();
} else if(StringUtils.isBlank(obj.getTarget())) {
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class);
failed.setErrorInfo("活动目标为空");
fileList.add(failed);
log.warn(String.format("活动目标为空,行号->%s", obj.getRowNum()));
} else if(StringUtils.isBlank(obj.getContent())) {
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class);
failed.setErrorInfo("活动内容为空");
fileList.add(failed);
log.warn(String.format("活动内容为空,行号->%s", obj.getRowNum()));
} else if(StringUtils.isBlank(obj.getActivityTime())) {
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class);
failed.setErrorInfo("活动时间为空");
fileList.add(failed);
log.warn(String.format("活动时间为空,行号->%s", obj.getRowNum()));
} else if(StringUtils.isBlank(obj.getAddress())) {
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class);
failed.setErrorInfo("活动地址为空");
fileList.add(failed);
log.warn(String.format("活动地址为空,行号->%s", obj.getRowNum()));
} else if(StringUtils.isBlank(obj.getLatitude())) {
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class);
failed.setErrorInfo("活动地址纬度为空");
fileList.add(failed);
log.warn(String.format("活动地址纬度为空,行号->%s", obj.getRowNum()));
} else if(StringUtils.isBlank(obj.getLongitude())) {
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class);
failed.setErrorInfo("活动地址经度为空");
fileList.add(failed);
log.warn(String.format("活动地址经度为空,行号->%s", obj.getRowNum()));
} else if(StringUtils.isBlank(obj.getResult())) {
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class);
failed.setErrorInfo("活动结果为空");
fileList.add(failed);
log.warn(String.format("活动结果为空,行号->%s", obj.getRowNum()));
}
}
if (CollectionUtils.isEmpty(result)) {
Collections.sort(numList);
String subList = numList.stream().map(String::valueOf).collect(Collectors.joining("、"));
return new Result().error(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "第" + subList + "行未成功!");
if (CollectionUtils.isNotEmpty(result)) {
result.forEach(item -> {
IcPartyActivityEntity entity = new IcPartyActivityEntity();
entity.setCustomerId(tokenDto.getCustomerId());
entity.setAgencyId(staffInfoCache.getAgencyId());
entity.setPids(staffInfoCache.getAgencyPIds());
entity.setTitle(item.getTitle());
entity.setTarget(item.getTarget());
entity.setContent(item.getContent());
entity.setPeopleCount(item.getPeopleCount());
entity.setActivityTime(DateUtils.parse(item.getActivityTime(), DateUtils.DATE_TIME_PATTERN));
entity.setAddress(item.getAddress());
entity.setLatitude(item.getLatitude());
entity.setLongitude(item.getLongitude());
entity.setResult(item.getResult());
insert(entity);
//保存活动与单位关系
icActivityUnitRelationService.deleteByActivity(entity.getId());
AtomicInteger i = new AtomicInteger(NumConstant.ONE);
List<IcActivityUnitRelationEntity> unitRelationList = Arrays.stream(item.getUnitName().split(StrConstant.COMMA)).map(unit -> {
IcActivityUnitRelationEntity relation = new IcActivityUnitRelationEntity();
relation.setCustomerId(entity.getCustomerId());
relation.setAgencyId(entity.getAgencyId());
relation.setPids(entity.getPids());
relation.setActivityId(entity.getId());
relation.setUnitId(option.get(unit));
relation.setSort(i.getAndIncrement());
return relation;
}).collect(Collectors.toList());
icActivityUnitRelationService.insertBatch(unitRelationList);
//保存活动与服务关系
icActivityServiceRelationService.deleteByActivity(entity.getId());
AtomicInteger j = new AtomicInteger(NumConstant.ONE);
List<IcActivityServiceRelationEntity> serviceRelationList = Arrays.stream(item.getServiceMatter().split(StrConstant.SEMICOLON)).map(service -> {
IcActivityServiceRelationEntity relation = new IcActivityServiceRelationEntity();
relation.setCustomerId(entity.getCustomerId());
relation.setAgencyId(entity.getAgencyId());
relation.setPids(entity.getPids());
relation.setActivityId(entity.getId());
relation.setServiceMatter(categoryMap.get(service));
relation.setSort(j.getAndIncrement());
return relation;
}).collect(Collectors.toList());
icActivityServiceRelationService.insertBatch(serviceRelationList);
});
}
String str = String.format("共%s条,成功导入%s条。", fileList.size() + result.size(), fileList.size() + result.size() - fileList.size());
result.forEach(item -> {
IcPartyActivityEntity entity = new IcPartyActivityEntity();
entity.setCustomerId(tokenDto.getCustomerId());
entity.setAgencyId(staffInfoCache.getAgencyId());
entity.setPids(staffInfoCache.getAgencyPIds());
entity.setTitle(item.getTitle());
entity.setTarget(item.getTarget());
entity.setContent(item.getContent());
entity.setPeopleCount(item.getPeopleCount());
entity.setActivityTime(DateUtils.parse(item.getActivityTime(), DateUtils.DATE_TIME_PATTERN));
entity.setAddress(item.getAddress());
entity.setLatitude(item.getLatitude());
entity.setLongitude(item.getLongitude());
entity.setResult(item.getResult());
insert(entity);
//保存活动与单位关系
icActivityUnitRelationService.deleteByActivity(entity.getId());
AtomicInteger i = new AtomicInteger(NumConstant.ONE);
List<IcActivityUnitRelationEntity> unitRelationList = Arrays.stream(item.getUnitName().split(StrConstant.COMMA)).map(unit -> {
IcActivityUnitRelationEntity relation = new IcActivityUnitRelationEntity();
relation.setCustomerId(entity.getCustomerId());
relation.setAgencyId(entity.getAgencyId());
relation.setPids(entity.getPids());
relation.setActivityId(entity.getId());
relation.setUnitId(option.get(unit));
relation.setSort(i.getAndIncrement());
return relation;
}).collect(Collectors.toList());
icActivityUnitRelationService.insertBatch(unitRelationList);
//保存活动与服务关系
icActivityServiceRelationService.deleteByActivity(entity.getId());
AtomicInteger j = new AtomicInteger(NumConstant.ONE);
List<IcActivityServiceRelationEntity> serviceRelationList = Arrays.stream(item.getServiceMatter().split(StrConstant.SEMICOLON)).map(service -> {
IcActivityServiceRelationEntity relation = new IcActivityServiceRelationEntity();
relation.setCustomerId(entity.getCustomerId());
relation.setAgencyId(entity.getAgencyId());
relation.setPids(entity.getPids());
relation.setActivityId(entity.getId());
relation.setServiceMatter(categoryMap.get(service));
relation.setSort(j.getAndIncrement());
return relation;
}).collect(Collectors.toList());
icActivityServiceRelationService.insertBatch(serviceRelationList);
});
String str = String.format("共%s条,成功导入%s条。", numList.size() + result.size(), numList.size() + result.size() - numList.size());
if (numList.size() > NumConstant.ZERO) {
Collections.sort(numList);
if (fileList.size() > NumConstant.ZERO) {
List<Integer> numList = fileList.stream().map(IcPartyActivityImportFailedExcel::getRowNum).sorted().collect(Collectors.toList());
String subList = numList.stream().map(String::valueOf).collect(Collectors.joining("、"));
log.warn(str + "第" + subList + "行未成功!");
return new Result().error(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), str + "第" + subList + "行未成功!");
}
return new Result().ok(str);
//错误数据生成文件,修改导入任务状态
erroeImport(fileList, taskId, tokenDto.getUserId());
}
private void erroeImport(List<IcPartyActivityImportFailedExcel> fileList, String importTaskId, String staffId) throws IOException {
String url = "";
//1.有错误数据则生成错误数据存放文件传到阿里云服务
if (CollectionUtils.isNotEmpty(fileList)) {
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("导入失败的数据列表", "导入失败的数据列表"),
IcPartyActivityImportFailedExcel.class, fileList);
// 文件名
String resultDescFileName = UUID.randomUUID().toString().concat(".xlsx");
FileItemFactory factory = new DiskFileItemFactory(16, null);
FileItem fileItem = factory.createItem("file", ContentType.APPLICATION_OCTET_STREAM.toString(), true, resultDescFileName);
OutputStream os = fileItem.getOutputStream();
Result<UploadImgResultDTO> uploadResult = null;
try {
workbook.write(os);
uploadResult = ossFeignClient.uploadImportTaskDescFile(new CommonsMultipartFile(fileItem));
} catch (Exception e) {
String errormsg = ExceptionUtils.getErrorStackTrace(e);
log.error("【联建活动信息导入】上传错误描述文件:{}", errormsg);
} finally {
try {
os.close();
} catch (IOException e) {
String errormsg = ExceptionUtils.getErrorStackTrace(e);
log.error("【联建活动信息导入】上传错误描述文件关闭输出流:{}", errormsg);
}
try {
fileItem.delete();
} catch (Exception e) {
String errormsg = ExceptionUtils.getErrorStackTrace(e);
log.error("【联建活动信息导入】上传错误描述文件删除临时文件:{}", errormsg);
}
}
if (uploadResult == null || !uploadResult.success()) {
log.error("【联建活动信息导入】调用OSS上传结果描述文件失败");
} else {
url = uploadResult.getData().getUrl();
}
}
//2.更新导入任务数据
ImportTaskCommonFormDTO importTaskForm = new ImportTaskCommonFormDTO();
importTaskForm.setOperatorId(staffId);
importTaskForm.setBizType(ImportTaskConstants.BIZ_TYPE_PARTY_ACTIVITY);
importTaskForm.setTaskId(importTaskId);
importTaskForm.setResultDescFilePath(url);
importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS);
if (CollectionUtils.isNotEmpty(fileList)) {
importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL);
importTaskForm.setResultDesc("联建活动导入存在错误数据");
}
Result result = commonServiceOpenFeignClient.finishImportTask(importTaskForm);
if (!result.success()) {
throw new RenException(result.getInternalMsg());
}
}
/**

197
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcPartyUnitServiceImpl.java

@ -17,6 +17,8 @@
package com.epmet.service.impl;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -34,6 +36,8 @@ import com.epmet.commons.tools.enums.DictTypeEnum;
import com.epmet.commons.tools.enums.PartyUnitTypeEnum;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.EpmetException;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.redis.common.CustomerStaffRedis;
import com.epmet.commons.tools.security.dto.TokenDto;
@ -41,17 +45,23 @@ import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.ExcelPoiUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.constant.UserDemandConstant;
import com.epmet.constants.ImportTaskConstants;
import com.epmet.dao.IcPartyUnitDao;
import com.epmet.dto.IcPartyUnitDTO;
import com.epmet.dto.form.ImportTaskCommonFormDTO;
import com.epmet.dto.form.PartyActivityFormDTO;
import com.epmet.dto.form.PartyUnitFormDTO;
import com.epmet.dto.form.demand.ServiceQueryFormDTO;
import com.epmet.dto.result.PartyUnitDistributionResultDTO;
import com.epmet.dto.result.UploadImgResultDTO;
import com.epmet.dto.result.demand.OptionDTO;
import com.epmet.dto.result.demand.ServiceStatDTO;
import com.epmet.entity.IcPartyUnitEntity;
import com.epmet.excel.IcPartyUnitImportExcel;
import com.epmet.excel.IcPartyUnitImportFailedExcel;
import com.epmet.feign.EpmetAdminOpenFeignClient;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.feign.OssFeignClient;
import com.epmet.service.IcPartyUnitService;
import com.epmet.service.IcResiDemandDictService;
import com.epmet.service.IcServiceItemDictService;
@ -60,14 +70,21 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.entity.ContentType;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
@ -90,6 +107,10 @@ public class IcPartyUnitServiceImpl extends BaseServiceImpl<IcPartyUnitDao, IcPa
private IcResiDemandDictService icResiDemandDictService;
@Resource
private IcServiceItemDictService icServiceItemDictService;
@Resource
private OssFeignClient ossFeignClient;
@Resource
private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient;
@Override
public PageData<IcPartyUnitDTO> search(PartyUnitFormDTO formDTO) {
@ -303,16 +324,19 @@ public class IcPartyUnitServiceImpl extends BaseServiceImpl<IcPartyUnitDao, IcPa
* @Date 2021/11/29 11:01
*/
@Override
public Result importData(TokenDto tokenDto, HttpServletResponse response, MultipartFile file) throws IOException {
public void importData(TokenDto tokenDto, HttpServletResponse response, MultipartFile file, String taskId) throws IOException {
List<IcPartyUnitImportFailedExcel> fileList = new ArrayList<>();
ExcelImportResult<IcPartyUnitImportExcel> importResult = ExcelPoiUtils.importExcelMore(file, 0, 1, IcPartyUnitImportExcel.class);
List<IcPartyUnitImportExcel> failList = importResult.getFailList();
//存放错误数据行号
List<Integer> numList = new ArrayList<>();
if (!org.springframework.util.CollectionUtils.isEmpty(failList)) {
for (IcPartyUnitImportExcel entity : failList) {
//打印失败的行 和失败的信息
log.warn("第{}行,{}", entity.getRowNum(), entity.getErrorMsg());
numList.add(entity.getRowNum());
IcPartyUnitImportFailedExcel failed = ConvertUtils.sourceToTarget(entity, IcPartyUnitImportFailedExcel.class);
failed.setErrorInfo(entity.getErrorMsg());
fileList.add(failed);
}
}
List<IcPartyUnitImportExcel> result = importResult.getList();
@ -329,7 +353,9 @@ public class IcPartyUnitServiceImpl extends BaseServiceImpl<IcPartyUnitDao, IcPa
IcPartyUnitImportExcel obj = iterator.next();
//单位名称不能为空,不可重复
if (StringUtils.isBlank(obj.getUnitName())) {
numList.add(obj.getRowNum());
IcPartyUnitImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyUnitImportFailedExcel.class);
failed.setErrorInfo("单位名称为空");
fileList.add(failed);
log.warn(String.format("单位名称为空,行号->%s", obj.getRowNum()));
iterator.remove();
} else {
@ -338,14 +364,18 @@ public class IcPartyUnitServiceImpl extends BaseServiceImpl<IcPartyUnitDao, IcPa
wrapper.eq(IcPartyUnitEntity::getUnitName, obj.getUnitName());
List<IcPartyUnitEntity> list = baseDao.selectList(wrapper);
if (CollectionUtils.isNotEmpty(list)) {
numList.add(obj.getRowNum());
IcPartyUnitImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyUnitImportFailedExcel.class);
failed.setErrorInfo("单位名称已存在");
fileList.add(failed);
log.warn(String.format("单位名称已存在,行号->%s", obj.getRowNum()));
iterator.remove();
}
}
//分类校验
if (StringUtils.isBlank(obj.getType()) || null == PartyUnitTypeEnum.getCode(obj.getType())) {
numList.add(obj.getRowNum());
IcPartyUnitImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyUnitImportFailedExcel.class);
failed.setErrorInfo("分类名不存在");
fileList.add(failed);
log.warn(String.format("分类名不存在,行号->%s", obj.getRowNum()));
iterator.remove();
}
@ -354,62 +384,139 @@ public class IcPartyUnitServiceImpl extends BaseServiceImpl<IcPartyUnitDao, IcPa
List<String> matters = Arrays.asList(obj.getServiceMatter().split(StrConstant.COLON));
matters.forEach(item -> {
if (null == categoryMap.get(item)) {
numList.add(obj.getRowNum());
IcPartyUnitImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyUnitImportFailedExcel.class);
failed.setErrorInfo("服务事项不存在");
fileList.add(failed);
log.warn(String.format("服务事项不存在,行号->%s", obj.getRowNum()));
iterator.remove();
}
});
}
//联系人 联系电话 在职党员 地址 中心位置经度 中心位置纬度 校验
if (StringUtils.isBlank(obj.getContact()) || StringUtils.isBlank(obj.getContactMobile()) ||
StringUtils.isBlank(obj.getContact()) ||
null == obj.getMemberCount() ||
StringUtils.isBlank(obj.getLatitude()) ||
StringUtils.isBlank(obj.getLongitude())) {
numList.add(obj.getRowNum());
log.warn(String.format("联系人、联系电话、在职党员、地址、中心位置经度、中心位置纬度为空,行号->%s", obj.getRowNum()));
if (StringUtils.isBlank(obj.getContact())) {
IcPartyUnitImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyUnitImportFailedExcel.class);
failed.setErrorInfo("联系人为空");
fileList.add(failed);
log.warn(String.format("联系人为空,行号->%s", obj.getRowNum()));
iterator.remove();
} else if (StringUtils.isBlank(obj.getContactMobile())) {
IcPartyUnitImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyUnitImportFailedExcel.class);
failed.setErrorInfo("联系电话为空");
fileList.add(failed);
log.warn(String.format("联系电话为空,行号->%s", obj.getRowNum()));
} else if (StringUtils.isBlank(obj.getAddress())) {
IcPartyUnitImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyUnitImportFailedExcel.class);
failed.setErrorInfo("地址为空");
fileList.add(failed);
log.warn(String.format("地址为空,行号->%s", obj.getRowNum()));
} else if (null == obj.getMemberCount()) {
IcPartyUnitImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyUnitImportFailedExcel.class);
failed.setErrorInfo("在职党员为空");
fileList.add(failed);
log.warn(String.format("在职党员为空,行号->%s", obj.getRowNum()));
} else if (StringUtils.isBlank(obj.getLatitude())) {
IcPartyUnitImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyUnitImportFailedExcel.class);
failed.setErrorInfo("中心位置纬度为空");
fileList.add(failed);
log.warn(String.format("中心位置纬度为空,行号->%s", obj.getRowNum()));
} else if (StringUtils.isBlank(obj.getLongitude())) {
IcPartyUnitImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyUnitImportFailedExcel.class);
failed.setErrorInfo("中心位置经度为空");
fileList.add(failed);
log.warn(String.format("中心位置经度为空,行号->%s", obj.getRowNum()));
}
}
if (CollectionUtils.isEmpty(result)) {
Collections.sort(numList);
String subList = numList.stream().map(String::valueOf).collect(Collectors.joining("、"));
return new Result().error(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "第" + subList + "行未成功!");
}
List<IcPartyUnitEntity> list = result.stream().map(item -> {
IcPartyUnitEntity entity = new IcPartyUnitEntity();
entity.setCustomerId(tokenDto.getCustomerId());
entity.setAgencyId(staffInfoCache.getAgencyId());
entity.setPids(staffInfoCache.getAgencyPIds());
entity.setUnitName(item.getUnitName());
entity.setType(PartyUnitTypeEnum.getCode(item.getType()));
if (StringUtils.isNotBlank(item.getServiceMatter())) {
entity.setServiceMatter(getServiceMatter(categoryMap, item.getServiceMatter()));
}
entity.setContact(item.getContact());
entity.setContactMobile(item.getContactMobile());
entity.setAddress(item.getAddress());
entity.setLatitude(item.getLatitude());
entity.setLongitude(item.getLongitude());
entity.setMemberCount(item.getMemberCount());
entity.setRemark(item.getRemark());
return entity;
}).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(result)) {
List<IcPartyUnitEntity> list = result.stream().map(item -> {
IcPartyUnitEntity entity = new IcPartyUnitEntity();
entity.setCustomerId(tokenDto.getCustomerId());
entity.setAgencyId(staffInfoCache.getAgencyId());
entity.setPids(staffInfoCache.getAgencyPIds());
entity.setUnitName(item.getUnitName());
entity.setType(PartyUnitTypeEnum.getCode(item.getType()));
if (StringUtils.isNotBlank(item.getServiceMatter())) {
entity.setServiceMatter(getServiceMatter(categoryMap, item.getServiceMatter()));
}
entity.setContact(item.getContact());
entity.setContactMobile(item.getContactMobile());
entity.setAddress(item.getAddress());
entity.setLatitude(item.getLatitude());
entity.setLongitude(item.getLongitude());
entity.setMemberCount(item.getMemberCount());
entity.setRemark(item.getRemark());
return entity;
}).collect(Collectors.toList());
insertBatch(list);
insertBatch(list);
}
String str = String.format("共%s条,成功导入%s条。", numList.size() + result.size(), numList.size() + result.size() - numList.size());
if (numList.size() > NumConstant.ZERO) {
Collections.sort(numList);
String str = String.format("共%s条,成功导入%s条。", fileList.size() + result.size(), fileList.size() + result.size() - fileList.size());
if (fileList.size() > NumConstant.ZERO) {
List<Integer> numList = fileList.stream().map(IcPartyUnitImportFailedExcel::getRowNum).sorted().collect(Collectors.toList());
String subList = numList.stream().map(String::valueOf).collect(Collectors.joining("、"));
log.warn(str + "第" + subList + "行未成功!");
return new Result().error(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), str + "第" + subList + "行未成功!");
}
return new Result().ok(str);
//错误数据生成文件,修改导入任务状态
erroeImport(fileList, taskId, tokenDto.getUserId());
}
private void erroeImport(List<IcPartyUnitImportFailedExcel> fileList, String importTaskId, String staffId) throws IOException {
String url = "";
//1.有错误数据则生成错误数据存放文件传到阿里云服务
if (CollectionUtils.isNotEmpty(fileList)) {
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("导入失败的数据列表", "导入失败的数据列表"),
IcPartyUnitImportFailedExcel.class, fileList);
// 文件名
String resultDescFileName = UUID.randomUUID().toString().concat(".xlsx");
FileItemFactory factory = new DiskFileItemFactory(16, null);
FileItem fileItem = factory.createItem("file", ContentType.APPLICATION_OCTET_STREAM.toString(), true, resultDescFileName);
OutputStream os = fileItem.getOutputStream();
Result<UploadImgResultDTO> uploadResult = null;
try {
workbook.write(os);
uploadResult = ossFeignClient.uploadImportTaskDescFile(new CommonsMultipartFile(fileItem));
} catch (Exception e) {
String errormsg = ExceptionUtils.getErrorStackTrace(e);
log.error("【联建单位信息导入】上传错误描述文件:{}", errormsg);
} finally {
try {
os.close();
} catch (IOException e) {
String errormsg = ExceptionUtils.getErrorStackTrace(e);
log.error("【联建单位信息导入】上传错误描述文件关闭输出流:{}", errormsg);
}
try {
fileItem.delete();
} catch (Exception e) {
String errormsg = ExceptionUtils.getErrorStackTrace(e);
log.error("【联建单位信息导入】上传错误描述文件删除临时文件:{}", errormsg);
}
}
if (uploadResult == null || !uploadResult.success()) {
log.error("【联建单位信息导入】调用OSS上传结果描述文件失败");
} else {
url = uploadResult.getData().getUrl();
}
}
//2.更新导入任务数据
ImportTaskCommonFormDTO importTaskForm = new ImportTaskCommonFormDTO();
importTaskForm.setOperatorId(staffId);
importTaskForm.setBizType(ImportTaskConstants.BIZ_TYPE_PARTY_UNIT);
importTaskForm.setTaskId(importTaskId);
importTaskForm.setResultDescFilePath(url);
importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS);
if (CollectionUtils.isNotEmpty(fileList)) {
importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL);
importTaskForm.setResultDesc("联建单位导入存在错误数据");
}
Result result = commonServiceOpenFeignClient.finishImportTask(importTaskForm);
if (!result.success()) {
throw new RenException(result.getInternalMsg());
}
}
/**
* @param formDTO
* @Description 按类型统计单位数量

30
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/BuildingController.java

@ -25,20 +25,22 @@ import com.epmet.commons.tools.annotation.LoginUser;
import com.epmet.commons.tools.aop.NoRepeatSubmit;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.EpmetException;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.constant.ImportErrorMsgConstants;
import com.epmet.constants.ImportTaskConstants;
import com.epmet.dao.IcBuildingUnitDao;
import com.epmet.dto.BuildingTreeLevelDTO;
import com.epmet.dto.form.IcBulidingFormDTO;
import com.epmet.dto.form.IcBulidingUnitFormDTO;
import com.epmet.dto.form.ImportInfoFormDTO;
import com.epmet.dto.form.ListIcNeighborHoodFormDTO;
import com.epmet.dto.form.*;
import com.epmet.dto.result.BuildingResultDTO;
import com.epmet.dto.result.BuildingResultPagedDTO;
import com.epmet.dto.result.IcNeighborHoodResultDTO;
import com.epmet.dto.result.ImportTaskCommonResultDTO;
import com.epmet.entity.IcBuildingUnitEntity;
import com.epmet.excel.IcBuildingExcel;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.service.BuildingService;
import com.epmet.service.IcBuildingService;
import com.epmet.service.NeighborHoodService;
@ -66,17 +68,12 @@ import java.util.stream.Collectors;
@RequestMapping("building")
public class BuildingController {
@Autowired
private NeighborHoodService neighborHoodService;
@Autowired
private IcBuildingService icBuildingService;
@Autowired
private BuildingService buildingService;
@Autowired
private IcBuildingUnitDao icBuildingUnitDao;
@Autowired
private EpmetCommonServiceOpenFeignClient epmetCommonServiceOpenFeignClient;
@PostMapping("buildinglist")
@ -219,7 +216,16 @@ public class BuildingController {
formDTO.setOrgType(orgType);
formDTO.setOrgId(orgId);
formDTO.setUserId(tokenDTO.getUserId());
return buildingService.buildingImportExcel(formDTO,file);
ImportTaskCommonFormDTO importFormDTO = new ImportTaskCommonFormDTO();
importFormDTO.setBizType(ImportTaskConstants.BIZ_TYPE_BUILDING);
importFormDTO.setOperatorId(formDTO.getUserId());
importFormDTO.setOriginFileName(ImportErrorMsgConstants.BUILDING_ERROR_NAME);
Result<ImportTaskCommonResultDTO> importTask = epmetCommonServiceOpenFeignClient.createImportTask(importFormDTO);
if (!importTask.success()){
throw new EpmetException("当前存在上传任务");
}
buildingService.buildingImportExcel(formDTO,file,importTask);
return new Result();
}
/**

59
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseController.java

@ -50,15 +50,22 @@ import com.epmet.service.IcNeighborHoodService;
import com.epmet.util.ExcelPoiUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.tomcat.util.http.MimeHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
@ -83,8 +90,6 @@ public class HouseController implements ResultDataResolver {
@Autowired
private IcHouseRedis icHouseRedis;
@Autowired
private IcNeighborHoodService neighborHoodService;
@Autowired
private IcHouseService icHouseService;
@Autowired
private EpmetCommonServiceOpenFeignClient epmetCommonServiceOpenFeignClient;
@ -255,52 +260,22 @@ public class HouseController implements ResultDataResolver {
@PostMapping("houseimport")
public Result houseImport(@LoginUser TokenDto tokenDTO, @RequestParam("file") MultipartFile file,
@RequestParam("orgId")String orgId,
@RequestParam("orgType")String orgType){
@RequestParam("orgType")String orgType,HttpServletRequest multipartRequest){
ImportInfoFormDTO formDTO = new ImportInfoFormDTO();
formDTO.setCustomerId(tokenDTO.getCustomerId());
formDTO.setOrgType(orgType);
formDTO.setOrgId(orgId);
formDTO.setUserId(tokenDTO.getUserId());
ExcelReader excelReader = null;
try {
InputStream inputStream = null;
try {
inputStream = file.getInputStream();
} catch (IOException e) {
return new Result<String>().error("读取文件失败");
}
ImportTaskCommonFormDTO importFormDTO = new ImportTaskCommonFormDTO();
importFormDTO.setBizType(ImportTaskConstants.BIZ_TYPE_HOUSE);
importFormDTO.setOperatorId(formDTO.getUserId());
importFormDTO.setOriginFileName(ImportErrorMsgConstants.HOUSE_ERROR_NAME);
Result<ImportTaskCommonResultDTO> importTask = epmetCommonServiceOpenFeignClient.createImportTask(importFormDTO);
if (!importTask.success()){
throw new EpmetException("创建任务失败");
}
excelReader = EasyExcel.read(inputStream).build();
// 这里为了简单 所以注册了 同样的head 和Listener 自己使用功能必须不同的Listener
ReadSheet readSheet = EasyExcel.readSheet(0).head(HouseInfoModel.class)
.registerReadListener(new ImportHouseInfoListener(formDTO,icBuildingDao,icHouseRedis,neighborHoodService,icHouseService,epmetCommonServiceOpenFeignClient,importTask.getData().getTaskId()))
.build();
excelReader.read(readSheet);
} finally {
if (excelReader != null) {
excelReader.finish();
}
}
ImportResultDTO dto = icHouseRedis.getImportResultDTO(formDTO.getCustomerId(), formDTO.getUserId());
if (null == dto){
return new Result<>();
}
List<Integer> nums = dto.getNums();
Integer num = dto.getNum();
String s = "共%s条数据,导入成功%s条。";
if (nums.size() > NumConstant.ZERO){
Collections.sort(nums);
s = s + "第"+nums.stream().map(String::valueOf).collect(Collectors.joining("、"))+"条导入失败";
return new Result<>().error(9999,String.format(s,num,num - nums.size()));
ImportTaskCommonFormDTO importFormDTO = new ImportTaskCommonFormDTO();
importFormDTO.setBizType(ImportTaskConstants.BIZ_TYPE_HOUSE);
importFormDTO.setOperatorId(formDTO.getUserId());
importFormDTO.setOriginFileName(ImportErrorMsgConstants.HOUSE_ERROR_NAME);
Result<ImportTaskCommonResultDTO> importTask = epmetCommonServiceOpenFeignClient.createImportTask(importFormDTO);
if (!importTask.success()){
throw new EpmetException("当前存在上传任务");
}
return new Result<>().error(9999,String.format(s,num,num));
houseService.dispose(file,formDTO,importTask);
return new Result<>();
}
}

19
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/IcNeighborHoodController.java

@ -19,6 +19,7 @@ package com.epmet.controller;
import com.epmet.commons.tools.annotation.LoginUser;
import com.epmet.commons.tools.dto.result.OptionResultDTO;
import com.epmet.commons.tools.exception.EpmetException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.Result;
@ -27,8 +28,13 @@ import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.commons.tools.validator.group.AddGroup;
import com.epmet.commons.tools.validator.group.DefaultGroup;
import com.epmet.commons.tools.validator.group.UpdateGroup;
import com.epmet.constant.ImportErrorMsgConstants;
import com.epmet.constants.ImportTaskConstants;
import com.epmet.dto.IcNeighborHoodDTO;
import com.epmet.dto.form.ImportInfoFormDTO;
import com.epmet.dto.form.ImportTaskCommonFormDTO;
import com.epmet.dto.result.ImportTaskCommonResultDTO;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.service.IcNeighborHoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -51,6 +57,8 @@ public class IcNeighborHoodController {
@Autowired
private IcNeighborHoodService icNeighborHoodService;
@Autowired
private EpmetCommonServiceOpenFeignClient epmetCommonServiceOpenFeignClient;
@GetMapping("page")
public Result<PageData<IcNeighborHoodDTO>> page(@RequestParam Map<String, Object> params){
@ -128,7 +136,16 @@ public class IcNeighborHoodController {
formDTO.setOrgType(orgType);
formDTO.setOrgId(orgId);
formDTO.setUserId(tokenDTO.getUserId());
return icNeighborHoodService.neighborhoodImport(formDTO,file);
ImportTaskCommonFormDTO importFormDTO = new ImportTaskCommonFormDTO();
importFormDTO.setBizType(ImportTaskConstants.BIZ_TYPE_NEIGHBOR_HOOD);
importFormDTO.setOperatorId(formDTO.getUserId());
importFormDTO.setOriginFileName(ImportErrorMsgConstants.NEIGHBORHOOD_ERROR_NAME);
Result<ImportTaskCommonResultDTO> importTask = epmetCommonServiceOpenFeignClient.createImportTask(importFormDTO);
if (!importTask.success()){
throw new EpmetException("当前存在上传任务");
}
icNeighborHoodService.neighborhoodImport(formDTO,file,importTask);
return new Result();
}
}

3
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/BuildingService.java

@ -25,6 +25,7 @@ import com.epmet.dto.form.ListIcNeighborHoodFormDTO;
import com.epmet.dto.result.BuildingResultDTO;
import com.epmet.dto.result.BuildingResultPagedDTO;
import com.epmet.dto.result.IcNeighborHoodResultDTO;
import com.epmet.dto.result.ImportTaskCommonResultDTO;
import com.epmet.excel.IcBuildingExcel;
import org.springframework.web.multipart.MultipartFile;
@ -74,6 +75,6 @@ public interface BuildingService {
* @author zxc
* @date 2022/2/13 10:18 上午
*/
Result buildingImportExcel(ImportInfoFormDTO formDTO, MultipartFile file) throws IOException;
Result buildingImportExcel(ImportInfoFormDTO formDTO, MultipartFile file,Result<ImportTaskCommonResultDTO> importTask) throws IOException;
}

6
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/HouseService.java

@ -17,11 +17,15 @@
package com.epmet.service;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.form.IcHouseFormDTO;
import com.epmet.dto.form.ImportInfoFormDTO;
import com.epmet.dto.form.ListIcNeighborHoodFormDTO;
import com.epmet.dto.result.HouseInfoDTO;
import com.epmet.dto.result.IcNeighborHoodResultDTO;
import com.epmet.dto.result.ImportTaskCommonResultDTO;
import com.epmet.excel.IcHouseExcel;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
@ -62,4 +66,6 @@ public interface HouseService {
void exportBuildinginfo(ListIcNeighborHoodFormDTO formDTO, HttpServletResponse response) throws Exception;
List<HouseInfoDTO> queryListHouseInfo(Set<String> houseIds, String customerId);
Result dispose(MultipartFile file, ImportInfoFormDTO formDTO, Result<ImportTaskCommonResultDTO> importTask);
}

3
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcNeighborHoodService.java

@ -24,6 +24,7 @@ import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.IcNeighborHoodDTO;
import com.epmet.dto.ImportGeneralDTO;
import com.epmet.dto.form.ImportInfoFormDTO;
import com.epmet.dto.result.ImportTaskCommonResultDTO;
import com.epmet.entity.IcNeighborHoodEntity;
import com.epmet.entity.IcNeighborHoodPropertyEntity;
import com.epmet.entity.IcPropertyManagementEntity;
@ -128,7 +129,7 @@ public interface IcNeighborHoodService extends BaseService<IcNeighborHoodEntity>
* @author zxc
* @date 2022/2/12 11:11 上午
*/
Result neighborhoodImport(ImportInfoFormDTO formDTO, MultipartFile file) throws IOException;
void neighborhoodImport(ImportInfoFormDTO formDTO, MultipartFile file,Result<ImportTaskCommonResultDTO> importTask) throws IOException;
/**
* 获取导入小区楼栋单元ID

14
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/BuildingServiceImpl.java

@ -46,6 +46,8 @@ import com.epmet.util.ExcelPoiUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@ -61,6 +63,7 @@ import java.util.stream.Collectors;
@Slf4j
@Service
@EnableAsync
public class BuildingServiceImpl implements BuildingService {
@ -401,7 +404,8 @@ public class BuildingServiceImpl implements BuildingService {
* @date 2022/2/13 10:15 上午
*/
@Override
public Result buildingImportExcel(ImportInfoFormDTO formDTO, MultipartFile file) throws IOException {
@Async
public Result buildingImportExcel(ImportInfoFormDTO formDTO, MultipartFile file,Result<ImportTaskCommonResultDTO> importTask) throws IOException {
ExcelReader excelReader = null;
try {
InputStream inputStream = null;
@ -410,14 +414,6 @@ public class BuildingServiceImpl implements BuildingService {
} catch (IOException e) {
return new Result<String>().error("读取文件失败");
}
ImportTaskCommonFormDTO importFormDTO = new ImportTaskCommonFormDTO();
importFormDTO.setBizType(ImportTaskConstants.BIZ_TYPE_BUILDING);
importFormDTO.setOperatorId(formDTO.getUserId());
importFormDTO.setOriginFileName(ImportErrorMsgConstants.BUILDING_ERROR_NAME);
Result<ImportTaskCommonResultDTO> importTask = epmetCommonServiceOpenFeignClient.createImportTask(importFormDTO);
if (!importTask.success()){
throw new EpmetException("创建任务失败");
}
excelReader = EasyExcel.read(inputStream).build();
// 这里为了简单 所以注册了 同样的head 和Listener 自己使用功能必须不同的Listener
ReadSheet readSheet = EasyExcel.readSheet(0).head(BuildingInfoModel.class)

45
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/HouseServiceImpl.java

@ -2,6 +2,9 @@ package com.epmet.service.impl;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.epmet.commons.tools.constant.NumConstant;
@ -14,6 +17,7 @@ import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.feign.ResultDataResolver;
import com.epmet.commons.tools.redis.common.CustomerStaffRedis;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dao.IcBuildingDao;
import com.epmet.dao.IcBuildingUnitDao;
import com.epmet.dao.IcHouseDao;
@ -23,15 +27,20 @@ import com.epmet.dto.IcBuildingDTO;
import com.epmet.dto.IcBuildingUnitDTO;
import com.epmet.dto.IcHouseDTO;
import com.epmet.dto.form.IcHouseFormDTO;
import com.epmet.dto.form.ImportInfoFormDTO;
import com.epmet.dto.form.ListIcNeighborHoodFormDTO;
import com.epmet.dto.result.HouseInfoDTO;
import com.epmet.dto.result.IcNeighborHoodResultDTO;
import com.epmet.dto.result.ImportTaskCommonResultDTO;
import com.epmet.entity.IcHouseEntity;
import com.epmet.enums.HousePurposeEnums;
import com.epmet.enums.HouseRentFlagEnums;
import com.epmet.enums.HouseTypeEnums;
import com.epmet.excel.IcHouseExcel;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.feign.GovOrgOpenFeignClient;
import com.epmet.model.HouseInfoModel;
import com.epmet.model.ImportHouseInfoListener;
import com.epmet.redis.IcHouseRedis;
import com.epmet.service.HouseService;
import com.epmet.service.IcBuildingService;
@ -42,17 +51,23 @@ import com.epmet.util.ExcelPoiUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Service
@EnableAsync
public class HouseServiceImpl implements HouseService, ResultDataResolver {
@ -77,6 +92,11 @@ public class HouseServiceImpl implements HouseService, ResultDataResolver {
private IcHouseRedis icHouseRedis;
@Autowired
private AgencyService agencyservice;
@Autowired
private IcNeighborHoodService neighborHoodService;
@Autowired
private EpmetCommonServiceOpenFeignClient epmetCommonServiceOpenFeignClient;
@Override
@ -329,4 +349,29 @@ public class HouseServiceImpl implements HouseService, ResultDataResolver {
});
return result;
}
@Async
@Override
public Result dispose(MultipartFile file, ImportInfoFormDTO formDTO, Result<ImportTaskCommonResultDTO> importTask) {
ExcelReader excelReader = null;
try {
InputStream inputStream = null;
try {
inputStream = file.getInputStream();
} catch (IOException e) {
return new Result<String>().error("读取文件失败");
}
excelReader = EasyExcel.read(inputStream).build();
// 这里为了简单 所以注册了 同样的head 和Listener 自己使用功能必须不同的Listener
ReadSheet readSheet = EasyExcel.readSheet(0).head(HouseInfoModel.class)
.registerReadListener(new ImportHouseInfoListener(formDTO,icBuildingDao,icHouseRedis,neighborHoodService,icHouseService,epmetCommonServiceOpenFeignClient,importTask.getData().getTaskId()))
.build();
excelReader.read(readSheet);
} finally {
if (excelReader != null) {
excelReader.finish();
}
}
return new Result();
}
}

47
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcNeighborHoodServiceImpl.java

@ -73,6 +73,8 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.http.entity.ContentType;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
@ -93,6 +95,7 @@ import java.util.stream.Collectors;
*/
@Slf4j
@Service
@EnableAsync
public class IcNeighborHoodServiceImpl extends BaseServiceImpl<IcNeighborHoodDao, IcNeighborHoodEntity> implements IcNeighborHoodService {
@Autowired
@ -230,21 +233,9 @@ public class IcNeighborHoodServiceImpl extends BaseServiceImpl<IcNeighborHoodDao
* @date 2022/2/12 11:11 上午
*/
@Override
public Result neighborhoodImport(ImportInfoFormDTO formDTO, MultipartFile file) throws IOException {
/*ExcelImportResult<IcNeighborHoodExcel> importResult = ExcelPoiUtils.importExcelMore(file, 0, 1, IcNeighborHoodExcel.class);
List<IcNeighborHoodExcel> failList = importResult.getFailList();
//存放错误数据行号
List<Integer> numList = new ArrayList<>();
if(CollectionUtils.isNotEmpty(failList)){
for ( IcNeighborHoodExcel entity : failList) {
//打印失败的行 和失败的信息
log.error("第{}行,{}",entity.getRowNum(),entity.getErrorMsg());
numList.add(entity.getRowNum());
}
}
List<IcNeighborHoodExcel> result =importResult.getList();
return disposeImportNeighborhood(formDTO,result);*/
return importNeighbor(formDTO,file);
@Async
public void neighborhoodImport(ImportInfoFormDTO formDTO, MultipartFile file,Result<ImportTaskCommonResultDTO> importTask) throws IOException {
importNeighbor(formDTO,file,importTask);
}
/**
@ -407,7 +398,7 @@ public class IcNeighborHoodServiceImpl extends BaseServiceImpl<IcNeighborHoodDao
return new Result().ok(str);
}
public Result importNeighbor(ImportInfoFormDTO formDTO, MultipartFile file){
public Result importNeighbor(ImportInfoFormDTO formDTO, MultipartFile file,Result<ImportTaskCommonResultDTO> importTask){
ExcelReader excelReader = null;
try {
InputStream inputStream = null;
@ -416,14 +407,7 @@ public class IcNeighborHoodServiceImpl extends BaseServiceImpl<IcNeighborHoodDao
} catch (IOException e) {
return new Result<String>().error("读取文件失败");
}
ImportTaskCommonFormDTO importFormDTO = new ImportTaskCommonFormDTO();
importFormDTO.setBizType(ImportTaskConstants.BIZ_TYPE_NEIGHBOR_HOOD);
importFormDTO.setOperatorId(formDTO.getUserId());
importFormDTO.setOriginFileName(ImportErrorMsgConstants.NEIGHBORHOOD_ERROR_NAME);
Result<ImportTaskCommonResultDTO> importTask = epmetCommonServiceOpenFeignClient.createImportTask(importFormDTO);
if (!importTask.success()){
throw new EpmetException("创建任务失败");
}
excelReader = EasyExcel.read(inputStream).build();
// 这里为了简单 所以注册了 同样的head 和Listener 自己使用功能必须不同的Listener
ReadSheet readSheet = EasyExcel.readSheet(0).head(NeighborHoodInfoModel.class)
@ -435,19 +419,8 @@ public class IcNeighborHoodServiceImpl extends BaseServiceImpl<IcNeighborHoodDao
excelReader.finish();
}
}
ImportResultDTO dto = icHouseRedis.getImportResultDTO(formDTO.getCustomerId(), formDTO.getUserId());
if (null == dto){
return new Result<>();
}
List<Integer> nums = dto.getNums();
Integer num = dto.getNum();
String s = "共%s条数据,导入成功%s条。";
if (nums.size() > NumConstant.ZERO){
Collections.sort(nums);
s = s + "第"+nums.stream().map(String::valueOf).collect(Collectors.joining("、"))+"条导入失败";
return new Result<>().error(9999,String.format(s,num,num - nums.size()));
}
return new Result<>().error(9999,String.format(s,num,num));
return new Result<>();
}
/**

8
epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/controller/IcPartymemberStyleController.java

@ -17,6 +17,7 @@
package com.epmet.modules.partymember.controller;
import com.baomidou.mybatisplus.extension.api.R;
import com.epmet.commons.tools.annotation.LoginUser;
import com.epmet.commons.tools.aop.NoRepeatSubmit;
import com.epmet.commons.tools.constant.NumConstant;
@ -41,6 +42,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@ -124,7 +126,9 @@ public class IcPartymemberStyleController {
}
@PostMapping("import")
public void importData(@LoginUser TokenDto tokenDto, HttpServletResponse response, @RequestPart("file") MultipartFile file) throws IOException {
//service方法是异步的,需要事务注解加在被调用方 否则事务不起作用
@Transactional(rollbackFor = Exception.class)
public Result importData(@LoginUser TokenDto tokenDto, HttpServletResponse response, @RequestPart("file") MultipartFile file) throws IOException {
// 校验文件类型
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
if (!"xls".equals(extension) && !"xlsx".equals(extension)) {
@ -141,6 +145,8 @@ public class IcPartymemberStyleController {
}
//2.执行导入程序
icPartymemberStyleService.importData(tokenDto, response, file, result.getData().getTaskId());
return new Result();
}
/**

6
epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/service/impl/IcPartymemberStyleServiceImpl.java

@ -71,6 +71,8 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.http.entity.ContentType;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
@ -92,6 +94,7 @@ import java.util.stream.Collectors;
*/
@Slf4j
@Service
@EnableAsync
public class IcPartymemberStyleServiceImpl extends BaseServiceImpl<IcPartymemberStyleDao, IcPartymemberStyleEntity> implements IcPartymemberStyleService {
@Resource
@ -254,7 +257,8 @@ public class IcPartymemberStyleServiceImpl extends BaseServiceImpl<IcPartymember
* @Date 2021/11/29 11:01
*/
@Override
@Transactional(rollbackFor = Exception.class)
//@Transactional(rollbackFor = Exception.class)
@Async
public void importData(TokenDto tokenDto, HttpServletResponse response, MultipartFile file, String taskId) throws IOException {
List<PartyMemberImportExcel> fileList = new ArrayList<>();
PartyMemberImportExcel excel = null;

48
epmet-user/epmet-user-server/src/main/java/com/epmet/entity/ImportTaskEntity.java

@ -1,48 +0,0 @@
package com.epmet.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.epmet.commons.mybatis.entity.BaseEpmetEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
*
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2022-02-15
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("import_task")
public class ImportTaskEntity extends BaseEpmetEntity {
private static final long serialVersionUID = 1L;
/**
* 业务类型resi:居民楼栋:building房屋:house依次补充
*/
private String bizType;
/**
* 处理状态processing:处理中finished:完成
*/
private String processStatus;
/**
* 谁导入的
*/
private String operatorId;
/**
* 开始导入的时间
*/
private Date startTime;
private String resultDescFile;
private String resultDesc;
}
Loading…
Cancel
Save