Commit 9164cbc6 authored by 向怀芳's avatar 向怀芳 🎱

Merge remote-tracking branch 'origin/master'

parents fedf2d0d bcf08111
...@@ -11,6 +11,7 @@ import cn.sh.stc.sict.theme.hphy.wd.DeptInfo; ...@@ -11,6 +11,7 @@ import cn.sh.stc.sict.theme.hphy.wd.DeptInfo;
import cn.sh.stc.sict.theme.hphy.wd.DoctInfo; import cn.sh.stc.sict.theme.hphy.wd.DoctInfo;
import cn.sh.stc.sict.theme.hphy.wd.HosInfo; import cn.sh.stc.sict.theme.hphy.wd.HosInfo;
import cn.sh.stc.sict.theme.hphy.wd.WanDaHttpUtil; import cn.sh.stc.sict.theme.hphy.wd.WanDaHttpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import ma.glasnost.orika.MapperFactory; import ma.glasnost.orika.MapperFactory;
...@@ -40,7 +41,10 @@ public class RefreshJob { ...@@ -40,7 +41,10 @@ public class RefreshJob {
private static final byte TOP_DEPT = 1; private static final byte TOP_DEPT = 1;
private static final byte TWO_DEPT = 2; private static final byte TWO_DEPT = 2;
@Scheduled(cron = "0 44 13 * * ?") /**
* 每月一日0点 更新医院信息
*/
@Scheduled(cron = "0 0 0 1 * ?")
public void updateHosp(){ public void updateHosp(){
HosInfo hosInfo = new HosInfo(); HosInfo hosInfo = new HosInfo();
List<HosInfo> list = WanDaHttpUtil.getHospitalInfo(hosInfo); List<HosInfo> list = WanDaHttpUtil.getHospitalInfo(hosInfo);
...@@ -70,42 +74,96 @@ public class RefreshJob { ...@@ -70,42 +74,96 @@ public class RefreshJob {
} }
} }
// @Scheduled(cron = "") /**
* 每周一1点 同步科室信息
*/
@Scheduled(cron = "0 0 1 ? * 1")
public void updateDept(){ public void updateDept(){
List<HpHosInfo> hospitals = hpHosInfoService.list(); List<HpHosInfo> hospitals = hpHosInfoService.list();
if (CollectionUtil.isEmpty(hospitals)){ if (CollectionUtil.isEmpty(hospitals)){
return; return;
} }
// TODO 获取一级科室
MapperFactory factory = new DefaultMapperFactory.Builder().build(); MapperFactory factory = new DefaultMapperFactory.Builder().build();
for (HpHosInfo hospital : hospitals) { for (HpHosInfo hospital : hospitals) {
saveOrUpdateTopDept(hospital.getHosOrgCode(), factory); // 获取一级科室
saveOrUpdateTopDept(hospital.getHosOrgCode());
// 获取二级科室
saveOrUpdateTwoDept(hospital.getHosOrgCode(), factory);
} }
// TODO 获取二级科室
} }
private void saveOrUpdateTopDept(String hosOrgCode, MapperFactory factory){ private void saveOrUpdateTopDept(String hosOrgCode){
List<DeptInfo> deptInfos = WanDaHttpUtil.getDeptInfoTop(new HosInfo(hosOrgCode)); List<DeptInfo> deptInfos = WanDaHttpUtil.getDeptInfoTop(new HosInfo(hosOrgCode));
if (CollectionUtil.isEmpty(deptInfos)){ if (CollectionUtil.isEmpty(deptInfos)){
return; return;
} }
List<HpDeptInfo> hpDeptInfos = cloneTopDept(deptInfos); List<HpDeptInfo> hpDeptInfos = cloneTopDept(deptInfos);
for (HpDeptInfo hpDeptInfo : hpDeptInfos) {
saveOrUpdateTopDept(hpDeptInfo);
}
} }
private void saveOrUpdateTopDept(HpDeptInfo hpDeptInfo){
try {
HpDeptInfo deptInfo = deptInfoService.getOne(
new LambdaQueryWrapper<HpDeptInfo>()
.eq(HpDeptInfo::getHosOrgCode, hpDeptInfo.getHosOrgCode())
.eq(HpDeptInfo::getOneDeptCode, hpDeptInfo.getOneDeptCode())
.eq(HpDeptInfo::getDeptLevel, TOP_DEPT)
);
if (deptInfo != null){
hpDeptInfo.setId(deptInfo.getId());
deptInfoService.updateById(hpDeptInfo);
}else {
deptInfoService.save(hpDeptInfo);
}
}catch (Exception e){
log.error("一级科室保存失败:{}", hpDeptInfo);
log.error(e.getMessage(), e);
}
}
private void saveOrUpdateTwoDept(String hosOrgCode, MapperFactory factory) {
List<DeptInfo> deptInfos = WanDaHttpUtil.getDeptInfoTwo(new DeptInfo(hosOrgCode));
if (CollectionUtil.isEmpty(deptInfos)){
return;
}
// @Scheduled(cron = "") List<HpDeptInfo> hpDeptInfos = factory.getMapperFacade().mapAsList(deptInfos, HpDeptInfo.class);
public void updateDeptTwo(){ for (HpDeptInfo hpDeptInfo : hpDeptInfos) {
hpDeptInfo.setDeptLevel(TWO_DEPT);
saveOrUpdateTwoDept(hpDeptInfo);
}
}
private void saveOrUpdateTwoDept(HpDeptInfo hpDeptInfo){
try {
HpDeptInfo deptInfo = deptInfoService.getOne(
new LambdaQueryWrapper<HpDeptInfo>()
.eq(HpDeptInfo::getHosOrgCode, hpDeptInfo.getHosOrgCode())
.eq(HpDeptInfo::getDeptCode, hpDeptInfo.getDeptCode())
.eq(HpDeptInfo::getDeptLevel, TWO_DEPT)
);
if (deptInfo != null){
hpDeptInfo.setId(deptInfo.getId());
deptInfoService.updateById(hpDeptInfo);
}else {
deptInfoService.save(hpDeptInfo);
}
}catch (Exception e){
log.error("二级科室保存失败:{}", hpDeptInfo);
log.error(e.getMessage(), e);
}
} }
@Scheduled(cron = "0 42 14 * * ?")
/**
* 每周一 2点 更新医生信息
*/
@Scheduled(cron = "0 0 2 ? * 1")
public void updateDocInfo(){ public void updateDocInfo(){
List<HpHosInfo> list = hpHosInfoService.list(); List<HpHosInfo> list = hpHosInfoService.list();
...@@ -143,6 +201,7 @@ public class RefreshJob { ...@@ -143,6 +201,7 @@ public class RefreshJob {
} }
}catch (Exception e){ }catch (Exception e){
log.error("医生信息保存出错:{}", docInfo); log.error("医生信息保存出错:{}", docInfo);
log.error(e.getMessage(), e);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment