From 3c5723e2b832823fc63e6d8cd1460b2e003583db Mon Sep 17 00:00:00 2001 From: peng <peng.com> Date: 星期一, 29 九月 2025 17:16:38 +0800 Subject: [PATCH] 抽奖活动添加次数规则 --- framework/src/main/java/cn/lili/modules/lmk/domain/vo/AddPrizeRuleVO.java | 47 +++++ framework/src/main/java/cn/lili/modules/lmk/mapper/AddPrizeRuleMapper.java | 34 ++++ framework/src/main/java/cn/lili/modules/lmk/service/impl/AddPrizeRuleServiceImpl.java | 119 ++++++++++++++ framework/src/main/java/cn/lili/modules/lmk/domain/entity/AddPrizeRule.java | 38 ++++ framework/src/main/java/cn/lili/modules/lmk/domain/query/AddPrizeRuleQuery.java | 22 ++ framework/src/main/resources/mapper/lmk/AddPrizeRuleMapper.xml | 47 +++++ framework/src/main/java/cn/lili/modules/lmk/service/AddPrizeRuleService.java | 65 ++++++++ framework/src/main/java/cn/lili/modules/lmk/domain/form/AddPrizeRuleForm.java | 50 ++++++ 8 files changed, 422 insertions(+), 0 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/entity/AddPrizeRule.java b/framework/src/main/java/cn/lili/modules/lmk/domain/entity/AddPrizeRule.java new file mode 100644 index 0000000..8cf1e3b --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/lmk/domain/entity/AddPrizeRule.java @@ -0,0 +1,38 @@ +package cn.lili.modules.lmk.domain.entity; + +import cn.lili.mybatis.BaseEntity; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import java.io.Serializable; +import lombok.Data; + +/** + * 鎶藉鐢ㄦ埛瑙勫垯閰嶇疆 + * + * @author peng + * @since 2025-09-29 + */ +@Data +@TableName("lmk_add_prize_rule") +public class AddPrizeRule extends BaseEntity { + + private static final long serialVersionUID = 1L; + + @TableField("rule_name") + /** 瑙勫垯鍚嶇О */ + private String ruleName; + + @TableField("rule_code") + /** 瑙勫垯缂栫爜 */ + private String ruleCode; + + @TableField("rule_value") + /** 瑙勫垯鍊� */ + private String ruleValue; + + @TableField("add_num") + /** 澧炲姞娆℃暟 */ + private Integer addNum; + + +} diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/form/AddPrizeRuleForm.java b/framework/src/main/java/cn/lili/modules/lmk/domain/form/AddPrizeRuleForm.java new file mode 100644 index 0000000..d919bad --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/lmk/domain/form/AddPrizeRuleForm.java @@ -0,0 +1,50 @@ +package cn.lili.modules.lmk.domain.form; + +import cn.lili.group.Update; +import cn.lili.group.Add; +import cn.lili.base.AbsForm; +import cn.lili.modules.lmk.domain.entity.AddPrizeRule; +import org.springframework.beans.BeanUtils; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import org.springframework.lang.NonNull; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import java.util.Date; + +/** + * 鎶藉鐢ㄦ埛瑙勫垯閰嶇疆琛ㄥ崟 + * + * @author peng + * @since 2025-09-29 + */ +@Data +@ApiModel(value = "AddPrizeRule琛ㄥ崟", description = "鎶藉鐢ㄦ埛瑙勫垯閰嶇疆琛ㄥ崟") +public class AddPrizeRuleForm extends AbsForm { + + @NotBlank(message = "瑙勫垯鍚嶇О涓嶈兘涓虹┖", groups = {Add.class, Update.class}) + @ApiModelProperty("瑙勫垯鍚嶇О") + private String ruleName; + + @NotBlank(message = "瑙勫垯缂栫爜涓嶈兘涓虹┖", groups = {Add.class, Update.class}) + @ApiModelProperty("瑙勫垯缂栫爜") + private String ruleCode; + + @NotBlank(message = "瑙勫垯鍊间笉鑳戒负绌�", groups = {Add.class, Update.class}) + @ApiModelProperty("瑙勫垯鍊�") + private String ruleValue; + + @NotNull(message = "澧炲姞娆℃暟涓嶈兘涓虹┖", groups = {Add.class, Update.class}) + @ApiModelProperty("澧炲姞娆℃暟") + private Integer addNum; + + public static AddPrizeRule getEntityByForm(@NonNull AddPrizeRuleForm form, AddPrizeRule entity) { + if(entity == null) { + entity = new AddPrizeRule(); + } + BeanUtils.copyProperties(form, entity); + return entity; + } + +} diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/query/AddPrizeRuleQuery.java b/framework/src/main/java/cn/lili/modules/lmk/domain/query/AddPrizeRuleQuery.java new file mode 100644 index 0000000..8a1fc2b --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/lmk/domain/query/AddPrizeRuleQuery.java @@ -0,0 +1,22 @@ +package cn.lili.modules.lmk.domain.query; + +import cn.lili.base.AbsQuery; +import java.util.List; +import org.springframework.lang.NonNull; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * 鎶藉鐢ㄦ埛瑙勫垯閰嶇疆鏌ヨ + * + * @author peng + * @since 2025-09-29 + */ +@Data +@ApiModel(value = "AddPrizeRule鏌ヨ鍙傛暟", description = "鎶藉鐢ㄦ埛瑙勫垯閰嶇疆鏌ヨ鍙傛暟") +public class AddPrizeRuleQuery extends AbsQuery { +} + diff --git a/framework/src/main/java/cn/lili/modules/lmk/domain/vo/AddPrizeRuleVO.java b/framework/src/main/java/cn/lili/modules/lmk/domain/vo/AddPrizeRuleVO.java new file mode 100644 index 0000000..04647bf --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/lmk/domain/vo/AddPrizeRuleVO.java @@ -0,0 +1,47 @@ +package cn.lili.modules.lmk.domain.vo; + +import cn.lili.base.AbsVo; +import cn.lili.modules.lmk.domain.entity.AddPrizeRule; +import java.util.List; +import org.springframework.lang.NonNull; +import org.springframework.beans.BeanUtils; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import java.util.Date; + +/** + * 鎶藉鐢ㄦ埛瑙勫垯閰嶇疆灞曠ず + * + * @author peng + * @since 2025-09-29 + */ +@Data +@ApiModel(value = "鎶藉鐢ㄦ埛瑙勫垯閰嶇疆鍝嶅簲鏁版嵁", description = "鎶藉鐢ㄦ埛瑙勫垯閰嶇疆鍝嶅簲鏁版嵁") +public class AddPrizeRuleVO extends AbsVo { + + /** 瑙勫垯鍚嶇О */ + @ApiModelProperty("瑙勫垯鍚嶇О") + private String ruleName; + + /** 瑙勫垯缂栫爜 */ + @ApiModelProperty("瑙勫垯缂栫爜") + private String ruleCode; + + /** 瑙勫垯鍊� */ + @ApiModelProperty("瑙勫垯鍊�") + private String ruleValue; + + /** 澧炲姞娆℃暟 */ + @ApiModelProperty("澧炲姞娆℃暟") + private Integer addNum; + + public static AddPrizeRuleVO getVoByEntity(@NonNull AddPrizeRule entity, AddPrizeRuleVO vo) { + if(vo == null) { + vo = new AddPrizeRuleVO(); + } + BeanUtils.copyProperties(entity, vo); + return vo; + } + +} diff --git a/framework/src/main/java/cn/lili/modules/lmk/mapper/AddPrizeRuleMapper.java b/framework/src/main/java/cn/lili/modules/lmk/mapper/AddPrizeRuleMapper.java new file mode 100644 index 0000000..7324216 --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/lmk/mapper/AddPrizeRuleMapper.java @@ -0,0 +1,34 @@ +package cn.lili.modules.lmk.mapper; + +import cn.lili.modules.lmk.domain.entity.AddPrizeRule; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import cn.lili.modules.lmk.domain.vo.AddPrizeRuleVO; +import cn.lili.modules.lmk.domain.form.AddPrizeRuleForm; +import cn.lili.modules.lmk.domain.query.AddPrizeRuleQuery; +import java.util.List; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * 鎶藉鐢ㄦ埛瑙勫垯閰嶇疆 Mapper 鎺ュ彛 + * + * @author peng + * @since 2025-09-29 + */ +@Mapper +public interface AddPrizeRuleMapper extends BaseMapper<AddPrizeRule> { + + /** + * id鏌ユ壘鎶藉鐢ㄦ埛瑙勫垯閰嶇疆 + * @param id + * @return + */ + AddPrizeRuleVO getById(String id); + + /** + * 鍒嗛〉 + */ + IPage getPage(IPage page, @Param("query") AddPrizeRuleQuery query); + +} diff --git a/framework/src/main/java/cn/lili/modules/lmk/service/AddPrizeRuleService.java b/framework/src/main/java/cn/lili/modules/lmk/service/AddPrizeRuleService.java new file mode 100644 index 0000000..8f69aa5 --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/lmk/service/AddPrizeRuleService.java @@ -0,0 +1,65 @@ +package cn.lili.modules.lmk.service; + +import cn.lili.modules.lmk.domain.entity.AddPrizeRule; +import com.baomidou.mybatisplus.extension.service.IService; +import cn.lili.base.Result; +import cn.lili.modules.lmk.domain.form.AddPrizeRuleForm; +import cn.lili.modules.lmk.domain.query.AddPrizeRuleQuery; +import java.util.List; + +/** + * 鎶藉鐢ㄦ埛瑙勫垯閰嶇疆 鏈嶅姟绫� + * + * @author peng + * @since 2025-09-29 + */ +public interface AddPrizeRuleService extends IService<AddPrizeRule> { + + /** + * 娣诲姞 + * @param form + * @return + */ + Result add(AddPrizeRuleForm form); + + /** + * 淇敼 + * @param form + * @return + */ + Result update(AddPrizeRuleForm form); + + /** + * 鎵归噺鍒犻櫎 + * @param ids + * @return + */ + Result remove(List<String> ids); + + /** + * id鍒犻櫎 + * @param id + * @return + */ + Result removeById(String id); + + /** + * 鍒嗛〉鏌ヨ + * @param query + * @return + */ + Result page(AddPrizeRuleQuery query); + + /** + * 鏍规嵁id鏌ユ壘 + * @param id + * @return + */ + Result detail(String id); + + /** + * 鍒楄〃 + * @return + */ + Result all(); +} diff --git a/framework/src/main/java/cn/lili/modules/lmk/service/impl/AddPrizeRuleServiceImpl.java b/framework/src/main/java/cn/lili/modules/lmk/service/impl/AddPrizeRuleServiceImpl.java new file mode 100644 index 0000000..74d1b90 --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/lmk/service/impl/AddPrizeRuleServiceImpl.java @@ -0,0 +1,119 @@ +package cn.lili.modules.lmk.service.impl; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import cn.lili.modules.lmk.domain.entity.AddPrizeRule; +import cn.lili.modules.lmk.mapper.AddPrizeRuleMapper; +import cn.lili.modules.lmk.service.AddPrizeRuleService; +import cn.lili.base.Result; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import cn.lili.modules.lmk.domain.form.AddPrizeRuleForm; +import cn.lili.modules.lmk.domain.vo.AddPrizeRuleVO; +import cn.lili.modules.lmk.domain.query.AddPrizeRuleQuery; +import org.springframework.stereotype.Service; +import lombok.RequiredArgsConstructor; +import cn.lili.utils.PageUtil; +import org.springframework.beans.BeanUtils; +import org.springframework.util.Assert; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * 鎶藉鐢ㄦ埛瑙勫垯閰嶇疆 鏈嶅姟瀹炵幇绫� + * + * @author peng + * @since 2025-09-29 + */ +@Service +@RequiredArgsConstructor +public class AddPrizeRuleServiceImpl extends ServiceImpl<AddPrizeRuleMapper, AddPrizeRule> implements AddPrizeRuleService { + + private final AddPrizeRuleMapper addPrizeRuleMapper; + + /** + * 娣诲姞 + * @param form + * @return + */ + @Override + public Result add(AddPrizeRuleForm form) { + AddPrizeRule entity = AddPrizeRuleForm.getEntityByForm(form, null); + baseMapper.insert(entity); + return Result.ok("娣诲姞鎴愬姛"); + } + + /** + * 淇敼 + * @param form + * @return + */ + @Override + public Result update(AddPrizeRuleForm form) { + AddPrizeRule entity = baseMapper.selectById(form.getId()); + + // 涓虹┖鎶汭llegalArgumentException锛屽仛鍏ㄥ眬寮傚父澶勭悊 + Assert.notNull(entity, "璁板綍涓嶅瓨鍦�"); + BeanUtils.copyProperties(form, entity); + baseMapper.updateById(entity); + return Result.ok("淇敼鎴愬姛"); + } + + /** + * 鎵归噺鍒犻櫎 + * @param ids + * @return + */ + @Override + public Result remove(List<String> ids) { + baseMapper.deleteBatchIds(ids); + return Result.ok("鍒犻櫎鎴愬姛"); + } + + /** + * id鍒犻櫎 + * @param id + * @return + */ + @Override + public Result removeById(String id) { + baseMapper.deleteById(id); + return Result.ok("鍒犻櫎鎴愬姛"); + } + + /** + * 鍒嗛〉鏌ヨ + * @param query + * @return + */ + @Override + public Result page(AddPrizeRuleQuery query) { + IPage<AddPrizeRuleVO> page = PageUtil.getPage(query, AddPrizeRuleVO.class); + baseMapper.getPage(page, query); + return Result.ok().data(page.getRecords()).total(page.getTotal()); + } + + /** + * 鏍规嵁id鏌ユ壘 + * @param id + * @return + */ + @Override + public Result detail(String id) { + AddPrizeRuleVO vo = baseMapper.getById(id); + Assert.notNull(vo, "璁板綍涓嶅瓨鍦�"); + return Result.ok().data(vo); + } + + /** + * 鍒楄〃 + * @return + */ + @Override + public Result all() { + List<AddPrizeRule> entities = baseMapper.selectList(null); + List<AddPrizeRuleVO> vos = entities.stream() + .map(entity -> AddPrizeRuleVO.getVoByEntity(entity, null)) + .collect(Collectors.toList()); + return Result.ok().data(vos); + } +} diff --git a/framework/src/main/resources/mapper/lmk/AddPrizeRuleMapper.xml b/framework/src/main/resources/mapper/lmk/AddPrizeRuleMapper.xml new file mode 100644 index 0000000..c279730 --- /dev/null +++ b/framework/src/main/resources/mapper/lmk/AddPrizeRuleMapper.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="cn.lili.modules.lmk.mapper.AddPrizeRuleMapper"> + + <!-- 閫氱敤鏌ヨ鏄犲皠缁撴灉 --> + <resultMap id="BaseResultMap" type="cn.lili.modules.lmk.domain.vo.AddPrizeRuleVO"> + <id column="id" property="id"/> + <result column="rule_name" property="ruleName" /> + <result column="rule_code" property="ruleCode" /> + <result column="rule_value" property="ruleValue" /> + <result column="add_num" property="addNum" /> + </resultMap> + + + + + + + + <select id="getById" resultMap="BaseResultMap"> + SELECT + LAPR.rule_name, + LAPR.rule_code, + LAPR.rule_value, + LAPR.add_num, + LAPR.id + FROM + lmk_add_prize_rule LAPR + WHERE + LAPR.id = #{id} AND LAPR.delete_flag = 0 + </select> + + + <select id="getPage" resultMap="BaseResultMap"> + SELECT + LAPR.rule_name, + LAPR.rule_code, + LAPR.rule_value, + LAPR.add_num, + LAPR.id + FROM + lmk_add_prize_rule LAPR + WHERE + LAPR.delete_flag = 0 + </select> + +</mapper> -- Gitblit v1.8.0