优惠券PC端代码移植

This commit is contained in:
纪寒 2023-09-20 17:17:35 +08:00
parent 52d44b2e9a
commit 1a9d2eedd5
6 changed files with 770 additions and 0 deletions

View File

@ -0,0 +1,94 @@
package com.xinelu.manage.controller.coupon;
import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.custominterface.Insert;
import com.xinelu.common.custominterface.Update;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.coupon.Coupon;
import com.xinelu.manage.service.coupon.ICouponService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 优惠券信息Controller
*
* @author xinyilu
* @date 2023-02-23
*/
@RestController
@RequestMapping("/system/coupon")
public class CouponController extends BaseController {
@Resource
private ICouponService couponService;
/**
* 查询优惠券信息列表
*/
@PreAuthorize("@ss.hasPermi('system:coupon:list')")
@GetMapping("/list")
public TableDataInfo list(Coupon coupon) {
startPage();
List<Coupon> list = couponService.selectCouponList(coupon);
return getDataTable(list);
}
/**
* 导出优惠券信息列表
*/
@PreAuthorize("@ss.hasPermi('system:coupon:export')")
@Log(title = "优惠券信息", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, Coupon coupon) {
List<Coupon> list = couponService.selectCouponList(coupon);
ExcelUtil<Coupon> util = new ExcelUtil<>(Coupon.class);
util.exportExcel(response, list, "优惠券信息数据");
}
/**
* 获取优惠券信息详细信息
*/
@PreAuthorize("@ss.hasPermi('system:coupon:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) {
return AjaxResult.success(couponService.selectCouponById(id));
}
/**
* 新增优惠券信息
*/
@PreAuthorize("@ss.hasPermi('system:coupon:add')")
@Log(title = "优惠券信息", businessType = BusinessType.INSERT)
@PostMapping("/add")
public AjaxResult add(@Validated(value = Insert.class) @RequestBody Coupon coupon) {
return couponService.insertCoupon(coupon);
}
/**
* 修改优惠券信息
*/
@PreAuthorize("@ss.hasPermi('system:coupon:edit')")
@Log(title = "优惠券信息", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
public AjaxResult edit(@Validated(value = Update.class) @RequestBody Coupon coupon) {
return couponService.updateCoupon(coupon);
}
/**
* 删除优惠券信息
*/
@PreAuthorize("@ss.hasPermi('system:coupon:remove')")
@Log(title = "优惠券信息", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(couponService.deleteCouponByIds(ids));
}
}

View File

@ -0,0 +1,157 @@
package com.xinelu.manage.domain.coupon;
import com.xinelu.common.annotation.Excel;
import com.xinelu.common.core.domain.BaseDomain;
import com.xinelu.common.custominterface.Insert;
import com.xinelu.common.custominterface.Update;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* 优惠券信息对象 coupon
*
* @author xinyilu
* @date 2023-02-23
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "优惠券信息对象", description = "coupon")
public class Coupon extends BaseDomain implements Serializable {
private static final long serialVersionUID = -7531593448659387618L;
/**
* 主键id
*/
@NotNull(message = "优惠券信息id不能为空", groups = {Update.class})
private Long id;
/**
* 优惠券名称
*/
@ApiModelProperty(value = "优惠券名称")
@Excel(name = "优惠券名称")
@NotBlank(message = "优惠券名称不能为空", groups = {Insert.class, Update.class})
private String couponTitle;
/**
* 优惠券编码
*/
@ApiModelProperty(value = "优惠券编码")
@Excel(name = "优惠券编码")
private String couponCode;
/**
* 优惠券类型满减券FULL_REDUCTION_COUPON代金券CASH_COUPON兑换券EXCHANGE_COUPON折扣券DISCOUNT_COUPON
*/
@ApiModelProperty(value = "优惠券类型满减券FULL_REDUCTION_COUPON代金券CASH_COUPON兑换券EXCHANGE_COUPON折扣券DISCOUNT_COUPON")
@Excel(name = "优惠券类型满减券FULL_REDUCTION_COUPON代金券CASH_COUPON兑换券EXCHANGE_COUPON折扣券DISCOUNT_COUPON")
@NotBlank(message = "优惠券类型不能为空", groups = {Insert.class, Update.class})
private String couponType;
/**
* 优惠券有效期单位
*/
@ApiModelProperty(value = "优惠券有效期,单位:天")
@Excel(name = "优惠券有效期,单位:天")
@NotNull(message = "优惠券有效期不能为空", groups = {Insert.class, Update.class})
private Integer couponReductionDays;
/**
* 优惠券面额
*/
@ApiModelProperty(value = "优惠券面额")
@Excel(name = "优惠券面额")
@NotNull(message = "优惠券面额不能为空", groups = {Update.class})
private BigDecimal couponPrice;
/**
* 优惠券适用门槛
*/
@ApiModelProperty(value = "优惠券适用门槛")
@Excel(name = "优惠券适用门槛")
@NotNull(message = "优惠券适用门槛不能为空", groups = {Insert.class, Update.class})
private BigDecimal couponConsumePrice;
/**
* 优惠券概述包括使用范围使用注意事项等信息
*/
@ApiModelProperty(value = "优惠券概述,包括使用范围,使用注意事项等信息")
@Excel(name = "优惠券概述,包括使用范围,使用注意事项等信息")
@NotBlank(message = "优惠券概述不能为空", groups = {Insert.class, Update.class})
private String couponDescription;
/**
* 领取方式新人福利NEW_PEOPLE_WELFARE活动赠送EVENT_GIFT消费返券CONSUME_REBATE
*/
@ApiModelProperty(value = "领取方式新人福利NEW_PEOPLE_WELFARE活动赠送EVENT_GIFT消费返券CONSUME_REBATE")
@Excel(name = "领取方式新人福利NEW_PEOPLE_WELFARE活动赠送EVENT_GIFT消费返券CONSUME_REBATE")
@NotBlank(message = "优惠券领取方式不能为空", groups = {Insert.class, Update.class})
private String receiveType;
/**
* 发放数量
*/
@ApiModelProperty(value = "发放数量")
@Excel(name = "发放数量")
private Integer receiveCount;
/**
* 发放数量上限
*/
@ApiModelProperty(value = "发放数量上限")
@Excel(name = "发放数量上限")
private Integer receiveLimitCount;
/**
* 全部商品ALL_PRODUCT指定商品SPECIFIED_COMMODITY
*/
@ApiModelProperty(value = "全部商品ALL_PRODUCT指定商品SPECIFIED_COMMODITY")
@Excel(name = "全部商品ALL_PRODUCT指定商品SPECIFIED_COMMODITY")
private String useScope;
/**
* 显示顺序
*/
@ApiModelProperty(value = "显示顺序")
@Excel(name = "显示顺序")
@NotNull(message = "显示顺序不能为空!", groups = {Insert.class, Update.class})
@Size(max = 5, message = "显示顺序不能超过5个字符")
private Integer showSort;
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("couponTitle", getCouponTitle())
.append("couponCode", getCouponCode())
.append("couponType", getCouponType())
.append("couponReductionDays", getCouponReductionDays())
.append("couponPrice", getCouponPrice())
.append("couponConsumePrice", getCouponConsumePrice())
.append("couponDescription", getCouponDescription())
.append("receiveType", getReceiveType())
.append("receiveCount", getReceiveCount())
.append("receiveLimitCount", getReceiveLimitCount())
.append("useScope", getUseScope())
.append("showSort", getShowSort())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.toString();
}
}

View File

@ -0,0 +1,71 @@
package com.xinelu.manage.mapper.coupon;
import com.xinelu.manage.domain.coupon.Coupon;
import java.util.List;
/**
* 优惠券信息Mapper接口
*
* @author xinyilu
* @date 2023-02-23
*/
public interface CouponMapper {
/**
* 查询优惠券信息
*
* @param id 优惠券信息主键
* @return 优惠券信息
*/
Coupon selectCouponById(Long id);
/**
* 查询优惠券信息列表
*
* @param coupon 优惠券信息
* @return 优惠券信息集合
*/
List<Coupon> selectCouponList(Coupon coupon);
/**
* 新增优惠券信息
*
* @param coupon 优惠券信息
* @return 结果
*/
int insertCoupon(Coupon coupon);
/**
* 修改优惠券信息
*
* @param coupon 优惠券信息
* @return 结果
*/
int updateCoupon(Coupon coupon);
/**
* 删除优惠券信息
*
* @param id 优惠券信息主键
* @return 结果
*/
int deleteCouponById(Long id);
/**
* 批量删除优惠券信息
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
int deleteCouponByIds(Long[] ids);
/**
* 查询优惠券信息(通过名称查询优惠券信息)
*
* @param couponTitle 优惠券信息主键
* @return 优惠券信息
*/
int selectCouponByTitle(String couponTitle);
}

View File

@ -0,0 +1,62 @@
package com.xinelu.manage.service.coupon;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.manage.domain.coupon.Coupon;
import java.util.List;
/**
* 优惠券信息Service接口
*
* @author xinyilu
* @date 2023-02-23
*/
public interface ICouponService {
/**
* 查询优惠券信息
*
* @param id 优惠券信息主键
* @return 优惠券信息
*/
Coupon selectCouponById(Long id);
/**
* 查询优惠券信息列表
*
* @param coupon 优惠券信息
* @return 优惠券信息集合
*/
List<Coupon> selectCouponList(Coupon coupon);
/**
* 新增优惠券信息
*
* @param coupon 优惠券信息
* @return 结果
*/
AjaxResult insertCoupon(Coupon coupon);
/**
* 修改优惠券信息
*
* @param coupon 优惠券信息
* @return 结果
*/
AjaxResult updateCoupon(Coupon coupon);
/**
* 批量删除优惠券信息
*
* @param ids 需要删除的优惠券信息主键集合
* @return 结果
*/
int deleteCouponByIds(Long[] ids);
/**
* 删除优惠券信息信息
*
* @param id 优惠券信息主键
* @return 结果
*/
int deleteCouponById(Long id);
}

View File

@ -0,0 +1,143 @@
package com.xinelu.manage.service.coupon.impl;
import com.xinelu.common.constant.Constants;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.utils.SecurityUtils;
import com.xinelu.common.utils.codes.GenerateSystemCodeUtil;
import com.xinelu.manage.domain.coupon.Coupon;
import com.xinelu.manage.mapper.coupon.CouponMapper;
import com.xinelu.manage.service.coupon.ICouponService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
/**
* 优惠券信息Service业务层处理
*
* @author xinyilu
* @date 2023-02-23
*/
@Service
public class CouponServiceImpl implements ICouponService {
@Resource
private CouponMapper couponMapper;
@Resource
private GenerateSystemCodeUtil generateSystemCodeUtil;
/**
* 查询优惠券信息
*
* @param id 优惠券信息主键
* @return 优惠券信息
*/
@Override
public Coupon selectCouponById(Long id) {
return couponMapper.selectCouponById(id);
}
/**
* 查询优惠券信息列表
*
* @param coupon 优惠券信息
* @return 优惠券信息
*/
@Override
public List<Coupon> selectCouponList(Coupon coupon) {
return couponMapper.selectCouponList(coupon);
}
/**
* 新增优惠券信息
*
* @param coupon 优惠券信息
* @return 结果
*/
@Override
public AjaxResult insertCoupon(Coupon coupon) {
//判断优惠券名称是否重复
int titleCount = couponMapper.selectCouponByTitle(coupon.getCouponTitle());
if (titleCount > 0) {
return AjaxResult.error("优惠劵名称重复,请重新输入!");
}
if (coupon.getCouponReductionDays() <= 0) {
return AjaxResult.error("优惠券有效期要大于0");
}
if (coupon.getCouponPrice().compareTo(BigDecimal.ZERO) <= 0 || coupon.getCouponConsumePrice().compareTo(BigDecimal.ZERO) <= 0) {
return AjaxResult.error("'优惠券面额'或'优惠券适用门槛'要大于0");
}
if (coupon.getCouponPrice().compareTo(coupon.getCouponConsumePrice()) == 0) {
return AjaxResult.error("优惠劵面额与优惠券门槛不能相等,请重新输入!");
}
if (coupon.getCouponPrice().compareTo(coupon.getCouponConsumePrice()) > 0) {
return AjaxResult.error("优惠劵面额不能大于优惠券门槛,请重新输入!");
}
coupon.setCreateTime(LocalDateTime.now());
coupon.setCreateBy(SecurityUtils.getUsername());
coupon.setCouponCode(Constants.COUPON_CODE + generateSystemCodeUtil.generateSystemCode(Constants.COUPON_CODE));
return AjaxResult.success(couponMapper.insertCoupon(coupon));
}
/**
* 修改优惠券信息
*
* @param coupon 优惠券信息
* @return 结果
*/
@Override
public AjaxResult updateCoupon(Coupon coupon) {
Coupon excuseCoupon = couponMapper.selectCouponById(coupon.getId());
if (Objects.isNull(excuseCoupon)) {
return AjaxResult.error("优惠券信息不存在!");
}
if (coupon.getCouponReductionDays() <= 0) {
return AjaxResult.error("优惠券有效期要大于0");
}
if (coupon.getCouponPrice().compareTo(BigDecimal.ZERO) <= 0 || coupon.getCouponConsumePrice().compareTo(BigDecimal.ZERO) <= 0) {
return AjaxResult.error("'优惠券面额'或'优惠券适用门槛'要大于0");
}
if (coupon.getCouponPrice().compareTo(coupon.getCouponConsumePrice()) == 0) {
return AjaxResult.error("优惠劵面额与优惠券门槛不能相等,请重新输入!");
}
if (coupon.getCouponPrice().compareTo(coupon.getCouponConsumePrice()) > 0) {
return AjaxResult.error("优惠劵面额不能大于优惠券门槛,请重新输入!");
}
//判断优惠券名称是否重复
if (StringUtils.isNotBlank(excuseCoupon.getCouponTitle()) && !excuseCoupon.getCouponTitle().equals(coupon.getCouponTitle())) {
int titleCount = couponMapper.selectCouponByTitle(coupon.getCouponTitle());
if (titleCount > 0) {
return AjaxResult.error("优惠劵名称重复,请重新输入!");
}
}
coupon.setUpdateTime(LocalDateTime.now());
coupon.setUpdateBy(SecurityUtils.getUsername());
return AjaxResult.success(couponMapper.updateCoupon(coupon));
}
/**
* 批量删除优惠券信息
*
* @param ids 需要删除的优惠券信息主键
* @return 结果
*/
@Override
public int deleteCouponByIds(Long[] ids) {
return couponMapper.deleteCouponByIds(ids);
}
/**
* 删除优惠券信息信息
*
* @param id 优惠券信息主键
* @return 结果
*/
@Override
public int deleteCouponById(Long id) {
return couponMapper.deleteCouponById(id);
}
}

View File

@ -0,0 +1,243 @@
<?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="com.xinelu.manage.mapper.coupon.CouponMapper">
<resultMap type="Coupon" id="CouponResult">
<result property="id" column="id"/>
<result property="couponTitle" column="coupon_title"/>
<result property="couponCode" column="coupon_code"/>
<result property="couponType" column="coupon_type"/>
<result property="couponReductionDays" column="coupon_reduction_days"/>
<result property="couponPrice" column="coupon_price"/>
<result property="couponConsumePrice" column="coupon_consume_price"/>
<result property="couponDescription" column="coupon_description"/>
<result property="receiveType" column="receive_type"/>
<result property="receiveCount" column="receive_count"/>
<result property="receiveLimitCount" column="receive_limit_count"/>
<result property="useScope" column="use_scope"/>
<result property="showSort" column="show_sort"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
</resultMap>
<sql id="selectCouponVo">
select id,
coupon_title,
coupon_code,
coupon_type,
coupon_reduction_days,
coupon_price,
coupon_consume_price,
coupon_description,
receive_type,
receive_count,
receive_limit_count,
use_scope,
show_sort,
create_by,
create_time,
update_by,
update_time
from coupon
</sql>
<select id="selectCouponList" parameterType="Coupon" resultMap="CouponResult">
<include refid="selectCouponVo"/>
<where>
<if test="couponTitle != null and couponTitle != ''">
and coupon_title like concat( #{couponTitle}, '%')
</if>
<if test="couponCode != null and couponCode != ''">
and coupon_code = #{couponCode}
</if>
<if test="couponType != null and couponType != ''">
and coupon_type = #{couponType}
</if>
<if test="couponReductionDays != null ">
and coupon_reduction_days = #{couponReductionDays}
</if>
<if test="couponPrice != null ">
and coupon_price = #{couponPrice}
</if>
<if test="couponConsumePrice != null ">
and coupon_consume_price = #{couponConsumePrice}
</if>
<if test="couponDescription != null and couponDescription != ''">
and coupon_description = #{couponDescription}
</if>
<if test="receiveType != null and receiveType != ''">
and receive_type = #{receiveType}
</if>
<if test="receiveCount != null ">
and receive_count = #{receiveCount}
</if>
<if test="receiveLimitCount != null ">
and receive_limit_count = #{receiveLimitCount}
</if>
<if test="useScope != null and useScope != ''">
and use_scope = #{useScope}
</if>
<if test="showSort != null ">
and show_sort = #{showSort}
</if>
</where>
ORDER BY create_time desc, show_sort asc
</select>
<select id="selectCouponById" parameterType="Long"
resultMap="CouponResult">
<include refid="selectCouponVo"/>
where id = #{id}
</select>
<insert id="insertCoupon" parameterType="Coupon" useGeneratedKeys="true"
keyProperty="id">
insert into coupon
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="couponTitle != null">coupon_title,
</if>
<if test="couponCode != null">coupon_code,
</if>
<if test="couponType != null">coupon_type,
</if>
<if test="couponReductionDays != null">coupon_reduction_days,
</if>
<if test="couponPrice != null">coupon_price,
</if>
<if test="couponConsumePrice != null">coupon_consume_price,
</if>
<if test="couponDescription != null">coupon_description,
</if>
<if test="receiveType != null">receive_type,
</if>
<if test="receiveCount != null">receive_count,
</if>
<if test="receiveLimitCount != null">receive_limit_count,
</if>
<if test="useScope != null">use_scope,
</if>
<if test="showSort != null">show_sort,
</if>
<if test="createBy != null">create_by,
</if>
<if test="createTime != null">create_time,
</if>
<if test="updateBy != null">update_by,
</if>
<if test="updateTime != null">update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="couponTitle != null">#{couponTitle},
</if>
<if test="couponCode != null">#{couponCode},
</if>
<if test="couponType != null">#{couponType},
</if>
<if test="couponReductionDays != null">#{couponReductionDays},
</if>
<if test="couponPrice != null">#{couponPrice},
</if>
<if test="couponConsumePrice != null">#{couponConsumePrice},
</if>
<if test="couponDescription != null">#{couponDescription},
</if>
<if test="receiveType != null">#{receiveType},
</if>
<if test="receiveCount != null">#{receiveCount},
</if>
<if test="receiveLimitCount != null">#{receiveLimitCount},
</if>
<if test="useScope != null">#{useScope},
</if>
<if test="showSort != null">#{showSort},
</if>
<if test="createBy != null">#{createBy},
</if>
<if test="createTime != null">#{createTime},
</if>
<if test="updateBy != null">#{updateBy},
</if>
<if test="updateTime != null">#{updateTime},
</if>
</trim>
</insert>
<update id="updateCoupon" parameterType="Coupon">
update coupon
<trim prefix="SET" suffixOverrides=",">
<if test="couponTitle != null">coupon_title =
#{couponTitle},
</if>
<if test="couponCode != null">coupon_code =
#{couponCode},
</if>
<if test="couponType != null">coupon_type =
#{couponType},
</if>
<if test="couponReductionDays != null">coupon_reduction_days =
#{couponReductionDays},
</if>
<if test="couponPrice != null">coupon_price =
#{couponPrice},
</if>
<if test="couponConsumePrice != null">coupon_consume_price =
#{couponConsumePrice},
</if>
<if test="couponDescription != null">coupon_description =
#{couponDescription},
</if>
<if test="receiveType != null">receive_type =
#{receiveType},
</if>
<if test="receiveCount != null">receive_count =
#{receiveCount},
</if>
<if test="receiveLimitCount != null">receive_limit_count =
#{receiveLimitCount},
</if>
<if test="useScope != null">use_scope =
#{useScope},
</if>
<if test="showSort != null">show_sort =
#{showSort},
</if>
<if test="createBy != null">create_by =
#{createBy},
</if>
<if test="createTime != null">create_time =
#{createTime},
</if>
<if test="updateBy != null">update_by =
#{updateBy},
</if>
<if test="updateTime != null">update_time =
#{updateTime},
</if>
</trim>
where id = #{id}
</update>
<delete id="deleteCouponById" parameterType="Long">
delete
from coupon
where id = #{id}
</delete>
<delete id="deleteCouponByIds" parameterType="String">
delete from coupon where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="selectCouponByTitle" resultType="java.lang.Integer">
select count(1)
from coupon
where coupon_title = #{couponTitle}
</select>
</mapper>