Commit 0474c4c6 authored by zhangly's avatar zhangly

更新医生信息逻辑调整

parent 53df22a7
......@@ -18,6 +18,8 @@ import java.io.Serializable;
@EqualsAndHashCode(callSuper = true)
public class HpDocInfo extends Model<HpDocInfo> {
@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<HpDocInfo> {
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<HpDocInfo> {
*/
@Override
protected Serializable pkVal() {
return this.resourceCode;
return this.id;
}
}
\ No newline at end of file
......@@ -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<HosInfo> 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<HpHosInfo> 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<HpHosInfo> 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<DoctInfo> doctInfos = WanDaHttpUtil.getDoctInfo(new DeptInfo(hosOrgCode));
if (CollectionUtil.isEmpty(doctInfos)) {
return;
}
List<HpDocInfo> 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<DeptInfo> 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<HpDeptInfo>()
......@@ -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<DeptInfo> 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<HpDeptInfo>()
......@@ -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<HpHosInfo> 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<DoctInfo> doctInfos = WanDaHttpUtil.getDoctInfo(new DeptInfo(hosOrgCode));
if (CollectionUtil.isEmpty(doctInfos)){
return;
}
List<HpDocInfo> 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<HpDeptInfo> cloneTopDept(List<DeptInfo> deptInfos){
private List<HpDeptInfo> cloneTopDept(List<DeptInfo> deptInfos) {
List<HpDeptInfo> hpDeptInfos = new ArrayList<>();
for (DeptInfo deptInfo : deptInfos) {
HpDeptInfo hpDeptInfo = new HpDeptInfo();
......
......@@ -24,4 +24,6 @@ public interface HpDocInfoService extends IService<HpDocInfo> {
boolean doctorExist(String resourceCode);
List<DoctorMatchVO> getRecommendList(HphyGuideRecord guide, List<PythonResult> pythonList);
void saveDoctor(List<HpDocInfo> docInfos, String hosOrgCode);
}
\ No newline at end of file
......@@ -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<HpDocInfoMapper, HpDocInfo
.sorted(Comparator.comparing(DoctorMatchVO::getMatchScore).reversed())
.collect(Collectors.toList());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void saveDoctor(List<HpDocInfo> docInfos, String hosOrgCode) {
this.remove(new LambdaQueryWrapper<HpDocInfo>().eq(HpDocInfo::getHosOrgCode, hosOrgCode));
this.saveBatch(docInfos);
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@
<mapper namespace="cn.sh.stc.sict.theme.hphy.dao.HpDocInfoMapper">
<resultMap type="cn.sh.stc.sict.theme.hphy.model.HpDocInfo" id="HpDocInfoMap">
<result property="id" column="id"/>
<result property="resourceCode" column="resource_code" jdbcType="VARCHAR"/>
<result property="hosOrgCode" column="hos_org_code" jdbcType="VARCHAR"/>
<result property="oneDeptCode" column="one_dept_code" jdbcType="VARCHAR"/>
......@@ -22,5 +23,5 @@
</resultMap>
<sql id="Base_Column_List">
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 </sql>
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 </sql>
</mapper>
\ No newline at end of file
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