Browse Source

获取工作人员缓存代码提交

dev_shibei_match
jianjun 4 years ago
parent
commit
7ebeaead8d
  1. 74
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/dto/result/CustomerStaffInfoCacheResult.java
  2. 2
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/CommonAggFeignClient.java
  3. 104
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/CustomerStaffRedis.java
  4. 15
      epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/dao/epmetuser/GovStaffRoleDao.java
  5. 5
      epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/epmetuser/impl/EpmetUserServiceImpl.java
  6. 16
      epmet-module/data-aggregator/data-aggregator-server/src/main/resources/mapper/epmetuser/GovStaffRoleDao.xml

74
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/dto/result/CustomerStaffInfoCacheResult.java

@ -0,0 +1,74 @@
package com.epmet.commons.tools.dto.result;
import com.epmet.commons.tools.dto.form.IdAndNameDTO;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
* @Author zxc
* @DateTime 2021/6/15 10:00 上午
* @DESC
*/
@Data
public class CustomerStaffInfoCacheResult implements Serializable {
private static final long serialVersionUID = 3519630252798469087L;
/**
* 工作人员所属组织ID
*/
private String agencyId;
/**
* 工作人员所属组织名称
*/
private String agencyName;
/**
* 工作人员ID
*/
private String staffId;
/**
* 真实姓名
*/
private String realName;
/**
* 性别0.未知1男2.
*/
private Integer gender;
/**
* 手机号-唯一键
*/
private String mobile;
/**
* 头像
*/
private String headPhoto;
/**
* 角色map key为角色key value 为角色名称
*/
private Map<String,String> roleMap;
/**
* 所属组织的上级组织
*/
private IdAndNameDTO parentAgency;
/**
* 所属网格列表
*/
private List<IdAndNameDTO> gridList;
/**
* 所属部门
*/
private List<IdAndNameDTO> deptList;
}

2
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/CommonAggFeignClient.java

@ -13,7 +13,7 @@ import org.springframework.web.bind.annotation.PostMapping;
* @Description
* @Author sun
*/
@FeignClient(name = ServiceConstant.DATA_AGGREGATOR_SERVER, fallbackFactory = CommonAggFeignClientFallBackFactory.class)
@FeignClient(name = ServiceConstant.DATA_AGGREGATOR_SERVER, fallbackFactory = CommonAggFeignClientFallBackFactory.class,url = "http://localhost:8114")
public interface CommonAggFeignClient {
/**

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

@ -1,20 +1,3 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.commons.tools.redis.common;
import cn.hutool.core.bean.BeanUtil;
@ -26,78 +9,81 @@ import com.epmet.commons.tools.redis.RedisUtils;
import com.epmet.commons.tools.redis.common.bean.CustomerStaffInfoCache;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.Result;
import org.redisson.api.RedissonClient;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.Map;
import static com.epmet.commons.tools.redis.RedisUtils.NOT_EXPIRE;
/**
* 工作人员缓存
* 工作人员缓存通用类
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2020-04-22
*/
@Slf4j
@Component
public class CustomerStaffRedis {
@Autowired
private RedisUtils redisUtils;
@Autowired
private RedissonClient redissonClient;
@Autowired
private CommonAggFeignClient commonAggFeignClient;
//@PostConstruct
public void init(){
CustomerStaffInfoCache role = this.getRole("45687aa479955f9d06204d415238f7cc", "9e37adcce6472152e6508a19d3683e02");
public void init() {
CustomerStaffInfoCache role = this.getStaffInfo("45687aa479955f9d06204d415238f7cc", "9e37adcce6472152e6508a19d3683e02");
System.out.println(JSON.toJSONString(role));
}
/**
* @Description 查询工作人员的角色
* @Param customerId
* @Param userId
* @author zxc
* @date 2021/6/15 3:20 下午
* desc: 根据工作人员Id 获取某工作人员信息如果缓存不存在则查询db返回;缓存默认一天
*
* @param customerId
* @param staffId
* @return com.epmet.commons.tools.redis.common.bean.CustomerStaffInfoCache
* @author LiuJanJun
* @date 2021/8/19 10:29 下午
* @remark 此方法仅用于 获取某个工作人员的信息不用于获取客户下所有工作人员信息
*/
public CustomerStaffInfoCache getRole(String customerId, String staffId){
String key = RedisKeys.getCustomerStaffInfoKey(customerId,staffId);
public CustomerStaffInfoCache getStaffInfo(String customerId, String staffId) {
String key = RedisKeys.getCustomerStaffInfoKey(customerId, staffId);
Map<String, Object> roleMap = redisUtils.hGetAll(key);
boolean empty = roleMap.isEmpty();
if (!empty){
CustomerStaffInfoCache result = ConvertUtils.mapToEntity(roleMap, CustomerStaffInfoCache.class);
//return result;
if (!CollectionUtils.isEmpty(roleMap)) {
return ConvertUtils.mapToEntity(roleMap, CustomerStaffInfoCache.class);
}
try {
Result<CustomerStaffInfoCache> staffResult = commonAggFeignClient.getStaffInfo(staffId);
if (staffResult == null || !staffResult.success()){
throw new RenException("获取工作人员信息失败");
}
if (staffResult.getData() == null){
return null;
}
Map<String, Object> map = BeanUtil.beanToMap(staffResult.getData(), false, true);
redisUtils.hMSet(key,map);
} catch (Exception e) {
e.printStackTrace();
Result<CustomerStaffInfoCache> staffResult = commonAggFeignClient.getStaffInfo(staffId);
if (staffResult == null || !staffResult.success()) {
throw new RenException("获取工作人员信息失败");
}
if (staffResult.getData() == null) {
log.warn("getStaffInfo staff is null,staffId:{}", staffId);
return null;
}
return null;
Map<String, Object> map = BeanUtil.beanToMap(staffResult.getData(), false, true);
redisUtils.hMSet(key, map);
return staffResult.getData();
}
/**
* @Description 放入缓存角色
* @Param customerId
* @Param userId
* @Param dto
* @author zxc
* @date 2021/6/15 4:01 下午
* desc: 根据客户id及工作人员Id 删除缓存
*
* @param customerId
* @param staffId
* @return boolean
* @author LiuJanJun
* @date 2021/8/19 10:39 下午
*/
public void setRole(String customerId, String staffId, CustomerStaffInfoCache dto){
String key = RedisKeys.getCustomerStaffInfoKey(customerId,staffId);
Map<String, Object> map = BeanUtil.beanToMap(dto, false, true);
redisUtils.hMSet(key, map,NOT_EXPIRE);
public 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);
}
}

15
epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/dao/epmetuser/GovStaffRoleDao.java

@ -19,7 +19,11 @@ package com.epmet.dataaggre.dao.epmetuser;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dataaggre.entity.epmetuser.GovStaffRoleEntity;
import com.epmet.dto.result.StaffRoleResultDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 政府端角色表
@ -29,5 +33,12 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface GovStaffRoleDao extends BaseDao<GovStaffRoleEntity> {
}
/**
* desc:根据员工id 获取角色列表
*
* @param staffId
* @return
*/
List<StaffRoleResultDTO> getStaffRoleList(@Param("staffId") String staffId);
}

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

@ -29,6 +29,7 @@ import com.epmet.dataaggre.service.epmetuser.StaffPatrolDetailService;
import com.epmet.dataaggre.service.epmetuser.StaffPatrolRecordService;
import com.epmet.dataaggre.service.govorg.GovOrgService;
import com.epmet.dataaggre.service.govproject.GovProjectService;
import com.epmet.dto.result.StaffRoleResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@ -534,6 +535,10 @@ public class EpmetUserServiceImpl implements EpmetUserService {
}
result.setAgencyName(agencyDTO.getOrganizationName());
List<StaffRoleResultDTO> roleList = govStaffRoleDao.getStaffRoleList(staffId);
Map<String, String> roleMap = roleList.stream().collect(Collectors.toMap(StaffRoleResultDTO::getRoleKey, StaffRoleResultDTO::getRoleName));
result.setRoleMap(roleMap);
//1.查询当前人员所在的网格列表
List<CustomerGridDTO> list = govOrgService.getStaffGridList(staffId);
List<IdAndNameDTO> idAndNameList = new ArrayList<>();

16
epmet-module/data-aggregator/data-aggregator-server/src/main/resources/mapper/epmetuser/GovStaffRoleDao.xml

@ -3,4 +3,18 @@
<mapper namespace="com.epmet.dataaggre.dao.epmetuser.GovStaffRoleDao">
</mapper>
<select id="getStaffRoleList" resultType="com.epmet.dto.result.StaffRoleResultDTO">
SELECT
DISTINCT
gsr.ROLE_KEY,
sr.ORG_ID,
sr.CUSTOMER_ID,
gsr.ROLE_NAME,
sr.STAFF_ID
FROM staff_role sr
LEFT JOIN gov_staff_role gsr ON gsr.ID = sr.ROLE_ID AND gsr.DEL_FLAG = 0
WHERE sr.DEL_FLAG = 0
AND sr.STAFF_ID = #{staffId}
</select>
</mapper>

Loading…
Cancel
Save