Browse Source

feat:优惠券

Joburgess 3 years ago
parent
commit
34d8201435

+ 3 - 3
codegen/src/main/resources/generateConfigration.xml

@@ -2,11 +2,11 @@
 <GenerateConfiguration>
 	<dbConfiguration>
 		<driverClass>com.mysql.jdbc.Driver</driverClass>
-		<url>jdbc:mysql://47.114.1.200:3306/mec_dev</url>
+		<url>jdbc:mysql://47.114.1.200:3306/mec_test</url>
 		<username>mec_dev</username>
 		<password>dayaDataOnline@2019</password>
-		<catalog>mec_dev</catalog>
-		<schema>mec_dev</schema>
+		<catalog>mec_test</catalog>
+		<schema>mec_test</schema>
 	</dbConfiguration>
 	<srcBase>e:/javabean</srcBase>
 	<pojoPackageName>com.ym.mec.biz.dal.entity</pojoPackageName>

+ 9 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/SysCouponCodeDao.java

@@ -0,0 +1,9 @@
+package com.ym.mec.biz.dal.dao;
+
+import com.ym.mec.common.dal.BaseDAO;
+import com.ym.mec.biz.dal.entity.SysCouponCode;
+
+public interface SysCouponCodeDao extends BaseDAO<Long, SysCouponCode> {
+
+	
+}

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/SysCouponDao.java

@@ -0,0 +1,11 @@
+package com.ym.mec.biz.dal.dao;
+
+import com.ym.mec.common.dal.BaseDAO;
+import com.ym.mec.biz.dal.entity.SysCoupon;
+import org.apache.ibatis.annotations.Param;
+
+public interface SysCouponDao extends BaseDAO<Integer, SysCoupon> {
+
+    SysCoupon lockCoupon(@Param("id") Integer id);
+	
+}

+ 215 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/SysCoupon.java

@@ -0,0 +1,215 @@
+package com.ym.mec.biz.dal.entity;
+
+import com.ym.mec.biz.dal.enums.CouponTypeEnum;
+import io.swagger.annotations.ApiModelProperty;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * 对应数据库表(sys_coupon):
+ */
+public class SysCoupon {
+
+	private Integer id;
+
+	@ApiModelProperty("优惠券名称")
+	private String name;
+
+	@ApiModelProperty("描述")
+	private String description;
+
+	@ApiModelProperty("状态:0停用,1启用")
+	private Integer status;
+
+	@ApiModelProperty("券类型:FULL_REDUCTION(满减券),DISCOUNT(折扣券)")
+	private CouponTypeEnum type;
+
+	@ApiModelProperty("面值")
+	private java.math.BigDecimal faceValue;
+
+	@ApiModelProperty("满多少")
+	private java.math.BigDecimal fullAmount;
+
+	@ApiModelProperty("限制兑换的最大次数")
+	private Integer limitExchangeNum;
+
+	@ApiModelProperty("期限(单位:天)")
+	private Integer deadline;
+
+	@ApiModelProperty("有效起始时间")
+	private java.util.Date effectiveStartTime;
+
+	@ApiModelProperty("有效截止时间")
+	private java.util.Date effectiveExpireTime;
+
+	@ApiModelProperty("领取结束时间")
+	private java.util.Date endDate;
+
+	@ApiModelProperty("领取开始时间")
+	private java.util.Date startDate;
+
+	@ApiModelProperty("库存量")
+	private Integer stockCount;
+
+	@ApiModelProperty("消耗数量")
+	private Integer consumeNum;
+
+	@ApiModelProperty("预警值")
+	private Integer warningStockNum;
+
+	private java.util.Date createTime;
+
+	private java.util.Date updateTime;
+
+	public Integer getId() {
+		return id;
+	}
+
+	public void setId(Integer id) {
+		this.id = id;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public String getDescription() {
+		return description;
+	}
+
+	public void setDescription(String description) {
+		this.description = description;
+	}
+
+	public Integer getStatus() {
+		return status;
+	}
+
+	public void setStatus(Integer status) {
+		this.status = status;
+	}
+
+	public CouponTypeEnum getType() {
+		return type;
+	}
+
+	public void setType(CouponTypeEnum type) {
+		this.type = type;
+	}
+
+	public BigDecimal getFaceValue() {
+		return faceValue;
+	}
+
+	public void setFaceValue(BigDecimal faceValue) {
+		this.faceValue = faceValue;
+	}
+
+	public BigDecimal getFullAmount() {
+		return fullAmount;
+	}
+
+	public void setFullAmount(BigDecimal fullAmount) {
+		this.fullAmount = fullAmount;
+	}
+
+	public Integer getLimitExchangeNum() {
+		return limitExchangeNum;
+	}
+
+	public void setLimitExchangeNum(Integer limitExchangeNum) {
+		this.limitExchangeNum = limitExchangeNum;
+	}
+
+	public Integer getDeadline() {
+		return deadline;
+	}
+
+	public void setDeadline(Integer deadline) {
+		this.deadline = deadline;
+	}
+
+	public Date getEffectiveStartTime() {
+		return effectiveStartTime;
+	}
+
+	public void setEffectiveStartTime(Date effectiveStartTime) {
+		this.effectiveStartTime = effectiveStartTime;
+	}
+
+	public Date getEffectiveExpireTime() {
+		return effectiveExpireTime;
+	}
+
+	public void setEffectiveExpireTime(Date effectiveExpireTime) {
+		this.effectiveExpireTime = effectiveExpireTime;
+	}
+
+	public Date getEndDate() {
+		return endDate;
+	}
+
+	public void setEndDate(Date endDate) {
+		this.endDate = endDate;
+	}
+
+	public Date getStartDate() {
+		return startDate;
+	}
+
+	public void setStartDate(Date startDate) {
+		this.startDate = startDate;
+	}
+
+	public Integer getStockCount() {
+		return stockCount;
+	}
+
+	public void setStockCount(Integer stockCount) {
+		this.stockCount = stockCount;
+	}
+
+	public Integer getConsumeNum() {
+		return consumeNum;
+	}
+
+	public void setConsumeNum(Integer consumeNum) {
+		this.consumeNum = consumeNum;
+	}
+
+	public Integer getWarningStockNum() {
+		return warningStockNum;
+	}
+
+	public void setWarningStockNum(Integer warningStockNum) {
+		this.warningStockNum = warningStockNum;
+	}
+
+	public Date getCreateTime() {
+		return createTime;
+	}
+
+	public void setCreateTime(Date createTime) {
+		this.createTime = createTime;
+	}
+
+	public Date getUpdateTime() {
+		return updateTime;
+	}
+
+	public void setUpdateTime(Date updateTime) {
+		this.updateTime = updateTime;
+	}
+
+	@Override
+	public String toString() {
+		return ToStringBuilder.reflectionToString(this);
+	}
+
+}

+ 136 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/SysCouponCode.java

@@ -0,0 +1,136 @@
+package com.ym.mec.biz.dal.entity;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+
+/**
+ * 对应数据库表(sys_coupon_code):
+ */
+public class SysCouponCode {
+
+	/**  */
+	private Long id;
+	
+	/**  */
+	private Integer couponId;
+	
+	/** 优惠码 */
+	private String code;
+	
+	/** 使用状态 */
+	private String usageStatus;
+	
+	/** 用户编号 */
+	private Integer userId;
+	
+	/** 实际使用时间 */
+	private java.util.Date usedTime;
+	
+	/** 使用开始日期 */
+	private java.util.Date useStartDate;
+	
+	/** 使用截止日期 */
+	private java.util.Date useDeadlineDate;
+	
+	/** 关联的订单号 */
+	private String paymentOrderId;
+	
+	/**  */
+	private java.util.Date createTime;
+	
+	/**  */
+	private java.util.Date updateTime;
+	
+	public void setId(Long id){
+		this.id = id;
+	}
+	
+	public Long getId(){
+		return this.id;
+	}
+			
+	public void setCouponId(Integer couponId){
+		this.couponId = couponId;
+	}
+	
+	public Integer getCouponId(){
+		return this.couponId;
+	}
+			
+	public void setCode(String code){
+		this.code = code;
+	}
+	
+	public String getCode(){
+		return this.code;
+	}
+			
+	public void setUsageStatus(String usageStatus){
+		this.usageStatus = usageStatus;
+	}
+	
+	public String getUsageStatus(){
+		return this.usageStatus;
+	}
+			
+	public void setUserId(Integer userId){
+		this.userId = userId;
+	}
+	
+	public Integer getUserId(){
+		return this.userId;
+	}
+			
+	public void setUsedTime(java.util.Date usedTime){
+		this.usedTime = usedTime;
+	}
+	
+	public java.util.Date getUsedTime(){
+		return this.usedTime;
+	}
+			
+	public void setUseStartDate(java.util.Date useStartDate){
+		this.useStartDate = useStartDate;
+	}
+	
+	public java.util.Date getUseStartDate(){
+		return this.useStartDate;
+	}
+			
+	public void setUseDeadlineDate(java.util.Date useDeadlineDate){
+		this.useDeadlineDate = useDeadlineDate;
+	}
+	
+	public java.util.Date getUseDeadlineDate(){
+		return this.useDeadlineDate;
+	}
+			
+	public void setPaymentOrderId(String paymentOrderId){
+		this.paymentOrderId = paymentOrderId;
+	}
+	
+	public String getPaymentOrderId(){
+		return this.paymentOrderId;
+	}
+			
+	public void setCreateTime(java.util.Date createTime){
+		this.createTime = createTime;
+	}
+	
+	public java.util.Date getCreateTime(){
+		return this.createTime;
+	}
+			
+	public void setUpdateTime(java.util.Date updateTime){
+		this.updateTime = updateTime;
+	}
+	
+	public java.util.Date getUpdateTime(){
+		return this.updateTime;
+	}
+			
+	@Override
+	public String toString() {
+		return ToStringBuilder.reflectionToString(this);
+	}
+
+}

+ 34 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/enums/CouponTypeEnum.java

@@ -0,0 +1,34 @@
+package com.ym.mec.biz.dal.enums;
+
+import com.ym.mec.common.enums.BaseEnum;
+
+public enum CouponTypeEnum implements BaseEnum<String, CouponTypeEnum> {
+
+    FULL_REDUCTION("FULL_REDUCTION","满减券"),
+    DISCOUNT("DISCOUNT","折扣券");
+
+    private String code;
+
+    private String msg;
+
+    CouponTypeEnum(String code, String msg) {
+        this.code = code;
+        this.msg = msg;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+
+    @Override
+    public String getCode() {
+        return this.code;
+    }}

+ 8 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/SysCouponCodeService.java

@@ -0,0 +1,8 @@
+package com.ym.mec.biz.service;
+
+import com.ym.mec.biz.dal.entity.SysCouponCode;
+import com.ym.mec.common.service.BaseService;
+
+public interface SysCouponCodeService extends BaseService<Long, SysCouponCode> {
+
+}

+ 10 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/SysCouponService.java

@@ -0,0 +1,10 @@
+package com.ym.mec.biz.service;
+
+import com.ym.mec.biz.dal.entity.SysCoupon;
+import com.ym.mec.common.service.BaseService;
+
+public interface SysCouponService extends BaseService<Integer, SysCoupon> {
+
+    void updateCoupon(SysCoupon sysCoupon);
+
+}

+ 22 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SysCouponCodeServiceImpl.java

@@ -0,0 +1,22 @@
+package com.ym.mec.biz.service.impl;
+
+import com.ym.mec.common.dal.BaseDAO;
+import org.springframework.beans.factory.annotation.Autowired;
+import com.ym.mec.common.service.impl.BaseServiceImpl;
+import com.ym.mec.biz.dal.entity.SysCouponCode;
+import com.ym.mec.biz.service.SysCouponCodeService;
+import com.ym.mec.biz.dal.dao.SysCouponCodeDao;
+import org.springframework.stereotype.Service;
+
+@Service
+public class SysCouponCodeServiceImpl extends BaseServiceImpl<Long, SysCouponCode>  implements SysCouponCodeService {
+	
+	@Autowired
+	private SysCouponCodeDao sysCouponCodeDao;
+
+	@Override
+	public BaseDAO<Long, SysCouponCode> getDAO() {
+		return sysCouponCodeDao;
+	}
+	
+}

+ 44 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SysCouponServiceImpl.java

@@ -0,0 +1,44 @@
+package com.ym.mec.biz.service.impl;
+
+import com.ym.mec.common.dal.BaseDAO;
+import com.ym.mec.common.exception.BizException;
+import org.springframework.beans.factory.annotation.Autowired;
+import com.ym.mec.common.service.impl.BaseServiceImpl;
+import com.ym.mec.biz.dal.entity.SysCoupon;
+import com.ym.mec.biz.service.SysCouponService;
+import com.ym.mec.biz.dal.dao.SysCouponDao;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Isolation;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Objects;
+
+@Service
+public class SysCouponServiceImpl extends BaseServiceImpl<Integer, SysCoupon>  implements SysCouponService {
+	
+	@Autowired
+	private SysCouponDao sysCouponDao;
+
+	@Override
+	public BaseDAO<Integer, SysCoupon> getDAO() {
+		return sysCouponDao;
+	}
+
+	@Override
+	@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
+	public void updateCoupon(SysCoupon sysCoupon) {
+		SysCoupon oldCoupon = sysCouponDao.lockCoupon(sysCoupon.getId());
+		if(Objects.isNull(oldCoupon)){
+			throw new BizException("优惠券信息不存在");
+		}
+		//如果已经有人领取,则只能修改库存总量与预警值
+		if(oldCoupon.getConsumeNum()>0){
+			oldCoupon.setStatus(sysCoupon.getStatus());
+			oldCoupon.setStockCount(sysCoupon.getStockCount());
+			oldCoupon.setWarningStockNum(sysCoupon.getWarningStockNum());
+			sysCouponDao.update(oldCoupon);
+			return;
+		}
+		sysCouponDao.update(sysCoupon);
+	}
+}

+ 96 - 0
mec-biz/src/main/resources/config/mybatis/SysCouponCodeMapper.xml

@@ -0,0 +1,96 @@
+<?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.ym.mec.biz.dal.dao.SysCouponCodeDao">
+
+	<resultMap type="com.ym.mec.biz.dal.entity.SysCouponCode" id="SysCouponCode">
+		<result column="id_" property="id" />
+		<result column="coupon_id_" property="couponId" />
+		<result column="code_" property="code" />
+		<result column="usage_status_" property="usageStatus" />
+		<result column="user_id_" property="userId" />
+		<result column="used_time_" property="usedTime" />
+		<result column="use_start_date_" property="useStartDate" />
+		<result column="use_deadline_date_" property="useDeadlineDate" />
+		<result column="payment_order_id_" property="paymentOrderId" />
+		<result column="create_time_" property="createTime" />
+		<result column="update_time_" property="updateTime" />
+	</resultMap>
+
+	<!-- 根据主键查询一条记录 -->
+	<select id="get" resultMap="SysCouponCode" >
+		SELECT * FROM sys_coupon_code WHERE id_ = #{id}
+	</select>
+
+	<!-- 全查询 -->
+	<select id="findAll" resultMap="SysCouponCode">
+		SELECT * FROM sys_coupon_code ORDER BY id_
+	</select>
+
+	<!-- 向数据库增加一条记录 -->
+	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.SysCouponCode" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
+		<!--
+		<selectKey resultClass="int" keyProperty="id" >
+		SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL
+		</selectKey>
+		-->
+		INSERT INTO sys_coupon_code (id_,coupon_id_,code_,usage_status_,user_id_,used_time_,use_start_date_,use_deadline_date_,payment_order_id_,create_time_,update_time_) VALUES(#{id},#{couponId},#{code},#{usageStatus},#{userId},#{usedTime},#{useStartDate},#{useDeadlineDate},#{paymentOrderId},#{createTime},#{updateTime})
+	</insert>
+
+	<!-- 根据主键查询一条记录 -->
+	<update id="update" parameterType="com.ym.mec.biz.dal.entity.SysCouponCode">
+		UPDATE sys_coupon_code <set>
+		<if test="couponId != null">
+			coupon_id_ = #{couponId},
+		</if>
+		<if test="usageStatus != null">
+			usage_status_ = #{usageStatus},
+		</if>
+		<if test="useStartDate != null">
+			use_start_date_ = #{useStartDate},
+		</if>
+		<if test="userId != null">
+			user_id_ = #{userId},
+		</if>
+		<if test="usedTime != null">
+			used_time_ = #{usedTime},
+		</if>
+		<if test="id != null">
+			id_ = #{id},
+		</if>
+		<if test="code != null">
+			code_ = #{code},
+		</if>
+		<if test="updateTime != null">
+			update_time_ = #{updateTime},
+		</if>
+		<if test="paymentOrderId != null">
+			payment_order_id_ = #{paymentOrderId},
+		</if>
+		<if test="useDeadlineDate != null">
+			use_deadline_date_ = #{useDeadlineDate},
+		</if>
+		<if test="createTime != null">
+			create_time_ = #{createTime},
+		</if>
+	</set> WHERE id_ = #{id}
+	</update>
+
+	<!-- 根据主键删除一条记录 -->
+	<delete id="delete" >
+		DELETE FROM sys_coupon_code WHERE id_ = #{id}
+	</delete>
+
+	<!-- 分页查询 -->
+	<select id="queryPage" resultMap="SysCouponCode" parameterType="map">
+		SELECT * FROM sys_coupon_code ORDER BY id_ <include refid="global.limit"/>
+	</select>
+
+	<!-- 查询当前表的总记录数 -->
+	<select id="queryCount" resultType="int">
+		SELECT COUNT(*) FROM sys_coupon_code
+	</select>
+</mapper>

+ 126 - 0
mec-biz/src/main/resources/config/mybatis/SysCouponMapper.xml

@@ -0,0 +1,126 @@
+<?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.ym.mec.biz.dal.dao.SysCouponDao">
+
+	<resultMap type="com.ym.mec.biz.dal.entity.SysCoupon" id="SysCoupon">
+		<result column="id_" property="id" />
+		<result column="name_" property="name" />
+		<result column="description_" property="description" />
+		<result column="status_" property="status" />
+		<result column="type_" property="type" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
+		<result column="face_value_" property="faceValue" />
+		<result column="is_enabled_" property="isEnabled" />
+		<result column="full_amount_" property="fullAmount" />
+		<result column="limit_exchange_num_" property="limitExchangeNum" />
+		<result column="deadline_" property="deadline" />
+		<result column="effective_start_time_" property="effectiveStartTime" />
+		<result column="effective_expire_time_" property="effectiveExpireTime" />
+		<result column="end_date_" property="endDate" />
+		<result column="start_date_" property="startDate" />
+		<result column="stock_count_" property="stockCount" />
+		<result column="consume_num_" property="consumeNum" />
+		<result column="warning_stock_num_" property="warningStockNum" />
+		<result column="create_time_" property="createTime" />
+		<result column="update_time_" property="updateTime" />
+	</resultMap>
+
+	<!-- 根据主键查询一条记录 -->
+	<select id="get" resultMap="SysCoupon" >
+		SELECT * FROM sys_coupon WHERE id_ = #{id}
+	</select>
+
+	<!-- 全查询 -->
+	<select id="findAll" resultMap="SysCoupon">
+		SELECT * FROM sys_coupon ORDER BY id_
+	</select>
+
+	<!-- 向数据库增加一条记录 -->
+	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.SysCoupon" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
+		INSERT INTO sys_coupon (id_,name_,description_,status_,type_,face_value_,is_enabled_,full_amount_,limit_exchange_num_,deadline_,
+		                        effective_start_time_, effective_expire_time_,end_date_,start_date_,stock_count_,consume_num_,warning_stock_num_,
+		                        create_time_,update_time_)
+		                        VALUES(#{id},#{name},#{description},#{status},#{type, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{faceValue},#{isEnabled},#{fullAmount},#{limitExchangeNum},#{deadline},
+		                               #{effectiveStartTime},#{effectiveExpireTime},#{endDate},#{startDate},#{stockCount},#{consumeNum},#{warningStockNum},
+		                               NOW(), NOW())
+	</insert>
+
+	<!-- 根据主键查询一条记录 -->
+	<update id="update" parameterType="com.ym.mec.biz.dal.entity.SysCoupon">
+		UPDATE sys_coupon
+		<set>
+			<if test="isEnabled != null">
+				is_enabled_ = #{isEnabled},
+			</if>
+			<if test="status != null">
+				status_ = #{status},
+			</if>
+			<if test="effectiveExpireTime != null">
+				effective_expire_time_ = #{effectiveExpireTime},
+			</if>
+			<if test="startDate != null">
+				start_date_ = #{startDate},
+			</if>
+			<if test="faceValue != null">
+				face_value_ = #{faceValue},
+			</if>
+			<if test="name != null">
+				name_ = #{name},
+			</if>
+			<if test="fullAmount != null">
+				full_amount_ = #{fullAmount},
+			</if>
+			<if test="deadline != null">
+				deadline_ = #{deadline},
+			</if>
+			<if test="stockCount != null">
+				stock_count_ = #{stockCount},
+			</if>
+			<if test="endDate != null">
+				end_date_ = #{endDate},
+			</if>
+			<if test="description != null">
+				description_ = #{description},
+			</if>
+			<if test="effectiveStartTime != null">
+				effective_start_time_ = #{effectiveStartTime},
+			</if>
+			<if test="consumeNum != null">
+				consume_num_ = #{consumeNum},
+			</if>
+			<if test="type != null">
+				type_ = #{type, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
+			</if>
+			<if test="limitExchangeNum != null">
+				limit_exchange_num_ = #{limitExchangeNum},
+			</if>
+			<if test="warningStockNum != null">
+				warning_stock_num_ = #{warningStockNum},
+			</if>
+				update_time_ = NOW()
+		</set>
+		WHERE id_ = #{id}
+	</update>
+
+	<!-- 根据主键删除一条记录 -->
+	<delete id="delete" >
+		DELETE FROM sys_coupon WHERE id_ = #{id}
+	</delete>
+
+	<!-- 分页查询 -->
+	<select id="queryPage" resultMap="SysCoupon" parameterType="map">
+		SELECT * FROM sys_coupon ORDER BY id_ <include refid="global.limit"/>
+	</select>
+
+	<!-- 查询当前表的总记录数 -->
+	<select id="queryCount" resultType="int">
+		SELECT COUNT(*) FROM sys_coupon
+	</select>
+
+	<select id="lockCoupon" resultMap="SysCoupon">
+		SELECT * FROM sys_coupon WHERE id_ = #{id} FOR UPDATE
+	</select>
+</mapper>

+ 61 - 0
mec-web/src/main/java/com/ym/mec/web/controller/SysCouponController.java

@@ -0,0 +1,61 @@
+package com.ym.mec.web.controller;
+
+import com.ym.mec.biz.dal.entity.SysCoupon;
+import com.ym.mec.biz.service.SysCouponService;
+import com.ym.mec.common.controller.BaseController;
+import com.ym.mec.common.page.QueryInfo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Objects;
+
+@RequestMapping("sysCoupon")
+@Api(tags = "优惠券")
+@RestController
+public class SysCouponController extends BaseController {
+
+	@Autowired
+	private SysCouponService sysCouponService;
+
+	@ApiOperation("新增")
+	@PostMapping(value = "add")
+	@PreAuthorize("@pcs.hasPermissions('sysCoupon/add')")
+	public Object add(@RequestBody SysCoupon sysCoupon) {
+		return succeed(sysCouponService.insert(sysCoupon));
+	}
+
+	@ApiOperation("修改")
+	@PostMapping(value = "updateCoupon")
+	@PreAuthorize("@pcs.hasPermissions('sysCoupon/updateCoupon')")
+	public Object updateCoupon(@RequestBody SysCoupon sysCoupon) {
+		sysCouponService.updateCoupon(sysCoupon);
+		return succeed();
+	}
+
+	@ApiOperation("删除")
+	@PostMapping(value = "delete")
+	@PreAuthorize("@pcs.hasPermissions('sysCoupon/delete')")
+	public Object del(Integer id) {
+		SysCoupon sysCoupon = sysCouponService.get(id);
+		if(Objects.isNull(sysCoupon)){
+			return failed("优惠券信息不存在");
+		}
+		if(sysCoupon.getConsumeNum()>0){
+			return failed("此优惠券已消耗,暂不可删除");
+		}
+		return succeed(sysCouponService.delete(id));
+	}
+
+	@ApiOperation("分页查询")
+	@PostMapping(value = "queryPage")
+	@PreAuthorize("@pcs.hasPermissions('sysCoupon/queryPage')")
+	public Object queryPage(QueryInfo queryInfo) {
+		return succeed(sysCouponService.queryPage(queryInfo));
+	}
+}