diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/dto/result/CustomerStaffInfoCacheResult.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/dto/result/CustomerStaffInfoCacheResult.java new file mode 100644 index 0000000000..8359f4d020 --- /dev/null +++ b/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 roleMap; + + /** + * 所属组织的上级组织 + */ + private IdAndNameDTO parentAgency; + + /** + * 所属网格列表 + */ + private List gridList; + + /** + * 所属部门 + */ + private List deptList; + +} diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/CommonAggFeignClient.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/CommonAggFeignClient.java index d9ceb0f3a0..7b87579a4d 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/CommonAggFeignClient.java +++ b/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 { /** diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/CustomerStaffRedis.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/CustomerStaffRedis.java index 5984a70d09..362294b66b 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/CustomerStaffRedis.java +++ b/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 - *

- * 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. - *

- * 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. - *

- * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - 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 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 staffResult = commonAggFeignClient.getStaffInfo(staffId); - if (staffResult == null || !staffResult.success()){ - throw new RenException("获取工作人员信息失败"); - } - if (staffResult.getData() == null){ - return null; - } - Map map = BeanUtil.beanToMap(staffResult.getData(), false, true); - redisUtils.hMSet(key,map); - } catch (Exception e) { - e.printStackTrace(); + + Result 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 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 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); } } diff --git a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/dao/epmetuser/GovStaffRoleDao.java b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/dao/epmetuser/GovStaffRoleDao.java index 5cdb42779f..a1bb0cccd9 100644 --- a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/dao/epmetuser/GovStaffRoleDao.java +++ b/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 { - -} \ No newline at end of file + + /** + * desc:根据员工id 获取角色列表 + * + * @param staffId + * @return + */ + List getStaffRoleList(@Param("staffId") String staffId); +} diff --git a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/epmetuser/impl/EpmetUserServiceImpl.java b/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/epmetuser/impl/EpmetUserServiceImpl.java index 037201b2c7..c75bcc1ebe 100644 --- a/epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/epmetuser/impl/EpmetUserServiceImpl.java +++ b/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 roleList = govStaffRoleDao.getStaffRoleList(staffId); + Map roleMap = roleList.stream().collect(Collectors.toMap(StaffRoleResultDTO::getRoleKey, StaffRoleResultDTO::getRoleName)); + result.setRoleMap(roleMap); + //1.查询当前人员所在的网格列表 List list = govOrgService.getStaffGridList(staffId); List idAndNameList = new ArrayList<>(); diff --git a/epmet-module/data-aggregator/data-aggregator-server/src/main/resources/mapper/epmetuser/GovStaffRoleDao.xml b/epmet-module/data-aggregator/data-aggregator-server/src/main/resources/mapper/epmetuser/GovStaffRoleDao.xml index 70497272c6..d81d193c57 100644 --- a/epmet-module/data-aggregator/data-aggregator-server/src/main/resources/mapper/epmetuser/GovStaffRoleDao.xml +++ b/epmet-module/data-aggregator/data-aggregator-server/src/main/resources/mapper/epmetuser/GovStaffRoleDao.xml @@ -3,4 +3,18 @@ - \ No newline at end of file + + +