Commit b63e0d35 by 王祖波

抽取校验服务

parent 1ab2fdd7
......@@ -3,9 +3,11 @@ package com.gic.haoban.manage.service.service.content.adaptor;
import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.enterprise.api.constant.EnterpriseServiceEnum;
import com.gic.enterprise.api.dto.EnterpriseUsingPermissionDto;
import com.gic.enterprise.api.dto.enterprise.EnterpriseUsingStatusDTO;
import com.gic.enterprise.api.service.EnterpriseUseForbidService;
import com.gic.redis.data.util.RedisUtil;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
......@@ -124,23 +126,24 @@ public class EnterpriseAdaptor {
}
public boolean checkEnterpriseHasRight(String enterpriseId,String rightMenuCode) {
String key = "haoban_enterprise_menuCode:" + enterpriseId;
return checkEnterpriseHasRights(enterpriseId,Lists.newArrayList(rightMenuCode));
}
public boolean checkEnterpriseHasRights(String enterpriseId,List<String> rightMenuCodes) {
String key = "haoban_enterprise_menuCode:" + enterpriseId + ":" + String.join(":", rightMenuCodes);
String cache = RedisUtil.getCache(key, String.class);
if (StringUtils.isBlank(cache)) {
cache = "0";
ServiceResponse<List<EnterpriseUsingStatusDTO>> tempServiceResponse = enterpriseUseForbidService.getUseEnterpriseByCode(rightMenuCode, enterpriseId);
if (!tempServiceResponse.isSuccess() || CollectionUtils.isEmpty(tempServiceResponse.getResult())) {
log.info("企业 {} 没有{}权限", enterpriseId, rightMenuCode);
RedisUtil.setCache(key, cache, cache_hour_sec, TimeUnit.SECONDS);
List<EnterpriseUsingPermissionDto> list = enterpriseUseForbidService.selectUsingEnterprisePermissionByEnterpriseId(enterpriseId);
if (CollectionUtils.isEmpty(list)) {
return false;
}
EnterpriseUsingStatusDTO enterpriseUsingStatusDTO = tempServiceResponse.getResult().get(0);
if (!Boolean.TRUE.equals(enterpriseUsingStatusDTO.getVaild())) {
log.info("企业 {} {}权限已失效", enterpriseId, rightMenuCode);
RedisUtil.setCache(key, cache, cache_hour_sec, TimeUnit.SECONDS);
return false;
List<String> hasList = list.stream().map(EnterpriseUsingPermissionDto::getRightMenuCode).collect(Collectors.toList());
hasList = hasList.stream().filter(rightMenuCodes::contains).collect(Collectors.toList());
if (CollectionUtils.isEmpty(hasList)) {
cache = "0";
}else {
cache = "1";
}
cache = "1";
RedisUtil.setCache(key, cache, cache_hour_sec, TimeUnit.SECONDS);
}
return StringUtils.equals(cache, "1");
......
......@@ -30,6 +30,7 @@ import com.gic.haoban.manage.service.pojo.bo.content.InteractRecordBO;
import com.gic.haoban.manage.service.pojo.bo.content.OrderEventMqBO;
import com.gic.haoban.manage.service.pojo.bo.content.binlog.MemberOrderBo;
import com.gic.haoban.manage.service.pojo.bo.content.message.InteractRecordMessageBO;
import com.gic.haoban.manage.service.service.content.adaptor.EnterpriseAdaptor;
import com.gic.haoban.manage.service.service.content.adaptor.InteractRecordBuilder;
import com.gic.haoban.manage.service.service.content.adaptor.WeekMonthDataAdaptor;
import com.gic.haoban.manage.service.service.content.message.InteractRecordMessageService;
......@@ -66,7 +67,7 @@ public class MallOrderStatusChangeApiServiceImpl implements MallOrderStatusChang
@Autowired
InteractRecordMessageService interactRecordMessageService;
@Autowired
private WeekMonthDataAdaptor weekMonthDataAdaptor;
private EnterpriseAdaptor enterpriseAdaptor;
@Autowired
private EnterpriseUseForbidService enterpriseUseForbidService;
@Autowired
......@@ -90,7 +91,6 @@ public class MallOrderStatusChangeApiServiceImpl implements MallOrderStatusChang
EnterpriseServiceEnum.CONTENT.getRightMenuCode(),
EnterpriseServiceEnum.GOODS_ANALYSIS.getRightMenuCode()
);
/***
* 订单状态变更事件
* @param params
......@@ -239,25 +239,9 @@ public class MallOrderStatusChangeApiServiceImpl implements MallOrderStatusChang
return ServiceResponse.success();
}
String enterpriseId = memberOrderBo.getEnterpriseId();
String key = "haoban_enterprise_content_deal_weimob:" + enterpriseId;
String cache = RedisUtil.getCache(key, String.class);
if (StringUtils.isBlank(cache)) {
List<EnterpriseUsingPermissionDto> list = enterpriseUseForbidService.selectUsingEnterprisePermissionByEnterpriseId(enterpriseId);
if (CollectionUtils.isEmpty(list)) {
return ServiceResponse.success();
}
List<String> hasList = list.stream().map(EnterpriseUsingPermissionDto::getRightMenuCode).collect(Collectors.toList());
hasList = hasList.stream().filter(rightCodeList::contains).collect(Collectors.toList());
if (CollectionUtils.isEmpty(hasList)) {
cache = "0";
}else {
cache = "1";
}
RedisUtil.setCache(key, cache, cache_hour_sec, TimeUnit.SECONDS);
}
if (!StringUtils.equals(cache, "1")) {
log.info("企业 {} 没有内容权限", enterpriseId);
boolean check = enterpriseAdaptor.checkEnterpriseHasRights(enterpriseId, rightCodeList);
if (!check) {
log.info("企业 {} 没有权限", enterpriseId);
return ServiceResponse.success();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment