diff --git a/epmet-admin/epmet-admin-server/src/main/resources/db/migration/V0.0.11__del_social_org.sql b/epmet-admin/epmet-admin-server/src/main/resources/db/migration/V0.0.11__del_social_org.sql new file mode 100644 index 0000000000..ae315be35c --- /dev/null +++ b/epmet-admin/epmet-admin-server/src/main/resources/db/migration/V0.0.11__del_social_org.sql @@ -0,0 +1,7 @@ +UPDATE sys_dict_data +SET DEL_FLAG = '1', +UPDATED_BY = 'yinzuomei', +UPDATED_TIME = NOW(), +remark = '2022.02.21删除社会组织功能,改用联建单位两新组织' +WHERE + dict_value = 'social_org'; \ No newline at end of file diff --git a/epmet-admin/epmet-admin-server/src/main/resources/mapper/SysDictDataDao.xml b/epmet-admin/epmet-admin-server/src/main/resources/mapper/SysDictDataDao.xml index ff1273d4ae..d7ea8fa27b 100644 --- a/epmet-admin/epmet-admin-server/src/main/resources/mapper/SysDictDataDao.xml +++ b/epmet-admin/epmet-admin-server/src/main/resources/mapper/SysDictDataDao.xml @@ -14,8 +14,8 @@ FROM sys_dict_data a INNER JOIN sys_dict_type b ON a.dict_type_id = b.id - WHERE - b.dict_type = #{dictType} + WHERE a.del_flag='0' + and b.dict_type = #{dictType} ORDER BY a.sort ASC @@ -27,8 +27,8 @@ FROM sys_dict_data a INNER JOIN sys_dict_type b ON a.dict_type_id = b.id - WHERE - b.dict_type = #{dictType} + WHERE a.del_flag='0' + and b.dict_type = #{dictType} ORDER BY a.sort asc diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/DingDingRobotConstant.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/DingDingRobotConstant.java new file mode 100644 index 0000000000..08c5708cf6 --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/DingDingRobotConstant.java @@ -0,0 +1,15 @@ +package com.epmet.commons.tools.constant; + +public interface DingDingRobotConstant { + /** + * 尹作梅测试用 + */ + String YZM_TEST_URL="https://oapi.dingtalk.com/robot/send?access_token=249c5f49006cf14b37f9c3bc502ede34c16926a5ac5a0deeb9c9b4be735c0daf"; + String YZM_TEST_SECRET="SECa03f447d67c62d924b5ae52dd9a7ddd9147d32c1d43f8cb43449f505444bdc6b"; + + /** + * EPMET V3 产品研发群 + */ + String V3_ROBOT_URL="https://oapi.dingtalk.com/robot/send?access_token=75e9ab857536f3018baa09009646876edbd263d07521a1a22eedfc3852623614"; + String V3_ROBOT_SECRET="SECdc8d3fb6780faa919f38fd43783f76d111255036c3b5bdcbc086dff023ee84d5"; +} diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/dto/form/DingTextBriefNessFormDTO.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/dto/form/DingTextBriefNessFormDTO.java new file mode 100644 index 0000000000..f6e324497e --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/dto/form/DingTextBriefNessFormDTO.java @@ -0,0 +1,27 @@ +package com.epmet.commons.tools.dto.form; + +import com.dingtalk.api.request.OapiRobotSendRequest; +import lombok.Data; + +/** + * 钉钉机器人发送文本通知,@手机号,简参 + */ +@Data +public class DingTextBriefNessFormDTO { + + /* { + "msgtype":"text", + "text":{ + "content":"我就是我, @15764229697 是不同的烟火" + }, + "at":{ + "atMobiles": [ + "15764229697" + ], + "isAtAll":false + } + }*/ + private String msgtype; + private OapiRobotSendRequest.Text text; + private OapiRobotSendRequest.At at; +} diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpClientManager.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpClientManager.java index 048745cfb6..ce4b79cb1e 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpClientManager.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpClientManager.java @@ -305,6 +305,7 @@ public class HttpClientManager { */ public Result sendAlarmMsg(String content) { Long timestamp = System.currentTimeMillis(); + //生产环境报警群:重要消息通知 String url = "https://oapi.dingtalk.com/robot/send?access_token=c40055ed85e45fdaafea00f3218928794262ff15163e09ad5c89764433b69806"; String secret = "SEC220eafdcb39ab5dd6cffa9f11b0e5de7178ddac9812d40fdceb6b1dda2963186"; diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/validator/group/QueryGroup.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/validator/group/QueryGroup.java new file mode 100644 index 0000000000..df4536366b --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/validator/group/QueryGroup.java @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2018 人人开源 All rights reserved. + * + * https://www.renren.io + * + * 版权所有,侵权必究! + */ + +package com.epmet.commons.tools.validator.group; + +/** + * 查询 Group + * + * @author Mark sunlightcs@gmail.com + * @since 1.0.0 + */ +public interface QueryGroup { + +} 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@ diff --git a/epmet-module/data-aggregator/data-aggregator-client/src/main/java/com/epmet/dataaggre/feign/DataAggregatorOpenFeignClient.java b/epmet-module/data-aggregator/data-aggregator-client/src/main/java/com/epmet/dataaggre/feign/DataAggregatorOpenFeignClient.java new file mode 100644 index 0000000000..a164b0c020 --- /dev/null +++ b/epmet-module/data-aggregator/data-aggregator-client/src/main/java/com/epmet/dataaggre/feign/DataAggregatorOpenFeignClient.java @@ -0,0 +1,24 @@ +package com.epmet.dataaggre.feign; + + +import com.epmet.commons.tools.constant.ServiceConstant; +import com.epmet.commons.tools.utils.Result; +import com.epmet.dataaggre.dto.govorg.form.GridLivelyFormDTO; +import com.epmet.dataaggre.feign.impl.DataAggregatorOpenFeignClientFallbackFactory; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +@FeignClient(name = ServiceConstant.DATA_AGGREGATOR_SERVER, fallbackFactory = DataAggregatorOpenFeignClientFallbackFactory.class) +// @FeignClient(name = ServiceConstant.DATA_AGGREGATOR_SERVER, fallbackFactory= DataAggregatorOpenFeignClientFallbackFactory.class,url = "localhost:8114") +public interface DataAggregatorOpenFeignClient { + + /** + * 定时任务导出网格活跃统计表 + * @param form + * @return + */ + @PostMapping(value = "data/aggregator/org/export-send-msg") + Result exportGridLiveRes(@RequestBody GridLivelyFormDTO form); + +} diff --git a/epmet-module/data-aggregator/data-aggregator-client/src/main/java/com/epmet/dataaggre/feign/impl/DataAggregatorOpenFeignClientFallback.java b/epmet-module/data-aggregator/data-aggregator-client/src/main/java/com/epmet/dataaggre/feign/impl/DataAggregatorOpenFeignClientFallback.java new file mode 100644 index 0000000000..ea2bfebddf --- /dev/null +++ b/epmet-module/data-aggregator/data-aggregator-client/src/main/java/com/epmet/dataaggre/feign/impl/DataAggregatorOpenFeignClientFallback.java @@ -0,0 +1,19 @@ +package com.epmet.dataaggre.feign.impl; + +import com.epmet.commons.tools.constant.ServiceConstant; +import com.epmet.commons.tools.utils.ModuleUtils; +import com.epmet.commons.tools.utils.Result; +import com.epmet.dataaggre.dto.govorg.form.GridLivelyFormDTO; +import com.epmet.dataaggre.feign.DataAggregatorOpenFeignClient; + +public class DataAggregatorOpenFeignClientFallback implements DataAggregatorOpenFeignClient { + /** + * 定时任务导出网格活跃统计表 + * @param form + * @return + */ + @Override + public Result exportGridLiveRes(GridLivelyFormDTO form) { + return ModuleUtils.feignConError(ServiceConstant.DATA_AGGREGATOR_SERVER, "pcworkRecordListExportSendMsg",form); + } +} diff --git a/epmet-module/data-aggregator/data-aggregator-client/src/main/java/com/epmet/dataaggre/feign/impl/DataAggregatorOpenFeignClientFallbackFactory.java b/epmet-module/data-aggregator/data-aggregator-client/src/main/java/com/epmet/dataaggre/feign/impl/DataAggregatorOpenFeignClientFallbackFactory.java new file mode 100644 index 0000000000..ffb9a28654 --- /dev/null +++ b/epmet-module/data-aggregator/data-aggregator-client/src/main/java/com/epmet/dataaggre/feign/impl/DataAggregatorOpenFeignClientFallbackFactory.java @@ -0,0 +1,17 @@ +package com.epmet.dataaggre.feign.impl; + +import com.epmet.dataaggre.feign.DataAggregatorOpenFeignClient; +import feign.hystrix.FallbackFactory; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +public class DataAggregatorOpenFeignClientFallbackFactory implements FallbackFactory { + private DataAggregatorOpenFeignClientFallback fallback = new DataAggregatorOpenFeignClientFallback(); + + @Override + public DataAggregatorOpenFeignClient create(Throwable throwable) { + return null; + } +} \ No newline at end of file diff --git a/epmet-module/data-aggregator/data-aggregator-server/pom.xml b/epmet-module/data-aggregator/data-aggregator-server/pom.xml index ff072d7624..0c2a67f75a 100644 --- a/epmet-module/data-aggregator/data-aggregator-server/pom.xml +++ b/epmet-module/data-aggregator/data-aggregator-server/pom.xml @@ -110,6 +110,12 @@ --> + + com.epmet + epmet-oss-client + 2.0.0 + compile + diff --git a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/controller/GovOrgController.java b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/controller/GovOrgController.java index a0f7bafdbb..c1b2b0e98a 100644 --- a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/controller/GovOrgController.java +++ b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/controller/GovOrgController.java @@ -27,7 +27,6 @@ import com.epmet.dataaggre.entity.govorg.CustomerAgencyEntity; import com.epmet.dataaggre.enums.GridMemberDataAnalysisEnums; import com.epmet.dataaggre.service.AggreGridService; import com.epmet.dataaggre.service.govorg.GovOrgService; -import com.epmet.dto.form.patrol.PcworkRecordListFormDTO; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; @@ -402,4 +401,15 @@ public class GovOrgController { govOrgService.grdiLivelyExport(response, formDTO); } + /** + * 定时任务调用本方法,查询网格活跃度统计结果,生成excel,上传oss.发送钉钉excel. + * @param formDTO + * @return + */ + @PostMapping("export-send-msg") + public Result pcworkRecordListExportSendMsg(@RequestBody GridLivelyFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO, GridLivelyFormDTO.Grid.class); + govOrgService.pcworkRecordListExportSendMsg(formDTO); + return new Result(); + } } diff --git a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/excel/GridLivelyExcel.java b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/excel/GridLivelyExcel.java index 655675326f..331511dbe6 100644 --- a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/excel/GridLivelyExcel.java +++ b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/excel/GridLivelyExcel.java @@ -29,40 +29,57 @@ import lombok.Data; */ @Data public class GridLivelyExcel { - @ExcelProperty("组织ID") @ExcelIgnore private String agencyId; //组织名称 + @Excel(name = "组织名称",width = 15) @ExcelProperty("组织名称") @ColumnWidth(15) private String agencyName; + //组织下所有网格总数 + @Excel(name = "网格总数",width = 15) @ExcelProperty("网格总数") @ColumnWidth(15) private Integer gridSumNum; + //活跃网格数 + @Excel(name = "活跃网格数",width = 15) @ExcelProperty("活跃网格数") @ColumnWidth(15) private Integer gridLivelyNum; + + //活跃网格数占比 + @Excel(name = "活跃网格数占比",width = 15) @ExcelProperty("活跃网格数占比") @ColumnWidth(15) private String gridLivelyRatio; + //正常运行网格数 + @Excel(name = "正常运行网格数",width = 15) @ExcelProperty("正常运行网格数") @ColumnWidth(15) private Integer gridOrdinaryNum; + + //正常运行网格数占比 + @Excel(name = "正常运行网格数占比",width = 15) @ExcelProperty("正常运行网格数占比") @ColumnWidth(15) private String gridOrdinaryRatio; + //僵尸网格数 + @Excel(name = "僵尸网格数",width = 15) @ExcelProperty("僵尸网格数") @ColumnWidth(15) private Integer gridLazyNum; + + //僵尸网格数占比 + @Excel(name = "僵尸网格数占比",width = 15) @ExcelProperty("僵尸网格数占比") @ColumnWidth(15) private String gridLazyRatio; diff --git a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/GovOrgService.java b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/GovOrgService.java index d81af9c6f7..51d938bb2e 100644 --- a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/GovOrgService.java +++ b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/GovOrgService.java @@ -182,4 +182,10 @@ public interface GovOrgService { * @Description 查询组织的直属下级组织下网格活跃度统计--文件导出 **/ void grdiLivelyExport(HttpServletResponse response, GridLivelyFormDTO formDTO); + + /** + * @Author sun + * @Description 查询组织的直属下级组织下网格活跃度统计--文件导出 + **/ + void pcworkRecordListExportSendMsg(GridLivelyFormDTO formDTO); } diff --git a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java index 4fc3cb4f81..7acb871048 100644 --- a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java +++ b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java @@ -1,18 +1,27 @@ package com.epmet.dataaggre.service.govorg.impl; +import cn.afterturn.easypoi.excel.ExcelExportUtil; +import cn.afterturn.easypoi.excel.entity.ExportParams; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.ExcelWriter; import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.fastjson.JSON; +import com.dingtalk.api.request.OapiRobotSendRequest; import com.epmet.commons.dynamic.datasource.annotation.DataSource; +import com.epmet.commons.tools.constant.DingDingRobotConstant; import com.epmet.commons.tools.constant.NumConstant; +import com.epmet.commons.tools.constant.StrConstant; +import com.epmet.commons.tools.dto.form.DingTextBriefNessFormDTO; 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.redis.common.CustomerStaffRedis; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.ExcelUtils; +import com.epmet.commons.tools.utils.HttpClientManager; +import com.epmet.commons.tools.utils.Result; import com.epmet.dataaggre.constant.DataSourceConstant; import com.epmet.dataaggre.dao.govorg.*; import com.epmet.dataaggre.dto.epmetuser.result.ListStaffResultDTO; @@ -28,13 +37,23 @@ import com.epmet.dataaggre.service.datastats.DataStatsService; import com.epmet.dataaggre.service.epmetuser.EpmetUserService; import com.epmet.dataaggre.service.govorg.GovOrgService; import com.epmet.dataaggre.service.opercrm.CustomerRelation; +import com.epmet.dto.result.UploadImgResultDTO; +import com.epmet.feign.OssFeignClient; 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.web.multipart.commons.CommonsMultipartFile; import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.OutputStream; import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.util.*; @@ -67,6 +86,8 @@ public class GovOrgServiceImpl implements GovOrgService { private EpmetUserService epmetUserService; @Autowired private DataStatsService dataStatsService; + @Autowired + private OssFeignClient ossFeignClient; /** * @param staffId @@ -690,4 +711,80 @@ public class GovOrgServiceImpl implements GovOrgService { return name.toString(); } + /** + * @Author sun + * @Description 查询组织的直属下级组织下网格活跃度统计--文件导出 + **/ + @Override + public void pcworkRecordListExportSendMsg(GridLivelyFormDTO formDTO) { + List data = ConvertUtils.sourceToTarget(grdiLively(formDTO), GridLivelyExcel.class); + if(CollectionUtils.isEmpty(data)){ + log.warn(String.format("网格员活跃度统计数据查询为空,入参【%s】", JSON.toJSONString(formDTO))); + return; + } + ExportParams exportParams = new ExportParams(); + String sheetName = excelSheetName(formDTO); + exportParams.setSheetName(sheetName); + Workbook workbook = ExcelExportUtil.exportExcel(exportParams, + GridLivelyExcel.class, data); + + // 文件名 + String resultDescFileName = sheetName.concat(".xls"); + + FileItemFactory factory = new DiskFileItemFactory(16, null); + FileItem fileItem = factory.createItem("file", ContentType.APPLICATION_OCTET_STREAM.toString(), true, resultDescFileName); + OutputStream os = null; + Result uploadResult = null; + try { + os = fileItem.getOutputStream(); + workbook.write(os); + uploadResult = ossFeignClient.uploadImportTaskDescFile(new CommonsMultipartFile(fileItem)); + } catch (Exception e) { + String errormsg = ExceptionUtils.getErrorStackTrace(e); + log.warn("【网格活跃度统计】上传错误描述文件异常:{}", errormsg); + } finally { + try { + os.close(); + } catch (IOException e) { + String errormsg = ExceptionUtils.getErrorStackTrace(e); + log.warn("【网格活跃度统计】上传错误描述文件关闭输出流:{}", errormsg); + } + try { + fileItem.delete(); + } catch (Exception e) { + String errormsg = ExceptionUtils.getErrorStackTrace(e); + log.warn("【网格活跃度统计】上传错误描述文件删除临时文件:{}", errormsg); + } + } + log.warn(String.format("网格员活跃度统计数据查询为空,返参【%s】", JSON.toJSONString(uploadResult))); + if (uploadResult == null || !uploadResult.success()) { + log.warn("【网格活跃度统计】调用OSS上传结果描述文件失败"); + } else { + //EPMETV3群机器人 + String secret = DingDingRobotConstant.V3_ROBOT_SECRET; + String url = DingDingRobotConstant.V3_ROBOT_URL; + // String secret = DingDingRobotConstant.YZM_TEST_SECRET; + // String url = DingDingRobotConstant.YZM_TEST_URL; + + DingTextBriefNessFormDTO dingTalkTextMsg=new DingTextBriefNessFormDTO(); + dingTalkTextMsg.setMsgtype("text"); + + //小雷哥手机号:18660295251, + OapiRobotSendRequest.At at = new OapiRobotSendRequest.At(); + at.setAtMobiles(Arrays.asList("18660295251")); + at.setIsAtAll(false); + dingTalkTextMsg.setAt(at); + + //文本方式发送 + OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text(); + text.setContent("网格活跃度统计: \n" + + "起止时间: " + formDTO.getStartTime().concat(StrConstant.UNDER_LINE).concat(formDTO.getEndTime()) + "\n" + + "文件下载地址: " + uploadResult.getData().getUrl() + "\n"+ + "请查收@18660295251"); + dingTalkTextMsg.setText(text); + HttpClientManager.getInstance().sendDingMsg(JSON.toJSONString(dingTalkTextMsg), url, secret); + } + } + + } diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/constant/ImportTaskConstants.java b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java similarity index 54% rename from epmet-user/epmet-user-client/src/main/java/com/epmet/constant/ImportTaskConstants.java rename to epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java index 685e80a39a..6212a35cb6 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/constant/ImportTaskConstants.java +++ b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java @@ -1,13 +1,20 @@ -package com.epmet.constant; +package com.epmet.constants; /** * 导入任务的业务类型常量 */ public interface ImportTaskConstants { /** - * 居民 + * 业务类型:居民 */ String BIZ_TYPE_RESI = "resi"; + 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"; + String BIZ_TYPE_PARTY_UNIT = "party_unit"; + String BIZ_TYPE_PARTY_ACTIVITY = "party_activity"; /** * 处理状态:处理中 diff --git a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ImportTaskCommonFormDTO.java b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ImportTaskCommonFormDTO.java new file mode 100644 index 0000000000..9eea1fe6c2 --- /dev/null +++ b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/form/ImportTaskCommonFormDTO.java @@ -0,0 +1,55 @@ +package com.epmet.dto.form; + +import com.epmet.commons.tools.dto.form.PageFormDTO; +import com.epmet.commons.tools.validator.group.QueryGroup; +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +@Data +public class ImportTaskCommonFormDTO extends PageFormDTO { + + public interface Create {} + public interface Finish {} + + /** + * 原始文件名 + */ + @NotBlank(message = "原始文件名必填", groups = { Create.class }) + private String originFileName; + + /** + * 操作者ID + */ + @NotBlank(message = "操作者ID必填", groups = { Create.class, Finish.class, QueryGroup.class}) + private String operatorId; + + /** + * 业务类型 + */ + @NotBlank(message = "业务类型必填", groups = { Create.class }) + private String bizType; + + /** + * 任务ID + */ + @NotBlank(message = "任务ID必填", groups = { Finish.class }) + private String taskId; + + /** + * 处理状态 + */ + @NotBlank(message = "处理状态必填", groups = { Finish.class }) + private String processStatus; + + /** + * 结果文件 url + */ + private String resultDescFilePath; + + /** + * 结果描述文本 + */ + private String resultDesc; + +} diff --git a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/ImportTaskCommonResultDTO.java b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/ImportTaskCommonResultDTO.java new file mode 100644 index 0000000000..9812f1abbc --- /dev/null +++ b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/dto/result/ImportTaskCommonResultDTO.java @@ -0,0 +1,43 @@ +package com.epmet.dto.result; + +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.Date; + +@Data +@NoArgsConstructor +public class ImportTaskCommonResultDTO implements Serializable { + public ImportTaskCommonResultDTO(String taskId) { + this.taskId = taskId; + } + + private String taskId; + + /** + * 原始文件名 + */ + private String originFileName; + + /** + * 业务类型。resi:居民;楼栋:building;房屋:house。依次补充 + */ + private String bizType; + + /** + * 处理状态。processing:处理中;finished:完成;导入失败:finished_fail + */ + private String processStatus; + + /** + * 开始导入的时间 + */ + private Date startTime; + + /** + * 失败文件地址 + */ + private String resultDescFile; + +} diff --git a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/EpmetCommonServiceOpenFeignClient.java b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/EpmetCommonServiceOpenFeignClient.java index 1fe124a14f..9ddd2d710d 100644 --- a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/EpmetCommonServiceOpenFeignClient.java +++ b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/EpmetCommonServiceOpenFeignClient.java @@ -4,12 +4,12 @@ import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.form.*; import com.epmet.dto.result.*; -import com.epmet.feign.fallback.EpmetCommonServiceOpenFeignClientFallback; import com.epmet.feign.fallback.EpmetCommonServiceOpenFeignClientFallbackFactory; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; import java.util.List; import java.util.Map; @@ -124,4 +124,20 @@ public interface EpmetCommonServiceOpenFeignClient { **/ @PostMapping(value = "commonservice/areacode/addareacode", consumes = MediaType.APPLICATION_JSON_VALUE) Result addAreaCode(AddAreaCodeFormDTO formDTO); + + /** + * 创建导入任务 + * @param input + * @return + */ + @RequestMapping("/commonservice/import-task/create") + Result createImportTask(@RequestBody ImportTaskCommonFormDTO input); + + /** + * 结束导入任务 + * @param input + * @return + */ + @RequestMapping("/commonservice/import-task/finish") + Result finishImportTask(@RequestBody ImportTaskCommonFormDTO input); } diff --git a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/fallback/EpmetCommonServiceOpenFeignClientFallback.java b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/fallback/EpmetCommonServiceOpenFeignClientFallback.java index 4afee3fa08..c3c62d64da 100644 --- a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/fallback/EpmetCommonServiceOpenFeignClientFallback.java +++ b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/fallback/EpmetCommonServiceOpenFeignClientFallback.java @@ -111,4 +111,14 @@ public class EpmetCommonServiceOpenFeignClientFallback implements EpmetCommonSer public Result addAreaCode(AddAreaCodeFormDTO formDTO) { return ModuleUtils.feignConError(ServiceConstant.EPMET_COMMON_SERVICE, "addAreaCode", formDTO); } + + @Override + public Result createImportTask(ImportTaskCommonFormDTO input) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_COMMON_SERVICE, "createImportTask", input); + } + + @Override + public Result finishImportTask(ImportTaskCommonFormDTO input) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_COMMON_SERVICE, "finishImportTask", input); + } } diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ImportTaskController.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ImportTaskController.java new file mode 100644 index 0000000000..8af4083542 --- /dev/null +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/controller/ImportTaskController.java @@ -0,0 +1,82 @@ +package com.epmet.controller; + +import com.epmet.commons.tools.annotation.LoginUser; +import com.epmet.commons.tools.exception.EpmetErrorCode; +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; +import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.commons.tools.validator.group.QueryGroup; +import com.epmet.dto.form.ImportTaskCommonFormDTO; +import com.epmet.dto.result.ImportTaskCommonResultDTO; +import com.epmet.service.ImportTaskService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("import-task") +public class ImportTaskController { + + @Autowired + private ImportTaskService importTaskService; + + /** + * desc:分页获取个人导入记录 + * @param tokenDto + * @return + */ + @RequestMapping("page") + public Result> list(@LoginUser TokenDto tokenDto, @RequestBody ImportTaskCommonFormDTO param) { + //tokenDto.setUserId("d8dfc6c1fa2538976059f3900036d419"); + param.setOperatorId(tokenDto.getUserId()); + ValidatorUtils.validateEntity(param, QueryGroup.class); + return new Result().ok(importTaskService.page(param)); + } + + /** + * 创建导入任务 + * @param input + * @return + */ + @RequestMapping("create") + public Result createTask(@RequestBody ImportTaskCommonFormDTO input) { + ValidatorUtils.validateEntity(input, ImportTaskCommonFormDTO.Create.class); + String operatorId = input.getOperatorId(); + String bizType = input.getBizType(); + String originFileName = input.getOriginFileName(); + + String taskId = importTaskService.createProcessTask(operatorId, bizType, originFileName); + ImportTaskCommonResultDTO ro = new ImportTaskCommonResultDTO(taskId); + return new Result().ok(ro); + } + + /** + * 结束任务 + * @param input + * @return + */ + @RequestMapping("finish") + public Result finishTask(@RequestBody ImportTaskCommonFormDTO input) { + ValidatorUtils.validateEntity(input, ImportTaskCommonFormDTO.Finish.class); + Boolean finished = importTaskService.finish(input.getTaskId(), input.getProcessStatus(), input.getOperatorId(), input.getResultDescFilePath(), input.getResultDesc()); + if (!finished) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), + "失败,请确认任务是否存在,以及是否已完成", + "失败,请确认任务是否存在,以及是否已完成"); + } + return new Result(); + } + + /** + * 检查是否有正在执行的任务。 + * @param bizType 业务类型,非必填,不传则任意一种导入正在执行都会返回true + * @return + */ + @GetMapping("processing-check") + public Result processingTaskCheck(@RequestParam(value = "biz_type", required = false) String bizType) { + Boolean r = importTaskService.processingTaskCheck(bizType); + return new Result().ok(r); + } + +} diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/ImportTaskDao.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/ImportTaskDao.java similarity index 100% rename from epmet-user/epmet-user-server/src/main/java/com/epmet/dao/ImportTaskDao.java rename to epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/dao/ImportTaskDao.java diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/entity/ImportTaskEntity.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/entity/ImportTaskEntity.java similarity index 88% rename from epmet-user/epmet-user-server/src/main/java/com/epmet/entity/ImportTaskEntity.java rename to epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/entity/ImportTaskEntity.java index 742c6cc93e..0602a42963 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/entity/ImportTaskEntity.java +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/entity/ImportTaskEntity.java @@ -1,7 +1,6 @@ package com.epmet.entity; import com.baomidou.mybatisplus.annotation.TableName; - import com.epmet.commons.mybatis.entity.BaseEpmetEntity; import lombok.Data; import lombok.EqualsAndHashCode; @@ -21,6 +20,16 @@ public class ImportTaskEntity extends BaseEpmetEntity { private static final long serialVersionUID = 1L; + /** + * 客户ID + */ + private String customerId; + + /** + * 原始文件名 + */ + private String originFileName; + /** * 业务类型。resi:居民;楼栋:building;房屋:house。依次补充 */ diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ImportTaskService.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ImportTaskService.java new file mode 100644 index 0000000000..918643d8f2 --- /dev/null +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/ImportTaskService.java @@ -0,0 +1,54 @@ +package com.epmet.service; + + +import com.epmet.commons.tools.page.PageData; +import com.epmet.dto.form.ImportTaskCommonFormDTO; +import com.epmet.dto.result.ImportTaskCommonResultDTO; + +/** + * + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-02-15 + */ +public interface ImportTaskService { + +// /** +// * 检查指定类型该用户是否存在处理中的导入任务 +// * @param operatorId 操作者ID +// * @param bizType 业务类型。resi:居民 +// * @return +// */ +// boolean existsProcessingTask(String operatorId, String bizType); + + /** + * 创建处理任务 + * @param operatorId + * @param bizType + * @param originFileName 原始文件名 + */ + String createProcessTask(String operatorId, String bizType, String originFileName); + + /** + * 结束导入 + * @param taskId 任务id + * @param processStatus 处理状态 + * @param resultDescFile 结果描述文件 + * @param resultDesc 结果描述文本 + */ + Boolean finish(String taskId, String processStatus, String operatorId, String resultDescFile, String resultDesc); + + /** + * desc:分页获取个人导入记录 + * @param param + * @return + */ + PageData page(ImportTaskCommonFormDTO param); + + /** + * 检查是否有正在执行的任务 + * @param bizType + * @return + */ + Boolean processingTaskCheck(String bizType); +} diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ImportTaskServiceImpl.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ImportTaskServiceImpl.java new file mode 100644 index 0000000000..cb28fecad8 --- /dev/null +++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/ImportTaskServiceImpl.java @@ -0,0 +1,123 @@ +package com.epmet.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; +import com.epmet.commons.tools.security.user.LoginUserUtil; +import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.constants.ImportTaskConstants; +import com.epmet.dao.ImportTaskDao; +import com.epmet.dto.form.ImportTaskCommonFormDTO; +import com.epmet.dto.result.ImportTaskCommonResultDTO; +import com.epmet.entity.ImportTaskEntity; +import com.epmet.service.ImportTaskService; +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-02-15 + */ +@Service +public class ImportTaskServiceImpl implements ImportTaskService { + + @Autowired + private ImportTaskDao importRecordDao; + + @Autowired + private LoginUserUtil loginUserUtil; + +// /** +// * 该用户,该业务类型,是否有正在处理的导入任务 +// * @param operatorId 操作者ID +// * @param bizType 业务类型。resi:居民 +// * @return +// */ +// @Override +// public boolean existsProcessingTask(String operatorId, String bizType) { +// LambdaQueryWrapper query = new LambdaQueryWrapper<>(); +// query.eq(ImportTaskEntity::getOperatorId, operatorId); +// query.eq(ImportTaskEntity::getBizType, bizType); +// query.eq(ImportTaskEntity::getProcessStatus, ImportTaskConstants.PROCESS_STATUS_PROCESSING); +// +// return importRecordDao.selectCount(query) > 0; +// } + + /** + * 检查是否有正在执行的任务 + * @param operatorId + * @param bizType + * @return + */ + public boolean existsProcessingTask(String operatorId, String bizType) { + LambdaQueryWrapper query = new LambdaQueryWrapper<>(); + query.eq(ImportTaskEntity::getOperatorId, operatorId); + query.eq(ImportTaskEntity::getBizType, bizType); + query.eq(ImportTaskEntity::getProcessStatus, ImportTaskConstants.PROCESS_STATUS_PROCESSING); + + return importRecordDao.selectCount(query) > 0; + } + + @Override + public String createProcessTask(String operatorId, String bizType, String originFileName) { + if (existsProcessingTask(operatorId, bizType)) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), + "存在进行中的导入", + "存在进行中的导入"); + } + + ImportTaskEntity importRecord = new ImportTaskEntity(); + importRecord.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_PROCESSING); + importRecord.setOperatorId(operatorId); + importRecord.setBizType(bizType); + importRecord.setCustomerId(loginUserUtil.getLoginUserCustomerId()); + importRecord.setStartTime(new Date()); + importRecord.setOriginFileName(originFileName); + + importRecordDao.insert(importRecord); + return importRecord.getId(); + } + + @Override + public Boolean finish(String taskId, String processStatus, String operatorId, String resultDescFile, String resultDesc) { + return importRecordDao.finish(taskId, processStatus, operatorId, resultDesc, resultDescFile) > 0; + } + + @Override + public PageData page(ImportTaskCommonFormDTO param) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(ImportTaskEntity::getOperatorId,param.getOperatorId()) + .orderByDesc(ImportTaskEntity::getStartTime); + Page page = PageHelper.startPage(param.getPageNo(), param.getPageSize(), param.isPage()).doSelectPage(() -> { + importRecordDao.selectList(queryWrapper); + }); + List list = new ArrayList<>(); + page.getResult().forEach(item->{ + ImportTaskCommonResultDTO record = ConvertUtils.sourceToTarget(item, ImportTaskCommonResultDTO.class); + record.setTaskId(item.getId()); + list.add(record); + }); + return new PageData<>(list,page.getTotal()); + } + + @Override + public Boolean processingTaskCheck(String bizType) { + LambdaQueryWrapper query = new LambdaQueryWrapper<>(); + if (StringUtils.isNotBlank(bizType)) { + query.eq(ImportTaskEntity::getBizType, bizType); + } + query.eq(ImportTaskEntity::getProcessStatus, ImportTaskConstants.PROCESS_STATUS_PROCESSING); + + return importRecordDao.selectCount(query) > 0; + } +} diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/resources/db/migration/V0.0.12__createImportTask.sql b/epmet-module/epmet-common-service/common-service-server/src/main/resources/db/migration/V0.0.12__createImportTask.sql new file mode 100644 index 0000000000..437af39520 --- /dev/null +++ b/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 + diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/resources/db/migration/V0.0.13__ImportTaskCommentModify.sql b/epmet-module/epmet-common-service/common-service-server/src/main/resources/db/migration/V0.0.13__ImportTaskCommentModify.sql new file mode 100644 index 0000000000..de7c4f70a0 --- /dev/null +++ b/epmet-module/epmet-common-service/common-service-server/src/main/resources/db/migration/V0.0.13__ImportTaskCommentModify.sql @@ -0,0 +1 @@ +alter table import_task modify column PROCESS_STATUS varchar(32) comment '处理状态。processing:处理中;finished_success:成功;finished_fail:未完全成功' \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/resources/mapper/ImportTaskDao.xml b/epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ImportTaskDao.xml similarity index 94% rename from epmet-user/epmet-user-server/src/main/resources/mapper/ImportTaskDao.xml rename to epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ImportTaskDao.xml index edc56fa5c7..fce694cb16 100644 --- a/epmet-user/epmet-user-server/src/main/resources/mapper/ImportTaskDao.xml +++ b/epmet-module/epmet-common-service/common-service-server/src/main/resources/mapper/ImportTaskDao.xml @@ -5,6 +5,7 @@ + diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/IcActivityServiceRelationDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/IcActivityServiceRelationDTO.java new file mode 100644 index 0000000000..c5f7f33641 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/IcActivityServiceRelationDTO.java @@ -0,0 +1,85 @@ +package com.epmet.dto; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + + +/** + * 联建活动与服务事项关联表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-02-21 + */ +@Data +public class IcActivityServiceRelationDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + private String id; + + /** + * 客户id + */ + private String customerId; + + /** + * 组织ID + */ + private String agencyId; + + /** + * 组织的所有上级 + */ + private String pids; + + /** + * 活动ID + */ + private String activityId; + + /** + * act_info表ID + */ + private String actId; + + /** + * 服务事项 + */ + private String serviceMatter; + + /** + * 删除标识 0未删除、1已删除 + */ + private String delFlag; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建人 + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新人 + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/IcActivityUnitRelationDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/IcActivityUnitRelationDTO.java new file mode 100644 index 0000000000..8af5942af0 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/IcActivityUnitRelationDTO.java @@ -0,0 +1,89 @@ +package com.epmet.dto; + +import java.io.Serializable; +import java.util.Date; +import lombok.Data; + + +/** + * 联建活动与单位关联表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-02-21 + */ +@Data +public class IcActivityUnitRelationDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + private String id; + + /** + * 客户id + */ + private String customerId; + + /** + * 组织ID + */ + private String agencyId; + + /** + * 组织的所有上级 + */ + private String pids; + + /** + * 活动ID + */ + private String activityId; + + /** + * act_info表ID + */ + private String actId; + + /** + * 单位ID + */ + private String unitId; + + /** + * 服务事项 + */ + private String serviceMatter; + + /** + * 删除标识 0未删除、1已删除 + */ + private String delFlag; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建人 + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新人 + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/IcPartyActivityDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/IcPartyActivityDTO.java index 81edd97c20..bcb04fb6ef 100644 --- a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/IcPartyActivityDTO.java +++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/IcPartyActivityDTO.java @@ -19,12 +19,15 @@ package com.epmet.dto; import com.epmet.commons.tools.validator.group.AddGroup; import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotEmpty; import java.io.Serializable; import java.util.Date; +import java.util.List; /** @@ -46,35 +49,44 @@ public class IcPartyActivityDTO implements Serializable { /** * 客户id */ + @JsonIgnore private String customerId; /** * 组织ID */ + @JsonIgnore private String agencyId; /** * 组织的所有上级 */ + @JsonIgnore private String pids; /** * act_info表ID */ + @JsonIgnore private String actId; + private String unitId; + private String unitName; /** * 单位ID */ - @NotBlank(message = "单位不能为空",groups = AddGroup.class) - private String unitId; - private String unitName; + @NotEmpty(message = "单位不能为空",groups = AddGroup.class) + private List unitIdList; + private List unitNameList; + + private String serviceMatter; + private String serviceMatterName; /** * 服务事项 */ - @NotBlank(message = "服务事项不能为空",groups = AddGroup.class) - private String serviceMatter; - private String serviceMatterName; + @NotEmpty(message = "服务事项不能为空",groups = AddGroup.class) + private List serviceMatterList; + private List serviceMatterNameList; /** * 活动标题 */ @@ -131,31 +143,37 @@ public class IcPartyActivityDTO implements Serializable { /** * 删除标识 0未删除、1已删除 */ + @JsonIgnore private String delFlag; /** * 乐观锁 */ + @JsonIgnore private Integer revision; /** * 创建人 */ + @JsonIgnore private String createdBy; /** * 创建时间 */ + @JsonIgnore private Date createdTime; /** * 更新人 */ + @JsonIgnore private String updatedBy; /** * 更新时间 */ + @JsonIgnore private Date updatedTime; } \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/LatestActServiceRelationDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/LatestActServiceRelationDTO.java new file mode 100644 index 0000000000..b25b10f432 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/LatestActServiceRelationDTO.java @@ -0,0 +1,79 @@ +package com.epmet.dto; + +import java.io.Serializable; +import java.util.Date; +import lombok.Data; + + +/** + * 联建活动与服务事项关联表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-02-21 + */ +@Data +public class LatestActServiceRelationDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + private String id; + + /** + * 客户id + */ + private String customerId; + + /** + * 组织ID + */ + private String agencyId; + + /** + * 组织的所有上级 + */ + private String pids; + + /** + * latest_act_info表ID + */ + private String actId; + + /** + * 服务事项 + */ + private String serviceMatter; + + /** + * 删除标识 0未删除、1已删除 + */ + private String delFlag; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建人 + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新人 + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/LatestActUnitRelationDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/LatestActUnitRelationDTO.java new file mode 100644 index 0000000000..534053660d --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/LatestActUnitRelationDTO.java @@ -0,0 +1,84 @@ +package com.epmet.dto; + +import java.io.Serializable; +import java.util.Date; +import lombok.Data; + + +/** + * 联建活动与单位关联表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-02-21 + */ +@Data +public class LatestActUnitRelationDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + private String id; + + /** + * 客户id + */ + private String customerId; + + /** + * 组织ID + */ + private String agencyId; + + /** + * 组织的所有上级 + */ + private String pids; + + /** + * latest_act_info表ID + */ + private String actId; + + /** + * 单位ID + */ + private String unitId; + + /** + * 服务事项 + */ + private String serviceMatter; + + /** + * 删除标识 0未删除、1已删除 + */ + private String delFlag; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建人 + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新人 + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/work/DraftActInfoFormDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/work/DraftActInfoFormDTO.java index f00ebe792f..a88d1d393f 100644 --- a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/work/DraftActInfoFormDTO.java +++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/work/DraftActInfoFormDTO.java @@ -170,7 +170,7 @@ public class DraftActInfoFormDTO implements Serializable { * 联建单位 */ private String unitId; - + private List unitIdList; /** * 活动目标 */ @@ -180,5 +180,6 @@ public class DraftActInfoFormDTO implements Serializable { * 服务事项 */ private String serviceMatter; + private List serviceMatterList; } diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/work/PublishActInfoFormDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/work/PublishActInfoFormDTO.java index ef1f3c3e19..099fa38e60 100644 --- a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/work/PublishActInfoFormDTO.java +++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/work/PublishActInfoFormDTO.java @@ -5,10 +5,7 @@ import lombok.Data; import org.hibernate.validator.constraints.Length; import javax.validation.Valid; -import javax.validation.constraints.Min; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; +import javax.validation.constraints.*; import java.io.Serializable; import java.math.BigDecimal; import java.util.List; @@ -200,9 +197,9 @@ public class PublishActInfoFormDTO implements Serializable { /** * 联建单位 */ - @NotBlank(message = "联建单位不能为空", groups = {AddPartyActivityGroup.class}) private String unitId; - + @NotEmpty(message = "联建单位不能为空", groups = {AddPartyActivityGroup.class}) + private List unitIdList; /** * 活动目标 */ @@ -212,6 +209,7 @@ public class PublishActInfoFormDTO implements Serializable { /** * 服务事项 */ - @NotBlank(message = "服务事项不能为空", groups = {AddPartyActivityGroup.class}) private String serviceMatter; + @NotEmpty(message = "服务事项不能为空", groups = {AddPartyActivityGroup.class}) + private List serviceMatterList; } diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/work/RePublishFormDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/work/RePublishFormDTO.java index b093e9dcba..587a60a0ff 100644 --- a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/work/RePublishFormDTO.java +++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/work/RePublishFormDTO.java @@ -5,10 +5,7 @@ import lombok.Data; import org.hibernate.validator.constraints.Length; import javax.validation.Valid; -import javax.validation.constraints.Min; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; +import javax.validation.constraints.*; import java.io.Serializable; import java.math.BigDecimal; import java.util.List; @@ -206,8 +203,9 @@ public class RePublishFormDTO implements Serializable { /** * 联建单位 */ - @NotBlank(message = "联建单位不能为空", groups = {AddPartyActivityGroup.class}) private String unitId; + @NotEmpty(message = "联建单位不能为空", groups = {PublishActInfoFormDTO.AddPartyActivityGroup.class}) + private List unitIdList; /** * 活动目标 @@ -218,6 +216,7 @@ public class RePublishFormDTO implements Serializable { /** * 服务事项 */ - @NotBlank(message = "服务事项不能为空", groups = {AddPartyActivityGroup.class}) private String serviceMatter; + @NotEmpty(message = "服务事项不能为空", groups = {PublishActInfoFormDTO.AddPartyActivityGroup.class}) + private List serviceMatterList; } diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/resi/ResiActDetailResultDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/resi/ResiActDetailResultDTO.java index a232ebdf33..aa33f41e69 100644 --- a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/resi/ResiActDetailResultDTO.java +++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/resi/ResiActDetailResultDTO.java @@ -186,6 +186,8 @@ public class ResiActDetailResultDTO implements Serializable { */ private String unitId; private String unitName; + private List unitIdList; + private List unitNameList; /** * 活动目标 */ @@ -196,4 +198,6 @@ public class ResiActDetailResultDTO implements Serializable { */ private String serviceMatter; private String serviceMatterName; + private List serviceMatterList; + private List serviceMatterNameList; } diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/ActPreviewResultDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/ActPreviewResultDTO.java index 5e3df9d139..caeed480d5 100644 --- a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/ActPreviewResultDTO.java +++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/ActPreviewResultDTO.java @@ -1,6 +1,7 @@ package com.epmet.dto.result.work; import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Data; import java.io.Serializable; @@ -74,7 +75,12 @@ public class ActPreviewResultDTO implements Serializable { * 主办方名称 */ private String sponsorName; - + @JsonIgnore + private String sponsorType; + @JsonIgnore + private String sponsorId; + @JsonIgnore + private String pid; /** * 联系人 */ @@ -100,6 +106,8 @@ public class ActPreviewResultDTO implements Serializable { */ private String unitId; private String unitName; + private List unitIdList; + private List unitNameList; /** * 活动目标 */ @@ -110,4 +118,6 @@ public class ActPreviewResultDTO implements Serializable { */ private String serviceMatter; private String serviceMatterName; + private List serviceMatterList; + private List serviceMatterNameList; } diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/CanceledActDetailResultDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/CanceledActDetailResultDTO.java index 3da7fade52..764d3ffabf 100644 --- a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/CanceledActDetailResultDTO.java +++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/CanceledActDetailResultDTO.java @@ -158,6 +158,8 @@ public class CanceledActDetailResultDTO implements Serializable { */ private String unitId; private String unitName; + private List unitIdList; + private List unitNameList; /** * 活动目标 */ @@ -168,4 +170,6 @@ public class CanceledActDetailResultDTO implements Serializable { */ private String serviceMatter; private String serviceMatterName; + private List serviceMatterList; + private List serviceMatterNameList; } diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/FinishedActDetailResultDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/FinishedActDetailResultDTO.java index 3e4bfbdc9a..5bf9c4bfb1 100644 --- a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/FinishedActDetailResultDTO.java +++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/FinishedActDetailResultDTO.java @@ -147,6 +147,8 @@ public class FinishedActDetailResultDTO implements Serializable { */ private String unitId; private String unitName; + private List unitIdList; + private List unitNameList; /** * 活动目标 */ @@ -157,4 +159,6 @@ public class FinishedActDetailResultDTO implements Serializable { */ private String serviceMatter; private String serviceMatterName; + private List serviceMatterList; + private List serviceMatterNameList; } diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/InProgressActDetailResultDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/InProgressActDetailResultDTO.java index 8dc4ad2fb2..03fdbf576b 100644 --- a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/InProgressActDetailResultDTO.java +++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/InProgressActDetailResultDTO.java @@ -142,6 +142,8 @@ public class InProgressActDetailResultDTO implements Serializable { */ private String unitId; private String unitName; + private List unitIdList; + private List unitNameList; /** * 活动目标 */ @@ -152,4 +154,6 @@ public class InProgressActDetailResultDTO implements Serializable { */ private String serviceMatter; private String serviceMatterName; + private List serviceMatterList; + private List serviceMatterNameList; } diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/LatestDraftActInfoResultDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/LatestDraftActInfoResultDTO.java index c4a250df92..70b4c5754f 100644 --- a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/LatestDraftActInfoResultDTO.java +++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/LatestDraftActInfoResultDTO.java @@ -176,7 +176,7 @@ public class LatestDraftActInfoResultDTO implements Serializable { * 联建单位 */ private String unitId; - + private List unitIdList; /** * 活动目标 */ @@ -186,4 +186,5 @@ public class LatestDraftActInfoResultDTO implements Serializable { * 服务事项 */ private String serviceMatter; + private List serviceMatterList; } diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/ReEditActInfoResultDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/ReEditActInfoResultDTO.java index a360fd53c3..367ab0ec1d 100644 --- a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/ReEditActInfoResultDTO.java +++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/work/ReEditActInfoResultDTO.java @@ -159,6 +159,8 @@ public class ReEditActInfoResultDTO implements Serializable { */ private String unitId; private String unitName; + private List unitIdList; + private List unitNameList; /** * 活动目标 */ @@ -169,4 +171,6 @@ public class ReEditActInfoResultDTO implements Serializable { */ private String serviceMatter; private String serviceMatterName; + private List serviceMatterList; + private List serviceMatterNameList; } diff --git a/epmet-module/epmet-heart/epmet-heart-server/pom.xml b/epmet-module/epmet-heart/epmet-heart-server/pom.xml index dca1adb1c5..7f1f461e0e 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..bbea13e834 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 @@ -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; @@ -34,18 +30,22 @@ 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; 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; @@ -66,6 +66,8 @@ public class IcCommunitySelfOrganizationController { @Autowired private IcCommunitySelfOrganizationService icCommunitySelfOrganizationService; + @Autowired + private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient; @GetMapping("page") public Result> page(@RequestParam Map params){ @@ -138,6 +140,8 @@ public class IcCommunitySelfOrganizationController { * @date 2021/11/25 9:03 上午 */ @PostMapping("importcommunityselforganization") + //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("请上传文件"); @@ -148,7 +152,18 @@ public class IcCommunitySelfOrganizationController { if (!"xls".equals(extension) && !"xlsx".equals(extension)) { throw new RenException("文件类型不匹配"); } - icCommunitySelfOrganizationService.importCommunitySelfOrganization(tokenDto, response, file); + //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()); + return new Result(); } 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/dao/IcActivityServiceRelationDao.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/IcActivityServiceRelationDao.java new file mode 100644 index 0000000000..46cfe4eb3e --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/IcActivityServiceRelationDao.java @@ -0,0 +1,25 @@ +package com.epmet.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.entity.IcActivityServiceRelationEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * 联建活动与服务事项关联表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-02-21 + */ +@Mapper +public interface IcActivityServiceRelationDao extends BaseDao { + /** + * 删除活动所属服务 + * + * @Param activityId + * @Return + * @Author zhaoqifeng + * @Date 2022/2/21 16:19 + */ + void deleteByActivity(@Param("activityId") String activityId); +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/IcActivityUnitRelationDao.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/IcActivityUnitRelationDao.java new file mode 100644 index 0000000000..be27ce119b --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/IcActivityUnitRelationDao.java @@ -0,0 +1,25 @@ +package com.epmet.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.entity.IcActivityUnitRelationEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * 联建活动与单位关联表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-02-21 + */ +@Mapper +public interface IcActivityUnitRelationDao extends BaseDao { + /** + * 删除活动所属单位 + * + * @Param activityId + * @Return + * @Author zhaoqifeng + * @Date 2022/2/21 16:19 + */ + void deleteByActivity(@Param("activityId") String activityId); +} \ No newline at end of file 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/dao/IcPartyActivityDao.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/IcPartyActivityDao.java index bb7e41c2ed..c8fba2ffed 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/IcPartyActivityDao.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/IcPartyActivityDao.java @@ -23,6 +23,8 @@ import com.epmet.dto.result.ActivityStatisticsDTO; import com.epmet.entity.IcPartyActivityEntity; import org.apache.ibatis.annotations.Mapper; +import java.util.List; + /** * 联建活动 * @@ -40,5 +42,16 @@ public interface IcPartyActivityDao extends BaseDao { * @Date 2021/12/9 16:06 */ ActivityStatisticsDTO getStatistics(PartyActivityFormDTO formDTO); - + + /** + * 活动列表查询 + * @Param formDTO + * @Return {@link java.util.List} + * @Author zhaoqifeng + * @Date 2022/2/21 14:50 + */ + List selectActivityList(PartyActivityFormDTO formDTO); + + + List getActivityList(PartyActivityFormDTO formDTO); } \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/LatestActServiceRelationDao.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/LatestActServiceRelationDao.java new file mode 100644 index 0000000000..6a46bf5031 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/LatestActServiceRelationDao.java @@ -0,0 +1,25 @@ +package com.epmet.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.entity.LatestActServiceRelationEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * 联建活动与服务事项关联表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-02-21 + */ +@Mapper +public interface LatestActServiceRelationDao extends BaseDao { + /** + * 删除活动所属服务 + * + * @Param activityId + * @Return + * @Author zhaoqifeng + * @Date 2022/2/21 16:19 + */ + void deleteByActivity(@Param("activityId") String activityId); +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/LatestActUnitRelationDao.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/LatestActUnitRelationDao.java new file mode 100644 index 0000000000..19e8d48e57 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/LatestActUnitRelationDao.java @@ -0,0 +1,25 @@ +package com.epmet.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.entity.LatestActUnitRelationEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * 联建活动与单位关联表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-02-21 + */ +@Mapper +public interface LatestActUnitRelationDao extends BaseDao { + /** + * 删除活动所属服务 + * + * @Param activityId + * @Return + * @Author zhaoqifeng + * @Date 2022/2/21 16:19 + */ + void deleteByActivity(@Param("activityId") String activityId); +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/IcActivityServiceRelationEntity.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/IcActivityServiceRelationEntity.java new file mode 100644 index 0000000000..31790b660f --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/IcActivityServiceRelationEntity.java @@ -0,0 +1,56 @@ +package com.epmet.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 联建活动与服务事项关联表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-02-21 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("ic_activity_service_relation") +public class IcActivityServiceRelationEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 客户id + */ + private String customerId; + + /** + * 组织ID + */ + private String agencyId; + + /** + * 组织的所有上级 + */ + private String pids; + + /** + * 活动ID + */ + private String activityId; + + /** + * act_info表ID + */ + private String actId; + + /** + * 服务事项 + */ + private String serviceMatter; + + /** + * 排序 + */ + private Integer sort; + +} diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/IcActivityUnitRelationEntity.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/IcActivityUnitRelationEntity.java new file mode 100644 index 0000000000..d7983ff41c --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/IcActivityUnitRelationEntity.java @@ -0,0 +1,56 @@ +package com.epmet.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 联建活动与单位关联表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-02-21 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("ic_activity_unit_relation") +public class IcActivityUnitRelationEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 客户id + */ + private String customerId; + + /** + * 组织ID + */ + private String agencyId; + + /** + * 组织的所有上级 + */ + private String pids; + + /** + * 活动ID + */ + private String activityId; + + /** + * act_info表ID + */ + private String actId; + + /** + * 单位ID + */ + private String unitId; + + /** + * 排序 + */ + private Integer sort; + +} diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/LatestActServiceRelationEntity.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/LatestActServiceRelationEntity.java new file mode 100644 index 0000000000..20e20de39b --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/LatestActServiceRelationEntity.java @@ -0,0 +1,41 @@ +package com.epmet.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 联建活动与服务事项关联表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-02-21 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("latest_act_service_relation") +public class LatestActServiceRelationEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 客户id + */ + private String customerId; + + /** + * latest_act_info表ID + */ + private String actId; + + /** + * 服务事项 + */ + private String serviceMatter; + + /** + * 排序 + */ + private Integer sort; + +} diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/LatestActUnitRelationEntity.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/LatestActUnitRelationEntity.java new file mode 100644 index 0000000000..d386197d79 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/LatestActUnitRelationEntity.java @@ -0,0 +1,41 @@ +package com.epmet.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 联建活动与单位关联表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-02-21 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("latest_act_unit_relation") +public class LatestActUnitRelationEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 客户id + */ + private String customerId; + + /** + * latest_act_info表ID + */ + private String actId; + + /** + * 单位ID + */ + private String unitId; + + /** + * 排序 + */ + private Integer sort; + +} diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/CommunitySelfOrgImportExcel.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/CommunitySelfOrgImportExcel.java new file mode 100644 index 0000000000..a55b7c9b69 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/CommunitySelfOrgImportExcel.java @@ -0,0 +1,37 @@ +/** + * 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 lombok.Data; + +/** + * 社会自组织导入错误数据存放文件 + * @author sun + */ +@Data +public class CommunitySelfOrgImportExcel { + + /*@Excel(name = "组织名称", width = 40) + private String agencyName;*/ + @Excel(name = "社会自组织名称", width = 40) + private String societyName; + @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/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/excel/ImportCommunitySelfOrganization.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/ImportCommunitySelfOrganization.java index 2a9995be2a..a6c6102431 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/ImportCommunitySelfOrganization.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/ImportCommunitySelfOrganization.java @@ -5,6 +5,7 @@ import cn.afterturn.easypoi.excel.annotation.ExcelCollection; import com.epmet.commons.tools.utils.ExcelVerifyInfo; import lombok.Data; +import javax.validation.constraints.NotBlank; import java.util.Date; import java.util.List; @@ -17,22 +18,27 @@ import java.util.List; public class ImportCommunitySelfOrganization extends ExcelVerifyInfo { @Excel(name = "组织名称", needMerge = true) + @NotBlank(message = "不能为空") private String organizationName; @Excel(name = "组织人数", needMerge = true) + //@NotNull(message = "不能为空") private Integer organizationPersonCount; @Excel(name = "服务事项", needMerge = true) + @NotBlank(message = "不能为空") private String serviceItem; @Excel(name = "负责人", needMerge = true) + @NotBlank(message = "不能为空") private String principalName; @Excel(name = "联系电话", needMerge = true) + @NotBlank(message = "不能为空") private String principalPhone; @Excel(name = "创建时间", needMerge = true) - private Date organizationCreatedTime; + private String organizationCreatedTime; @ExcelCollection(name = "组织成员") private List persons; diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/IcActivityServiceRelationService.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/IcActivityServiceRelationService.java new file mode 100644 index 0000000000..ae402d24a0 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/IcActivityServiceRelationService.java @@ -0,0 +1,44 @@ +package com.epmet.service; + +import com.epmet.commons.mybatis.service.BaseService; +import com.epmet.entity.IcActivityServiceRelationEntity; + +import java.util.List; + +/** + * 联建活动与服务事项关联表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-02-21 + */ +public interface IcActivityServiceRelationService extends BaseService { + /** + * 获取活动所属服务事项 + * + * @Param activityId 活动ID + * @Return {@link List } + * @Author zhaoqifeng + * @Date 2022/2/21 14:36 + */ + List getServiceList(String activityId); + + /** + * 物理删除活动所属服务事项 + * + * @Param activityId + * @Return + * @Author zhaoqifeng + * @Date 2022/2/21 16:10 + */ + void deleteByActivity(String activityId); + + /** + * 逻辑删除活动所属服务事项 + * + * @Param activityId + * @Return + * @Author zhaoqifeng + * @Date 2022/2/21 16:10 + */ + void delete(String activityId); +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/IcActivityUnitRelationService.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/IcActivityUnitRelationService.java new file mode 100644 index 0000000000..3d109db98b --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/IcActivityUnitRelationService.java @@ -0,0 +1,44 @@ +package com.epmet.service; + +import com.epmet.commons.mybatis.service.BaseService; +import com.epmet.entity.IcActivityUnitRelationEntity; + +import java.util.List; + +/** + * 联建活动与单位关联表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-02-21 + */ +public interface IcActivityUnitRelationService extends BaseService { + /** + * 获取活动所属党建单位 + * + * @Param activityId 活动ID + * @Return {@link List} + * @Author zhaoqifeng + * @Date 2022/2/21 14:36 + */ + List getUnitList(String activityId); + + /** + * 物理删除删除活动所属单位 + * + * @Param activityId + * @Return + * @Author zhaoqifeng + * @Date 2022/2/21 16:10 + */ + void deleteByActivity(String activityId); + + /** + * 逻辑删除删除活动所属单位 + * + * @Param activityId + * @Return + * @Author zhaoqifeng + * @Date 2022/2/21 16:10 + */ + void delete(String activityId); +} \ 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/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/LatestActServiceRelationService.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/LatestActServiceRelationService.java new file mode 100644 index 0000000000..6cc376aab0 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/LatestActServiceRelationService.java @@ -0,0 +1,44 @@ +package com.epmet.service; + +import com.epmet.commons.mybatis.service.BaseService; +import com.epmet.entity.LatestActServiceRelationEntity; + +import java.util.List; + +/** + * 联建活动与服务事项关联表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-02-21 + */ +public interface LatestActServiceRelationService extends BaseService { + /** + * 获取活动所属服务事项列表 + * + * @Param actId + * @Return {@link List < String>} + * @Author zhaoqifeng + * @Date 2022/2/22 14:53 + */ + List getServiceMatterList(String actId); + + /** + * 物理删除活动所属服务事项 + * + * @Param actId + * @Return + * @Author zhaoqifeng + * @Date 2022/2/22 14:54 + */ + void deleteByAct(String actId); + + /** + * 逻辑删除活动所属服务事项 + * + * @Param actId + * @Return + * @Author zhaoqifeng + * @Date 2022/2/22 14:54 + */ + void delete(String actId); +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/LatestActUnitRelationService.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/LatestActUnitRelationService.java new file mode 100644 index 0000000000..da31dc42ba --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/LatestActUnitRelationService.java @@ -0,0 +1,45 @@ +package com.epmet.service; + +import com.epmet.commons.mybatis.service.BaseService; +import com.epmet.entity.LatestActUnitRelationEntity; + +import java.util.List; + +/** + * 联建活动与单位关联表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-02-21 + */ +public interface LatestActUnitRelationService extends BaseService { + /** + * 获取活动所属联建单位列表 + * + * @Param actId + * @Return {@link List< String>} + * @Author zhaoqifeng + * @Date 2022/2/22 14:53 + */ + List getUnitList(String actId); + + /** + * 物理删除活动所属单位列表 + * + * @Param actId + * @Return + * @Author zhaoqifeng + * @Date 2022/2/22 14:54 + */ + void deleteByAct(String actId); + + /** + * 逻辑删除活动所属单位列表 + * + * @Param actId + * @Return + * @Author zhaoqifeng + * @Date 2022/2/22 14:54 + */ + void delete(String actId); + +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/ActInfoServiceImpl.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/ActInfoServiceImpl.java index e595bdd0c6..407cb74dac 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/ActInfoServiceImpl.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/ActInfoServiceImpl.java @@ -22,7 +22,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; import com.epmet.commons.tools.constant.FieldConstant; import com.epmet.commons.tools.constant.NumConstant; -import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.page.PageData; @@ -34,6 +33,7 @@ import com.epmet.dao.ActInfoDao; import com.epmet.dao.ActUserRelationDao; import com.epmet.dao.HeartUserInfoDao; import com.epmet.dto.ActInfoDTO; +import com.epmet.dto.IcPartyActivityDTO; import com.epmet.dto.IcPartyUnitDTO; import com.epmet.dto.form.resi.*; import com.epmet.dto.result.demand.OptionDTO; @@ -42,7 +42,6 @@ import com.epmet.entity.ActInfoEntity; import com.epmet.entity.ActUserRelationEntity; import com.epmet.service.*; import com.epmet.utils.CaculateDistance; -import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -77,6 +76,12 @@ public class ActInfoServiceImpl extends BaseServiceImpl page(Map params) { @@ -255,16 +260,26 @@ public class ActInfoServiceImpl extends BaseServiceImpl serviceItemList=icServiceItemDictService.queryDictList(tokenDto.getCustomerId()); - Map categoryMap=serviceItemList.stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel)); - detailResultDTO.setServiceMatterName(MapUtils.isNotEmpty(categoryMap) && categoryMap.containsKey(detailResultDTO.getServiceMatter()) ? categoryMap.get(detailResultDTO.getServiceMatter()) : StrConstant.EPMETY_STR); - } - if (StringUtils.isNotBlank(detailResultDTO.getUnitId())) { - //获取单位名称 - IcPartyUnitDTO unitDTO = icPartyUnitService.get(detailResultDTO.getUnitId()); - detailResultDTO.setUnitName(null != unitDTO ? unitDTO.getUnitName() : StrConstant.EPMETY_STR); + if (ActConstant.PARTY.equals(detailResultDTO.getActType())) { + IcPartyActivityDTO dto = icPartyActivityService.getActivityByActId(formDto.getActId()); + if (null != dto) { + //获取服务事项 + List serviceItemList = icServiceItemDictService.queryDictList(tokenDto.getCustomerId()); + Map categoryMap = serviceItemList.stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel)); + List services = icActivityServiceRelationService.getServiceList(dto.getId()); + List serviceNames = services.stream().map(categoryMap::get).collect(Collectors.toList()); + detailResultDTO.setServiceMatterList(services); + detailResultDTO.setServiceMatterNameList(serviceNames); + + //获取联建单位 + IcPartyUnitDTO unitDTO = new IcPartyUnitDTO(); + unitDTO.setAgencyId(dto.getAgencyId()); + Map option = icPartyUnitService.option(unitDTO).stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel)); + List unitIds = icActivityUnitRelationService.getUnitList(dto.getId()); + List unitNames = unitIds.stream().map(option::get).collect(Collectors.toList()); + detailResultDTO.setUnitIdList(unitIds); + detailResultDTO.setUnitNameList(unitNames); + } } return new Result().ok(detailResultDTO); } diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcActivityServiceRelationServiceImpl.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcActivityServiceRelationServiceImpl.java new file mode 100644 index 0000000000..b85129f293 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcActivityServiceRelationServiceImpl.java @@ -0,0 +1,78 @@ +package com.epmet.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.dao.IcActivityServiceRelationDao; +import com.epmet.entity.IcActivityServiceRelationEntity; +import com.epmet.service.IcActivityServiceRelationService; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 联建活动与服务事项关联表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-02-21 + */ +@Service +public class IcActivityServiceRelationServiceImpl extends BaseServiceImpl implements IcActivityServiceRelationService { + + + /** + * 获取活动所属服务事项 + * + * @param activityId + * @Param activityId 活动ID + * @Return {@link List } + * @Author zhaoqifeng + * @Date 2022/2/21 14:36 + */ + @Override + public List getServiceList(String activityId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(IcActivityServiceRelationEntity::getActivityId, activityId); + wrapper.orderByAsc(IcActivityServiceRelationEntity::getSort); + List list = baseDao.selectList(wrapper); + if (CollectionUtils.isEmpty(list)) { + return Collections.emptyList(); + } + return list.stream().map(IcActivityServiceRelationEntity::getServiceMatter).collect(Collectors.toList()); + } + + /** + * 删除活动所属服务事项 + * + * @param activityId + * @Param activityId + * @Return + * @Author zhaoqifeng + * @Date 2022/2/21 16:10 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteByActivity(String activityId) { + baseDao.deleteByActivity(activityId); + } + + /** + * 逻辑删除活动所属服务事项 + * + * @param activityId + * @Param activityId + * @Return + * @Author zhaoqifeng + * @Date 2022/2/21 16:10 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(String activityId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(IcActivityServiceRelationEntity::getActivityId, activityId); + baseDao.delete(wrapper); + } +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcActivityUnitRelationServiceImpl.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcActivityUnitRelationServiceImpl.java new file mode 100644 index 0000000000..d7bedf1d0b --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcActivityUnitRelationServiceImpl.java @@ -0,0 +1,77 @@ +package com.epmet.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.dao.IcActivityUnitRelationDao; +import com.epmet.entity.IcActivityUnitRelationEntity; +import com.epmet.service.IcActivityUnitRelationService; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 联建活动与单位关联表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-02-21 + */ +@Service +public class IcActivityUnitRelationServiceImpl extends BaseServiceImpl implements IcActivityUnitRelationService { + + /** + * 获取活动所属党建单位 + * + * @param activityId + * @Param activityId 活动ID + * @Return {@link List } + * @Author zhaoqifeng + * @Date 2022/2/21 14:36 + */ + @Override + public List getUnitList(String activityId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(IcActivityUnitRelationEntity::getActivityId, activityId); + wrapper.orderByAsc(IcActivityUnitRelationEntity::getSort); + List list = baseDao.selectList(wrapper); + if (CollectionUtils.isEmpty(list)) { + return Collections.emptyList(); + } + return list.stream().map(IcActivityUnitRelationEntity::getUnitId).collect(Collectors.toList()); + } + + /** + * 删除活动所属单位 + * + * @param activityId + * @Param activityId + * @Return + * @Author zhaoqifeng + * @Date 2022/2/21 16:10 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteByActivity(String activityId) { + baseDao.deleteByActivity(activityId); + } + + /** + * 逻辑删除删除活动所属单位 + * + * @param activityId + * @Param activityId + * @Return + * @Author zhaoqifeng + * @Date 2022/2/21 16:10 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(String activityId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(IcActivityUnitRelationEntity::getActivityId, activityId); + baseDao.delete(wrapper); + } +} \ 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..7dd0c6343e 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,53 @@ 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.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; +import org.springframework.web.multipart.commons.CommonsMultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.io.OutputStream; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @@ -64,12 +83,18 @@ import static com.epmet.commons.tools.utils.DateUtils.DATE_PATTERN; * @since v1.0.0 2021-11-18 */ @Service +@Slf4j +@EnableAsync 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 +387,9 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl testExcelImportResult = ExcelPoiUtils.importExcelMore(file, 0, 2, ImportCommunitySelfOrganization.class); List list = testExcelImportResult.getList(); @@ -410,7 +435,7 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl { @@ -446,6 +471,212 @@ 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); + log.warn("手机号码不合法,自组织名称{}", obj.getOrganizationName()); + } + 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(DateUtils.parse(l.getOrganizationCreatedTime(), DATE_PATTERN)); + + List persons = new ArrayList<>(); + AtomicReference bl = new AtomicReference<>(false); + StringBuffer msg = new StringBuffer(""); + if (CollectionUtils.isNotEmpty(l.getPersons())){ + l.getPersons().forEach(p -> { + boolean m = PhoneValidatorUtils.isMobile(p.getPersonPhone()); + boolean t = PhoneValidatorUtils.isTel(p.getPersonPhone()); + if (!m && !t){ + bl.set(true); + msg.append("自组织下成员手机号错误;"); + log.warn("自组织下成员手机号错误,自组织名称{}", l.getOrganizationName()); + return; + //throw new EpmetException(EpmetErrorCode.CHECK_PHONE_ERROR.getCode()); + } + }); + 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)){ + bl.set(true); + msg.append("自组织下成员手机号重复;"); + log.warn("自组织下成员手机号重复,自组织名称{}", l.getOrganizationName()); + /*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());*/ + } + } + if(bl.get()){ + CommunitySelfOrgImportExcel ex = new CommunitySelfOrgImportExcel(); + //ex.setAgencyName(l.getOrganizationName()); + ex.setSocietyName(l.getOrganizationName()); + ex.setErrorInfo(msg.toString()); + fileList.add(ex); + return; + } + baseDao.insert(e); + if(CollectionUtils.isNotEmpty(persons)){ + persons.forEach(p -> { + p.setCustomerId(tokenDto.getCustomerId()); + p.setOrgId(e.getId()); + }); + personnelService.insertBatch(persons); + } + + }); + } + //4.错误数据生成文件,修改导入任务状态 + String url = erroeImport(fileList); + upImportTask(url, taskId, tokenDto.getUserId(), true); + } catch (Exception e) { + String errorMsg = ExceptionUtils.getErrorStackTrace(e); + log.error("【社会自组织信息导入】程序错误:{}", errorMsg); + upImportTask(null, taskId, tokenDto.getUserId(), false); + } + } + /** + * @Author sun + * @Description 社会自组织导入,错误数据生成导入失败文件存到阿里云,修改导入任务为已结束 + **/ + private String erroeImport(List fileList) 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(); + } + return url; + } + /** + * @Author sun + * @Description 社会自组织导入修改导入任务状态 + **/ + private void upImportTask(String url, String importTaskId, String staffId, Boolean status) { + //2.更新导入任务数据 + ImportTaskCommonFormDTO importTaskForm = new ImportTaskCommonFormDTO(); + importTaskForm.setOperatorId(staffId); + importTaskForm.setBizType(ImportTaskConstants.BIZ_TYPE_PARTY_MEMBER); + importTaskForm.setTaskId(importTaskId); + importTaskForm.setResultDescFilePath(url); + if (status && StringUtils.isBlank(url)) { + importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS); + } else { + 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/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 4cea3f9136..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,14 +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.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; -import com.epmet.commons.tools.constant.FieldConstant; 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; @@ -32,30 +34,44 @@ 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.service.IcPartyActivityService; -import com.epmet.service.IcPartyUnitService; -import com.epmet.service.IcServiceItemDictService; +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; /** @@ -72,6 +88,14 @@ public class IcPartyActivityServiceImpl extends BaseServiceImpl wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(IcPartyActivityEntity::getAgencyId, formDTO.getAgencyId()); - wrapper.eq(StringUtils.isNotBlank(formDTO.getUnitId()), IcPartyActivityEntity::getUnitId, formDTO.getUnitId()); - wrapper.eq(StringUtils.isNotBlank(formDTO.getServiceMatter()), IcPartyActivityEntity::getServiceMatter, formDTO.getServiceMatter()); - wrapper.like(StringUtils.isNotBlank(formDTO.getTitle()), IcPartyActivityEntity::getTitle, formDTO.getTitle()); - wrapper.between(IcPartyActivityEntity::getActivityTime, formDTO.getStartTime(), formDTO.getEndTime()); - wrapper.orderByDesc(IcPartyActivityEntity::getUpdatedTime); - List list = baseDao.selectList(wrapper); + List list = baseDao.selectActivityList(formDTO); PageInfo pageInfo = new PageInfo<>(list); List dtoList = ConvertUtils.sourceToTarget(list, IcPartyActivityDTO.class); - IcPartyUnitDTO unitDTO = new IcPartyUnitDTO(); - unitDTO.setAgencyId(formDTO.getAgencyId()); if (CollectionUtils.isNotEmpty(dtoList)) { + //获取组织下联建单位 + IcPartyUnitDTO unitDTO = new IcPartyUnitDTO(); + unitDTO.setAgencyId(formDTO.getAgencyId()); Map option = icPartyUnitService.option(unitDTO).stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel)); dtoList.forEach(dto -> { - dto.setUnitName(option.get(dto.getUnitId())); + //联建单位ID与单位名匹配 + List unitIds = Arrays.asList(dto.getUnitId().split(StrConstant.COMMA)); + List unitNames = unitIds.stream().map(option::get).collect(Collectors.toList()); + dto.setUnitName(StringUtils.join(unitNames, StrConstant.COMMA)); }); } @@ -118,54 +139,49 @@ public class IcPartyActivityServiceImpl extends BaseServiceImpl wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(IcPartyActivityEntity::getAgencyId, formDTO.getAgencyId()); - wrapper.eq(StringUtils.isNotBlank(formDTO.getUnitId()), IcPartyActivityEntity::getUnitId, formDTO.getUnitId()); - wrapper.eq(StringUtils.isNotBlank(formDTO.getServiceMatter()), IcPartyActivityEntity::getServiceMatter, formDTO.getServiceMatter()); - wrapper.like(StringUtils.isNotBlank(formDTO.getTitle()), IcPartyActivityEntity::getTitle, formDTO.getTitle()); - wrapper.between(IcPartyActivityEntity::getActivityTime, formDTO.getStartTime(), formDTO.getEndTime()); - wrapper.orderByDesc(IcPartyActivityEntity::getUpdatedTime); - List list = baseDao.selectList(wrapper); + List list = baseDao.selectActivityList(formDTO); List dtoList = ConvertUtils.sourceToTarget(list, IcPartyActivityDTO.class); - IcPartyUnitDTO unitDTO = new IcPartyUnitDTO(); - unitDTO.setAgencyId(formDTO.getAgencyId()); if (CollectionUtils.isNotEmpty(dtoList)) { + IcPartyUnitDTO unitDTO = new IcPartyUnitDTO(); + unitDTO.setAgencyId(formDTO.getAgencyId()); Map option = icPartyUnitService.option(unitDTO).stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel)); dtoList.forEach(dto -> { - dto.setUnitName(option.get(dto.getUnitId())); + List unitIds = Arrays.asList(dto.getUnitId().split(StrConstant.COMMA)); + List unitNames = unitIds.stream().map(option::get).collect(Collectors.toList()); + dto.setUnitName(StringUtils.join(unitNames, StrConstant.COMMA)); }); } return dtoList; } - private QueryWrapper getWrapper(Map params){ - String id = (String)params.get(FieldConstant.ID_HUMP); - - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); - - return wrapper; - } - @Override public IcPartyActivityDTO get(String id) { IcPartyActivityEntity entity = baseDao.selectById(id); if (null == entity) { return null; } - //获取服务事项名称 + IcPartyActivityDTO dto = ConvertUtils.sourceToTarget(entity, IcPartyActivityDTO.class); + + //获取服务事项 List serviceItemList=icServiceItemDictService.queryDictList(entity.getCustomerId()); Map categoryMap=serviceItemList.stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel)); + List services = icActivityServiceRelationService.getServiceList(id); + List serviceNames = services.stream().map(categoryMap::get).collect(Collectors.toList()); + dto.setServiceMatterList(services); + dto.setServiceMatterNameList(serviceNames); + + //获取单位 + //获取组织下联建单位 + IcPartyUnitDTO unitDTO = new IcPartyUnitDTO(); + unitDTO.setAgencyId(entity.getAgencyId()); + Map option = icPartyUnitService.option(unitDTO).stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel)); + List unitIds = icActivityUnitRelationService.getUnitList(id); + List unitNames = unitIds.stream().map(option::get).collect(Collectors.toList()); + dto.setUnitIdList(unitIds); + dto.setUnitNameList(unitNames); - IcPartyActivityDTO dto = ConvertUtils.sourceToTarget(entity, IcPartyActivityDTO.class); - dto.setServiceMatterName(categoryMap.get(dto.getServiceMatter())); - //获取单位名称 - IcPartyUnitDTO unitDTO = icPartyUnitService.get(dto.getUnitId()); - if (null != unitDTO) { - dto.setUnitName(unitDTO.getUnitName()); - } return dto; } @@ -182,6 +198,35 @@ public class IcPartyActivityServiceImpl extends BaseServiceImpl unitRelationList = dto.getUnitIdList().stream().map(unitId -> { + IcActivityUnitRelationEntity relation = new IcActivityUnitRelationEntity(); + relation.setCustomerId(entity.getCustomerId()); + relation.setAgencyId(entity.getAgencyId()); + relation.setPids(entity.getPids()); + relation.setActivityId(entity.getId()); + relation.setUnitId(unitId); + relation.setSort(i.getAndIncrement()); + return relation; + }).collect(Collectors.toList()); + icActivityUnitRelationService.insertBatch(unitRelationList); + + //保存活动与服务关系 + icActivityServiceRelationService.deleteByActivity(entity.getId()); + AtomicInteger j = new AtomicInteger(NumConstant.ONE); + List serviceRelationList = dto.getServiceMatterList().stream().map(service -> { + IcActivityServiceRelationEntity relation = new IcActivityServiceRelationEntity(); + relation.setCustomerId(entity.getCustomerId()); + relation.setAgencyId(entity.getAgencyId()); + relation.setPids(entity.getPids()); + relation.setActivityId(entity.getId()); + relation.setServiceMatter(service); + relation.setSort(j.getAndIncrement()); + return relation; + }).collect(Collectors.toList()); + icActivityServiceRelationService.insertBatch(serviceRelationList); } @Override @@ -189,6 +234,8 @@ 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(); @@ -234,72 +283,201 @@ public class IcPartyActivityServiceImpl extends BaseServiceImpl%s", obj.getRowNum())); iterator.remove(); - } else if (null == option.get(obj.getUnitName())){ - numList.add(obj.getRowNum()); - log.warn(String.format("单位名称不存在,行号->%s", obj.getRowNum())); - iterator.remove(); + } else { + List unitList = Arrays.asList(obj.getUnitName().split(StrConstant.COMMA)); + unitList.forEach(unit -> { + if (null == option.get(unit)) { + IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class); + failed.setErrorInfo("单位名称不存在"); + fileList.add(failed); + log.warn(String.format("单位名称不存在,行号->%s", obj.getRowNum())); + iterator.remove(); + } + }); } //服务事项校验 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 if (null == categoryMap.get(obj.getServiceMatter())){ - numList.add(obj.getRowNum()); - log.warn(String.format("服务事项不存在,行号->%s", obj.getRowNum())); - iterator.remove(); + } else { + List serviceList = Arrays.asList(obj.getServiceMatter().split(StrConstant.SEMICOLON)); + serviceList.forEach(service -> { + if (null == categoryMap.get(service)) { + IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class); + failed.setErrorInfo("服务事项不存在"); + fileList.add(failed); + log.warn(String.format("服务事项不存在,行号->%s", obj.getRowNum())); + iterator.remove(); + } + }); + } //活动标题 活动目标 活动内容 活动时间 活动地址 活动地址经度 活动地址纬度 活动结果 - 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); + 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()); + + 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("、")); - return new Result().error(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "第" + subList + "行未成功!"); + log.warn(str + "第" + subList + "行未成功!"); } - List list = result.stream().map(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.setUnitId(option.get(item.getUnitName())); - entity.setServiceMatter(categoryMap.get(item.getServiceMatter())); - 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()); - return entity; - }).collect(Collectors.toList()); + //错误数据生成文件,修改导入任务状态 + erroeImport(fileList, taskId, tokenDto.getUserId()); + } - insertBatch(list); + 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); + } + } - 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 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 + "行未成功!"); + 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()); } - return new Result().ok(str); } /** @@ -347,14 +525,7 @@ public class IcPartyActivityServiceImpl extends BaseServiceImpl wrapper = new LambdaQueryWrapper<>(); - wrapper.and(wp -> wp.eq(IcPartyActivityEntity::getAgencyId, formDTO.getAgencyId()).or(). - like(IcPartyActivityEntity::getPids, formDTO.getAgencyId())); - wrapper.eq(StringUtils.isNotBlank(formDTO.getServiceMatter()), IcPartyActivityEntity::getServiceMatter, formDTO.getServiceMatter()); - wrapper.ge(null != formDTO.getStartTime(),IcPartyActivityEntity::getActivityTime, formDTO.getStartTime()); - wrapper.le(null != formDTO.getEndTime(), IcPartyActivityEntity::getActivityTime, formDTO.getEndTime()); - wrapper.orderByDesc(IcPartyActivityEntity::getActivityTime); - List list = baseDao.selectList(wrapper); + List list = baseDao.getActivityList(formDTO); List dtoList = ConvertUtils.sourceToTarget(list, IcPartyActivityDTO.class); IcPartyUnitDTO unitDTO = new IcPartyUnitDTO(); @@ -367,8 +538,15 @@ public class IcPartyActivityServiceImpl extends BaseServiceImpl categoryMap=serviceItemList.stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel)); //数据组装 dtoList.forEach(dto -> { - dto.setServiceMatterName(categoryMap.get(dto.getServiceMatter())); - dto.setUnitName(option.get(dto.getUnitId())); + //联建单位ID与单位名匹配 + List unitIds = Arrays.asList(dto.getUnitId().split(StrConstant.COMMA)); + List unitNames = unitIds.stream().map(option::get).collect(Collectors.toList()); + dto.setUnitName(StringUtils.join(unitNames, StrConstant.COMMA)); + + //服务事项与服务事项名匹配 + List services = Arrays.asList(dto.getServiceMatter().split(StrConstant.COMMA)); + List serviceNames = services.stream().map(categoryMap::get).collect(Collectors.toList()); + dto.setServiceMatterName(StringUtils.join(serviceNames, StrConstant.SEMICOLON)); }); } PageInfo pageInfo = new PageInfo<>(dtoList); 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 按类型统计单位数量 diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/LatestActInfoServiceImpl.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/LatestActInfoServiceImpl.java index 3ff7ce31bf..dd5a9d994d 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/LatestActInfoServiceImpl.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/LatestActInfoServiceImpl.java @@ -31,6 +31,8 @@ import com.epmet.entity.LatestActInfoEntity; import com.epmet.redis.LatestActInfoRedis; import com.epmet.service.LatestActContentService; import com.epmet.service.LatestActInfoService; +import com.epmet.service.LatestActServiceRelationService; +import com.epmet.service.LatestActUnitRelationService; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -38,6 +40,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.annotation.Resource; import java.util.Arrays; import java.util.Date; import java.util.List; @@ -56,6 +59,10 @@ public class LatestActInfoServiceImpl extends BaseServiceImpl page(Map params) { @@ -158,6 +165,8 @@ public class LatestActInfoServiceImpl extends BaseServiceImpl implements LatestActServiceRelationService { + + + /** + * 获取活动所属服务事项列表 + * + * @param actId + * @Param actId + * @Return {@link List < String>} + * @Author zhaoqifeng + * @Date 2022/2/22 14:53 + */ + @Override + public List getServiceMatterList(String actId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(LatestActServiceRelationEntity::getActId, actId); + wrapper.orderByAsc(LatestActServiceRelationEntity::getSort); + List list = baseDao.selectList(wrapper); + if (CollectionUtils.isEmpty(list)) { + return Collections.emptyList(); + } + return list.stream().map(LatestActServiceRelationEntity::getServiceMatter).collect(Collectors.toList()); + } + + /** + * 删除活动所属服务事项 + * + * @param actId + * @Param actId + * @Return + * @Author zhaoqifeng + * @Date 2022/2/22 14:54 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteByAct(String actId) { + baseDao.deleteByActivity(actId); + } + + /** + * 逻辑删除活动所属服务事项 + * + * @param actId + * @Param actId + * @Return + * @Author zhaoqifeng + * @Date 2022/2/22 14:54 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(String actId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(LatestActServiceRelationEntity::getActId, actId); + baseDao.delete(wrapper); + } +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/LatestActUnitRelationServiceImpl.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/LatestActUnitRelationServiceImpl.java new file mode 100644 index 0000000000..ceaa0ff9a6 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/LatestActUnitRelationServiceImpl.java @@ -0,0 +1,78 @@ +package com.epmet.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.dao.LatestActUnitRelationDao; +import com.epmet.entity.LatestActUnitRelationEntity; +import com.epmet.service.LatestActUnitRelationService; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 联建活动与单位关联表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-02-21 + */ +@Service +public class LatestActUnitRelationServiceImpl extends BaseServiceImpl implements LatestActUnitRelationService { + + + /** + * 获取活动所属联建单位列表 + * + * @param actId + * @Param actId + * @Return {@link List < String>} + * @Author zhaoqifeng + * @Date 2022/2/22 14:53 + */ + @Override + public List getUnitList(String actId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(LatestActUnitRelationEntity::getActId, actId); + wrapper.orderByAsc(LatestActUnitRelationEntity::getSort); + List list = baseDao.selectList(wrapper); + if (CollectionUtils.isEmpty(list)) { + return Collections.emptyList(); + } + return list.stream().map(LatestActUnitRelationEntity::getUnitId).collect(Collectors.toList()); + } + + /** + * 删除活动所属单位列表 + * + * @param actId + * @Param actId + * @Return + * @Author zhaoqifeng + * @Date 2022/2/22 14:54 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteByAct(String actId) { + baseDao.deleteByActivity(actId); + } + + /** + * 逻辑删除活动所属单位列表 + * + * @param actId + * @Param actId + * @Return + * @Author zhaoqifeng + * @Date 2022/2/22 14:54 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(String actId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(LatestActUnitRelationEntity::getActId, actId); + baseDao.delete(wrapper); + } +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/WorkActDraftServiceImpl.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/WorkActDraftServiceImpl.java index 5572a48f48..1273ffa577 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/WorkActDraftServiceImpl.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/WorkActDraftServiceImpl.java @@ -1,8 +1,10 @@ package com.epmet.service.impl; +import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.security.user.LoginUserUtil; import com.epmet.commons.tools.utils.DateUtils; +import com.epmet.constant.ActConstant; import com.epmet.dto.IcPartyUnitDTO; import com.epmet.dto.LatestActContentDTO; import com.epmet.dto.LatestActInfoDTO; @@ -11,6 +13,8 @@ import com.epmet.dto.form.work.DraftActContentFormDTO; import com.epmet.dto.form.work.DraftActInfoFormDTO; import com.epmet.dto.result.demand.OptionDTO; import com.epmet.dto.result.work.*; +import com.epmet.entity.LatestActServiceRelationEntity; +import com.epmet.entity.LatestActUnitRelationEntity; import com.epmet.service.*; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; @@ -24,6 +28,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; /** @@ -45,7 +50,10 @@ public class WorkActDraftServiceImpl implements WorkActDraftService { private IcServiceItemDictService icServiceItemDictService; @Resource private IcPartyUnitService icPartyUnitService; - + @Resource + private LatestActServiceRelationService latestActServiceRelationService; + @Resource + private LatestActUnitRelationService latestActUnitRelationService; /** * @return com.epmet.dto.form.work.PublishActInitResultDTO @@ -86,6 +94,10 @@ public class WorkActDraftServiceImpl implements WorkActDraftService { if(null!=latestAct){ List actContentList=latestActContentService.selectActContentList(latestAct.getActDraftId()); latestAct.setActContent(actContentList); + List unitList = latestActUnitRelationService.getUnitList(latestAct.getActDraftId()); + latestAct.setUnitIdList(unitList); + List serviceList = latestActServiceRelationService.getServiceMatterList(latestAct.getActDraftId()); + latestAct.setServiceMatterList(serviceList); } return latestAct; }else{ @@ -116,6 +128,32 @@ public class WorkActDraftServiceImpl implements WorkActDraftService { } SaveActDraftResultDTO resultDTO=new SaveActDraftResultDTO(); resultDTO.setActDraftId(actDraftId); + + //保存活动与服务关系 + latestActServiceRelationService.deleteByAct(actDraftId); + AtomicInteger i = new AtomicInteger(NumConstant.ONE); + List serviceList = formDTO.getServiceMatterList().stream().map(service -> { + LatestActServiceRelationEntity entity = new LatestActServiceRelationEntity(); + entity.setCustomerId(formDTO.getCustomerId()); + entity.setActId(actDraftId); + entity.setServiceMatter(service); + entity.setSort(i.getAndIncrement()); + return entity; + }).collect(Collectors.toList()); + latestActServiceRelationService.insertBatch(serviceList); + + //保存活动与单位关系 + latestActUnitRelationService.deleteByAct(actDraftId); + AtomicInteger j = new AtomicInteger(NumConstant.ONE); + List unitList = formDTO.getUnitIdList().stream().map(unitId -> { + LatestActUnitRelationEntity entity = new LatestActUnitRelationEntity(); + entity.setCustomerId(formDTO.getCustomerId()); + entity.setActId(actDraftId); + entity.setUnitId(unitId); + entity.setSort(j.getAndIncrement()); + return entity; + }).collect(Collectors.toList()); + latestActUnitRelationService.insertBatch(unitList); return resultDTO; } @@ -146,6 +184,24 @@ public class WorkActDraftServiceImpl implements WorkActDraftService { IcPartyUnitDTO unitDTO = icPartyUnitService.get(actPreviewResultDTO.getUnitId()); actPreviewResultDTO.setUnitName(unitDTO.getUnitName()); } + if (ActConstant.PARTY.equals(actPreviewResultDTO.getActType())) { + //获取服务事项 + List serviceItemList = icServiceItemDictService.queryDictList(formDTO.getCustomerId()); + Map categoryMap = serviceItemList.stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel)); + List services = latestActServiceRelationService.getServiceMatterList(formDTO.getActDraftId()); + List serviceNames = services.stream().map(categoryMap::get).collect(Collectors.toList()); + actPreviewResultDTO.setServiceMatterList(services); + actPreviewResultDTO.setServiceMatterNameList(serviceNames); + + //获取联建单位 + IcPartyUnitDTO unitDTO = new IcPartyUnitDTO(); + unitDTO.setAgencyId(ActConstant.SPONSOR_AGENCY.equals(actPreviewResultDTO.getSponsorType())?actPreviewResultDTO.getSponsorId():actPreviewResultDTO.getPid()); + Map option = icPartyUnitService.option(unitDTO).stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel)); + List unitIds = latestActUnitRelationService.getUnitList(formDTO.getActDraftId()); + List unitNames = unitIds.stream().map(option::get).collect(Collectors.toList()); + actPreviewResultDTO.setUnitIdList(unitIds); + actPreviewResultDTO.setUnitNameList(unitNames); + } } return actPreviewResultDTO; } @@ -280,9 +336,7 @@ public class WorkActDraftServiceImpl implements WorkActDraftService { latestActInfoDTO.setAuditSwitch(formDTO.getAuditSwitch()); latestActInfoDTO.setActType(formDTO.getActType()); - latestActInfoDTO.setUnitId(formDTO.getUnitId()); latestActInfoDTO.setTarget(formDTO.getTarget()); - latestActInfoDTO.setServiceMatter(formDTO.getServiceMatter()); return latestActInfoDTO; } diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/WorkActServiceImpl.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/WorkActServiceImpl.java index 7b076059b9..7ab8dc2e52 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/WorkActServiceImpl.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/WorkActServiceImpl.java @@ -33,7 +33,6 @@ import com.epmet.entity.*; import com.epmet.feign.EpmetMessageOpenFeignClient; import com.epmet.feign.GovOrgOpenFeignClient; import com.epmet.service.*; -import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -44,6 +43,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @@ -102,6 +102,10 @@ public class WorkActServiceImpl implements WorkActService { private IcPartyUnitService icPartyUnitService; @Resource private IcServiceItemDictService icServiceItemDictService; + @Resource + private IcActivityUnitRelationService icActivityUnitRelationService; + @Resource + private IcActivityServiceRelationService icActivityServiceRelationService; /** @@ -232,6 +236,36 @@ public class WorkActServiceImpl implements WorkActService { if (ActConstant.PARTY.equals(formDTO.getActType())) { IcPartyActivityEntity activity = getPartyActivityEntity(formDTO, actInfoEntity); icPartyActivityService.insert(activity); + + //保存活动与单位关系 + icActivityUnitRelationService.deleteByActivity(activity.getId()); + AtomicInteger i = new AtomicInteger(NumConstant.ONE); + List unitRelationList = formDTO.getUnitIdList().stream().map(unitId -> { + IcActivityUnitRelationEntity relation = new IcActivityUnitRelationEntity(); + relation.setCustomerId(activity.getCustomerId()); + relation.setAgencyId(activity.getAgencyId()); + relation.setPids(activity.getPids()); + relation.setActivityId(activity.getId()); + relation.setUnitId(unitId); + relation.setSort(i.getAndIncrement()); + return relation; + }).collect(Collectors.toList()); + icActivityUnitRelationService.insertBatch(unitRelationList); + + //保存活动与服务关系 + icActivityServiceRelationService.deleteByActivity(activity.getId()); + AtomicInteger j = new AtomicInteger(NumConstant.ONE); + List serviceRelationList = formDTO.getServiceMatterList().stream().map(service -> { + IcActivityServiceRelationEntity relation = new IcActivityServiceRelationEntity(); + relation.setCustomerId(activity.getCustomerId()); + relation.setAgencyId(activity.getAgencyId()); + relation.setPids(activity.getPids()); + relation.setActivityId(activity.getId()); + relation.setServiceMatter(service); + relation.setSort(j.getAndIncrement()); + return relation; + }).collect(Collectors.toList()); + icActivityServiceRelationService.insertBatch(serviceRelationList); } return publishActResultDTO; @@ -779,17 +813,26 @@ public class WorkActServiceImpl implements WorkActService { canceledActDetailResultDTO.setIsMyPublish(false); } - if (StringUtils.isNotBlank(canceledActDetailResultDTO.getServiceMatter())) { - //获取服务事项 - List serviceItemList = icServiceItemDictService.queryDictList(customerId); - Map categoryMap = serviceItemList.stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel)); - canceledActDetailResultDTO.setServiceMatterName(MapUtils.isNotEmpty(categoryMap) && categoryMap.containsKey(canceledActDetailResultDTO.getServiceMatter()) ? - categoryMap.get(canceledActDetailResultDTO.getServiceMatter()) : StrConstant.EPMETY_STR); - } - if (StringUtils.isNotBlank(canceledActDetailResultDTO.getUnitId())) { - //获取单位名称 - IcPartyUnitDTO unitDTO = icPartyUnitService.get(canceledActDetailResultDTO.getUnitId()); - canceledActDetailResultDTO.setUnitName(unitDTO.getUnitName()); + if (ActConstant.PARTY.equals(canceledActDetailResultDTO.getActType())) { + IcPartyActivityDTO dto = icPartyActivityService.getActivityByActId(actId); + if (null != dto) { + //获取服务事项 + List serviceItemList = icServiceItemDictService.queryDictList(customerId); + Map categoryMap = serviceItemList.stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel)); + List services = icActivityServiceRelationService.getServiceList(dto.getId()); + List serviceNames = services.stream().map(categoryMap::get).collect(Collectors.toList()); + canceledActDetailResultDTO.setServiceMatterList(services); + canceledActDetailResultDTO.setServiceMatterNameList(serviceNames); + + //获取联建单位 + IcPartyUnitDTO unitDTO = new IcPartyUnitDTO(); + unitDTO.setAgencyId(dto.getAgencyId()); + Map option = icPartyUnitService.option(unitDTO).stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel)); + List unitIds = icActivityUnitRelationService.getUnitList(dto.getId()); + List unitNames = unitIds.stream().map(option::get).collect(Collectors.toList()); + canceledActDetailResultDTO.setUnitIdList(unitIds); + canceledActDetailResultDTO.setUnitNameList(unitNames); + } } } return canceledActDetailResultDTO; @@ -835,17 +878,26 @@ public class WorkActServiceImpl implements WorkActService { }else{ resultDTO.setIsMyPublish(false); } - - if (StringUtils.isNotBlank(resultDTO.getServiceMatter())) { - //获取服务事项 - List serviceItemList = icServiceItemDictService.queryDictList(formDTO.getCustomerId()); - Map categoryMap = serviceItemList.stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel)); - resultDTO.setServiceMatterName(MapUtils.isNotEmpty(categoryMap) && categoryMap.containsKey(resultDTO.getServiceMatter()) ? categoryMap.get(resultDTO.getServiceMatter()) : StrConstant.EPMETY_STR); - } - if (StringUtils.isNotBlank(resultDTO.getUnitId())) { - //获取单位名称 - IcPartyUnitDTO unitDTO = icPartyUnitService.get(resultDTO.getUnitId()); - resultDTO.setUnitName(unitDTO.getUnitName()); + if (ActConstant.PARTY.equals(resultDTO.getActType())) { + IcPartyActivityDTO dto = icPartyActivityService.getActivityByActId(formDTO.getActId()); + if (null != dto) { + //获取服务事项 + List serviceItemList = icServiceItemDictService.queryDictList(formDTO.getCustomerId()); + Map categoryMap = serviceItemList.stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel)); + List services = icActivityServiceRelationService.getServiceList(dto.getId()); + List serviceNames = services.stream().map(categoryMap::get).collect(Collectors.toList()); + resultDTO.setServiceMatterList(services); + resultDTO.setServiceMatterNameList(serviceNames); + + //获取联建单位 + IcPartyUnitDTO unitDTO = new IcPartyUnitDTO(); + unitDTO.setAgencyId(dto.getAgencyId()); + Map option = icPartyUnitService.option(unitDTO).stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel)); + List unitIds = icActivityUnitRelationService.getUnitList(dto.getId()); + List unitNames = unitIds.stream().map(option::get).collect(Collectors.toList()); + resultDTO.setUnitIdList(unitIds); + resultDTO.setUnitNameList(unitNames); + } } } return resultDTO; @@ -915,16 +967,26 @@ public class WorkActServiceImpl implements WorkActService { }else{ resultDTO.setIsMyPublish(false); } - if (StringUtils.isNotBlank(resultDTO.getServiceMatter())) { - //获取服务事项 - List serviceItemList=icServiceItemDictService.queryDictList(customerId); - Map categoryMap=serviceItemList.stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel)); - resultDTO.setServiceMatterName(MapUtils.isNotEmpty(categoryMap) && categoryMap.containsKey(resultDTO.getServiceMatter()) ? categoryMap.get(resultDTO.getServiceMatter()) : StrConstant.EPMETY_STR); - } - if (StringUtils.isNotBlank(resultDTO.getUnitId())) { - //获取单位名称 - IcPartyUnitDTO unitDTO = icPartyUnitService.get(resultDTO.getUnitId()); - resultDTO.setUnitName(unitDTO.getUnitName()); + if (ActConstant.PARTY.equals(resultDTO.getActType())) { + IcPartyActivityDTO dto = icPartyActivityService.getActivityByActId(actId); + if (null != dto) { + //获取服务事项 + List serviceItemList = icServiceItemDictService.queryDictList(customerId); + Map categoryMap = serviceItemList.stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel)); + List services = icActivityServiceRelationService.getServiceList(dto.getId()); + List serviceNames = services.stream().map(categoryMap::get).collect(Collectors.toList()); + resultDTO.setServiceMatterList(services); + resultDTO.setServiceMatterNameList(serviceNames); + + //获取联建单位 + IcPartyUnitDTO unitDTO = new IcPartyUnitDTO(); + unitDTO.setAgencyId(dto.getAgencyId()); + Map option = icPartyUnitService.option(unitDTO).stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel)); + List unitIds = icActivityUnitRelationService.getUnitList(dto.getId()); + List unitNames = unitIds.stream().map(option::get).collect(Collectors.toList()); + resultDTO.setUnitIdList(unitIds); + resultDTO.setUnitNameList(unitNames); + } } } return resultDTO; @@ -1309,16 +1371,26 @@ public class WorkActServiceImpl implements WorkActService { List actContent=actContentDao.selectByActId(actId); resultDTO.setActContent(actContent); - if (StringUtils.isNotBlank(resultDTO.getServiceMatter())) { - //获取服务事项 - List serviceItemList=icServiceItemDictService.queryDictList(customerId); - Map categoryMap=serviceItemList.stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel)); - resultDTO.setServiceMatterName(MapUtils.isNotEmpty(categoryMap) && categoryMap.containsKey(resultDTO.getServiceMatter()) ? categoryMap.get(resultDTO.getServiceMatter()) : StrConstant.EPMETY_STR); - } - if (StringUtils.isNotBlank(resultDTO.getUnitId())) { - //获取单位名称 - IcPartyUnitDTO unitDTO = icPartyUnitService.get(resultDTO.getUnitId()); - resultDTO.setUnitName(unitDTO.getUnitName()); + if (ActConstant.PARTY.equals(resultDTO.getActType())) { + IcPartyActivityDTO dto = icPartyActivityService.getActivityByActId(actId); + if (null != dto) { + //获取服务事项 + List serviceItemList = icServiceItemDictService.queryDictList(customerId); + Map categoryMap = serviceItemList.stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel)); + List services = icActivityServiceRelationService.getServiceList(dto.getId()); + List serviceNames = services.stream().map(categoryMap::get).collect(Collectors.toList()); + resultDTO.setServiceMatterList(services); + resultDTO.setServiceMatterNameList(serviceNames); + + //获取联建单位 + IcPartyUnitDTO unitDTO = new IcPartyUnitDTO(); + unitDTO.setAgencyId(dto.getAgencyId()); + Map option = icPartyUnitService.option(unitDTO).stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel)); + List unitIds = icActivityUnitRelationService.getUnitList(dto.getId()); + List unitNames = unitIds.stream().map(option::get).collect(Collectors.toList()); + resultDTO.setUnitIdList(unitIds); + resultDTO.setUnitNameList(unitNames); + } } return resultDTO; @@ -1438,6 +1510,36 @@ public class WorkActServiceImpl implements WorkActService { IcPartyActivityEntity activity = getPartyActivityEntity(ConvertUtils.sourceToTarget(rePublishFormDTO, PublishActInfoFormDTO.class), newActInfoEntity); activity.setId(activityDTO.getId()); icPartyActivityService.updateById(activity); + + //保存活动与单位关系 + icActivityUnitRelationService.deleteByActivity(activity.getId()); + AtomicInteger i = new AtomicInteger(NumConstant.ONE); + List unitRelationList = rePublishFormDTO.getUnitIdList().stream().map(unitId -> { + IcActivityUnitRelationEntity relation = new IcActivityUnitRelationEntity(); + relation.setCustomerId(activityDTO.getCustomerId()); + relation.setAgencyId(activityDTO.getAgencyId()); + relation.setPids(activityDTO.getPids()); + relation.setActivityId(activityDTO.getId()); + relation.setUnitId(unitId); + relation.setSort(i.getAndIncrement()); + return relation; + }).collect(Collectors.toList()); + icActivityUnitRelationService.insertBatch(unitRelationList); + + //保存活动与服务关系 + icActivityServiceRelationService.deleteByActivity(activity.getId()); + AtomicInteger j = new AtomicInteger(NumConstant.ONE); + List serviceRelationList = rePublishFormDTO.getServiceMatterList().stream().map(service -> { + IcActivityServiceRelationEntity relation = new IcActivityServiceRelationEntity(); + relation.setCustomerId(activityDTO.getCustomerId()); + relation.setAgencyId(activityDTO.getAgencyId()); + relation.setPids(activityDTO.getPids()); + relation.setActivityId(activityDTO.getId()); + relation.setServiceMatter(service); + relation.setSort(j.getAndIncrement()); + return relation; + }).collect(Collectors.toList()); + icActivityServiceRelationService.insertBatch(serviceRelationList); } } @@ -1462,8 +1564,6 @@ public class WorkActServiceImpl implements WorkActService { logger.warn("根据agencyId查询组织信息失败,agencyId={}",formDTO.getSponsorId()); } entity.setActId(actInfoEntity.getId()); - entity.setUnitId(actInfoEntity.getUnitId()); - entity.setServiceMatter(actInfoEntity.getServiceMatter()); entity.setTitle(actInfoEntity.getTitle()); entity.setTarget(actInfoEntity.getTarget()); entity.setContent(getContent(formDTO.getActContent())); diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/db/migration/V0.0.11__ic_party_change.sql b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/db/migration/V0.0.11__ic_party_change.sql new file mode 100644 index 0000000000..ad3305d8f3 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/db/migration/V0.0.11__ic_party_change.sql @@ -0,0 +1,68 @@ +CREATE TABLE `ic_activity_service_relation` ( + `ID` varchar(64) NOT NULL COMMENT '主键', + `CUSTOMER_ID` varchar(64) NOT NULL COMMENT '客户id', + `AGENCY_ID` varchar(64) NOT NULL COMMENT '组织ID', + `PIDS` varchar(255) DEFAULT NULL COMMENT '组织的所有上级', + `ACTIVITY_ID` varchar(32) NOT NULL COMMENT '活动ID', + `ACT_ID` varchar(64) DEFAULT NULL COMMENT 'act_info表ID', + `SERVICE_MATTER` varchar(32) NOT NULL DEFAULT '1' COMMENT '服务事项', + `SORT` int(4) DEFAULT NULL COMMENT '排序', + `DEL_FLAG` varchar(1) NOT NULL DEFAULT '0' COMMENT '删除标识 0未删除、1已删除', + `REVISION` int(11) NOT NULL DEFAULT '0' COMMENT '乐观锁', + `CREATED_BY` varchar(32) NOT NULL COMMENT '创建人', + `CREATED_TIME` datetime NOT NULL COMMENT '创建时间', + `UPDATED_BY` varchar(32) NOT NULL COMMENT '更新人', + `UPDATED_TIME` datetime NOT NULL COMMENT '更新时间', + PRIMARY KEY (`ID`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='联建活动与服务事项关联表'; +CREATE TABLE `ic_activity_unit_relation` ( + `ID` varchar(64) NOT NULL COMMENT '主键', + `CUSTOMER_ID` varchar(64) NOT NULL COMMENT '客户id', + `AGENCY_ID` varchar(64) NOT NULL COMMENT '组织ID', + `PIDS` varchar(255) DEFAULT NULL COMMENT '组织的所有上级', + `ACTIVITY_ID` varchar(32) NOT NULL COMMENT '活动ID', + `ACT_ID` varchar(64) DEFAULT NULL COMMENT 'act_info表ID', + `UNIT_ID` varchar(32) NOT NULL COMMENT '单位ID', + `SORT` int(4) DEFAULT '1' COMMENT '排序', + `DEL_FLAG` varchar(1) NOT NULL DEFAULT '0' COMMENT '删除标识 0未删除、1已删除', + `REVISION` int(11) NOT NULL DEFAULT '0' COMMENT '乐观锁', + `CREATED_BY` varchar(32) NOT NULL COMMENT '创建人', + `CREATED_TIME` datetime NOT NULL COMMENT '创建时间', + `UPDATED_BY` varchar(32) NOT NULL COMMENT '更新人', + `UPDATED_TIME` datetime NOT NULL COMMENT '更新时间', + PRIMARY KEY (`ID`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='联建活动与单位关联表'; +CREATE TABLE `latest_act_service_relation` ( + `ID` varchar(64) NOT NULL COMMENT '主键', + `CUSTOMER_ID` varchar(64) NOT NULL COMMENT '客户id', + `ACT_ID` varchar(64) DEFAULT NULL COMMENT 'latest_act_info表ID', + `SERVICE_MATTER` varchar(32) NOT NULL COMMENT '服务事项', + `SORT` int(4) DEFAULT '1' COMMENT '排序', + `DEL_FLAG` varchar(1) NOT NULL DEFAULT '0' COMMENT '删除标识 0未删除、1已删除', + `REVISION` int(11) NOT NULL DEFAULT '0' COMMENT '乐观锁', + `CREATED_BY` varchar(32) NOT NULL COMMENT '创建人', + `CREATED_TIME` datetime NOT NULL COMMENT '创建时间', + `UPDATED_BY` varchar(32) NOT NULL COMMENT '更新人', + `UPDATED_TIME` datetime NOT NULL COMMENT '更新时间', + PRIMARY KEY (`ID`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='联建活动与服务事项关联表'; +CREATE TABLE `latest_act_unit_relation` ( + `ID` varchar(64) NOT NULL DEFAULT '1' COMMENT '主键', + `CUSTOMER_ID` varchar(64) NOT NULL COMMENT '客户id', + `ACT_ID` varchar(64) DEFAULT NULL COMMENT 'latest_act_info表ID', + `UNIT_ID` varchar(32) NOT NULL COMMENT '单位ID', + `SORT` int(4) DEFAULT NULL COMMENT '排序', + `DEL_FLAG` varchar(1) NOT NULL DEFAULT '0' COMMENT '删除标识 0未删除、1已删除', + `REVISION` int(11) NOT NULL DEFAULT '0' COMMENT '乐观锁', + `CREATED_BY` varchar(32) NOT NULL COMMENT '创建人', + `CREATED_TIME` datetime NOT NULL COMMENT '创建时间', + `UPDATED_BY` varchar(32) NOT NULL COMMENT '更新人', + `UPDATED_TIME` datetime NOT NULL COMMENT '更新时间', + PRIMARY KEY (`ID`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='联建活动与单位关联表'; + +ALTER TABLE `epmet_heart`.`ic_party_activity` + MODIFY COLUMN `UNIT_ID` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '单位ID' AFTER `ACT_ID`, + MODIFY COLUMN `SERVICE_MATTER` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '服务事项' AFTER `UNIT_ID`; + +UPDATE act_info SET ACT_TYPE = 'heart' WHERE ACT_TYPE IS NULL; \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/db/migration/V0.0.12__insert_ic_party_relation.sql b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/db/migration/V0.0.12__insert_ic_party_relation.sql new file mode 100644 index 0000000000..41aaf825dd --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/db/migration/V0.0.12__insert_ic_party_relation.sql @@ -0,0 +1,40 @@ +INSERT INTO ic_activity_unit_relation +SELECT + UUID() AS ID, + CUSTOMER_ID, + AGENCY_ID, + PIDS, + ID AS ACTIVITY_ID, + ACT_ID, + UNIT_ID, + 1 AS SORT, + DEL_FLAG, + REVISION, + CREATED_BY, + NOW(), + UPDATED_BY, + NOW() +FROM + ic_party_activity +WHERE UNIT_ID IS NOT NULL AND UNIT_ID != ''; +UPDATE ic_activity_unit_relation SET ID = REPLACE (ID, '-', ''); +INSERT INTO ic_activity_service_relation +SELECT + UUID() AS ID, + CUSTOMER_ID, + AGENCY_ID, + PIDS, + ID AS ACTIVITY_ID, + ACT_ID, + SERVICE_MATTER, + 1 AS SORT, + DEL_FLAG, + REVISION, + CREATED_BY, + NOW(), + UPDATED_BY, + NOW() +FROM + ic_party_activity +WHERE SERVICE_MATTER IS NOT NULL AND UNIT_ID != ''; +UPDATE ic_activity_service_relation SET ID = REPLACE (ID, '-', ''); \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/IcActivityServiceRelationDao.xml b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/IcActivityServiceRelationDao.xml new file mode 100644 index 0000000000..dabb923f67 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/IcActivityServiceRelationDao.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + DELETE FROM ic_activity_service_relation WHERE ACTIVITY_ID = #{activityId} + + + + \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/IcActivityUnitRelationDao.xml b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/IcActivityUnitRelationDao.xml new file mode 100644 index 0000000000..f8947c98e4 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/IcActivityUnitRelationDao.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + DELETE FROM ic_activity_unit_relation WHERE ACTIVITY_ID = #{activityId} + + + + \ No newline at end of file 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/epmet-heart/epmet-heart-server/src/main/resources/mapper/IcPartyActivityDao.xml b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/IcPartyActivityDao.xml index b0033b9379..429461fbfb 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/IcPartyActivityDao.xml +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/IcPartyActivityDao.xml @@ -28,14 +28,16 @@ + + + \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/LatestActInfoDao.xml b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/LatestActInfoDao.xml index 67f4cb64a7..1bcd53d153 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/LatestActInfoDao.xml +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/LatestActInfoDao.xml @@ -114,6 +114,9 @@ lai.SPONSOR_NAME AS sponsorName, lai.SPONSOR_CONTACTS AS sponsorContacts, lai.SPONSOR_TEL AS sponsorTel, + lai.SPONSOR_TYPE, + lai.SPONSOR_ID, + lai.PID, lai.ACT_TYPE, lai.UNIT_ID, lai.SERVICE_MATTER, diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/LatestActServiceRelationDao.xml b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/LatestActServiceRelationDao.xml new file mode 100644 index 0000000000..abc0deda55 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/LatestActServiceRelationDao.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + DELETE FROM latest_act_service_relation WHERE ACT_ID = #{activityId} + + + \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/LatestActUnitRelationDao.xml b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/LatestActUnitRelationDao.xml new file mode 100644 index 0000000000..e679b5dc53 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/LatestActUnitRelationDao.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + DELETE FROM latest_act_unit_relation WHERE ACT_ID = #{activityId} + + + \ No newline at end of file diff --git a/epmet-module/epmet-job/epmet-job-server/pom.xml b/epmet-module/epmet-job/epmet-job-server/pom.xml index db2669bc48..4b6620ada0 100644 --- a/epmet-module/epmet-job/epmet-job-server/pom.xml +++ b/epmet-module/epmet-job/epmet-job-server/pom.xml @@ -102,6 +102,12 @@ 2.0.0 compile + + com.epmet + data-aggregator-client + 2.0.0 + compile + diff --git a/epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/controller/DemoController.java b/epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/controller/DemoController.java index 6bb9718720..b0f2b3a32f 100644 --- a/epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/controller/DemoController.java +++ b/epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/controller/DemoController.java @@ -8,12 +8,16 @@ package com.epmet.controller; +import com.alibaba.fastjson.JSON; +import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.dataaggre.dto.govorg.form.GridLivelyFormDTO; +import com.epmet.dataaggre.feign.DataAggregatorOpenFeignClient; import com.epmet.feign.DataStatisticalOpenFeignClient; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; /** * 定时任务 @@ -27,6 +31,8 @@ public class DemoController { @Autowired private DataStatisticalOpenFeignClient client; + @Autowired + private DataAggregatorOpenFeignClient dataAggregatorFeignClient; @GetMapping("testAlarm") public void testAlarm() { @@ -35,4 +41,18 @@ public class DemoController { //} client.agencyGridIssueStats(null); } + + + @PostMapping("exportGridLiveRes") + public Result exportGridLiveRes(@RequestParam("params") String params) { + if(StringUtils.isBlank(params)){ + return new Result(); + } + GridLivelyFormDTO formDTO = new GridLivelyFormDTO(); + if (StringUtils.isNotBlank(params)) { + formDTO = JSON.parseObject(params, GridLivelyFormDTO.class); + } + ValidatorUtils.validateEntity(formDTO,GridLivelyFormDTO.Grid.class); + return dataAggregatorFeignClient.exportGridLiveRes(formDTO); + } } diff --git a/epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/task/ExportGridLiveResTask.java b/epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/task/ExportGridLiveResTask.java new file mode 100644 index 0000000000..a3a4aae9bb --- /dev/null +++ b/epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/task/ExportGridLiveResTask.java @@ -0,0 +1,68 @@ +package com.epmet.task; + +import com.alibaba.fastjson.JSON; +import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.dataaggre.dto.govorg.form.GridLivelyFormDTO; +import com.epmet.dataaggre.feign.DataAggregatorOpenFeignClient; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; + + +/** + * 每个星期一的凌晨5点执行,查询网格活跃度统计导出excel,上传oss, 发送钉钉@小雷哥 + */ +@Slf4j +@Component("exportGridLiveResTask") +public class ExportGridLiveResTask implements ITask { + + @Autowired + private DataAggregatorOpenFeignClient dataAggregatorFeignClient; + + @Override + public void run(String params) { + if(StringUtils.isBlank(params)){ + return; + } + GridLivelyFormDTO formDTO = new GridLivelyFormDTO(); + if (StringUtils.isNotBlank(params)) { + formDTO = JSON.parseObject(params, GridLivelyFormDTO.class); + } + //默认获取当前日期的上一个自然周 + if (StringUtils.isBlank(formDTO.getStartTime()) || StringUtils.isBlank(formDTO.getEndTime())) { + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.DATE, -1); + //上周日的日期 + Date yesterday = calendar.getTime(); + DateFormat format = new SimpleDateFormat("yyyyMMdd"); + Calendar c = new GregorianCalendar(); + //这里设置一周开始时间是星期一 + c.setFirstDayOfWeek(Calendar.MONDAY); + c.setTime(yesterday); + c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); + //获取当前自然周的起始时间 + String beginTime = format.format(c.getTime()); + c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() + 6); + //当前自然周的截止时间 + String endTime = format.format(c.getTime()); + formDTO.setStartTime(beginTime); + formDTO.setEndTime(endTime); + } + ValidatorUtils.validateEntity(formDTO,GridLivelyFormDTO.Grid.class); + Result result = dataAggregatorFeignClient.exportGridLiveRes(formDTO); + if(!result.success()){ + log.error(String.format("exportGridLiveResTask网格活跃度统计导出失败,入参:%s",params)); + } + } + + + +} \ No newline at end of file diff --git a/epmet-module/epmet-oss/epmet-oss-client/src/main/java/com/epmet/feign/OssFeignClient.java b/epmet-module/epmet-oss/epmet-oss-client/src/main/java/com/epmet/feign/OssFeignClient.java index 60697791d7..f1144b878d 100644 --- a/epmet-module/epmet-oss/epmet-oss-client/src/main/java/com/epmet/feign/OssFeignClient.java +++ b/epmet-module/epmet-oss/epmet-oss-client/src/main/java/com/epmet/feign/OssFeignClient.java @@ -14,7 +14,11 @@ import com.epmet.dto.result.UploadImgResultDTO; import com.epmet.feign.fallback.OssFeignClientFallbackFactory; import feign.codec.Encoder; import feign.form.spring.SpringFormEncoder; +import org.springframework.beans.factory.ObjectFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.http.HttpMessageConverters; import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.cloud.openfeign.support.SpringEncoder; import org.springframework.context.annotation.Bean; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; @@ -64,12 +68,24 @@ public interface OssFeignClient { @GetMapping(value = "oss/file/getOssFileUrl") Result getOssFileUrl(@RequestParam String filePath, @RequestParam String privacy); + /** + * 上传任务描述文件 + * 不限制大小 + * @param file + * @return + */ + @PostMapping(value = "oss/file/importTaskDescFile/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + Result uploadImportTaskDescFile(@RequestPart("file") MultipartFile file); //@Configuration class MultipartSupportConfig { + + @Autowired + private ObjectFactory messageConverters; + @Bean public Encoder feignFormEncoder() { - return new SpringFormEncoder(); + return new SpringFormEncoder(new SpringEncoder(messageConverters)); } } diff --git a/epmet-module/epmet-oss/epmet-oss-client/src/main/java/com/epmet/feign/fallback/OssFeignClientFallback.java b/epmet-module/epmet-oss/epmet-oss-client/src/main/java/com/epmet/feign/fallback/OssFeignClientFallback.java index dc43ed7467..805c2fc492 100644 --- a/epmet-module/epmet-oss/epmet-oss-client/src/main/java/com/epmet/feign/fallback/OssFeignClientFallback.java +++ b/epmet-module/epmet-oss/epmet-oss-client/src/main/java/com/epmet/feign/fallback/OssFeignClientFallback.java @@ -50,4 +50,9 @@ public class OssFeignClientFallback implements OssFeignClient { return ModuleUtils.feignConError(ServiceConstant.EPMET_OSS_SERVER, "download", filePath,privacy); } + @Override + public Result uploadImportTaskDescFile(MultipartFile file) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_OSS_SERVER, "uploadImportTaskDescFile", "MultipartFile"); + } + } diff --git a/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/controller/OssController.java b/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/controller/OssController.java index ac84d4d820..1b79042fbc 100644 --- a/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/controller/OssController.java +++ b/epmet-module/epmet-oss/epmet-oss-server/src/main/java/com/epmet/controller/OssController.java @@ -437,4 +437,15 @@ public class OssController { return new Result().ok(ossService.getOssFileUrl(filePath,privacy)); } + /** + * 上传任务描述文件 + * 不限制大小 + * @param file + * @return + */ + @PostMapping("/importTaskDescFile/upload") + public Result uploadImportTaskDescFile(@RequestPart("file") MultipartFile file) { + return ossService.uploadImg(file, null); + } + } diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/CustomerGridDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/CustomerGridDTO.java index a3600b2e0e..7acfd64627 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/CustomerGridDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/CustomerGridDTO.java @@ -62,6 +62,11 @@ public class CustomerGridDTO implements Serializable { */ private String latitude; + /** + * 中心点位位置 + */ + private String centerAddress; + /** * 所属地区码(所属组织地区码) */ diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddAgencyFormDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddAgencyFormDTO.java index 7a5e6b5537..575a498d57 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddAgencyFormDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddAgencyFormDTO.java @@ -85,4 +85,22 @@ public class AddAgencyFormDTO implements Serializable { @Length(max=30,message = "区县级机关名称不能超过30个字") private String district; + //02.21新增需求:小程序工作端添加组织增加中心点位置入口,点击进入地图选择点位,可以搜索,中心点为必填 + //该接口为通用接口,后端暂时先不限制必填。由前端控制 + /** + * 中心位置经度 + */ + // @NotBlank(message = "请选择网格中心点位", groups = AddGridFormDTO.AddGrid.class) + private String longitude; + + /** + * 中心位置纬度 + */ + // @NotBlank(message = "请选择网格中心点位", groups = AddGridFormDTO.AddGrid.class) + private String latitude; + + /** + * 中心点位位置 + */ + private String centerAddress; } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddAgencyV2FormDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddAgencyV2FormDTO.java index 50ee7a010c..0cbb5c1ab5 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddAgencyV2FormDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddAgencyV2FormDTO.java @@ -99,4 +99,23 @@ public class AddAgencyV2FormDTO implements Serializable { * 联系电话 */ private String mobile; + + //02.21新增需求:小程序工作端添加组织增加中心点位置入口,点击进入地图选择点位,可以搜索,中心点为必填 + //该接口为通用接口,后端暂时先不限制必填。由前端控制 + /** + * 中心位置经度 + */ + // @NotBlank(message = "请选择网格中心点位", groups = AddGridFormDTO.AddGrid.class) + private String longitude; + + /** + * 中心位置纬度 + */ + // @NotBlank(message = "请选择网格中心点位", groups = AddGridFormDTO.AddGrid.class) + private String latitude; + + /** + * 中心点位位置 + */ + private String centerAddress; } diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddGridFormDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddGridFormDTO.java index 965f8b5fc6..9eab6ce157 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddGridFormDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/AddGridFormDTO.java @@ -51,4 +51,22 @@ public class AddGridFormDTO implements Serializable { */ private String mobile; + //02.21新增需求:小程序工作端添加组织增加中心点位置入口,点击进入地图选择点位,可以搜索,中心点为必填 + //该接口为通用接口,后端暂时先不限制必填。由前端控制 + /** + * 中心位置经度 + */ + // @NotBlank(message = "请选择网格中心点位", groups = AddGridFormDTO.AddGrid.class) + private String longitude; + + /** + * 中心位置纬度 + */ + // @NotBlank(message = "请选择网格中心点位", groups = AddGridFormDTO.AddGrid.class) + private String latitude; + + /** + * 中心点位位置 + */ + private String centerAddress; } diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/EditAgencyFormDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/EditAgencyFormDTO.java index 7b3ff97ed8..7473027fde 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/EditAgencyFormDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/EditAgencyFormDTO.java @@ -89,4 +89,23 @@ public class EditAgencyFormDTO implements Serializable { @NotBlank(message = "组织级别不能为空;社区级:community,乡(镇、街道)级:street,区县级: district,市级: city省级:province", groups = AddAgencyV2FormDTO.AddUserInternalGroup.class) private String level; + + //02.21新增需求:小程序工作端添加组织增加中心点位置入口,点击进入地图选择点位,可以搜索,中心点为必填 + //该接口为通用接口,后端暂时先不限制必填。由前端控制 + /** + * 中心位置经度 + */ + // @NotBlank(message = "请选择网格中心点位", groups = AddGridFormDTO.AddGrid.class) + private String longitude; + + /** + * 中心位置纬度 + */ + // @NotBlank(message = "请选择网格中心点位", groups = AddGridFormDTO.AddGrid.class) + private String latitude; + + /** + * 中心点位位置 + */ + private String centerAddress; } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/EditGridFormDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/EditGridFormDTO.java index 1c42608fd8..8774da4f99 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/EditGridFormDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/EditGridFormDTO.java @@ -59,4 +59,22 @@ public class EditGridFormDTO implements Serializable { */ private String mobile; + //02.21新增需求:小程序工作端添加组织增加中心点位置入口,点击进入地图选择点位,可以搜索,中心点为必填 + //该接口为通用接口,后端暂时先不限制必填。由前端控制 + /** + * 中心位置经度 + */ + // @NotBlank(message = "请选择网格中心点位", groups = AddGridFormDTO.AddGrid.class) + private String longitude; + + /** + * 中心位置纬度 + */ + // @NotBlank(message = "请选择网格中心点位", groups = AddGridFormDTO.AddGrid.class) + private String latitude; + + /** + * 中心点位位置 + */ + private String centerAddress; } diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/AgencysResultDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/AgencysResultDTO.java index cace2a4c84..99028d23bb 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/AgencysResultDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/AgencysResultDTO.java @@ -118,4 +118,19 @@ public class AgencysResultDTO implements Serializable { * 联系电话 */ private String mobile; + + /** + * 中心位置经度 + */ + private String longitude; + + /** + * 中心位置纬度 + */ + private String latitude; + + /** + * 中心点位位置 + */ + private String centerAddress; } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/GridDetailResultDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/GridDetailResultDTO.java index f9a2726a1a..cae98d8bc4 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/GridDetailResultDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/GridDetailResultDTO.java @@ -35,6 +35,11 @@ public class GridDetailResultDTO implements Serializable { */ private String latitude; + /** + * 中心点位位置 + */ + private String centerAddress; + /** * 所属地区码(所属组织地区码) */ diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/UpdateBuildingHouseNumResultDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/UpdateBuildingHouseNumResultDTO.java new file mode 100644 index 0000000000..0a3d25f464 --- /dev/null +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/UpdateBuildingHouseNumResultDTO.java @@ -0,0 +1,21 @@ +package com.epmet.dto.result; + +import com.epmet.commons.tools.constant.NumConstant; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author zxc + * @DateTime 2022/3/3 5:24 下午 + * @DESC + */ +@Data +public class UpdateBuildingHouseNumResultDTO implements Serializable { + + private static final long serialVersionUID = 4350166505117596584L; + + private String id; + + private Integer num; +} diff --git a/epmet-module/gov-org/gov-org-server/pom.xml b/epmet-module/gov-org/gov-org-server/pom.xml index f89dd2f265..beacf36eb9 100644 --- a/epmet-module/gov-org/gov-org-server/pom.xml +++ b/epmet-module/gov-org/gov-org-server/pom.xml @@ -33,6 +33,11 @@ epmet-commons-dynamic-datasource 2.0.0 + + com.epmet + epmet-oss-client + 2.0.0 + org.springframework.boot spring-boot-starter-web diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/GovOrgApplication.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/GovOrgApplication.java index ff43e6542c..348a7b67b0 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/GovOrgApplication.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/GovOrgApplication.java @@ -13,6 +13,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.scheduling.annotation.EnableAsync; /** * @@ -24,6 +25,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients; @EnableDiscoveryClient @EnableFeignClients @ServletComponentScan +@EnableAsync public class GovOrgApplication { public static void main(String[] args) { diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/constant/ImportErrorMsgConstants.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/constant/ImportErrorMsgConstants.java new file mode 100644 index 0000000000..6dce569719 --- /dev/null +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/constant/ImportErrorMsgConstants.java @@ -0,0 +1,22 @@ +package com.epmet.constant; + +/** + * @Author zxc + * @DateTime 2022/2/21 4:25 下午 + * @DESC + */ +public interface ImportErrorMsgConstants { + + String EXIST_ERROR = "数据已存在"; + + String HOUSE_ERROR = "所属组织、所属网格、所属小区、所属楼栋、单元号、房屋类型、房屋用途、出租、房主姓名、房主电话、房主身份证的值未填写,或者所填写信息在系统中未找到"; + + String BUILDING_ERROR = "所属组织、所属网格、所属小区、楼栋类型、单元数的值未填写,或者所填写信息在系统中未找到"; + + String NEIGHBOR_HOOD_ERROR = "所属组织、所属网格、详细地址的值未填写,或者所填写信息在系统中未找到"; + + String HOUSE_ERROR_NAME = "导入失败的列表-房屋"; + String BUILDING_ERROR_NAME = "导入失败的列表-楼宇"; + String NEIGHBORHOOD_ERROR_NAME = "导入失败的列表-小区"; + +} diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/BuildingController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/BuildingController.java index 2ac1605193..349df657f4 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/BuildingController.java +++ b/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(file.getOriginalFilename()); + Result importTask = epmetCommonServiceOpenFeignClient.createImportTask(importFormDTO); + if (!importTask.success()){ + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"","存在进行中的导入"); + } + buildingService.buildingImportExcel(formDTO,file,importTask); + return new Result(); } /** diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseController.java index 017da95fd9..ea54959b86 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseController.java @@ -27,17 +27,18 @@ import com.epmet.commons.tools.aop.NoRepeatSubmit; import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.feign.ResultDataResolver; 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.IcBuildingDao; import com.epmet.dto.form.*; -import com.epmet.dto.result.HouseInfoDTO; -import com.epmet.dto.result.IcNeighborHoodResultDTO; -import com.epmet.dto.result.ImportResultDTO; -import com.epmet.dto.result.LoginUserDetailsResultDTO; +import com.epmet.dto.result.*; import com.epmet.excel.IcHouseExcel; +import com.epmet.feign.EpmetCommonServiceOpenFeignClient; import com.epmet.feign.EpmetUserOpenFeignClient; import com.epmet.feign.GovOrgOpenFeignClient; import com.epmet.model.HouseInfoModel; @@ -49,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; @@ -82,9 +90,9 @@ public class HouseController implements ResultDataResolver { @Autowired private IcHouseRedis icHouseRedis; @Autowired - private IcNeighborHoodService neighborHoodService; - @Autowired private IcHouseService icHouseService; + @Autowired + private EpmetCommonServiceOpenFeignClient epmetCommonServiceOpenFeignClient; @PostMapping("houselist") @@ -252,44 +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().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)) - .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 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(file.getOriginalFilename()); + Result importTask = epmetCommonServiceOpenFeignClient.createImportTask(importFormDTO); + if (!importTask.success()){ + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"","存在进行中的导入"); } - return new Result<>().error(9999,String.format(s,num,num)); + houseService.dispose(file,formDTO,importTask); + return new Result<>(); } } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/IcNeighborHoodController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/IcNeighborHoodController.java index a78ea28431..107b6c612e 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/IcNeighborHoodController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/IcNeighborHoodController.java @@ -17,8 +17,11 @@ package com.epmet.controller; +import com.alibaba.fastjson.JSON; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.dto.result.OptionResultDTO; +import com.epmet.commons.tools.exception.EpmetErrorCode; +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,9 +30,15 @@ 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 lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -47,10 +56,13 @@ import java.util.Map; */ @RestController @RequestMapping("icneighborhood") +@Slf4j public class IcNeighborHoodController { @Autowired private IcNeighborHoodService icNeighborHoodService; + @Autowired + private EpmetCommonServiceOpenFeignClient epmetCommonServiceOpenFeignClient; @GetMapping("page") public Result> page(@RequestParam Map params){ @@ -128,7 +140,17 @@ 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(file.getOriginalFilename()); + Result importTask = epmetCommonServiceOpenFeignClient.createImportTask(importFormDTO); + if (!importTask.success()){ + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"","存在进行中的导入"); + } + log.info("插入任务结果"+ JSON.toJSONString(importTask.getData())); + icNeighborHoodService.neighborhoodImport(formDTO,file,importTask); + return new Result(); } } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcBuildingDao.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcBuildingDao.java index cc052eed19..87ee60fcd4 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcBuildingDao.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcBuildingDao.java @@ -22,6 +22,7 @@ import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.dto.ImportGeneralDTO; import com.epmet.dto.result.BaseInfoFamilyBuildingResultDTO; import com.epmet.dto.result.BuildingResultDTO; +import com.epmet.dto.result.UpdateBuildingHouseNumResultDTO; import com.epmet.entity.CustomerAgencyEntity; import com.epmet.entity.IcBuildingEntity; import com.epmet.entity.IcHouseEntity; @@ -162,4 +163,28 @@ public interface IcBuildingDao extends BaseDao { */ List selectExistHouse(@Param("ids")List ids); + /** + * Desc: 查询客户下户数为空的 + * @param customerId + * @author zxc + * @date 2022/3/3 5:20 下午 + */ + List selectHouseTotalIsNull(@Param("customerId")String customerId); + + /** + * Desc: 查询楼栋下的户数 + * @param ids + * @author zxc + * @date 2022/3/3 5:26 下午 + */ + List selectHouseNum(@Param("ids")List ids); + + /** + * Desc: 批量更新楼栋户数 + * @param nums + * @author zxc + * @date 2022/3/3 5:31 下午 + */ + void allUpdateHouseNum(@Param("nums") List nums); + } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/CustomerAgencyEntity.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/CustomerAgencyEntity.java index cde41fbecc..fda8070609 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/CustomerAgencyEntity.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/CustomerAgencyEntity.java @@ -124,6 +124,11 @@ public class CustomerAgencyEntity extends BaseEpmetEntity { */ private String latitude; + /** + * 中心点位位置 + */ + private String centerAddress; + /** * 组织编码 */ diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/CustomerGridEntity.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/CustomerGridEntity.java index 49fe1b4bdb..d6018c2a29 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/CustomerGridEntity.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/CustomerGridEntity.java @@ -55,6 +55,11 @@ public class CustomerGridEntity extends BaseEpmetEntity { */ private String latitude; + /** + * 中心点位位置 + */ + private String centerAddress; + /** * 所属地区码(所属组织地区码) */ diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/model/BuildingErrorInfoModel.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/model/BuildingErrorInfoModel.java new file mode 100644 index 0000000000..7477c1a109 --- /dev/null +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/model/BuildingErrorInfoModel.java @@ -0,0 +1,24 @@ +package com.epmet.model; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import com.alibaba.excel.annotation.ExcelProperty; +import lombok.Data; + +/** + * @Author zxc + * @DateTime 2022/2/15 10:07 上午 + * @DESC + */ +@Data +public class BuildingErrorInfoModel { + + @Excel(name = "小区名称" , width = 20) + private String neighborHoodName; + + @Excel(name = "楼栋名称", width = 20) + private String buildingName; + + @Excel(name = "错误信息", width = 100) + private String errorMsg; + +} diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/model/HouseErrorInfoModel.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/model/HouseErrorInfoModel.java new file mode 100644 index 0000000000..5d2a444f90 --- /dev/null +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/model/HouseErrorInfoModel.java @@ -0,0 +1,31 @@ +package com.epmet.model; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import com.alibaba.excel.annotation.ExcelProperty; +import lombok.Data; +import org.hibernate.validator.constraints.Length; + +/** + * @Author zxc + * @DateTime 2022/2/13 1:26 下午 + * @DESC + */ +@Data +public class HouseErrorInfoModel { + + @Excel(name = "所属小区", width = 20) + private String neighborHoodName; + + @Excel(name = "所属楼栋", width = 20) + private String buildingName; + + @Excel(name = "单元号", width = 20) + private Integer buildingUnit; + + @Excel(name = "门牌号", width = 20) + private String doorName; + + @Excel(name = "错误信息", width = 200) + private String errorMsg; + +} diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/model/ImportBuildingInfoListener.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/model/ImportBuildingInfoListener.java index 808a69f810..6c1963888a 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/model/ImportBuildingInfoListener.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/model/ImportBuildingInfoListener.java @@ -9,20 +9,22 @@ import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache; import com.epmet.commons.tools.redis.common.bean.GridInfoCache; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.constant.CustomerGridConstant; +import com.epmet.constant.ImportErrorMsgConstants; +import com.epmet.constants.ImportTaskConstants; import com.epmet.dao.IcBuildingDao; import com.epmet.dto.ImportGeneralDTO; import com.epmet.dto.form.ImportInfoFormDTO; +import com.epmet.dto.form.ImportTaskCommonFormDTO; import com.epmet.dto.result.ImportResultDTO; import com.epmet.enums.BuildingTypeEnums; +import com.epmet.feign.EpmetCommonServiceOpenFeignClient; import com.epmet.redis.IcHouseRedis; import com.epmet.service.IcNeighborHoodService; import org.apache.commons.lang3.StringUtils; import org.springframework.util.CollectionUtils; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.io.IOException; +import java.util.*; import java.util.stream.Collectors; /** @@ -34,6 +36,9 @@ public class ImportBuildingInfoListener extends AnalysisEventListener nums = new ArrayList<>(); Integer num = NumConstant.ZERO; + List errorInfos = new ArrayList<>(); + BuildingInfoModel info = null; + String taskId = ""; List needDisposeList = new ArrayList<>(); List needInsertList = new ArrayList<>(); @@ -54,12 +59,15 @@ public class ImportBuildingInfoListener extends AnalysisEventListener { nums.add(e.getNum()); + disposeErrorMsg(info,ImportErrorMsgConstants.EXIST_ERROR); }); } } @@ -157,6 +199,7 @@ public class ImportBuildingInfoListener extends AnalysisEventListener nums = new ArrayList<>(); Integer num = NumConstant.ZERO; + List errorInfos = new ArrayList<>(); + HouseInfoModel info = null; + String taskId = ""; List needDisposeList = new ArrayList<>(); List needInsertList = new ArrayList<>(); @@ -59,13 +68,16 @@ public class ImportHouseInfoListener extends AnalysisEventListener importInfo = neighborHoodService.getImportInfo(formDTO, needDisposeList); @@ -132,10 +214,8 @@ public class ImportHouseInfoListener extends AnalysisEventListener list = icBuildingDao.selectHouseTotalIsNull(formDTO.getCustomerId()); + if (!CollectionUtils.isEmpty(list)){ + List houseNum = icBuildingDao.selectHouseNum(list); + if (!CollectionUtils.isEmpty(houseNum)){ + icBuildingDao.allUpdateHouseNum(houseNum); + } + } // 删除缓存 icHouseRedis.delTemporaryCacheGrids(formDTO.getCustomerId(), formDTO.getUserId()); icHouseRedis.delTemporaryCacheNeighBorHood(formDTO.getCustomerId(), formDTO.getUserId()); @@ -431,6 +542,25 @@ public class ImportHouseInfoListener extends AnalysisEventListener { List nums = new ArrayList<>(); Integer num = NumConstant.ZERO; + List errorInfos = new ArrayList<>(); + NeighborHoodInfoModel info = null; + String taskId = ""; List needDisposeList = new ArrayList<>(); List needInsertList = new ArrayList<>(); @@ -55,22 +64,54 @@ public class ImportNeighborHoodInfoListener extends AnalysisEventListener { nums.add(e.getNum()); + disposeErrorMsg(info,ImportErrorMsgConstants.EXIST_ERROR); }); } List notExistList = groupByBuildingExistStatus.get(false); @@ -167,18 +211,23 @@ public class ImportNeighborHoodInfoListener extends AnalysisEventListener importTask) throws IOException; } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/HouseService.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/HouseService.java index ad5d1d69cb..c7a065024e 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/HouseService.java +++ b/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 queryListHouseInfo(Set houseIds, String customerId); + + Result dispose(MultipartFile file, ImportInfoFormDTO formDTO, Result importTask); } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcNeighborHoodService.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcNeighborHoodService.java index 6a7ba74a55..1d6193834f 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcNeighborHoodService.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcNeighborHoodService.java @@ -24,12 +24,14 @@ 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; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -127,7 +129,7 @@ public interface IcNeighborHoodService extends BaseService * @author zxc * @date 2022/2/12 11:11 上午 */ - Result neighborhoodImport(ImportInfoFormDTO formDTO, MultipartFile file) throws IOException; + Result neighborhoodImport(ImportInfoFormDTO formDTO, MultipartFile file,Result importTask) throws IOException; /** * 获取导入小区,楼栋,单元ID @@ -143,4 +145,6 @@ public interface IcNeighborHoodService extends BaseService void insertPropertyManagement(List propertyManagementEntities); void neighborHoodPropertyInsert(List entities); + + String orgGeneralImport(Collection errorRows, Class tClass) throws IOException; } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java index 535d411b79..c20fd83965 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java @@ -158,7 +158,13 @@ public class AgencyServiceImpl implements AgencyService { originalEntity.setCode(formDTO.getCode()); originalEntity.setContacts(formDTO.getContacts()); originalEntity.setMobile(formDTO.getMobile()); - + if(StringUtils.isNotBlank(formDTO.getLatitude())){ + originalEntity.setLatitude(formDTO.getLatitude()); + } + if(StringUtils.isNotBlank(formDTO.getLongitude())){ + originalEntity.setLongitude(formDTO.getLongitude()); + } + originalEntity.setCenterAddress(formDTO.getCenterAddress()); //当前客户开启了area_code_switch参数:open: 选择地区编码必填;closed: 无需选择地区编码 if (CustomerAgencyConstant.AREA_CODE_SWITCH_OPEN.equals(formDTO.getAreaCodeSwitch())) { CustomerAgencyEntity parent = customerAgencyDao.selectById(originalEntity.getPid()); diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/BuildingServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/BuildingServiceImpl.java index 15daabf246..091ef5dd1e 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/BuildingServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/BuildingServiceImpl.java @@ -13,24 +13,26 @@ 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.EpmetException; import com.epmet.commons.tools.exception.RenException; 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.constant.ImportErrorMsgConstants; +import com.epmet.constants.ImportTaskConstants; import com.epmet.dao.*; import com.epmet.dto.BuildingTreeLevelDTO; import com.epmet.dto.CustomerStaffAgencyDTO; import com.epmet.dto.IcBuildingDTO; import com.epmet.dto.form.IcBulidingFormDTO; import com.epmet.dto.form.ImportInfoFormDTO; +import com.epmet.dto.form.ImportTaskCommonFormDTO; 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.ImportResultDTO; +import com.epmet.dto.result.*; import com.epmet.entity.*; import com.epmet.enums.BuildingTypeEnums; import com.epmet.excel.IcBuildingExcel; +import com.epmet.feign.EpmetCommonServiceOpenFeignClient; import com.epmet.model.BuildingInfoModel; import com.epmet.model.HouseInfoModel; import com.epmet.model.ImportBuildingInfoListener; @@ -44,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; @@ -89,6 +93,8 @@ public class BuildingServiceImpl implements BuildingService { private IcHouseRedis icHouseRedis; @Autowired private IcNeighborHoodService neighborHoodService; + @Autowired + private EpmetCommonServiceOpenFeignClient epmetCommonServiceOpenFeignClient; @Override @Transactional(rollbackFor = Exception.class) @@ -397,7 +403,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 importTask) throws IOException { ExcelReader excelReader = null; try { InputStream inputStream = null; @@ -409,27 +416,21 @@ public class BuildingServiceImpl implements BuildingService { excelReader = EasyExcel.read(inputStream).build(); // 这里为了简单 所以注册了 同样的head 和Listener 自己使用功能必须不同的Listener ReadSheet readSheet = EasyExcel.readSheet(0).head(BuildingInfoModel.class) - .registerReadListener(new ImportBuildingInfoListener(formDTO,icHouseRedis,icBuildingDao,neighborHoodService)) + .registerReadListener(new ImportBuildingInfoListener(formDTO,icHouseRedis,icBuildingDao,neighborHoodService,epmetCommonServiceOpenFeignClient,importTask.getData().getTaskId())) .build(); excelReader.read(readSheet); + } catch (Exception e){ + ImportTaskCommonFormDTO input = new ImportTaskCommonFormDTO(); + input.setOperatorId(formDTO.getUserId()); + input.setTaskId(importTask.getData().getTaskId()); + input.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL); + epmetCommonServiceOpenFeignClient.finishImportTask(input); } finally { if (excelReader != null) { excelReader.finish(); } } - ImportResultDTO dto = icHouseRedis.getImportResultDTO(formDTO.getCustomerId(), formDTO.getUserId()); - if (null == dto){ - return new Result<>(); - } - List 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<>(); } private List searchAllBuilding(ListIcNeighborHoodFormDTO formDTO) { diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerGridServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerGridServiceImpl.java index 57fc7340fb..cd0080f548 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerGridServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CustomerGridServiceImpl.java @@ -272,7 +272,10 @@ public class CustomerGridServiceImpl extends BaseServiceImpl importTask) { + ExcelReader excelReader = null; + try { + InputStream inputStream = null; + try { + inputStream = file.getInputStream(); + } catch (IOException e) { + return new Result().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); + } catch (Exception e){ + ImportTaskCommonFormDTO input = new ImportTaskCommonFormDTO(); + input.setOperatorId(formDTO.getUserId()); + input.setTaskId(importTask.getData().getTaskId()); + input.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL); + epmetCommonServiceOpenFeignClient.finishImportTask(input); + } finally { + if (excelReader != null) { + excelReader.finish(); + } + } + return new Result(); + } } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcNeighborHoodServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcNeighborHoodServiceImpl.java index 99db449d72..d68ba40e01 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcNeighborHoodServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcNeighborHoodServiceImpl.java @@ -17,10 +17,12 @@ package com.epmet.service.impl; -import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult; +import cn.afterturn.easypoi.excel.ExcelExportUtil; +import cn.afterturn.easypoi.excel.entity.ExportParams; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.ExcelReader; import com.alibaba.excel.read.metadata.ReadSheet; +import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -31,6 +33,7 @@ import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; import com.epmet.commons.tools.dto.result.OptionResultDTO; 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.page.PageData; import com.epmet.commons.tools.redis.common.CustomerOrgRedis; import com.epmet.commons.tools.redis.common.CustomerStaffRedis; @@ -39,34 +42,46 @@ import com.epmet.commons.tools.redis.common.bean.GridInfoCache; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.constant.CustomerGridConstant; +import com.epmet.constants.ImportTaskConstants; import com.epmet.dao.CustomerGridDao; import com.epmet.dao.IcBuildingDao; import com.epmet.dao.IcNeighborHoodDao; import com.epmet.dao.IcPropertyManagementDao; import com.epmet.dto.*; import com.epmet.dto.form.ImportInfoFormDTO; -import com.epmet.dto.result.ImportResultDTO; +import com.epmet.dto.form.ImportTaskCommonFormDTO; +import com.epmet.dto.result.ImportTaskCommonResultDTO; import com.epmet.dto.result.InfoByNamesResultDTO; +import com.epmet.dto.result.UploadImgResultDTO; import com.epmet.entity.*; import com.epmet.excel.IcNeighborHoodExcel; +import com.epmet.feign.EpmetCommonServiceOpenFeignClient; +import com.epmet.feign.OssFeignClient; import com.epmet.model.ImportNeighborHoodInfoListener; import com.epmet.model.NeighborHoodInfoModel; import com.epmet.redis.IcHouseRedis; import com.epmet.service.*; -import com.epmet.util.ExcelPoiUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.ListUtils; +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.annotation.Resource; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.util.*; +import java.util.concurrent.ExecutorService; import java.util.stream.Collectors; /** @@ -95,6 +110,12 @@ public class IcNeighborHoodServiceImpl extends BaseServiceImpl page(Map params) { @@ -210,21 +231,44 @@ public class IcNeighborHoodServiceImpl extends BaseServiceImpl importResult = ExcelPoiUtils.importExcelMore(file, 0, 1, IcNeighborHoodExcel.class); - List failList = importResult.getFailList(); - //存放错误数据行号 - List numList = new ArrayList<>(); - if(CollectionUtils.isNotEmpty(failList)){ - for ( IcNeighborHoodExcel entity : failList) { - //打印失败的行 和失败的信息 - log.error("第{}行,{}",entity.getRowNum(),entity.getErrorMsg()); - numList.add(entity.getRowNum()); + public Result neighborhoodImport(ImportInfoFormDTO formDTO, MultipartFile file,Result importTask) { + log.info("neighborhoodImport start====="); + executorService.submit(() -> { + // importNeighbor(formDTO,file,importTask); + log.info("neighborhoodImport thread start====="); + ExcelReader excelReader = null; + try { + InputStream inputStream = null; + try { + inputStream = file.getInputStream(); + } catch (IOException e) { + throw new EpmetException("读取文件失败"); + } + + excelReader = EasyExcel.read(inputStream).build(); + // 这里为了简单 所以注册了 同样的head 和Listener 自己使用功能必须不同的Listener + ReadSheet readSheet = EasyExcel.readSheet(0).head(NeighborHoodInfoModel.class) + .registerReadListener(new ImportNeighborHoodInfoListener(formDTO,icHouseRedis,icBuildingDao,this,propertyManagementDao,epmetCommonServiceOpenFeignClient,importTask.getData().getTaskId())) + .build(); + log.info("neighborhoodImport build readSheet num:{}",readSheet.getSheetNo()); + excelReader.read(readSheet); + } catch (Exception e){ + log.error("neighborhoodImport import exception", e); + ImportTaskCommonFormDTO input = new ImportTaskCommonFormDTO(); + input.setOperatorId(formDTO.getUserId()); + input.setTaskId(importTask.getData().getTaskId()); + input.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL); + Result result = epmetCommonServiceOpenFeignClient.finishImportTask(input); + log.info("neighborhoodImport finishImportTask result:{}", JSON.toJSONString(result)); + } finally { + if (excelReader != null) { + excelReader.finish(); + } } - } - List result =importResult.getList(); - return disposeImportNeighborhood(formDTO,result);*/ - return importNeighbor(formDTO,file); + log.info("neighborhoodImport thread end====="); + }); + + return new Result<>(); } /** @@ -387,7 +431,7 @@ public class IcNeighborHoodServiceImpl extends BaseServiceImpl importTask){ ExcelReader excelReader = null; try { InputStream inputStream = null; @@ -396,30 +440,26 @@ public class IcNeighborHoodServiceImpl extends BaseServiceImpl().error("读取文件失败"); } + excelReader = EasyExcel.read(inputStream).build(); // 这里为了简单 所以注册了 同样的head 和Listener 自己使用功能必须不同的Listener ReadSheet readSheet = EasyExcel.readSheet(0).head(NeighborHoodInfoModel.class) - .registerReadListener(new ImportNeighborHoodInfoListener(formDTO,icHouseRedis,icBuildingDao,this,propertyManagementDao)) + .registerReadListener(new ImportNeighborHoodInfoListener(formDTO,icHouseRedis,icBuildingDao,this,propertyManagementDao,epmetCommonServiceOpenFeignClient,importTask.getData().getTaskId())) .build(); excelReader.read(readSheet); + } catch (Exception e){ + ImportTaskCommonFormDTO input = new ImportTaskCommonFormDTO(); + input.setOperatorId(formDTO.getUserId()); + input.setTaskId(importTask.getData().getTaskId()); + input.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL); + epmetCommonServiceOpenFeignClient.finishImportTask(input); } finally { if (excelReader != null) { excelReader.finish(); } } - ImportResultDTO dto = icHouseRedis.getImportResultDTO(formDTO.getCustomerId(), formDTO.getUserId()); - if (null == dto){ - return new Result<>(); - } - List 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<>(); } /** @@ -609,4 +649,44 @@ public class IcNeighborHoodServiceImpl extends BaseServiceImpl String orgGeneralImport(Collection errorRows, Class tClass) throws IOException { + Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("导入失败的数据列表","导入失败的数据列表"), + tClass, errorRows); + + // 文件名 + String resultDescFileName = UUID.randomUUID().toString().concat(".xls"); + + 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上传结果描述文件失败"); + return null; + } + return uploadResult.getData().getUrl(); + } + } diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/db/migration/V0.0.12__addagency_grid_address.sql b/epmet-module/gov-org/gov-org-server/src/main/resources/db/migration/V0.0.12__addagency_grid_address.sql new file mode 100644 index 0000000000..dad5775467 --- /dev/null +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/db/migration/V0.0.12__addagency_grid_address.sql @@ -0,0 +1,2 @@ +alter table customer_agency add COLUMN CENTER_ADDRESS VARCHAR(128) comment '中心点位地址' AFTER LATITUDE; +alter table customer_grid add COLUMN CENTER_ADDRESS VARCHAR(128) comment '中心点位地址' AFTER LATITUDE; \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerGridDao.xml b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerGridDao.xml index 623ca76ed4..357c8cebdc 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerGridDao.xml +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerGridDao.xml @@ -185,6 +185,7 @@ grid_name AS gridName, longitude AS longitude, latitude AS latitude, + CENTER_ADDRESS AS centerAddress, area_code AS areaCode, manage_district AS manageDistrict, total_user AS totalUser, @@ -242,6 +243,15 @@ contacts = #{contacts}, mobile = #{mobile}, updated_by = #{updatedBy}, + + LONGITUDE= #{longitude}, + + + LATITUDE= #{latitude}, + + + CENTER_ADDRESS= #{centerAddress}, + UPDATED_TIME=NOW() where id = #{id} diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcBuildingDao.xml b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcBuildingDao.xml index ee64e59aca..c2482d86af 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcBuildingDao.xml +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcBuildingDao.xml @@ -25,6 +25,23 @@ + + + UPDATE ic_building + set + TOTAL_HOUSE_NUM = CASE + + when id = #{n.id} then #{n.num} + end, + UPDATED_TIME = NOW() + WHERE DEL_FLAG = '0' + AND id in( + + #{n.id} + + ) + + + + + + + diff --git a/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/member/ResiGroupMemberDTO.java b/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/member/ResiGroupMemberDTO.java index a64ebdb042..9244410c3b 100644 --- a/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/member/ResiGroupMemberDTO.java +++ b/epmet-module/resi-group/resi-group-client/src/main/java/com/epmet/resi/group/dto/member/ResiGroupMemberDTO.java @@ -65,7 +65,7 @@ public class ResiGroupMemberDTO implements Serializable { private String groupInvitationId; /** - * 状态:( 审核通过 - approved、 已禁言 - silent、 被移出群 - removed) + * 状态:( 审核通过 - approved、 已禁言 - silent、 被移出群 - removed)exit:退群 */ private String status; diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/controller/ExitGroupController.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/controller/ExitGroupController.java index ca8e7013fd..f49d0b2677 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/controller/ExitGroupController.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/controller/ExitGroupController.java @@ -1,6 +1,7 @@ package com.epmet.modules.group.controller; import com.epmet.commons.tools.annotation.LoginUser; +import com.epmet.commons.tools.aop.NoRepeatSubmit; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; @@ -54,6 +55,7 @@ public class ExitGroupController { * @description 组员自主退群 * @Date 2021/4/30 15:09 **/ + @NoRepeatSubmit @PostMapping("memexitgroup") public Result memExitGroup(@LoginUser TokenDto tokenDto, @RequestBody MemExitGroupFormDTO formDTO){ formDTO.setUserId(tokenDto.getUserId()); diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/ExitGroupServiceImpl.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/ExitGroupServiceImpl.java index 62e10b0303..f73a2e46c8 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/ExitGroupServiceImpl.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/group/service/impl/ExitGroupServiceImpl.java @@ -2,6 +2,7 @@ package com.epmet.modules.group.service.impl; import com.epmet.commons.tools.constant.*; import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.form.UserRoleFormDTO; @@ -223,7 +224,7 @@ public class ExitGroupServiceImpl implements ExitGroupService { //1、当前组员是否还在群里? ResiGroupMemberDTO resiGroupMemberDTO=resiGroupMemberDao.selectGroupMemberInfo(formDTO.getGroupId(),formDTO.getUserId()); if(null == resiGroupMemberDTO){ - throw new RenException("已退出当前小组,请勿重复操作"); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "已退出当前小组,请勿重复操作","已退出当前小组,请勿重复操作"); } //2、组长不允许退群,提示:请先转移组长身份后再退组 if(ModuleConstant.GROUP_LEADER.equals(resiGroupMemberDTO.getGroupLeaderFlag())){ diff --git a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/member/entity/ResiGroupMemberEntity.java b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/member/entity/ResiGroupMemberEntity.java index 0e21de29db..84f166b844 100644 --- a/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/member/entity/ResiGroupMemberEntity.java +++ b/epmet-module/resi-group/resi-group-server/src/main/java/com/epmet/modules/member/entity/ResiGroupMemberEntity.java @@ -63,7 +63,7 @@ public class ResiGroupMemberEntity extends BaseEpmetEntity { private String groupInvitationId; /** - * 状态:( 审核通过 - approved、 已禁言 - silent、 被移出群 - removed) + * 状态:( 审核通过 - approved、 已禁言 - silent、 被移出群 - removed)exit:退群 */ private String status; diff --git a/epmet-module/resi-partymember/resi-partymember-server/pom.xml b/epmet-module/resi-partymember/resi-partymember-server/pom.xml index 5639637b73..500fc4408e 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..b99c297700 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 @@ -17,9 +17,11 @@ 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; +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 +29,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,7 +40,9 @@ 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.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -60,6 +68,8 @@ public class IcPartymemberStyleController { @Autowired private IcPartymemberStyleService icPartymemberStyleService; + @Autowired + private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient; @GetMapping("page") public Result> page(@RequestParam Map params){ @@ -116,8 +126,27 @@ public class IcPartymemberStyleController { } @PostMapping("import") + //service方法是异步的,需要事务注解加在被调用方 否则事务不起作用 + @Transactional(rollbackFor = Exception.class) public Result importData(@LoginUser TokenDto tokenDto, HttpServletResponse response, @RequestPart("file") MultipartFile file) throws IOException { - return icPartymemberStyleService.importData(tokenDto, response, file); + // 校验文件类型 + 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()); + + return new Result(); } /** diff --git a/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/excel/PartyMemberImportExcel.java b/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/excel/PartyMemberImportExcel.java new file mode 100644 index 0000000000..40bd4946ec --- /dev/null +++ b/epmet-module/resi-partymember/resi-partymember-server/src/main/java/com/epmet/modules/partymember/excel/PartyMemberImportExcel.java @@ -0,0 +1,40 @@ +/** + * 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.modules.partymember.excel; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import lombok.Data; + +/** + * 党员风采导入错误数据存放文件 + * @author sun + */ +@Data +public class PartyMemberImportExcel { + + @Excel(name = "所属网格", width = 30) + private String gridName; + @Excel(name = "党员姓名", width = 20) + private String name; + @Excel(name = "主要事迹", width = 30) + private String mainDeed; + @Excel(name = "所属分类", width = 30) + private String categoryName; + @Excel(name = "错误信息", width = 40) + private String errorInfo; +} \ No newline at end of file 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 implements IcPartymemberStyleService { @Resource @@ -82,6 +103,10 @@ public class IcPartymemberStyleServiceImpl extends BaseServiceImpl page(Map params) { @@ -232,86 +257,190 @@ public class IcPartymemberStyleServiceImpl extends BaseServiceImpl importResult = ExcelPoiUtils.importExcelMore(file, 0, 1, IcPartymemberStyleImportExcel.class); + //@Transactional(rollbackFor = Exception.class) + @Async + public void importData(TokenDto tokenDto, HttpServletResponse response, MultipartFile file, String taskId) { + try { + log.info("党员风采导入,子线程开始执行"); + List fileList = new ArrayList<>(); + PartyMemberImportExcel excel = null; + ExcelImportResult importResult = ExcelPoiUtils.importExcelMore(file, 0, 1, IcPartymemberStyleImportExcel.class); - List failList = importResult.getFailList(); - //存放错误数据行号 - List numList = new ArrayList<>(); - if (!org.springframework.util.CollectionUtils.isEmpty(failList)) { - for (IcPartymemberStyleImportExcel entity : failList) { - //打印失败的行 和失败的信息 - log.warn("第{}行,{}", entity.getRowNum(), entity.getErrorMsg()); - numList.add(entity.getRowNum()); + List failList = importResult.getFailList(); + //存放错误数据行号 + List numList = new ArrayList<>(); + if (!org.springframework.util.CollectionUtils.isEmpty(failList)) { + for (IcPartymemberStyleImportExcel entity : failList) { + //打印失败的行 和失败的信息 + log.warn("第{}行,{}", entity.getRowNum(), entity.getErrorMsg()); + numList.add(entity.getRowNum()); + excel = new PartyMemberImportExcel(); + excel.setGridName(entity.getGridName()); + excel.setName(entity.getName()); + excel.setMainDeed(entity.getMainDeed()); + excel.setCategoryName(entity.getCategoryName()); + excel.setErrorInfo(entity.getErrorMsg()); + fileList.add(excel); + } } - } - List result = importResult.getList(); + List result = importResult.getList(); - CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId()); - //获取组织下网格信息 - GridOptionFormDTO formDTO = new GridOptionFormDTO(); - formDTO.setAgencyId(staffInfoCache.getAgencyId()); - Result> gridOptionResult = govOrgOpenFeignClient.getGridIListByAgency(staffInfoCache.getAgencyId()); - if (!gridOptionResult.success()) { - throw new EpmetException(gridOptionResult.getCode(), gridOptionResult.getMsg()); - } - Map gridMap = gridOptionResult.getData().stream().collect(Collectors.toMap(CustomerGridDTO::getGridName, CustomerGridDTO::getId)); - //获取党员风采所有分类:key:分类名称; - Map categoryDictMap=icPartymemberStyleCategoryDictService.getCategoryDictMap(tokenDto.getCustomerId()); - //1.数据校验 只允许导入当前组织下的网格的数据 - //网格名称不一样的数据舍弃或者分类名称不存在也舍弃 - Iterator iterator = result.iterator(); - while (iterator.hasNext()) { - IcPartymemberStyleImportExcel obj = iterator.next(); - if (null == gridMap.get(obj.getGridName().trim())) { - numList.add(obj.getRowNum()); - log.warn(String.format("不是当前组织下可导入的数据,网格名称->%s,行号->%s", obj.getGridName(), obj.getRowNum())); - iterator.remove(); - continue; + CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId()); + //获取组织下网格信息 + GridOptionFormDTO formDTO = new GridOptionFormDTO(); + formDTO.setAgencyId(staffInfoCache.getAgencyId()); + Result> gridOptionResult = govOrgOpenFeignClient.getGridIListByAgency(staffInfoCache.getAgencyId()); + if (!gridOptionResult.success()) { + throw new EpmetException(gridOptionResult.getCode(), gridOptionResult.getMsg()); + } + Map gridMap = gridOptionResult.getData().stream().collect(Collectors.toMap(CustomerGridDTO::getGridName, CustomerGridDTO::getId)); + //获取党员风采所有分类:key:分类名称; + Map categoryDictMap=icPartymemberStyleCategoryDictService.getCategoryDictMap(tokenDto.getCustomerId()); + //1.数据校验 只允许导入当前组织下的网格的数据 + //网格名称不一样的数据舍弃或者分类名称不存在也舍弃 + Iterator iterator = result.iterator(); + while (iterator.hasNext()) { + IcPartymemberStyleImportExcel obj = iterator.next(); + if (null == gridMap.get(obj.getGridName().trim())) { + numList.add(obj.getRowNum()); + log.warn(String.format("不是当前组织下可导入的数据,网格名称->%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 (null == categoryDictMap.get(obj.getCategoryName().trim())) { - numList.add(obj.getRowNum()); - log.warn(String.format("分类名称【%s】不存在,不可导入,行号->%s", obj.getCategoryName(), obj.getRowNum())); - iterator.remove(); + /*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.isEmpty(result)) { + List imageList = new ArrayList<>(); + List list = result.stream().map(item -> { + IcPartymemberStyleEntity entity = new IcPartymemberStyleEntity(); + entity.setId(UUID.randomUUID().toString().replace("-", "")); + entity.setCustomerId(tokenDto.getCustomerId()); + entity.setAgencyId(staffInfoCache.getAgencyId()); + entity.setGridId(gridMap.get(item.getGridName())); + GridInfoCache gridInfo = CustomerOrgRedis.getGridInfo(entity.getGridId()); + if (null != gridInfo) { + entity.setGridPids(gridInfo.getPids()); + } + entity.setName(item.getName()); + entity.setMainDeed(item.getMainDeed()); + IcPartymemberStyleCategoryDictEntity dictEntity=categoryDictMap.get(item.getCategoryName()); + entity.setCategoryId(null == dictEntity ? StrConstant.EPMETY_STR : dictEntity.getId()); + entity.setCategoryCode(null == dictEntity ? StrConstant.EPMETY_STR : dictEntity.getCategoryCode()); + AtomicInteger i = new AtomicInteger(); + return entity; + }).collect(Collectors.toList()); + + insertBatch(list); + icPartymemberStyleImageService.insertBatch(imageList); + + /*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 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);*/ } + //生成导入失败数据对应的文件,修改任务状态 + String url = erroeImport(fileList); + upImportTask(url, taskId, tokenDto.getUserId(), true); + } catch (Exception e) { + String errorMsg = ExceptionUtils.getErrorStackTrace(e); + log.error("【党员风采信息导入】程序错误:{}", errorMsg); + upImportTask(null, taskId, tokenDto.getUserId(), false); } - 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 imageList = new ArrayList<>(); - List list = result.stream().map(item -> { - IcPartymemberStyleEntity entity = new IcPartymemberStyleEntity(); - entity.setId(UUID.randomUUID().toString().replace("-", "")); - entity.setCustomerId(tokenDto.getCustomerId()); - entity.setAgencyId(staffInfoCache.getAgencyId()); - entity.setGridId(gridMap.get(item.getGridName())); - GridInfoCache gridInfo = CustomerOrgRedis.getGridInfo(entity.getGridId()); - if (null != gridInfo) { - entity.setGridPids(gridInfo.getPids()); - } - entity.setName(item.getName()); - entity.setMainDeed(item.getMainDeed()); - IcPartymemberStyleCategoryDictEntity dictEntity=categoryDictMap.get(item.getCategoryName()); - entity.setCategoryId(null == dictEntity ? StrConstant.EPMETY_STR : dictEntity.getId()); - entity.setCategoryCode(null == dictEntity ? StrConstant.EPMETY_STR : dictEntity.getCategoryCode()); - AtomicInteger i = new AtomicInteger(); - return entity; - }).collect(Collectors.toList()); + } + + /** + * @Author sun + * @Description 党员风采导入,错误数据生成导入失败文件 + **/ + private String erroeImport(List fileList) throws IOException { + String url = ""; + //1.有错误数据则生成错误数据存放文件传到阿里云服务 + if (!org.springframework.util.CollectionUtils.isEmpty(fileList)) { + Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("导入失败的数据列表", "导入失败的数据列表"), + PartyMemberImportExcel.class, fileList); - insertBatch(list); - icPartymemberStyleImageService.insertBatch(imageList); + // 文件名 + 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); + } + } - 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 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 + "行未成功!"); + if (uploadResult == null || !uploadResult.success()) { + log.error("【党员风采信息导入】调用OSS上传结果描述文件失败"); + } + url = uploadResult.getData().getUrl(); + } + return url; + } + /** + * @Author sun + * @Description 党员风采导入修改导入任务状态 + **/ + private void upImportTask(String url, String importTaskId, String staffId, Boolean status) { + //更新导入任务数据 + ImportTaskCommonFormDTO importTaskForm = new ImportTaskCommonFormDTO(); + importTaskForm.setOperatorId(staffId); + importTaskForm.setBizType(ImportTaskConstants.BIZ_TYPE_PARTY_MEMBER); + importTaskForm.setTaskId(importTaskId); + importTaskForm.setResultDescFilePath(url); + if (status && StringUtils.isBlank(url)) { + importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS); + } else { + importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL); + importTaskForm.setResultDesc("党员风采导入存在程序错误"); + } + Result result = commonServiceOpenFeignClient.finishImportTask(importTaskForm); + if (!result.success()) { + throw new RenException(result.getInternalMsg()); } - return new Result().ok(str); } /** diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java index 9cfd689cfc..d1d176cbe9 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java @@ -650,7 +650,7 @@ public interface EpmetUserOpenFeignClient { @GetMapping(value = "/epmetuser/user/queryUserClient/{userId}") Result queryUserClient(@PathVariable("userId") String userId); - @PostMapping("/epmetuser/icresidemanddict/demandoption/demandoption") + @PostMapping("/epmetuser/icresidemanddict/demandoption") Result> getDemandOptions(); @PostMapping("/epmetuser/icresiuser/categorycount") diff --git a/epmet-user/epmet-user-server/pom.xml b/epmet-user/epmet-user-server/pom.xml index 6e1a4ae13d..d8bd604283 100644 --- a/epmet-user/epmet-user-server/pom.xml +++ b/epmet-user/epmet-user-server/pom.xml @@ -154,6 +154,11 @@ 2.0.0 compile + + com.epmet + common-service-client + 2.0.0 + diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java index 67c1aabd7e..0c3adbb8fa 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java @@ -34,6 +34,7 @@ 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.feign.ResultDataResolver; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.redis.RedisUtils; @@ -45,8 +46,8 @@ import com.epmet.commons.tools.utils.HttpClientManager; import com.epmet.commons.tools.utils.IpUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; -import com.epmet.constant.ImportTaskConstants; import com.epmet.constant.SystemMessageType; +import com.epmet.constants.ImportTaskConstants; import com.epmet.dto.IcResiUserDTO; import com.epmet.dto.form.*; import com.epmet.dto.result.*; @@ -57,31 +58,36 @@ import com.epmet.feign.OperCustomizeOpenFeignClient; import com.epmet.feign.OssFeignClient; import com.epmet.service.IcResiUserImportService; import com.epmet.service.IcResiUserService; -import com.epmet.service.ImportTaskService; import jodd.io.FileUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.tomcat.util.http.MimeHeaders; import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import org.springframework.web.context.request.RequestContextHolder; 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.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.Field; import java.net.URLEncoder; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.*; +import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; @@ -94,7 +100,7 @@ import java.util.stream.Collectors; @Slf4j @RestController @RequestMapping("icresiuser") -public class IcResiUserController { +public class IcResiUserController implements ResultDataResolver { /** * 居民上传临时目录 @@ -124,9 +130,6 @@ public class IcResiUserController { private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient; @Autowired private LoginUserUtil loginUserUtil; - @Autowired - private ImportTaskService importTaskService; - /** * 模板枚举 @@ -431,53 +434,118 @@ public class IcResiUserController { */ @NoRepeatSubmit @PostMapping("importExcel") - public void importExcelByEasyExcel(@RequestHeader("customerId") String customerId,@RequestPart("file") MultipartFile file, HttpServletResponse response) { + public Result importExcelByEasyExcel(@RequestHeader("customerId") String customerId,@RequestPart("file") MultipartFile file, HttpServletRequest multipartRequest, HttpServletResponse response) { if (file.isEmpty()) { throw new RenException("请上传文件"); } - // 校验文件类型 - String extension = FilenameUtils.getExtension(file.getOriginalFilename()); + String originalFilename = file.getOriginalFilename(); + // 一.校验文件类型 + String extension = FilenameUtils.getExtension(originalFilename); if (!"xls".equals(extension) && !"xlsx".equals(extension)) { throw new RenException("文件类型不匹配"); } String operatorId = loginUserUtil.getLoginUserId(); - String importTaskId; - // 记录导入任务 - if (importTaskService.existsProcessingTask(operatorId, ImportTaskConstants.BIZ_TYPE_RESI)) { - throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), - "已存在执行中的导入任务,请等待执行完成。", - "已存在执行中的导入任务,请等待执行完成。"); - } else { - importTaskId = importTaskService.createProcessTask(operatorId, ImportTaskConstants.BIZ_TYPE_RESI); - } + String importTaskId = icResiUserImportService.createImportTaskRecord(operatorId, ImportTaskConstants.BIZ_TYPE_RESI, originalFilename); - Path savePath = null; + // 二.缓存上传的文件 + Path importTempFileSavePath; try { String fileName = UUID.randomUUID().toString().concat(".").concat(extension); - savePath = IC_RESI_UPLOAD_DIR.resolve(fileName); + importTempFileSavePath = IC_RESI_UPLOAD_DIR.resolve(fileName); + IOUtils.copy(file.getInputStream(), new FileOutputStream(importTempFileSavePath.toString())); + } catch (Exception e) { + log.error("【上传居民信息】保存上传的文件失败:{}", ExceptionUtils.getErrorStackTrace(e)); + throw new RenException("上传失败"); + } - IOUtils.copy(file.getInputStream(), new FileOutputStream(savePath.toString())); - List formItemList = icResiUserService.listFormItems(customerId,IcFormCodeEnum.RESI_BASE_INFO.getCode()); + HttpServletRequest request = ((StandardMultipartHttpServletRequest)multipartRequest).getRequest(); - icResiUserImportService.importIcResiInfoFromExcel(importTaskId, formItemList, savePath.toString(), response); - } catch (Throwable e) { - String errorMsg = ExceptionUtils.getThrowableErrorStackTrace(e); - log.error("【导入居民信息失败】导入失败:{}", errorMsg); + HashMap headers = getHeadersFromRequest(request); + + // 三.异步执行导入 + CompletableFuture.runAsync(() -> { + + try { + // 睡眠2秒钟,等待主线程先结束,主线程会清空request对象的headers,等他执行了清空之后,我们这边再手动setHeader进去 + Thread.sleep(2000l); + System.out.println("请求头:" + headers); + } catch (InterruptedException e) { + String errorMsg = ExceptionUtils.getErrorStackTrace(e); + log.error("【上传居民信息】失败,睡眠2s发生中断:{}", errorMsg); + return; + } - // 要将导入任务状态设置为结束但不成功 - importTaskService.finish(importTaskId, ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL, operatorId, null, e.getMessage()); - throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); - } finally { try { - if (savePath != null){ - Files.delete(savePath); + setHeaders2Request(request, headers); + + List formItemList = icResiUserService.listFormItems(customerId,IcFormCodeEnum.RESI_BASE_INFO.getCode()); + icResiUserImportService.importIcResiInfoFromExcel(importTaskId, formItemList, importTempFileSavePath.toString(), response, IC_RESI_UPLOAD_DIR); + } catch (Throwable e) { + String errorMsg = ExceptionUtils.getThrowableErrorStackTrace(e); + log.error("【导入居民信息失败】导入失败:{}", errorMsg); + + // 要将导入任务状态设置为结束但不成功。不报错即成功,没有返回值 + icResiUserImportService.finishImportTask(importTaskId, operatorId, ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL, "系统异常,请查看系统日志", null); + } finally { + try { + if (importTempFileSavePath != null){ + Files.delete(importTempFileSavePath); + } + } catch (IOException e) { + log.error("【导入居民信息失败】清理上传的文件失败:{}", ExceptionUtils.getErrorStackTrace(e)); } - } catch (IOException e) { - log.error("【导入居民信息失败】清理上传的文件失败:{}", ExceptionUtils.getErrorStackTrace(e)); + + // 清理request对象 + RequestContextHolder.resetRequestAttributes(); } + }); + + return new Result(); + } + + private HashMap getHeadersFromRequest(HttpServletRequest request) { + HashMap headers = new HashMap<>(); + Enumeration headerNames = request.getHeaderNames(); + if (headerNames != null) { + while (headerNames.hasMoreElements()) { + String name = headerNames.nextElement(); + Enumeration values = request.getHeaders(name); + while (values.hasMoreElements()) { + String value = values.nextElement(); + headers.put(name, value); + } + } + } + return headers; + } + + private void setHeaders2Request(HttpServletRequest request, HashMap headers) { + for (Map.Entry kv : headers.entrySet()) { + setParam2Header(request, kv.getKey(), kv.getValue()); + } + } + + private void setParam2Header(HttpServletRequest requestFacade, String key, String value){ + Class requestFacadeClass = requestFacade.getClass(); + try { + Field requestField = requestFacadeClass.getDeclaredField("request"); + requestField.setAccessible(true); + Object requestObject = requestField.get(requestFacade); + + Field coyoteRequestField = requestObject.getClass().getDeclaredField("coyoteRequest"); + coyoteRequestField.setAccessible(true); + Object coyoteRequestObject = coyoteRequestField.get(requestObject); + + Field headers = coyoteRequestObject.getClass().getDeclaredField("headers"); + headers.setAccessible(true); + MimeHeaders o2 = (MimeHeaders)headers.get(coyoteRequestObject); + o2.addValue(key).setString(value); + } catch (Exception e) { + e.printStackTrace(); + log.error("为子线程设置请求头出错"); } } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcResiUserDao.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcResiUserDao.java index d152fc3776..35abe08623 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcResiUserDao.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcResiUserDao.java @@ -239,7 +239,7 @@ public interface IcResiUserDao extends BaseDao { Map getCategoryListMap(@Param("columns")List columns, @Param("icUserId") String icUserId); - Map selectResiInfoMap(@Param("idCard") String idCard); + Map selectResiInfoMap(@Param("idCard") String idCard, @Param("resiId") String resiId); List> selectResiUsers(@Param("types")List types,@Param("orgId")String orgId); diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/enums/IcResiUserTableEnum.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/enums/IcResiUserTableEnum.java index 9d72768f33..5bb46b6369 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/enums/IcResiUserTableEnum.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/enums/IcResiUserTableEnum.java @@ -1,6 +1,9 @@ package com.epmet.enums; import lombok.AllArgsConstructor; +import lombok.Data; + +import java.util.List; /** * @Description 描述 @@ -13,21 +16,40 @@ public enum IcResiUserTableEnum { /** * 注释 */ - IC_RESI_USER("ic_resi_user","社区居民基本信息录入表", 0, 3, null), - IC_PARTY_MEMBER("ic_party_member","党员信息录入表", 1, 2, "IS_PARTY"), - IC_ENSURE_HOUSE("ic_ensure_house","保障房人员信息录入表", 2, 2, "IS_ENSURE_HOUSE"), - IC_UNEMPLOYED("ic_unemployed","失业人员信息录入表", 3, 2, "IS_UNEMPLOYED"), - IC_VETERANS("ic_veterans","退役军人信息录入表", 4, 2, "IS_VETERANS"), - IC_UNITED_FRONT("ic_united_front","统战人员信息录入表", 5, 2, "IS_UNITED_FRONT"), - IC_VOLUNTEER("ic_volunteer","志愿者信息录入表", 6, 3, "IS_VOLUNTEER"), - IC_OLD_PEOPLE("ic_old_people","老年人信息录入表", 7, 2, "IS_OLD_PEOPLE"), - IC_SPECIAL("ic_special","特殊人群信息录入表", 8, 3, "IS_SPECIAL"); + IC_RESI_USER("ic_resi_user","社区居民基本信息录入表", 0, 3, null, true), + IC_PARTY_MEMBER("ic_party_member","党员信息录入表", 1, 2, "IS_PARTY", true), + IC_ENSURE_HOUSE("ic_ensure_house","保障房人员信息录入表", 2, 2, "IS_ENSURE_HOUSE", true), + IC_UNEMPLOYED("ic_unemployed","失业人员信息录入表", 3, 2, "IS_UNEMPLOYED", true), + IC_VETERANS("ic_veterans","退役军人信息录入表", 4, 2, "IS_VETERANS", true), + IC_UNITED_FRONT("ic_united_front","统战人员信息录入表", 5, 2, "IS_UNITED_FRONT", true), + IC_VOLUNTEER("ic_volunteer","志愿者信息录入表", 6, 3, "IS_VOLUNTEER", true), + IC_OLD_PEOPLE("ic_old_people","老年人信息录入表", 7, 2, "IS_OLD_PEOPLE", true), + IC_SPECIAL("ic_special","特殊人群信息录入表", 8, 3, "IS_SPECIAL", true), + +// 下面的是:没有实际数据库表,在ic_resi_user中有一个标记,但是导入的时候是有单独的sheet的 + IC_DBH("ic_resi_user","低保人员信息录入表", null, 2, "IS_DBH", false), + IC_YLFN("ic_resi_user","育龄妇女信息录入表", null, 2, "IS_YLFN", false), + IC_XFRY("ic_resi_user","信访人员信息录入表", null, 2, "IS_XFRY", false), + IC_KC("ic_resi_user","空巢老人信息录入表", null, 2, "IS_KC", false), + IC_SD("ic_resi_user","失独人员信息录入表", null, 2, "IS_SD", false), + IC_SN("ic_resi_user","失能人员信息录入表", null, 2, "IS_SN", false), + IC_SZ("ic_resi_user","失智人员信息录入表", null, 2, "IS_SZ", false), + IC_CJ("ic_resi_user","残疾人员信息录入表", null, 2, "IS_CJ", false), + IC_DB("ic_resi_user","大病人员信息录入表", null, 2, "IS_DB", false), + IC_MB("ic_resi_user","慢病人员信息录入表", null, 2, "IS_MB", false); private String tableName; + /** + * 表描述 && sheet名称 + */ private String tableComment; - private int sheetNo; + private Integer sheetNo; private int headRowNo; private String mainTableFlagColumnName; + /** + * 该sheet是否有数据库表 + */ + private boolean existsDBTable; /** * 根据表名获取枚举对象 @@ -63,34 +85,18 @@ public enum IcResiUserTableEnum { return tableName; } - public void setTableName(String tableName) { - this.tableName = tableName; - } - public String getTableComment() { return tableComment; } - public void setTableComment(String tableComment) { - this.tableComment = tableComment; - } - public int getSheetNo() { return sheetNo; } - public void setSheetNo(int sheetNo) { - this.sheetNo = sheetNo; - } - public int getHeadRowNo() { return headRowNo; } - public void setHeadRowNo(int headRowNo) { - this.headRowNo = headRowNo; - } - public String getMainTableFlagColumnName() { return mainTableFlagColumnName; } @@ -98,4 +104,8 @@ public enum IcResiUserTableEnum { public void setMainTableFlagColumnName(String mainTableFlagColumnName) { this.mainTableFlagColumnName = mainTableFlagColumnName; } + + public boolean isExistsDBTable() { + return existsDBTable; + } } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/handler/IcResiVirtualSheetImportListener.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/handler/IcResiVirtualSheetImportListener.java new file mode 100644 index 0000000000..79ddbea5a9 --- /dev/null +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/handler/IcResiVirtualSheetImportListener.java @@ -0,0 +1,44 @@ +package com.epmet.excel.handler; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import com.epmet.enums.IcResiUserTableEnum; +import com.epmet.service.impl.IcResiUserImportServiceImpl; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class IcResiVirtualSheetImportListener extends AnalysisEventListener> { + + private IcResiUserImportServiceImpl importService; + + private IcResiUserTableEnum sheetEnumObject; + + /** + * 身份证号列表 + */ + private List> resiInfo = new ArrayList<>(); + + public IcResiVirtualSheetImportListener(IcResiUserImportServiceImpl importService, IcResiUserTableEnum sheetEnumObject) { + this.importService = importService; + this.sheetEnumObject = sheetEnumObject; + } + + @Override + public void invoke(Map data, AnalysisContext context) { + if (data != null && data.size() > 0) { + resiInfo.add(data); + } + } + + @Override + public void doAfterAllAnalysed(AnalysisContext context) { + try { + importService.persistIcResiVirtualSheetExtraInfo(resiInfo, sheetEnumObject); + } finally { + // 清空数据 + resiInfo.clear(); + } + } +} diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserImportService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserImportService.java index 35748c9ddc..7358dcd961 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserImportService.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserImportService.java @@ -3,6 +3,7 @@ package com.epmet.service; import com.epmet.dto.result.FormItemResult; import javax.servlet.http.HttpServletResponse; +import java.nio.file.Path; import java.util.List; /** @@ -12,5 +13,23 @@ import java.util.List; */ public interface IcResiUserImportService { - void importIcResiInfoFromExcel(String importTaskId, List formItemList, String excelPathName, HttpServletResponse response); + void importIcResiInfoFromExcel(String importTaskId, List formItemList, String excelPathName, HttpServletResponse response, Path importTempPath); + + /** + * 创建导入任务 + * @param operatorId + * @param bizType + * @return + */ + String createImportTaskRecord(String operatorId, String bizType, String originFileName); + + /** + * 完成导入任务 + * @param importTaskId 任务ID + * @param operatorId 操作者ID + * @param processStatus 处理状态,见 ImportTaskConstants.PROCESS_STATUS_* + * @param resultDesc 结果描述,非必填 + * @param resultDescPath 结果描述文件,excel等文件,有错误的话需要传入,成功则不需要 + */ + void finishImportTask(String importTaskId, String operatorId, String processStatus, String resultDesc, String resultDescPath); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/ImportTaskService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/ImportTaskService.java deleted file mode 100644 index 65245abd98..0000000000 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/ImportTaskService.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.epmet.service; - - -/** - * - * - * @author generator generator@elink-cn.com - * @since v1.0.0 2022-02-15 - */ -public interface ImportTaskService { - - /** - * 检查指定类型该用户是否存在处理中的导入任务 - * @param operatorId 操作者ID - * @param bizType 业务类型。resi:居民 - * @return - */ - boolean existsProcessingTask(String operatorId, String bizType); - - /** - * 创建处理任务 - * @param operatorId - * @param bizType - */ - String createProcessTask(String operatorId, String bizType); - - /** - * 结束导入 - * @param taskId 任务id - * @param processStatus 处理状态 - * @param resultDescFile 结果描述文件 - * @param resultDesc 结果描述文本 - */ - Boolean finish(String taskId, String processStatus, String operatorId, String resultDescFile, String resultDesc); -} \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserImportServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserImportServiceImpl.java index 348766de19..414a077729 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserImportServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserImportServiceImpl.java @@ -12,6 +12,7 @@ import com.epmet.bean.ResiImportResiCategoryChangedCache; import com.epmet.bean.ResiImportChangedData; import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.constant.StrConstant; +import com.epmet.commons.tools.constant.ThreadLocalConstant; import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; import com.epmet.commons.tools.dto.result.OptionResultDTO; import com.epmet.commons.tools.exception.EpmetErrorCode; @@ -25,7 +26,7 @@ import com.epmet.commons.tools.redis.common.CustomerStaffRedis; import com.epmet.commons.tools.security.user.LoginUserUtil; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.Result; -import com.epmet.constant.ImportTaskConstants; +import com.epmet.constants.ImportTaskConstants; import com.epmet.dao.IcResiUserDao; import com.epmet.dao.IcUserChangeDetailedDao; import com.epmet.dao.IcUserChangeRecordDao; @@ -39,25 +40,27 @@ import com.epmet.entity.IcUserChangeRecordEntity; import com.epmet.entity.IcUserTransferRecordEntity; import com.epmet.enums.IcResiUserTableEnum; import com.epmet.excel.handler.IcResiImportDynamicExcelListener; -import com.epmet.feign.EpmetAdminOpenFeignClient; -import com.epmet.feign.EpmetUserOpenFeignClient; -import com.epmet.feign.GovOrgOpenFeignClient; -import com.epmet.feign.OperCustomizeOpenFeignClient; +import com.epmet.excel.handler.IcResiVirtualSheetImportListener; +import com.epmet.feign.*; import com.epmet.service.*; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import lombok.Data; 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.web.multipart.commons.CommonsMultipartFile; import javax.servlet.http.HttpServletResponse; -import java.io.File; -import java.io.IOException; -import java.net.URLEncoder; +import java.io.*; +import java.nio.file.Path; import java.util.*; import java.util.stream.Collectors; @@ -72,6 +75,11 @@ import java.util.stream.Collectors; @Service public class IcResiUserImportServiceImpl implements IcResiUserImportService, ResultDataResolver { + /** + * 身份证号列序号 + */ + public static final Integer ID_CARD_COLUMN_NO = 9; + // 错误和跳过excel行暂存 public static final ThreadLocal>> errorRows = new ThreadLocal<>(); @@ -130,8 +138,9 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res private RedisUtils redisUtils; @Autowired - private ImportTaskService importTaskService; - + private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient; + @Autowired + private OssFeignClient ossFeignClient; /** * 字表中不需要的列 @@ -198,24 +207,6 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res private String errorInfo; } - @Data - public static class SkipedRow { - - @Excel(name = "工作表") - private String sheetName; - - private String tableName; - - @Excel(name = "身份证号") - private String idCard; - - @Excel(name = "姓名") - private String name; - - @Excel(name = "信息") - private String info; - } - /** * 导入居民信息 * @param importTaskId 导入任务id @@ -224,7 +215,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res * @param response 响应对象 */ @Override - public void importIcResiInfoFromExcel(String importTaskId, List formItemList, String excelPathName, HttpServletResponse response) { + public void importIcResiInfoFromExcel(String importTaskId, List formItemList, String excelPathName, HttpServletResponse response, Path importTempPath) { String loginUserId = loginUserUtil.getLoginUserId(); String loginUserApp = loginUserUtil.getLoginUserApp(); @@ -243,8 +234,6 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res CustomerAgencyDTO agencyInfo = getResultDataOrThrowsException(govOrgOpenFeignClient.getAgencyById(currUserAgencyId), ServiceConstant.GOV_ORG_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), null, null); String customerId = agencyInfo.getCustomerId(); - boolean hasErrorRows = false; - try { initImportThreadLocal(customerId); @@ -254,12 +243,13 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res // 上传附表信息 for (IcResiUserTableEnum sheet : IcResiUserTableEnum.values()) { + // 是主表 if (sheet == IcResiUserTableEnum.IC_RESI_USER) { continue; } try { - importIcResiExtraInfoFromExcel(formItemList, excelPathName, sheet.getSheetNo(), sheet.getHeadRowNo(), currUserAgencyId, loginUserId, sheet.getTableName(), customerId); + importIcResiExtraInfoFromExcel(formItemList, excelPathName, sheet, currUserAgencyId, loginUserId, customerId); } catch (Exception e) { String errorMsg = ExceptionUtils.getErrorStackTrace(e); log.error("导入IC居民附加信息【{}】错误:{}", sheet.getTableComment(), errorMsg); @@ -275,30 +265,24 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res Map categoryChangedResis = newlyOrChangedResi.get().getCategoryChangedResis(); Map transferedResis = newlyOrChangedResi.get().getTransferedResis(); - log.info("类别变动居民数:{}", categoryChangedResis.size()); - log.info("调动居民数:{}", transferedResis.size()); - //保存调动或者变更记录 saveNewResiCategoryRecord(); saveResiCategoryChangedRecord(categoryChangedResis); saveTransferedResiRecord(transferedResis); - hasErrorRows = hasErrorRows(); - - try { - // todo 做了导入记录之后,这里就要判断,没有错误就不生成文件了 - downLoadResults(hasErrorRows, response); - } catch (Exception e) { - log.error("【导入IC居民附加信息】下载导入结果信息失败:{}", ExceptionUtils.getErrorStackTrace(e)); - } - - // 更新上传记录 - if (hasErrorRows) { - importTaskService.finish(importTaskId, ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL, loginUserId, - null, null); + // 生成错误描述文件 && 更新上传记录 + LinkedList errorRows = getErrorRows(); + if (CollectionUtils.isNotEmpty(errorRows)) { + String resultDescFilePath = null; + try { + resultDescFilePath = generateResultDescFile(errorRows, importTempPath); + } catch (Exception e) { + String errorMsg = ExceptionUtils.getErrorStackTrace(e); + log.error("【居民信息导入】", errorMsg); + } + finishImportTask(importTaskId, loginUserId, ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL,null, resultDescFilePath); } else { - importTaskService.finish(importTaskId, ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS, loginUserId, - null, null); + finishImportTask(importTaskId, loginUserId, ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS,null, null); } } catch (Exception e) { @@ -323,19 +307,16 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res } /** - * 是否有错误行 + * 返回错误行 * @return */ - private Boolean hasErrorRows() { - boolean hasError = false; - Map> tableAndErrorRows = errorRows.get(); - for (Map.Entry> entry:tableAndErrorRows.entrySet()) { - if (entry.getValue().size() != 0) { - hasError = true; - } + private LinkedList getErrorRows() { + LinkedList list = new LinkedList<>(); + for (Map.Entry> entry : errorRows.get().entrySet()) { + list.addAll(entry.getValue()); } - return hasError; + return list; } /** @@ -346,12 +327,6 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res String operatorId = loginUserUtil.getLoginUserId(); String importTag = operatorId + System.currentTimeMillis(); - // 跳过的,不导入的行 - Map> skipedRowsMap = new LinkedHashMap<>(); - for (IcResiUserTableEnum e : IcResiUserTableEnum.values()) { - skipedRowsMap.put(e.getTableName(), new LinkedList<>()); - } - // 错误信息 Map> errorRowsMap = new LinkedHashMap<>(); for (IcResiUserTableEnum e : IcResiUserTableEnum.values()) { @@ -399,19 +374,35 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res * * @param formItemList * @param excelPathName - * @param sheetNo - * @param headRowNumber + * @param sheetEnumObject sheet枚举对象 * @param currUserAgencyId * @param currentUserId - * @param targetTableName 要插入哪一个表 * @return */ - private void importIcResiExtraInfoFromExcel(List formItemList, String excelPathName, int sheetNo, int headRowNumber, String currUserAgencyId, String currentUserId, - String targetTableName, String customerId) { - - IcResiImportDynamicExcelListener readListener = new IcResiImportDynamicExcelListener(this, customerId, currentUserId, currUserAgencyId, null, - false, targetTableName, formItemList, headRowNumber); - EasyExcelFactory.read(new File(excelPathName)).registerReadListener(readListener).headRowNumber(headRowNumber).sheet(sheetNo).doRead(); + private void importIcResiExtraInfoFromExcel(List formItemList, String excelPathName, IcResiUserTableEnum sheetEnumObject, String currUserAgencyId, + String currentUserId, String customerId) { + + // 如果该sheet对应有实际的数据库表,使用items动态的解析 + if (sheetEnumObject.isExistsDBTable()) { + IcResiImportDynamicExcelListener readListener = new IcResiImportDynamicExcelListener( + this, customerId, currentUserId, currUserAgencyId, null, + false, sheetEnumObject.getTableName(), formItemList, sheetEnumObject.getHeadRowNo()); + + EasyExcelFactory.read(new File(excelPathName)) + .registerReadListener(readListener) + .headRowNumber(sheetEnumObject.getHeadRowNo()) + .sheet(sheetEnumObject.getTableComment()) + .doRead(); + } else { + // 实际上并不存在该sheet对应的数据库表,此时无法使用items解析,就要读取固定的ID_CARD字段数据,更新主表字段为true + IcResiVirtualSheetImportListener vitualSheetReadListener = new IcResiVirtualSheetImportListener(this, sheetEnumObject); + + EasyExcelFactory.read(new File(excelPathName)) + .registerReadListener(vitualSheetReadListener) + .headRowNumber(sheetEnumObject.getHeadRowNo()) + .sheet(sheetEnumObject.getTableComment()) + .doRead(); + } } /** @@ -434,7 +425,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res String idCard = columnAndValues.get("ID_CARD"); - Map existingResiMap = icResiUserDao.selectResiInfoMap(idCard); + Map existingResiMap = icResiUserDao.selectResiInfoMap(idCard, null); if (existingResiMap == null) { // 新导入的居民,因为还没有读取子sheet,所以这些居民类别没有办法获取,先默认设置成0,后面读取子sheet的时候再更新 @@ -446,6 +437,16 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res columnAndValues.put("IS_UNITED_FRONT", "0"); columnAndValues.put("IS_VETERANS", "0"); columnAndValues.put("IS_VOLUNTEER", "0"); + columnAndValues.put("IS_DBH", "0"); + columnAndValues.put("IS_YLFN", "0"); + columnAndValues.put("IS_XFRY", "0"); + columnAndValues.put("IS_KC", "0"); + columnAndValues.put("IS_SD", "0"); + columnAndValues.put("IS_SN", "0"); + columnAndValues.put("IS_SZ", "0"); + columnAndValues.put("IS_CJ", "0"); + columnAndValues.put("IS_DB", "0"); + columnAndValues.put("IS_MB", "0"); } else { // 该居民已存在,要做更新操作,因为还没有读取子sheet,所以这些居民最新类别没有办法获取,先设置上旧的数据 columnAndValues.put("IS_ENSURE_HOUSE", existingResiMap.get("IS_ENSURE_HOUSE")); @@ -456,6 +457,16 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res columnAndValues.put("IS_UNITED_FRONT", existingResiMap.get("IS_UNITED_FRONT")); columnAndValues.put("IS_VETERANS", existingResiMap.get("IS_VETERANS")); columnAndValues.put("IS_VOLUNTEER", existingResiMap.get("IS_VOLUNTEER")); + columnAndValues.put("IS_DBH", existingResiMap.get("IS_DBH")); + columnAndValues.put("IS_YLFN", existingResiMap.get("IS_YLFN")); + columnAndValues.put("IS_XFRY", existingResiMap.get("IS_XFRY")); + columnAndValues.put("IS_KC", existingResiMap.get("IS_KC")); + columnAndValues.put("IS_SD", existingResiMap.get("IS_SD")); + columnAndValues.put("IS_SN", existingResiMap.get("IS_SN")); + columnAndValues.put("IS_SZ", existingResiMap.get("IS_SZ")); + columnAndValues.put("IS_CJ", existingResiMap.get("IS_CJ")); + columnAndValues.put("IS_DB", existingResiMap.get("IS_DB")); + columnAndValues.put("IS_MB", existingResiMap.get("IS_MB")); } columnAndValues.put("AGENCY_ID", currUserAgencyId); @@ -472,12 +483,6 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res ResiImportChangedData transferData; if ((transferData = this.getResiImportTrasferData(existingResiMap, columnAndValues)) != null) { newlyOrChangedResi.get().getTransferedResis().put(existingResiMap.get("ID"), transferData); - } else { - // 组织维度没有发生变化,看是否有居民类型变更 - ResiImportChangedData d = getResiImportCategoryChangedData(existingResiMap, columnAndValues); - if (d != null) { - newlyOrChangedResi.get().getCategoryChangedResis().put(existingResiMap.get("ID"), d); - } } } else { // 新增居民 @@ -485,22 +490,8 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res columnAndValues.put("CREATED_BY", currentUserId); columnAndValues.put("ID", resiId); - icResiUserDao.add(tableName, columnAndValues); - // 过滤出本居民含有哪些类别 - Map resiCategories = resiCategoryColumnNameAndLabel.get().keySet() - .stream() - .filter((categoryColumnName) -> "1".equals(columnAndValues.get(categoryColumnName))) - .collect(Collectors.toMap((k) -> k, (k) -> columnAndValues.get(k))); - -// newlyOrChangedResi.get().getNewResis().put(resiId, -// new ResiImportCategoryData(columnAndValues.get("AGENCY_ID"), -// columnAndValues.get("GRID_ID"), -// columnAndValues.get("VILLAGE_ID"), -// columnAndValues.get("BUILD_ID"), -// columnAndValues.get("UNIT_ID"), -// columnAndValues.get("HOME_ID"), -// resiCategories)); + icResiUserDao.add(tableName, columnAndValues); ResiImportCategoryData categoryData = new ResiImportCategoryData(resiId, columnAndValues.get("AGENCY_ID"), @@ -509,7 +500,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res columnAndValues.get("BUILD_ID"), columnAndValues.get("UNIT_ID"), columnAndValues.get("HOME_ID"), - resiCategories); + new HashMap<>()); redisUtils.hMSet(RedisKeys.icResiImportResiCategoryKey(newlyOrChangedResi.get().getImportTag(), "add", resiId), BeanUtil.beanToMap(categoryData)); categoryData = null; @@ -567,13 +558,13 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res } // 检查用户是否存在 - Map resiInfoMap = icResiUserDao.selectResiInfoMap(idCard); + Map existResiInfoMap = icResiUserDao.selectResiInfoMap(idCard, null); - if (resiInfoMap == null || resiInfoMap.size() == 0) { + if (existResiInfoMap == null || existResiInfoMap.size() == 0) { throw new RenException(EpmetErrorCode.RESI_NOT_FOUND.getCode(), String.format("身份证号为【%s】的居民信息未找到,请确认该居民信息存在", idCard)); } - String icResiId = resiInfoMap.get("ID"); + String icResiId = existResiInfoMap.get("ID"); columnAndValues.put("IC_RESI_USER", icResiId); columnAndValues.put("CUSTOMER_ID", loginUserUtil.getLoginUserCustomerId()); @@ -601,7 +592,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res // 保存到类别变更缓存中 saveSubTableInfoToCategoryChangedResiCache(icResiId, Objects.requireNonNull(IcResiUserTableEnum.getObjectByTableName(targetTableName)).getMainTableFlagColumnName(), - resiInfoMap); + existResiInfoMap); } catch (Exception e) { String errorMsg; @@ -624,6 +615,45 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res } } + /** + * 虚拟(不对应实际的数据库表)sheet的数据导入持久化 + * @param sheetEnumObject + */ + public void persistIcResiVirtualSheetExtraInfo(List> resiInfo, IcResiUserTableEnum sheetEnumObject) { + for (Map columnAndValues : resiInfo) { + String idCard = columnAndValues.get(ID_CARD_COLUMN_NO); + try { + Map resiInfoMap = icResiUserDao.selectResiInfoMap(idCard, null); + + if (resiInfoMap == null || resiInfoMap.size() == 0) { + throw new RenException(EpmetErrorCode.RESI_NOT_FOUND.getCode(), String.format("身份证号为【%s】的居民信息未找到,请确认该居民信息存在", idCard)); + } + String icResiId = resiInfoMap.get("ID"); + + // 更新主表中该居民类型字段为true + updateMainTableResiTypeFlag(sheetEnumObject, icResiId); + + // 保存类别变更信息 + saveSubTableInfoToCategoryChangedResiCache(icResiId, sheetEnumObject.getMainTableFlagColumnName(), resiInfoMap); + } catch (Exception e) { + String errorMsg; + if (e instanceof RenException || e instanceof EpmetException) { + errorMsg = e.getMessage(); + } else { + errorMsg = "未知系统错误"; + log.error(ExceptionUtils.getErrorStackTrace(e)); + } + + ErrorRow errorRow = new ErrorRow(); + errorRow.setName(columnAndValues.get("NAME")); + errorRow.setIdCard(idCard); + errorRow.setErrorInfo(errorMsg); + errorRow.setTableName(sheetEnumObject.getTableName()); + errorRows.get().get(sheetEnumObject.getTableName()).add(errorRow); + } + } + } + /** * 去掉多余的列 * @param originColumnAndValues @@ -1067,38 +1097,51 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res private void updateMainTableResiTypeFlag(IcResiUserTableEnum icResiUserTableEnum, String resiUserId) { HashMap map = new HashMap<>(); map.put(icResiUserTableEnum.getMainTableFlagColumnName(), true); - icResiUserDao.upTable("ic_resi_user", resiUserId, map); + icResiUserDao.upTable(IcResiUserTableEnum.IC_RESI_USER.getTableName(), resiUserId, map); } /** - * 下载导入结果 - * @param response + * 生成导入结果 * @throws IOException */ - public void downLoadResults(Boolean hasErrorRows, HttpServletResponse response) throws IOException { - String fileName; - - // 判断是否有错误信息,以确定文件名 - if (hasErrorRows) { - fileName = "导入失败条目清单.xls"; - } else { - fileName = "导入成功.xls"; + public String generateResultDescFile(LinkedList errorRows, Path importTempDir) throws IOException { + errorRows.forEach(row -> {row.setSheetName(IcResiUserTableEnum.getObjectByTableName(row.tableName).getTableComment());}); + Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("导入失败的数据列表","导入失败的数据列表"), + ErrorRow.class, errorRows); + + // 文件名 + String resultDescFileName = UUID.randomUUID().toString().concat(".xls"); + + 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); + } } - response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); - response.setHeader("content-Type", "application/vnd.ms-excel"); - response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(fileName, "UTF-8")); - LinkedList list = new LinkedList<>(); - for (Map.Entry> entry : errorRows.get().entrySet()) { - list.addAll(entry.getValue()); + if (uploadResult == null || !uploadResult.success()) { + log.error("【居民信息导入】调用OSS上传结果描述文件失败"); + return null; } - - list.forEach(row -> {row.setSheetName(IcResiUserTableEnum.getObjectByTableName(row.tableName).getTableComment());}); - - Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("导入失败的列表","导入失败列表(没有数据说明全部成功)"), - ErrorRow.class, list); - - workbook.write(response.getOutputStream()); + return uploadResult.getData().getUrl(); } /** @@ -1121,93 +1164,6 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res return null; } - HashMap existingResiCategories = new HashMap<>(); - HashMap newResiCategories = new HashMap<>(); - - for (String categoryColumnName : resiCategoryColumnNameAndLabel.get().keySet()) { - String oldCategoryValue = existingResiMap.get(categoryColumnName); - String newCategoryValue = newResiMap.get(categoryColumnName); - - if (StringUtils.isBlank(oldCategoryValue)) oldCategoryValue = "0"; - if (StringUtils.isBlank(newCategoryValue)) newCategoryValue = "0"; - - if ("1".equals(oldCategoryValue) || "1".equals(newCategoryValue)) { - // 新旧值有一个为1,则放入 - existingResiCategories.put(categoryColumnName, oldCategoryValue); - newResiCategories.put(categoryColumnName, newCategoryValue); - } - -// if ("1".equals(oldCategoryValue)) { -// existingResiCategories.put(categoryColumnName, oldCategoryValue); -// } -// -// if ("1".equals(newCategoryValue)) { -// newResiCategories.put(categoryColumnName, newCategoryValue); -// } - } - - ResiImportCategoryData oldOne = new ResiImportCategoryData( - existingResiMap.get("ID"), - existingResiMap.get("AGENCY_ID"), - existingResiMap.get("GRID_ID"), - existingResiMap.get("VILLAGE_ID"), - existingResiMap.get("BUILD_ID"), - existingResiMap.get("UNIT_ID"), - existingResiMap.get("HOME_ID"), - existingResiCategories); - - ResiImportCategoryData newOne = new ResiImportCategoryData( - newResiMap.get("ID"), - newResiMap.get("AGENCY_ID"), - newResiMap.get("GRID_ID"), - newResiMap.get("VILLAGE_ID"), - newResiMap.get("BUILD_ID"), - newResiMap.get("UNIT_ID"), - newResiMap.get("HOME_ID"), - newResiCategories); - - return new ResiImportChangedData(oldOne, newOne); - } - - /** - * 类别变更的居民信息封装。只要发生变化,0或者1都要保存 - * 1. - * @param existingResiMap - * @param newResiMap - * @return - */ - private ResiImportChangedData getResiImportCategoryChangedData(Map existingResiMap, Map newResiMap) { - // 发生变化的类别列明 - HashMap oldCategories = new HashMap<>(); - HashMap newCategories = new HashMap<>(); - - Set categoryColumnNames = resiCategoryColumnNameAndLabel.get().keySet(); - for (String categoryColumnName : categoryColumnNames) { - - String existingColumnValue = existingResiMap.get(categoryColumnName); - String newColumnValue = newResiMap.get(categoryColumnName); - - // 先转为0再对比 - if (StringUtils.isBlank(existingColumnValue)) existingColumnValue = "0"; - if (StringUtils.isBlank(newColumnValue)) newColumnValue = "0"; - - if (!existingColumnValue.equals(newColumnValue)) { - oldCategories.put(categoryColumnName, existingColumnValue); - newCategories.put(categoryColumnName, newColumnValue); - } - -// if (StringUtils.isAllBlank(existingColumnValue, newColumnValue)) { -// // 都为空,则没发生变化 -// continue; -// } else { -// -// } - } - - if (oldCategories.size() == 0) { - return null; - } - ResiImportCategoryData oldOne = new ResiImportCategoryData( existingResiMap.get("ID"), existingResiMap.get("AGENCY_ID"), @@ -1216,7 +1172,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res existingResiMap.get("BUILD_ID"), existingResiMap.get("UNIT_ID"), existingResiMap.get("HOME_ID"), - oldCategories); + new HashMap<>()); ResiImportCategoryData newOne = new ResiImportCategoryData( newResiMap.get("ID"), @@ -1226,7 +1182,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res newResiMap.get("BUILD_ID"), newResiMap.get("UNIT_ID"), newResiMap.get("HOME_ID"), - newCategories); + new HashMap<>()); return new ResiImportChangedData(oldOne, newOne); } @@ -1235,20 +1191,19 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res * * @param icResiId 居民id * @param columnName 该项信息在主表的列名 + * @param existResiInfoMap 已存在的居民信息map */ - private void saveSubTableInfoToCategoryChangedResiCache(String icResiId, String columnName, Map resiInfoMap) { + private void saveSubTableInfoToCategoryChangedResiCache(String icResiId, String columnName, Map existResiInfoMap) { ResiImportResiCategoryChangedCache cc = newlyOrChangedResi.get(); -// Map newResis = cc.getNewResis(); Map categoryChangedResis = cc.getCategoryChangedResis(); Map transferedResis = cc.getTransferedResis(); -// ResiImportCategoryData newResi = newResis.get(icResiId); + // 为新增居民 String userCateRedisKey = RedisKeys.icResiImportResiCategoryKey(newlyOrChangedResi.get().getImportTag(), "add", icResiId); - Map < String, Object > addUserMap = redisUtils.hGetAll(userCateRedisKey); + Map addUserMap = redisUtils.hGetAll(userCateRedisKey); if (addUserMap != null && addUserMap.size() > 0) { - //说明是新增居民 ResiImportCategoryData newResiCateData = ConvertUtils.mapToEntity(addUserMap, ResiImportCategoryData.class); newResiCateData.getCategories().put(columnName, "1"); redisUtils.hMSet(userCateRedisKey, BeanUtil.beanToMap(newResiCateData)); @@ -1256,47 +1211,53 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res return; } - ResiImportChangedData categoryChangedData = categoryChangedResis.get(icResiId); - if (categoryChangedData != null) { - // 说明是类别变更的居民 - Map oldCategories = categoryChangedData.getOldData().getCategories(); - Map newCategories = categoryChangedData.getNewData().getCategories(); - - if ("0".equals(resiInfoMap.get(columnName))) { - oldCategories.put(columnName, "0"); - newCategories.put(columnName, "1"); - } - - return; - } + String oldValue = existResiInfoMap.get(columnName); + // 为发生调动的居民。不管标志相同与否都往里面put ResiImportChangedData transferedData = transferedResis.get(icResiId); if (transferedData != null) { - // 说明是发生调动的居民,新数据值为1 Map newCategories = transferedData.getNewData().getCategories(); Map oldCategories = transferedData.getOldData().getCategories(); - String oldValue = resiInfoMap.get(columnName); - if (StringUtils.isBlank(oldValue)) { - oldValue = "0"; - } - - oldCategories.put(columnName, oldValue); + oldCategories.put(columnName, oldValue); newCategories.put(columnName, "1"); return; } - if ("0".equals(resiInfoMap.get(columnName))) { - // 非新增,非调动,变更的数据不在主sheet中,而在附sheet中。看是否发生人员类型变更(从0->1) - ResiImportCategoryData oldOne = new ResiImportCategoryData(); - ResiImportCategoryData newOne = new ResiImportCategoryData(); + // 类别变更的居民。不管标志相同与否都往里面put + ResiImportChangedData categoryChangedData = categoryChangedResis.get(icResiId); + if (categoryChangedData != null) { + Map oldCategories = categoryChangedData.getOldData().getCategories(); + Map newCategories = categoryChangedData.getNewData().getCategories(); - oldOne.getCategories().put(columnName, "0"); - newOne.getCategories().put(columnName, "1"); + oldCategories.put(columnName, oldValue); + newCategories.put(columnName, "1"); - ResiImportChangedData cd = new ResiImportChangedData(oldOne, newOne); - categoryChangedResis.put(icResiId, cd); + return; } + + // 非新增,非调动,可能是类别变更的,只是主表中没有数据,只有附加表的数据 + ResiImportCategoryData oldOne = new ResiImportCategoryData(); + ResiImportCategoryData newOne = new ResiImportCategoryData(); + + oldOne.setAgencyId(existResiInfoMap.get("AGENCY_ID")); + oldOne.setGridId(existResiInfoMap.get("GRID_ID")); + oldOne.setVillageId(existResiInfoMap.get("VILLAGE_ID")); + oldOne.setBuildId(existResiInfoMap.get("BUILD_ID")); + oldOne.setUnitId(existResiInfoMap.get("UNIT_ID")); + oldOne.setHomeId(existResiInfoMap.get("HOME_ID")); + oldOne.getCategories().put(columnName, oldValue); + + newOne.setAgencyId(existResiInfoMap.get("AGENCY_ID")); + newOne.setGridId(existResiInfoMap.get("GRID_ID")); + newOne.setVillageId(existResiInfoMap.get("VILLAGE_ID")); + newOne.setBuildId(existResiInfoMap.get("BUILD_ID")); + newOne.setUnitId(existResiInfoMap.get("UNIT_ID")); + newOne.setHomeId(existResiInfoMap.get("HOME_ID")); + newOne.getCategories().put(columnName, "1"); + + ResiImportChangedData cd = new ResiImportChangedData(oldOne, newOne); + categoryChangedResis.put(icResiId, cd); } /** @@ -1316,7 +1277,9 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res Map oldCategories = oldData.getCategories(); Map newCategories = newData.getCategories(); - fillResiSubCategoryInfo4TransferAndCategoryChange(oldData, newData); + Map resiInfoMap = icResiUserDao.selectResiInfoMap(null, resiId); + + fillResiSubCategoryInfo4TransferAndCategoryChange(oldData, newData, resiInfoMap); StringBuilder sbBefore = new StringBuilder(""); StringBuilder sbAfter = new StringBuilder(""); @@ -1333,23 +1296,19 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res } // 生成changeRecord并存入 - IcResiUserEntity resiInfo = icResiUserDao.selectById(resiId); - IcUserChangeRecordEntity changeRecord = fillChangeRecord(loginUserUtil.getLoginUserCustomerId(), resiId, resiInfo.getName(), null, loginUserUtil.getLoginUserId(), + IcUserChangeRecordEntity changeRecord = fillChangeRecord(loginUserUtil.getLoginUserCustomerId(), resiId, resiInfoMap.get("NAME"), null, loginUserUtil.getLoginUserId(), operator.getRealName() , descBefore, descAfter, "category", "类别", "", now); icUserChangeRecordDao.insert(changeRecord); for (Map.Entry columnEntry : newCategories.entrySet()) { String newValue = columnEntry.getValue(); String oldValue = oldCategories.get(columnEntry.getKey()); - oldValue = oldValue == null ? "0" : oldValue; if (newValue.equals(oldValue)) { // 新旧值相等,跳过 continue; } - int value = newValue.equals("1") && oldValue.equals("0") ? 1 : -1; - String agencyId = newData.getAgencyId(); String gridId = newData.getGridId(); String villageId = newData.getVillageId(); @@ -1357,17 +1316,9 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res String unitId = newData.getUnitId(); String homeId = newData.getHomeId(); - // 如果只有附加表信息,但是没有主表信息,并且附加表基础信息很多空着的,此处需要从主表获取了然后填充一下该信息 - if (agencyId == null) agencyId = resiInfo.getAgencyId(); - if (gridId == null) gridId = resiInfo.getGridId(); - if (villageId == null) villageId = resiInfo.getVillageId(); - if (buildId == null) buildId = resiInfo.getBuildId(); - if (unitId == null) unitId = resiInfo.getUnitId(); - if (homeId == null) homeId = resiInfo.getHomeId(); - IcUserChangeDetailedEntity newDetail = fillChangeDetail(loginUserUtil.getLoginUserCustomerId(), resiId, changeRecord.getId(), agencyId, gridId, villageId, buildId, unitId, - homeId, "category", "类别", columnEntry.getKey(), value, resiInfo.getPids()); + homeId, "category", "类别", columnEntry.getKey(), 1, resiInfoMap.get("PIDS")); icUserChangeDetailedDao.insert(newDetail); } @@ -1425,10 +1376,10 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res icUserChangeRecordDao.insert(changeRecord); // 插入changeDetail - for (Map.Entry column : newResiInfoObj.getCategories().entrySet()) { + for (Map.Entry mainTableColumn : newResiInfoObj.getCategories().entrySet()) { IcUserChangeDetailedEntity changedetail = fillChangeDetail(loginUserUtil.getLoginUserCustomerId(), newResiInfoObj.getResiId(), changeRecord.getId(), newResiInfoObj.getAgencyId(), newResiInfoObj.getGridId(), newResiInfoObj.getVillageId(), newResiInfoObj.getBuildId(), newResiInfoObj.getUnitId(), - newResiInfoObj.getHomeId(), "add", "新增", column.getKey(), 1, resiInfo.getPids()); + newResiInfoObj.getHomeId(), "add", "新增", mainTableColumn.getKey(), 1, resiInfo.getPids()); icUserChangeDetailedDao.insert(changedetail); changedetail = null; @@ -1451,11 +1402,15 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res for (Map.Entry resi : transferedResis.entrySet()) { String resiId = resi.getKey(); + Map resiInfoMap = icResiUserDao.selectResiInfoMap(null, resiId); + String resiName = resiInfoMap.get("NAME"); + String pids = resiInfoMap.get("PIDS"); + ResiImportCategoryData oldData = resi.getValue().getOldData(); ResiImportCategoryData newData = resi.getValue().getNewData(); // 把附加表的旧数据填充到新数据中 - fillResiSubCategoryInfo4TransferAndCategoryChange(oldData, newData); + fillResiSubCategoryInfo4TransferAndCategoryChange(oldData, newData, resiInfoMap); StringBuilder sbBefore = new StringBuilder(); StringBuilder sbAfter = new StringBuilder(); @@ -1466,7 +1421,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res String oldBuildId = oldData.getBuildId(); String oldUnitId = oldData.getUnitId(); String oldHomeId = oldData.getHomeId(); - // + String newAgencyId = newData.getAgencyId(); String newGridId = newData.getGridId(); String newvillageId = newData.getVillageId(); @@ -1476,22 +1431,22 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res IcResiUserOrgMsgFormDTO oldOrgFormDTO = new IcResiUserOrgMsgFormDTO(); oldOrgFormDTO.setCustomerId(customerId); - oldOrgFormDTO.setAgencyId(oldData.getAgencyId()); - oldOrgFormDTO.setGridId(oldData.getGridId()); - oldOrgFormDTO.setNeighborHoodId(oldData.getVillageId()); - oldOrgFormDTO.setBuildingId(oldData.getBuildId()); - oldOrgFormDTO.setBuildingUnitId(oldData.getUnitId()); - oldOrgFormDTO.setHouseId(oldData.getHomeId()); + oldOrgFormDTO.setAgencyId(oldAgencyId); + oldOrgFormDTO.setGridId(oldGridId); + oldOrgFormDTO.setNeighborHoodId(oldvillageId); + oldOrgFormDTO.setBuildingId(oldBuildId); + oldOrgFormDTO.setBuildingUnitId(oldUnitId); + oldOrgFormDTO.setHouseId(oldHomeId); Result oldOrgInfoRst = govOrgOpenFeignClient.icResiUserOrgMsg(oldOrgFormDTO); IcResiUserOrgMsgFormDTO newOrgInfo = new IcResiUserOrgMsgFormDTO(); newOrgInfo.setCustomerId(customerId); - newOrgInfo.setAgencyId(newData.getAgencyId()); - newOrgInfo.setGridId(newData.getGridId()); - newOrgInfo.setNeighborHoodId(newData.getVillageId()); - newOrgInfo.setBuildingId(newData.getBuildId()); - newOrgInfo.setBuildingUnitId(newData.getUnitId()); - newOrgInfo.setHouseId(newData.getHomeId()); + newOrgInfo.setAgencyId(newAgencyId); + newOrgInfo.setGridId(newGridId); + newOrgInfo.setNeighborHoodId(newvillageId); + newOrgInfo.setBuildingId(newBuildId); + newOrgInfo.setBuildingUnitId(newUnitId); + newOrgInfo.setHouseId(newHomeId); Result newOrgInfoRst = govOrgOpenFeignClient.icResiUserOrgMsg(newOrgInfo); IcResiUserOrgMsgResultDTO oldOrg = null; @@ -1554,16 +1509,14 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res } } - IcResiUserEntity resiInfo = icResiUserDao.selectById(resiId); - // 保存 transferRecord - IcUserTransferRecordEntity transferRecord = fillTransferRecord(resiInfo, operator, customerId, oldAgencyId, oldGridId, - oldvillageId, oldBuildId, oldUnitId, oldHomeId, customerId, + IcUserTransferRecordEntity transferRecord = fillTransferRecord(resiId, resiName, operator, customerId, + oldAgencyId, oldGridId, oldvillageId, oldBuildId, oldUnitId, oldHomeId, customerId, newAgencyId, newGridId, newvillageId, newBuildId, newUnitId, newHomeId, oldOrg, newOrg); icUserTransferRecordDao.insert(transferRecord); // 保存 调动changeRecord - IcUserChangeRecordEntity transferChangeRecord = fillChangeRecord(customerId, resiId, resiInfo.getName(), transferRecord.getId(), operator.getStaffId(), + IcUserChangeRecordEntity transferChangeRecord = fillChangeRecord(customerId, resiId, resiName, transferRecord.getId(), operator.getStaffId(), operator.getRealName(), sbBefore.toString(), sbAfter.toString(), "transfer", "调动", "", now); icUserChangeRecordDao.insert(transferChangeRecord); @@ -1572,17 +1525,14 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res sbAfter = new StringBuilder(); // 过滤居民类别的key并集 - Set bingji = new HashSet<>(); - newData.getCategories().keySet().forEach((k) -> bingji.add(k)); - oldData.getCategories().keySet().forEach((k) -> bingji.add(k)); +// Set bingji = new HashSet<>(); +// newData.getCategories().keySet().forEach((k) -> bingji.add(k)); +// oldData.getCategories().keySet().forEach((k) -> bingji.add(k)); - for (String category : bingji) { + for (String category : newData.getCategories().keySet()) { String newColumnValue = newData.getCategories().get(category); String oldColumnValue = oldData.getCategories().get(category); - if (oldColumnValue == null) oldColumnValue = "0"; - if (newColumnValue == null) newColumnValue = "0"; - if (newColumnValue.equals(oldColumnValue)) { continue; } @@ -1600,7 +1550,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res String categoryDescAfter = sbAfter.toString(); if (!StringUtils.isAllBlank(categoryDescBefore, categoryDescAfter)) { - IcUserChangeRecordEntity categoryChangeRecord = fillChangeRecord(customerId, resiId, resiInfo.getName(), transferRecord.getId(), operator.getStaffId(), + IcUserChangeRecordEntity categoryChangeRecord = fillChangeRecord(customerId, resiId, resiName, transferRecord.getId(), operator.getStaffId(), operator.getRealName(), categoryDescBefore, categoryDescAfter , "category", "类别", "", now); icUserChangeRecordDao.insert(categoryChangeRecord); } @@ -1613,9 +1563,9 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res // 之前是这个类型,那这个类型需要-1 String oldValue = oldCategories.getValue(); if ("1".equals(oldValue)) { - IcUserChangeDetailedEntity changeDetail = fillChangeDetail(customerId, resiId, transferChangeRecord.getId(), oldData.getAgencyId(), - oldData.getGridId(), oldData.getVillageId(), oldData.getBuildId(), oldData.getUnitId(), - oldData.getHomeId(), transferChangeRecord.getType(), transferChangeRecord.getTypeName(), key, -1, resiInfo.getPids()); + IcUserChangeDetailedEntity changeDetail = fillChangeDetail(customerId, resiId, transferChangeRecord.getId(), oldAgencyId, + oldGridId, oldvillageId, oldBuildId, oldUnitId, + oldHomeId, transferChangeRecord.getType(), transferChangeRecord.getTypeName(), key, -1, pids); icUserChangeDetailedDao.insert(changeDetail); } } @@ -1627,9 +1577,9 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res // 现在是这个类型,这个类型要+1 if ("1".equals(newValue)) { - IcUserChangeDetailedEntity changeDetail = fillChangeDetail(customerId, resiId, transferChangeRecord.getId(), newData.getAgencyId(), - newData.getGridId(), newData.getVillageId(), newData.getBuildId(), newData.getUnitId(), - newData.getHomeId(), transferChangeRecord.getType(), transferChangeRecord.getTypeName(), key, 1, resiInfo.getPids()); + IcUserChangeDetailedEntity changeDetail = fillChangeDetail(customerId, resiId, transferChangeRecord.getId(), newAgencyId, + newGridId, newvillageId, newBuildId, newUnitId, + newHomeId, transferChangeRecord.getType(), transferChangeRecord.getTypeName(), key, 1, pids); icUserChangeDetailedDao.insert(changeDetail); } } @@ -1642,18 +1592,43 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res * @param oldData * @param newData */ - private void fillResiSubCategoryInfo4TransferAndCategoryChange(ResiImportCategoryData oldData, ResiImportCategoryData newData) { - for (String category : oldData.getCategories().keySet()) { - String newValue = newData.getCategories().get(category); - String oldValue = oldData.getCategories().get(category); - - // 如果新数据中没有或者是0,并且是附加表信息,并且旧数据是1, 拿旧数据的过来 - if ((newValue == null || "0".equals(newValue)) - && "1".equals(oldValue) - && IcResiUserTableEnum.existsColumn(category)) { - newData.getCategories().put(category, "1"); + private void fillResiSubCategoryInfo4TransferAndCategoryChange(ResiImportCategoryData oldData, ResiImportCategoryData newData, Map resiInfoMap) { + + Map oldCates = oldData.getCategories(); + Map newCates = newData.getCategories(); + + for (IcResiUserTableEnum c : IcResiUserTableEnum.values()) { + // 主表,跳过 + String mainTableColumnName = c.getMainTableFlagColumnName(); + if (mainTableColumnName == null) { + return; + } + + // 不为空,说明本次导入含有该居民的类别信息,不需要补充 + String oldValue = oldCates.get(mainTableColumnName); + if (StringUtils.isNotBlank(oldValue)) { + return; + } + + // 本次导入不含有该居民类别信息,db中存储的数据,如果是1,newValue和oldValue都应该为1 + oldValue = resiInfoMap.get(mainTableColumnName); + if ("1".equals(oldValue)) { + oldCates.put(mainTableColumnName, oldValue); + newCates.put(mainTableColumnName, oldValue); } } + +// for (String category : oldData.getCategories().keySet()) { +// String newValue = newData.getCategories().get(category); +// String oldValue = oldData.getCategories().get(category); +// +// // 如果新数据中没有或者是0,并且是附加表信息,并且旧数据是1, 拿旧数据的过来 +// if ((newValue == null || "0".equals(newValue)) +// && "1".equals(oldValue) +// && IcResiUserTableEnum.existsColumn(category)) { +// newData.getCategories().put(category, "1"); +// } +// } } /** @@ -1733,7 +1708,6 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res /** * 填充调动记录 - * @param resiInfo * @param operator * @param oldCustomerId * @param oldAgencyId @@ -1751,15 +1725,15 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res * @param newHomeId * @return */ - private IcUserTransferRecordEntity fillTransferRecord(IcResiUserEntity resiInfo, CustomerStaffInfoCacheResult operator, String oldCustomerId, String oldAgencyId, String oldGridId, + private IcUserTransferRecordEntity fillTransferRecord(String resiId, String resiName, CustomerStaffInfoCacheResult operator, String oldCustomerId, String oldAgencyId, String oldGridId, String oldVillageId, String oldBuildId, String oldUnitId, String oldHomeId, String newCustomerId, String newAgencyId, String newGridId, String newVillageId, String newBuildId, String newUnitId, String newHomeId, IcResiUserOrgMsgResultDTO oldOrg, IcResiUserOrgMsgResultDTO newOrg) { IcUserTransferRecordEntity recordEntity = new IcUserTransferRecordEntity(); - recordEntity.setIcUserId(resiInfo.getId()); + recordEntity.setIcUserId(resiId); recordEntity.setOperatorId(operator.getStaffId()); - recordEntity.setIcUserName(resiInfo.getName()); + recordEntity.setIcUserName(resiName); recordEntity.setOperatorName(operator.getRealName()); recordEntity.setOldCustomerId(oldCustomerId); recordEntity.setOldAgencyId(oldAgencyId); @@ -1793,45 +1767,45 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res return recordEntity; } + /** + * 创建导入任务 + * @param operatorId + * @param bizType + * @return + */ + public String createImportTaskRecord(String operatorId, String bizType, String originFilename) { + ImportTaskCommonFormDTO importTaskForm = new ImportTaskCommonFormDTO(); + importTaskForm.setOperatorId(operatorId); + importTaskForm.setBizType(bizType); + importTaskForm.setOriginFileName(originFilename); + Result result = commonServiceOpenFeignClient.createImportTask(importTaskForm); + if (result != null && !result.success()) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), result.getMsg(), result.getMsg()); + } + return result.getData().getTaskId(); + } - - //private IcUserTransferRecordEntity fillTransferRecord(String resiId, String resiName, String operatorId, String operatorName, String oldCustomerId, - // String oldAgencyId, String oldAgencyName, String oldGridId, String oldGridName, String neighborhoodId, - // String neighborhoodName, String oldBuildingId, String oldBuildingName, ) { - - //IcUserTransferRecordEntity recordEntity = new IcUserTransferRecordEntity(); - //recordEntity.setIcUserId(); - //recordEntity.setOperatorId(); - //recordEntity.setIcUserName(); - //recordEntity.setOperatorName(); - //recordEntity.setOldCustomerId(); - //recordEntity.setOldAgencyId(); - //recordEntity.setOldAgencyName(); - //recordEntity.setOldGridId(); - //recordEntity.setOldGridName(); - //recordEntity.setOldNeighborHoodId(); - //recordEntity.setOldNeighborHoodName(); - //recordEntity.setOldBuildingId(); - //recordEntity.setOldBuildingName(); - //recordEntity.setOldBuildingUnitId(); - //recordEntity.setOldBuildingUnitName(); - //recordEntity.setOldHouseId(); - //recordEntity.setOldHouseName(); - //recordEntity.setTransferTime(); - //recordEntity.setRemark(); - //recordEntity.setNewCustomerId(); - //recordEntity.setNewAgencyId(); - //recordEntity.setNewAgencyName(); - //recordEntity.setNewGridId(); - //recordEntity.setNewGridName(); - //recordEntity.setNewNeighborHoodId(); - //recordEntity.setNewNeighborHoodName(); - //recordEntity.setNewBuildingId(); - //recordEntity.setNewBuildingName(); - //recordEntity.setNewBuildingUnitId(); - //recordEntity.setNewBuildingUnitName(); - //recordEntity.setNewHouseId(); - //recordEntity.setNewHouseName(); - //} + /** + * 完成导入任务 + * @param importTaskId 任务ID + * @param operatorId 操作者ID + * @param processStatus 处理状态,见 ImportTaskConstants.PROCESS_STATUS_* + * @param resultDesc 结果描述,非必填 + * @param resultDescPath 结果描述文件,excel等文件,有错误的话需要传入,成功则不需要 + */ + public void finishImportTask(String importTaskId, String operatorId, String processStatus, String resultDesc, String resultDescPath) { + ImportTaskCommonFormDTO importFinishTaskForm = new ImportTaskCommonFormDTO(); + importFinishTaskForm.setTaskId(importTaskId); + importFinishTaskForm.setProcessStatus(processStatus); + importFinishTaskForm.setOperatorId(operatorId); + importFinishTaskForm.setResultDesc(resultDesc); + importFinishTaskForm.setResultDescFilePath(resultDescPath); + + Result result = commonServiceOpenFeignClient.finishImportTask(importFinishTaskForm); + if (result == null || !result.success()) { + log.error("【居民信息导入】结束导入任务失败:taskId:{}, processStatus:{}, operatorId:{}, resultDesc:{}, resultDescPath:{}", + importTaskId, processStatus, operatorId, resultDesc, resultDescPath); + } + } } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java index 1e22b13b33..bab73c6909 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java @@ -40,8 +40,10 @@ import com.epmet.commons.tools.redis.common.CustomerStaffRedis; import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache; import com.epmet.commons.tools.redis.common.bean.GridInfoCache; import com.epmet.commons.tools.security.dto.TokenDto; +import com.epmet.commons.tools.security.user.LoginUserUtil; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.DateUtils; +import com.epmet.commons.tools.utils.HttpContextUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.constant.IcPlatformConstant; import com.epmet.constant.IcResiUserConstant; @@ -71,6 +73,7 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; import java.math.RoundingMode; import java.sql.Date; diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/ImportTaskServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/ImportTaskServiceImpl.java deleted file mode 100644 index d80ee5d9a6..0000000000 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/ImportTaskServiceImpl.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.epmet.service.impl; - -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.epmet.constant.ImportTaskConstants; -import com.epmet.dao.ImportTaskDao; -import com.epmet.entity.ImportTaskEntity; -import com.epmet.service.ImportTaskService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.Date; - -/** - * - * - * @author generator generator@elink-cn.com - * @since v1.0.0 2022-02-15 - */ -@Service -public class ImportTaskServiceImpl implements ImportTaskService { - - @Autowired - private ImportTaskDao importRecordDao; - - /** - * 该用户,该业务类型,是否有正在处理的导入任务 - * @param operatorId 操作者ID - * @param bizType 业务类型。resi:居民 - * @return - */ - @Override - public boolean existsProcessingTask(String operatorId, String bizType) { - LambdaQueryWrapper query = new LambdaQueryWrapper<>(); - query.eq(ImportTaskEntity::getOperatorId, operatorId); - query.eq(ImportTaskEntity::getBizType, bizType); - query.eq(ImportTaskEntity::getProcessStatus, ImportTaskConstants.PROCESS_STATUS_PROCESSING); - - return importRecordDao.selectCount(query) > 0; - } - - @Override - public String createProcessTask(String operatorId, String bizType) { - ImportTaskEntity importRecord = new ImportTaskEntity(); - importRecord.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_PROCESSING); - importRecord.setOperatorId(operatorId); - importRecord.setBizType(bizType); - importRecord.setStartTime(new Date()); - - importRecordDao.insert(importRecord); - return importRecord.getId(); - } - - @Override - public Boolean finish(String taskId, String processStatus, String operatorId, String resultDescFile, String resultDesc) { - return importRecordDao.finish(taskId, processStatus, operatorId, resultDesc, resultDescFile) > 0; - } -} \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/resources/mapper/IcResiUserDao.xml b/epmet-user/epmet-user-server/src/main/resources/mapper/IcResiUserDao.xml index 28396dd34e..ff945fede7 100644 --- a/epmet-user/epmet-user-server/src/main/resources/mapper/IcResiUserDao.xml +++ b/epmet-user/epmet-user-server/src/main/resources/mapper/IcResiUserDao.xml @@ -552,8 +552,12 @@