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 EMPLOYEE_NAME_MAP = new HashMap<>(); private final static Map DEPT_NAME_MAP = new HashMap<>(); private final static Map DEPT_AND_EMPLOYEE_NAME = new HashMap<>(); private final static Map REGION_MAP = new HashMap<>(); private final static Map WJW_ANAESTHESIA_MAP = new HashMap<>(); private final static Map WJW_DEPARTMENT_MAP = new HashMap<>(); private final static Map WJW_NATION_MAP = new HashMap<>(); private final static Map COUNTRY_MAP = new HashMap<>(); private final static Map USER_MAP = new HashMap<>(); private final static Map YB_CONTACT_RELATION_MAP = new HashMap<>(); private final static Map YB_DEPT_MAP = new HashMap<>(); private final RedisLikeDao dao; private final CorpWxSrvc srvc; private final static Map MESSAGE = new HashMap<>(2); public void setMessage(String key, String value) { MESSAGE.put(key, value); } public Map 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); } }