|  |  | @ -1,22 +1,66 @@ | 
			
		
	
		
			
				
					|  |  |  | package com.epmet.service.impl; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
			
		
	
		
			
				
					|  |  |  | import com.baomidou.mybatisplus.core.metadata.IPage; | 
			
		
	
		
			
				
					|  |  |  | import com.alibaba.excel.EasyExcel; | 
			
		
	
		
			
				
					|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
			
		
	
		
			
				
					|  |  |  | import com.baomidou.mybatisplus.core.toolkit.StringUtils; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.AppClientConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.NumConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.exception.EpmetErrorCode; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.exception.EpmetException; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.exception.ExceptionUtils; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.exception.RenException; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.feign.ResultDataResolver; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.page.PageData; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.ConvertUtils; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.FieldConstant; | 
			
		
	
		
			
				
					|  |  |  | 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.utils.*; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.constants.ImportTaskConstants; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dao.IcNatRelationDao; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dao.IcResiUserDao; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dao.IcVaccineDao; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.IcVaccineDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dao.UserBaseInfoDao; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.IcNatDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.IcNoticeDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.form.AddIcNatFormDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.form.ImportTaskCommonFormDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.form.MyNatListFormDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.form.SendNoticeFormDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.result.*; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.entity.IcNatRelationEntity; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.entity.IcResiUserEntity; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.entity.IcVaccineEntity; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.excel.data.IcNatImportExcelData; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.excel.handler.IcNatExcelImportListener; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.excel.handler.IcVaccineExcelImportListener; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.feign.EpmetCommonServiceOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.feign.EpmetUserOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.feign.OssFeignClient; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.service.IcNoticeService; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.service.IcVaccineService; | 
			
		
	
		
			
				
					|  |  |  | import org.apache.commons.lang3.StringUtils; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.service.UserService; | 
			
		
	
		
			
				
					|  |  |  | 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.http.entity.ContentType; | 
			
		
	
		
			
				
					|  |  |  | 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.util.Arrays; | 
			
		
	
		
			
				
					|  |  |  | import java.util.List; | 
			
		
	
		
			
				
					|  |  |  | import java.util.Map; | 
			
		
	
		
			
				
					|  |  |  | import java.io.IOException; | 
			
		
	
		
			
				
					|  |  |  | import java.io.OutputStream; | 
			
		
	
		
			
				
					|  |  |  | import java.nio.file.Files; | 
			
		
	
		
			
				
					|  |  |  | import java.nio.file.Path; | 
			
		
	
		
			
				
					|  |  |  | import java.util.*; | 
			
		
	
		
			
				
					|  |  |  | import java.util.stream.Collectors; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | /** | 
			
		
	
		
			
				
					|  |  |  |  * 疫苗接种记录 | 
			
		
	
	
		
			
				
					|  |  | @ -24,59 +68,568 @@ import java.util.Map; | 
			
		
	
		
			
				
					|  |  |  |  * @author generator generator@elink-cn.com | 
			
		
	
		
			
				
					|  |  |  |  * @since v1.0.0 2022-04-06 | 
			
		
	
		
			
				
					|  |  |  |  */ | 
			
		
	
		
			
				
					|  |  |  | @Slf4j | 
			
		
	
		
			
				
					|  |  |  | @Service | 
			
		
	
		
			
				
					|  |  |  | public class IcVaccineServiceImpl extends BaseServiceImpl<IcVaccineDao, IcVaccineEntity> implements IcVaccineService { | 
			
		
	
		
			
				
					|  |  |  | public class IcVaccineServiceImpl extends BaseServiceImpl<IcVaccineDao, IcVaccineEntity> implements IcVaccineService, ResultDataResolver { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private EpmetUserOpenFeignClient epmetUserOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private IcNoticeService icNoticeService; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private OssFeignClient ossFeignClient; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private UserBaseInfoDao userBaseInfoDao; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private IcNatRelationDao icNatRelationDao; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private IcResiUserDao icResiUserDao; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private UserService userService; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * @Author sun | 
			
		
	
		
			
				
					|  |  |  |      * @Description 核酸检测-上报核酸记录 | 
			
		
	
		
			
				
					|  |  |  |      **/ | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public PageData<IcVaccineDTO> page(Map<String, Object> params) { | 
			
		
	
		
			
				
					|  |  |  |         IPage<IcVaccineEntity> page = baseDao.selectPage( | 
			
		
	
		
			
				
					|  |  |  |                 getPage(params, FieldConstant.CREATED_TIME, false), | 
			
		
	
		
			
				
					|  |  |  |                 getWrapper(params) | 
			
		
	
		
			
				
					|  |  |  |         ); | 
			
		
	
		
			
				
					|  |  |  |         return getPageData(page, IcVaccineDTO.class); | 
			
		
	
		
			
				
					|  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
			
				
					|  |  |  |     public void add(AddIcNatFormDTO formDTO) { | 
			
		
	
		
			
				
					|  |  |  |         //0.先根据身份证号和检查时间以及检测结果校验数据是否存在
 | 
			
		
	
		
			
				
					|  |  |  |         IcNatDTO icNatDTO = baseDao.getNatDTO(formDTO.getCustomerId(), null, formDTO.getIdCard(), DateUtils.format(formDTO.getNatTime(), DateUtils.DATE_TIME_PATTERN_END_WITH_MINUTE), null); | 
			
		
	
		
			
				
					|  |  |  |         //按身份证号核酸时间存在记录的 核酸结果相同的提示已存在相同记录核酸结果不同的提示已存在去修改【业务要求的】
 | 
			
		
	
		
			
				
					|  |  |  |         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())) { | 
			
		
	
		
			
				
					|  |  |  |             throw new RenException(EpmetErrorCode.IC_NAT.getCode(), EpmetErrorCode.IC_NAT.getMsg()); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         //1.获取所填居民所属组织缓存信息
 | 
			
		
	
		
			
				
					|  |  |  |         AgencyInfoCache agencyInfo = CustomerOrgRedis.getAgencyInfo(formDTO.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |         if (null == agencyInfo) { | 
			
		
	
		
			
				
					|  |  |  |             throw new RenException(String.format("获取组织缓存信息失败%s", formDTO.getAgencyId())); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         //2.新增核酸基础信息数据
 | 
			
		
	
		
			
				
					|  |  |  |         IcVaccineEntity entity = ConvertUtils.sourceToTarget(formDTO, IcVaccineEntity.class); | 
			
		
	
		
			
				
					|  |  |  |         if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(formDTO.getUserId())) { | 
			
		
	
		
			
				
					|  |  |  |             entity.setIsResiUser("1"); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         insert(entity); | 
			
		
	
		
			
				
					|  |  |  |         //3.核酸记录关系表新增与组织的关系数据
 | 
			
		
	
		
			
				
					|  |  |  |         IcNatRelationEntity relationEntity = ConvertUtils.sourceToTarget(formDTO, IcNatRelationEntity.class); | 
			
		
	
		
			
				
					|  |  |  |         relationEntity.setIcNatId(entity.getId()); | 
			
		
	
		
			
				
					|  |  |  |         relationEntity.setPids(com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(agencyInfo.getPids()) ? agencyInfo.getPids() + ":" + formDTO.getAgencyId() : formDTO.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |         icNatRelationDao.insert(relationEntity); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         //3.新增通知表信息
 | 
			
		
	
		
			
				
					|  |  |  |         if (formDTO.getChannel().size() > NumConstant.ZERO) { | 
			
		
	
		
			
				
					|  |  |  |             SendNoticeFormDTO dto = new SendNoticeFormDTO(); | 
			
		
	
		
			
				
					|  |  |  |             List<SendNoticeFormDTO.UserListBean> userList = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |             userList.add(ConvertUtils.sourceToTarget(formDTO, SendNoticeFormDTO.UserListBean.class)); | 
			
		
	
		
			
				
					|  |  |  |             dto.setCustomerId(formDTO.getCustomerId()); | 
			
		
	
		
			
				
					|  |  |  |             dto.setUserList(userList); | 
			
		
	
		
			
				
					|  |  |  |             dto.setChannel(formDTO.getChannel()); | 
			
		
	
		
			
				
					|  |  |  |             dto.setOrigin("2"); | 
			
		
	
		
			
				
					|  |  |  |             dto.setContent(formDTO.getContent()); | 
			
		
	
		
			
				
					|  |  |  |             dto.setStaffId(formDTO.getStaffId()); | 
			
		
	
		
			
				
					|  |  |  |             icNoticeService.sendNotice(dto); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * @Author sun | 
			
		
	
		
			
				
					|  |  |  |      * @Description 核酸检测-居民端我的上报 | 
			
		
	
		
			
				
					|  |  |  |      **/ | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public List<IcVaccineDTO> list(Map<String, Object> params) { | 
			
		
	
		
			
				
					|  |  |  |         List<IcVaccineEntity> entityList = baseDao.selectList(getWrapper(params)); | 
			
		
	
		
			
				
					|  |  |  |     public List<MyNatListResultDTO> myNatList(MyNatListFormDTO formDTO) { | 
			
		
	
		
			
				
					|  |  |  |         //1.根据token信息查询居民身份证号
 | 
			
		
	
		
			
				
					|  |  |  |         UserBaseInfoResultDTO dto = userBaseInfoDao.selectListByUserIdList(formDTO.getUserId()); | 
			
		
	
		
			
				
					|  |  |  |         if (null != dto) { | 
			
		
	
		
			
				
					|  |  |  |             formDTO.setIdCard(dto.getIdNum()); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         //2.查询当前人员创建的或该身份证号录入的核算检测数据(居民端录入、数字平台录入、数字平台导入、数字平台同步的)
 | 
			
		
	
		
			
				
					|  |  |  |         List<MyNatListResultDTO> resultList = baseDao.getMyNatList(formDTO); | 
			
		
	
		
			
				
					|  |  |  |         return resultList; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * @Author sun | 
			
		
	
		
			
				
					|  |  |  |      * @Description 【核酸】本组织及下级核酸检测信息列表 | 
			
		
	
		
			
				
					|  |  |  |      * | 
			
		
	
		
			
				
					|  |  |  |      * @return*/ | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public PageData<NatListResultDTO> natList(MyNatListFormDTO formDTO) { | 
			
		
	
		
			
				
					|  |  |  |         //1.根据是查询客户数据还是本辖区数据走不同逻辑
 | 
			
		
	
		
			
				
					|  |  |  |         if ("current".equals(formDTO.getOrgType())) { | 
			
		
	
		
			
				
					|  |  |  |             //本辖区数据
 | 
			
		
	
		
			
				
					|  |  |  |             //2.获取工作人员缓存信息
 | 
			
		
	
		
			
				
					|  |  |  |             CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(formDTO.getCustomerId(), formDTO.getUserId()); | 
			
		
	
		
			
				
					|  |  |  |             if (null == staffInfo) { | 
			
		
	
		
			
				
					|  |  |  |                 throw new EpmetException(String.format("查询工作人员%s缓存信息失败...", formDTO.getUserId())); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             formDTO.setAgencyId(staffInfo.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |             //3.按条件查询业务数据
 | 
			
		
	
		
			
				
					|  |  |  |             PageInfo<NatListResultDTO> data = PageHelper.startPage(formDTO.getPageNo(), formDTO.getPageSize(), formDTO.getIsPage()) | 
			
		
	
		
			
				
					|  |  |  |                     .doSelectPageInfo(() -> baseDao.getNatList(formDTO)); | 
			
		
	
		
			
				
					|  |  |  |             return new PageData(data.getList(), data.getTotal()); | 
			
		
	
		
			
				
					|  |  |  |         } else if ("all".equals(formDTO.getOrgType())) { | 
			
		
	
		
			
				
					|  |  |  |             //客户下数据
 | 
			
		
	
		
			
				
					|  |  |  |             PageInfo<NatListResultDTO> data = PageHelper.startPage(formDTO.getPageNo(), formDTO.getPageSize(), formDTO.getIsPage()) | 
			
		
	
		
			
				
					|  |  |  |                     .doSelectPageInfo(() -> baseDao.getCustomerNatList(formDTO)); | 
			
		
	
		
			
				
					|  |  |  |             return new PageData(data.getList(), data.getTotal()); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         return ConvertUtils.sourceToTarget(entityList, IcVaccineDTO.class); | 
			
		
	
		
			
				
					|  |  |  |         return new PageData(new ArrayList(), 0); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     private QueryWrapper<IcVaccineEntity> getWrapper(Map<String, Object> params){ | 
			
		
	
		
			
				
					|  |  |  |         String id = (String)params.get(FieldConstant.ID_HUMP); | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * @Author sun | 
			
		
	
		
			
				
					|  |  |  |      * @Description 【核酸】核酸检测信息详情 | 
			
		
	
		
			
				
					|  |  |  |      **/ | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public IcNatDTO detail(MyNatListFormDTO formDTO) { | 
			
		
	
		
			
				
					|  |  |  |         IcNatDTO resultDTO = new IcNatDTO(); | 
			
		
	
		
			
				
					|  |  |  |         //1.查询核酸记录信息
 | 
			
		
	
		
			
				
					|  |  |  |         IcVaccineEntity entity = baseDao.selectById(formDTO.getIcNatId()); | 
			
		
	
		
			
				
					|  |  |  |         if (null == resultDTO) { | 
			
		
	
		
			
				
					|  |  |  |             return resultDTO; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         resultDTO = ConvertUtils.sourceToTarget(entity, IcNatDTO.class); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         //2.查询对应的通知记录信息
 | 
			
		
	
		
			
				
					|  |  |  |         IcNoticeDTO dto = icNoticeService.getNotice(entity.getCustomerId(), entity.getIdCard()); | 
			
		
	
		
			
				
					|  |  |  |         if (null != dto) { | 
			
		
	
		
			
				
					|  |  |  |             resultDTO.setChannel(dto.getChannelList()); | 
			
		
	
		
			
				
					|  |  |  |             resultDTO.setContent(dto.getContent()); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         return resultDTO; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         QueryWrapper<IcVaccineEntity> wrapper = new QueryWrapper<>(); | 
			
		
	
		
			
				
					|  |  |  |         wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * @Author sun | 
			
		
	
		
			
				
					|  |  |  |      * @Description 【核酸】核酸检测信息修改 | 
			
		
	
		
			
				
					|  |  |  |      **/ | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
			
				
					|  |  |  |     public void edit(AddIcNatFormDTO formDTO) { | 
			
		
	
		
			
				
					|  |  |  |         //0.先根据身份证号和检测时间以及检测结果校验除当前数据是否还存在相同数据
 | 
			
		
	
		
			
				
					|  |  |  |         IcNatDTO icNatDTO = baseDao.getNatDTO(formDTO.getCustomerId(), formDTO.getIcNatId(), formDTO.getIdCard(), DateUtils.format(formDTO.getNatTime(), DateUtils.DATE_TIME_PATTERN_END_WITH_MINUTE), formDTO.getNatResult()); | 
			
		
	
		
			
				
					|  |  |  |         if (null != icNatDTO) { | 
			
		
	
		
			
				
					|  |  |  |             throw new RenException(EpmetErrorCode.IC_NAT.getCode(), EpmetErrorCode.IC_NAT.getMsg()); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         //1.更新核酸记录基础信息表数据
 | 
			
		
	
		
			
				
					|  |  |  |         IcVaccineEntity entity = ConvertUtils.sourceToTarget(formDTO, IcVaccineEntity.class); | 
			
		
	
		
			
				
					|  |  |  |         entity.setId(formDTO.getIcNatId()); | 
			
		
	
		
			
				
					|  |  |  |         if (!updateById(entity)) { | 
			
		
	
		
			
				
					|  |  |  |             log.error(String.format("数据修改失败,核酸记录Id->%s", formDTO.getIcNatId())); | 
			
		
	
		
			
				
					|  |  |  |             throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "核酸记录修改失败"); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         //修改只涉及到基础信息的修改 不会修改关系数据 关系表不涉及更新
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         return wrapper; | 
			
		
	
		
			
				
					|  |  |  |         //3.新增通知表信息
 | 
			
		
	
		
			
				
					|  |  |  |         if (CollectionUtils.isNotEmpty(formDTO.getChannel())) { | 
			
		
	
		
			
				
					|  |  |  |             SendNoticeFormDTO dto = new SendNoticeFormDTO(); | 
			
		
	
		
			
				
					|  |  |  |             List<SendNoticeFormDTO.UserListBean> userList = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |             userList.add(ConvertUtils.sourceToTarget(formDTO, SendNoticeFormDTO.UserListBean.class)); | 
			
		
	
		
			
				
					|  |  |  |             dto.setCustomerId(formDTO.getCustomerId()); | 
			
		
	
		
			
				
					|  |  |  |             dto.setUserList(userList); | 
			
		
	
		
			
				
					|  |  |  |             dto.setChannel(formDTO.getChannel()); | 
			
		
	
		
			
				
					|  |  |  |             dto.setOrigin("2"); | 
			
		
	
		
			
				
					|  |  |  |             dto.setContent(formDTO.getContent()); | 
			
		
	
		
			
				
					|  |  |  |             dto.setStaffId(formDTO.getStaffId()); | 
			
		
	
		
			
				
					|  |  |  |             icNoticeService.sendNotice(dto); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * @Author sun | 
			
		
	
		
			
				
					|  |  |  |      * @Description 【核酸】核酸检测信息删除/取消同步 | 
			
		
	
		
			
				
					|  |  |  |      **/ | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public IcVaccineDTO get(String id) { | 
			
		
	
		
			
				
					|  |  |  |         IcVaccineEntity entity = baseDao.selectById(id); | 
			
		
	
		
			
				
					|  |  |  |         return ConvertUtils.sourceToTarget(entity, IcVaccineDTO.class); | 
			
		
	
		
			
				
					|  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
			
				
					|  |  |  |     public void del(MyNatListFormDTO formDTO) { | 
			
		
	
		
			
				
					|  |  |  |         //1.确定删除则需要删除基础数据以及所有可能存在的关系数据,物理删除业务数据
 | 
			
		
	
		
			
				
					|  |  |  |         if (baseDao.delById(formDTO.getIcNatId()) < NumConstant.ONE) { | 
			
		
	
		
			
				
					|  |  |  |             log.error(String.format("数据删除失败,核酸记录Id->%s", formDTO.getIcNatId())); | 
			
		
	
		
			
				
					|  |  |  |             throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "数据删除失败"); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         //关系数据删除
 | 
			
		
	
		
			
				
					|  |  |  |         icNatRelationDao.delRelation(formDTO.getIcNatId(), null); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * @Author sun | 
			
		
	
		
			
				
					|  |  |  |      * @Description 【核酸】核酸检测信息同步 | 
			
		
	
		
			
				
					|  |  |  |      **/ | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
			
				
					|  |  |  |     public void save(IcVaccineDTO dto) { | 
			
		
	
		
			
				
					|  |  |  |         IcVaccineEntity entity = ConvertUtils.sourceToTarget(dto, IcVaccineEntity.class); | 
			
		
	
		
			
				
					|  |  |  |         insert(entity); | 
			
		
	
		
			
				
					|  |  |  |     public void synchro(MyNatListFormDTO formDTO) { | 
			
		
	
		
			
				
					|  |  |  |         //1.检验核酸基础信息是否存在
 | 
			
		
	
		
			
				
					|  |  |  |         IcVaccineEntity entity = baseDao.selectById(formDTO.getIcNatId()); | 
			
		
	
		
			
				
					|  |  |  |         if (null == entity) { | 
			
		
	
		
			
				
					|  |  |  |             log.error(String.format("核酸记录数据不存在同步失败,核酸记录Id->%s", formDTO.getIcNatId())); | 
			
		
	
		
			
				
					|  |  |  |             throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "数据同步失败,核酸记录数据不存在"); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         //获取工作人员缓存数据
 | 
			
		
	
		
			
				
					|  |  |  |         CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(formDTO.getCustomerId(), formDTO.getUserId()); | 
			
		
	
		
			
				
					|  |  |  |         if (null == staffInfo) { | 
			
		
	
		
			
				
					|  |  |  |             throw new EpmetException(String.format("查询工作人员%s缓存信息失败...", formDTO.getUserId())); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         //2.不管是否已存在关系数据都是先删后增
 | 
			
		
	
		
			
				
					|  |  |  |         icNatRelationDao.delRelation(formDTO.getIcNatId(), staffInfo.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |         //3.新增关系数据
 | 
			
		
	
		
			
				
					|  |  |  |         IcNatRelationEntity relationEntity = new IcNatRelationEntity(); | 
			
		
	
		
			
				
					|  |  |  |         relationEntity.setCustomerId(formDTO.getCustomerId()); | 
			
		
	
		
			
				
					|  |  |  |         relationEntity.setIcNatId(formDTO.getIcNatId()); | 
			
		
	
		
			
				
					|  |  |  |         relationEntity.setAgencyId(staffInfo.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |         relationEntity.setPids(com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(staffInfo.getAgencyPIds())?staffInfo.getAgencyPIds()+":"+staffInfo.getAgencyId():staffInfo.getAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |         relationEntity.setUserType("synchro"); | 
			
		
	
		
			
				
					|  |  |  |         icNatRelationDao.insert(relationEntity); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * @Author sun | 
			
		
	
		
			
				
					|  |  |  |      * @Description 【核酸】核酸检测信息取消同步 | 
			
		
	
		
			
				
					|  |  |  |      **/ | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
			
				
					|  |  |  |     public void update(IcVaccineDTO dto) { | 
			
		
	
		
			
				
					|  |  |  |         IcVaccineEntity entity = ConvertUtils.sourceToTarget(dto, IcVaccineEntity.class); | 
			
		
	
		
			
				
					|  |  |  |         updateById(entity); | 
			
		
	
		
			
				
					|  |  |  |     public void cancelSynchro(MyNatListFormDTO formDTO) { | 
			
		
	
		
			
				
					|  |  |  |         //1.获取工作人员缓存数据
 | 
			
		
	
		
			
				
					|  |  |  |         CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(formDTO.getCustomerId(), formDTO.getUserId()); | 
			
		
	
		
			
				
					|  |  |  |         if (null == staffInfo) { | 
			
		
	
		
			
				
					|  |  |  |             throw new EpmetException(String.format("查询工作人员%s缓存信息失败...", formDTO.getUserId())); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         //1.物理删除关系数据
 | 
			
		
	
		
			
				
					|  |  |  |         if (icNatRelationDao.delRelation(formDTO.getIcNatId(), staffInfo.getAgencyId()) < NumConstant.ONE) { | 
			
		
	
		
			
				
					|  |  |  |             log.error(String.format("数据取消同步失败,核酸记录Id->%s", formDTO.getIcNatId())); | 
			
		
	
		
			
				
					|  |  |  |             throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "取消同步操作失败"); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @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); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             LoginUserDetailsResultDTO loginUserDetails = userService.getLoginUserDetails(app, client, userId); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             String agencyId = loginUserDetails.getAgencyId(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             IcNatExcelImportListener listener = new IcNatExcelImportListener(userId, agencyId, loginUserDetails.getOrgIdPath().replace(":".concat(agencyId), ""), this); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             EasyExcel.read(filePath.toFile(), IcNatImportExcelData.class, listener).headRowNumber(2).sheet(0).doRead(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             Path errorDescFile = null; | 
			
		
	
		
			
				
					|  |  |  |             String errorDesFileUrl = null; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             List<IcNatImportExcelData.RowRemarkMessage> errorRows = listener.getErrorRows(); | 
			
		
	
		
			
				
					|  |  |  |             List<IcNatImportExcelData.RowRemarkMessage> otherRows = listener.getOtherRows(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             boolean failed = errorRows.size() > 0; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             // 合并到一起写入
 | 
			
		
	
		
			
				
					|  |  |  |             errorRows.addAll(otherRows); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             // 生成并上传描述文件
 | 
			
		
	
		
			
				
					|  |  |  |             if (errorRows.size() > 0) { | 
			
		
	
		
			
				
					|  |  |  |                 try { | 
			
		
	
		
			
				
					|  |  |  |                     // 文件生成
 | 
			
		
	
		
			
				
					|  |  |  |                     Path errorDescDir = FileUtils.getAndCreateDirUnderEpmetFilesDir("ic_nat", "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, IcNatImportExcelData.RowRemarkMessage.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) { | 
			
		
	
		
			
				
					|  |  |  |                     e.printStackTrace(); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * 核酸检测信息 | 
			
		
	
		
			
				
					|  |  |  |      * | 
			
		
	
		
			
				
					|  |  |  |      * @param idCard | 
			
		
	
		
			
				
					|  |  |  |      * @Param idCard | 
			
		
	
		
			
				
					|  |  |  |      * @Return {@link List< NatListDTO >} | 
			
		
	
		
			
				
					|  |  |  |      * @Author zhaoqifeng | 
			
		
	
		
			
				
					|  |  |  |      * @Date 2022/3/29 16:29 | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public List<NatListDTO> getNatList(String customerId, String idCard) { | 
			
		
	
		
			
				
					|  |  |  |         LambdaQueryWrapper<IcVaccineEntity> wrapper = new LambdaQueryWrapper<>(); | 
			
		
	
		
			
				
					|  |  |  |         wrapper.eq(IcVaccineEntity::getCustomerId, customerId); | 
			
		
	
		
			
				
					|  |  |  |         wrapper.eq(IcVaccineEntity::getIdCard, idCard); | 
			
		
	
		
			
				
					|  |  |  |         wrapper.orderByDesc(IcVaccineEntity::getNatTime); | 
			
		
	
		
			
				
					|  |  |  |         List<IcVaccineEntity> list = baseDao.selectList(wrapper); | 
			
		
	
		
			
				
					|  |  |  |         if (CollectionUtils.isEmpty(list)) { | 
			
		
	
		
			
				
					|  |  |  |             return Collections.emptyList(); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         return list.stream().map(item -> { | 
			
		
	
		
			
				
					|  |  |  |             NatListDTO dto = new NatListDTO(); | 
			
		
	
		
			
				
					|  |  |  |             dto.setAddress(item.getNatAddress()); | 
			
		
	
		
			
				
					|  |  |  |             dto.setTestTime(DateUtils.format(item.getNatTime(), DateUtils.DATE_TIME_PATTERN_END_WITH_MINUTE)); | 
			
		
	
		
			
				
					|  |  |  |             switch (item.getNatResult()) | 
			
		
	
		
			
				
					|  |  |  |             { | 
			
		
	
		
			
				
					|  |  |  |                 case NumConstant.ZERO_STR: | 
			
		
	
		
			
				
					|  |  |  |                     dto.setResult("阴性"); | 
			
		
	
		
			
				
					|  |  |  |                     break; | 
			
		
	
		
			
				
					|  |  |  |                 case NumConstant.ONE_STR: | 
			
		
	
		
			
				
					|  |  |  |                     dto.setResult("阳性"); | 
			
		
	
		
			
				
					|  |  |  |                     break; | 
			
		
	
		
			
				
					|  |  |  |                 default: | 
			
		
	
		
			
				
					|  |  |  |                     dto.setResult("未知"); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             return dto; | 
			
		
	
		
			
				
					|  |  |  |         }).collect(Collectors.toList()); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public Integer updateIsResiFlag(String customerId, String icResiUserId) { | 
			
		
	
		
			
				
					|  |  |  |         return baseDao.updateIsResiFlag(customerId,icResiUserId); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * 批量持久化 | 
			
		
	
		
			
				
					|  |  |  |      * @param entities | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     public void batchPersist(List<IcVaccineEntity> entities, IcVaccineExcelImportListener listener) { | 
			
		
	
		
			
				
					|  |  |  |         String customerId = EpmetRequestHolder.getHeader(AppClientConstant.CUSTOMER_ID); | 
			
		
	
		
			
				
					|  |  |  |         String currentUserId = EpmetRequestHolder.getHeader(AppClientConstant.USER_ID); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         entities.forEach(e -> { | 
			
		
	
		
			
				
					|  |  |  |             try { | 
			
		
	
		
			
				
					|  |  |  |                 persisVaccine(e, customerId, currentUserId, listener); | 
			
		
	
		
			
				
					|  |  |  |             } catch (Exception exception) { | 
			
		
	
		
			
				
					|  |  |  |                 String errorMsg = ExceptionUtils.getErrorStackTrace(exception); | 
			
		
	
		
			
				
					|  |  |  |                 log.error(errorMsg); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |                 IcNatImportExcelData.RowRemarkMessage errorRow = new IcNatImportExcelData.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 | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
			
				
					|  |  |  |     public void delete(String[] ids) { | 
			
		
	
		
			
				
					|  |  |  |         // 逻辑删除(@TableLogic 注解)
 | 
			
		
	
		
			
				
					|  |  |  |         baseDao.deleteBatchIds(Arrays.asList(ids)); | 
			
		
	
		
			
				
					|  |  |  |     public void persisVaccine(IcVaccineEntity e, String customerId, String currentUserId, IcNatExcelImportListener listener) { | 
			
		
	
		
			
				
					|  |  |  |         List<IcNatImportExcelData.RowRemarkMessage> otherRows = listener.getOtherRows(); | 
			
		
	
		
			
				
					|  |  |  |         String agencyPids = listener.getCurrentAgencyPids(); | 
			
		
	
		
			
				
					|  |  |  |         String agencyId = listener.getCurrentAgencyId(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         Date natTime = e.getNatTime(); | 
			
		
	
		
			
				
					|  |  |  |         String idCard = e.getIdCard(); | 
			
		
	
		
			
				
					|  |  |  |         String name = e.getName(); | 
			
		
	
		
			
				
					|  |  |  |         String mobile = e.getMobile(); | 
			
		
	
		
			
				
					|  |  |  |         String natResult = e.getNatResult(); | 
			
		
	
		
			
				
					|  |  |  |         String natAddress = e.getNatAddress(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         //1.先看客户下有没有这个人
 | 
			
		
	
		
			
				
					|  |  |  |         IcVaccineEntity resiNat = getResiNat(customerId, idCard, natTime); | 
			
		
	
		
			
				
					|  |  |  |         if (resiNat != null && !"import".equals(resiNat.getUserType())) { | 
			
		
	
		
			
				
					|  |  |  |             // 有这个人,并且不是导入的
 | 
			
		
	
		
			
				
					|  |  |  |             String message = "已存在该次核酸检测录入记录,请到系统中修改"; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             IcNatImportExcelData.RowRemarkMessage errorRow = new IcNatImportExcelData.RowRemarkMessage(); | 
			
		
	
		
			
				
					|  |  |  |             errorRow.setName(name); | 
			
		
	
		
			
				
					|  |  |  |             errorRow.setMobile(mobile); | 
			
		
	
		
			
				
					|  |  |  |             errorRow.setIdCard(idCard); | 
			
		
	
		
			
				
					|  |  |  |             errorRow.setErrorInfo(message); | 
			
		
	
		
			
				
					|  |  |  |             otherRows.add(errorRow); | 
			
		
	
		
			
				
					|  |  |  |             return; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         if (resiNat != null) { | 
			
		
	
		
			
				
					|  |  |  |             boolean needUpdate = false; | 
			
		
	
		
			
				
					|  |  |  |             // 有这个人,也是导入的,那就要更新le
 | 
			
		
	
		
			
				
					|  |  |  |             ArrayList<String> changedFieldNames = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |             if (!name.equals(resiNat.getName())) { | 
			
		
	
		
			
				
					|  |  |  |                 changedFieldNames.add("姓名"); | 
			
		
	
		
			
				
					|  |  |  |                 resiNat.setName(name); | 
			
		
	
		
			
				
					|  |  |  |                 needUpdate = true; | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             if (!natResult.equals(resiNat.getNatResult())) { | 
			
		
	
		
			
				
					|  |  |  |                 changedFieldNames.add("检测结果"); | 
			
		
	
		
			
				
					|  |  |  |                 resiNat.setNatResult(natResult); | 
			
		
	
		
			
				
					|  |  |  |                 needUpdate = true; | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             // 检测地点和手机号先不提示,说需要提示再提示。需要考虑两个都不为空&&不相等 || 两个中一个为空一个不为空
 | 
			
		
	
		
			
				
					|  |  |  |             if ((com.baomidou.mybatisplus.core.toolkit.StringUtils.isBlank(natAddress) && com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(resiNat.getNatAddress())) | 
			
		
	
		
			
				
					|  |  |  |                     || (com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(natAddress) && com.baomidou.mybatisplus.core.toolkit.StringUtils.isBlank(resiNat.getNatAddress())) | 
			
		
	
		
			
				
					|  |  |  |                     || (com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(natAddress) && com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(resiNat.getNatAddress()) && !natAddress.equals(resiNat.getNatAddress()))) { | 
			
		
	
		
			
				
					|  |  |  |                 resiNat.setNatAddress(natAddress); | 
			
		
	
		
			
				
					|  |  |  |                 needUpdate = true; | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             if (!mobile.equals(resiNat.getMobile())) { | 
			
		
	
		
			
				
					|  |  |  |                 resiNat.setMobile(mobile); | 
			
		
	
		
			
				
					|  |  |  |                 needUpdate = true; | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             if (changedFieldNames.size() > 0) { | 
			
		
	
		
			
				
					|  |  |  |                 String fieldsStr = String.join(",", changedFieldNames); | 
			
		
	
		
			
				
					|  |  |  |                 String message = "该次核酸检测记录已存在,执行更新动作," + fieldsStr + "已成功更新"; | 
			
		
	
		
			
				
					|  |  |  |                 IcNatImportExcelData.RowRemarkMessage errorRow = new IcNatImportExcelData.RowRemarkMessage(); | 
			
		
	
		
			
				
					|  |  |  |                 errorRow.setName(name); | 
			
		
	
		
			
				
					|  |  |  |                 errorRow.setMobile(mobile); | 
			
		
	
		
			
				
					|  |  |  |                 errorRow.setIdCard(idCard); | 
			
		
	
		
			
				
					|  |  |  |                 errorRow.setErrorInfo(message); | 
			
		
	
		
			
				
					|  |  |  |                 otherRows.add(errorRow); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             if (needUpdate) { | 
			
		
	
		
			
				
					|  |  |  |                 resiNat.setUpdatedBy(currentUserId); | 
			
		
	
		
			
				
					|  |  |  |                 resiNat.setUpdatedTime(new Date()); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |                 IcResiUserEntity resi = getResi(customerId, idCard, null); | 
			
		
	
		
			
				
					|  |  |  |                 resiNat.setIsResiUser(resi != null ? "1" : "0"); | 
			
		
	
		
			
				
					|  |  |  |                 resiNat.setUserId(resi != null ? resi.getId() : ""); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |                 baseDao.updateById(resiNat); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             // 还要创建关系。只有本辖区及下级居民,才建立关系
 | 
			
		
	
		
			
				
					|  |  |  |             if (getResi(customerId, idCard, String.join(":", Arrays.asList(agencyPids, agencyId))) != null) { | 
			
		
	
		
			
				
					|  |  |  |                 createNatRelation(resiNat.getId(), listener.getCurrentAgencyId(), listener.getCurrentAgencyPids()); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             return; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         // 执行新增操作
 | 
			
		
	
		
			
				
					|  |  |  |         IcResiUserEntity resi = getResi(customerId, idCard, null); | 
			
		
	
		
			
				
					|  |  |  |         e.setIsResiUser(resi != null ? "1" : "0"); | 
			
		
	
		
			
				
					|  |  |  |         e.setUserId(resi != null ? resi.getId() : ""); | 
			
		
	
		
			
				
					|  |  |  |         e.setUserType("import"); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         baseDao.insert(e); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         // 还要创建关系。只有本辖区及下级居民,才建立关系
 | 
			
		
	
		
			
				
					|  |  |  |         if (getResi(customerId, idCard, String.join(":", Arrays.asList(agencyPids, agencyId))) != null) { | 
			
		
	
		
			
				
					|  |  |  |             createNatRelation(e.getId(), listener.getCurrentAgencyId(), listener.getCurrentAgencyPids()); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * 是否是指定条件下的居民; | 
			
		
	
		
			
				
					|  |  |  |      * 0:否 | 
			
		
	
		
			
				
					|  |  |  |      * 1:是 | 
			
		
	
		
			
				
					|  |  |  |      * @param customerId | 
			
		
	
		
			
				
					|  |  |  |      * @param idCard | 
			
		
	
		
			
				
					|  |  |  |      * @return | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     public IcResiUserEntity getResi(String customerId, String idCard, String pids) { | 
			
		
	
		
			
				
					|  |  |  |         LambdaQueryWrapper<IcResiUserEntity> query = new LambdaQueryWrapper(); | 
			
		
	
		
			
				
					|  |  |  |         query.eq(IcResiUserEntity::getCustomerId, customerId); | 
			
		
	
		
			
				
					|  |  |  |         query.eq(IcResiUserEntity::getIdCard, idCard); | 
			
		
	
		
			
				
					|  |  |  |         if (StringUtils.isNotBlank(pids)) { | 
			
		
	
		
			
				
					|  |  |  |             query.likeRight(IcResiUserEntity::getPids, pids); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         return icResiUserDao.selectOne(query); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * | 
			
		
	
		
			
				
					|  |  |  |      * @param customerId | 
			
		
	
		
			
				
					|  |  |  |      * @param idCard | 
			
		
	
		
			
				
					|  |  |  |      * @return | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     public IcVaccineEntity getResiNat(String customerId, String idCard, Date natTime) { | 
			
		
	
		
			
				
					|  |  |  |         LambdaQueryWrapper<IcVaccineEntity> query = new LambdaQueryWrapper<>(); | 
			
		
	
		
			
				
					|  |  |  |         query.eq(IcVaccineEntity::getCustomerId, customerId); | 
			
		
	
		
			
				
					|  |  |  |         query.eq(IcVaccineEntity::getIdCard, idCard); | 
			
		
	
		
			
				
					|  |  |  |         query.eq(IcVaccineEntity::getNatTime, natTime); | 
			
		
	
		
			
				
					|  |  |  |         return baseDao.selectOne(query); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * 创建nat关系 | 
			
		
	
		
			
				
					|  |  |  |      * @param natId | 
			
		
	
		
			
				
					|  |  |  |      * @param currentUserAgencyId | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     private void createNatRelation(String natId, String currentUserAgencyId, String agencyPids) { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         // 没有关系创建关系,有关系就跳过
 | 
			
		
	
		
			
				
					|  |  |  |         LambdaQueryWrapper<IcNatRelationEntity> query = new LambdaQueryWrapper<>(); | 
			
		
	
		
			
				
					|  |  |  |         query.eq(IcNatRelationEntity::getIcNatId, natId); | 
			
		
	
		
			
				
					|  |  |  |         query.eq(IcNatRelationEntity::getAgencyId, currentUserAgencyId); | 
			
		
	
		
			
				
					|  |  |  |         if (icNatRelationDao.selectCount(query) > 0) { | 
			
		
	
		
			
				
					|  |  |  |             return; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         IcNatRelationEntity relation = new IcNatRelationEntity(); | 
			
		
	
		
			
				
					|  |  |  |         relation.setAgencyId(currentUserAgencyId); | 
			
		
	
		
			
				
					|  |  |  |         relation.setPids(String.join(":", Arrays.asList(agencyPids, currentUserAgencyId))); | 
			
		
	
		
			
				
					|  |  |  |         relation.setIcNatId(natId); | 
			
		
	
		
			
				
					|  |  |  |         relation.setUserType("import"); | 
			
		
	
		
			
				
					|  |  |  |         icNatRelationDao.insert(relation); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
	
		
			
				
					|  |  | 
 |