@ -10,21 +10,25 @@ 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.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.IcResiUserDao ;
import com.epmet.dao.IcVaccineDao ;
import com.epmet.dao.IcVaccineRelationDao ;
import com.epmet.dto.IcNatDTO ;
import com.epmet.dto.IcVaccineDTO ;
import com.epmet.dto.form.ImportTaskCommonFormDTO ;
import com.epmet.dto.form.VaccineListFormDTO ;
import com.epmet.dto.form.* ;
import com.epmet.dto.result.IcVaccineListResultDTO ;
import com.epmet.dto.result.LoginUserDetailsResultDTO ;
import com.epmet.dto.result.UploadImgResultDTO ;
import com.epmet.dto.result.VaccineListDTO ;
import com.epmet.entity.IcNatEntity ;
import com.epmet.entity.IcResiUserEntity ;
import com.epmet.entity.IcVaccineEntity ;
import com.epmet.entity.IcVaccineRelationEntity ;
@ -33,6 +37,7 @@ import com.epmet.excel.data.IcVaccineImportExcelData;
import com.epmet.excel.handler.IcVaccineExcelImportListener ;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient ;
import com.epmet.feign.OssFeignClient ;
import com.epmet.service.IcNoticeService ;
import com.epmet.service.IcVaccineService ;
import com.epmet.service.UserService ;
import com.epmet.utils.ImportTaskUtils ;
@ -77,6 +82,8 @@ public class IcVaccineServiceImpl extends BaseServiceImpl<IcVaccineDao, IcVaccin
private IcResiUserDao icResiUserDao ;
@Autowired
private UserService userService ;
@Autowired
private IcNoticeService icNoticeService ;
/ * *
* @Author sun
@ -394,6 +401,7 @@ public class IcVaccineServiceImpl extends BaseServiceImpl<IcVaccineDao, IcVaccin
LambdaQueryWrapper < IcResiUserEntity > query = new LambdaQueryWrapper ( ) ;
query . eq ( IcResiUserEntity : : getCustomerId , customerId ) ;
query . eq ( IcResiUserEntity : : getIdCard , idCard ) ;
query . eq ( IcResiUserEntity : : getStatus , NumConstant . ZERO_STR ) ;
if ( StringUtils . isNotBlank ( pids ) ) {
query . likeRight ( IcResiUserEntity : : getPids , pids ) ;
}
@ -475,4 +483,85 @@ public class IcVaccineServiceImpl extends BaseServiceImpl<IcVaccineDao, IcVaccin
return ConvertUtils . sourceToTarget ( entity , IcVaccineDTO . class ) ;
}
@Override
public void add ( AddIcVaccineFormDTO formDTO ) {
//0.先根据身份证号和接种时间校验数据是否存在
IcVaccineDTO icVaccineDTO = baseDao . getVaccineDTO ( formDTO . getCustomerId ( ) , null , formDTO . getIdCard ( ) , DateUtils . format ( formDTO . getInoculateTime ( ) , DateUtils . DATE_TIME_PATTERN_END_WITH_MINUTE ) ) ;
if ( null ! = icVaccineDTO ) {
throw new RenException ( EpmetErrorCode . IC_VACCINE . getCode ( ) , EpmetErrorCode . IC_VACCINE . 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 ( StringUtils . isNotBlank ( formDTO . getUserId ( ) ) ) {
entity . setIsResiUser ( "1" ) ;
}
insert ( entity ) ;
//3.疫苗记录关系表新增与组织的关系数据
IcVaccineRelationEntity relationEntity = ConvertUtils . sourceToTarget ( formDTO , IcVaccineRelationEntity . class ) ;
relationEntity . setIcVaccineId ( entity . getId ( ) ) ;
relationEntity . setPids ( StringUtils . isNotBlank ( agencyInfo . getPids ( ) ) ? agencyInfo . getPids ( ) + ":" + formDTO . getAgencyId ( ) : formDTO . getAgencyId ( ) ) ;
icVaccineRelationDao . 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 ( "1" ) ;
dto . setContent ( formDTO . getContent ( ) ) ;
dto . setStaffId ( formDTO . getStaffId ( ) ) ;
icNoticeService . sendNotice ( dto ) ;
}
}
@Override
public void edit ( AddIcVaccineFormDTO formDTO ) {
//0.先根据身份证号和接种时间校验除当前数据是否还存在相同数据
IcVaccineDTO icVaccineDTO = baseDao . getVaccineDTO ( formDTO . getCustomerId ( ) , formDTO . getVaccineId ( ) , formDTO . getIdCard ( ) , DateUtils . format ( formDTO . getInoculateTime ( ) , DateUtils . DATE_TIME_PATTERN_END_WITH_MINUTE ) ) ;
if ( null ! = icVaccineDTO ) {
throw new RenException ( EpmetErrorCode . IC_VACCINE . getCode ( ) , EpmetErrorCode . IC_VACCINE . getMsg ( ) ) ;
}
//1.更新核酸记录基础信息表数据
IcVaccineEntity entity = ConvertUtils . sourceToTarget ( formDTO , IcVaccineEntity . class ) ;
entity . setId ( formDTO . getVaccineId ( ) ) ;
if ( ! updateById ( entity ) ) {
log . error ( String . format ( "数据修改失败,核酸记录Id->%s" , formDTO . getVaccineId ( ) ) ) ;
throw new EpmetException ( EpmetErrorCode . EPMET_COMMON_OPERATION_FAIL . getCode ( ) , "疫苗接种记录信息修改失败" ) ;
}
//修改只涉及到基础信息的修改 不会修改关系数据 关系表不涉及更新
//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 ( "1" ) ;
dto . setContent ( formDTO . getContent ( ) ) ;
dto . setStaffId ( formDTO . getStaffId ( ) ) ;
icNoticeService . sendNotice ( dto ) ;
}
}
@Override
public void del ( IcVaccineFormDTO formDTO ) {
//1.确定删除则需要删除基础数据以及所有可能存在的关系数据,物理删除业务数据
if ( baseDao . delById ( formDTO . getVaccineId ( ) ) < NumConstant . ONE ) {
log . error ( String . format ( "数据删除失败,疫苗接种记录Id->%s" , formDTO . getVaccineId ( ) ) ) ;
throw new EpmetException ( EpmetErrorCode . EPMET_COMMON_OPERATION_FAIL . getCode ( ) , "数据删除失败" ) ;
}
//关系数据删除
icVaccineRelationDao . delRelation ( formDTO . getVaccineId ( ) , null ) ;
}
}