|
|
@@ -0,0 +1,105 @@
|
|
|
+package com.cyksj.web.controller.manage;
|
|
|
+
|
|
|
+import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
+import com.cyksj.common.annotation.Log;
|
|
|
+import com.cyksj.dto.Result;
|
|
|
+import com.cyksj.enums.BusinessType;
|
|
|
+import com.cyksj.enums.GatewayResponse;
|
|
|
+import com.cyksj.model.entity.NanoUserQuota;
|
|
|
+import com.cyksj.service.quota.NanoUserQuotaService;
|
|
|
+import com.ejlchina.searcher.BeanSearcher;
|
|
|
+import com.ejlchina.searcher.SearchResult;
|
|
|
+import com.ejlchina.searcher.util.MapUtils;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 用户固定配额管理接口
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
+@RestController
|
|
|
+@RequestMapping("/manage/nanoUserQuota")
|
|
|
+public class NanoUserQuotaController {
|
|
|
+
|
|
|
+ private final HttpServletRequest request;
|
|
|
+ private final BeanSearcher beanSearcher;
|
|
|
+ private final NanoUserQuotaService nanoUserQuotaService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询用户配额列表
|
|
|
+ */
|
|
|
+ @GetMapping("/list")
|
|
|
+ public Result<SearchResult<NanoUserQuota>> list() {
|
|
|
+ SearchResult<NanoUserQuota> search = beanSearcher.search(NanoUserQuota.class,
|
|
|
+ MapUtils.flatBuilder(request.getParameterMap()).build());
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据ID获取用户配额详情
|
|
|
+ */
|
|
|
+ @GetMapping("/{id}")
|
|
|
+ public Result<NanoUserQuota> getById(@PathVariable Long id) {
|
|
|
+ NanoUserQuota quota = nanoUserQuotaService.getById(id);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(quota);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增用户配额
|
|
|
+ */
|
|
|
+ @PostMapping
|
|
|
+ public Result<String> add(@RequestBody @Validated NanoUserQuota quota) {
|
|
|
+ nanoUserQuotaService.save(quota);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改用户配额
|
|
|
+ */
|
|
|
+ @PutMapping
|
|
|
+ public Result<String> update(@RequestBody @Validated NanoUserQuota quota) {
|
|
|
+ nanoUserQuotaService.updateById(quota);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除用户配额
|
|
|
+ */
|
|
|
+ @DeleteMapping("/{id}")
|
|
|
+ public Result<String> delete(@PathVariable Long id) {
|
|
|
+ nanoUserQuotaService.removeById(id);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据用户token获取配额信息
|
|
|
+ */
|
|
|
+ @GetMapping("/token/{userToken}")
|
|
|
+ public Result<NanoUserQuota> getByUserToken(@PathVariable String userToken) {
|
|
|
+ NanoUserQuota quota = nanoUserQuotaService.getByUserToken(userToken);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(quota);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据用户ID获取配额信息
|
|
|
+ */
|
|
|
+ @GetMapping("/uid/{uid}")
|
|
|
+ public Result<NanoUserQuota> getByUid(@PathVariable Long uid) {
|
|
|
+ NanoUserQuota quota = nanoUserQuotaService.getByUid(uid);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(quota);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新配额使用情况
|
|
|
+ */
|
|
|
+ @PutMapping("/usage/{id}")
|
|
|
+ public Result<String> updateUsage(@PathVariable Long id, @RequestParam Integer usedQuota) {
|
|
|
+ nanoUserQuotaService.updateUsage(id, usedQuota);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+}
|