123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- package thyyxxk.webserver.service.redislike;
- import com.alibaba.fastjson.JSONObject;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.stereotype.Service;
- import thyyxxk.webserver.dao.his.redislike.RedisLikeDao;
- import thyyxxk.webserver.entity.dictionary.CodeName;
- import thyyxxk.webserver.entity.login.UserInfo;
- import thyyxxk.webserver.service.externalhttp.CorpWxSrvc;
- import thyyxxk.webserver.utils.StringUtil;
- import thyyxxk.webserver.utils.TokenUtil;
- import java.util.HashMap;
- import java.util.Map;
- @Service
- @Slf4j
- public class RedisLikeService {
- public final static String SCROLLING_MESSAGES = "scrollingMessages";
- public final static String SYSTEM_UPDATES_MESSAGE = "systemUpdatesMessage";
- private final static Map<String, String> EMPLOYEE_NAME_MAP = new HashMap<>();
- private final static Map<String, String> DEPT_NAME_MAP = new HashMap<>();
- private final static Map<String, String> DEPT_AND_EMPLOYEE_NAME = new HashMap<>();
- private final static Map<String, String> REGION_MAP = new HashMap<>();
- private final static Map<String, String> WJW_ANAESTHESIA_MAP = new HashMap<>();
- private final static Map<String, String> WJW_DEPARTMENT_MAP = new HashMap<>();
- private final static Map<String, String> WJW_NATION_MAP = new HashMap<>();
- private final static Map<String, String> COUNTRY_MAP = new HashMap<>();
- private final static Map<String, UserInfo> USER_MAP = new HashMap<>();
- private final static Map<String, String> YB_CONTACT_RELATION_MAP = new HashMap<>();
- private final static Map<String, String> YB_DEPT_MAP = new HashMap<>();
- private final RedisLikeDao dao;
- private final CorpWxSrvc srvc;
- private final static Map<String, String> MESSAGE = new HashMap<>(2);
- public void setMessage(String key, String value) {
- MESSAGE.put(key, value);
- }
- public Map<String, String> getMessage() {
- return MESSAGE;
- }
- public RedisLikeService(RedisLikeDao dao, CorpWxSrvc srvc) {
- this.dao = dao;
- this.srvc = srvc;
- }
- public String getEmployeeName(String code) {
- if (StringUtil.invalidValue(code)) {
- return null;
- }
- String username = EMPLOYEE_NAME_MAP.get(code);
- if (null == username) {
- username = dao.selectEmployeeName(code);
- EMPLOYEE_NAME_MAP.put(code, username);
- }
- return username;
- }
- public String getDeptAndEmployeeName(String code) {
- if (StringUtil.invalidValue(code)) {
- return null;
- }
- String result = DEPT_AND_EMPLOYEE_NAME.get(code);
- if (null == result) {
- result = dao.selectDeptAndUser(code);
- DEPT_AND_EMPLOYEE_NAME.put(code, result);
- }
- return result;
- }
- public String getDeptName(String code) {
- if (StringUtil.invalidValue(code)) {
- return null;
- }
- String deptName = DEPT_NAME_MAP.get(code);
- if (null == deptName) {
- deptName = dao.selectDeptName(code);
- DEPT_NAME_MAP.put(code, deptName);
- }
- return deptName;
- }
- public String getRegionName(String code) {
- if (StringUtil.isBlank(code)) {
- return null;
- }
- String regionName = REGION_MAP.get(code);
- if (null == regionName) {
- CodeName region = dao.selectAdmdvsNameAndParentName(code);
- if (null == region) {
- region = dao.selectAdmdvsName(code);
- if (null == region) {
- region = dao.selectAdmdvsNameAndParentName(code.substring(0, 4) + "00");
- if (null == region) {
- region = dao.selectAdmdvsName(code.substring(0, 4) + "00");
- }
- }
- }
- if (null == region) {
- regionName = "未知";
- } else {
- regionName = region.getCode() + region.getName();
- }
- REGION_MAP.put(code, regionName);
- }
- return regionName;
- }
- public String getWjwAnaesthesia(String code) {
- if (StringUtil.invalidValue(code)) {
- return null;
- }
- String wjwCode = WJW_ANAESTHESIA_MAP.get(code);
- if (null == wjwCode) {
- wjwCode = dao.selectWjwAnaesthesia(code);
- WJW_ANAESTHESIA_MAP.put(code, wjwCode);
- }
- return wjwCode;
- }
- public String getWjwDepartment(String code) {
- if (StringUtil.invalidValue(code)) {
- return null;
- }
- String wjwCode = WJW_DEPARTMENT_MAP.get(code);
- if (null == wjwCode) {
- wjwCode = dao.selectWjwDepartment(code);
- WJW_DEPARTMENT_MAP.put(code, wjwCode);
- }
- return wjwCode;
- }
- public String getYbDept(String code) {
- if (StringUtil.invalidValue(code)) {
- return null;
- }
- String ybCode = YB_DEPT_MAP.get(code);
- if (null == ybCode) {
- ybCode = dao.selecYbDept(code);
- YB_DEPT_MAP.put(code, ybCode);
- }
- return ybCode;
- }
- public String getWjwNation(String code) {
- if (StringUtil.invalidValue(code)) {
- return null;
- }
- String wjwCode = WJW_NATION_MAP.get(code);
- if (null == wjwCode) {
- wjwCode = dao.selectWjwNation(code);
- WJW_NATION_MAP.put(code, wjwCode);
- }
- return wjwCode;
- }
- /**
- * @description:获取医保联系人关系
- * @author: lihong
- * @date: 2023/2/9 15:14
- * @param: code
- * @return: java.lang.String
- **/
- public String getYbCodeContactRelation(String code) {
- if (StringUtil.invalidValue(code)) {
- return null;
- }
- String ybCode = YB_CONTACT_RELATION_MAP.get(code);
- if (null == ybCode) {
- ybCode = dao.selectYbCodeContactRelation(code);
- YB_CONTACT_RELATION_MAP.put(code, ybCode);
- }
- return ybCode;
- }
- public String getCountryName(String code) {
- if (StringUtil.invalidValue(code)) {
- return null;
- }
- String name = COUNTRY_MAP.get(code);
- if (null == name) {
- name = dao.selectCountryName(code);
- COUNTRY_MAP.put(code, name);
- }
- return name;
- }
- public UserInfo getUserInfoByCode(String code) {
- if (StringUtil.invalidValue(code)) {
- return null;
- }
- UserInfo userInfo = USER_MAP.get(code);
- if (null == userInfo) {
- userInfo = dao.selectUserInfo(code);
- if (null == userInfo) {
- userInfo = dao.selectUserInfoFromHis(code);
- dao.insertNewUserToDjUserBase(userInfo);
- }
- userInfo.setDeptName(getDeptName(userInfo.getDeptCode()));
- userInfo.setRoles(dao.selectUserRoles(code));
- userInfo.setPartTimeDept(dao.selectUserPartTimeDept(userInfo.getCode()));
- USER_MAP.put(code, userInfo);
- }
- try {
- if (StringUtil.isBlank(userInfo.getAvatar())) {
- JSONObject json = srvc.getUserinfo(TokenUtil.getWeComAddressBookToken(), userInfo.getCodeRs());
- userInfo.setAvatar(json.getString("avatar"));
- }
- } catch (Exception ignored) {
- }
- return userInfo;
- }
- public UserInfo getUserInfoByToken() {
- return getUserInfoByCode(TokenUtil.getTokenUserId());
- }
- public void handleUserRoleChanged(String code) {
- UserInfo userInfo = getUserInfoByCode(code);
- userInfo.setRoles(dao.selectUserRoles(code));
- USER_MAP.replace(code, userInfo);
- }
- public void handleUserPwdChanged(String code, String pwd) {
- UserInfo userInfo = getUserInfoByCode(code);
- userInfo.setPassword(pwd);
- USER_MAP.replace(code, userInfo);
- }
- public void handleUserLogin(String code) {
- USER_MAP.remove(code);
- getUserInfoByCode(code);
- }
- }
|