dcs 2 months ago
parent
commit
3465493b73

+ 68 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/controller/ProductCouponController.java

@@ -0,0 +1,68 @@
+package com.bosshand.virgo.api.workark.controller;
+
+
+import com.bosshand.virgo.api.workark.model.ProductCoupon;
+import com.bosshand.virgo.api.workark.service.ProductCouponService;
+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({"workarkProductCoupon"})
+@Api(tags = {"商品优惠券管理"})
+public class ProductCouponController {
+
+    @Autowired
+    ProductCouponService productCouponService;
+
+    @ApiOperation("保存")
+    @RequestMapping(value = "", method = RequestMethod.POST)
+    public Response insert(@RequestBody ProductCoupon productCoupon) {
+        productCouponService.save(productCoupon);
+        return Response.ok();
+    }
+
+    @ApiOperation("更新")
+    @RequestMapping(value = "/update", method = RequestMethod.PUT)
+    public Response update(@RequestBody ProductCoupon productCoupon) {
+        productCouponService.update(productCoupon);
+        return Response.ok();
+    }
+
+    @ApiOperation("删除")
+    @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
+    public Response delete(@PathVariable long id) {
+        productCouponService.delete(id);
+        return Response.ok();
+    }
+
+    @ApiOperation("查询")
+    @RequestMapping(value = "/query", method = RequestMethod.POST)
+    public Response getList(@RequestBody ProductCoupon productCoupon) {
+        return Response.ok(productCouponService.getList(productCoupon));
+    }
+
+    @ApiOperation("分页查询")
+    @RequestMapping(value = "/{currPage}/{pageSize}", method = RequestMethod.POST)
+    public Response list(@RequestBody ProductCoupon productCoupon, @PathVariable int currPage, @PathVariable int pageSize) {
+        int totalCount = productCouponService.getTotalCount(productCoupon);
+        List<ProductCoupon> dataList = productCouponService.getLimit(productCoupon, 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(productCouponService.get(id));
+    }
+
+}

+ 25 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/dao/ProductCouponDao.java

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

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

@@ -0,0 +1,221 @@
+package com.bosshand.virgo.api.workark.model;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * 商品优惠券
+ */
+public class ProductCoupon {
+
+    private Long id;
+
+    /**
+     * 类型(1、打折,2、现金)
+     */
+    private Integer type;
+
+    /**
+     * 折扣(0.88折,0.75折 等)
+     */
+    private BigDecimal discount;
+
+    /**
+     * 组织id
+     */
+    private long organizationId;
+
+    /**
+     * 用户id
+     */
+    private long userId;
+
+    /**
+     * 状态 (0、待领取,1、已领取,2、已使用 3、已过期)
+     */
+    private Integer state;
+
+    /**
+     * 创建时间
+     */
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date createTime;
+
+    /**
+     * 领取时间
+     */
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date receiveTime;
+
+    /**
+     * 使用时间
+     */
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date useTime;
+
+    /**
+     * 失效时间
+     */
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date terminateTime;
+
+    /**
+     * 有效期 (小时)
+     */
+    private Integer lifespan;
+
+    /**
+     * 商品目录id (可以使用优惠券的范围)
+     */
+    private long productLevelId;
+
+    /**
+     * 优惠金额 (元)
+     */
+    private BigDecimal couponAmount;
+
+    /**
+     * 标题
+     */
+    private String title;
+
+    /**
+     *  门槛金额
+     */
+    private BigDecimal threshold;
+
+    /**
+     * 使用说明
+     */
+    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 BigDecimal getDiscount() {
+        return discount;
+    }
+
+    public void setDiscount(BigDecimal discount) {
+        this.discount = discount;
+    }
+
+    public long getOrganizationId() {
+        return organizationId;
+    }
+
+    public void setOrganizationId(long organizationId) {
+        this.organizationId = organizationId;
+    }
+
+    public long getUserId() {
+        return userId;
+    }
+
+    public void setUserId(long userId) {
+        this.userId = userId;
+    }
+
+    public Integer getState() {
+        return state;
+    }
+
+    public void setState(Integer state) {
+        this.state = state;
+    }
+
+    public Date getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+
+    public Date getReceiveTime() {
+        return receiveTime;
+    }
+
+    public void setReceiveTime(Date receiveTime) {
+        this.receiveTime = receiveTime;
+    }
+
+    public Date getUseTime() {
+        return useTime;
+    }
+
+    public void setUseTime(Date useTime) {
+        this.useTime = useTime;
+    }
+
+    public Date getTerminateTime() {
+        return terminateTime;
+    }
+
+    public void setTerminateTime(Date terminateTime) {
+        this.terminateTime = terminateTime;
+    }
+
+    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 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/ProductCouponService.java

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

+ 124 - 0
virgo.api/src/main/resources/mapper/ProductCouponMapper.xml

@@ -0,0 +1,124 @@
+<!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.ProductCouponDao">
+
+    <resultMap type="com.bosshand.virgo.api.workark.model.ProductCoupon" id="result">
+        <id column="id" property="id"/>
+        <result column="type" property="type"/>
+        <result column="discount" property="discount"/>
+        <result column="organizationId" property="organizationId"/>
+        <result column="userId" property="userId"/>
+        <result column="state" property="state"/>
+        <result column="createTime" property="createTime"/>
+        <result column="receiveTime" property="receiveTime"/>
+        <result column="useTime" property="useTime"/>
+        <result column="terminateTime" property="terminateTime"/>
+        <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="description" property="description"/>
+    </resultMap>
+
+    <select id="get" resultMap="result">
+        select * from workark_product_coupon where id = #{id}
+    </select>
+
+    <select id="getList" resultMap="result">
+        select * from workark_product_coupon
+        <where>
+            <if test="organizationId != 0">
+                and organizationId = #{organizationId}
+            </if>
+            <if test="userId != 0">
+                and userId = #{userId}
+            </if>
+            <if test="type != null">
+                and type = #{type}
+            </if>
+            <if test="state != null">
+                and state = #{state}
+            </if>
+            <if test="productLevelId != 0">
+                and productLevelId = #{productLevelId}
+            </if>
+        </where>
+    </select>
+
+    <select id="getTotalCount" parameterType="com.bosshand.virgo.api.workark.model.ProductCoupon" resultType="Integer">
+        SELECT count(*) FROM workark_product_coupon
+        <where>
+            <if test="organizationId != 0">
+                and organizationId = #{organizationId}
+            </if>
+            <if test="userId != 0">
+                and userId = #{userId}
+            </if>
+            <if test="type != null">
+                and type = #{type}
+            </if>
+            <if test="state != null">
+                and state = #{state}
+            </if>
+            <if test="productLevelId != 0">
+                and productLevelId = #{productLevelId}
+            </if>
+        </where>
+    </select>
+
+    <select id="getLimit" resultMap="result">
+        select * from workark_product_coupon
+        <where>
+            <if test="p.organizationId != 0">
+                and organizationId = #{p.organizationId}
+            </if>
+            <if test="p.userId != 0">
+                and userId = #{p.userId}
+            </if>
+            <if test="p.type != null">
+                and type = #{p.type}
+            </if>
+            <if test="p.state != null">
+                and state = #{p.state}
+            </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 (type, discount, organizationId, userId, createTime, lifespan, productLevelId, couponAmount, title, threshold, description)
+        VALUES (#{type}, #{discount}, #{organizationId}, #{userId}, now(), #{lifespan}, #{productLevelId}, #{couponAmount}, #{title}, #{threshold}, #{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="discount!=null">discount=#{discount},</if>
+            <if test="organizationId!=0">organizationId=#{organizationId},</if>
+            <if test="userId!=0">userId=#{userId},</if>
+            <if test="state!=null">state=#{state},</if>
+            <if test="state==1">receiveTime=now(),</if>
+            <if test="state==2">useTime=now(),</if>
+            <if test="state==3">terminateTime=now(),</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="description!=null">description=#{description},</if>
+        </trim>
+        WHERE id=#{id}
+    </update>
+
+    <delete id="delete">
+        DELETE FROM workark_product_coupon WHERE id=#{id}
+    </delete>
+
+</mapper>