dcs 2 months ago
parent
commit
6f18a0dc01

+ 67 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/controller/ProductCouponModelController.java

@@ -0,0 +1,67 @@
+package com.bosshand.virgo.api.workark.controller;
+
+import com.bosshand.virgo.api.workark.model.ProductCouponModel;
+import com.bosshand.virgo.api.workark.service.ProductCouponModelService;
+import com.bosshand.virgo.core.response.Response;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@RequestMapping({"workarkProductCouponModel"})
+@Api(tags = {"商品优惠券模板管理"})
+public class ProductCouponModelController {
+
+    @Autowired
+    ProductCouponModelService productCouponModelService;
+
+    @ApiOperation("保存")
+    @RequestMapping(value = "", method = RequestMethod.POST)
+    public Response insert(@RequestBody ProductCouponModel productCouponModel) {
+        productCouponModelService.save(productCouponModel);
+        return Response.ok();
+    }
+
+    @ApiOperation("更新")
+    @RequestMapping(value = "/update", method = RequestMethod.PUT)
+    public Response update(@RequestBody ProductCouponModel productCouponModel) {
+        productCouponModelService.update(productCouponModel);
+        return Response.ok();
+    }
+
+    @ApiOperation("删除")
+    @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
+    public Response delete(@PathVariable long id) {
+        productCouponModelService.delete(id);
+        return Response.ok();
+    }
+
+    @ApiOperation("查询")
+    @RequestMapping(value = "/query", method = RequestMethod.POST)
+    public Response getList(@RequestBody ProductCouponModel productCouponModel) {
+        return Response.ok(productCouponModelService.getList(productCouponModel));
+    }
+
+    @ApiOperation("分页查询")
+    @RequestMapping(value = "/{currPage}/{pageSize}", method = RequestMethod.POST)
+    public Response list(@RequestBody ProductCouponModel productCouponModel, @PathVariable int currPage, @PathVariable int pageSize) {
+        int totalCount = productCouponModelService.getTotalCount(productCouponModel);
+        List<ProductCouponModel> dataList = productCouponModelService.getLimit(productCouponModel, currPage, pageSize);
+        Map<String, Object> result = new HashMap<>();
+        result.put("dataList", dataList);
+        result.put("totalCount", totalCount);
+        return Response.ok(result);
+    }
+
+    @ApiOperation("详情")
+    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
+    public Response get(@PathVariable long id) {
+        return Response.ok(productCouponModelService.get(id));
+    }
+
+}

+ 26 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/dao/ProductCouponModelDao.java

@@ -0,0 +1,26 @@
+package com.bosshand.virgo.api.workark.dao;
+
+import com.bosshand.virgo.api.workark.model.ProductCouponModel;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+@Mapper
+public interface ProductCouponModelDao {
+
+    void delete(long id);
+
+    void save(ProductCouponModel productCouponModel);
+
+    void update(ProductCouponModel productCouponModel);
+
+    List<ProductCouponModel> getList(ProductCouponModel productCouponModel);
+
+    ProductCouponModel get(long id);
+
+    int getTotalCount(ProductCouponModel productCouponModel);
+
+    List<ProductCouponModel> getLimit(@Param("p") ProductCouponModel p, @Param("currIndex") int currIndex, @Param("pageSize") int pageSize);
+
+}

+ 26 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/model/ProductCoupon.java

@@ -17,6 +17,11 @@ public class ProductCoupon {
      */
     private Integer type;
 
+    /**
+     * 其他类型(新用户类型券、口令类型券 等)
+     */
+    private Integer otherType;
+
     /**
      * 折扣(0.88折,0.75折 等)
      */
@@ -86,6 +91,11 @@ public class ProductCoupon {
      */
     private BigDecimal threshold;
 
+    /**
+     * 最高限制金额
+     */
+    private BigDecimal mostConstraint;
+
     /**
      * 使用说明
      */
@@ -107,6 +117,14 @@ public class ProductCoupon {
         this.type = type;
     }
 
+    public Integer getOtherType() {
+        return otherType;
+    }
+
+    public void setOtherType(Integer otherType) {
+        this.otherType = otherType;
+    }
+
     public BigDecimal getDiscount() {
         return discount;
     }
@@ -211,6 +229,14 @@ public class ProductCoupon {
         this.threshold = threshold;
     }
 
+    public BigDecimal getMostConstraint() {
+        return mostConstraint;
+    }
+
+    public void setMostConstraint(BigDecimal mostConstraint) {
+        this.mostConstraint = mostConstraint;
+    }
+
     public String getDescription() {
         return description;
     }

+ 166 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/model/ProductCouponModel.java

@@ -0,0 +1,166 @@
+package com.bosshand.virgo.api.workark.model;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * 优惠券模板
+ */
+public class ProductCouponModel {
+
+    private Long id;
+
+    /**
+     * 类型(1、打折,2、现金)
+     */
+    private Integer type;
+
+    /**
+     * 其他类型(新用户类型券、口令类型券 等)
+     */
+    private Integer otherType;
+
+    /**
+     * 折扣(0.88折,0.75折 等)
+     */
+    private BigDecimal discount;
+
+    /**
+     * 创建时间
+     */
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date createTime;
+
+    /**
+     * 有效期 (小时)
+     */
+    private Integer lifespan;
+
+    /**
+     * 商品目录id (可以使用优惠券的范围)
+     */
+    private long productLevelId;
+
+    /**
+     * 优惠金额 (元)
+     */
+    private BigDecimal couponAmount;
+
+    /**
+     * 标题
+     */
+    private String title;
+
+    /**
+     * 门槛金额
+     */
+    private BigDecimal threshold;
+
+    /**
+     * 最高限制金额
+     */
+    private BigDecimal mostConstraint;
+
+    /**
+     * 使用说明
+     */
+    private String description;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Integer getType() {
+        return type;
+    }
+
+    public void setType(Integer type) {
+        this.type = type;
+    }
+
+    public Integer getOtherType() {
+        return otherType;
+    }
+
+    public void setOtherType(Integer otherType) {
+        this.otherType = otherType;
+    }
+
+    public BigDecimal getDiscount() {
+        return discount;
+    }
+
+    public void setDiscount(BigDecimal discount) {
+        this.discount = discount;
+    }
+
+    public Date getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+
+    public Integer getLifespan() {
+        return lifespan;
+    }
+
+    public void setLifespan(Integer lifespan) {
+        this.lifespan = lifespan;
+    }
+
+    public long getProductLevelId() {
+        return productLevelId;
+    }
+
+    public void setProductLevelId(long productLevelId) {
+        this.productLevelId = productLevelId;
+    }
+
+    public BigDecimal getCouponAmount() {
+        return couponAmount;
+    }
+
+    public void setCouponAmount(BigDecimal couponAmount) {
+        this.couponAmount = couponAmount;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public BigDecimal getThreshold() {
+        return threshold;
+    }
+
+    public void setThreshold(BigDecimal threshold) {
+        this.threshold = threshold;
+    }
+
+    public BigDecimal getMostConstraint() {
+        return mostConstraint;
+    }
+
+    public void setMostConstraint(BigDecimal mostConstraint) {
+        this.mostConstraint = mostConstraint;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+}

+ 45 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/service/ProductCouponModelService.java

@@ -0,0 +1,45 @@
+package com.bosshand.virgo.api.workark.service;
+
+import com.bosshand.virgo.api.workark.dao.ProductCouponModelDao;
+import com.bosshand.virgo.api.workark.model.ProductCouponModel;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class ProductCouponModelService {
+
+    @Autowired
+    ProductCouponModelDao productCouponModelDao;
+
+    public void delete(long id) {
+        productCouponModelDao.delete(id);
+    }
+
+    public void save(ProductCouponModel productCouponModel){
+        productCouponModelDao.save(productCouponModel);
+    }
+
+    public void update(ProductCouponModel productCouponModel) {
+        productCouponModelDao.update(productCouponModel);
+    }
+
+    public List<ProductCouponModel> getList(ProductCouponModel productCouponModel){
+        return productCouponModelDao.getList(productCouponModel);
+    }
+
+    public int getTotalCount(ProductCouponModel productCouponModel) {
+        return productCouponModelDao.getTotalCount(productCouponModel);
+    }
+
+    public List<ProductCouponModel> getLimit(ProductCouponModel productCouponModel, int currPage, int pageSize) {
+        int currIndex = (currPage - 1) * pageSize;
+        return productCouponModelDao.getLimit(productCouponModel, currIndex, pageSize);
+    }
+
+    public ProductCouponModel get(long id){
+        return productCouponModelDao.get(id);
+    }
+
+}

+ 15 - 2
virgo.api/src/main/resources/mapper/ProductCouponMapper.xml

@@ -7,6 +7,7 @@
     <resultMap type="com.bosshand.virgo.api.workark.model.ProductCoupon" id="result">
         <id column="id" property="id"/>
         <result column="type" property="type"/>
+        <result column="otherType" property="otherType"/>
         <result column="discount" property="discount"/>
         <result column="organizationId" property="organizationId"/>
         <result column="userId" property="userId"/>
@@ -20,6 +21,7 @@
         <result column="couponAmount" property="couponAmount"/>
         <result column="title" property="title"/>
         <result column="threshold" property="threshold"/>
+        <result column="mostConstraint" property="mostConstraint"/>
         <result column="description" property="description"/>
     </resultMap>
 
@@ -39,6 +41,9 @@
             <if test="type != null">
                 and type = #{type}
             </if>
+            <if test="otherType != null">
+                and otherType = #{otherType}
+            </if>
             <if test="state != null">
                 and state = #{state}
             </if>
@@ -60,6 +65,9 @@
             <if test="type != null">
                 and type = #{type}
             </if>
+            <if test="otherType != null">
+                and otherType = #{otherType}
+            </if>
             <if test="state != null">
                 and state = #{state}
             </if>
@@ -81,6 +89,9 @@
             <if test="p.type != null">
                 and type = #{p.type}
             </if>
+            <if test="p.otherType != null">
+                and otherType = #{p.otherType}
+            </if>
             <if test="p.state != null">
                 and state = #{p.state}
             </if>
@@ -92,14 +103,15 @@
     </select>
 
     <insert id="save" useGeneratedKeys="true" keyProperty="id">
-        INSERT INTO workark_product_coupon (type, discount, organizationId, userId, createTime, lifespan, productLevelId, couponAmount, title, threshold, description)
-        VALUES (#{type}, #{discount}, #{organizationId}, #{userId}, now(), #{lifespan}, #{productLevelId}, #{couponAmount}, #{title}, #{threshold}, #{description})
+        INSERT INTO workark_product_coupon (type, otherType, discount, organizationId, userId, createTime, lifespan, productLevelId, couponAmount, title, threshold, mostConstraint, description)
+        VALUES (#{type}, #{otherType}, #{discount}, #{organizationId}, #{userId}, now(), #{lifespan}, #{productLevelId}, #{couponAmount}, #{title}, #{threshold}, #{mostConstraint}, #{description})
     </insert>
 
     <update id="update" parameterType="com.bosshand.virgo.api.workark.model.ProductCoupon">
         UPDATE workark_product_coupon
         <trim prefix="set" suffixOverrides=",">
             <if test="type!=null">type=#{type},</if>
+            <if test="otherType!=null">otherType=#{otherType},</if>
             <if test="discount!=null">discount=#{discount},</if>
             <if test="organizationId!=0">organizationId=#{organizationId},</if>
             <if test="userId!=0">userId=#{userId},</if>
@@ -112,6 +124,7 @@
             <if test="couponAmount!=null">couponAmount=#{couponAmount},</if>
             <if test="title!=null">title=#{title},</if>
             <if test="threshold!=null">threshold=#{threshold},</if>
+            <if test="mostConstraint!=null">mostConstraint=#{mostConstraint},</if>
             <if test="description!=null">description=#{description},</if>
         </trim>
         WHERE id=#{id}

+ 98 - 0
virgo.api/src/main/resources/mapper/ProductCouponModelMapper.xml

@@ -0,0 +1,98 @@
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.bosshand.virgo.api.workark.dao.ProductCouponModelDao">
+
+    <resultMap type="com.bosshand.virgo.api.workark.model.ProductCouponModel" id="result">
+        <id column="id" property="id"/>
+        <result column="type" property="type"/>
+        <result column="otherType" property="otherType"/>
+        <result column="discount" property="discount"/>
+        <result column="createTime" property="createTime"/>
+        <result column="lifespan" property="lifespan"/>
+        <result column="productLevelId" property="productLevelId"/>
+        <result column="couponAmount" property="couponAmount"/>
+        <result column="title" property="title"/>
+        <result column="threshold" property="threshold"/>
+        <result column="mostConstraint" property="mostConstraint"/>
+        <result column="description" property="description"/>
+    </resultMap>
+
+    <select id="get" resultMap="result">
+        select * from workark_product_coupon_model where id = #{id}
+    </select>
+
+    <select id="getList" resultMap="result">
+        select * from workark_product_coupon_model
+        <where>
+            <if test="type != null">
+                and type = #{type}
+            </if>
+            <if test="otherType != null">
+                and otherType = #{otherType}
+            </if>
+            <if test="productLevelId != 0">
+                and productLevelId = #{productLevelId}
+            </if>
+        </where>
+    </select>
+
+    <select id="getTotalCount" parameterType="com.bosshand.virgo.api.workark.model.ProductCouponModel" resultType="Integer">
+        SELECT count(*) FROM workark_product_coupon_model
+        <where>
+            <if test="type != null">
+                and type = #{type}
+            </if>
+            <if test="otherType != null">
+                and otherType = #{otherType}
+            </if>
+            <if test="productLevelId != 0">
+                and productLevelId = #{productLevelId}
+            </if>
+        </where>
+    </select>
+
+    <select id="getLimit" resultMap="result">
+        select * from workark_product_coupon_model
+        <where>
+            <if test="p.type != null">
+                and type = #{p.type}
+            </if>
+            <if test="p.otherType != null">
+                and otherType = #{p.otherType}
+            </if>
+            <if test="p.productLevelId != 0">
+                and productLevelId = #{p.productLevelId}
+            </if>
+        </where>
+        order by createTime desc limit #{currIndex} , #{pageSize}
+    </select>
+
+    <insert id="save" useGeneratedKeys="true" keyProperty="id">
+        INSERT INTO workark_product_coupon_model (type, otherType, discount, createTime, lifespan, productLevelId, couponAmount, title, threshold, mostConstraint, description)
+        VALUES (#{type}, #{otherType}, #{discount}, now(), #{lifespan}, #{productLevelId}, #{couponAmount}, #{title}, #{threshold}, #{mostConstraint}, #{description})
+    </insert>
+
+    <update id="update" parameterType="com.bosshand.virgo.api.workark.model.ProductCouponModel">
+        UPDATE workark_product_coupon_model
+        <trim prefix="set" suffixOverrides=",">
+            <if test="type!=null">type=#{type},</if>
+            <if test="otherType!=null">otherType=#{otherType},</if>
+            <if test="discount!=null">discount=#{discount},</if>
+            <if test="lifespan!=null">lifespan=#{lifespan},</if>
+            <if test="productLevelId!=0">productLevelId=#{productLevelId},</if>
+            <if test="couponAmount!=null">couponAmount=#{couponAmount},</if>
+            <if test="title!=null">title=#{title},</if>
+            <if test="threshold!=null">threshold=#{threshold},</if>
+            <if test="mostConstraint!=null">mostConstraint=#{mostConstraint},</if>
+            <if test="description!=null">description=#{description},</if>
+        </trim>
+        WHERE id=#{id}
+    </update>
+
+    <delete id="delete">
+        DELETE FROM workark_product_coupon_model WHERE id=#{id}
+    </delete>
+
+</mapper>