后台-赠送钻石水晶-按用户角色每月限制赠送金币数-修改

This commit is contained in:
khalil
2025-07-16 19:17:24 +08:00
parent 89b3dc953e
commit a4449d80ad
2 changed files with 56 additions and 10 deletions

View File

@@ -3,6 +3,7 @@ package com.accompany.admin.service.record;
import com.accompany.admin.mapper.OfficialGoldRecordMapperExpand;
import com.accompany.admin.model.AdminRefUserRoleKey;
import com.accompany.admin.service.system.AdminRoleService;
import com.accompany.admin.service.system.SysConfAdminService;
import com.accompany.business.dto.OfficialGoldRoleLimitServiceConfigDto;
import com.accompany.common.constant.Constant;
import com.accompany.common.status.BusiStatus;
@@ -10,12 +11,14 @@ import com.accompany.common.utils.DateTimeUtil;
import com.accompany.core.exception.AdminServiceException;
import com.accompany.core.service.SysConfService;
import com.alibaba.fastjson2.JSON;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Nullable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
@@ -27,10 +30,18 @@ public class OfficialGoldRoleLimitService {
@Autowired
private SysConfService sysConfService;
@Autowired
private SysConfAdminService sysConfAdminService;
@Autowired
private AdminRoleService adminRoleService;
@Autowired
private OfficialGoldRecordMapperExpand recordMapperExpand;
@Nullable
public BigDecimal getLimitByRoleId(int roleId){
OfficialGoldRoleLimitServiceConfigDto config = getConfig();
return config.getRoleMonthlyLimitMap().get(roleId);
}
public boolean overLimit(int adminId){
OfficialGoldRoleLimitServiceConfigDto config = getConfig();
List<AdminRefUserRoleKey> roleKeyList = adminRoleService.getRoleByAdminId(adminId);
@@ -63,6 +74,19 @@ public class OfficialGoldRoleLimitService {
return true;
}
@SneakyThrows
public void saveRoleLimit(Integer roleId, BigDecimal officialMonthlyLimit) {
OfficialGoldRoleLimitServiceConfigDto config = getConfig();
BigDecimal limitValue = config.getRoleMonthlyLimitMap().get(roleId);
if (null != officialMonthlyLimit && !officialMonthlyLimit.equals(limitValue)) {
config.getRoleMonthlyLimitMap().put(roleId, officialMonthlyLimit);
sysConfAdminService.updateConfigValueById(Constant.SysConfId.OFFICIAL_GOLD_ROLE_LIMIT_CONFIG, JSON.toJSONString(config));
} else if (null == officialMonthlyLimit && null != limitValue){
config.getRoleMonthlyLimitMap().remove(roleId);
sysConfAdminService.updateConfigValueById(Constant.SysConfId.OFFICIAL_GOLD_ROLE_LIMIT_CONFIG, JSON.toJSONString(config));
}
}
private OfficialGoldRoleLimitServiceConfigDto getConfig(){
String configStr = sysConfService.getSysConfValueById(Constant.SysConfId.OFFICIAL_GOLD_ROLE_LIMIT_CONFIG);
if (!StringUtils.hasText(configStr)){
@@ -70,5 +94,4 @@ public class OfficialGoldRoleLimitService {
}
return JSON.parseObject(configStr, OfficialGoldRoleLimitServiceConfigDto.class);
}
}

View File

@@ -3,19 +3,28 @@ package com.accompany.admin.controller.system;
import com.accompany.admin.common.ErrorCode;
import com.accompany.admin.controller.BaseController;
import com.accompany.admin.model.AdminRole;
import com.accompany.admin.service.record.OfficialGoldRoleLimitService;
import com.accompany.admin.service.system.AdminMenuService;
import com.accompany.admin.service.system.AdminRoleService;
import com.accompany.common.status.BusiStatus;
import com.accompany.common.utils.BlankUtil;
import com.accompany.core.exception.AdminServiceException;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@Api(tags = "后台角色")
@Controller
@RequestMapping("/admin/role")
public class AdminRoleController extends BaseController {
@@ -25,6 +34,8 @@ public class AdminRoleController extends BaseController {
private AdminRoleService adminRoleService;
@Autowired
private AdminMenuService adminMenuService;
@Autowired
private OfficialGoldRoleLimitService officialGoldRoleLimitService;
/**
@@ -45,27 +56,39 @@ public class AdminRoleController extends BaseController {
@RequestMapping("/getone")
@ResponseBody
public void getAdminRole(Integer id) {
if (BlankUtil.isBlank(id)){
throw new AdminServiceException(BusiStatus.PARAMERROR);
}
JSONObject jsonObject = new JSONObject();
if (!BlankUtil.isBlank(id)) {
try {
AdminRole adminRole = adminRoleService.getRoleById(id);
if (adminRole != null) {
jsonObject.put("entity", adminRole);
}
} catch (Exception e) {
logger.warn("getAdminRole fail,cause by " + e.getMessage(), e);
try {
AdminRole adminRole = adminRoleService.getRoleById(id);
if (adminRole != null) {
jsonObject.put("entity", adminRole);
BigDecimal limit = officialGoldRoleLimitService.getLimitByRoleId(adminRole.getId());
jsonObject.put("officialMonthlyLimit", limit);
}
} catch (Exception e) {
logger.warn("getAdminRole fail,cause by " + e.getMessage(), e);
}
writeJson(jsonObject.toJSONString());
}
@ApiOperation("保存角色")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "角色id"),
@ApiImplicitParam(name = "name", value = "角色名", required = true),
@ApiImplicitParam(name = "officialMonthlyLimit", value = "角色每月赠送金币限制"),
})
@RequestMapping("/save")
@ResponseBody
public void saveRole(AdminRole adminRole, boolean isEdit) {
public void saveRole(AdminRole adminRole, boolean isEdit, BigDecimal officialMonthlyLimit) {
int result = -1;
if (adminRole != null) {
try {
result = adminRoleService.saveRole(adminRole, isEdit);
if (result > 0){
officialGoldRoleLimitService.saveRoleLimit(adminRole.getId(), officialMonthlyLimit);
}
} catch (Exception e) {
logger.warn("saveRole fail,cause by " + e.getMessage(), e);
}