Commit c68b7cbcdd3a8426e065939f81f36764678a1bcb
1 parent
88b6cc1c75
Exists in
master
and in
6 other branches
lyms_basicconfig 缓存配置
Showing 5 changed files with 113 additions and 62 deletions
- platform-biz-service/src/main/java/com/lyms/platform/permission/BasicConfigContainer.java
- platform-biz-service/src/main/java/com/lyms/platform/permission/service/impl/BabyPatientExtendEarServiceImpl.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/CouponController.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/platform/BaseConfigConstant.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/platform/BaseConfigUtil.java
platform-biz-service/src/main/java/com/lyms/platform/permission/BasicConfigContainer.java
View file @
c68b7cb
| 1 | +package com.lyms.platform.permission; | |
| 2 | + | |
| 3 | +import com.lyms.platform.pojo.BasicConfig; | |
| 4 | +import org.apache.commons.lang3.StringUtils; | |
| 5 | +import org.slf4j.Logger; | |
| 6 | +import org.slf4j.LoggerFactory; | |
| 7 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 8 | +import org.springframework.data.mongodb.core.MongoTemplate; | |
| 9 | +import org.springframework.data.mongodb.core.query.Criteria; | |
| 10 | +import org.springframework.data.mongodb.core.query.Query; | |
| 11 | +import org.springframework.stereotype.Component; | |
| 12 | + | |
| 13 | +import javax.annotation.PostConstruct; | |
| 14 | +import java.util.ArrayList; | |
| 15 | +import java.util.HashMap; | |
| 16 | +import java.util.List; | |
| 17 | +import java.util.Map; | |
| 18 | + | |
| 19 | +/** | |
| 20 | + * @Author: litao | |
| 21 | + * @Date: 2017/5/12 0012 14:55 | |
| 22 | + * @Version: V1.0 | |
| 23 | + */ | |
| 24 | +@Component | |
| 25 | +public class BasicConfigContainer { | |
| 26 | + | |
| 27 | + private Logger logger = LoggerFactory.getLogger(BasicConfigContainer.class); | |
| 28 | + | |
| 29 | + @Autowired | |
| 30 | + private MongoTemplate mongoTemplate; | |
| 31 | + | |
| 32 | + /** 用于存储 k-v 的数据*/ | |
| 33 | + private List<Map<String, BasicConfig>> map = new ArrayList<>(); | |
| 34 | + | |
| 35 | + /** 用于存储 parent key 相同的数据 */ | |
| 36 | + private List<Map<String, List<BasicConfig>>> parentMap = new ArrayList<>(); | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * 初始平台缓存信息 | |
| 40 | + */ | |
| 41 | + @PostConstruct | |
| 42 | + public void initCache() { | |
| 43 | + List<BasicConfig> configs = mongoTemplate.findAll(BasicConfig.class); | |
| 44 | + for (BasicConfig config : configs) { | |
| 45 | + if(StringUtils.isBlank(config.getParentId()) || !"0".equals(config.getParentId())) { | |
| 46 | + Map<String, List<BasicConfig>> tempMap = new HashMap<>(); | |
| 47 | + List<BasicConfig> childs = mongoTemplate.find(Query.query(Criteria.where("parentId").is(config.getId())), BasicConfig.class); | |
| 48 | + tempMap.put(config.getId(), childs); | |
| 49 | + parentMap.add(tempMap); | |
| 50 | + } else { | |
| 51 | + Map<String, BasicConfig> tempMap = new HashMap<>(); | |
| 52 | + tempMap.put(config.getId(), config); | |
| 53 | + map.add(tempMap); | |
| 54 | + } | |
| 55 | + } | |
| 56 | + logger.info("baseconfig 加载完成"); | |
| 57 | + } | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * 删除平台缓存信息 | |
| 61 | + */ | |
| 62 | + public void deleteCache() { | |
| 63 | + this.map.clear(); | |
| 64 | + this.parentMap.clear(); | |
| 65 | + logger.info("baseconfig 清理完成"); | |
| 66 | + } | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * 刷新缓存 | |
| 70 | + */ | |
| 71 | + public void flush() { | |
| 72 | + deleteCache(); | |
| 73 | + initCache(); | |
| 74 | + } | |
| 75 | + | |
| 76 | + /** | |
| 77 | + * 获取所有子级 | |
| 78 | + * @param parentId | |
| 79 | + * @return | |
| 80 | + */ | |
| 81 | + public List<BasicConfig> getChilds(String parentId) { | |
| 82 | + for (Map<String, List<BasicConfig>> listMap : parentMap) { | |
| 83 | + if(listMap.containsKey(parentId)) { | |
| 84 | + return listMap.get(parentId); | |
| 85 | + } | |
| 86 | + } | |
| 87 | + return null; | |
| 88 | + } | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * | |
| 92 | + * @param parentId | |
| 93 | + * @return | |
| 94 | + */ | |
| 95 | + public List<Map<String, Object>> getKvChilds(String parentId) { | |
| 96 | + return null; | |
| 97 | + } | |
| 98 | + | |
| 99 | + public BasicConfig getVal(String id){ | |
| 100 | + for (Map<String, BasicConfig> configMap : map) { | |
| 101 | + if(configMap.containsKey(id)) { | |
| 102 | + return configMap.get(id); | |
| 103 | + } | |
| 104 | + } | |
| 105 | + return null; | |
| 106 | + } | |
| 107 | +} | 
platform-biz-service/src/main/java/com/lyms/platform/permission/service/impl/BabyPatientExtendEarServiceImpl.java
View file @
c68b7cb
| ... | ... | @@ -2,6 +2,8 @@ | 
| 2 | 2 | |
| 3 | 3 | import com.lyms.platform.common.result.BaseObjectResponse; | 
| 4 | 4 | import com.lyms.platform.common.result.RespBuilder; | 
| 5 | +import com.lyms.platform.common.utils.SystemConfig; | |
| 6 | +import com.lyms.platform.permission.BasicConfigContainer; | |
| 5 | 7 | import com.lyms.platform.permission.dao.master.BabyPatientExtendEarMapper; | 
| 6 | 8 | import com.lyms.platform.permission.model.BabyPatientExtendEar; | 
| 7 | 9 | import com.lyms.platform.permission.model.BabyPatientExtendEarBirth; | 
| 8 | 10 | |
| ... | ... | @@ -21,10 +23,14 @@ | 
| 21 | 23 | @Autowired | 
| 22 | 24 | private BabyPatientExtendEarMapper earMapper; | 
| 23 | 25 | |
| 26 | + @Autowired | |
| 27 | + private BasicConfigContainer configContainer; | |
| 28 | + | |
| 24 | 29 | @Override | 
| 25 | 30 | public BaseObjectResponse insert(BabyPatientExtendEar ear, BabyPatientExtendEarBirth earBirth, | 
| 26 | 31 | BabyPatientExtendEarMother earMother, BabyPatientExtendEarFamily earFamily, Integer userId) { | 
| 27 | 32 | System.out.println("ear = [" + ear + "], earBirth = [" + earBirth + "], earMother = [" + earMother + "], earFamily = [" + earFamily + "], userId = [" + userId + "]"); | 
| 33 | + System.out.println(configContainer.getChilds(SystemConfig.CENSUS_TYPE_ID)); | |
| 28 | 34 | return RespBuilder.buildSuccess(); | 
| 29 | 35 | } | 
| 30 | 36 | 
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/CouponController.java
View file @
c68b7cb
| ... | ... | @@ -78,7 +78,6 @@ | 
| 78 | 78 | public BaseObjectResponse testUse(@PathVariable String code, @PathVariable String hospitalId, HttpServletRequest request) { | 
| 79 | 79 | LoginContext loginState = (LoginContext) request.getAttribute("loginContext"); | 
| 80 | 80 | return couponService.use(code, hospitalId, loginState.getId()); | 
| 81 | -// return couponService.use(hospitalId, code, 110); | |
| 82 | 81 | } | 
| 83 | 82 | |
| 84 | 83 | 
platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/platform/BaseConfigConstant.java
View file @
c68b7cb
platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/platform/BaseConfigUtil.java
View file @
c68b7cb
| 1 | -package com.lyms.platform.operate.web.utils.platform; | |
| 2 | - | |
| 3 | -import com.lyms.platform.pojo.BasicConfig; | |
| 4 | -import org.apache.struts.config.BaseConfig; | |
| 5 | -import org.slf4j.Logger; | |
| 6 | -import org.slf4j.LoggerFactory; | |
| 7 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 8 | -import org.springframework.data.mongodb.core.MongoTemplate; | |
| 9 | -import org.springframework.stereotype.Component; | |
| 10 | - | |
| 11 | -import javax.annotation.PostConstruct; | |
| 12 | -import java.util.ArrayList; | |
| 13 | -import java.util.List; | |
| 14 | -import java.util.Map; | |
| 15 | - | |
| 16 | -/** | |
| 17 | - * @Author: litao | |
| 18 | - * @Date: 2017/5/12 0012 14:55 | |
| 19 | - * @Version: V1.0 | |
| 20 | - */ | |
| 21 | -@Component | |
| 22 | -public class BaseConfigUtil { | |
| 23 | - | |
| 24 | - private Logger logger = LoggerFactory.getLogger(BaseConfigUtil.class); | |
| 25 | - | |
| 26 | - @Autowired | |
| 27 | - private MongoTemplate mongoTemplate; | |
| 28 | - | |
| 29 | - /** 用于存储 k-v 的数据*/ | |
| 30 | - private List<Map<String, BaseConfig>> maps = new ArrayList<>(); | |
| 31 | - | |
| 32 | - /** 用于存储 parent key 相同的数据 */ | |
| 33 | - private List<Map<String, List<BaseConfig>>> parentMaps = new ArrayList<>(); | |
| 34 | - | |
| 35 | - | |
| 36 | - /** | |
| 37 | - * 初始平台缓存信息 | |
| 38 | - */ | |
| 39 | - @PostConstruct | |
| 40 | - public void initCache() { | |
| 41 | - List<BasicConfig> configs = mongoTemplate.findAll(BasicConfig.class); | |
| 42 | - | |
| 43 | - } | |
| 44 | - | |
| 45 | - /** | |
| 46 | - * 删除平台缓存信息 | |
| 47 | - */ | |
| 48 | - public void deleteCache() { | |
| 49 | - | |
| 50 | - } | |
| 51 | - | |
| 52 | -} |