From 0fd46d97c6e498d70c058ab4eeaa74efd2a11d01 Mon Sep 17 00:00:00 2001 From: zhaoqifeng Date: Fri, 25 Feb 2022 17:19:31 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=81=94=E5=BB=BA=E5=8D=95=E4=BD=8D?= =?UTF-8?q?=E5=92=8C=E8=81=94=E5=BB=BA=E6=B4=BB=E5=8A=A8=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/constants/ImportTaskConstants.java | 2 + .../controller/IcPartyActivityController.java | 66 ++++- .../controller/IcPartyUnitController.java | 77 +++++- .../IcPartyActivityImportFailedExcel.java | 38 +++ .../excel/IcPartyUnitImportFailedExcel.java | 38 +++ .../epmet/service/IcPartyActivityService.java | 3 +- .../com/epmet/service/IcPartyUnitService.java | 3 +- .../impl/IcPartyActivityServiceImpl.java | 261 +++++++++++++----- .../service/impl/IcPartyUnitServiceImpl.java | 197 ++++++++++--- 9 files changed, 559 insertions(+), 126 deletions(-) create mode 100644 epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/IcPartyActivityImportFailedExcel.java create mode 100644 epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/IcPartyUnitImportFailedExcel.java 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 82e25887b7..6212a35cb6 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 @@ -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"; /** * 处理状态:处理中 diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcPartyActivityController.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcPartyActivityController.java index 5071fd8710..75de3a06d6 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcPartyActivityController.java +++ b/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> 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 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()); + } + } } /** diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcPartyUnitController.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcPartyUnitController.java index 5aaf4863fb..817e1657a9 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcPartyUnitController.java +++ b/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> 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 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()); + } + } + } } \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/IcPartyActivityImportFailedExcel.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/IcPartyActivityImportFailedExcel.java new file mode 100644 index 0000000000..7ee7a96358 --- /dev/null +++ b/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 + *

+ * 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. + *

+ * 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. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +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; +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/IcPartyUnitImportFailedExcel.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/IcPartyUnitImportFailedExcel.java new file mode 100644 index 0000000000..2cd7e44e2a --- /dev/null +++ b/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 + *

+ * 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. + *

+ * 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. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +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; +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/IcPartyActivityService.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/IcPartyActivityService.java index c36db9b2d6..6fe8225b11 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/IcPartyActivityService.java +++ b/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 { * @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 按类型统计单位数量 diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcPartyActivityServiceImpl.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcPartyActivityServiceImpl.java index 503466278a..b72739dbbc 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcPartyActivityServiceImpl.java +++ b/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 fileList = new ArrayList<>(); ExcelImportResult importResult = ExcelPoiUtils.importExcelMore(file, 0, 1, IcPartyActivityImportExcel.class); List failList = importResult.getFailList(); //存放错误数据行号 - List 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 result = importResult.getList(); @@ -262,14 +283,18 @@ public class IcPartyActivityServiceImpl extends BaseServiceImpl%s", obj.getRowNum())); iterator.remove(); } else { List 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%s", obj.getRowNum())); iterator.remove(); } else { List 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%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 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 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 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 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 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 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 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()); + } } /** diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcPartyUnitServiceImpl.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcPartyUnitServiceImpl.java index 2849e6ae42..3924261510 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcPartyUnitServiceImpl.java +++ b/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 search(PartyUnitFormDTO formDTO) { @@ -303,16 +324,19 @@ public class IcPartyUnitServiceImpl extends BaseServiceImpl fileList = new ArrayList<>(); + ExcelImportResult importResult = ExcelPoiUtils.importExcelMore(file, 0, 1, IcPartyUnitImportExcel.class); List failList = importResult.getFailList(); //存放错误数据行号 - List 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 result = importResult.getList(); @@ -329,7 +353,9 @@ public class IcPartyUnitServiceImpl extends BaseServiceImpl%s", obj.getRowNum())); iterator.remove(); } else { @@ -338,14 +364,18 @@ public class IcPartyUnitServiceImpl extends BaseServiceImpl 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 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 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 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 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 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 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 按类型统计单位数量 From 73ff7a02e6fa28586dcdde625c99da35c053031f Mon Sep 17 00:00:00 2001 From: sunyuchao Date: Mon, 28 Feb 2022 11:50:57 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=AE=AE=E9=A2=98=E8=BD=AC=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=20=E5=88=86=E5=B8=83=E5=BC=8F=E9=94=81=20=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/dto/form/ShiftProjectFormDTO.java | 4 ++++ .../controller/IssueManageController.java | 1 + .../epmet/service/impl/IssueServiceImpl.java | 24 +++++++++---------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/epmet-module/gov-issue/gov-issue-client/src/main/java/com/epmet/dto/form/ShiftProjectFormDTO.java b/epmet-module/gov-issue/gov-issue-client/src/main/java/com/epmet/dto/form/ShiftProjectFormDTO.java index b44cdb4acd..adb4ed7409 100644 --- a/epmet-module/gov-issue/gov-issue-client/src/main/java/com/epmet/dto/form/ShiftProjectFormDTO.java +++ b/epmet-module/gov-issue/gov-issue-client/src/main/java/com/epmet/dto/form/ShiftProjectFormDTO.java @@ -52,6 +52,10 @@ public class ShiftProjectFormDTO implements Serializable { * 议题标签 */ private List tagList; + /** + * token中客户Id + */ + private String customerId; } diff --git a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/controller/IssueManageController.java b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/controller/IssueManageController.java index 1c522d1afb..a77e531b26 100644 --- a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/controller/IssueManageController.java +++ b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/controller/IssueManageController.java @@ -181,6 +181,7 @@ public class IssueManageController { @PostMapping("shiftproject-v2") public Result shiftProjectV2(@LoginUser TokenDto tokenDTO, @RequestBody ShiftProjectFormDTO formDTO) { formDTO.setStaffId(tokenDTO.getUserId()); + formDTO.setCustomerId(tokenDTO.getCustomerId()); ValidatorUtils.validateEntity(formDTO); return issueService.shiftProjectV2(formDTO); } diff --git a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueServiceImpl.java b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueServiceImpl.java index cebca254d9..379eaf6444 100644 --- a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueServiceImpl.java +++ b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueServiceImpl.java @@ -964,25 +964,25 @@ public class IssueServiceImpl extends BaseServiceImpl imp public Result shiftProjectV2(ShiftProjectFormDTO formDTO) { RLock lock = null; try { - // 锁持有10分钟,等待10s - lock = distributedLock.tryLock(formDTO.getIssueId()); + //获取锁,判断当前议题是否已处理 + lock = distributedLock.tryLock(formDTO.getCustomerId() + formDTO.getIssueId()); //1:查询议题数据 IssueEntity entity = baseDao.selectById(formDTO.getIssueId()); if (null == entity) { - throw new RenException(IssueConstant.SELECT_EXCEPTION); + throw new EpmetException(9999,IssueConstant.SELECT_EXCEPTION,IssueConstant.SELECT_EXCEPTION); } if (IssueConstant.ISSUE_SHIFT_PROJECT.equals(entity.getIssueStatus())) { - throw new RenException(IssueConstant.ISSUE_SHIFT_PROJECT_EXCEPTION); + throw new EpmetException(9999,IssueConstant.ISSUE_SHIFT_PROJECT_EXCEPTION,IssueConstant.ISSUE_SHIFT_PROJECT_EXCEPTION); } if (!IssueConstant.ISSUE_VOTING.equals(entity.getIssueStatus())) { - throw new RenException(IssueConstant.ISSUE_VOTING_EXCEPTION); + throw new EpmetException(9999,IssueConstant.ISSUE_VOTING_EXCEPTION,IssueConstant.ISSUE_VOTING_EXCEPTION); } formDTO.setIssueDTO(ConvertUtils.sourceToTarget(entity, IssueDTO.class)); //获取议题分类 List categoryList = issueCategoryService.getCategoryByIssue(formDTO.getIssueId()); if (CollectionUtils.isEmpty(categoryList)) { - throw new RenException(EpmetErrorCode.CATEGORY_IS_NULL.getCode()); + throw new EpmetException(EpmetErrorCode.CATEGORY_IS_NULL.getCode(),EpmetErrorCode.CATEGORY_IS_NULL.getMsg(),EpmetErrorCode.CATEGORY_IS_NULL.getMsg()); } //公开回复内容审核 @@ -994,10 +994,10 @@ public class IssueServiceImpl extends BaseServiceImpl imp textScanParamDTO.getTasks().add(taskDTO); Result textSyncScanResult = ScanContentUtils.textSyncScan(scanApiUrl.concat(textSyncScanMethod), textScanParamDTO); if (!textSyncScanResult.success()) { - throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); + throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(),EpmetErrorCode.SERVER_ERROR.getMsg(),EpmetErrorCode.SERVER_ERROR.getMsg()); } else { if (!textSyncScanResult.getData().isAllPass()) { - throw new RenException(EpmetErrorCode.TEXT_SCAN_FAILED.getCode()); + throw new EpmetException(EpmetErrorCode.TEXT_SCAN_FAILED.getCode(),EpmetErrorCode.TEXT_SCAN_FAILED.getMsg(),EpmetErrorCode.TEXT_SCAN_FAILED.getMsg()); } } } @@ -1007,7 +1007,7 @@ public class IssueServiceImpl extends BaseServiceImpl imp //2:调用resi-group查询话题创建人数据(目前议题来源只有来自话题),为了到项目服务初始数据以及发送消息使用 Result resultTopicDTO = resiGroupFeignClient.getTopicById(entity.getSourceId()); if (!resultTopicDTO.success() || null == resultTopicDTO.getData()) { - throw new RenException(IssueConstant.SELECT_TOPIC_EXCEPTION); + throw new EpmetException(9999,IssueConstant.SELECT_TOPIC_EXCEPTION,IssueConstant.SELECT_TOPIC_EXCEPTION); } ResiTopicDTO topicDTO = resultTopicDTO.getData(); formDTO.setTopicDTO(topicDTO); @@ -1019,7 +1019,7 @@ public class IssueServiceImpl extends BaseServiceImpl imp Result resultDTO = govProjectFeignClient.issueShiftProject(formDTO); if (!resultDTO.success() || null == resultDTO.getData()) { logger.error(resultDTO.getInternalMsg()); - throw new RenException(IssueConstant.GOV_PRJECT_EXCEPTION); + throw new EpmetException(9999,IssueConstant.GOV_PRJECT_EXCEPTION,IssueConstant.GOV_PRJECT_EXCEPTION); } IssueProjectResultDTO issueProjectResultDTO = resultDTO.getData(); //更新项目对标签的引用次数 @@ -1054,7 +1054,7 @@ public class IssueServiceImpl extends BaseServiceImpl imp //5:调用epmet-message服务,给居民端话题创建人、议题发起人以及政府端工作人员发送消息 if (!shiftProjectMessage(issueProjectResultDTO, formDTO, entity).success()) { - throw new RenException(IssueConstant.SAVE_MSG_EXCEPTION); + throw new EpmetException(9999,IssueConstant.SAVE_MSG_EXCEPTION,IssueConstant.SAVE_MSG_EXCEPTION); } //5-1:2020.10.26 添加给居民端话题创建人、议题发起人以及政府端工作人员推送微信订阅消息功能 sun if (!wxmpShiftProjectMessage(issueProjectResultDTO, formDTO, entity).success()) { @@ -1088,7 +1088,7 @@ public class IssueServiceImpl extends BaseServiceImpl imp //SendMqMsgUtil.build().openFeignClient(messageOpenFeignClient).sendProjectChangedMqMsg(); return new Result(); } catch (Exception e) { - return new Result().error("议题数据正在处理中,请勿重复提交!"); + return new Result().error(e.getMessage()); } finally { distributedLock.unLock(lock); } From c9e439d8f9f907752b88da9c829ab252a3dc115b Mon Sep 17 00:00:00 2001 From: jianjun Date: Mon, 28 Feb 2022 14:02:48 +0800 Subject: [PATCH 3/3] =?UTF-8?q?gateway=20commonservice=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- epmet-gateway/src/main/resources/bootstrap.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/epmet-gateway/src/main/resources/bootstrap.yml b/epmet-gateway/src/main/resources/bootstrap.yml index c8c245b15a..598f8d7518 100644 --- a/epmet-gateway/src/main/resources/bootstrap.yml +++ b/epmet-gateway/src/main/resources/bootstrap.yml @@ -234,6 +234,7 @@ spring: - Path=${server.servlet.context-path}/commonservice/** filters: - StripPrefix=1 + - CpAuth=true #党建园地 - id: resi-home-server uri: @gateway.routes.resi-home-server.uri@