diff --git a/xinelu-nurse-manage/src/main/java/com/xinelu/manage/controller/coupon/CouponController.java b/xinelu-nurse-manage/src/main/java/com/xinelu/manage/controller/coupon/CouponController.java new file mode 100644 index 0000000..976eda4 --- /dev/null +++ b/xinelu-nurse-manage/src/main/java/com/xinelu/manage/controller/coupon/CouponController.java @@ -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 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 list = couponService.selectCouponList(coupon); + ExcelUtil 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)); + } +} diff --git a/xinelu-nurse-manage/src/main/java/com/xinelu/manage/domain/coupon/Coupon.java b/xinelu-nurse-manage/src/main/java/com/xinelu/manage/domain/coupon/Coupon.java new file mode 100644 index 0000000..aab3f6a --- /dev/null +++ b/xinelu-nurse-manage/src/main/java/com/xinelu/manage/domain/coupon/Coupon.java @@ -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(); + } +} diff --git a/xinelu-nurse-manage/src/main/java/com/xinelu/manage/mapper/coupon/CouponMapper.java b/xinelu-nurse-manage/src/main/java/com/xinelu/manage/mapper/coupon/CouponMapper.java new file mode 100644 index 0000000..cfeeeab --- /dev/null +++ b/xinelu-nurse-manage/src/main/java/com/xinelu/manage/mapper/coupon/CouponMapper.java @@ -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 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); + +} diff --git a/xinelu-nurse-manage/src/main/java/com/xinelu/manage/service/coupon/ICouponService.java b/xinelu-nurse-manage/src/main/java/com/xinelu/manage/service/coupon/ICouponService.java new file mode 100644 index 0000000..d8a38a4 --- /dev/null +++ b/xinelu-nurse-manage/src/main/java/com/xinelu/manage/service/coupon/ICouponService.java @@ -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 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); +} diff --git a/xinelu-nurse-manage/src/main/java/com/xinelu/manage/service/coupon/impl/CouponServiceImpl.java b/xinelu-nurse-manage/src/main/java/com/xinelu/manage/service/coupon/impl/CouponServiceImpl.java new file mode 100644 index 0000000..6cb78d0 --- /dev/null +++ b/xinelu-nurse-manage/src/main/java/com/xinelu/manage/service/coupon/impl/CouponServiceImpl.java @@ -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 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); + } +} diff --git a/xinelu-nurse-manage/src/main/resources/mapper/manage/coupon/CouponMapper.xml b/xinelu-nurse-manage/src/main/resources/mapper/manage/coupon/CouponMapper.xml new file mode 100644 index 0000000..91545ed --- /dev/null +++ b/xinelu-nurse-manage/src/main/resources/mapper/manage/coupon/CouponMapper.xml @@ -0,0 +1,243 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + + + + + insert into coupon + + 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, + + + + #{couponTitle}, + + #{couponCode}, + + #{couponType}, + + #{couponReductionDays}, + + #{couponPrice}, + + #{couponConsumePrice}, + + #{couponDescription}, + + #{receiveType}, + + #{receiveCount}, + + #{receiveLimitCount}, + + #{useScope}, + + #{showSort}, + + #{createBy}, + + #{createTime}, + + #{updateBy}, + + #{updateTime}, + + + + + + update coupon + + coupon_title = + #{couponTitle}, + + coupon_code = + #{couponCode}, + + coupon_type = + #{couponType}, + + coupon_reduction_days = + #{couponReductionDays}, + + coupon_price = + #{couponPrice}, + + coupon_consume_price = + #{couponConsumePrice}, + + coupon_description = + #{couponDescription}, + + receive_type = + #{receiveType}, + + receive_count = + #{receiveCount}, + + receive_limit_count = + #{receiveLimitCount}, + + use_scope = + #{useScope}, + + show_sort = + #{showSort}, + + create_by = + #{createBy}, + + create_time = + #{createTime}, + + update_by = + #{updateBy}, + + update_time = + #{updateTime}, + + + where id = #{id} + + + + delete + from coupon + where id = #{id} + + + + delete from coupon where id in + + #{id} + + + + +