|
@@ -0,0 +1,145 @@
|
|
|
+package com.caimei365.tools.service.impl;
|
|
|
+
|
|
|
+import com.caimei365.tools.mapper.CmBehaviorRecordMapper;
|
|
|
+import com.caimei365.tools.model.po.CmCouponAssociatePo;
|
|
|
+import com.caimei365.tools.model.po.CmCouponPo;
|
|
|
+import com.caimei365.tools.model.po.CmVipCouponPo;
|
|
|
+import com.caimei365.tools.model.po.CmVipCouponRelation;
|
|
|
+import com.caimei365.tools.service.CmVipCouponService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Description
|
|
|
+ *
|
|
|
+ * @author : Charles
|
|
|
+ * @date : 2023/2/1
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class CmVipCouponServiceImpl implements CmVipCouponService {
|
|
|
+ private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
|
|
|
+ private static Calendar calendar = Calendar.getInstance();
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CmBehaviorRecordMapper cmBehaviorRecordMapper;
|
|
|
+ /**
|
|
|
+ * 放开优惠券,创建下季度优惠券
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void openCoupon() {
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
|
|
|
+ Date date = new Date();
|
|
|
+ String startTime = simpleDateFormat.format(date);
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(date);
|
|
|
+ calendar.add(Calendar.MONTH,3);
|
|
|
+ Date time = calendar.getTime();
|
|
|
+ String endTime = simpleDateFormat.format(time);
|
|
|
+ CmVipCouponPo vipCouponPo = new CmVipCouponPo();
|
|
|
+
|
|
|
+ List<CmVipCouponPo> cmVipCouponPoList = 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 修改专属优惠券配置中优惠券的有效时间
|
|
|
+ calendar.setTime(time);
|
|
|
+ calendar.add(Calendar.MONTH,2);
|
|
|
+ Date times =calendar.getTime();
|
|
|
+ String formatTime = simpleDateFormat.format(times);
|
|
|
+ Date startDate = getMinDay(endTime);
|
|
|
+ Date endDate = getMaxDay(formatTime);
|
|
|
+ CmCouponAssociatePo associatePo = new CmCouponAssociatePo();
|
|
|
+ List<CmCouponPo> cmCouponPoList = cmBehaviorRecordMapper.selCoupon();
|
|
|
+ for (CmCouponPo cmCouponPo: cmCouponPoList) {
|
|
|
+
|
|
|
+ cmCouponPo.setConfigure(0);
|
|
|
+ // 修改优惠券配置属性
|
|
|
+ cmBehaviorRecordMapper.updateCoupon(cmCouponPo);
|
|
|
+ // 插入专属优惠券配置中优惠券
|
|
|
+ cmCouponPo.setName("超级会员优惠券"+endTime);
|
|
|
+ cmCouponPo.setStartDate(startDate);
|
|
|
+ cmCouponPo.setEndDate(endDate);
|
|
|
+ cmCouponPo.setConfigure(1);
|
|
|
+ cmCouponPo.setCreateDate(new Date());
|
|
|
+ cmCouponPo.setDelFlag("0");
|
|
|
+ cmBehaviorRecordMapper.insertCoupon(cmCouponPo);
|
|
|
+ // 插入新优惠券商品
|
|
|
+ Integer integer = cmBehaviorRecordMapper.selById();
|
|
|
+ List<CmCouponAssociatePo> associatePoList = cmBehaviorRecordMapper.selCouponPro(cmCouponPo.getId());
|
|
|
+ if (associatePoList.size() != 0) {
|
|
|
+ for (CmCouponAssociatePo couponAssociatePo : associatePoList) {
|
|
|
+ couponAssociatePo.setCouponId(integer);
|
|
|
+ cmBehaviorRecordMapper.insertCouponAssociate(couponAssociatePo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("========优惠券创建成功========");
|
|
|
+ /*
|
|
|
+ * vip优惠券月份关系
|
|
|
+ */
|
|
|
+ CmVipCouponRelation relation = new CmVipCouponRelation();
|
|
|
+ Integer cmVipCouponPoId = cmBehaviorRecordMapper.selSvipCouponById();
|
|
|
+ List<CmCouponPo> cmCouponPos = cmBehaviorRecordMapper.selCoupon();
|
|
|
+ if (cmVipCouponPoId != 0 && cmVipCouponPoId != null) {
|
|
|
+ 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优惠券月份关系创建========");
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ 输入日期字符串比如201703,返回当月第一天的Date
|
|
|
+ */
|
|
|
+ public static Date getMinDay(String month) {
|
|
|
+ try {
|
|
|
+ Date nowDate = sdf.parse(month);
|
|
|
+ calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(nowDate);
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
|
|
|
+ return calendar.getTime();
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ 输入日期字符串,返回下个月1号0点
|
|
|
+ */
|
|
|
+ public static Date getMaxDay(String month) {
|
|
|
+ try {
|
|
|
+ Date nowDate = sdf.parse(month);
|
|
|
+ calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(nowDate);
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH,1);
|
|
|
+ return calendar.getTime();
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|