Browse Source

CustomerStaffRedis调整为静态方法 无需注入直接使用

dev_shibei_match
jianjun 4 years ago
parent
commit
2b279651ff
  1. 2
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/filter/LogMsgSendFilter.java
  2. 34
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/CustomerStaffRedis.java
  3. 5
      epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/controller/DemoController.java
  4. 10
      epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/epmetmessage/impl/EpmetMessageServiceImpl.java
  5. 4
      epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/epmetuser/impl/EpmetUserServiceImpl.java
  6. 5
      epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/evaluationindex/screen/impl/ScreenProjectServiceImpl.java
  7. 6
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java
  8. 9
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffRoleServiceImpl.java

2
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/filter/LogMsgSendFilter.java

@ -205,7 +205,7 @@ public class LogMsgSendFilter extends LevelFilter {
}
return slashMatcher.start();
} catch (Exception e) {
logger.warn("getCharacterPosition no matche", e);
logger.warn("getCharacterPosition no matche");
return string.length();
}
}

34
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/CustomerStaffRedis.java

@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import javax.annotation.PostConstruct;
import java.util.Map;
/**
@ -32,14 +33,21 @@ public class CustomerStaffRedis {
private RedisUtils redisUtils;
@Autowired
private CommonAggFeignClient commonAggFeignClient;
private static CustomerStaffRedis customerStaffRedis;
private static final String ROLE_MAP_KEY = "roleMap";
//@PostConstruct
@PostConstruct
public void init(){
CustomerStaffInfoCacheResult role = this.getStaffInfo("45687aa479955f9d06204d415238f7cc", "9e37adcce6472152e6508a19d3683e02");
role = this.getStaffInfo("45687aa479955f9d06204d415238f7cc", "7f694a66efe60a47c2114875f310248a");
customerStaffRedis = this;
customerStaffRedis.redisUtils = this.redisUtils;
customerStaffRedis.commonAggFeignClient = this.commonAggFeignClient;
}
public static void initTest() {
CustomerStaffInfoCacheResult role = getStaffInfo("45687aa479955f9d06204d415238f7cc", "9e37adcce6472152e6508a19d3683e02");
role = getStaffInfo("45687aa479955f9d06204d415238f7cc", "7f694a66efe60a47c2114875f310248a");
System.out.println(JSON.toJSONString(role));
System.out.println(JSON.toJSONString(this.getStaffRoleMap("45687aa479955f9d06204d415238f7cc", "7f694a66efe60a47c2114875f310248a")));
System.out.println(JSON.toJSONString(getStaffRoleMap("45687aa479955f9d06204d415238f7cc", "7f694a66efe60a47c2114875f310248a")));
}
/**
@ -52,9 +60,9 @@ public class CustomerStaffRedis {
* @date 2021/8/19 10:29 下午
* @remark 此方法仅用于 获取某个工作人员的信息不用于获取客户下所有工作人员信息
*/
public CustomerStaffInfoCacheResult getStaffInfo(String customerId, String staffId) {
public static CustomerStaffInfoCacheResult getStaffInfo(String customerId, String staffId) {
String key = RedisKeys.getCustomerStaffInfoKey(customerId, staffId);
Map<String, Object> roleMap = redisUtils.hGetAll(key);
Map<String, Object> roleMap = customerStaffRedis.redisUtils.hGetAll(key);
if (!CollectionUtils.isEmpty(roleMap)) {
return ConvertUtils.mapToEntity(roleMap, CustomerStaffInfoCacheResult.class);
}
@ -66,8 +74,8 @@ public class CustomerStaffRedis {
}
@Nullable
private CustomerStaffInfoCache reloadStaffCache(String staffId, String key) {
Result<CustomerStaffInfoCache> staffResult = commonAggFeignClient.getStaffInfo(staffId);
private static CustomerStaffInfoCache reloadStaffCache(String staffId, String key) {
Result<CustomerStaffInfoCache> staffResult = customerStaffRedis.commonAggFeignClient.getStaffInfo(staffId);
if (staffResult == null || !staffResult.success()) {
throw new RenException("获取工作人员信息失败");
}
@ -78,7 +86,7 @@ public class CustomerStaffRedis {
}
Map<String, Object> map = BeanUtil.beanToMap(resultData, false, true);
redisUtils.hMSet(key, map);
customerStaffRedis.redisUtils.hMSet(key, map);
return resultData;
}
@ -92,9 +100,9 @@ public class CustomerStaffRedis {
* @date 2021/8/19 10:29 下午
* @remark 此方法仅用于 获取某个工作人员的信息不用于获取客户下所有工作人员信息
*/
public Map<String,String> getStaffRoleMap(String customerId, String staffId) {
public static Map<String,String> getStaffRoleMap(String customerId, String staffId) {
String key = RedisKeys.getCustomerStaffInfoKey(customerId, staffId);
Map<String, String> roleMap = (Map<String, String>) redisUtils.hGet(key,ROLE_MAP_KEY);
Map<String, String> roleMap = (Map<String, String>) customerStaffRedis.redisUtils.hGet(key,ROLE_MAP_KEY);
if (!CollectionUtils.isEmpty(roleMap)) {
return roleMap;
}
@ -112,13 +120,13 @@ public class CustomerStaffRedis {
* @author LiuJanJun
* @date 2021/8/19 10:39 下午
*/
public boolean delStaffInfoFormCache(String customerId, String staffId) {
public static Boolean delStaffInfoFormCache(String customerId, String staffId) {
if (StringUtils.isBlank(customerId) || StringUtils.isBlank(staffId)) {
log.warn("delStaffInfoFormCache param is blank,customerId:{},staffId:{}", customerId, staffId);
return false;
}
String key = RedisKeys.getCustomerStaffInfoKey(customerId, staffId);
return redisUtils.delete(key);
return customerStaffRedis.redisUtils.delete(key);
}
}

5
epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/controller/DemoController.java

@ -2,7 +2,6 @@ package com.epmet.dataaggre.controller;
import com.epmet.commons.tools.redis.common.CustomerStaffRedis;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.utils.SpringContextUtils;
import com.epmet.dataaggre.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@ -21,8 +20,8 @@ public class DemoController {
demoService.doIt();
CustomerStaffRedis bean = SpringContextUtils.getBean(CustomerStaffRedis.class);
bean.init();
//CustomerStaffRedis bean = SpringContextUtils.getBean(CustomerStaffRedis.class);
CustomerStaffRedis.initTest();
return new Result();
}

10
epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/epmetmessage/impl/EpmetMessageServiceImpl.java

@ -43,8 +43,6 @@ import java.util.stream.Collectors;
public class EpmetMessageServiceImpl implements EpmetMessageService {
@Autowired
private InfoReceiversDao infoReceiversDao;
@Autowired
private CustomerStaffRedis customerStaffRedis;
/**
* @param formDTO
@ -75,7 +73,7 @@ public class EpmetMessageServiceImpl implements EpmetMessageService {
ReceiverDTO dto = new ReceiverDTO();
dto.setStaffId(item.getStaffId());
dto.setReadFlag(item.getReadFlag());
CustomerStaffInfoCacheResult staffInfoCache = customerStaffRedis.getStaffInfo(item.getCustomerId(), item.getStaffId());
CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(item.getCustomerId(), item.getStaffId());
dto.setStaffName(staffInfoCache.getRealName());
dto.setGender(staffInfoCache.getGender());
dto.setHeadPhoto(staffInfoCache.getHeadPhoto());
@ -105,7 +103,7 @@ public class EpmetMessageServiceImpl implements EpmetMessageService {
List<String> staffNameList = new ArrayList<>();
for (String userId : group.getStaffIdList()) {
//查询每个工作人员的基本信息,获取姓名
CustomerStaffInfoCacheResult staffInfoCache = customerStaffRedis.getStaffInfo(customerId, userId);
CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(customerId, userId);
if (null != staffInfoCache) {
staffNameList.add(staffInfoCache.getRealName());
}
@ -136,7 +134,7 @@ public class EpmetMessageServiceImpl implements EpmetMessageService {
if (CollectionUtils.isNotEmpty(staffIds.getList())) {
for (String userId : staffIds.getList()) {
//查询每个工作人员的基本信息
CustomerStaffInfoCacheResult staffInfoCache = customerStaffRedis.getStaffInfo(formDTO.getCustomerId(), userId);
CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(formDTO.getCustomerId(), userId);
if (null != staffInfoCache) {
StaffInfoCommonDTO staffInfo = new StaffInfoCommonDTO();
staffInfo.setStaffId(userId);
@ -167,7 +165,7 @@ public class EpmetMessageServiceImpl implements EpmetMessageService {
result.setTotal((int) data.getTotal());
for (InfoReplyDetail detail : data.getList()) {
//查询每个工作人员的基本信息
CustomerStaffInfoCacheResult staffInfoCache = customerStaffRedis.getStaffInfo(formDTO.getCustomerId(), detail.getStaffId());
CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(formDTO.getCustomerId(), detail.getStaffId());
detail.setStaffName(staffInfoCache.getRealName());
detail.setGender(staffInfoCache.getGender().toString());
detail.setHeadPhoto(StringUtils.isNotBlank(staffInfoCache.getHeadPhoto()) ? staffInfoCache.getHeadPhoto() : StrConstant.EPMETY_STR);

4
epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/epmetuser/impl/EpmetUserServiceImpl.java

@ -76,8 +76,6 @@ public class EpmetUserServiceImpl implements EpmetUserService {
private GovProjectService govProjectService;
@Resource
private GovStaffRoleDao govStaffRoleDao;
@Resource
private CustomerStaffRedis customerStaffRedis;
/**
* @Description 根据UserIds查询
@ -487,7 +485,7 @@ public class EpmetUserServiceImpl implements EpmetUserService {
RoleUsersResultDTO dto = new RoleUsersResultDTO();
dto.setStaffId(item.getStaffId());
//从redis获取用户信息
CustomerStaffInfoCacheResult staffInfoCache = customerStaffRedis.getStaffInfo(item.getCustomerId(), item.getStaffId());
CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(item.getCustomerId(), item.getStaffId());
dto.setGender(staffInfoCache.getGender());
dto.setHeadPhoto(staffInfoCache.getHeadPhoto());
dto.setName(staffInfoCache.getRealName());

5
epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/evaluationindex/screen/impl/ScreenProjectServiceImpl.java

@ -56,8 +56,7 @@ public class ScreenProjectServiceImpl implements ScreenProjectService {
private ScreenEventImgDataDao screenEventImgDataDao;
@Autowired
private ScreenProjectDataDao screenProjectDataDao;
@Autowired
private CustomerStaffRedis staffRedis;
@Autowired
private ScreenProjectCategoryOrgDailyDao screenProjectCategoryOrgDailyDao;
@Autowired
@ -118,7 +117,7 @@ public class ScreenProjectServiceImpl implements ScreenProjectService {
CustomerAgencyUserRoleFormDTO userRoleFormDTO = new CustomerAgencyUserRoleFormDTO();
userRoleFormDTO.setCustomerId(formDTO.getCustomerId());
userRoleFormDTO.setStaffId(item.getReportUserId());
Map<String, String> staffRoleMap = staffRedis.getStaffRoleMap(formDTO.getCustomerId(), item.getReportUserId());
Map<String, String> staffRoleMap = CustomerStaffRedis.getStaffRoleMap(formDTO.getCustomerId(), item.getReportUserId());
if (!CollectionUtils.isEmpty(staffRoleMap)){
item.setReportUserRoleSet(staffRoleMap.keySet());
}

6
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java

@ -99,8 +99,6 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl<CustomerStaffDao,
private GovStaffRoleDao govStaffRoleDao;
@Autowired
private OperCrmOpenFeignClient operCrmOpenFeignClient;
@Autowired
private CustomerStaffRedis staffRedis;
@Override
public PageData<CustomerStaffDTO> page(Map<String, Object> params) {
@ -343,7 +341,7 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl<CustomerStaffDao,
m.put(r.getRoleKey(),r.getRoleName());
});
dto.setRoles(m);
staffRedis.delStaffInfoFormCache(dto.getCustomerId(), dto.getStaffId());
CustomerStaffRedis.delStaffInfoFormCache(dto.getCustomerId(), dto.getStaffId());
return new Result<CustomerStaffDTO>().ok(ConvertUtils.sourceToTarget(staffEntity, CustomerStaffDTO.class));
}
@ -416,7 +414,7 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl<CustomerStaffDao,
m.put(r.getRoleKey(),r.getRoleName());
});
dto.setRoles(m);
staffRedis.delStaffInfoFormCache(dto.getCustomerId(), dto.getStaffId());
CustomerStaffRedis.delStaffInfoFormCache(dto.getCustomerId(), dto.getStaffId());
return new Result();
}

9
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffRoleServiceImpl.java

@ -24,10 +24,8 @@ import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.redis.common.CustomerStaffRedis;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dao.GovStaffRoleTemplateDao;
import com.epmet.dao.StaffRoleDao;
import com.epmet.dto.StaffRoleDTO;
import com.epmet.dto.form.CommonUserFormDTO;
@ -38,7 +36,6 @@ import com.epmet.dto.result.*;
import com.epmet.entity.StaffRoleEntity;
import com.epmet.service.StaffRoleService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@ -54,12 +51,6 @@ import java.util.*;
@Service
public class StaffRoleServiceImpl extends BaseServiceImpl<StaffRoleDao, StaffRoleEntity> implements StaffRoleService {
@Autowired
private CustomerStaffRedis staffRedis;
@Autowired
private GovStaffRoleTemplateDao govStaffRoleTemplateDao;
@Override
public PageData<StaffRoleDTO> page(Map<String, Object> params) {
IPage<StaffRoleEntity> page = baseDao.selectPage(

Loading…
Cancel
Save