diff --git a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java
index c67ddbb549..82e25887b7 100644
--- a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java
+++ b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java
@@ -11,6 +11,8 @@ public interface ImportTaskConstants {
String BIZ_TYPE_NEIGHBOR_HOOD = "neighborHood";
String BIZ_TYPE_BUILDING = "building";
String BIZ_TYPE_HOUSE = "house";
+ String BIZ_TYPE_PARTY_MEMBER = "party_member";
+ String BIZ_TYPE_COMMUNITY_SELF_ORG = "community_self_org";
/**
* 处理状态:处理中
diff --git a/epmet-module/epmet-heart/epmet-heart-server/pom.xml b/epmet-module/epmet-heart/epmet-heart-server/pom.xml
index ba92a6d321..5bc910e846 100644
--- a/epmet-module/epmet-heart/epmet-heart-server/pom.xml
+++ b/epmet-module/epmet-heart/epmet-heart-server/pom.xml
@@ -94,6 +94,18 @@
epmet-commons-rocketmq
2.0.0
+
+ com.epmet
+ common-service-client
+ 2.0.0
+ compile
+
+
+ com.epmet
+ epmet-oss-client
+ 2.0.0
+ compile
+
diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcCommunitySelfOrganizationController.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcCommunitySelfOrganizationController.java
index 5dc6a27d04..94fd66386b 100644
--- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcCommunitySelfOrganizationController.java
+++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcCommunitySelfOrganizationController.java
@@ -34,14 +34,17 @@ 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.constants.ImportTaskConstants;
import com.epmet.dto.IcCommunitySelfOrganizationDTO;
import com.epmet.dto.form.*;
import com.epmet.dto.form.demand.ServiceQueryFormDTO;
import com.epmet.dto.result.CommunitySelfOrganizationListResultDTO;
+import com.epmet.dto.result.ImportTaskCommonResultDTO;
import com.epmet.dto.result.demand.OptionDTO;
import com.epmet.excel.ExportCommunitySelfOrganizationExcel;
import com.epmet.excel.IcCommunitySelfOrganizationExcel;
import com.epmet.excel.ImportCommunitySelfOrganizationSon;
+import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.service.IcCommunitySelfOrganizationService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FilenameUtils;
@@ -66,6 +69,8 @@ public class IcCommunitySelfOrganizationController {
@Autowired
private IcCommunitySelfOrganizationService icCommunitySelfOrganizationService;
+ @Autowired
+ private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient;
@GetMapping("page")
public Result> page(@RequestParam Map params){
@@ -138,7 +143,7 @@ public class IcCommunitySelfOrganizationController {
* @date 2021/11/25 9:03 上午
*/
@PostMapping("importcommunityselforganization")
- public Result importCommunitySelfOrganization(@LoginUser TokenDto tokenDto, HttpServletResponse response, @RequestPart("file") MultipartFile file) throws Exception {
+ public void importCommunitySelfOrganization(@LoginUser TokenDto tokenDto, HttpServletResponse response, @RequestPart("file") MultipartFile file) throws Exception {
if (file.isEmpty()) {
throw new RenException("请上传文件");
}
@@ -148,8 +153,17 @@ public class IcCommunitySelfOrganizationController {
if (!"xls".equals(extension) && !"xlsx".equals(extension)) {
throw new RenException("文件类型不匹配");
}
- icCommunitySelfOrganizationService.importCommunitySelfOrganization(tokenDto, response, file);
- return new Result();
+ //1.查询当前工作人员是否有再导入的党员先锋数据,有则不允许导入,没有则进行新的导入
+ ImportTaskCommonFormDTO importTaskForm = new ImportTaskCommonFormDTO();
+ importTaskForm.setOriginFileName(file.getOriginalFilename());
+ importTaskForm.setOperatorId(tokenDto.getUserId());
+ importTaskForm.setBizType(ImportTaskConstants.BIZ_TYPE_COMMUNITY_SELF_ORG);
+ Result result = commonServiceOpenFeignClient.createImportTask(importTaskForm);
+ if (!result.success()) {
+ throw new RenException(result.getInternalMsg());
+ }
+ //2.执行导入程序
+ icCommunitySelfOrganizationService.importCommunitySelfOrganization(tokenDto, response, file, result.getData().getTaskId());
}
/**
diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/IcCommunitySelfOrganizationDao.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/IcCommunitySelfOrganizationDao.java
index efc9881b2a..e8fc375773 100644
--- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/IcCommunitySelfOrganizationDao.java
+++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/IcCommunitySelfOrganizationDao.java
@@ -18,6 +18,7 @@
package com.epmet.dao;
import com.epmet.commons.mybatis.dao.BaseDao;
+import com.epmet.dto.IcCommunitySelfOrganizationDTO;
import com.epmet.dto.form.CommunitySelfOrganizationListFormDTO;
import com.epmet.dto.result.CommunitySelfOrganizationListDTO;
import com.epmet.dto.result.demand.OptionDTO;
@@ -63,5 +64,5 @@ public interface IcCommunitySelfOrganizationDao extends BaseDao selectOrgByOrgName(@Param("names")List names, @Param("customerId") String customerId);
-
+ List selectOrgByCustomerId(@Param("customerId") String customerId);
}
\ No newline at end of file
diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/IcCommunitySelfOrganizationService.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/IcCommunitySelfOrganizationService.java
index 9f8c8f4682..ab97e36e84 100644
--- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/IcCommunitySelfOrganizationService.java
+++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/IcCommunitySelfOrganizationService.java
@@ -157,7 +157,7 @@ public interface IcCommunitySelfOrganizationService extends BaseService queryListById(List communityOrgIds);
}
\ No newline at end of file
diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java
index 5176518aa2..663461c62c 100644
--- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java
+++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java
@@ -1,5 +1,7 @@
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.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -12,6 +14,7 @@ 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.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.CustomerOrgRedis;
@@ -21,37 +24,49 @@ import com.epmet.commons.tools.security.dto.TokenDto;
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.commons.tools.validator.PhoneValidatorUtils;
import com.epmet.constant.IcCommunitySelfOrganizationConstant;
import com.epmet.constant.UserDemandConstant;
+import com.epmet.constants.ImportTaskConstants;
import com.epmet.dao.IcCommunitySelfOrganizationDao;
import com.epmet.dto.IcCommunitySelfOrganizationDTO;
-import com.epmet.dto.form.AddCommunitySelfOrganizationFormDTO;
-import com.epmet.dto.form.CommunitySelfOrganizationListFormDTO;
-import com.epmet.dto.form.DelCommunitySelfOrganizationFormDTO;
-import com.epmet.dto.form.EditCommunitySelfOrganizationFormDTO;
+import com.epmet.dto.form.*;
import com.epmet.dto.form.demand.ServiceQueryFormDTO;
import com.epmet.dto.result.CommunitySelfOrganizationListDTO;
import com.epmet.dto.result.CommunitySelfOrganizationListResultDTO;
+import com.epmet.dto.result.UploadImgResultDTO;
import com.epmet.dto.result.demand.OptionDTO;
import com.epmet.entity.IcCommunitySelfOrganizationEntity;
import com.epmet.entity.IcCommunitySelfOrganizationPersonnelEntity;
+import com.epmet.excel.CommunitySelfOrgImportExcel;
import com.epmet.excel.ImportCommunitySelfOrganization;
+import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
+import com.epmet.feign.OssFeignClient;
import com.epmet.service.IcCommunitySelfOrganizationPersonnelService;
import com.epmet.service.IcCommunitySelfOrganizationService;
import com.epmet.service.IcUserDemandRecService;
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.beans.factory.annotation.Autowired;
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.servlet.http.HttpServletResponse;
import java.io.IOException;
+import java.io.OutputStream;
import java.util.*;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
@@ -64,12 +79,17 @@ import static com.epmet.commons.tools.utils.DateUtils.DATE_PATTERN;
* @since v1.0.0 2021-11-18
*/
@Service
+@Slf4j
public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl implements IcCommunitySelfOrganizationService {
@Autowired
private IcCommunitySelfOrganizationPersonnelService personnelService;
@Autowired
private IcUserDemandRecService icUserDemandRecService;
+ @Autowired
+ private OssFeignClient ossFeignClient;
+ @Autowired
+ private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient;
@Override
public PageData page(Map params) {
@@ -362,9 +382,9 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl testExcelImportResult = ExcelPoiUtils.importExcelMore(file, 0, 2, ImportCommunitySelfOrganization.class);
List list = testExcelImportResult.getList();
@@ -446,6 +466,172 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl fileList = new ArrayList<>();
+ CommunitySelfOrgImportExcel excel = null;
+ //1.读取Excel数据
+ ExcelImportResult testExcelImportResult = ExcelPoiUtils.importExcelMore(file, 0, 2, ImportCommunitySelfOrganization.class);
+ //2.存在错误行数据时存入错误数据集合中
+ for (ImportCommunitySelfOrganization entity : testExcelImportResult.getFailList()) {
+ //打印失败的行 和失败的信息
+ log.warn("第{}行,{}", entity.getRowNum(), entity.getErrorMsg());
+ excel = new CommunitySelfOrgImportExcel();
+ excel.setAgencyName(entity.getOrganizationName());
+ excel.setSocietyName(entity.getOrganizationName());
+ excel.setErrorInfo(entity.getErrorMsg());
+ fileList.add(excel);
+ }
+ //正确行数据集合
+ List list = testExcelImportResult.getList();
+ if (CollectionUtils.isNotEmpty(list)){
+ //3.分别判断导入数据是否是当前组织下数据、社会自组织名称是否已存在、手机号是否规范
+ //3-1.查询当前组织下已从存在的社会自组织名称
+ CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId());
+ //查询当前组织下的社会自组织数据
+ List communitySeltOrgList = baseDao.selectOrgByCustomerId(tokenDto.getCustomerId());
+ //组织信息
+ AgencyInfoCache agencyInfo = CustomerOrgRedis.getAgencyInfo(staffInfoCache.getAgencyId());
+ //3-2.检验数据,把不允许导入的数据剔除
+ Iterator iterator = list.iterator();
+ while (iterator.hasNext()) {
+ AtomicBoolean bl = new AtomicBoolean(false);
+ StringBuffer errMsg = new StringBuffer("");
+ ImportCommunitySelfOrganization obj = iterator.next();
+ //社会自组织名称重复
+ communitySeltOrgList.forEach(org -> {
+ if (obj.getOrganizationName().equals(org.getOrganizationName())) {
+ log.warn(String.format("当前客户下的社会自组织名称已存在,社会自组织名称->%s,行号->%s", obj.getOrganizationName(), obj.getRowNum()));
+ errMsg.append("客户下社会自组织名称已存在;");
+ bl.set(true);
+ }
+ });
+ //手机号不合规
+ boolean m = PhoneValidatorUtils.isMobile(obj.getPrincipalPhone());
+ boolean t = PhoneValidatorUtils.isTel(obj.getPrincipalPhone());
+ if (!m && !t){
+ errMsg.append("手机号码不合法;");
+ bl.set(true);
+ }
+ if(bl.get()){
+ excel = new CommunitySelfOrgImportExcel();
+ excel.setAgencyName(obj.getOrganizationName());
+ excel.setSocietyName(obj.getOrganizationName());
+ excel.setErrorInfo(errMsg.toString());
+ fileList.add(excel);
+ iterator.remove();
+ }
+ }
+
+ list.forEach(l -> {
+ IcCommunitySelfOrganizationEntity e = ConvertUtils.sourceToTarget(l, IcCommunitySelfOrganizationEntity.class);
+ e.setCustomerId(tokenDto.getCustomerId());
+ e.setOrgId(agencyInfo.getId());
+ e.setOrgType(IcCommunitySelfOrganizationConstant.ORG_TYPE_AGENCY);
+ e.setPid(agencyInfo.getPid());
+ e.setPids(agencyInfo.getPids());
+ e.setOrganizationCreatedTime(l.getOrganizationCreatedTime());
+ baseDao.insert(e);
+ if (CollectionUtils.isNotEmpty(l.getPersons())){
+ l.getPersons().forEach(p -> {
+ boolean m = PhoneValidatorUtils.isMobile(p.getPersonPhone());
+ boolean t = PhoneValidatorUtils.isTel(p.getPersonPhone());
+ if (!m && !t){
+ throw new EpmetException(EpmetErrorCode.CHECK_PHONE_ERROR.getCode());
+ }
+ });
+ List persons = ConvertUtils.sourceToTarget(l.getPersons(), IcCommunitySelfOrganizationPersonnelEntity.class);
+ Map> groupByPhone = persons.stream().collect(Collectors.groupingBy(IcCommunitySelfOrganizationPersonnelEntity::getPersonPhone));
+ List phones = new ArrayList<>();
+ groupByPhone.forEach((k,v) -> {
+ if (v.size() > NumConstant.ONE){
+ phones.add(k);
+ }
+ });
+ if (CollectionUtils.isNotEmpty(phones)){
+ StringBuffer sb = new StringBuffer();
+ phones.forEach(p -> {
+ sb.append(p).append(",");
+ });
+ String copywriter = sb.toString().substring(NumConstant.ZERO, sb.length() - NumConstant.ONE);
+ EpmetErrorCode.EXISTS_SAME_PHONE_ERROR.setMsg(String.format(EpmetErrorCode.EXISTS_SAME_PHONE_ERROR.getMsg(),copywriter));
+ throw new RenException(EpmetErrorCode.EXISTS_SAME_PHONE_ERROR.getCode());
+ }
+ persons.forEach(p -> {
+ p.setCustomerId(tokenDto.getCustomerId());
+ p.setOrgId(e.getId());
+ });
+ personnelService.insertBatch(persons);
+ }
+ });
+ }
+ //4.错误数据生成文件,修改导入任务状态
+ erroeImport(fileList, taskId, tokenDto.getUserId());
+ }
+ /**
+ * @Author sun
+ * @Description 社会自组织导入导入,错误数据生成导入失败文件存到阿里云,修改导入任务为已结束
+ **/
+ private void erroeImport(List fileList, String importTaskId, String staffId) throws IOException {
+ String url = "";
+ //1.有错误数据则生成错误数据存放文件传到阿里云服务
+ if (!org.springframework.util.CollectionUtils.isEmpty(fileList)) {
+ Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("导入失败的数据列表", "导入失败的数据列表"),
+ CommunitySelfOrgImportExcel.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 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上传结果描述文件失败");
+ }
+ url = uploadResult.getData().getUrl();
+ }
+ //2.更新导入任务数据
+ ImportTaskCommonFormDTO importTaskForm = new ImportTaskCommonFormDTO();
+ importTaskForm.setOperatorId(staffId);
+ importTaskForm.setBizType(ImportTaskConstants.BIZ_TYPE_PARTY_MEMBER);
+ importTaskForm.setTaskId(importTaskId);
+ importTaskForm.setResultDescFilePath(url);
+ importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS);
+ if (StringUtils.isNotBlank(url)) {
+ importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL);
+ importTaskForm.setResultDesc("社会自组织导入存在错误数据");
+ }
+ Result result = commonServiceOpenFeignClient.finishImportTask(importTaskForm);
+ if (!result.success()) {
+ throw new RenException(result.getInternalMsg());
+ }
+ }
@Override
public List queryListById(List communityOrgIds) {
diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/IcCommunitySelfOrganizationDao.xml b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/IcCommunitySelfOrganizationDao.xml
index fc1a118ced..d2575e0af0 100644
--- a/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/IcCommunitySelfOrganizationDao.xml
+++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/IcCommunitySelfOrganizationDao.xml
@@ -97,4 +97,18 @@
#{n}
+
+
+
\ No newline at end of file
diff --git a/epmet-module/resi-partymember/resi-partymember-server/pom.xml b/epmet-module/resi-partymember/resi-partymember-server/pom.xml
index 4c7c11b2fd..462586a0b6 100644
--- a/epmet-module/resi-partymember/resi-partymember-server/pom.xml
+++ b/epmet-module/resi-partymember/resi-partymember-server/pom.xml
@@ -93,6 +93,18 @@
2.0.0
compile
+
+ com.epmet
+ common-service-client
+ 2.0.0
+ compile
+
+
+ com.epmet
+ epmet-oss-client
+ 2.0.0
+ compile
+
diff --git a/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/controller/IcPartymemberStyleController.java b/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/controller/IcPartymemberStyleController.java
index ee3a025d13..4f41645000 100644
--- a/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/controller/IcPartymemberStyleController.java
+++ b/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/controller/IcPartymemberStyleController.java
@@ -20,6 +20,7 @@ package com.epmet.modules.partymember.controller;
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.RenException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.ExcelUtils;
@@ -27,6 +28,10 @@ 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.form.ImportTaskCommonFormDTO;
+import com.epmet.dto.result.ImportTaskCommonResultDTO;
+import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.modules.partymember.excel.IcPartymemberStyleExcel;
import com.epmet.modules.partymember.service.IcPartymemberStyleService;
import com.epmet.resi.partymember.dto.partymember.IcPartymemberStyleDTO;
@@ -34,6 +39,7 @@ import com.epmet.resi.partymember.dto.partymember.form.PartyMemberStyleFormDTO;
import com.epmet.resi.partymember.dto.partymember.form.StyleShowListFormDTO;
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;
@@ -60,6 +66,8 @@ public class IcPartymemberStyleController {
@Autowired
private IcPartymemberStyleService icPartymemberStyleService;
+ @Autowired
+ private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient;
@GetMapping("page")
public Result> page(@RequestParam Map params){
@@ -116,8 +124,23 @@ public class IcPartymemberStyleController {
}
@PostMapping("import")
- public Result importData(@LoginUser TokenDto tokenDto, HttpServletResponse response, @RequestPart("file") MultipartFile file) throws IOException {
- return icPartymemberStyleService.importData(tokenDto, response, file);
+ public void 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)) {
+ throw new RenException("文件类型不匹配");
+ }
+ //1.查询当前工作人员是否有再导入的党员先锋数据,有则不允许导入,没有则进行新的导入
+ ImportTaskCommonFormDTO importTaskForm = new ImportTaskCommonFormDTO();
+ importTaskForm.setOriginFileName(file.getOriginalFilename());
+ importTaskForm.setOperatorId(tokenDto.getUserId());
+ importTaskForm.setBizType(ImportTaskConstants.BIZ_TYPE_PARTY_MEMBER);
+ Result result = commonServiceOpenFeignClient.createImportTask(importTaskForm);
+ if (!result.success()) {
+ throw new RenException(result.getInternalMsg());
+ }
+ //2.执行导入程序
+ icPartymemberStyleService.importData(tokenDto, response, file, result.getData().getTaskId());
}
/**
diff --git a/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/service/IcPartymemberStyleService.java b/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/service/IcPartymemberStyleService.java
index 1baf248479..533cb59262 100644
--- a/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/service/IcPartymemberStyleService.java
+++ b/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/service/IcPartymemberStyleService.java
@@ -108,7 +108,7 @@ public interface IcPartymemberStyleService extends BaseService page(Map params) {
@@ -233,7 +255,9 @@ public class IcPartymemberStyleServiceImpl extends BaseServiceImpl fileList = new ArrayList<>();
+ PartyMemberImportExcel excel = null;
ExcelImportResult importResult = ExcelPoiUtils.importExcelMore(file, 0, 1, IcPartymemberStyleImportExcel.class);
List failList = importResult.getFailList();
@@ -244,6 +268,13 @@ public class IcPartymemberStyleServiceImpl extends BaseServiceImpl result = importResult.getList();
@@ -267,19 +298,35 @@ public class IcPartymemberStyleServiceImpl extends BaseServiceImpl%s,行号->%s", obj.getGridName(), obj.getRowNum()));
+ excel = new PartyMemberImportExcel();
+ excel.setGridName(obj.getGridName());
+ excel.setName(obj.getName());
+ excel.setMainDeed(obj.getMainDeed());
+ excel.setCategoryName(obj.getCategoryName());
+ excel.setErrorInfo("不是当前组织下网格");
+ fileList.add(excel);
iterator.remove();
continue;
}
if (null == categoryDictMap.get(obj.getCategoryName().trim())) {
numList.add(obj.getRowNum());
log.warn(String.format("分类名称【%s】不存在,不可导入,行号->%s", obj.getCategoryName(), obj.getRowNum()));
+ excel = new PartyMemberImportExcel();
+ excel.setGridName(obj.getGridName());
+ excel.setName(obj.getName());
+ excel.setMainDeed(obj.getMainDeed());
+ excel.setCategoryName(obj.getCategoryName());
+ excel.setErrorInfo("分类名称不存在");
+ fileList.add(excel);
iterator.remove();
}
}
if (CollectionUtils.isEmpty(result)) {
- Collections.sort(numList);
+ /*Collections.sort(numList);
String subList = numList.stream().map(String::valueOf).collect(Collectors.joining("、"));
- return new Result().error(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "第" + subList + "行未成功!");
+ return new Result().error(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "第" + subList + "行未成功!");*/
+ erroeImport(fileList, taskId, tokenDto.getUserId());
+ return;
}
List imageList = new ArrayList<>();
List list = result.stream().map(item -> {
@@ -304,14 +351,75 @@ public class IcPartymemberStyleServiceImpl extends BaseServiceImpl NumConstant.ZERO) {
Collections.sort(numList);
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);
+ return new Result().ok(str);*/
+ erroeImport(fileList, taskId, tokenDto.getUserId());
+ }
+
+ /**
+ * @Author sun
+ * @Description 党员风采导入,错误数据生成导入失败文件,修改导入任务为已结束
+ **/
+ private void erroeImport(List fileList, String importTaskId, String staffId) throws IOException {
+ String url = "";
+ //1.有错误数据则生成错误数据存放文件传到阿里云服务
+ if (!org.springframework.util.CollectionUtils.isEmpty(fileList)) {
+ Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("导入失败的数据列表", "导入失败的数据列表"),
+ PartyMemberImportExcel.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 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上传结果描述文件失败");
+ }
+ url = uploadResult.getData().getUrl();
+ }
+ //2.更新导入任务数据
+ ImportTaskCommonFormDTO importTaskForm = new ImportTaskCommonFormDTO();
+ importTaskForm.setOperatorId(staffId);
+ importTaskForm.setBizType(ImportTaskConstants.BIZ_TYPE_PARTY_MEMBER);
+ importTaskForm.setTaskId(importTaskId);
+ importTaskForm.setResultDescFilePath(url);
+ importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS);
+ if (StringUtils.isNotBlank(url)) {
+ importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL);
+ importTaskForm.setResultDesc("党员风采导入存在错误数据");
+ }
+ Result result = commonServiceOpenFeignClient.finishImportTask(importTaskForm);
+ if (!result.success()) {
+ throw new RenException(result.getInternalMsg());
+ }
}
/**