Bläddra i källkod

新增情侣套餐规则管理相关接口

codingliang 10 månader sedan
förälder
incheckning
6739289e9c

+ 66 - 0
src/main/java/com/sqx/modules/lovers/controller/LoversSetRuleController.java

@@ -0,0 +1,66 @@
+package com.sqx.modules.lovers.controller;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.sqx.common.exception.SqxException;
+import com.sqx.common.utils.PageUtils;
+import com.sqx.common.utils.Result;
+import com.sqx.modules.lovers.dto.LoversSetRuleDTO;
+import com.sqx.modules.lovers.dto.LoversSetRuleQueryDTO;
+import com.sqx.modules.lovers.service.LoversSetRuleService;
+import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.validation.Valid;
+
+/**
+ * 情侣套餐-规则
+ *
+ * @author codingliang
+ * @date 2025-08-22
+ */
+@RestController
+@RequestMapping("lovers-set-rule")
+@RequiredArgsConstructor
+public class LoversSetRuleController {
+
+    private final LoversSetRuleService loversSetRuleService;
+
+    @GetMapping("page")
+    @ApiOperation("情侣套餐规则分页")
+    public Result page(LoversSetRuleQueryDTO queryDTO) {
+        PageUtils page = loversSetRuleService.page(queryDTO);
+        return Result.success().put("data", page);
+    }
+
+    @PostMapping
+    @ApiOperation("新增情侣套餐规则")
+    public Result add(@Valid LoversSetRuleDTO loversSetRule) {
+        loversSetRuleService.add(loversSetRule);
+        return Result.success();
+    }
+
+    @PutMapping
+    @ApiOperation("修改情侣套餐规则")
+    public Result update(@Valid LoversSetRuleDTO loversSetRule) {
+        if (ObjectUtil.isNull(loversSetRule.getId())) {
+            throw new SqxException("规则ID不能为空");
+        }
+
+        loversSetRuleService.update(loversSetRule);
+        return Result.success();
+    }
+
+    @DeleteMapping("{id}")
+    @ApiOperation("删除情侣套餐规则")
+    public Result delete(@PathVariable String id) {
+        loversSetRuleService.removeById(id);
+        return Result.success();
+    }
+}

+ 27 - 0
src/main/java/com/sqx/modules/lovers/dto/LoversSetRuleDTO.java

@@ -0,0 +1,27 @@
+package com.sqx.modules.lovers.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+
+@Data
+public class LoversSetRuleDTO implements Serializable {
+
+    @ApiModelProperty("id")
+    private Long id;
+
+    @ApiModelProperty("规则名称")
+    @NotBlank(message = "规则名称不能为空")
+    private String name;
+
+    @ApiModelProperty("排序")
+    @NotNull(message = "排序不能为空")
+    private Integer sort;
+
+    @ApiModelProperty("规则内容")
+    @NotBlank(message = "规则内容不能为空")
+    private String content;
+}

+ 17 - 0
src/main/java/com/sqx/modules/lovers/dto/LoversSetRuleQueryDTO.java

@@ -0,0 +1,17 @@
+package com.sqx.modules.lovers.dto;
+
+import com.sqx.common.query.PageQuery;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * @author codingliang
+ * @date 2025-08-22
+ */
+@Data
+public class LoversSetRuleQueryDTO extends PageQuery {
+
+    @ApiModelProperty("规则名称")
+    private String name;
+
+}

+ 9 - 0
src/main/java/com/sqx/modules/lovers/service/LoversSetRuleService.java

@@ -1,7 +1,16 @@
 package com.sqx.modules.lovers.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.sqx.common.utils.PageUtils;
+import com.sqx.modules.lovers.dto.LoversSetRuleDTO;
+import com.sqx.modules.lovers.dto.LoversSetRuleQueryDTO;
 import com.sqx.modules.lovers.entity.LoversSetRule;
 
 public interface LoversSetRuleService extends IService<LoversSetRule> {
+
+    PageUtils page(LoversSetRuleQueryDTO queryDTO);
+
+    void add(LoversSetRuleDTO loversSetRule);
+
+    void update(LoversSetRuleDTO loversSetRule);
 }

+ 64 - 0
src/main/java/com/sqx/modules/lovers/service/impl/LoversSetRuleServiceImpl.java

@@ -1,11 +1,75 @@
 package com.sqx.modules.lovers.service.impl;
 
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.sqx.common.exception.SqxException;
+import com.sqx.common.utils.PageUtils;
 import com.sqx.modules.lovers.dao.LoversSetRuleDao;
+import com.sqx.modules.lovers.dto.LoversSetRuleDTO;
+import com.sqx.modules.lovers.dto.LoversSetRuleQueryDTO;
 import com.sqx.modules.lovers.entity.LoversSetRule;
 import com.sqx.modules.lovers.service.LoversSetRuleService;
+import com.sqx.modules.lovers.vo.LoversSetRuleVO;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+import java.util.stream.Collectors;
+
 @Service
 public class LoversSetRuleServiceImpl extends ServiceImpl<LoversSetRuleDao, LoversSetRule> implements LoversSetRuleService {
+
+    @Override
+    public PageUtils page(LoversSetRuleQueryDTO queryDTO) {
+        Page<LoversSetRule> pages = new Page<>(queryDTO.getPage(), queryDTO.getLimit());
+        LambdaQueryWrapper<LoversSetRule> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(StrUtil.isNotBlank(queryDTO.getName()), LoversSetRule::getName, queryDTO.getName());
+
+        IPage<LoversSetRule> page = this.page(pages, queryWrapper);
+        PageUtils pageUtils = new PageUtils(page);
+
+        List<LoversSetRuleVO> vos = pageUtils.getList().stream().map(e -> {
+            LoversSetRuleVO vo = new LoversSetRuleVO();
+            BeanUtil.copyProperties(e, vo);
+            return vo;
+        }).collect(Collectors.toList());
+
+        pageUtils.setList(vos);
+
+        return pageUtils;
+    }
+
+    @Override
+    public void add(LoversSetRuleDTO loversSetRule) {
+        // 检测名称是否重复
+        checkNameUnique(null, loversSetRule.getName());
+
+        LoversSetRule entity = new LoversSetRule();
+        BeanUtil.copyProperties(loversSetRule, entity);
+        entity.setDelFlag("0");
+
+        this.save(entity);
+    }
+
+    @Override
+    public void update(LoversSetRuleDTO loversSetRule) {
+        checkNameUnique(loversSetRule.getId(), loversSetRule.getName());
+
+        LoversSetRule entity = new LoversSetRule();
+        BeanUtil.copyProperties(loversSetRule, entity);
+        this.updateById(entity);
+    }
+
+    private void checkNameUnique(Long id, String name) {
+        LambdaQueryWrapper<LoversSetRule> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.ne(ObjectUtil.isNotNull(id), LoversSetRule::getId, id);
+        queryWrapper.eq(LoversSetRule::getName, name);
+        if (this.count(queryWrapper) > 0) {
+            throw new SqxException("规则名称重复");
+        }
+    }
 }

+ 22 - 0
src/main/java/com/sqx/modules/lovers/vo/LoversSetRuleVO.java

@@ -0,0 +1,22 @@
+package com.sqx.modules.lovers.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class LoversSetRuleVO implements Serializable {
+
+    @ApiModelProperty("主键id")
+    private Long id;
+
+    @ApiModelProperty("规则名称")
+    private String name;
+
+    @ApiModelProperty("排序")
+    private Integer sort;
+
+    @ApiModelProperty("规则内容")
+    private String content;
+}