Browse Source

Merge remote-tracking branch 'origin/房屋tree_yzm' into dev

master
yinzuomei 3 years ago
parent
commit
6002c5c8a3
  1. 3
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/CustomerStaffRedis.java
  2. 4
      epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/epmetuser/impl/EpmetUserServiceImpl.java
  3. 96
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcPartyActivityController.java
  4. 93
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcPartyUnitController.java
  5. 71
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/IcPartyActivityImportExcel.java
  6. 79
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/IcPartyUnitImportExcel.java
  7. 20
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/IcPartyUnitImportFailedExcel.java
  8. 111
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/handler/IcPartyActivityImportListener.java
  9. 139
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/handler/IcPartyUnitExcelImportListener.java
  10. 21
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/IcPartyActivityService.java
  11. 22
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/IcPartyUnitService.java
  12. 377
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcPartyActivityServiceImpl.java
  13. 353
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcPartyUnitServiceImpl.java
  14. 1
      epmet-module/epmet-heart/epmet-heart-server/src/main/resources/db/migration/V0.0.30__icpartyunit.sql
  15. BIN
      epmet-module/epmet-heart/epmet-heart-server/src/main/resources/templates/icpartyactivity_import_tem.xlsx
  16. 3
      epmet-user/epmet-user-client/src/main/java/com/epmet/dto/ChangeWelfareDTO.java
  17. 6
      epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/AddIcNatFormDTO.java
  18. 4
      epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/IcTripReportFormDTO.java
  19. 3
      epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcNatController.java
  20. 21
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcNatServiceImpl.java

3
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/CustomerStaffRedis.java

@ -88,11 +88,12 @@ public class CustomerStaffRedis {
private static CustomerStaffInfoCache reloadStaffCache(String staffId, String key) {
Result<CustomerStaffInfoCache> staffResult = customerStaffRedis.commonAggFeignClient.getStaffInfo(staffId);
if (staffResult == null || !staffResult.success()) {
log.error("/data/aggregator/epmetuser/getStaffInfo/{staffId} 异常 staffId: ",staffId);
throw new RenException("获取工作人员信息失败");
}
CustomerStaffInfoCache resultData = staffResult.getData();
if (resultData == null) {
log.warn("getStaffInfo staff is null,staffId:{}", staffId);
log.error("getStaffInfo staff is null,staffId:{}", staffId);
return null;
}

4
epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/epmetuser/impl/EpmetUserServiceImpl.java

@ -9,7 +9,6 @@ import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.dto.form.IdAndNameDTO;
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult;
import com.epmet.commons.tools.enums.OrgTypeEnum;
import com.epmet.commons.tools.exception.EpmetException;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.EpmetException;
import com.epmet.commons.tools.page.PageData;
@ -56,9 +55,9 @@ import com.epmet.dataaggre.service.opercustomize.CustomerFootBarService;
import com.epmet.dto.IcResiUserDTO;
import com.epmet.dto.UserBaseInfoDTO;
import com.epmet.dto.form.DetailByTypeFormDTO;
import com.epmet.dto.form.GetStaffExistRoleFormDTO;
import com.epmet.dto.form.SystemMsgFormDTO;
import com.epmet.dto.result.DetailByTypeResultDTO;
import com.epmet.dto.form.GetStaffExistRoleFormDTO;
import com.epmet.dto.result.NewUserRoleResultDTO;
import com.epmet.dto.result.StaffRoleResultDTO;
import com.epmet.feign.EpmetMessageOpenFeignClient;
@ -638,6 +637,7 @@ public class EpmetUserServiceImpl implements EpmetUserService {
.eq(CustomerStaffEntity::getDelFlag,NumConstant.ZERO_STR);
CustomerStaffEntity staffEntity = customerStaffDao.selectOne(queryWrapper);
if (null == staffEntity) {
log.error(String.format("customer_staff is null staffId:%s",staffId));
return null;
}
CustomerStaffResultDTO result = ConvertUtils.sourceToTarget(staffEntity, CustomerStaffResultDTO.class);

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

@ -23,14 +23,14 @@ import com.alibaba.excel.write.metadata.WriteSheet;
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.constant.ServiceConstant;
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.security.dto.TokenDto;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.commons.tools.utils.ExcelUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.utils.*;
import com.epmet.commons.tools.utils.poi.excel.handler.FreezeAndFilter;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.commons.tools.validator.group.AddGroup;
@ -46,7 +46,6 @@ 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.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
@ -56,12 +55,14 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.nio.file.Path;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.UUID;
/**
@ -73,7 +74,7 @@ import java.util.concurrent.CompletableFuture;
@Slf4j
@RestController
@RequestMapping("icpartyactivity")
public class IcPartyActivityController {
public class IcPartyActivityController implements ResultDataResolver {
@Autowired
private IcPartyActivityService icPartyActivityService;
@ -163,58 +164,49 @@ public class IcPartyActivityController {
*/
@PostMapping("import")
public Result importData(@LoginUser TokenDto tokenDto, HttpServletResponse response, @RequestPart("file") MultipartFile file) throws IOException {
if (file.isEmpty()) {
throw new RenException("请上传文件");
// 1.暂存文件
String originalFilename = file.getOriginalFilename();
String extName = originalFilename.substring(originalFilename.lastIndexOf("."));
Path fileSavePath;
try {
Path importPath = FileUtils.getAndCreateDirUnderEpmetFilesDir("ic_party_activity", "import");
fileSavePath = importPath.resolve(UUID.randomUUID().toString().concat(extName));
} catch (IOException e) {
String errorMsg = ExceptionUtils.getErrorStackTrace(e);
log.error("【联建活动导入】创建临时存储文件失败:{}", errorMsg);
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "文件上传失败", "文件上传失败");
}
String originalFilename = file.getOriginalFilename();
// 校验文件类型
String extension = FilenameUtils.getExtension(originalFilename);
if (!"xls".equals(extension) && !"xlsx".equals(extension)) {
throw new RenException("文件类型不匹配");
InputStream is = null;
FileOutputStream os = null;
try {
is = file.getInputStream();
os = new FileOutputStream(fileSavePath.toString());
IOUtils.copy(is, os);
} catch (Exception e) {
log.error("method exception", e);
} finally {
org.apache.poi.util.IOUtils.closeQuietly(is);
org.apache.poi.util.IOUtils.closeQuietly(os);
}
//1.查询当前工作人员是否有再导入的党员先锋数据,有则不允许导入,没有则进行新的导入
// 2.生成导入任务记录
ImportTaskCommonFormDTO importTaskForm = new ImportTaskCommonFormDTO();
importTaskForm.setOriginFileName(file.getOriginalFilename());
importTaskForm.setOperatorId(tokenDto.getUserId());
importTaskForm.setBizType(ImportTaskConstants.BIZ_TYPE_PARTY_UNIT);
Result<ImportTaskCommonResultDTO> result = commonServiceOpenFeignClient.createImportTask(importTaskForm);
if (!result.success()) {
throw new RenException(result.getInternalMsg());
}
importTaskForm.setBizType(ImportTaskConstants.BIZ_TYPE_PARTY_ACTIVITY);
importTaskForm.setOriginFileName(originalFilename);
// 异步执行导入
CompletableFuture.runAsync(() -> {
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
log.error("method exception", e);
}
submitResiImportTask(tokenDto, response, file, result.getData().getTaskId());
});
return new Result();
}
ImportTaskCommonResultDTO rstData = getResultDataOrThrowsException(commonServiceOpenFeignClient.createImportTask(importTaskForm),
ServiceConstant.EPMET_COMMON_SERVICE,
EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),
"联建活动导入错误",
"联建活动导入失败");
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());
}
}
// 3.执行导入
icPartyActivityService.execAsyncExcelImport(fileSavePath, rstData.getTaskId(),tokenDto.getCustomerId(),tokenDto.getUserId());
return new Result();
}
/**

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

@ -8,16 +8,16 @@ import com.epmet.commons.tools.annotation.LoginUser;
import com.epmet.commons.tools.aop.NoRepeatSubmit;
import com.epmet.commons.tools.constant.AppClientConstant;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.ServiceConstant;
import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.dto.result.OptionDataResultDTO;
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.security.dto.TokenDto;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.commons.tools.utils.ExcelUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.utils.*;
import com.epmet.commons.tools.utils.poi.excel.handler.FreezeAndFilter;
import com.epmet.commons.tools.validator.AssertUtils;
import com.epmet.commons.tools.validator.ValidatorUtils;
@ -34,7 +34,6 @@ 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.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -46,12 +45,14 @@ import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.nio.file.Path;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.UUID;
import java.util.stream.Collectors;
@ -64,7 +65,7 @@ import java.util.stream.Collectors;
@Slf4j
@RestController
@RequestMapping("icpartyunit")
public class IcPartyUnitController {
public class IcPartyUnitController implements ResultDataResolver {
@Autowired
private IcPartyUnitService icPartyUnitService;
@ -192,37 +193,48 @@ public class IcPartyUnitController {
*/
@PostMapping("import")
public Result importData(@LoginUser TokenDto tokenDto, HttpServletRequest multipartRequest, HttpServletResponse response, @RequestPart("file") MultipartFile file) throws IOException {
// 1.暂存文件
String originalFilename = file.getOriginalFilename();
String extName = originalFilename.substring(originalFilename.lastIndexOf("."));
if (file.isEmpty()) {
throw new RenException("请上传文件");
Path fileSavePath;
try {
Path importPath = FileUtils.getAndCreateDirUnderEpmetFilesDir("ic_party_unit", "import");
fileSavePath = importPath.resolve(UUID.randomUUID().toString().concat(extName));
} catch (IOException e) {
String errorMsg = ExceptionUtils.getErrorStackTrace(e);
log.error("【联建单位导入】创建临时存储文件失败:{}", errorMsg);
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "文件上传失败", "文件上传失败");
}
String originalFilename = file.getOriginalFilename();
// 校验文件类型
String extension = FilenameUtils.getExtension(originalFilename);
if (!"xls".equals(extension) && !"xlsx".equals(extension)) {
throw new RenException("文件类型不匹配");
InputStream is = null;
FileOutputStream os = null;
try {
is = file.getInputStream();
os = new FileOutputStream(fileSavePath.toString());
IOUtils.copy(is, os);
} catch (Exception e) {
log.error("method exception", e);
} finally {
org.apache.poi.util.IOUtils.closeQuietly(is);
org.apache.poi.util.IOUtils.closeQuietly(os);
}
//1.查询当前工作人员是否有再导入的党员先锋数据,有则不允许导入,没有则进行新的导入
// 2.生成导入任务记录
ImportTaskCommonFormDTO importTaskForm = new ImportTaskCommonFormDTO();
importTaskForm.setOriginFileName(file.getOriginalFilename());
importTaskForm.setOperatorId(tokenDto.getUserId());
importTaskForm.setBizType(ImportTaskConstants.BIZ_TYPE_PARTY_UNIT);
Result<ImportTaskCommonResultDTO> result = commonServiceOpenFeignClient.createImportTask(importTaskForm);
if (!result.success()) {
throw new RenException(result.getInternalMsg());
}
importTaskForm.setOriginFileName(originalFilename);
// 异步执行导入
CompletableFuture.runAsync(() -> {
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
log.error("method exception", e);
}
submitResiImportTask(tokenDto, response, file, result.getData().getTaskId());
});
ImportTaskCommonResultDTO rstData = getResultDataOrThrowsException(commonServiceOpenFeignClient.createImportTask(importTaskForm),
ServiceConstant.EPMET_COMMON_SERVICE,
EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),
"联建单位导入错误",
"联建单位导入失败");
// 3.执行导入
icPartyUnitService.execAsyncExcelImport(fileSavePath, rstData.getTaskId(),tokenDto.getCustomerId(),tokenDto.getUserId());
return new Result();
}
@ -297,27 +309,6 @@ public class IcPartyUnitController {
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());
}
}
}
/**
* Desc: 获取联建单位名字
* @param formDTO

71
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/IcPartyActivityImportExcel.java

@ -17,9 +17,16 @@
package com.epmet.excel;
import cn.afterturn.easypoi.excel.annotation.Excel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.epmet.commons.tools.utils.ExcelVerifyInfo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;
/**
* 联建活动
@ -28,39 +35,57 @@ import lombok.Data;
* @since v1.0.0 2021-11-19
*/
@Data
public class IcPartyActivityImportExcel extends ExcelVerifyInfo {
@Excel(name = "单位名称")
private String unitName;
public class IcPartyActivityImportExcel extends ExcelVerifyInfo {
@Excel(name = "服务事项")
private String serviceMatter;
@Excel(name = "活动标题")
@NotBlank(message = "活动标题必填")
@Length(max = 50, message = "活动标题最多输入50字")
@ExcelProperty(value = "活动标题*")
private String title;
@Excel(name = "活动目标")
@NotBlank(message = "活动目标必填")
@Length(max = 100, message = "活动目标最多输入100字")
@ExcelProperty(value = "活动目标*")
private String target;
@Excel(name = "活动内容")
private String content;
@NotNull(message = "服务人数必填")
@ExcelProperty(value = "服务人数*")
private Integer peopleCount;
@Excel(name = "活动地址")
@NotNull(message = "活动时间不能为空")
@ExcelProperty("活动时间*")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date activityTime;
@NotBlank(message = "详细地址")
@Length(max = 250, message = "详细地址最多输入250字")
@ExcelProperty(value = "详细地址*")
private String address;
@Excel(name = "活动地址经度")
private String longitude;
@Excel(name = "活动地址纬度")
private String latitude;
@Data
public static class ErrorRow {
@ColumnWidth(38)
@ExcelProperty(value = "活动标题*")
private String title;
@Excel(name = "服务人数")
private Integer peopleCount;
@ColumnWidth(40)
@ExcelProperty(value = "活动目标*")
private String target;
@ColumnWidth(10)
@ExcelProperty(value = "服务人数*")
private Integer peopleCount;
@Excel(name = "活动时间")
private String activityTime;
@ColumnWidth(25)
@ExcelProperty("活动时间*")
private Date activityTime;
@Excel(name = "活动结果")
private String result;
@ColumnWidth(40)
@ExcelProperty(value = "详细地址*")
private String address;
@ColumnWidth(60)
@ExcelProperty("错误信息")
private String errorInfo;
}
}

79
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/IcPartyUnitImportExcel.java

@ -17,9 +17,14 @@
package com.epmet.excel;
import cn.afterturn.easypoi.excel.annotation.Excel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.epmet.commons.tools.utils.ExcelVerifyInfo;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
* 联建单位
@ -30,33 +35,73 @@ import lombok.Data;
@Data
public class IcPartyUnitImportExcel extends ExcelVerifyInfo {
@Excel(name = "单位名称")
@NotBlank(message = "单位名称必填")
@Length(max = 50,message = "单位名称最多输入50字")
@ExcelProperty(value = "单位名称*")
private String unitName;
@Excel(name = "分类")
private String type;
@Excel(name = "服务事项")
private String serviceMatter;
@NotBlank(message = "分类必填")
@ExcelProperty(value = "分类*")
private String typeName;
@Excel(name = "联系人")
@Length(max = 30,message = "联系人最多输入30字")
@NotBlank(message = "联系人必填")
@ExcelProperty(value = "联系人*")
private String contact;
@Excel(name = "联系电话")
@Length(max = 30,message = "联系电话最多输入30字")
@NotBlank(message = "联系电话必填")
@ExcelProperty(value = "联系电话*")
private String contactMobile;
@Excel(name = "在职党员")
@NotNull(message = "在职党员必填")
@ExcelProperty(value = "在职党员*")
private Integer memberCount;
@Excel(name = "地址")
@Length(max = 500,message = "备注最多输入50字")
@ExcelProperty(value = "备注")
private String remark;
@Length(max = 250,message = "详细地址最多输入250字")
@NotBlank(message = "详细地址必填")
@ExcelProperty(value = "详细地址*")
private String address;
@Excel(name = "中心位置经度")
private String longitude;
@Data
public static class ErrorRow {
@ColumnWidth(40)
@ExcelProperty("单位名称*")
private String unitName;
@Excel(name = "中心位置纬度")
private String latitude;
@ColumnWidth(20)
@ExcelProperty("分类*")
private String type;
@Excel(name = "备注")
private String remark;
@ColumnWidth(20)
@ExcelProperty("联系人*")
private String contact;
@ColumnWidth(20)
@ExcelProperty("联系电话*")
private String contactMobile;
@ColumnWidth(10)
@ExcelProperty("在职党员*")
private Integer memberCount;
@ColumnWidth(30)
@ExcelProperty("备注")
private String remark;
@ColumnWidth(50)
@ExcelProperty("详细地址*")
private String address;
@ColumnWidth(50)
@ExcelProperty("错误信息")
private String errorInfo;
}
}

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

@ -30,9 +30,27 @@ import lombok.Data;
@Data
public class IcPartyUnitImportFailedExcel extends ExcelVerifyInfo {
@Excel(name = "单位名称", width = 40)
@Excel(name = "单位名称*", width = 40)
private String unitName;
@Excel(name = "分类*",width = 20)
private String type;
@Excel(name = "联系人*",width = 20)
private String contact;
@Excel(name = "联系电话*",width = 20)
private String contactMobile;
@Excel(name = "在职党员*",width = 10)
private Integer memberCount;
@Excel(name = "备注",width = 30)
private String remark;
@Excel(name = "详细地址*",width = 50)
private String address;
@Excel(name = "错误信息", width = 50)
private String errorInfo;
}

111
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/handler/IcPartyActivityImportListener.java

@ -0,0 +1,111 @@
package com.epmet.excel.handler;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.exception.ValidateException;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.entity.IcPartyActivityEntity;
import com.epmet.excel.IcPartyActivityImportExcel;
import com.epmet.service.impl.IcPartyActivityServiceImpl;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.List;
/**
* @Description
* @Author yzm
* @Date 2023/2/20 15:36
*/
@Slf4j
public class IcPartyActivityImportListener implements ReadListener<IcPartyActivityImportExcel> {
/**
* 最大条数阈值
*/
public static final int MAX_THRESHOLD = 200;
/**
* 当前操作用户
*/
private CustomerStaffInfoCacheResult staffInfo;
private String customerId;
/**
* 数据
*/
private List<IcPartyActivityEntity> datas = new ArrayList<>();
/**
* 错误项列表
*/
private List<IcPartyActivityImportExcel.ErrorRow> errorRows = new ArrayList<>();
private IcPartyActivityServiceImpl icPartyActivityService;
public IcPartyActivityImportListener(String customerId, CustomerStaffInfoCacheResult staffInfo, IcPartyActivityServiceImpl icPartyActivityService) {
this.customerId=customerId;
this.staffInfo = staffInfo;
this.icPartyActivityService = icPartyActivityService;
}
@Override
public void invoke(IcPartyActivityImportExcel data, AnalysisContext context) {
try {
// 先校验数据
ValidatorUtils.validateEntity(data);
IcPartyActivityEntity e = ConvertUtils.sourceToTarget(data, IcPartyActivityEntity.class);
e.setCustomerId(customerId);
e.setAgencyId(staffInfo.getAgencyId());
e.setPids(staffInfo.getAgencyPIds());
e.setContent(StrConstant.EPMETY_STR);
datas.add(e);
if (datas.size() == MAX_THRESHOLD) {
execPersist();
}
} catch (Exception e) {
String errorMsg = null;
if (e instanceof ValidateException) {
errorMsg = ((ValidateException) e).getMsg();
} else {
errorMsg = "未知错误";
log.error("【联建活动导入】出错:{}", ExceptionUtils.getErrorStackTrace(e));
}
IcPartyActivityImportExcel.ErrorRow errorRow = ConvertUtils.sourceToTarget(data,IcPartyActivityImportExcel.ErrorRow.class);
errorRow.setErrorInfo(errorMsg);
errorRows.add(errorRow);
}
}
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
// 最后几条达不到阈值,这里必须再调用一次
execPersist();
}
/**
* 执行持久化
*/
private void execPersist() {
try {
if (datas != null && datas.size() > 0) {
icPartyActivityService.batchPersist(datas);
}
} finally {
datas.clear();
}
}
/**
* 获取错误行
* @return
*/
public List<IcPartyActivityImportExcel.ErrorRow> getErrorRows() {
return errorRows;
}
}

139
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/handler/IcPartyUnitExcelImportListener.java

@ -0,0 +1,139 @@
package com.epmet.excel.handler;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.exception.ValidateException;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.entity.IcPartyUnitEntity;
import com.epmet.excel.IcPartyUnitImportExcel;
import com.epmet.service.impl.IcPartyUnitServiceImpl;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* @Description
* @Author yzm
* @Date 2023/2/20 15:36
*/
@Slf4j
public class IcPartyUnitExcelImportListener implements ReadListener<IcPartyUnitImportExcel> {
/**
* 最大条数阈值
*/
public static final int MAX_THRESHOLD = 200;
/**
* 当前操作用户
*/
private CustomerStaffInfoCacheResult staffInfo;
private String customerId;
/**
* 数据
*/
private List<IcPartyUnitEntity> datas = new ArrayList<>();
/**
* 错误项列表
*/
private List<IcPartyUnitImportExcel.ErrorRow> errorRows = new ArrayList<>();
private IcPartyUnitServiceImpl icPartyUnitService;
//字典表数据
private Map<String, String> partyUnitTypeMap;
public IcPartyUnitExcelImportListener(String customerId, CustomerStaffInfoCacheResult staffInfo, IcPartyUnitServiceImpl icPartyUnitService,Map<String, String> partyUnitTypeMap) {
this.customerId=customerId;
this.staffInfo = staffInfo;
this.icPartyUnitService = icPartyUnitService;
this.partyUnitTypeMap=partyUnitTypeMap;
}
@Override
public void invoke(IcPartyUnitImportExcel data, AnalysisContext context) {
try {
// 先校验数据
ValidatorUtils.validateEntity(data);
AtomicBoolean bl = new AtomicBoolean(false);
StringBuffer errMsg = new StringBuffer("");
//先对一下字段值填写是否正确做判断
if (!partyUnitTypeMap.containsKey(data.getTypeName())) {
errMsg.append("‘返回方式’值填写错误;");
bl.set(true);
}
//错误数据记录到错误文件
if (bl.get()) {
IcPartyUnitImportExcel.ErrorRow errorRow = ConvertUtils.sourceToTarget(data,IcPartyUnitImportExcel.ErrorRow.class);
errorRow.setErrorInfo(errMsg.toString());
errorRows.add(errorRow);
return;
}
// 判断名称是否已存在
if(icPartyUnitService.checkUnitName(data.getUnitName(),staffInfo.getAgencyId(),null)){
IcPartyUnitImportExcel.ErrorRow errorRow = ConvertUtils.sourceToTarget(data,IcPartyUnitImportExcel.ErrorRow.class);
errorRow.setErrorInfo("联建单位名称已存在");
errorRows.add(errorRow);
return;
}
IcPartyUnitEntity e = ConvertUtils.sourceToTarget(data, IcPartyUnitEntity.class);
if (partyUnitTypeMap.containsKey(data.getTypeName())) {
e.setType(partyUnitTypeMap.get(data.getTypeName()));
}
e.setCustomerId(customerId);
e.setAgencyId(staffInfo.getAgencyId());
e.setPids(staffInfo.getAgencyPIds());
datas.add(e);
if (datas.size() == MAX_THRESHOLD) {
execPersist();
}
} catch (Exception e) {
String errorMsg = null;
if (e instanceof ValidateException) {
errorMsg = ((ValidateException) e).getMsg();
} else {
errorMsg = "未知错误";
log.error("【联建单位导入】出错:{}", ExceptionUtils.getErrorStackTrace(e));
}
IcPartyUnitImportExcel.ErrorRow errorRow = ConvertUtils.sourceToTarget(data,IcPartyUnitImportExcel.ErrorRow.class);
errorRow.setErrorInfo(errorMsg);
errorRows.add(errorRow);
}
}
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
// 最后几条达不到阈值,这里必须再调用一次
execPersist();
}
/**
* 执行持久化
*/
private void execPersist() {
try {
if (datas != null && datas.size() > 0) {
icPartyUnitService.batchPersist(datas);
}
} finally {
datas.clear();
}
}
/**
* 获取错误行
* @return
*/
public List<IcPartyUnitImportExcel.ErrorRow> getErrorRows() {
return errorRows;
}
}

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

@ -24,10 +24,8 @@ import com.epmet.dto.IcPartyActivityDTO;
import com.epmet.dto.form.PartyActivityFormDTO;
import com.epmet.dto.result.demand.OptionDTO;
import com.epmet.entity.IcPartyActivityEntity;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
/**
@ -88,17 +86,6 @@ public interface IcPartyActivityService extends BaseService<IcPartyActivityEntit
*/
void delete(String id);
/**
* 导入数据
* @Param tokenDto
* @Param response
* @Param file
* @Return
* @Author zhaoqifeng
* @Date 2021/11/29 11:01
*/
void importData(TokenDto tokenDto, HttpServletResponse response, MultipartFile file, String taskId) throws IOException;
/**
* 联建活动统计
* @Param formDTO
@ -134,4 +121,10 @@ public interface IcPartyActivityService extends BaseService<IcPartyActivityEntit
* @Date 2021/12/23 16:13
*/
void deleteByActId(String actId);
/**
* 执行Excel导入
* @param filePath
*/
void execAsyncExcelImport(Path filePath, String importTaskId,String customerId,String userId);
}

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

@ -14,10 +14,8 @@ import com.epmet.dto.result.PartyUnitDistributionResultDTO;
import com.epmet.dto.result.PartyUnitListResultDTO;
import com.epmet.dto.result.demand.OptionDTO;
import com.epmet.entity.IcPartyUnitEntity;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
/**
@ -107,18 +105,6 @@ public interface IcPartyUnitService extends BaseService<IcPartyUnitEntity> {
*/
List<OptionDTO> options(IcPartyUnitDTO dto);
/**
* 导入数据
*
* @Param tokenDto
* @Param response
* @Param file
* @Return
* @Author zhaoqifeng
* @Date 2021/11/29 11:01
*/
void importData(TokenDto tokenDto, HttpServletResponse response, MultipartFile file, String taskId) throws IOException;
/**
* @Description 按类型统计单位数量
* @Param formDTO
@ -187,4 +173,10 @@ public interface IcPartyUnitService extends BaseService<IcPartyUnitEntity> {
* @return
*/
List<String> getUnitNames(List<String> unitIds);
/**
* 执行Excel导入
* @param filePath
*/
void execAsyncExcelImport(Path filePath, String importTaskId,String customerId,String userId);
}

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

@ -17,25 +17,20 @@
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.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.redis.common.CustomerOrgRedis;
import com.epmet.commons.tools.redis.common.CustomerStaffRedis;
import com.epmet.commons.tools.redis.common.bean.GridInfoCache;
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.utils.*;
import com.epmet.constants.ImportTaskConstants;
import com.epmet.dao.IcPartyActivityDao;
import com.epmet.dto.IcPartyActivityDTO;
@ -49,7 +44,7 @@ import com.epmet.entity.IcActivityServiceRelationEntity;
import com.epmet.entity.IcActivityUnitRelationEntity;
import com.epmet.entity.IcPartyActivityEntity;
import com.epmet.excel.IcPartyActivityImportExcel;
import com.epmet.excel.IcPartyActivityImportFailedExcel;
import com.epmet.excel.handler.IcPartyActivityImportListener;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.feign.OssFeignClient;
import com.epmet.service.*;
@ -62,16 +57,15 @@ 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.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@ -121,15 +115,17 @@ public class IcPartyActivityServiceImpl extends BaseServiceImpl<IcPartyActivityD
unitDTO.setAgencyId(formDTO.getAgencyId());
// Map<String, String> option = icPartyUnitService.option(unitDTO).stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel));
dtoList.forEach(dto -> {
//联建单位ID与单位名匹配
List<String> unitIds = Arrays.asList(dto.getUnitId().split(StrConstant.COMMA));
// List<String> unitNames = unitIds.stream().map(option::get).collect(Collectors.toList());
// if(CollectionUtils.isEmpty(unitNames)){
List<String> unitNames=icPartyUnitService.getUnitNames(unitIds);
// }
dto.setUnitIdList(unitIds);
dto.setUnitName(StringUtils.join(unitNames, StrConstant.COMMA));
dto.setUnitNameList(unitNames);
if(StringUtils.isNotBlank(dto.getUnitId())){
//联建单位ID与单位名匹配
List<String> unitIds = Arrays.asList(dto.getUnitId().split(StrConstant.COMMA));
// List<String> unitNames = unitIds.stream().map(option::get).collect(Collectors.toList());
// if(CollectionUtils.isEmpty(unitNames)){
List<String> unitNames=icPartyUnitService.getUnitNames(unitIds);
// }
dto.setUnitIdList(unitIds);
dto.setUnitName(StringUtils.join(unitNames, StrConstant.COMMA));
dto.setUnitNameList(unitNames);
}
if (StringUtils.isNotEmpty(dto.getGridId())) {
GridInfoCache gridInfo = CustomerOrgRedis.getGridInfo(dto.getGridId());
if (null != gridInfo) {
@ -283,248 +279,6 @@ public class IcPartyActivityServiceImpl extends BaseServiceImpl<IcPartyActivityD
icActivityServiceRelationService.delete(id);
}
/**
* 导入数据
*
* @param tokenDto
* @param response
* @param file
* @Param tokenDto
* @Param response
* @Param file
* @Return
* @Author zhaoqifeng
* @Date 2021/11/29 11:01
*/
@Override
public void importData(TokenDto tokenDto, HttpServletResponse response, MultipartFile file, String taskId) throws IOException {
List<IcPartyActivityImportFailedExcel> fileList = new ArrayList<>();
ExcelImportResult<IcPartyActivityImportExcel> importResult = ExcelPoiUtils.importExcelMore(file, 0, 1, IcPartyActivityImportExcel.class);
List<IcPartyActivityImportExcel> failList = importResult.getFailList();
//存放错误数据行号
if (!org.springframework.util.CollectionUtils.isEmpty(failList)) {
for (IcPartyActivityImportExcel entity : failList) {
//打印失败的行 和失败的信息
log.warn("第{}行,{}", entity.getRowNum(), entity.getErrorMsg());
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(entity, IcPartyActivityImportFailedExcel.class);
failed.setErrorInfo(entity.getErrorMsg());
fileList.add(failed);
}
}
List<IcPartyActivityImportExcel> result = importResult.getList();
CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId());
//获取服务事项
List<OptionDTO> serviceItemList = icServiceItemDictService.queryDictList(tokenDto.getCustomerId());
Map<String, String> categoryMap = serviceItemList.stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel));
//获取联建单位
IcPartyUnitDTO unitDTO = new IcPartyUnitDTO();
unitDTO.setAgencyId(staffInfoCache.getAgencyId());
Map<String, String> option = icPartyUnitService.option(unitDTO).stream().collect(Collectors.toMap(OptionDTO::getLabel, OptionDTO::getValue));
//1.数据校验
Iterator<IcPartyActivityImportExcel> iterator = result.iterator();
while (iterator.hasNext()) {
IcPartyActivityImportExcel obj = iterator.next();
//单位名称校验
if (StringUtils.isBlank(obj.getUnitName())) {
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class);
failed.setErrorInfo("单位名称为空");
fileList.add(failed);
log.warn(String.format("单位名称为空,行号->%s", obj.getRowNum()));
iterator.remove();
} else {
List<String> unitList = Arrays.asList(obj.getUnitName().split(StrConstant.COMMA));
unitList.forEach(unit -> {
if (null == option.get(unit)) {
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())) {
IcPartyActivityImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyActivityImportFailedExcel.class);
failed.setErrorInfo("服务事项为空");
fileList.add(failed);
log.warn(String.format("服务事项为空,行号->%s", obj.getRowNum()));
iterator.remove();
} else {
List<String> serviceList = Arrays.asList(obj.getServiceMatter().split(StrConstant.SEMICOLON));
serviceList.forEach(service -> {
if (null == categoryMap.get(service)) {
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())) {
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.isNotEmpty(result)) {
result.forEach(item -> {
IcPartyActivityEntity entity = new IcPartyActivityEntity();
entity.setCustomerId(tokenDto.getCustomerId());
entity.setAgencyId(staffInfoCache.getAgencyId());
entity.setPids(staffInfoCache.getAgencyPIds());
entity.setTitle(item.getTitle());
entity.setTarget(item.getTarget());
entity.setContent(item.getContent());
entity.setPeopleCount(item.getPeopleCount());
entity.setActivityTime(DateUtils.parse(item.getActivityTime(), DateUtils.DATE_TIME_PATTERN));
entity.setAddress(item.getAddress());
entity.setLatitude(item.getLatitude());
entity.setLongitude(item.getLongitude());
entity.setResult(item.getResult());
insert(entity);
//保存活动与单位关系
icActivityUnitRelationService.deleteByActivity(entity.getId());
AtomicInteger i = new AtomicInteger(NumConstant.ONE);
List<IcActivityUnitRelationEntity> unitRelationList = Arrays.stream(item.getUnitName().split(StrConstant.COMMA)).map(unit -> {
IcActivityUnitRelationEntity relation = new IcActivityUnitRelationEntity();
relation.setCustomerId(entity.getCustomerId());
relation.setAgencyId(entity.getAgencyId());
relation.setPids(entity.getPids());
relation.setActivityId(entity.getId());
relation.setUnitId(option.get(unit));
relation.setSort(i.getAndIncrement());
return relation;
}).collect(Collectors.toList());
icActivityUnitRelationService.insertBatch(unitRelationList);
//保存活动与服务关系
icActivityServiceRelationService.deleteByActivity(entity.getId());
AtomicInteger j = new AtomicInteger(NumConstant.ONE);
List<IcActivityServiceRelationEntity> serviceRelationList = Arrays.stream(item.getServiceMatter().split(StrConstant.SEMICOLON)).map(service -> {
IcActivityServiceRelationEntity relation = new IcActivityServiceRelationEntity();
relation.setCustomerId(entity.getCustomerId());
relation.setAgencyId(entity.getAgencyId());
relation.setPids(entity.getPids());
relation.setActivityId(entity.getId());
relation.setServiceMatter(categoryMap.get(service));
relation.setSort(j.getAndIncrement());
return relation;
}).collect(Collectors.toList());
icActivityServiceRelationService.insertBatch(serviceRelationList);
});
}
String str = String.format("共%s条,成功导入%s条。", fileList.size() + result.size(), fileList.size() + result.size() - fileList.size());
if (fileList.size() > NumConstant.ZERO) {
List<Integer> numList = fileList.stream().map(IcPartyActivityImportFailedExcel::getRowNum).sorted().collect(Collectors.toList());
String subList = numList.stream().map(String::valueOf).collect(Collectors.joining("、"));
log.warn(str + "第" + subList + "行未成功!");
}
//错误数据生成文件,修改导入任务状态
erroeImport(fileList, taskId, tokenDto.getUserId());
}
private void erroeImport(List<IcPartyActivityImportFailedExcel> fileList, String importTaskId, String staffId) throws IOException {
String url = "";
//1.有错误数据则生成错误数据存放文件传到阿里云服务
if (CollectionUtils.isNotEmpty(fileList)) {
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("导入失败的数据列表", "导入失败的数据列表"),
IcPartyActivityImportFailedExcel.class, fileList);
// 文件名
String resultDescFileName = UUID.randomUUID().toString().concat(".xlsx");
FileItemFactory factory = new DiskFileItemFactory(16, null);
FileItem fileItem = factory.createItem("file", ContentType.APPLICATION_OCTET_STREAM.toString(), true, resultDescFileName);
OutputStream os = fileItem.getOutputStream();
Result<UploadImgResultDTO> uploadResult = null;
try {
workbook.write(os);
uploadResult = ossFeignClient.uploadImportTaskDescFile(new CommonsMultipartFile(fileItem));
} catch (Exception e) {
String errormsg = ExceptionUtils.getErrorStackTrace(e);
log.error("【联建活动信息导入】上传错误描述文件:{}", errormsg);
} finally {
try {
os.close();
} catch (IOException e) {
String errormsg = ExceptionUtils.getErrorStackTrace(e);
log.error("【联建活动信息导入】上传错误描述文件关闭输出流:{}", errormsg);
}
try {
fileItem.delete();
} catch (Exception e) {
String errormsg = ExceptionUtils.getErrorStackTrace(e);
log.error("【联建活动信息导入】上传错误描述文件删除临时文件:{}", errormsg);
}
}
if (uploadResult == null || !uploadResult.success()) {
log.error("【联建活动信息导入】调用OSS上传结果描述文件失败");
} else {
url = uploadResult.getData().getUrl();
}
}
//2.更新导入任务数据
ImportTaskCommonFormDTO importTaskForm = new ImportTaskCommonFormDTO();
importTaskForm.setOperatorId(staffId);
importTaskForm.setBizType(ImportTaskConstants.BIZ_TYPE_PARTY_ACTIVITY);
importTaskForm.setTaskId(importTaskId);
importTaskForm.setResultDescFilePath(url);
importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS);
if (CollectionUtils.isNotEmpty(fileList)) {
importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL);
importTaskForm.setResultDesc("联建活动导入存在错误数据");
}
Result result = commonServiceOpenFeignClient.finishImportTask(importTaskForm);
if (!result.success()) {
throw new RenException(result.getInternalMsg());
}
}
/**
* 联建活动统计
*
@ -656,4 +410,101 @@ public class IcPartyActivityServiceImpl extends BaseServiceImpl<IcPartyActivityD
formDTO.setEndTime(DateUtils.parse(end.concat(" 23:59:59"), DateUtils.DATE_TIME_PATTERN));
}
/**
* 执行Excel导入
*
* @param filePath
* @param importTaskId
* @param customerId
* @param userId
*/
@Override
public void execAsyncExcelImport(Path filePath, String importTaskId, String customerId, String userId) {
try {
//获取当前登录用户所属组织id
CustomerStaffInfoCacheResult staffInfo= SpringContextUtils.getBean(IcPartyUnitServiceImpl.class).queryCurrentStaff(customerId,userId);
IcPartyActivityImportListener listener = new IcPartyActivityImportListener(customerId,staffInfo, this);
EasyExcel.read(filePath.toFile(), IcPartyActivityImportExcel.class, listener).headRowNumber(1).sheet(0).doRead();
Path errorDescFile = null;
String errorDesFileUrl = null;
List<IcPartyActivityImportExcel.ErrorRow> errorRows = listener.getErrorRows();
boolean failed = errorRows.size() > 0;
if (failed) {
// 生成并上传错误文件
try {
// 文件生成
Path errorDescDir = FileUtils.getAndCreateDirUnderEpmetFilesDir("ic_party_activity", "import", "error_des");
String fileName = UUID.randomUUID().toString().concat(".xlsx");
errorDescFile = errorDescDir.resolve(fileName);
FileItemFactory factory = new DiskFileItemFactory(16, errorDescDir.toFile());
FileItem fileItem = factory.createItem("file", ContentType.APPLICATION_OCTET_STREAM.toString(), true, fileName);
OutputStream os = fileItem.getOutputStream();
EasyExcel.write(os, IcPartyActivityImportExcel.ErrorRow.class).sheet("导入失败列表").doWrite(errorRows);
// 文件上传oss
Result<UploadImgResultDTO> errorDesFileUploadResult = ossFeignClient.uploadImportTaskDescFile(new CommonsMultipartFile(fileItem));
if (errorDesFileUploadResult.success()) {
errorDesFileUrl = errorDesFileUploadResult.getData().getUrl();
}
} finally {
if (Files.exists(errorDescFile)) {
Files.delete(errorDescFile);
}
}
}
ImportTaskCommonFormDTO importFinishTaskForm = new ImportTaskCommonFormDTO();
importFinishTaskForm.setTaskId(importTaskId);
importFinishTaskForm.setProcessStatus(failed ? ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL : ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS);
importFinishTaskForm.setOperatorId(userId);
importFinishTaskForm.setResultDesc("");
importFinishTaskForm.setResultDescFilePath(errorDesFileUrl);
Result result = commonServiceOpenFeignClient.finishImportTask(importFinishTaskForm);
if (!result.success()) {
log.error("【联建活动导入】finishImportTask失败");
}
} catch (Exception e) {
String errorMsg = ExceptionUtils.getErrorStackTrace(e);
log.error("【联建活动导入】出错:{}", errorMsg);
ImportTaskCommonFormDTO importFinishTaskForm = new ImportTaskCommonFormDTO();
importFinishTaskForm.setTaskId(importTaskId);
importFinishTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL);
importFinishTaskForm.setOperatorId(userId);
importFinishTaskForm.setResultDesc("导入失败");
Result result = commonServiceOpenFeignClient.finishImportTask(importFinishTaskForm);
if (!result.success()) {
log.error("【联建活动导入】导入记录状态修改为'完成'失败");
}
} finally {
// 删除临时文件
if (Files.exists(filePath)) {
try {
Files.delete(filePath);
} catch (IOException e) {
log.error("method exception", e);
}
}
}
}
/**
* 批量持久化
* @param entities
*/
public void batchPersist(List<IcPartyActivityEntity> entities) {
entities.forEach(e -> {
String id = IdWorker.getIdStr(e);
e.setId(id);
baseDao.insert(e);
});
}
}

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

@ -17,12 +17,11 @@
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.excel.EasyExcel;
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.toolkit.IdWorker;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.rocketmq.messages.ServerSatisfactionCalFormDTO;
import com.epmet.commons.tools.constant.FieldConstant;
@ -33,11 +32,9 @@ import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult;
import com.epmet.commons.tools.dto.result.DictListResultDTO;
import com.epmet.commons.tools.dto.result.OptionDataResultDTO;
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.CustomerOrgRedis;
import com.epmet.commons.tools.redis.common.CustomerStaffRedis;
@ -45,7 +42,7 @@ import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache;
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.ExcelPoiUtils;
import com.epmet.commons.tools.utils.FileUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.constant.UserDemandConstant;
import com.epmet.constants.ImportTaskConstants;
@ -59,7 +56,7 @@ import com.epmet.dto.result.demand.ServiceStatDTO;
import com.epmet.entity.IcCommunitySelfOrganizationEntity;
import com.epmet.entity.IcPartyUnitEntity;
import com.epmet.excel.IcPartyUnitImportExcel;
import com.epmet.excel.IcPartyUnitImportFailedExcel;
import com.epmet.excel.handler.IcPartyUnitExcelImportListener;
import com.epmet.feign.*;
import com.epmet.service.IcCommunitySelfOrganizationService;
import com.epmet.service.IcPartyUnitService;
@ -75,18 +72,17 @@ 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 javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.stream.Collectors;
@ -380,214 +376,6 @@ public class IcPartyUnitServiceImpl extends BaseServiceImpl<IcPartyUnitDao, IcPa
}).collect(Collectors.toList());
}
/**
* 导入数据
*
* @param tokenDto
* @param response
* @param file
* @Param tokenDto
* @Param response
* @Param file
* @Return
* @Author zhaoqifeng
* @Date 2021/11/29 11:01
*/
@Override
public void importData(TokenDto tokenDto, HttpServletResponse response, MultipartFile file, String taskId) throws IOException {
List<IcPartyUnitImportFailedExcel> fileList = new ArrayList<>();
ExcelImportResult<IcPartyUnitImportExcel> importResult = ExcelPoiUtils.importExcelMore(file, 0, 1, IcPartyUnitImportExcel.class);
List<IcPartyUnitImportExcel> failList = importResult.getFailList();
//存放错误数据行号
if (!org.springframework.util.CollectionUtils.isEmpty(failList)) {
for (IcPartyUnitImportExcel entity : failList) {
//打印失败的行 和失败的信息
log.warn("第{}行,{}", entity.getRowNum(), entity.getErrorMsg());
IcPartyUnitImportFailedExcel failed = ConvertUtils.sourceToTarget(entity, IcPartyUnitImportFailedExcel.class);
failed.setErrorInfo(entity.getErrorMsg());
fileList.add(failed);
}
}
List<IcPartyUnitImportExcel> result = importResult.getList();
CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId());
if (null == staffInfoCache) {
throw new EpmetException(8000, "获取用户缓存失败");
}
List<OptionDTO> serviceItemList = icServiceItemDictService.queryDictList(tokenDto.getCustomerId());
Map<String, String> categoryMap = serviceItemList.stream().collect(Collectors.toMap(OptionDTO::getValue, OptionDTO::getLabel));
//1.数据校验
Iterator<IcPartyUnitImportExcel> iterator = result.iterator();
while (iterator.hasNext()) {
IcPartyUnitImportExcel obj = iterator.next();
//单位名称不能为空,不可重复
if (StringUtils.isBlank(obj.getUnitName())) {
IcPartyUnitImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyUnitImportFailedExcel.class);
failed.setErrorInfo("单位名称为空");
fileList.add(failed);
log.warn(String.format("单位名称为空,行号->%s", obj.getRowNum()));
iterator.remove();
} else {
LambdaQueryWrapper<IcPartyUnitEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(IcPartyUnitEntity::getAgencyId, staffInfoCache.getAgencyId());
wrapper.eq(IcPartyUnitEntity::getUnitName, obj.getUnitName());
List<IcPartyUnitEntity> list = baseDao.selectList(wrapper);
if (CollectionUtils.isNotEmpty(list)) {
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())) {
IcPartyUnitImportFailedExcel failed = ConvertUtils.sourceToTarget(obj, IcPartyUnitImportFailedExcel.class);
failed.setErrorInfo("分类名不存在");
fileList.add(failed);
log.warn(String.format("分类名不存在,行号->%s", obj.getRowNum()));
iterator.remove();
}
//服务事项校验
if (StringUtils.isNotBlank(obj.getServiceMatter())) {
List<String> matters = Arrays.asList(obj.getServiceMatter().split(StrConstant.COLON));
matters.forEach(item -> {
if (null == categoryMap.get(item)) {
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())) {
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.isNotEmpty(result)) {
List<IcPartyUnitEntity> list = result.stream().map(item -> {
IcPartyUnitEntity entity = new IcPartyUnitEntity();
entity.setCustomerId(tokenDto.getCustomerId());
entity.setAgencyId(staffInfoCache.getAgencyId());
entity.setPids(staffInfoCache.getAgencyPIds());
entity.setUnitName(item.getUnitName());
entity.setType(PartyUnitTypeEnum.getCode(item.getType()));
if (StringUtils.isNotBlank(item.getServiceMatter())) {
entity.setServiceMatter(getServiceMatter(categoryMap, item.getServiceMatter()));
}
entity.setContact(item.getContact());
entity.setContactMobile(item.getContactMobile());
entity.setAddress(item.getAddress());
entity.setLatitude(item.getLatitude());
entity.setLongitude(item.getLongitude());
entity.setMemberCount(item.getMemberCount());
entity.setRemark(item.getRemark());
return entity;
}).collect(Collectors.toList());
insertBatch(list);
}
String str = String.format("共%s条,成功导入%s条。", fileList.size() + result.size(), fileList.size() + result.size() - fileList.size());
if (fileList.size() > NumConstant.ZERO) {
List<Integer> numList = fileList.stream().map(IcPartyUnitImportFailedExcel::getRowNum).sorted().collect(Collectors.toList());
String subList = numList.stream().map(String::valueOf).collect(Collectors.joining("、"));
log.warn(str + "第" + subList + "行未成功!");
}
//错误数据生成文件,修改导入任务状态
erroeImport(fileList, taskId, tokenDto.getUserId());
}
private void erroeImport(List<IcPartyUnitImportFailedExcel> fileList, String importTaskId, String staffId) throws IOException {
String url = "";
//1.有错误数据则生成错误数据存放文件传到阿里云服务
if (CollectionUtils.isNotEmpty(fileList)) {
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("导入失败的数据列表", "导入失败的数据列表"),
IcPartyUnitImportFailedExcel.class, fileList);
// 文件名
String resultDescFileName = UUID.randomUUID().toString().concat(".xlsx");
FileItemFactory factory = new DiskFileItemFactory(16, null);
FileItem fileItem = factory.createItem("file", ContentType.APPLICATION_OCTET_STREAM.toString(), true, resultDescFileName);
OutputStream os = fileItem.getOutputStream();
Result<UploadImgResultDTO> uploadResult = null;
try {
workbook.write(os);
uploadResult = ossFeignClient.uploadImportTaskDescFile(new CommonsMultipartFile(fileItem));
} catch (Exception e) {
String errormsg = ExceptionUtils.getErrorStackTrace(e);
log.error("【联建单位信息导入】上传错误描述文件:{}", errormsg);
} finally {
try {
os.close();
} catch (IOException e) {
String errormsg = ExceptionUtils.getErrorStackTrace(e);
log.error("【联建单位信息导入】上传错误描述文件关闭输出流:{}", errormsg);
}
try {
fileItem.delete();
} catch (Exception e) {
String errormsg = ExceptionUtils.getErrorStackTrace(e);
log.error("【联建单位信息导入】上传错误描述文件删除临时文件:{}", errormsg);
}
}
if (uploadResult == null || !uploadResult.success()) {
log.error("【联建单位信息导入】调用OSS上传结果描述文件失败");
} else {
url = uploadResult.getData().getUrl();
}
}
//2.更新导入任务数据
ImportTaskCommonFormDTO importTaskForm = new ImportTaskCommonFormDTO();
importTaskForm.setOperatorId(staffId);
importTaskForm.setBizType(ImportTaskConstants.BIZ_TYPE_PARTY_UNIT);
importTaskForm.setTaskId(importTaskId);
importTaskForm.setResultDescFilePath(url);
importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS);
if (CollectionUtils.isNotEmpty(fileList)) {
importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL);
importTaskForm.setResultDesc("联建单位导入存在错误数据");
}
Result result = commonServiceOpenFeignClient.finishImportTask(importTaskForm);
if (!result.success()) {
throw new RenException(result.getInternalMsg());
}
}
/**
* @param formDTO
* @Description 按类型统计单位数量
@ -798,4 +586,133 @@ public class IcPartyUnitServiceImpl extends BaseServiceImpl<IcPartyUnitDao, IcPa
}
return baseDao.getUnitNames(unitIds);
}
/**
* 执行Excel导入
*
* @param filePath
* @param importTaskId
* @param customerId
* @param userId
*/
@Override
public void execAsyncExcelImport(Path filePath, String importTaskId, String customerId, String userId) {
try {
//获取当前登录用户所属组织id
CustomerStaffInfoCacheResult staffInfo= queryCurrentStaff(customerId,userId);
//联建单位分类:楼宇党建、两新组织、区域单位党建、机关直属部门、社会团体、民办非企业单位、基金会、其他
Result<Map<String, String>> partyUnitTypeMap = epmetAdminOpenFeignClient.dictMap(DictTypeEnum.PARTY_UNIT_TYPE.getCode());
Map<String, String> tMap = partyUnitTypeMap.getData().entrySet().stream().collect(Collectors.toMap(entry -> entry.getValue(), entry -> entry.getKey()));
IcPartyUnitExcelImportListener listener = new IcPartyUnitExcelImportListener(customerId,staffInfo, this,tMap);
EasyExcel.read(filePath.toFile(), IcPartyUnitImportExcel.class, listener).headRowNumber(1).sheet(0).doRead();
Path errorDescFile = null;
String errorDesFileUrl = null;
List<IcPartyUnitImportExcel.ErrorRow> errorRows = listener.getErrorRows();
boolean failed = errorRows.size() > 0;
if (failed) {
// 生成并上传错误文件
try {
// 文件生成
Path errorDescDir = FileUtils.getAndCreateDirUnderEpmetFilesDir("ic_party_unit", "import", "error_des");
String fileName = UUID.randomUUID().toString().concat(".xlsx");
errorDescFile = errorDescDir.resolve(fileName);
FileItemFactory factory = new DiskFileItemFactory(16, errorDescDir.toFile());
FileItem fileItem = factory.createItem("file", ContentType.APPLICATION_OCTET_STREAM.toString(), true, fileName);
OutputStream os = fileItem.getOutputStream();
EasyExcel.write(os, IcPartyUnitImportExcel.ErrorRow.class).sheet("导入失败列表").doWrite(errorRows);
// 文件上传oss
Result<UploadImgResultDTO> errorDesFileUploadResult = ossFeignClient.uploadImportTaskDescFile(new CommonsMultipartFile(fileItem));
if (errorDesFileUploadResult.success()) {
errorDesFileUrl = errorDesFileUploadResult.getData().getUrl();
}
} finally {
if (Files.exists(errorDescFile)) {
Files.delete(errorDescFile);
}
}
}
ImportTaskCommonFormDTO importFinishTaskForm = new ImportTaskCommonFormDTO();
importFinishTaskForm.setTaskId(importTaskId);
importFinishTaskForm.setProcessStatus(failed ? ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL : ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS);
importFinishTaskForm.setOperatorId(userId);
importFinishTaskForm.setResultDesc("");
importFinishTaskForm.setResultDescFilePath(errorDesFileUrl);
Result result = commonServiceOpenFeignClient.finishImportTask(importFinishTaskForm);
if (!result.success()) {
log.error("【联建单位导入】finishImportTask失败");
}
} catch (Exception e) {
String errorMsg = ExceptionUtils.getErrorStackTrace(e);
log.error("【联建单位导入】出错:{}", errorMsg);
ImportTaskCommonFormDTO importFinishTaskForm = new ImportTaskCommonFormDTO();
importFinishTaskForm.setTaskId(importTaskId);
importFinishTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL);
importFinishTaskForm.setOperatorId(userId);
importFinishTaskForm.setResultDesc("导入失败");
Result result = commonServiceOpenFeignClient.finishImportTask(importFinishTaskForm);
if (!result.success()) {
log.error("【联建单位导入】导入记录状态修改为'完成'失败");
}
} finally {
// 删除临时文件
if (Files.exists(filePath)) {
try {
Files.delete(filePath);
} catch (IOException e) {
log.error("method exception", e);
}
}
}
}
public CustomerStaffInfoCacheResult queryCurrentStaff(String customerId, String userId) {
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(customerId, userId);
if (null == staffInfo) {
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "查询工作人员缓存信息异常", EpmetErrorCode.SERVER_ERROR.getMsg());
}
return staffInfo;
}
/**
* 批量持久化
* @param entities
*/
public void batchPersist(List<IcPartyUnitEntity> entities) {
entities.forEach(e -> {
String id = IdWorker.getIdStr(e);
e.setId(id);
baseDao.insert(e);
});
}
/**
*
* @param unitName
* @param agencyId
* @param id
* @return true 已存在
* false 不存在
*/
public Boolean checkUnitName(String unitName,String agencyId,String id){
LambdaQueryWrapper<IcPartyUnitEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(IcPartyUnitEntity::getAgencyId, agencyId)
.eq(IcPartyUnitEntity::getUnitName, unitName)
.ne(StringUtils.isNotBlank(id),IcPartyUnitEntity::getId,id);
List<IcPartyUnitEntity> list = baseDao.selectList(wrapper);
if (CollectionUtils.isNotEmpty(list)) {
return true;
}
return false;
}
}

1
epmet-module/epmet-heart/epmet-heart-server/src/main/resources/db/migration/V0.0.30__icpartyunit.sql

@ -0,0 +1 @@
alter table ic_party_unit MODIFY COLUMN `TYPE` varchar(32) NULL COMMENT '分类 【字典表】:02.20因烟台导入需求改为不必填';

BIN
epmet-module/epmet-heart/epmet-heart-server/src/main/resources/templates/icpartyactivity_import_tem.xlsx

Binary file not shown.

3
epmet-user/epmet-user-client/src/main/java/com/epmet/dto/ChangeWelfareDTO.java

@ -1,9 +1,11 @@
package com.epmet.dto;
import com.epmet.commons.tools.validator.group.AddGroup;
import com.epmet.commons.tools.validator.group.CustomerClientShowGroup;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.Date;
@ -27,6 +29,7 @@ public class ChangeWelfareDTO implements Serializable {
/**
* epmet用户主键
*/
@NotBlank(message = "userId不能为空",groups = AddGroup.class)
private String userId;
/**

6
epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/AddIcNatFormDTO.java

@ -5,7 +5,6 @@ import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
@ -110,6 +109,9 @@ public class AddIcNatFormDTO implements Serializable {
private String customerId;
private String staffId;
private String client;
/**
* 政府端:gov居民端:resi运营端:oper
*/
private String app;
}

4
epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/IcTripReportFormDTO.java

@ -183,7 +183,7 @@ public class IcTripReportFormDTO implements Serializable {
/**
* 交通方式来源字典表(traffic_type)
*/
@NotBlank(message = "返回方式不能为空", groups = {PcAddRequired.class, ResiUserRequired.class})
// @NotBlank(message = "返回方式不能为空", groups = {PcAddRequired.class, ResiUserRequired.class})
private String trafficType;
/**
* 其他返回方式交通方式为其他时此列需要有值
@ -192,7 +192,7 @@ public class IcTripReportFormDTO implements Serializable {
/**
* 来源地详细信息 source_address字段的说明
*/
@NotBlank(message = "来自地区不能为空", groups = {PcAddRequired.class, ResiUserRequired.class})
// @NotBlank(message = "来自地区不能为空", groups = {PcAddRequired.class, ResiUserRequired.class})
private String sourceDetailAddress;
/**
* 疫苗接种针次 (0针 1针 2针 3针)小寨子

3
epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcNatController.java

@ -92,7 +92,8 @@ public class IcNatController implements ResultDataResolver {
ValidatorUtils.validateEntity(formDTO, AddIcNatFormDTO.Nat.class);
formDTO.setCustomerId(tokenDto.getCustomerId());
formDTO.setStaffId(tokenDto.getUserId());
formDTO.setClient(tokenDto.getClient());
// formDTO.setClient(tokenDto.getClient());
formDTO.setApp(tokenDto.getApp());
icNucleinService.add(formDTO);
return new Result();
}

21
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcNatServiceImpl.java

@ -119,7 +119,7 @@ public class IcNatServiceImpl extends BaseServiceImpl<IcNatDao, IcNatEntity> imp
if (null != icNatDTO && icNatDTO.getNatResult().equals(formDTO.getNatResult())) {
throw new RenException(EpmetErrorCode.IC_NAT_IDCARD_NATTIME.getCode(), EpmetErrorCode.IC_NAT_IDCARD_NATTIME.getMsg());
} else if (null != icNatDTO && !icNatDTO.getNatResult().equals(formDTO.getNatResult())) {
if ("wxmp".equals(formDTO.getClient())) {
if (AppClientConstant.APP_RESI.equals(formDTO.getApp())) {
throw new RenException(EpmetErrorCode.RESI_IC_NAT.getCode(), EpmetErrorCode.RESI_IC_NAT.getMsg());
}
throw new RenException(EpmetErrorCode.IC_NAT.getCode(), EpmetErrorCode.IC_NAT.getMsg());
@ -129,10 +129,6 @@ public class IcNatServiceImpl extends BaseServiceImpl<IcNatDao, IcNatEntity> imp
if (null == agencyInfo) {
throw new RenException(String.format("获取组织缓存信息失败%s", formDTO.getAgencyId()));
}
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(formDTO.getCustomerId(), formDTO.getStaffId());
if (null == staffInfo){
throw new EpmetException(String.format("获取工作人员信息失败%s", formDTO.getStaffId()));
}
ResiAndLocalResiResultDTO resiCount = icResiUserDao.getResiCount(formDTO.getAgencyId(), formDTO.getIdCard(), formDTO.getCustomerId());
//2.新增核酸基础信息数据
IcNatEntity entity = ConvertUtils.sourceToTarget(formDTO, IcNatEntity.class);
@ -146,8 +142,19 @@ public class IcNatServiceImpl extends BaseServiceImpl<IcNatDao, IcNatEntity> imp
IcNatRelationEntity relationEntity = ConvertUtils.sourceToTarget(formDTO, IcNatRelationEntity.class);
relationEntity.setIcNatId(entity.getId());
relationEntity.setIsLocalResiUser(resiCount.getIsLocal() == NumConstant.ZERO ? NumConstant.ZERO_STR : NumConstant.ONE_STR);
relationEntity.setAgencyId(staffInfo.getAgencyId());
relationEntity.setPids(StringUtils.isNotBlank(staffInfo.getAgencyPIds()) ? staffInfo.getAgencyPIds() + ":" + staffInfo.getAgencyId() : staffInfo.getAgencyId());
if(AppClientConstant.APP_GOV.equals(formDTO.getApp())){
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(formDTO.getCustomerId(), formDTO.getStaffId());
if (null == staffInfo){
log.error(String.format("获取工作人员信息失败%s", formDTO.getStaffId()));
throw new EpmetException(String.format("获取工作人员信息失败%s", formDTO.getStaffId()));
}
relationEntity.setAgencyId(staffInfo.getAgencyId());
relationEntity.setPids(StringUtils.isNotBlank(staffInfo.getAgencyPIds()) ? staffInfo.getAgencyPIds() + ":" + staffInfo.getAgencyId() : staffInfo.getAgencyId());
}else{
relationEntity.setAgencyId(formDTO.getAgencyId());
AgencyInfoCache agencyInfoCache=CustomerOrgRedis.getAgencyInfo(formDTO.getAgencyId());
relationEntity.setPids(StringUtils.isNotBlank(agencyInfoCache.getPids()) ? agencyInfoCache.getPids() + ":" + formDTO.getAgencyId() : formDTO.getAgencyId());
}
icNatRelationDao.insert(relationEntity);
//3.新增通知表信息

Loading…
Cancel
Save