|
|
@@ -0,0 +1,93 @@
|
|
|
+package com.etotem.cfc.controller.admin;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
+import com.etotem.cfc.entity.ProblemDomain;
|
|
|
+import com.etotem.cfc.mapper.ProblemDomainMapper;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestAttribute;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 管理端-问题域 CRUD(改版v1,W1)
|
|
|
+ */
|
|
|
+@Tag(name = "管理端-问题域", description = "问题域 CRUD 管理")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/admin/problem-domain")
|
|
|
+public class AdminProblemDomainController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ProblemDomainMapper problemDomainMapper;
|
|
|
+
|
|
|
+ @Operation(summary = "问题域列表(含停用,管理端)")
|
|
|
+ @PostMapping("/list")
|
|
|
+ public Result<List<ProblemDomain>> list(@RequestBody Map<String, Object> params) {
|
|
|
+ LambdaQueryWrapper<ProblemDomain> wrapper = new LambdaQueryWrapper<ProblemDomain>()
|
|
|
+ .orderByAsc(ProblemDomain::getSortOrder)
|
|
|
+ .orderByAsc(ProblemDomain::getId);
|
|
|
+ // 可选状态过滤
|
|
|
+ if (params != null && params.get("status") != null) {
|
|
|
+ wrapper.eq(ProblemDomain::getStatus, Integer.parseInt(params.get("status").toString()));
|
|
|
+ }
|
|
|
+ return Result.success(problemDomainMapper.selectList(wrapper));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "新增/更新问题域")
|
|
|
+ @PostMapping("/save")
|
|
|
+ public Result<ProblemDomain> save(@RequestBody ProblemDomain domain, @RequestAttribute("userId") Long userId) {
|
|
|
+ if (domain.getCode() == null || domain.getCode().isEmpty()) {
|
|
|
+ return Result.error("编码不能为空");
|
|
|
+ }
|
|
|
+ if (domain.getName() == null || domain.getName().isEmpty()) {
|
|
|
+ return Result.error("名称不能为空");
|
|
|
+ }
|
|
|
+ // 编码唯一性校验
|
|
|
+ ProblemDomain exists = problemDomainMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<ProblemDomain>()
|
|
|
+ .eq(ProblemDomain::getCode, domain.getCode())
|
|
|
+ .last("LIMIT 1"));
|
|
|
+ if (exists != null && (domain.getId() == null || !exists.getId().equals(domain.getId()))) {
|
|
|
+ return Result.error("编码已存在: " + domain.getCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ Date now = new Date();
|
|
|
+ if (domain.getId() == null) {
|
|
|
+ if (domain.getStatus() == null) {
|
|
|
+ domain.setStatus(1);
|
|
|
+ }
|
|
|
+ if (domain.getRewardCfValue() == null) {
|
|
|
+ domain.setRewardCfValue(0);
|
|
|
+ }
|
|
|
+ if (domain.getSortOrder() == null) {
|
|
|
+ domain.setSortOrder(0);
|
|
|
+ }
|
|
|
+ domain.setCreatedAt(now);
|
|
|
+ domain.setUpdatedAt(now);
|
|
|
+ problemDomainMapper.insert(domain);
|
|
|
+ } else {
|
|
|
+ domain.setUpdatedAt(now);
|
|
|
+ problemDomainMapper.updateById(domain);
|
|
|
+ }
|
|
|
+ return Result.success(domain);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "删除问题域")
|
|
|
+ @PostMapping("/delete")
|
|
|
+ public Result<Void> delete(@RequestBody Map<String, Object> params, @RequestAttribute("userId") Long userId) {
|
|
|
+ Long id = params.get("id") != null ? Long.valueOf(params.get("id").toString()) : null;
|
|
|
+ if (id == null) {
|
|
|
+ return Result.error("缺少 id");
|
|
|
+ }
|
|
|
+ problemDomainMapper.deleteById(id);
|
|
|
+ return Result.success(null);
|
|
|
+ }
|
|
|
+}
|