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 * @Description
* @Author sun * @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 { 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; package com.epmet.commons.tools.redis.common;
import cn.hutool.core.bean.BeanUtil; 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.redis.common.bean.CustomerStaffInfoCache;
import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.Result; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.Map; import java.util.Map;
import static com.epmet.commons.tools.redis.RedisUtils.NOT_EXPIRE;
/** /**
* 工作人员缓存 * 工作人员缓存通用类
* *
* @author generator generator@elink-cn.com * @author generator generator@elink-cn.com
* @since v1.0.0 2020-04-22 * @since v1.0.0 2020-04-22
*/ */
@Slf4j
@Component @Component
public class CustomerStaffRedis { public class CustomerStaffRedis {
@Autowired @Autowired
private RedisUtils redisUtils; private RedisUtils redisUtils;
@Autowired @Autowired
private RedissonClient redissonClient;
@Autowired
private CommonAggFeignClient commonAggFeignClient; private CommonAggFeignClient commonAggFeignClient;
//@PostConstruct //@PostConstruct
public void init(){ public void init() {
CustomerStaffInfoCache role = this.getRole("45687aa479955f9d06204d415238f7cc", "9e37adcce6472152e6508a19d3683e02"); CustomerStaffInfoCache role = this.getStaffInfo("45687aa479955f9d06204d415238f7cc", "9e37adcce6472152e6508a19d3683e02");
System.out.println(JSON.toJSONString(role)); System.out.println(JSON.toJSONString(role));
} }
/** /**
* @Description 查询工作人员的角色 * desc: 根据工作人员Id 获取某工作人员信息如果缓存不存在则查询db返回;缓存默认一天
* @Param customerId *
* @Param userId * @param customerId
* @author zxc * @param staffId
* @date 2021/6/15 3:20 下午 * @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){ public CustomerStaffInfoCache getStaffInfo(String customerId, String staffId) {
String key = RedisKeys.getCustomerStaffInfoKey(customerId,staffId); String key = RedisKeys.getCustomerStaffInfoKey(customerId, staffId);
Map<String, Object> roleMap = redisUtils.hGetAll(key); Map<String, Object> roleMap = redisUtils.hGetAll(key);
boolean empty = roleMap.isEmpty(); if (!CollectionUtils.isEmpty(roleMap)) {
if (!empty){ return ConvertUtils.mapToEntity(roleMap, CustomerStaffInfoCache.class);
CustomerStaffInfoCache result = ConvertUtils.mapToEntity(roleMap, CustomerStaffInfoCache.class);
//return result;
} }
try {
Result<CustomerStaffInfoCache> staffResult = commonAggFeignClient.getStaffInfo(staffId); Result<CustomerStaffInfoCache> staffResult = commonAggFeignClient.getStaffInfo(staffId);
if (staffResult == null || !staffResult.success()){ if (staffResult == null || !staffResult.success()) {
throw new RenException("获取工作人员信息失败"); throw new RenException("获取工作人员信息失败");
} }
if (staffResult.getData() == null){ if (staffResult.getData() == null) {
return null; log.warn("getStaffInfo staff is null,staffId:{}", staffId);
} return null;
Map<String, Object> map = BeanUtil.beanToMap(staffResult.getData(), false, true);
redisUtils.hMSet(key,map);
} catch (Exception e) {
e.printStackTrace();
} }
return null; Map<String, Object> map = BeanUtil.beanToMap(staffResult.getData(), false, true);
redisUtils.hMSet(key, map);
return staffResult.getData();
} }
/** /**
* @Description 放入缓存角色 * desc: 根据客户id及工作人员Id 删除缓存
* @Param customerId *
* @Param userId * @param customerId
* @Param dto * @param staffId
* @author zxc * @return boolean
* @date 2021/6/15 4:01 下午 * @author LiuJanJun
* @date 2021/8/19 10:39 下午
*/ */
public void setRole(String customerId, String staffId, CustomerStaffInfoCache dto){ public boolean delStaffInfoFormCache(String customerId, String staffId) {
String key = RedisKeys.getCustomerStaffInfoKey(customerId,staffId); if (StringUtils.isBlank(customerId) || StringUtils.isBlank(staffId)) {
Map<String, Object> map = BeanUtil.beanToMap(dto, false, true); log.warn("delStaffInfoFormCache param is blank,customerId:{},staffId:{}", customerId, staffId);
redisUtils.hMSet(key, map,NOT_EXPIRE); 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.commons.mybatis.dao.BaseDao;
import com.epmet.dataaggre.entity.epmetuser.GovStaffRoleEntity; import com.epmet.dataaggre.entity.epmetuser.GovStaffRoleEntity;
import com.epmet.dto.result.StaffRoleResultDTO;
import org.apache.ibatis.annotations.Mapper; 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 @Mapper
public interface GovStaffRoleDao extends BaseDao<GovStaffRoleEntity> { 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.epmetuser.StaffPatrolRecordService;
import com.epmet.dataaggre.service.govorg.GovOrgService; import com.epmet.dataaggre.service.govorg.GovOrgService;
import com.epmet.dataaggre.service.govproject.GovProjectService; import com.epmet.dataaggre.service.govproject.GovProjectService;
import com.epmet.dto.result.StaffRoleResultDTO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -534,6 +535,10 @@ public class EpmetUserServiceImpl implements EpmetUserService {
} }
result.setAgencyName(agencyDTO.getOrganizationName()); 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.查询当前人员所在的网格列表 //1.查询当前人员所在的网格列表
List<CustomerGridDTO> list = govOrgService.getStaffGridList(staffId); List<CustomerGridDTO> list = govOrgService.getStaffGridList(staffId);
List<IdAndNameDTO> idAndNameList = new ArrayList<>(); 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 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