From 0474c4c651779de825b4dd0a9641c9c501a2e4e4 Mon Sep 17 00:00:00 2001 From: zhangly Date: Fri, 29 Jan 2021 13:38:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8C=BB=E7=94=9F=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E9=80=BB=E8=BE=91=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stc/sict/theme/hphy/model/HpDocInfo.java | 6 +- .../sict/theme/hphy/schedule/RefreshJob.java | 146 +++++++++--------- .../theme/hphy/service/HpDocInfoService.java | 2 + .../service/impl/HpDocInfoServiceImpl.java | 9 ++ .../main/resources/mapper/HpDocInfoMapper.xml | 3 +- 5 files changed, 87 insertions(+), 79 deletions(-) diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/model/HpDocInfo.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/model/HpDocInfo.java index ffe08fa..e02c07d 100644 --- a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/model/HpDocInfo.java +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/model/HpDocInfo.java @@ -18,6 +18,8 @@ import java.io.Serializable; @EqualsAndHashCode(callSuper = true) public class HpDocInfo extends Model { @TableId + @ApiModelProperty(hidden = false, value = "id") + private Long id; @ApiModelProperty(hidden = false, value = "医生资源代码") private String resourceCode; @ApiModelProperty(hidden = false, value = "医院代码") @@ -50,6 +52,8 @@ public class HpDocInfo extends Model { private String doctSpecialty; @ApiModelProperty(hidden = false, value = "展示次序") private String indexNo; + @ApiModelProperty(hidden = false, value = "是否有资源(0有,1无)") + private String isResource; /** @@ -59,6 +63,6 @@ public class HpDocInfo extends Model { */ @Override protected Serializable pkVal() { - return this.resourceCode; + return this.id; } } \ No newline at end of file diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/schedule/RefreshJob.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/schedule/RefreshJob.java index 6c8d217..1e454a6 100644 --- a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/schedule/RefreshJob.java +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/schedule/RefreshJob.java @@ -45,11 +45,11 @@ public class RefreshJob { * 每月一日0点 更新医院信息 */ @Scheduled(cron = "0 0 0 1 * ?") - public void updateHosp(){ + public void updateHosp() { HosInfo hosInfo = new HosInfo(); List list = WanDaHttpUtil.getHospitalInfo(hosInfo); - if (CollectionUtil.isEmpty(list)){ + if (CollectionUtil.isEmpty(list)) { return; } @@ -61,26 +61,13 @@ public class RefreshJob { } } - private void saveOrUpdateHospital(HpHosInfo hpHosInfo){ - try { - if (hpHosInfoService.hospitalExist(hpHosInfo.getHosOrgCode())){ - hpHosInfoService.updateById(hpHosInfo); - }else { - hpHosInfoService.save(hpHosInfo); - } - }catch (Exception e){ - log.error("医院保存出错:{}", hpHosInfo); - log.error(e.getMessage(), e); - } - } - /** - * 每周一1点 同步科室信息 + * 每月一1点 同步科室信息 */ - @Scheduled(cron = "0 0 1 ? * 1") - public void updateDept(){ + @Scheduled(cron = "0 0 1 1 * ?") + public void updateDept() { List hospitals = hpHosInfoService.list(); - if (CollectionUtil.isEmpty(hospitals)){ + if (CollectionUtil.isEmpty(hospitals)) { return; } @@ -94,9 +81,60 @@ public class RefreshJob { } } - private void saveOrUpdateTopDept(String hosOrgCode){ + /** + * 每周一 2点 更新医生信息 + * + * 1、调用接口获取医生列表 + * 2、删除现有医生信息 + * 3、插入新的医生信息 + */ + @Scheduled(cron = "0 0 2 ? * 1") + public void updateDocInfo() { + List list = hpHosInfoService.list(); + + if (CollectionUtil.isEmpty(list)) { + return; + } + + MapperFactory factory = new DefaultMapperFactory.Builder().build(); + for (HpHosInfo hpHosInfo : list) { + saveDoctor(hpHosInfo.getHosOrgCode(), factory); + } + } + + + private void saveDoctor(String hosOrgCode, MapperFactory factory) { + List doctInfos = WanDaHttpUtil.getDoctInfo(new DeptInfo(hosOrgCode)); + + if (CollectionUtil.isEmpty(doctInfos)) { + return; + } + + List docInfos = factory.getMapperFacade().mapAsList(doctInfos, HpDocInfo.class); + try { + docInfoService.saveDoctor(docInfos, hosOrgCode); + }catch (Exception e){ + log.error("医院 {} 医生信息保存出错", hosOrgCode); + log.error(e.getMessage(), e); + } + } + + private void saveOrUpdateHospital(HpHosInfo hpHosInfo) { + try { + if (hpHosInfoService.hospitalExist(hpHosInfo.getHosOrgCode())) { + hpHosInfoService.updateById(hpHosInfo); + } else { + hpHosInfoService.save(hpHosInfo); + } + } catch (Exception e) { + log.error("医院保存出错:{}", hpHosInfo); + log.error(e.getMessage(), e); + } + } + + private void saveOrUpdateTopDept(String hosOrgCode) { List deptInfos = WanDaHttpUtil.getDeptInfoTop(new HosInfo(hosOrgCode)); - if (CollectionUtil.isEmpty(deptInfos)){ + if (CollectionUtil.isEmpty(deptInfos)) { return; } @@ -106,7 +144,7 @@ public class RefreshJob { } } - private void saveOrUpdateTopDept(HpDeptInfo hpDeptInfo){ + private void saveOrUpdateTopDept(HpDeptInfo hpDeptInfo) { try { HpDeptInfo deptInfo = deptInfoService.getOne( new LambdaQueryWrapper() @@ -114,13 +152,13 @@ public class RefreshJob { .eq(HpDeptInfo::getOneDeptCode, hpDeptInfo.getOneDeptCode()) .eq(HpDeptInfo::getDeptLevel, TOP_DEPT) ); - if (deptInfo != null){ + if (deptInfo != null) { hpDeptInfo.setId(deptInfo.getId()); deptInfoService.updateById(hpDeptInfo); - }else { + } else { deptInfoService.save(hpDeptInfo); } - }catch (Exception e){ + } catch (Exception e) { log.error("一级科室保存失败:{}", hpDeptInfo); log.error(e.getMessage(), e); } @@ -128,7 +166,7 @@ public class RefreshJob { private void saveOrUpdateTwoDept(String hosOrgCode, MapperFactory factory) { List deptInfos = WanDaHttpUtil.getDeptInfoTwo(new DeptInfo(hosOrgCode)); - if (CollectionUtil.isEmpty(deptInfos)){ + if (CollectionUtil.isEmpty(deptInfos)) { return; } @@ -139,7 +177,7 @@ public class RefreshJob { } } - private void saveOrUpdateTwoDept(HpDeptInfo hpDeptInfo){ + private void saveOrUpdateTwoDept(HpDeptInfo hpDeptInfo) { try { HpDeptInfo deptInfo = deptInfoService.getOne( new LambdaQueryWrapper() @@ -147,65 +185,19 @@ public class RefreshJob { .eq(HpDeptInfo::getDeptCode, hpDeptInfo.getDeptCode()) .eq(HpDeptInfo::getDeptLevel, TWO_DEPT) ); - if (deptInfo != null){ + if (deptInfo != null) { hpDeptInfo.setId(deptInfo.getId()); deptInfoService.updateById(hpDeptInfo); - }else { + } else { deptInfoService.save(hpDeptInfo); } - }catch (Exception e){ + } catch (Exception e) { log.error("二级科室保存失败:{}", hpDeptInfo); log.error(e.getMessage(), e); } } - - /** - * 每周一 2点 更新医生信息 - */ - @Scheduled(cron = "0 0 2 ? * 1") - public void updateDocInfo(){ - List list = hpHosInfoService.list(); - - if (CollectionUtil.isEmpty(list)){ - return; - } - - MapperFactory factory = new DefaultMapperFactory.Builder().build(); - for (HpHosInfo hpHosInfo : list) { - saveOrUpdateDoctor(hpHosInfo.getHosOrgCode(), factory); - } - - } - - private void saveOrUpdateDoctor(String hosOrgCode, MapperFactory factory){ - List doctInfos = WanDaHttpUtil.getDoctInfo(new DeptInfo(hosOrgCode)); - - if (CollectionUtil.isEmpty(doctInfos)){ - return; - } - - List docInfos = factory.getMapperFacade().mapAsList(doctInfos, HpDocInfo.class); - - for (HpDocInfo docInfo : docInfos) { - saveOrUpdateDoctor(docInfo); - } - } - - private void saveOrUpdateDoctor(HpDocInfo docInfo){ - try { - if (docInfoService.doctorExist(docInfo.getResourceCode())){ - docInfoService.updateById(docInfo); - }else { - docInfoService.save(docInfo); - } - }catch (Exception e){ - log.error("医生信息保存出错:{}", docInfo); - log.error(e.getMessage(), e); - } - } - - private List cloneTopDept(List deptInfos){ + private List cloneTopDept(List deptInfos) { List hpDeptInfos = new ArrayList<>(); for (DeptInfo deptInfo : deptInfos) { HpDeptInfo hpDeptInfo = new HpDeptInfo(); diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/service/HpDocInfoService.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/service/HpDocInfoService.java index a8d6bec..5575289 100644 --- a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/service/HpDocInfoService.java +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/service/HpDocInfoService.java @@ -24,4 +24,6 @@ public interface HpDocInfoService extends IService { boolean doctorExist(String resourceCode); List getRecommendList(HphyGuideRecord guide, List pythonList); + + void saveDoctor(List docInfos, String hosOrgCode); } \ No newline at end of file diff --git a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/service/impl/HpDocInfoServiceImpl.java b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/service/impl/HpDocInfoServiceImpl.java index 54446f4..0f9bcfd 100644 --- a/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/service/impl/HpDocInfoServiceImpl.java +++ b/smart-health-modules/theme-schema/src/main/java/cn/sh/stc/sict/theme/hphy/service/impl/HpDocInfoServiceImpl.java @@ -12,6 +12,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.Comparator; @@ -70,4 +71,12 @@ public class HpDocInfoServiceImpl extends ServiceImpl docInfos, String hosOrgCode) { + this.remove(new LambdaQueryWrapper().eq(HpDocInfo::getHosOrgCode, hosOrgCode)); + this.saveBatch(docInfos); + } } \ No newline at end of file diff --git a/smart-health-modules/theme-schema/src/main/resources/mapper/HpDocInfoMapper.xml b/smart-health-modules/theme-schema/src/main/resources/mapper/HpDocInfoMapper.xml index b63dbe9..6cf49cc 100644 --- a/smart-health-modules/theme-schema/src/main/resources/mapper/HpDocInfoMapper.xml +++ b/smart-health-modules/theme-schema/src/main/resources/mapper/HpDocInfoMapper.xml @@ -3,6 +3,7 @@ + @@ -22,5 +23,5 @@ - resource_code, hos_org_code, one_dept_code, dept_code, hos_name, one_dept_name, dept_name, resource_name, doct_tile, person_type, person_id, doct_img, doct_sex, doct_info, doct_specialty, index_no + id, resource_code, hos_org_code, one_dept_code, dept_code, hos_name, one_dept_name, dept_name, resource_name, doct_tile, person_type, person_id, doct_img, doct_sex, doct_info, doct_specialty, index_no \ No newline at end of file -- 2.22.0