|  | @ -2,18 +2,15 @@ package com.yihu.wlyy.service.system;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.yihu.wlyy.entity.dict.HealthProblemDict;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.util.DateUtil;
 | 
	
		
			
				|  |  | import net.sf.json.JSONArray;
 | 
	
		
			
				|  |  | import net.sf.json.JSONObject;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.data.redis.core.StringRedisTemplate;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.BeanPropertyRowMapper;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
	
		
			
				|  |  | import org.springframework.scheduling.annotation.Async;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | import org.thymeleaf.util.DartUtils;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import javax.annotation.PostConstruct;
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
		
			
				|  |  | import java.util.Date;
 | 
	
		
			
				|  |  | import java.util.List;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
		
			
				|  |  |  * Created by chenweida on 2017/8/9.
 | 
	
	
		
			
				|  | @ -31,6 +28,8 @@ public class Icd10DictServcie {
 | 
	
		
			
				|  |  |     private StringRedisTemplate redisTemplate;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private JdbcTemplate jdbcTemplate;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private Icd10DictServcieJob icd10DictServcieJob;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 根据icd10的 code 获取name
 | 
	
	
		
			
				|  | @ -86,69 +85,18 @@ public class Icd10DictServcie {
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         List<HealthProblemDict> healthProblemDicts = getHealthProblemDicts();
 | 
	
		
			
				|  |  |         //缓存keyIcd10
 | 
	
		
			
				|  |  |         cacheIcd10(healthProblemDicts);
 | 
	
		
			
				|  |  |         icd10DictServcieJob.cacheIcd10(healthProblemDicts);
 | 
	
		
			
				|  |  |         //缓存keyHealthProblem
 | 
	
		
			
				|  |  |         cacheHealthProblem(healthProblemDicts);
 | 
	
		
			
				|  |  |         icd10DictServcieJob.cacheHealthProblem(healthProblemDicts);
 | 
	
		
			
				|  |  |         //缓存keyHealthProblem2Dict
 | 
	
		
			
				|  |  |         cacheHealthProblem2Dict(healthProblemDicts);
 | 
	
		
			
				|  |  |         icd10DictServcieJob.cacheHealthProblem2Dict(healthProblemDicts);
 | 
	
		
			
				|  |  |         //缓存keyDict2healthProblem
 | 
	
		
			
				|  |  |         cacheDict2healthProblem(healthProblemDicts);
 | 
	
		
			
				|  |  |         icd10DictServcieJob.cacheDict2healthProblem(healthProblemDicts);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         redisTemplate.opsForValue().set(ok, DateUtil.dateToStrLong(new Date()) + "初始化完成");
 | 
	
		
			
				|  |  |         return true;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Async
 | 
	
		
			
				|  |  |     private void cacheIcd10(List<HealthProblemDict> healthProblemDicts) {
 | 
	
		
			
				|  |  |         healthProblemDicts.stream().forEach(one -> {
 | 
	
		
			
				|  |  |             String key = keyIcd10 + one.getCode();
 | 
	
		
			
				|  |  |             redisTemplate.opsForValue().set(key, one.getName());
 | 
	
		
			
				|  |  |         });
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Async
 | 
	
		
			
				|  |  |     private void cacheHealthProblem(List<HealthProblemDict> healthProblemDicts) {
 | 
	
		
			
				|  |  |         healthProblemDicts.stream().forEach(one -> {
 | 
	
		
			
				|  |  |             String key = keyHealthProblem + one.getHpcode();
 | 
	
		
			
				|  |  |             redisTemplate.opsForValue().set(key, one.getHpname());
 | 
	
		
			
				|  |  |         });
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * key是 code   value是 hpcode  1对1
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     @Async
 | 
	
		
			
				|  |  |     private void cacheDict2healthProblem(List<HealthProblemDict> healthProblemDicts) {
 | 
	
		
			
				|  |  |         healthProblemDicts.stream().forEach(one -> {
 | 
	
		
			
				|  |  |             String key = keyDict2healthProblem + one.getCode();
 | 
	
		
			
				|  |  |             JSONObject jsonObject = new JSONObject();
 | 
	
		
			
				|  |  |             jsonObject.put("key", one.getHpcode());
 | 
	
		
			
				|  |  |             jsonObject.put("value", one.getHpname());
 | 
	
		
			
				|  |  |             redisTemplate.opsForValue().set(key, jsonObject.toString());
 | 
	
		
			
				|  |  |         });
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * key是 hpcode    value是 code  1对多
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     @Async
 | 
	
		
			
				|  |  |     private void cacheHealthProblem2Dict(List<HealthProblemDict> healthProblemDicts) {
 | 
	
		
			
				|  |  |         Map<String, List<KeyValueModel>> saveMap = new HashMap<>();
 | 
	
		
			
				|  |  |         healthProblemDicts.stream().forEach(one -> {
 | 
	
		
			
				|  |  |             List<KeyValueModel> valueList = saveMap.get(one.getHpcode());
 | 
	
		
			
				|  |  |             if (valueList == null) {
 | 
	
		
			
				|  |  |                 valueList = new ArrayList<KeyValueModel>();
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             valueList.add(new KeyValueModel(one.getCode(), one.getName()));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             saveMap.put(one.getHpcode(), valueList);
 | 
	
		
			
				|  |  |         });
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         for (Map.Entry<String, List<KeyValueModel>> one : saveMap.entrySet()) {
 | 
	
		
			
				|  |  |             String key = keyHealthProblem2Dict + one.getKey();
 | 
	
		
			
				|  |  |             redisTemplate.opsForValue().set(key, JSONArray.fromObject(one.getValue()).toString());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private List<HealthProblemDict> getHealthProblemDicts() {
 | 
	
		
			
				|  |  |         String sql = "select i.*,p.code hpcode,p.`name` hpname from icd10_dict i,hp_icd10_relation hp,health_problem_dict p where i.id=hp.icd10_id and hp.hp_id=p.id";
 |