|
|
@ -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()){ |
|
|
|
if (staffResult == null || !staffResult.success()) { |
|
|
|
throw new RenException("获取工作人员信息失败"); |
|
|
|
} |
|
|
|
if (staffResult.getData() == null){ |
|
|
|
if (staffResult.getData() == 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; |
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|