huangzhiguo hace 2 años
padre
commit
7622501be1

+ 3 - 3
src/main/java/com/caimei365/tools/controller/BaseApi.java

@@ -62,9 +62,9 @@ public class BaseApi {
      * 临时接口
      */
     @GetMapping("/record/update")
-    public void svipCoupon(Integer startId, Integer endId) throws IOException {
-
-        cmBehaviorRecordService.updateClubAddress(startId, endId);
+    public void svipCoupon() throws IOException {
+        cmVipCouponService.openCoupon();
+//        cmBehaviorRecordService.updateClubAddress(startId, endId);
     }
 
     /**

+ 17 - 1
src/main/java/com/caimei365/tools/mapper/CmBehaviorRecordMapper.java

@@ -53,10 +53,18 @@ public interface CmBehaviorRecordMapper {
      */
     void updateOldData(CmUserPo userPo);
 
-    List<CmVipCouponPo> selSvipCoupon(@Param("startTime") String startTime, @Param("endTime") String endTime);
+    CmVipCouponPo selSvipCoupon(@Param("startTime") String startTime, @Param("endTime") String endTime);
 
+    /**
+     * 将本季度优惠券开放
+     * @param cmVipCouponPo
+     */
     void updateSvipCoupon(CmVipCouponPo cmVipCouponPo);
 
+    /**
+     * 生成下一季度优惠券
+     * @param cmVipCouponPo
+     */
     void insertVipCouponMonth(CmVipCouponPo cmVipCouponPo);
 
     List<CmCouponPo> selCoupon();
@@ -67,10 +75,18 @@ public interface CmBehaviorRecordMapper {
 
     List<CmCouponAssociatePo> selCouponPro(@Param("couponId") Integer couponId);
 
+    /**
+     * 插入新优惠券商品
+     * @param associate
+     */
     void insertCouponAssociate(CmCouponAssociatePo associate);
 
     Integer selSvipCouponById();
 
+    /**
+     * vip优惠券月份关系
+     * @param cmVipCouponRelation
+     */
     void insertRelation(CmVipCouponRelation cmVipCouponRelation);
 
     List<CmBehaviorRecordPo> countNum(@Param("accessDate") String accessDate);

+ 19 - 29
src/main/java/com/caimei365/tools/service/impl/CmVipCouponServiceImpl.java

@@ -46,19 +46,15 @@ public class CmVipCouponServiceImpl implements CmVipCouponService {
         String endTime = simpleDateFormat.format(time);
         CmVipCouponPo vipCouponPo = new CmVipCouponPo();
 
-        List<CmVipCouponPo> cmVipCouponPoList = cmBehaviorRecordMapper.selSvipCoupon(startTime, endTime);
+        CmVipCouponPo cmVipCouponPo = cmBehaviorRecordMapper.selSvipCoupon(startTime, endTime);
         // 将本季度优惠券开放
-        if (cmVipCouponPoList.size() != 0) {
-            for (CmVipCouponPo cmVipCouponPo : cmVipCouponPoList) {
-                cmBehaviorRecordMapper.updateSvipCoupon(cmVipCouponPo);
-                // 生成下一季度优惠券
-                vipCouponPo.setUseTime(endTime);
-                vipCouponPo.setStatus("1");
-                vipCouponPo.setUpdateTime(date);
-                vipCouponPo.setDelFlag("1");
-                cmBehaviorRecordMapper.insertVipCouponMonth(vipCouponPo);
-            }
-        }
+        cmBehaviorRecordMapper.updateSvipCoupon(cmVipCouponPo);
+        // 生成下一季度优惠券
+        vipCouponPo.setUseTime(endTime);
+        vipCouponPo.setStatus("1");
+        vipCouponPo.setUpdateTime(date);
+        vipCouponPo.setDelFlag("1");
+        cmBehaviorRecordMapper.insertVipCouponMonth(vipCouponPo);
         // 修改专属优惠券配置中优惠券的有效时间
         calendar.setTime(time);
         calendar.add(Calendar.MONTH, 2);
@@ -80,6 +76,17 @@ public class CmVipCouponServiceImpl implements CmVipCouponService {
             cmCouponPo.setCreateDate(new Date());
             cmCouponPo.setDelFlag("0");
             cmBehaviorRecordMapper.insertCoupon(cmCouponPo);
+
+            /*
+             * vip优惠券月份关系
+             */
+            CmVipCouponRelation relation = new CmVipCouponRelation();
+            relation.setCouponId(cmCouponPo.getId());
+            relation.setMontId(vipCouponPo.getId());
+            relation.setDelFlag("0");
+            relation.setUpdateTime(date);
+            cmBehaviorRecordMapper.insertRelation(relation);
+
             // 插入新优惠券商品
             List<CmCouponAssociatePo> associatePoList = cmBehaviorRecordMapper.selCouponPro(cmCouponPo.getId());
             if (associatePoList.size() != 0) {
@@ -90,23 +97,6 @@ public class CmVipCouponServiceImpl implements CmVipCouponService {
             }
         }
         log.info("========优惠券创建成功========");
-        /*
-         * vip优惠券月份关系
-         */
-        CmVipCouponRelation relation = new CmVipCouponRelation();
-        Integer cmVipCouponPoId = cmBehaviorRecordMapper.selSvipCouponById();
-        List<CmCouponPo> cmCouponPos = cmBehaviorRecordMapper.selCoupon();
-        if (cmVipCouponPoId != 0 && null != cmVipCouponPoId ) {
-            for (int i = 0; i < cmCouponPos.size(); i++) {
-                relation.setCouponId(cmCouponPos.get(i).getId());
-                relation.setMontId(cmVipCouponPoId.toString());
-                relation.setDelFlag("0");
-                relation.setUpdateTime(date);
-                cmBehaviorRecordMapper.insertRelation(relation);
-            }
-        }
-
-        log.info("========vip优惠券月份关系创建========");
     }
 
     /**

+ 1 - 1
src/main/resources/mapper/CmBehaviorRecordMapper.xml

@@ -46,7 +46,7 @@
         SET delFlag = 0
         WHERE id = #{id}
     </update>
-    <insert id="insertVipCouponMonth">
+    <insert id="insertVipCouponMonth" parameterType="com.caimei365.tools.model.po.CmVipCouponPo" keyProperty="id" useGeneratedKeys="true" >
         INSERT INTO cm_svip_coupon_month (useTime, updateTime, status,delFlag)
         VALUES (#{useTime}, #{updateTime}, #{status}, #{delFlag})
     </insert>