|
@@ -1,57 +1,109 @@
|
|
|
package com.example.xiaoshiweixinback.service;
|
|
|
|
|
|
+import com.alibaba.druid.sql.ast.statement.SQLForeignKeyImpl;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.example.xiaoshiweixinback.business.common.base.RedisConf;
|
|
|
+import com.example.xiaoshiweixinback.business.exception.BusinessException;
|
|
|
import com.example.xiaoshiweixinback.business.redis.RedisService;
|
|
|
+import com.example.xiaoshiweixinback.business.utils.*;
|
|
|
import com.example.xiaoshiweixinback.domain.AssoPersonFunction;
|
|
|
|
|
|
import com.example.xiaoshiweixinback.domain.AssoPersonVip;
|
|
|
import com.example.xiaoshiweixinback.domain.AssoVipFunction;
|
|
|
import com.example.xiaoshiweixinback.domain.Vip;
|
|
|
+import com.example.xiaoshiweixinback.entity.sysFuctionRights.FunctionConfig;
|
|
|
+import com.example.xiaoshiweixinback.entity.vo.PersonnelVO;
|
|
|
import com.example.xiaoshiweixinback.mapper.AssoPersonFunctionMapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
-* @author admin
|
|
|
-* @description 针对表【asso_person_function(人员功能关联表)】的数据库操作Service实现
|
|
|
-* @createDate 2024-04-10 23:08:39
|
|
|
-*/
|
|
|
+ * @author admin
|
|
|
+ * @description 针对表【asso_person_function(人员功能关联表)】的数据库操作Service实现
|
|
|
+ * @createDate 2024-04-10 23:08:39
|
|
|
+ */
|
|
|
@Service
|
|
|
public class AssoPersonFunctionService extends ServiceImpl<AssoPersonFunctionMapper, AssoPersonFunction> {
|
|
|
-@Autowired
|
|
|
-private RedisService redisService;
|
|
|
-@Autowired
|
|
|
-private VipService vipService;
|
|
|
-@Autowired
|
|
|
-private AssoVipFunctionService assoVipFunctionService;
|
|
|
- public void get(String functionUuid){
|
|
|
- String personUuid ="";
|
|
|
- String redisKey =RedisConf.PERSON_FUNCTION+RedisConf.SYMBOL_COLON+personUuid+RedisConf.SYMBOL_COLON+functionUuid;
|
|
|
- Object o =redisService.get(redisKey);
|
|
|
- if(o==null){
|
|
|
- AssoPersonFunction assoPersonFunction = vipService.getAssoPersonFunction(functionUuid);
|
|
|
- if(assoPersonFunction==null){
|
|
|
- Vip vip =vipService.getDefaultVip();
|
|
|
- AssoVipFunction assoVipFunction = assoVipFunctionService.getByVipUuidAndFunId(vip.getVipUuid(),personUuid);
|
|
|
- if(assoVipFunction!=null){}
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
+ @Autowired
|
|
|
+ private RedisService redisService;
|
|
|
+ @Autowired
|
|
|
+ private VipService vipService;
|
|
|
+ @Autowired
|
|
|
+ private AssoVipFunctionService assoVipFunctionService;
|
|
|
+ @Autowired
|
|
|
+ private CacheUtil cacheUtil;
|
|
|
|
|
|
- }
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public FunctionConfig getFunctionConfig(String functionUuid) {
|
|
|
+ PersonnelVO personnelVO = cacheUtil.getLoginUser(LoginUtils.getToken());
|
|
|
+ String personUuid = personnelVO.getUuid();
|
|
|
+ //从redis里取出功能
|
|
|
+ String redisKey = RedisConf.PERSON_FUNCTION + RedisConf.SYMBOL_COLON + personUuid + RedisConf.SYMBOL_COLON + functionUuid;
|
|
|
+ Object o = redisService.get(redisKey);
|
|
|
+ FunctionConfig functionConfig = null;
|
|
|
+
|
|
|
+ //若redis取出为空
|
|
|
+ if (o == null) {
|
|
|
+
|
|
|
+ //取出人员和功能关联
|
|
|
+ AssoPersonFunction assoPersonFunction = vipService.getAssoPersonFunction(functionUuid);
|
|
|
|
|
|
+ //若人员和功能没有关联则取出和默认会员关联的功能
|
|
|
+ if (assoPersonFunction == null) {
|
|
|
+ Vip vip = vipService.getDefaultVip();
|
|
|
+ AssoVipFunction assoVipFunction = assoVipFunctionService.getByVipUuidAndFunId(vip.getVipUuid(), functionUuid);
|
|
|
+ if (assoVipFunction != null) {
|
|
|
+ Date createDate = new Date();
|
|
|
+ Date expiryDate = DateUtils.getPlusMonthDate(createDate, vip.getLastTime());
|
|
|
+ assoPersonFunction = new AssoPersonFunction();
|
|
|
+ assoPersonFunction.setFunctionUuid(functionUuid);
|
|
|
+ assoPersonFunction.setExpiryTime(expiryDate);
|
|
|
+ assoPersonFunction.setCreateTime(createDate);
|
|
|
+ assoPersonFunction.setFunctionParameter(assoVipFunction.getFunctionParameter());
|
|
|
+ assoPersonFunction.setVipType(vip.getVipType());
|
|
|
+ assoPersonFunction.setVipUuid(vip.getVipUuid());
|
|
|
+ assoPersonFunction.setPersonUuid(personUuid);
|
|
|
+ assoPersonFunction.insert();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //设置键值
|
|
|
+ if (assoPersonFunction != null) {
|
|
|
+ redisService.setKeyLastToMidNight(redisKey, assoPersonFunction.getFunctionParameter());
|
|
|
+ }
|
|
|
+ functionConfig = JSON.parseObject(assoPersonFunction.getFunctionParameter(), FunctionConfig.class);
|
|
|
+
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ functionConfig = JSON.parseObject(String.valueOf(o), FunctionConfig.class);
|
|
|
+ }
|
|
|
+ if (functionConfig == null) {
|
|
|
+ throw new BusinessException("402", "无权限");
|
|
|
+ } else {
|
|
|
+ if (functionConfig.getCanGetNum() == 0) {
|
|
|
+ throw new BusinessException("402", "超过可使用次数");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return functionConfig;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
+ public void subFunctionCount(FunctionConfig functionConfig, String functionUuid) {
|
|
|
+ PersonnelVO personnelVO = cacheUtil.getLoginUser(LoginUtils.getToken());
|
|
|
+ String personUuid = personnelVO.getUuid();
|
|
|
+ functionConfig.setCanGetNum(functionConfig.getCanGetNum() - 1);
|
|
|
+ String redisKey = RedisConf.PERSON_FUNCTION + RedisConf.SYMBOL_COLON + personUuid + RedisConf.SYMBOL_COLON + functionUuid;
|
|
|
|
|
|
- public void addDefault() {
|
|
|
- //获得
|
|
|
- Vip vip = vipService.getDefaultVip();
|
|
|
- List<AssoVipFunction> assoVipFunctions = assoVipFunctionService.getVipFunctionByVipUuid(vip.getVipUuid());
|
|
|
+ redisService.setKeyLastToMidNight(redisKey, JsonUtils.objectToJson(functionConfig));
|
|
|
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|