|
@ -1,9 +1,11 @@ |
|
|
package com.epmet.modules.partymember.service.impl; |
|
|
package com.epmet.modules.partymember.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
|
|
import com.epmet.commons.tools.constant.AppClientConstant; |
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
@ -16,20 +18,23 @@ import com.epmet.commons.tools.enums.IcFormCodeEnum; |
|
|
import com.epmet.commons.tools.enums.PartyPostEnum; |
|
|
import com.epmet.commons.tools.enums.PartyPostEnum; |
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
|
|
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
|
|
|
import com.epmet.commons.tools.feign.ResultDataResolver; |
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
import com.epmet.commons.tools.utils.*; |
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
import com.epmet.constants.ImportTaskConstants; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
|
|
import com.epmet.dto.form.IcFormOptionsQueryFormDTO; |
|
|
import com.epmet.dto.form.IcFormOptionsQueryFormDTO; |
|
|
import com.epmet.dto.form.IcPartyMemberFormDTO; |
|
|
import com.epmet.dto.form.IcPartyMemberFormDTO; |
|
|
import com.epmet.dto.form.IcPartyMemberListFormDTO; |
|
|
import com.epmet.dto.form.IcPartyMemberListFormDTO; |
|
|
import com.epmet.dto.result.PartyMemberAgeResultDTO; |
|
|
import com.epmet.dto.result.PartyMemberAgeResultDTO; |
|
|
import com.epmet.dto.result.PartyMemberEducationResultDTO; |
|
|
import com.epmet.dto.result.PartyMemberEducationResultDTO; |
|
|
|
|
|
import com.epmet.dto.result.UploadImgResultDTO; |
|
|
import com.epmet.feign.EpmetAdminOpenFeignClient; |
|
|
import com.epmet.feign.EpmetAdminOpenFeignClient; |
|
|
import com.epmet.feign.EpmetUserOpenFeignClient; |
|
|
import com.epmet.feign.EpmetUserOpenFeignClient; |
|
|
import com.epmet.feign.OperCustomizeOpenFeignClient; |
|
|
import com.epmet.feign.OperCustomizeOpenFeignClient; |
|
|
|
|
|
import com.epmet.feign.OssFeignClient; |
|
|
import com.epmet.modules.partyOrg.dao.IcPartyOrgDao; |
|
|
import com.epmet.modules.partyOrg.dao.IcPartyOrgDao; |
|
|
import com.epmet.modules.partyOrg.entity.IcPartyOrgEntity; |
|
|
import com.epmet.modules.partyOrg.entity.IcPartyOrgEntity; |
|
|
import com.epmet.modules.partyOrg.service.IcPartyOrgService; |
|
|
import com.epmet.modules.partyOrg.service.IcPartyOrgService; |
|
@ -39,20 +44,34 @@ import com.epmet.modules.partymember.dao.IcPartyMemberPointDao; |
|
|
import com.epmet.modules.partymember.entity.IcPartyMemberEntity; |
|
|
import com.epmet.modules.partymember.entity.IcPartyMemberEntity; |
|
|
import com.epmet.modules.partymember.entity.IcPartyMemberPayRecordEntity; |
|
|
import com.epmet.modules.partymember.entity.IcPartyMemberPayRecordEntity; |
|
|
import com.epmet.modules.partymember.entity.IcPartyMemberPointEntity; |
|
|
import com.epmet.modules.partymember.entity.IcPartyMemberPointEntity; |
|
|
|
|
|
import com.epmet.modules.partymember.excel.IcPartyMemberImportExcel; |
|
|
|
|
|
import com.epmet.modules.partymember.excel.handler.IcPartyMemberImportListener; |
|
|
import com.epmet.modules.partymember.service.IcPartyMemberService; |
|
|
import com.epmet.modules.partymember.service.IcPartyMemberService; |
|
|
import com.epmet.resi.partymember.dto.partymember.IcPartyMemberDTO; |
|
|
import com.epmet.resi.partymember.dto.partymember.IcPartyMemberDTO; |
|
|
import com.epmet.resi.partymember.dto.partymember.form.IcPartyMemberFromDTO; |
|
|
import com.epmet.resi.partymember.dto.partymember.form.IcPartyMemberFromDTO; |
|
|
import com.epmet.resi.partymember.dto.partymember.result.IcPartyMemberResultDTO; |
|
|
import com.epmet.resi.partymember.dto.partymember.result.IcPartyMemberResultDTO; |
|
|
|
|
|
import com.epmet.utils.ImportTaskUtils; |
|
|
import com.github.pagehelper.PageHelper; |
|
|
import com.github.pagehelper.PageHelper; |
|
|
import com.github.pagehelper.PageInfo; |
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
|
|
import org.apache.commons.fileupload.FileItem; |
|
|
|
|
|
import org.apache.commons.fileupload.disk.DiskFileItemFactory; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
import org.apache.http.entity.ContentType; |
|
|
|
|
|
import org.apache.poi.util.IOUtils; |
|
|
|
|
|
import org.springframework.scheduling.annotation.Async; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile; |
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
import java.io.OutputStream; |
|
|
import java.math.BigDecimal; |
|
|
import java.math.BigDecimal; |
|
|
import java.math.RoundingMode; |
|
|
import java.math.RoundingMode; |
|
|
|
|
|
import java.nio.file.Files; |
|
|
|
|
|
import java.nio.file.Path; |
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@ -62,8 +81,9 @@ import java.util.stream.Collectors; |
|
|
* @author generator generator@elink-cn.com |
|
|
* @author generator generator@elink-cn.com |
|
|
* @since v1.0.0 2022-05-17 |
|
|
* @since v1.0.0 2022-05-17 |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
@Slf4j |
|
|
@Service |
|
|
@Service |
|
|
public class IcPartyMemberServiceImpl extends BaseServiceImpl<IcPartyMemberDao, IcPartyMemberEntity> implements IcPartyMemberService { |
|
|
public class IcPartyMemberServiceImpl extends BaseServiceImpl<IcPartyMemberDao, IcPartyMemberEntity> implements IcPartyMemberService, ResultDataResolver { |
|
|
|
|
|
|
|
|
@Resource |
|
|
@Resource |
|
|
private IcPartyOrgService icPartyOrgService; |
|
|
private IcPartyOrgService icPartyOrgService; |
|
@ -79,6 +99,8 @@ public class IcPartyMemberServiceImpl extends BaseServiceImpl<IcPartyMemberDao, |
|
|
private IcPartyMemberPayRecordDao icPartyMemberPayRecordDao; |
|
|
private IcPartyMemberPayRecordDao icPartyMemberPayRecordDao; |
|
|
@Resource |
|
|
@Resource |
|
|
private IcPartyMemberPointDao icPartyMemberPointDao; |
|
|
private IcPartyMemberPointDao icPartyMemberPointDao; |
|
|
|
|
|
@Resource |
|
|
|
|
|
private OssFeignClient ossFeignClient; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public PageData<IcPartyMemberResultDTO> page(TokenDto tokenDto, IcPartyMemberFromDTO formDTO) { |
|
|
public PageData<IcPartyMemberResultDTO> page(TokenDto tokenDto, IcPartyMemberFromDTO formDTO) { |
|
@ -419,4 +441,202 @@ public class IcPartyMemberServiceImpl extends BaseServiceImpl<IcPartyMemberDao, |
|
|
}).collect(Collectors.toList()); |
|
|
}).collect(Collectors.toList()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 执行Excel导入 |
|
|
|
|
|
* |
|
|
|
|
|
* @param filePath |
|
|
|
|
|
* @param importTaskId |
|
|
|
|
|
*/ |
|
|
|
|
|
@Async |
|
|
|
|
|
@Override |
|
|
|
|
|
public void execAsyncExcelImport(Path filePath, String importTaskId) { |
|
|
|
|
|
String userId = null; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
userId = EpmetRequestHolder.getHeader(AppClientConstant.USER_ID); |
|
|
|
|
|
String app = EpmetRequestHolder.getHeader(AppClientConstant.APP); |
|
|
|
|
|
String client = EpmetRequestHolder.getHeader(AppClientConstant.CLIENT); |
|
|
|
|
|
|
|
|
|
|
|
log.info("【核酸检测导入】userId:{}, app:{}, client:{}", userId, app, client); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IcPartyMemberImportListener listener = new IcPartyMemberImportListener(userId, this); |
|
|
|
|
|
|
|
|
|
|
|
EasyExcel.read(filePath.toFile(), IcPartyMemberImportExcel.class, listener).headRowNumber(2).sheet(0).doRead(); |
|
|
|
|
|
|
|
|
|
|
|
String errorDesFileUrl = null; |
|
|
|
|
|
|
|
|
|
|
|
List<IcPartyMemberImportExcel.RowRemarkMessage> errorRows = listener.getErrorRows(); |
|
|
|
|
|
List<IcPartyMemberImportExcel.RowRemarkMessage> otherRows = listener.getOtherRows(); |
|
|
|
|
|
|
|
|
|
|
|
boolean failed = errorRows.size() > 0; |
|
|
|
|
|
|
|
|
|
|
|
// 合并到一起写入
|
|
|
|
|
|
errorRows.addAll(otherRows); |
|
|
|
|
|
|
|
|
|
|
|
// 生成并上传描述文件
|
|
|
|
|
|
OutputStream os = null; |
|
|
|
|
|
FileItem fileItem = null; |
|
|
|
|
|
if (errorRows.size() > 0) { |
|
|
|
|
|
try { |
|
|
|
|
|
// 文件生成
|
|
|
|
|
|
Path errorDescDir = FileUtils.getAndCreateDirUnderEpmetFilesDir("ic_nat", "import", "error_des"); |
|
|
|
|
|
String timeMillis = String.valueOf(System.currentTimeMillis()); |
|
|
|
|
|
String fileName = "icnat_import_error_".concat(timeMillis).concat(".xlsx"); |
|
|
|
|
|
|
|
|
|
|
|
fileItem = new DiskFileItemFactory(DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD, errorDescDir.toFile()) |
|
|
|
|
|
.createItem("file", ContentType.APPLICATION_OCTET_STREAM.toString(), false, fileName); |
|
|
|
|
|
|
|
|
|
|
|
os = fileItem.getOutputStream(); |
|
|
|
|
|
|
|
|
|
|
|
EasyExcel.write(os, IcPartyMemberImportExcel.RowRemarkMessage.class).sheet("信息列表").doWrite(errorRows); |
|
|
|
|
|
// 文件上传oss
|
|
|
|
|
|
Result<UploadImgResultDTO> errorDesFileUploadResult = ossFeignClient.uploadImportTaskDescFile(new CommonsMultipartFile(fileItem)); |
|
|
|
|
|
if (errorDesFileUploadResult.success()) { |
|
|
|
|
|
errorDesFileUrl = errorDesFileUploadResult.getData().getUrl(); |
|
|
|
|
|
} |
|
|
|
|
|
} finally { |
|
|
|
|
|
IOUtils.closeQuietly(os); |
|
|
|
|
|
try { |
|
|
|
|
|
fileItem.delete(); |
|
|
|
|
|
} catch (Exception e){ |
|
|
|
|
|
log.error("【核酸检测导入】删除临时描述文件失败:{}", ExceptionUtils.getErrorStackTrace(e)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 完成导入
|
|
|
|
|
|
Result result = ImportTaskUtils.finishImportTask(importTaskId, |
|
|
|
|
|
failed ? ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL : ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS, |
|
|
|
|
|
errorDesFileUrl, |
|
|
|
|
|
""); |
|
|
|
|
|
|
|
|
|
|
|
if (!result.success()) { |
|
|
|
|
|
log.error("【核酸检测导入】导入记录状态修改为'finished_success'失败"); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
String errorMsg = ExceptionUtils.getErrorStackTrace(e); |
|
|
|
|
|
log.error("【核酸检测导入】出错:{}", errorMsg); |
|
|
|
|
|
|
|
|
|
|
|
Result result = ImportTaskUtils.finishImportTask(importTaskId, ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL, null, "导入失败"); |
|
|
|
|
|
|
|
|
|
|
|
if (!result.success()) { |
|
|
|
|
|
log.error("【核酸检测导入】导入记录状态修改为'finished_fail'失败"); |
|
|
|
|
|
} |
|
|
|
|
|
} finally { |
|
|
|
|
|
// 删除临时文件
|
|
|
|
|
|
if (Files.exists(filePath)) { |
|
|
|
|
|
try { |
|
|
|
|
|
Files.delete(filePath); |
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
log.error("method exception", e); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 批量持久化 |
|
|
|
|
|
* @param entities |
|
|
|
|
|
*/ |
|
|
|
|
|
public void batchPersist(List<IcPartyMemberEntity> entities, IcPartyMemberImportListener listener) { |
|
|
|
|
|
String customerId = EpmetRequestHolder.getHeader(AppClientConstant.CUSTOMER_ID); |
|
|
|
|
|
String currentUserId = EpmetRequestHolder.getHeader(AppClientConstant.USER_ID); |
|
|
|
|
|
|
|
|
|
|
|
entities.forEach(e -> { |
|
|
|
|
|
try { |
|
|
|
|
|
persistPartyMember(e, customerId, currentUserId, listener); |
|
|
|
|
|
} catch (Exception exception) { |
|
|
|
|
|
String errorMsg = ExceptionUtils.getErrorStackTrace(exception); |
|
|
|
|
|
log.error(errorMsg); |
|
|
|
|
|
|
|
|
|
|
|
IcPartyMemberImportExcel.RowRemarkMessage errorRow = new IcPartyMemberImportExcel.RowRemarkMessage(); |
|
|
|
|
|
errorRow.setName(e.getName()); |
|
|
|
|
|
errorRow.setMobile(e.getMobile()); |
|
|
|
|
|
errorRow.setIdCard(e.getIdCard()); |
|
|
|
|
|
errorRow.setErrorInfo("未知系统错误"); |
|
|
|
|
|
listener.getErrorRows().add(errorRow); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 单条持久化 |
|
|
|
|
|
* @Param e |
|
|
|
|
|
* @Param customerId |
|
|
|
|
|
* @Param currentUserId |
|
|
|
|
|
* @Param listener |
|
|
|
|
|
* @Return |
|
|
|
|
|
* @Author zhaoqifeng |
|
|
|
|
|
* @Date 2022/5/23 15:24 |
|
|
|
|
|
*/ |
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
|
public void persistPartyMember(IcPartyMemberEntity e, String customerId, String currentUserId, IcPartyMemberImportListener listener) { |
|
|
|
|
|
List<IcPartyMemberImportExcel.RowRemarkMessage> otherRows = listener.getOtherRows(); |
|
|
|
|
|
String idCard = e.getIdCard(); |
|
|
|
|
|
String name = e.getName(); |
|
|
|
|
|
String mobile = e.getMobile(); |
|
|
|
|
|
|
|
|
|
|
|
//获取党组织信息
|
|
|
|
|
|
LambdaUpdateWrapper<IcPartyOrgEntity> orgWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
|
|
orgWrapper.eq(IcPartyOrgEntity::getCustomerId, customerId); |
|
|
|
|
|
orgWrapper.eq(IcPartyOrgEntity::getPartyOrgName, e.getSszb()); |
|
|
|
|
|
IcPartyOrgEntity org = icPartyOrgDao.selectOne(orgWrapper); |
|
|
|
|
|
if (null == org) { |
|
|
|
|
|
String message = "所属党组织不存在"; |
|
|
|
|
|
IcPartyMemberImportExcel.RowRemarkMessage errorRow = new IcPartyMemberImportExcel.RowRemarkMessage(); |
|
|
|
|
|
errorRow.setName(name); |
|
|
|
|
|
errorRow.setMobile(mobile); |
|
|
|
|
|
errorRow.setIdCard(idCard); |
|
|
|
|
|
errorRow.setErrorInfo(message); |
|
|
|
|
|
otherRows.add(errorRow); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//判断党员是否已存在
|
|
|
|
|
|
LambdaQueryWrapper<IcPartyMemberEntity> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
|
wrapper.eq(IcPartyMemberEntity::getCustomerId, customerId); |
|
|
|
|
|
wrapper.eq(IcPartyMemberEntity::getIdCard, e.getIdCard()); |
|
|
|
|
|
IcPartyMemberEntity partyMember = baseDao.selectOne(wrapper); |
|
|
|
|
|
if (null != partyMember) { |
|
|
|
|
|
String message = "党员已存在"; |
|
|
|
|
|
IcPartyMemberImportExcel.RowRemarkMessage errorRow = new IcPartyMemberImportExcel.RowRemarkMessage(); |
|
|
|
|
|
errorRow.setName(name); |
|
|
|
|
|
errorRow.setMobile(mobile); |
|
|
|
|
|
errorRow.setIdCard(idCard); |
|
|
|
|
|
errorRow.setErrorInfo(message); |
|
|
|
|
|
otherRows.add(errorRow); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
e.setAgencyId(org.getAgencyId()); |
|
|
|
|
|
e.setAgencyPids(org.getAgencyPids()); |
|
|
|
|
|
e.setSszb(org.getId()); |
|
|
|
|
|
e.setOrgPids(org.getOrgPids()); |
|
|
|
|
|
|
|
|
|
|
|
e.setIsLd(("是").equals(e.getIsLd())?NumConstant.ONE_STR:NumConstant.ZERO_STR); |
|
|
|
|
|
e.setIsDyzxh(("是").equals(e.getIsDyzxh())?NumConstant.ONE_STR:NumConstant.ZERO_STR); |
|
|
|
|
|
e.setIsMxx(("是").equals(e.getIsMxx())?NumConstant.ONE_STR:NumConstant.ZERO_STR); |
|
|
|
|
|
//职务
|
|
|
|
|
|
e.setPartyZw(PartyPostEnum.getCode(e.getPartyZw())); |
|
|
|
|
|
//文化程度
|
|
|
|
|
|
//获取文化程度字典
|
|
|
|
|
|
DictListFormDTO dictFormDTO = new DictListFormDTO(); |
|
|
|
|
|
dictFormDTO.setDictType(DictTypeEnum.EDUCATION.getCode()); |
|
|
|
|
|
Result<List<DictListResultDTO>> education = epmetAdminOpenFeignClient.dictList(dictFormDTO); |
|
|
|
|
|
if (CollectionUtils.isNotEmpty(education.getData())) { |
|
|
|
|
|
Map<String, String> map = education.getData().stream().collect(Collectors.toMap(DictListResultDTO::getLabel, DictListResultDTO::getValue)); |
|
|
|
|
|
e.setCulture(map.get(e.getCulture())); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//同步ic_resi_user表对应的数据,并获取志愿者类型
|
|
|
|
|
|
Result<IcPartyMemberDTO> result = epmetUserOpenFeignClient.icPartyMemberSync(ConvertUtils.sourceToTarget(e, IcPartyMemberDTO.class)); |
|
|
|
|
|
if (!result.success() && null != result.getData()) { |
|
|
|
|
|
e.setIcResiUser(result.getData().getIcResiUser()); |
|
|
|
|
|
e.setVolunteerCategory(result.getData().getVolunteerCategory()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
baseDao.insert(e); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |