Ver código fonte

Merge branch 'dev_v1.3.4_20220902' of http://git.dayaedu.com/yonge/cooleshow into dev_v1.3.4_20220902

liujunchi 2 anos atrás
pai
commit
afb4c1a553

+ 6 - 2
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/io/request/coupon/CouponInfoVO.java

@@ -368,12 +368,16 @@ public class CouponInfoVO {
         }
 
         public CouponInfo inventory(Integer inventory) {
-            this.inventory = inventory;
+            if (Objects.isNull(this.inventory)) {
+                this.inventory = inventory;
+            }
             return this;
         }
 
         public CouponInfo quantityLimit(Integer quantityLimit) {
-            this.quantityLimit = quantityLimit;
+            if (Objects.isNull(this.quantityLimit)) {
+                this.quantityLimit = quantityLimit;
+            }
             return this;
         }
 

+ 17 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/CouponInfoServiceImp.java

@@ -19,6 +19,7 @@ import com.yonge.cooleshow.biz.dal.service.CouponInfoService;
 import com.yonge.cooleshow.biz.dal.vo.coupon.CouponInfoWrapper;
 import com.yonge.cooleshow.biz.dal.wrapper.StatGroupWrapper;
 import com.yonge.cooleshow.biz.dal.wrapper.coupon.CouponInventoryWrapper;
+import com.yonge.cooleshow.common.enums.EStatus;
 import com.yonge.toolset.base.exception.BizException;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -125,6 +126,7 @@ public class CouponInfoServiceImp extends ServiceImpl<CouponInfoMapper, CouponIn
      * @param couponInfo CouponInfo
      * @return CouponInfo
      */
+    @Transactional(rollbackFor = Exception.class)
     @Override
     public CouponInfo saveOrUpdateCouponInfo(CouponInfo couponInfo) {
 
@@ -132,6 +134,21 @@ public class CouponInfoServiceImp extends ServiceImpl<CouponInfoMapper, CouponIn
 
             // 新增优惠券
             save(couponInfo);
+
+            // 添加库存变更记录
+            if (couponInfo.getInventory() > 0) {
+
+                CouponInventoryWrapper wrapper = CouponInventoryWrapper.builder()
+                        .userId(couponInfo.getCreatedBy())
+                        .couponId(couponInfo.getId())
+                        .dataType(CouponInventoryEnum.ADDITION)
+                        .number(couponInfo.getInventory())
+                        .remark("")
+                        .status(EStatus.ENABLE.getValue())
+                        .build();
+
+                couponInventoryMapper.insert(JSON.parseObject(wrapper.jsonString(), CouponInventory.class));
+            }
         } else {
 
             CouponInfo info = getById(couponInfo.getId());

+ 5 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/coupon/CouponInventoryWrapper.java

@@ -1,5 +1,6 @@
 package com.yonge.cooleshow.biz.dal.wrapper.coupon;
 
+import com.alibaba.fastjson.JSON;
 import com.yonge.cooleshow.biz.dal.enums.coupon.CouponInventoryEnum;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
@@ -32,6 +33,10 @@ public class CouponInventoryWrapper implements Serializable {
     private String username;
     private String realName;
 
+    public String jsonString() {
+        return JSON.toJSONString(this);
+    }
+
     public String getUsername() {
         if (StringUtils.isEmpty(this.username)
                 && StringUtils.isNotEmpty(getRealName())) {

+ 2 - 1
cooleshow-user/user-biz/src/main/resources/config/mybatis/CouponInfoMapper.xml

@@ -47,6 +47,7 @@
                 AND t1.category_ = #{record.category}
             </if>
         </where>
+        ORDER BY t1.id_ DESC
     </select>
 
     <!--优惠券发放统计-->
@@ -97,7 +98,7 @@
                 AND (#{record.startTime} &lt;= UNIX_TIMESTAMP(t1.created_time_) AND UNIX_TIMESTAMP(t1.created_time_) &lt;= #{record.endTime})
             </if>
         </where>
-        <if test="record.groupByUser != null">GROUP BY t1.user_id_</if>
+        <if test="record.groupByUser != null">GROUP BY t1.user_id_</if> ORDER BY t1.id_ DESC
     </select>
     <!--优惠券库存调整信息-->