|
|
@ -1,28 +1,33 @@ |
|
|
|
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.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
|
|
|
import com.epmet.commons.mybatis.enums.DelFlagEnum; |
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; |
|
|
|
import com.epmet.commons.tools.enums.DictTypeEnum; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.feign.ResultDataResolver; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.redis.common.CustomerOrgRedis; |
|
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
|
import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache; |
|
|
|
import com.epmet.commons.tools.redis.common.bean.GridInfoCache; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
|
import com.epmet.commons.tools.utils.FileUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
|
import com.epmet.commons.tools.utils.*; |
|
|
|
import com.epmet.constant.IcResiUserConstant; |
|
|
|
import com.epmet.constants.ImportTaskConstants; |
|
|
|
import com.epmet.dao.IcDangerAreaDao; |
|
|
|
import com.epmet.dao.IcTripReportRecordDao; |
|
|
|
import com.epmet.dao.UserBaseInfoDao; |
|
|
|
import com.epmet.dto.IcEpidemicSpecialAttentionDTO; |
|
|
@ -30,9 +35,13 @@ import com.epmet.dto.IcTripReportRecordDTO; |
|
|
|
import com.epmet.dto.form.*; |
|
|
|
import com.epmet.dto.result.TripListDTO; |
|
|
|
import com.epmet.dto.result.UploadImgResultDTO; |
|
|
|
import com.epmet.entity.IcDangerAreaEntity; |
|
|
|
import com.epmet.entity.IcTripReportRecordEntity; |
|
|
|
import com.epmet.excel.IcPsTripReportRecordExcel; |
|
|
|
import com.epmet.excel.data.IcTripReportExcelData; |
|
|
|
import com.epmet.excel.error.IcPsTripReportRecordErrorExcel; |
|
|
|
import com.epmet.excel.handler.IcTripReportExcelImportListener; |
|
|
|
import com.epmet.feign.EpmetAdminOpenFeignClient; |
|
|
|
import com.epmet.feign.EpmetCommonServiceOpenFeignClient; |
|
|
|
import com.epmet.feign.OssFeignClient; |
|
|
|
import com.epmet.service.IcEpidemicSpecialAttentionService; |
|
|
@ -49,17 +58,21 @@ 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 javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.nio.file.Path; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.atomic.AtomicBoolean; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -83,6 +96,10 @@ public class IcTripReportRecordServiceImpl extends BaseServiceImpl<IcTripReportR |
|
|
|
private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient; |
|
|
|
@Autowired |
|
|
|
private OssFeignClient ossFeignClient; |
|
|
|
@Autowired |
|
|
|
private EpmetAdminOpenFeignClient adminOpenFeignClient; |
|
|
|
@Autowired |
|
|
|
private IcDangerAreaDao icDangerAreaDao; |
|
|
|
|
|
|
|
/** |
|
|
|
* pc: 行程上报-列表 |
|
|
@ -466,4 +483,228 @@ public class IcTripReportRecordServiceImpl extends BaseServiceImpl<IcTripReportR |
|
|
|
} |
|
|
|
return list.get(NumConstant.ZERO); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 磐石-行程上报-导入excel |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Async |
|
|
|
@Override |
|
|
|
public void psExecAsyncExcelImport(TokenDto tokenDto, HttpServletResponse response, InputStream inputStream, String taskId) { |
|
|
|
try { |
|
|
|
log.info("磐石街道行程上报导入,子线程开始执行"); |
|
|
|
//异常数据集合
|
|
|
|
List<IcPsTripReportRecordErrorExcel> fileList = new ArrayList<>(); |
|
|
|
IcPsTripReportRecordErrorExcel excel = null; |
|
|
|
//1.读取Excel数据
|
|
|
|
ExcelImportResult<IcPsTripReportRecordExcel> testExcelImportResult = ExcelPoiUtils.importExcel1(inputStream, 0, 3, IcPsTripReportRecordExcel.class); |
|
|
|
//2.存在错误行数据时存入错误数据集合中
|
|
|
|
if (CollectionUtils.isNotEmpty(testExcelImportResult.getFailList())) { |
|
|
|
for (IcPsTripReportRecordExcel entity : testExcelImportResult.getFailList()) { |
|
|
|
//打印失败的行 和失败的信息
|
|
|
|
log.warn("第{}行,{}", entity.getRowNum(), entity.getErrorMsg()); |
|
|
|
excel = new IcPsTripReportRecordErrorExcel(); |
|
|
|
excel.setName(entity.getName()); |
|
|
|
excel.setIdCard(entity.getIdCard()); |
|
|
|
excel.setPresentAddress(entity.getPresentAddress()); |
|
|
|
excel.setMobile(entity.getMobile()); |
|
|
|
excel.setErrorInfo(entity.getErrorMsg()); |
|
|
|
fileList.add(excel); |
|
|
|
} |
|
|
|
} |
|
|
|
//3.正确行数据集合
|
|
|
|
List<IcPsTripReportRecordExcel> list = testExcelImportResult.getList(); |
|
|
|
if (CollectionUtils.isNotEmpty(list)) { |
|
|
|
//3-1.校验数据值,把填写不对的数据剔除
|
|
|
|
Iterator<IcPsTripReportRecordExcel> iterator = list.iterator(); |
|
|
|
while (iterator.hasNext()) { |
|
|
|
AtomicBoolean bl = new AtomicBoolean(false); |
|
|
|
StringBuffer errMsg = new StringBuffer(""); |
|
|
|
IcPsTripReportRecordExcel obj = iterator.next(); |
|
|
|
//返回方式为其他时需要填写"其他返回方式"
|
|
|
|
if (CollectionUtils.isEmpty(obj.getTraffic()) || |
|
|
|
("其他".equals(obj.getTraffic().get(0).getTrafficType()) && StringUtils.isBlank(obj.getTraffic().get(0).getTrafficTypeExplain()))) { |
|
|
|
errMsg.append("返回方式为其他时,请补充“其他返回方式”;"); |
|
|
|
bl.set(true); |
|
|
|
} |
|
|
|
if (bl.get()) { |
|
|
|
excel = new IcPsTripReportRecordErrorExcel(); |
|
|
|
excel.setName(obj.getName()); |
|
|
|
excel.setIdCard(obj.getIdCard()); |
|
|
|
excel.setPresentAddress(obj.getPresentAddress()); |
|
|
|
excel.setMobile(obj.getMobile()); |
|
|
|
excel.setErrorInfo(errMsg.toString()); |
|
|
|
fileList.add(excel); |
|
|
|
iterator.remove(); |
|
|
|
} |
|
|
|
} |
|
|
|
//3-2.获取需要的字典表数据
|
|
|
|
//交通方式
|
|
|
|
Result<Map<String, String>> trafficTypeMap = adminOpenFeignClient.dictMap(DictTypeEnum.TRAFFIC_TYPE.getCode()); |
|
|
|
//7天内旅居史情况
|
|
|
|
Result<Map<String, String>> sojournHistoryMap = adminOpenFeignClient.dictMap(DictTypeEnum.SOJOURN_HISTORY.getCode()); |
|
|
|
//隔离状态
|
|
|
|
Result<Map<String, String>> isolateTypeMap = adminOpenFeignClient.dictMap(DictTypeEnum.ISOLATE_TYPE.getCode()); |
|
|
|
//行程记录类型
|
|
|
|
Result<Map<String, String>> tripDataTypeMap = adminOpenFeignClient.dictMap(DictTypeEnum.TRIP_DATA_TYPE.getCode()); |
|
|
|
//获取当前登录用户所属组织id
|
|
|
|
CustomerStaffInfoCacheResult staffInfo = queryCurrentStaff(tokenDto.getCustomerId(), tokenDto.getUserId()); |
|
|
|
//风险地区数据
|
|
|
|
LambdaQueryWrapper<IcDangerAreaEntity> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
wrapper.eq(IcDangerAreaEntity::getCustomerId, tokenDto.getCustomerId()); |
|
|
|
wrapper.eq(IcDangerAreaEntity::getDelFlag, DelFlagEnum.NORMAL.value()); |
|
|
|
List<IcDangerAreaEntity> areaList = icDangerAreaDao.selectList(wrapper); |
|
|
|
Map<String, String> map1 = areaList.stream().collect(Collectors.toMap(IcDangerAreaEntity::getDistrict, IcDangerAreaEntity::getDangerLevel)); |
|
|
|
Map<String, String> map2 = areaList.stream().collect(Collectors.toMap(IcDangerAreaEntity::getCity, IcDangerAreaEntity::getDangerLevel)); |
|
|
|
Map<String, String> map3 = areaList.stream().collect(Collectors.toMap(IcDangerAreaEntity::getProvince, IcDangerAreaEntity::getDangerLevel)); |
|
|
|
|
|
|
|
list.forEach(l -> { |
|
|
|
//3-3.数据赋值
|
|
|
|
AtomicBoolean bl = new AtomicBoolean(false); |
|
|
|
StringBuffer errMsg = new StringBuffer(""); |
|
|
|
IcTripReportRecordEntity e = ConvertUtils.sourceToTarget(l, IcTripReportRecordEntity.class); |
|
|
|
e.setCustomerId(tokenDto.getCustomerId()); |
|
|
|
e.setAgencyId(staffInfo.getAgencyId()); |
|
|
|
e.setPids(staffInfo.getAgencyPIds()); |
|
|
|
e.setUserType(IcResiUserConstant.USER_TYPE_IMPORT); |
|
|
|
if (!CollectionUtils.isEmpty(l.getSource())) { |
|
|
|
e.setSourceAddress(l.getSource().get(0).getSourceAddress()); |
|
|
|
e.setSourceDetailAddress(l.getSource().get(0).getSourceDetailAddress()); |
|
|
|
} |
|
|
|
if (!CollectionUtils.isEmpty(l.getPresent())) { |
|
|
|
e.setPresentAddress(l.getPresent().get(0).getPresentAddress()); |
|
|
|
e.setDetailAddress(l.getPresent().get(0).getDetailAddress()); |
|
|
|
} |
|
|
|
if (!CollectionUtils.isEmpty(l.getTraffic()) && trafficTypeMap.getData().containsKey(l.getTraffic().get(0).getTrafficType())) { |
|
|
|
e.setTrafficType(trafficTypeMap.getData().get(l.getTraffic().get(0).getTrafficType())); |
|
|
|
e.setTrafficTypeExplain(l.getTraffic().get(0).getTrafficTypeExplain()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(l.getSojournHistory())) { |
|
|
|
e.setSojournHistory(sojournHistoryMap.getData().get(l.getSojournHistory())); |
|
|
|
} else { |
|
|
|
String[] str = e.getSourceAddress().split("-"); |
|
|
|
if (str.length < 3) { |
|
|
|
bl.set(true); |
|
|
|
errMsg.append("数据不完整,‘来源地’信息填写格式错误;"); |
|
|
|
} |
|
|
|
e.setSojournHistory("4"); |
|
|
|
if (map1.containsKey(str[2])) { |
|
|
|
e.setSojournHistory(map1.get(str[2]).equals("2") ? "1" : ("1".equals(map1.get(str[2])) ? "2" : ("0".equals(map1.get(str[2])) ? "3" : "4"))); |
|
|
|
} |
|
|
|
if (map2.containsKey(str[1])) { |
|
|
|
e.setSojournHistory(map2.get(str[1]).equals("2") ? "1" : ("1".equals(map2.get(str[1])) ? "2" : ("0".equals(map2.get(str[1])) ? "3" : "4"))); |
|
|
|
} |
|
|
|
if (map3.containsKey(str[0])) { |
|
|
|
e.setSojournHistory(map3.get(str[0]).equals("2") ? "1" : ("1".equals(map3.get(str[0])) ? "2" : ("0".equals(map3.get(str[0])) ? "3" : "4"))); |
|
|
|
} |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(l.getIsolateType())) { |
|
|
|
e.setIsolateType(isolateTypeMap.getData().get(l.getIsolateType())); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(l.getTripDataType())) { |
|
|
|
e.setTripDataType(tripDataTypeMap.getData().get(l.getTripDataType())); |
|
|
|
} |
|
|
|
e.setIsArriveCheck("是".equals(l.getIsArriveCheck()) ? "1" : "0"); |
|
|
|
e.setIsArrive("是".equals(l.getIsArrive()) ? "1" : "0"); |
|
|
|
//必要字段没值的
|
|
|
|
if (StringUtils.isEmpty(e.getSourceAddress()) || StringUtils.isEmpty(e.getPresentAddress()) |
|
|
|
|| StringUtils.isEmpty(e.getTrafficType())) { |
|
|
|
errMsg.append("数据不完整,请检查‘来源地’、‘在曹居住地点’、‘返回方式’信息是否填写完整;"); |
|
|
|
bl.set(true); |
|
|
|
} |
|
|
|
if (bl.get()) { |
|
|
|
IcPsTripReportRecordErrorExcel el = new IcPsTripReportRecordErrorExcel(); |
|
|
|
el.setName(l.getName()); |
|
|
|
el.setIdCard(l.getIdCard()); |
|
|
|
el.setPresentAddress(l.getPresentAddress()); |
|
|
|
el.setMobile(l.getMobile()); |
|
|
|
el.setErrorInfo(errMsg.toString()); |
|
|
|
fileList.add(el); |
|
|
|
return; |
|
|
|
} |
|
|
|
//3-4.保存数据
|
|
|
|
baseDao.insert(e); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
//4.错误数据生成文件,修改导入任务状态
|
|
|
|
String url = erroeImport(fileList); |
|
|
|
upImportTask(url, taskId, tokenDto.getUserId(), true); |
|
|
|
} catch (Exception e) { |
|
|
|
String errorMsg = ExceptionUtils.getErrorStackTrace(e); |
|
|
|
log.error("【行程上报数据导入】程序错误:{}", errorMsg); |
|
|
|
upImportTask(null, taskId, tokenDto.getUserId(), false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author sun |
|
|
|
* @Description 行程上报数据导入,错误数据生成导入失败文件存到阿里云,修改导入任务为已结束 |
|
|
|
**/ |
|
|
|
private String erroeImport(List<IcPsTripReportRecordErrorExcel> fileList) throws IOException { |
|
|
|
String url = ""; |
|
|
|
//1.有错误数据则生成错误数据存放文件传到阿里云服务
|
|
|
|
if (!org.springframework.util.CollectionUtils.isEmpty(fileList)) { |
|
|
|
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("导入失败的数据列表", "导入失败的数据列表"), |
|
|
|
IcPsTripReportRecordErrorExcel.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上传结果描述文件失败"); |
|
|
|
} |
|
|
|
url = uploadResult.getData().getUrl(); |
|
|
|
} |
|
|
|
return url; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author sun |
|
|
|
* @Description 行程上报数据导入修改导入任务状态 |
|
|
|
**/ |
|
|
|
private void upImportTask(String url, String importTaskId, String staffId, Boolean status) { |
|
|
|
//2.更新导入任务数据
|
|
|
|
ImportTaskCommonFormDTO importTaskForm = new ImportTaskCommonFormDTO(); |
|
|
|
importTaskForm.setOperatorId(staffId); |
|
|
|
importTaskForm.setBizType(ImportTaskConstants.PS_BIZ_TYPE_IC_TRIP_REPORT); |
|
|
|
importTaskForm.setTaskId(importTaskId); |
|
|
|
importTaskForm.setResultDescFilePath(url); |
|
|
|
if (status && StringUtils.isBlank(url)) { |
|
|
|
importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS); |
|
|
|
} else { |
|
|
|
importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL); |
|
|
|
importTaskForm.setResultDesc("行程上报数据导入存在程序错误"); |
|
|
|
} |
|
|
|
Result result = commonServiceOpenFeignClient.finishImportTask(importTaskForm); |
|
|
|
if (!result.success()) { |
|
|
|
throw new RenException(result.getInternalMsg()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|