RedisLikeService.java 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. package thyyxxk.webserver.service.redislike;
  2. import com.alibaba.fastjson.JSONObject;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.springframework.stereotype.Service;
  5. import thyyxxk.webserver.dao.his.redislike.RedisLikeDao;
  6. import thyyxxk.webserver.entity.dictionary.CodeName;
  7. import thyyxxk.webserver.entity.login.UserInfo;
  8. import thyyxxk.webserver.service.externalhttp.CorpWxSrvc;
  9. import thyyxxk.webserver.utils.StringUtil;
  10. import thyyxxk.webserver.utils.TokenUtil;
  11. import java.util.HashMap;
  12. import java.util.Map;
  13. @Service
  14. @Slf4j
  15. public class RedisLikeService {
  16. public final static String SCROLLING_MESSAGES = "scrollingMessages";
  17. public final static String SYSTEM_UPDATES_MESSAGE = "systemUpdatesMessage";
  18. private final static Map<String, String> EMPLOYEE_NAME_MAP = new HashMap<>();
  19. private final static Map<String, String> DEPT_NAME_MAP = new HashMap<>();
  20. private final static Map<String, String> DEPT_AND_EMPLOYEE_NAME = new HashMap<>();
  21. private final static Map<String, String> REGION_MAP = new HashMap<>();
  22. private final static Map<String, String> WJW_ANAESTHESIA_MAP = new HashMap<>();
  23. private final static Map<String, String> WJW_DEPARTMENT_MAP = new HashMap<>();
  24. private final static Map<String, String> WJW_NATION_MAP = new HashMap<>();
  25. private final static Map<String, String> COUNTRY_MAP = new HashMap<>();
  26. private final static Map<String, UserInfo> USER_MAP = new HashMap<>();
  27. private final static Map<String, String> YB_CONTACT_RELATION_MAP = new HashMap<>();
  28. private final static Map<String, String> YB_DEPT_MAP = new HashMap<>();
  29. private final RedisLikeDao dao;
  30. private final CorpWxSrvc srvc;
  31. private final static Map<String, String> MESSAGE = new HashMap<>(2);
  32. public void setMessage(String key, String value) {
  33. MESSAGE.put(key, value);
  34. }
  35. public Map<String, String> getMessage() {
  36. return MESSAGE;
  37. }
  38. public RedisLikeService(RedisLikeDao dao, CorpWxSrvc srvc) {
  39. this.dao = dao;
  40. this.srvc = srvc;
  41. }
  42. public String getEmployeeName(String code) {
  43. if (StringUtil.invalidValue(code)) {
  44. return null;
  45. }
  46. String username = EMPLOYEE_NAME_MAP.get(code);
  47. if (null == username) {
  48. username = dao.selectEmployeeName(code);
  49. EMPLOYEE_NAME_MAP.put(code, username);
  50. }
  51. return username;
  52. }
  53. public String getDeptAndEmployeeName(String code) {
  54. if (StringUtil.invalidValue(code)) {
  55. return null;
  56. }
  57. String result = DEPT_AND_EMPLOYEE_NAME.get(code);
  58. if (null == result) {
  59. result = dao.selectDeptAndUser(code);
  60. DEPT_AND_EMPLOYEE_NAME.put(code, result);
  61. }
  62. return result;
  63. }
  64. public String getDeptName(String code) {
  65. if (StringUtil.invalidValue(code)) {
  66. return null;
  67. }
  68. String deptName = DEPT_NAME_MAP.get(code);
  69. if (null == deptName) {
  70. deptName = dao.selectDeptName(code);
  71. DEPT_NAME_MAP.put(code, deptName);
  72. }
  73. return deptName;
  74. }
  75. public String getRegionName(String code) {
  76. if (StringUtil.isBlank(code)) {
  77. return null;
  78. }
  79. String regionName = REGION_MAP.get(code);
  80. if (null == regionName) {
  81. CodeName region = dao.selectAdmdvsNameAndParentName(code);
  82. if (null == region) {
  83. region = dao.selectAdmdvsName(code);
  84. if (null == region) {
  85. region = dao.selectAdmdvsNameAndParentName(code.substring(0, 4) + "00");
  86. if (null == region) {
  87. region = dao.selectAdmdvsName(code.substring(0, 4) + "00");
  88. }
  89. }
  90. }
  91. if (null == region) {
  92. regionName = "未知";
  93. } else {
  94. regionName = region.getCode() + region.getName();
  95. }
  96. REGION_MAP.put(code, regionName);
  97. }
  98. return regionName;
  99. }
  100. public String getWjwAnaesthesia(String code) {
  101. if (StringUtil.invalidValue(code)) {
  102. return null;
  103. }
  104. String wjwCode = WJW_ANAESTHESIA_MAP.get(code);
  105. if (null == wjwCode) {
  106. wjwCode = dao.selectWjwAnaesthesia(code);
  107. WJW_ANAESTHESIA_MAP.put(code, wjwCode);
  108. }
  109. return wjwCode;
  110. }
  111. public String getWjwDepartment(String code) {
  112. if (StringUtil.invalidValue(code)) {
  113. return null;
  114. }
  115. String wjwCode = WJW_DEPARTMENT_MAP.get(code);
  116. if (null == wjwCode) {
  117. wjwCode = dao.selectWjwDepartment(code);
  118. WJW_DEPARTMENT_MAP.put(code, wjwCode);
  119. }
  120. return wjwCode;
  121. }
  122. public String getYbDept(String code) {
  123. if (StringUtil.invalidValue(code)) {
  124. return null;
  125. }
  126. String ybCode = YB_DEPT_MAP.get(code);
  127. if (null == ybCode) {
  128. ybCode = dao.selecYbDept(code);
  129. YB_DEPT_MAP.put(code, ybCode);
  130. }
  131. return ybCode;
  132. }
  133. public String getWjwNation(String code) {
  134. if (StringUtil.invalidValue(code)) {
  135. return null;
  136. }
  137. String wjwCode = WJW_NATION_MAP.get(code);
  138. if (null == wjwCode) {
  139. wjwCode = dao.selectWjwNation(code);
  140. WJW_NATION_MAP.put(code, wjwCode);
  141. }
  142. return wjwCode;
  143. }
  144. /**
  145. * @description:获取医保联系人关系
  146. * @author: lihong
  147. * @date: 2023/2/9 15:14
  148. * @param: code
  149. * @return: java.lang.String
  150. **/
  151. public String getYbCodeContactRelation(String code) {
  152. if (StringUtil.invalidValue(code)) {
  153. return null;
  154. }
  155. String ybCode = YB_CONTACT_RELATION_MAP.get(code);
  156. if (null == ybCode) {
  157. ybCode = dao.selectYbCodeContactRelation(code);
  158. YB_CONTACT_RELATION_MAP.put(code, ybCode);
  159. }
  160. return ybCode;
  161. }
  162. public String getCountryName(String code) {
  163. if (StringUtil.invalidValue(code)) {
  164. return null;
  165. }
  166. String name = COUNTRY_MAP.get(code);
  167. if (null == name) {
  168. name = dao.selectCountryName(code);
  169. COUNTRY_MAP.put(code, name);
  170. }
  171. return name;
  172. }
  173. public UserInfo getUserInfoByCode(String code) {
  174. if (StringUtil.invalidValue(code)) {
  175. return null;
  176. }
  177. UserInfo userInfo = USER_MAP.get(code);
  178. if (null == userInfo) {
  179. userInfo = dao.selectUserInfo(code);
  180. if (null == userInfo) {
  181. userInfo = dao.selectUserInfoFromHis(code);
  182. dao.insertNewUserToDjUserBase(userInfo);
  183. }
  184. userInfo.setDeptName(getDeptName(userInfo.getDeptCode()));
  185. userInfo.setRoles(dao.selectUserRoles(code));
  186. userInfo.setPartTimeDept(dao.selectUserPartTimeDept(userInfo.getCode()));
  187. USER_MAP.put(code, userInfo);
  188. }
  189. try {
  190. if (StringUtil.isBlank(userInfo.getAvatar())) {
  191. JSONObject json = srvc.getUserinfo(TokenUtil.getWeComAddressBookToken(), userInfo.getCodeRs());
  192. userInfo.setAvatar(json.getString("avatar"));
  193. }
  194. } catch (Exception ignored) {
  195. }
  196. return userInfo;
  197. }
  198. public UserInfo getUserInfoByToken() {
  199. return getUserInfoByCode(TokenUtil.getTokenUserId());
  200. }
  201. public void handleUserRoleChanged(String code) {
  202. UserInfo userInfo = getUserInfoByCode(code);
  203. userInfo.setRoles(dao.selectUserRoles(code));
  204. USER_MAP.replace(code, userInfo);
  205. }
  206. public void handleUserPwdChanged(String code, String pwd) {
  207. UserInfo userInfo = getUserInfoByCode(code);
  208. userInfo.setPassword(pwd);
  209. USER_MAP.replace(code, userInfo);
  210. }
  211. public void handleUserLogin(String code) {
  212. USER_MAP.remove(code);
  213. getUserInfoByCode(code);
  214. }
  215. }