|
|
@@ -3,6 +3,7 @@ package org.spring.ai.config.cms.controller.enterprise;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DatePattern;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
@@ -14,14 +15,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.spring.ai.config.biz.crud.entity.ActivationCode;
|
|
|
-import org.spring.ai.config.biz.crud.entity.AiDevice;
|
|
|
-import org.spring.ai.config.biz.crud.entity.Proxy;
|
|
|
-import org.spring.ai.config.biz.crud.entity.SalesPackage;
|
|
|
-import org.spring.ai.config.biz.crud.service.ActivationCodeService;
|
|
|
-import org.spring.ai.config.biz.crud.service.AiDeviceService;
|
|
|
-import org.spring.ai.config.biz.crud.service.ProxyService;
|
|
|
-import org.spring.ai.config.biz.crud.service.SalesPackageService;
|
|
|
+import org.apache.commons.lang3.math.NumberUtils;
|
|
|
+import org.spring.ai.config.biz.crud.entity.*;
|
|
|
+import org.spring.ai.config.biz.crud.service.*;
|
|
|
import org.spring.ai.config.cms.admctr.service.AdmPowerWebService;
|
|
|
import org.spring.ai.config.cms.entity.req.ActivationCodeAddReq;
|
|
|
import org.spring.ai.config.cms.entity.req.ActivationCodeListReq;
|
|
|
@@ -75,6 +71,9 @@ public class ActivationCodeController {
|
|
|
@Resource
|
|
|
private AdmPowerWebService admPowerWebService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private MgrUserInfoService mgrUserInfoService;
|
|
|
+
|
|
|
|
|
|
@ApiOperation(value = "激活码列表")
|
|
|
@PostMapping(value = "list")
|
|
|
@@ -83,12 +82,19 @@ public class ActivationCodeController {
|
|
|
if (activationCodeListReq == null) {
|
|
|
throw new BusinessException(ErrorCodeEnum.INPUT_PARAMETER_ERROR.getCode(), ErrorCodeEnum.INPUT_PARAMETER_ERROR.getDesc());
|
|
|
}
|
|
|
+ int adminId = admPowerWebService.getLoginAdminId(req.getAdminToken());
|
|
|
LambdaQueryWrapper<ActivationCode> queryWrapper = Wrappers.lambdaQuery();
|
|
|
queryWrapper.eq(StrUtil.isNotBlank(activationCodeListReq.getActivationCode()), ActivationCode::getActivationCode, activationCodeListReq.getActivationCode());
|
|
|
queryWrapper.eq(activationCodeListReq.getPackageType() != null, ActivationCode::getPackageType, activationCodeListReq.getPackageType());
|
|
|
- queryWrapper.eq(activationCodeListReq.getProxyId() != null, ActivationCode::getProxyId, activationCodeListReq.getProxyId());
|
|
|
queryWrapper.eq(activationCodeListReq.getTiming() != null, ActivationCode::getTiming, activationCodeListReq.getTiming());
|
|
|
queryWrapper.eq(activationCodeListReq.getTiming() != null, ActivationCode::getTimeUnit, activationCodeListReq.getTimeUnit());
|
|
|
+ if (adminId != 1) {
|
|
|
+ MgrUserInfo mgrUserInfo = mgrUserInfoService.getById(adminId);
|
|
|
+ Integer proxyId = mgrUserInfo == null ? null : mgrUserInfo.getProxyId();
|
|
|
+ queryWrapper.eq(ActivationCode::getProxyId, proxyId);
|
|
|
+ } else {
|
|
|
+ queryWrapper.eq(activationCodeListReq.getProxyId() != null, ActivationCode::getProxyId, activationCodeListReq.getProxyId());
|
|
|
+ }
|
|
|
queryWrapper.orderByAsc(ActivationCode::getIsUse);
|
|
|
queryWrapper.orderByDesc(ActivationCode::getCreateTime);
|
|
|
IPage<ActivationCode> iPage = activationCodeService.page(new Page<>(req.getPage(), req.getPageSize()), queryWrapper);
|
|
|
@@ -116,22 +122,44 @@ public class ActivationCodeController {
|
|
|
if (activationCodeAddReq == null) {
|
|
|
throw new BusinessException(ErrorCodeEnum.INPUT_PARAMETER_ERROR.getCode(), ErrorCodeEnum.INPUT_PARAMETER_ERROR.getDesc());
|
|
|
}
|
|
|
+ int adminId = admPowerWebService.getLoginAdminId(req.getAdminToken());
|
|
|
SalesPackage salesPackage = salesPackageService.getById(activationCodeAddReq.getSalesPackageId());
|
|
|
if (salesPackage == null) {
|
|
|
throw new BusinessException(ErrorCodeEnum.FAIL.getCode(), "套餐不存在");
|
|
|
}
|
|
|
+ boolean result = true;
|
|
|
+ Integer proxId = activationCodeAddReq.getProxyId();
|
|
|
+ if (adminId != 1) {
|
|
|
+ MgrUserInfo mgrUserInfo = mgrUserInfoService.getById(adminId);
|
|
|
+ if (mgrUserInfo == null || mgrUserInfo.getProxyId() == null) {
|
|
|
+ throw new BusinessException(ErrorCodeEnum.FAIL.getCode(), "未绑定代理");
|
|
|
+ }
|
|
|
+ proxId = mgrUserInfo.getProxyId();
|
|
|
+ int monthNum;
|
|
|
+ if (ObjectUtil.equals(salesPackage.getTimeUnit(), NumberUtils.INTEGER_ONE)) {
|
|
|
+ monthNum = activationCodeAddReq.getAddNum();
|
|
|
+ } else {
|
|
|
+ monthNum = activationCodeAddReq.getAddNum() * 12;
|
|
|
+ }
|
|
|
+ //扣减代理月份
|
|
|
+ result = proxyService.minusMonth(proxId, monthNum);
|
|
|
+ }
|
|
|
List<ActivationCode> insertList = new LinkedList<>();
|
|
|
for (int i = 0; i < activationCodeAddReq.getAddNum(); i++) {
|
|
|
ActivationCode activationCode = new ActivationCode();
|
|
|
BeanUtil.copyProperties(salesPackage, activationCode, "id");
|
|
|
- activationCode.setProxyId(activationCodeAddReq.getProxyId());
|
|
|
+ activationCode.setProxyId(proxId);
|
|
|
activationCode.setActivationCode(RandomUtil.randomString(4) + "-" + RandomUtil.randomString(4) + "-" + RandomUtil.randomString(4));
|
|
|
activationCode.setCreateTime(LocalDateTime.now());
|
|
|
activationCode.setUpdateTime(LocalDateTime.now());
|
|
|
activationCode.setIsUse(YesNoEnum.NO.getCode());
|
|
|
insertList.add(activationCode);
|
|
|
}
|
|
|
- boolean result = activationCodeService.batchInsert(insertList);
|
|
|
+ if (result) {
|
|
|
+ result = activationCodeService.batchInsert(insertList);
|
|
|
+ } else {
|
|
|
+ throw new BusinessException(ErrorCodeEnum.FAIL.getCode(), "代理可生成套餐额度不足");
|
|
|
+ }
|
|
|
return result ? Result.success() : Result.error("批量生成失败");
|
|
|
}
|
|
|
|
|
|
@@ -184,10 +212,17 @@ public class ActivationCodeController {
|
|
|
* @return: java.util.List<org.spring.ai.config.cms.entity.vo.ExportActivationVo>
|
|
|
*/
|
|
|
public List<ExportActivationVo> getExportActivationVoList(ActivationCodeListReq activationCodeListReq) {
|
|
|
+ int adminId = admPowerWebService.getLoginAdminId(activationCodeListReq.getAdminToken());
|
|
|
LambdaQueryWrapper<ActivationCode> queryWrapper = Wrappers.lambdaQuery();
|
|
|
queryWrapper.eq(StrUtil.isNotBlank(activationCodeListReq.getActivationCode()), ActivationCode::getActivationCode, activationCodeListReq.getActivationCode());
|
|
|
queryWrapper.eq(activationCodeListReq.getPackageType() != null, ActivationCode::getPackageType, activationCodeListReq.getPackageType());
|
|
|
- queryWrapper.eq(activationCodeListReq.getProxyId() != null, ActivationCode::getProxyId, activationCodeListReq.getProxyId());
|
|
|
+ if (adminId != 1) {
|
|
|
+ MgrUserInfo mgrUserInfo = mgrUserInfoService.getById(adminId);
|
|
|
+ Integer proxyId = mgrUserInfo == null ? null : mgrUserInfo.getProxyId();
|
|
|
+ queryWrapper.eq(ActivationCode::getProxyId, proxyId);
|
|
|
+ } else {
|
|
|
+ queryWrapper.eq(activationCodeListReq.getProxyId() != null, ActivationCode::getProxyId, activationCodeListReq.getProxyId());
|
|
|
+ }
|
|
|
queryWrapper.eq(activationCodeListReq.getTiming() != null, ActivationCode::getTiming, activationCodeListReq.getTiming());
|
|
|
queryWrapper.eq(activationCodeListReq.getTiming() != null, ActivationCode::getTimeUnit, activationCodeListReq.getTimeUnit());
|
|
|
queryWrapper.eq(ActivationCode::getIsUse, YesNoEnum.NO.getCode());
|