|
|
@ -1,5 +1,7 @@ |
|
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil; |
|
|
|
import cn.afterturn.easypoi.excel.entity.ExportParams; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
@ -8,27 +10,57 @@ import com.epmet.commons.tools.constant.FieldConstant; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; |
|
|
|
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; |
|
|
|
import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache; |
|
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
|
import com.epmet.commons.tools.utils.ExcelPoiUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.constants.ImportTaskConstants; |
|
|
|
import com.epmet.dao.IcEpidemicSpecialAttentionDao; |
|
|
|
import com.epmet.dto.IcEpidemicSpecialAttentionDTO; |
|
|
|
import com.epmet.dto.form.CancelAttentionPackageFormDTO; |
|
|
|
import com.epmet.dto.form.ImportTaskCommonFormDTO; |
|
|
|
import com.epmet.dto.form.VaccinationAddFormDTO; |
|
|
|
import com.epmet.dto.form.VaccinationListFormDTO; |
|
|
|
import com.epmet.dto.result.UploadImgResultDTO; |
|
|
|
import com.epmet.dto.result.VaccinationListResultDTO; |
|
|
|
import com.epmet.entity.IcEpidemicSpecialAttentionEntity; |
|
|
|
import com.epmet.enums.AttentionTypeEnum; |
|
|
|
import com.epmet.enums.ChannelEnum; |
|
|
|
import com.epmet.excel.ImportEpidemicSpecialAttention; |
|
|
|
import com.epmet.excel.error.EpidemicSpecialAttentionErrorModel; |
|
|
|
import com.epmet.feign.EpmetCommonServiceOpenFeignClient; |
|
|
|
import com.epmet.feign.OssFeignClient; |
|
|
|
import com.epmet.service.IcEpidemicSpecialAttentionService; |
|
|
|
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.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.util.*; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -38,8 +70,14 @@ import java.util.stream.Collectors; |
|
|
|
* @since v1.0.0 2022-03-28 |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
@Slf4j |
|
|
|
public class IcEpidemicSpecialAttentionServiceImpl extends BaseServiceImpl<IcEpidemicSpecialAttentionDao, IcEpidemicSpecialAttentionEntity> implements IcEpidemicSpecialAttentionService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient; |
|
|
|
@Autowired |
|
|
|
private OssFeignClient ossFeignClient; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<IcEpidemicSpecialAttentionDTO> page(Map<String, Object> params) { |
|
|
|
IPage<IcEpidemicSpecialAttentionEntity> page = baseDao.selectPage( |
|
|
@ -106,7 +144,7 @@ public class IcEpidemicSpecialAttentionServiceImpl extends BaseServiceImpl<IcEpi |
|
|
|
throw new EpmetException("未查询到工作人员信息"+formDTO.getUserId()); |
|
|
|
} |
|
|
|
formDTO.setOrgId(staffInfo.getAgencyId()); |
|
|
|
// 关注类型,核酸检测:2,疫苗接种:1
|
|
|
|
// 关注类型,核酸检测:2,疫苗接种:1,行程上报:0
|
|
|
|
if (formDTO.getAttentionType().equals(NumConstant.ONE)){ |
|
|
|
if (formDTO.isPage()){ |
|
|
|
PageInfo<VaccinationListResultDTO> pageInfo = PageHelper.startPage(formDTO.getPageNo(), formDTO.getPageSize()).doSelectPageInfo(() -> baseDao.vaccinationList(formDTO)); |
|
|
@ -214,6 +252,148 @@ public class IcEpidemicSpecialAttentionServiceImpl extends BaseServiceImpl<IcEpi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Desc: 【疫苗接种关注名单,核酸检测关注名单】导入 |
|
|
|
* @param tokenDto |
|
|
|
* @param inputStream |
|
|
|
* @param attentionType |
|
|
|
* @param taskId |
|
|
|
* @author zxc |
|
|
|
* @date 2022/3/29 15:35 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Async |
|
|
|
public void importFile(TokenDto tokenDto, InputStream inputStream, Integer attentionType, String taskId) { |
|
|
|
List<EpidemicSpecialAttentionErrorModel> errorInfo = new ArrayList<>(); |
|
|
|
|
|
|
|
try { |
|
|
|
List<ImportEpidemicSpecialAttention> list = ExcelPoiUtils.importExcel(inputStream, 0,1,ImportEpidemicSpecialAttention.class); |
|
|
|
if (CollectionUtils.isEmpty(list)){ |
|
|
|
closeTask(taskId,tokenDto.getUserId(), ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL,""); |
|
|
|
return; |
|
|
|
} |
|
|
|
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId()); |
|
|
|
if (null == staffInfo){ |
|
|
|
throw new EpmetException("未查询到工作人员信息"+tokenDto.getUserId()); |
|
|
|
} |
|
|
|
AgencyInfoCache agencyInfo = CustomerOrgRedis.getAgencyInfo(staffInfo.getAgencyId()); |
|
|
|
if (null == agencyInfo){ |
|
|
|
throw new EpmetException("未查询到组织信息"+staffInfo.getAgencyId()); |
|
|
|
} |
|
|
|
for (int i = 0; i < list.size(); i++) { |
|
|
|
list.get(i).setNum(i+1); |
|
|
|
list.get(i).setAttentionType(attentionType); |
|
|
|
list.get(i).setChannel(getChannel(list.get(i).getChannelString())); |
|
|
|
if (StringUtils.isBlank(list.get(i).getName()) && !list.get(i).getAddStatus()){ |
|
|
|
errorInfo.add(getErrorInfo(list.get(i), "姓名不能为空",i+1)); |
|
|
|
list.get(i).setAddStatus(true); |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(list.get(i).getIdCard()) && !list.get(i).getAddStatus()){ |
|
|
|
errorInfo.add(getErrorInfo(list.get(i), "身份证号不能为空",i+1)); |
|
|
|
list.get(i).setAddStatus(true); |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(list.get(i).getMobile()) && !list.get(i).getAddStatus()){ |
|
|
|
errorInfo.add(getErrorInfo(list.get(i), "电话不能为空",i+1)); |
|
|
|
list.get(i).setAddStatus(true); |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
Map<String, Long> groupByIdCard = list.stream().collect(Collectors.groupingBy(ImportEpidemicSpecialAttention::getIdCard, Collectors.counting())); |
|
|
|
groupByIdCard.forEach((idCard,count) -> { |
|
|
|
if (Integer.valueOf(count.toString()).compareTo(1) != 0){ |
|
|
|
for (ImportEpidemicSpecialAttention i : list) { |
|
|
|
if (idCard.equals(i.getIdCard()) && !i.getAddStatus()){ |
|
|
|
errorInfo.add(getErrorInfo(i,"数据重复",i.getNum())); |
|
|
|
i.setAddStatus(true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
List<String> idCards = list.stream().map(m -> m.getIdCard()).collect(Collectors.toList()); |
|
|
|
List<String> existList = baseDao.getExistList(attentionType, idCards); |
|
|
|
if (CollectionUtils.isNotEmpty(existList)){ |
|
|
|
for (String s : existList) { |
|
|
|
for (int i = NumConstant.ZERO; i < list.size(); i++) { |
|
|
|
if (s.equals(list.get(i).getIdCard()) && !list.get(i).getAddStatus()){ |
|
|
|
errorInfo.add(getErrorInfo(list.get(i),"数据已存在",list.get(i).getNum())); |
|
|
|
list.get(i).setAddStatus(true); |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Map<Boolean, List<ImportEpidemicSpecialAttention>> groupByStatus = list.stream().collect(Collectors.groupingBy(ImportEpidemicSpecialAttention::getAddStatus)); |
|
|
|
List<ImportEpidemicSpecialAttention> needInsert = groupByStatus.get(false); |
|
|
|
if (CollectionUtils.isNotEmpty(needInsert)){ |
|
|
|
List<IcEpidemicSpecialAttentionEntity> entities = ConvertUtils.sourceToTarget(needInsert, IcEpidemicSpecialAttentionEntity.class); |
|
|
|
entities.forEach(e -> { |
|
|
|
e.setIsAttention(NumConstant.ONE); |
|
|
|
e.setOrgId(agencyInfo.getId()); |
|
|
|
e.setPid(agencyInfo.getPid()); |
|
|
|
e.setPids(agencyInfo.getPids()); |
|
|
|
e.setCustomerId(tokenDto.getCustomerId()); |
|
|
|
}); |
|
|
|
insertBatch(entities); |
|
|
|
} |
|
|
|
if (CollectionUtils.isNotEmpty(errorInfo)){ |
|
|
|
String url = importOssUpload(errorInfo, EpidemicSpecialAttentionErrorModel.class); |
|
|
|
closeTask(taskId,tokenDto.getUserId(),ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL,url); |
|
|
|
}else { |
|
|
|
closeTask(taskId,tokenDto.getUserId(),ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS,""); |
|
|
|
} |
|
|
|
}catch (Exception e){ |
|
|
|
log.error(e.getMessage()); |
|
|
|
closeTask(taskId,tokenDto.getUserId(),ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL,""); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public List<String> getChannel(String channelString){ |
|
|
|
List<String> result = new ArrayList<>(); |
|
|
|
if (StringUtils.isBlank(channelString)){ |
|
|
|
return result; |
|
|
|
} |
|
|
|
String[] split = channelString.split(","); |
|
|
|
for (String s : split) { |
|
|
|
result.add(ChannelEnum.getKeyByValue(s)); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Desc: 关闭任务 |
|
|
|
* @param taskId |
|
|
|
* @param userId |
|
|
|
* @param status |
|
|
|
* @param url |
|
|
|
* @author zxc |
|
|
|
* @date 2022/3/30 09:05 |
|
|
|
*/ |
|
|
|
public void closeTask(String taskId,String userId,String status,String url){ |
|
|
|
ImportTaskCommonFormDTO input = new ImportTaskCommonFormDTO(); |
|
|
|
input.setOperatorId(userId); |
|
|
|
input.setTaskId(taskId); |
|
|
|
input.setProcessStatus(status); |
|
|
|
input.setResultDescFilePath(url); |
|
|
|
commonServiceOpenFeignClient.finishImportTask(input); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Desc: 构造错误信息 |
|
|
|
* @param dto |
|
|
|
* @param info |
|
|
|
* @param num |
|
|
|
* @author zxc |
|
|
|
* @date 2022/3/29 17:17 |
|
|
|
*/ |
|
|
|
public EpidemicSpecialAttentionErrorModel getErrorInfo(ImportEpidemicSpecialAttention dto,String info,Integer num){ |
|
|
|
EpidemicSpecialAttentionErrorModel result = ConvertUtils.sourceToTarget(dto, EpidemicSpecialAttentionErrorModel.class); |
|
|
|
result.setErrorMsg(info); |
|
|
|
result.setNum(num); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 传入身份证集合,返回已经关注的身份证号列表 |
|
|
|
* |
|
|
@ -229,4 +409,50 @@ public class IcEpidemicSpecialAttentionServiceImpl extends BaseServiceImpl<IcEpi |
|
|
|
return baseDao.getIdCardList(customerId,idCardSet,NumConstant.TWO); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Desc: 文件上传并返回url |
|
|
|
* @param errorRows |
|
|
|
* @param tClass |
|
|
|
* @author zxc |
|
|
|
* @date 2022/3/30 09:16 |
|
|
|
*/ |
|
|
|
public <T> String importOssUpload(Collection<?> errorRows, Class<T> 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<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上传结果描述文件失败"); |
|
|
|
return null; |
|
|
|
} |
|
|
|
return uploadResult.getData().getUrl(); |
|
|
|
} |
|
|
|
|
|
|
|
} |