123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396 |
- package com.yihu.wlyy.job;
- 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.
- * 每天1点同步 智业的字典数据
- */
- public class ZyDictJob implements Job {
- private Logger logger = LoggerFactory.getLogger(ZyDictJob.class);
- @Autowired
- 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 ZyIvSubjectClassDictDao zyIvSubjectClassDictDao;
- @Autowired
- private JwPrescriptionService jwPrescriptionService;
- @Override
- public void execute(JobExecutionContext context) throws JobExecutionException {
- 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();
- }
- }
- @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);
- }
- }
- @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);
- }
- @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);
- }
- @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);
- }
- @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);
- }
- }
- @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);
- }
- }
- @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);
- }
- }
- @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);
- }
- }
- /**
- * 得到单个字典
- *
- * @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());
- }
- }
- /**
- * 智业的字典
- */
- public static final String IV_MEASURE_UNIT_DICT = "IV_MEASURE_UNIT_DICT";//("计量单位字典", "IV_MEASURE_UNIT_DICT"),
- public static final String IV_PHYSIC_FORM_DICT = " IV_PHYSIC_FORM_DICT";//("药品剂型字典", "IV_PHYSIC_FORM_DICT"),
- public static final String IV_PHYSIC_INJECT_PLACE_DICT = " IV_PHYSIC_INJECT_PLACE_DICT(";//"计量单位字典", "IV_PHYSIC_INJECT_PLACE_DICT"),
- public static final String IV_PHYSIC_SKIN_TEST_DICT = " IV_PHYSIC_SKIN_TEST_DICT";//("皮试类型字典", "IV_PHYSIC_SKIN_TEST_DICT"),
- public static final String IV_RATE_TYPE_DICT = " IV_RATE_TYPE_DICT";//("费别字典", "IV_RATE_TYPE_DICT"),
- public static final String IV_RECIPE_FREQUENCY_DICT = " IV_RECIPE_FREQUENCY_DICT";//("频次字典", "IV_RECIPE_FREQUENCY_DICT"),
- public static final String IV_RECIPE_USAGE_DICT = " IV_RECIPE_USAGE_DICT";//("用药方法字典", "IV_RECIPE_USAGE_DICT"),
- public static final String IV_SEX_DICT = " IV_SEX_DICT";//("性别字典", "IV_SEX_DICT"),
- public static final String IV_PHYSIC_DICT = " IV_PHYSIC_DICT";//("药品字典", "IV_PHYSIC_DICT"),
- public static final String IV_ORG_PHYSIC_ALLOT_DICT = " IV_ORG_PHYSIC_ALLOT_DICT";//("机构药品分发字典", "IV_ORG_PHYSIC_ALLOT_DICT "),
- public static final String IV_SUBJECT_CLASS_DICT = " IV_SUBJECT_CLASS_DICT";//("科目类别字典", "IV_SUBJECT_CLASS_DICT"),
- public static final String IV_PHYSIC_TOXICOLOGY_TYPE_DICT = " IV_PHYSIC_TOXICOLOGY_TYPE_DICT";//("药品毒理分类字典", "IV_PHYSIC_TOXICOLOGY_TYPE_DICT"),
- public static final String IV_DEPT_DICT = " IV_DEPT_DICT";//("科室字典", "IV_DEPT_DICT"),
- public static final String IV_DEPT_TYPE_DICT = " IV_DEPT_TYPE_DICT";//("科室类型字典", "IV_DEPT_TYPE_DICT"),
- public static final String IV_DIAGNOSE_DICT = " IV_DIAGNOSE_DICT";//("诊断字典", "IV_DIAGNOSE_DICT"),
- public static final String IV_DIAGNOSE_CLASS_DICT = " IV_DIAGNOSE_CLASS_DICT";//("诊断类别字典", "IV_DIAGNOSE_CLASS_DICT"),
- public static final String IV_STAFF_DICT = " IV_STAFF_DICT";//("员工字典", "IV_STAFF_DICT"),
- 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"),
- zy_iv_dept_dict("科室字典", "zy_iv_dept_dict"),
- zy_iv_dept_staff_allot_dict("科室员工配置字典", "zy_iv_dept_staff_allot_dict"),
- zy_iv_diagnose_class_dict("诊断类别字典", "zy_iv_diagnose_class_dict"),
- zy_iv_diagnose_dict("诊断字典表", "zy_iv_diagnose_dict"),
- zy_iv_org_physic_allot_dict("机构药品分发字典", "zy_iv_org_physic_allot_dict"),
- zy_iv_physic_dict("药品字典", "zy_iv_physic_dict"),
- zy_iv_staff_dict("员工字典", "zy_iv_staff_dict"),
- zy_iv_staff_reg_type_allot_dict("员工挂号类型配置字典", "zy_iv_staff_reg_type_allot_dict"),
- zy_iv_subject_class_dict("科目类别字典", "zy_iv_subject_class_dict");
- TableName(String name, String dict) {
- this.name = name;
- this.dict = dict;
- }
- private String name;
- private String dict;
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getDict() {
- return dict;
- }
- public void setDict(String dict) {
- this.dict = dict;
- }
- }
- /**
- * 根据字典获取表名
- *
- * @param dictName
- * @return
- */
- public String getTableName(String dictName) {
- switch (dictName) {
- case IV_PHYSIC_FORM_DICT: {
- return TableName.zy_common_dict.getDict();
- }
- case IV_PHYSIC_INJECT_PLACE_DICT: {
- return TableName.zy_common_dict.getDict();
- }
- case IV_PHYSIC_SKIN_TEST_DICT: {
- return TableName.zy_common_dict.getDict();
- }
- case IV_RATE_TYPE_DICT: {
- return TableName.zy_common_dict.getDict();
- }
- case IV_RECIPE_FREQUENCY_DICT: {
- return TableName.zy_common_dict.getDict();
- }
- case IV_RECIPE_USAGE_DICT: {
- return TableName.zy_common_dict.getDict();
- }
- case IV_SEX_DICT: {
- return TableName.zy_common_dict.getDict();
- }
- case IV_PHYSIC_TOXICOLOGY_TYPE_DICT: {
- return TableName.zy_common_dict.getDict();
- }
- case IV_MEASURE_UNIT_DICT: {
- return TableName.zy_common_dict.getDict();
- }
- case IV_DEPT_TYPE_DICT: {
- return TableName.zy_common_dict.getDict();
- }
- case IV_PHYSIC_DICT: {
- return TableName.zy_iv_physic_dict.getDict();
- }
- case IV_ORG_PHYSIC_ALLOT_DICT: {
- return TableName.zy_iv_org_physic_allot_dict.getDict();
- }
- case IV_SUBJECT_CLASS_DICT: {
- return TableName.zy_iv_subject_class_dict.getDict();
- }
- case IV_DIAGNOSE_DICT: {
- return TableName.zy_iv_diagnose_dict.getDict();
- }
- case IV_DIAGNOSE_CLASS_DICT: {
- return TableName.zy_iv_diagnose_class_dict.getDict();
- }
- case IV_STAFF_DICT: {
- return TableName.zy_iv_staff_dict.getDict();
- }
- case IV_STAFF_REG_TYPE_ALLOT_DICT: {
- return TableName.zy_iv_staff_reg_type_allot_dict.getDict();
- }
- case IV_DEPT_STAFF_ALLOT_DICT: {
- return TableName.zy_iv_dept_staff_allot_dict.getDict();
- }
- case IV_DEPT_DICT: {
- return TableName.zy_iv_dept_dict.getDict();
- }
- }
- return "";
- }
- }
|