|
@ -1,14 +1,22 @@
|
|
|
package com.yihu.wlyy.job;
|
|
|
|
|
|
import com.yihu.wlyy.entity.organization.Hospital;
|
|
|
import com.yihu.wlyy.repository.organization.HospitalDao;
|
|
|
import com.yihu.wlyy.entity.zydict.*;
|
|
|
import com.yihu.wlyy.repository.zydict.*;
|
|
|
import com.yihu.wlyy.service.third.jw.JwPrescriptionService;
|
|
|
import net.sf.json.JSONArray;
|
|
|
import net.sf.json.JSONObject;
|
|
|
import org.quartz.Job;
|
|
|
import org.quartz.JobExecutionContext;
|
|
|
import org.quartz.JobExecutionException;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
|
/**
|
|
|
* Created by chenweida on 2017/8/10.
|
|
@ -16,69 +24,239 @@ import java.util.List;
|
|
|
*/
|
|
|
public class ZyDictJob implements Job {
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(ZyDictJob.class);
|
|
|
@Autowired
|
|
|
private JwPrescriptionService jwPrescriptionService;
|
|
|
private ZyCommonDictDao zyCommonDictDao;
|
|
|
@Autowired
|
|
|
private ZyIvDeptDictDao zyIvDeptDictDao;
|
|
|
@Autowired
|
|
|
private ZyIvDeptStaffAllotDictDao zyIvDeptStaffAllotDictDao;
|
|
|
@Autowired
|
|
|
private ZyIvDiagnoseClassDictDao zyIvDiagnoseClassDictDao;
|
|
|
@Autowired
|
|
|
private ZyIvDiagnoseDictDao zyIvDiagnoseDictDao;
|
|
|
@Autowired
|
|
|
private ZyIvOrgPhysicAllotDictDao zyIvOrgPhysicAllotDictDao;
|
|
|
@Autowired
|
|
|
private ZyIvPhysicDictDao zyIvPhysicDictDao;
|
|
|
@Autowired
|
|
|
private ZyIvStaffDictDao zyIvStaffDictDao;
|
|
|
@Autowired
|
|
|
private ZyIvStaffRegTypeAllotDictDao zyIvStaffRegTypeAllotDictDao;
|
|
|
@Autowired
|
|
|
private HospitalDao hospitalDao;
|
|
|
private ZyIvSubjectClassDictDao zyIvSubjectClassDictDao;
|
|
|
|
|
|
@Autowired
|
|
|
private JwPrescriptionService jwPrescriptionService;
|
|
|
|
|
|
@Override
|
|
|
public void execute(JobExecutionContext context) throws JobExecutionException {
|
|
|
List<Hospital> hospitals = hospitalDao.findAllHospital();
|
|
|
//同步 zy_common_dict
|
|
|
synchronizeZyCommonDict(hospitals);
|
|
|
//同步 zy_iv_dept_dict
|
|
|
synchronizeZy_iv_dept_dict(hospitals);
|
|
|
//同步 zy_iv_dept_staff_allot_dict
|
|
|
synchronizeZy_iv_dept_staff_allot_dict(hospitals);
|
|
|
//同步 zy_iv_diagnose_class_dict
|
|
|
synchronizeZy_iv_diagnose_class_dict(hospitals);
|
|
|
//同步 zy_iv_org_physic_allot_dict
|
|
|
synchronizeZy_iv_org_physic_allot_dict(hospitals);
|
|
|
//同步 zy_iv_physic_dict
|
|
|
synchronizeZy_iv_physic_dict(hospitals);
|
|
|
//同步 zy_iv_staff_dict
|
|
|
synchronizeZ_iv_staff_dict(hospitals);
|
|
|
//同步 zy_iv_staff_reg_type_allot_dict
|
|
|
synchronizeZy_iv_staff_reg_type_allot_dict(hospitals);
|
|
|
//同步 zy_iv_subject_class_dict
|
|
|
synchronizeZy_iv_subject_class_dict(hospitals);
|
|
|
try {
|
|
|
//同步 zy_common_dict
|
|
|
synchronizeZyCommonDict();
|
|
|
//同步 zy_iv_dept_dict
|
|
|
synchronizeZy_iv_dept_dict();
|
|
|
//同步 zy_iv_dept_staff_allot_dict
|
|
|
synchronizeZy_iv_dept_staff_allot_dict();
|
|
|
//同步 zy_iv_diagnose_class_dict
|
|
|
synchronizeZy_iv_diagnose_class_dict();
|
|
|
//同步 zy_iv_org_physic_allot_dict
|
|
|
synchronizeZy_iv_org_physic_allot_dict();
|
|
|
//同步 zy_iv_physic_dict
|
|
|
synchronizeZy_iv_physic_dict();
|
|
|
//同步 zy_iv_staff_dict
|
|
|
synchronizeZ_iv_staff_dict();
|
|
|
//同步 zy_iv_staff_reg_type_allot_dict
|
|
|
synchronizeZy_iv_staff_reg_type_allot_dict();
|
|
|
//同步 zy_iv_subject_class_dict
|
|
|
synchronizeZy_iv_subject_class_dict();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
private void synchronizeZy_iv_subject_class_dict(List<Hospital> hospitals) {
|
|
|
@Transactional
|
|
|
private void synchronizeZy_iv_subject_class_dict() throws Exception {
|
|
|
String dictName = this.IV_SUBJECT_CLASS_DICT;
|
|
|
List<ZyIvSubjectClassDict> zyIvSubjectClassDicts = new ArrayList<>();
|
|
|
//得到list
|
|
|
commonGetOneDict(zyIvSubjectClassDicts, ZyIvSubjectClassDict.class, dictName);
|
|
|
if (zyIvSubjectClassDicts.size() > 0) {
|
|
|
//清空表
|
|
|
zyIvSubjectClassDictDao.deleteAll();
|
|
|
//新增数据
|
|
|
zyIvSubjectClassDictDao.save(zyIvSubjectClassDicts);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void synchronizeZy_iv_staff_reg_type_allot_dict(List<Hospital> hospitals) {
|
|
|
@Transactional
|
|
|
private void synchronizeZy_iv_staff_reg_type_allot_dict() throws Exception {
|
|
|
String dictName = this.IV_STAFF_REG_TYPE_ALLOT_DICT;
|
|
|
List<ZyIvStaffRegTypeAllotDict> zyIvStaffRegTypeAllotDicts = new ArrayList<>();
|
|
|
//得到list
|
|
|
commonGetOneDict(zyIvStaffRegTypeAllotDicts, ZyIvStaffRegTypeAllotDict.class, dictName);
|
|
|
|
|
|
//清空表
|
|
|
zyIvStaffRegTypeAllotDictDao.deleteAll();
|
|
|
//新增数据
|
|
|
zyIvStaffRegTypeAllotDictDao.save(zyIvStaffRegTypeAllotDicts);
|
|
|
}
|
|
|
|
|
|
private void synchronizeZ_iv_staff_dict(List<Hospital> hospitals) {
|
|
|
@Transactional
|
|
|
private void synchronizeZ_iv_staff_dict() throws Exception {
|
|
|
String dictName = this.IV_STAFF_DICT;
|
|
|
List<ZyIvStaffDict> zyIvStaffDicts = new ArrayList<>();
|
|
|
//得到list
|
|
|
commonGetOneDict(zyIvStaffDicts, ZyIvDeptDict.class, dictName);
|
|
|
//清空表
|
|
|
zyIvStaffDictDao.deleteAll();
|
|
|
//新增数据
|
|
|
zyIvStaffDictDao.save(zyIvStaffDicts);
|
|
|
}
|
|
|
|
|
|
private void synchronizeZy_iv_physic_dict(List<Hospital> hospitals) {
|
|
|
@Transactional
|
|
|
private void synchronizeZy_iv_physic_dict() throws Exception {
|
|
|
String dictName = this.IV_PHYSIC_DICT;
|
|
|
List<ZyIvPhysicDict> zyIvPhysicDicts = new ArrayList<>();
|
|
|
//得到list
|
|
|
commonGetOneDict(zyIvPhysicDicts, ZyIvPhysicDict.class, dictName);
|
|
|
|
|
|
//清空表
|
|
|
zyIvPhysicDictDao.deleteAll();
|
|
|
//新增数据
|
|
|
zyIvPhysicDictDao.save(zyIvPhysicDicts);
|
|
|
}
|
|
|
|
|
|
private void synchronizeZy_iv_org_physic_allot_dict(List<Hospital> hospitals) {
|
|
|
@Transactional
|
|
|
private void synchronizeZy_iv_org_physic_allot_dict() throws Exception {
|
|
|
String dictName = this.IV_ORG_PHYSIC_ALLOT_DICT;
|
|
|
List<ZyIvOrgPhysicAllotDict> zyIvOrgPhysicAllotDicts = new ArrayList<>();
|
|
|
//得到list
|
|
|
commonGetOneDict(zyIvOrgPhysicAllotDicts, ZyIvOrgPhysicAllotDict.class, dictName);
|
|
|
if (zyIvOrgPhysicAllotDicts.size() > 0) {
|
|
|
//清空表
|
|
|
zyIvOrgPhysicAllotDictDao.deleteAll();
|
|
|
//新增数据
|
|
|
zyIvOrgPhysicAllotDictDao.save(zyIvOrgPhysicAllotDicts);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void synchronizeZy_iv_diagnose_class_dict(List<Hospital> hospitals) {
|
|
|
@Transactional
|
|
|
private void synchronizeZy_iv_diagnose_class_dict() throws Exception {
|
|
|
String dictName = this.IV_DIAGNOSE_CLASS_DICT;
|
|
|
List<ZyIvDiagnoseClassDict> zIvDiagnoseClassDicts = new ArrayList<>();
|
|
|
//得到list
|
|
|
commonGetOneDict(zIvDiagnoseClassDicts, ZyIvDiagnoseClassDict.class, dictName);
|
|
|
if (zIvDiagnoseClassDicts.size() > 0) {
|
|
|
//清空表
|
|
|
zyIvDiagnoseClassDictDao.deleteAll();
|
|
|
//新增数据
|
|
|
zyIvDiagnoseClassDictDao.save(zIvDiagnoseClassDicts);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void synchronizeZy_iv_dept_staff_allot_dict(List<Hospital> hospitals) {
|
|
|
@Transactional
|
|
|
private void synchronizeZy_iv_dept_staff_allot_dict() throws Exception {
|
|
|
String dictName = this.IV_DEPT_STAFF_ALLOT_DICT;
|
|
|
List<ZyIvDeptStaffAllotDict> syIvDeptStaffAllotDictz = new ArrayList<>();
|
|
|
//得到list
|
|
|
commonGetOneDict(syIvDeptStaffAllotDictz, ZyIvDeptStaffAllotDict.class, dictName);
|
|
|
|
|
|
if (syIvDeptStaffAllotDictz.size() > 0) {
|
|
|
//清空表
|
|
|
zyIvDeptStaffAllotDictDao.deleteAll();
|
|
|
//新增数据
|
|
|
zyIvDeptStaffAllotDictDao.save(syIvDeptStaffAllotDictz);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void synchronizeZyCommonDict(List<Hospital> hospitals) {
|
|
|
@Transactional
|
|
|
private void synchronizeZyCommonDict() throws Exception {
|
|
|
String[] dictNames = new String[]{
|
|
|
this.IV_PHYSIC_FORM_DICT, this.IV_PHYSIC_INJECT_PLACE_DICT, this.IV_PHYSIC_SKIN_TEST_DICT,
|
|
|
this.IV_RATE_TYPE_DICT, this.IV_RECIPE_FREQUENCY_DICT, this.IV_RECIPE_USAGE_DICT,
|
|
|
this.IV_SEX_DICT, this.IV_PHYSIC_TOXICOLOGY_TYPE_DICT, this.IV_MEASURE_UNIT_DICT,
|
|
|
this.IV_DEPT_TYPE_DICT};
|
|
|
List<ZyCommonDict> zyCommonDictz = new ArrayList<>();
|
|
|
Boolean isFlush = true;
|
|
|
for (String dictName : dictNames) {
|
|
|
String json = null;
|
|
|
try {
|
|
|
//调用智业的接口得到字典
|
|
|
json = jwPrescriptionService.getDictForI(dictName);
|
|
|
JSONObject returnJson = JSONObject.fromObject(json);
|
|
|
if (returnJson.getInt("status") != 200) {
|
|
|
throw new Exception("zy dict error status not 200");
|
|
|
}
|
|
|
if (returnJson.containsKey("data")) {
|
|
|
JSONArray dataJSONArray = returnJson.getJSONObject("data").getJSONArray("returnData");
|
|
|
ZyCommonDict[] zyCommonDictArrays = (ZyCommonDict[]) JSONArray.toArray(dataJSONArray, ZyCommonDict.class);
|
|
|
zyCommonDictz.addAll(Arrays.asList(zyCommonDictArrays));
|
|
|
} else {
|
|
|
throw new Exception("zy dict error no contain data");
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
isFlush = false; //设置状态不能更新
|
|
|
logger.error("dictName:" + dictName);
|
|
|
logger.error("returnJson:" + json);
|
|
|
logger.error(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
//判断是否可以更新
|
|
|
if (isFlush) {
|
|
|
// 判断返回的数据是否大于0
|
|
|
if (zyCommonDictz.size() > 0) {
|
|
|
//清空表
|
|
|
zyCommonDictDao.deleteAll();
|
|
|
//新增数据
|
|
|
zyCommonDictDao.save(zyCommonDictz);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
|
private void synchronizeZy_iv_dept_dict() throws Exception {
|
|
|
String dictName = this.IV_DEPT_DICT;
|
|
|
List<ZyIvDeptDict> zyIvDeptDicts = new ArrayList<>();
|
|
|
//得到list
|
|
|
commonGetOneDict(zyIvDeptDicts, ZyIvDeptDict.class, dictName);
|
|
|
if (zyIvDeptDicts.size() > 0) {
|
|
|
//清空表
|
|
|
zyIvDeptDictDao.deleteAll();
|
|
|
//新增数据
|
|
|
zyIvDeptDictDao.save(zyIvDeptDicts);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void synchronizeZy_iv_dept_dict(List<Hospital> hospitals) {
|
|
|
/**
|
|
|
* 得到单个字典
|
|
|
*
|
|
|
* @param tList
|
|
|
* @param clazz class
|
|
|
* @param dictName 字典名称
|
|
|
*/
|
|
|
private void commonGetOneDict(List tList, Class clazz, String dictName) {
|
|
|
|
|
|
String json = null;
|
|
|
try {
|
|
|
//调用智业的接口得到字典
|
|
|
json = jwPrescriptionService.getDictForI(dictName);
|
|
|
JSONObject returnJson = JSONObject.fromObject(json);
|
|
|
if (returnJson.getInt("status") != 200) {
|
|
|
throw new Exception("zy dict error status not 200");
|
|
|
}
|
|
|
if (returnJson.containsKey("data")) {
|
|
|
JSONArray dataJSONArray = returnJson.getJSONObject("data").getJSONArray("returnData");
|
|
|
tList.addAll(Arrays.asList(JSONArray.toArray(dataJSONArray, clazz)));
|
|
|
} else {
|
|
|
throw new Exception("zy dict error no contain data");
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
logger.error("dictName:" + dictName);
|
|
|
logger.error("returnJson:" + json);
|
|
|
logger.error(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
@ -104,7 +282,9 @@ public class ZyDictJob implements Job {
|
|
|
public static final String IV_STAFF_REG_TYPE_ALLOT_DICT = " IV_STAFF_REG_TYPE_ALLOT_DICT";//("员工挂号类型配置字典", "IV_STAFF_REG_TYPE_ALLOT_DICT"),
|
|
|
public static final String IV_DEPT_STAFF_ALLOT_DICT = " IV_DEPT_STAFF_ALLOT_DICT";//("科室员工配置字典", "IV_DEPT_STAFF_ALLOT_DICT");
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 字典表的枚举类
|
|
|
*/
|
|
|
public enum TableName {
|
|
|
|
|
|
zy_common_dict("通用字典", "zy_common_dict"),
|
|
@ -141,6 +321,7 @@ public class ZyDictJob implements Job {
|
|
|
public void setDict(String dict) {
|
|
|
this.dict = dict;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|