Mr.qian 2 týždňov pred
rodič
commit
4746b2782c

+ 94 - 79
mall-service/src/main/java/com/txz/mall/service/impl/StoreFlashActivityServiceImpl.java

@@ -1,5 +1,6 @@
 package com.txz.mall.service.impl;
 
+import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.github.pagehelper.PageHelper;
 import com.txz.mall.core.AbstractService;
@@ -9,9 +10,7 @@ import com.txz.mall.dao.StoreCombinationMapper;
 import com.txz.mall.dao.StoreFlashActivityMapper;
 import com.txz.mall.model.StoreCombination;
 import com.txz.mall.model.StoreFlashActivity;
-import com.txz.mall.service.StoreCombinationService;
 import com.txz.mall.service.StoreFlashActivityService;
-import com.txz.mall.util.EasyToUseUtil;
 import com.txz.mall.util.I18nUtil;
 import dto.StoreFlashActivityDTO;
 import org.apache.commons.lang3.StringUtils;
@@ -35,14 +34,14 @@ import java.util.List;
 @Service
 @Transactional
 public class StoreFlashActivityServiceImpl extends AbstractService<StoreFlashActivity> implements StoreFlashActivityService {
-
+    
     @Resource
     private StoreFlashActivityMapper storeFlashActivityMapper;
-
+    
     @Lazy
     @Resource
     private StoreCombinationMapper storeCombinationMapper;
-
+    
     @Override
     public List<StoreFlashActivity> activityList(StoreFlashActivity storeFlashActivity, Integer page, Integer size) {
         PageHelper.startPage(page, size);
@@ -59,17 +58,35 @@ public class StoreFlashActivityServiceImpl extends AbstractService<StoreFlashAct
         if (storeFlashActivity.getStatus() != null) {
             criteria.andEqualTo("status", storeFlashActivity.getStatus());
         }
-        if (storeFlashActivity.getActiveState() != null) {
-            criteria.andEqualTo("activeState", storeFlashActivity.getActiveState());
+        // if (storeFlashActivity.getActiveState() != null) {
+        //     criteria.andEqualTo("activeState", storeFlashActivity.getActiveState());
+        // }
+        
+        // 不知道哪个臭SB写的,减少改动,暂时先这样处理
+        Date now = new Date();
+        if (ObjectUtil.isNotEmpty(storeFlashActivity.getActiveState())) {
+            
+            switch (storeFlashActivity.getActiveState()) {
+                case 0:
+                    criteria.andGreaterThan("startTime", now);
+                    break;
+                case 1:
+                    criteria.andLessThanOrEqualTo("startTime", now);
+                    criteria.andGreaterThanOrEqualTo("endTime", now);
+                    break;
+                case 2:
+                    criteria.andLessThan("endTime", now);
+                    break;
+            }
         }
-        Date date = new Date();
+        
         List<StoreFlashActivity> activityList = findByCondition(condition);
         for (StoreFlashActivity flashActivity : activityList) {
             Date startTime = flashActivity.getStartTime();
             Date endTime = flashActivity.getEndTime();
-            if (startTime.getTime() > date.getTime()) {
+            if (startTime.getTime() > now.getTime()) {
                 flashActivity.setActiveState(0);
-            } else if (endTime.getTime() < date.getTime()) {
+            } else if (endTime.getTime() < now.getTime()) {
                 flashActivity.setActiveState(2);
             } else {
                 flashActivity.setActiveState(1);
@@ -77,52 +94,52 @@ public class StoreFlashActivityServiceImpl extends AbstractService<StoreFlashAct
         }
         return activityList;
     }
-
+    
     @Override
     public void modify(StoreFlashActivityDTO dto) {
-
+        
         StoreFlashActivity storeFlashActivityOri = findById(dto.getId());
-        if(ObjectUtils.isEmpty(storeFlashActivityOri)){
+        if (ObjectUtils.isEmpty(storeFlashActivityOri)) {
             String s = I18nUtil.get("activity.does.not.exist.id");
-            throw new ServiceException(s+storeFlashActivityOri.getId());
+            throw new ServiceException(s + storeFlashActivityOri.getId());
         }
-//        FlashActivityVO activityVOOri = new FlashActivityVO();
-//        //数据库中的现有数据
-//        Integer statusOri = storeFlashActivityOri.getStatus();  //目测这也是可以控制活动是否开启的 也对应对应m_store_combination.isshow
-//        String contentOri = storeFlashActivityOri.getContent();  //解析出来对应 `effective_time`拼团订单有效时间(小时)', `people` stock
-//        if(!ObjectUtils.isEmpty(contentOri)) {
-//             activityVOOri = JSONObject.parseObject(storeFlashActivityOri.getContent(), FlashActivityVO.class);
-//        }
-//        Date startTimeOri = storeFlashActivityOri.getStartTime();
-//        Date endTimeOri = storeFlashActivityOri.getEndTime();
-//        Integer isDeleteOri = storeFlashActivityOri.getIsDelete();
-//        Integer activeStateOri = storeFlashActivityOri.getActiveState();//活动状态目测是定时任务来时时修改的  对应m_store_combination.isshow
-
-//        storeCombination.setPeople(activityVO.getGroupNumber());
-//        storeCombination.setEffectiveTime(activityVO.getCountdownTime());
-//        if (activityVO.getInventory() != null) {
-//            storeCombination.setStock(activityVO.getInventory());
-//        }
-
-
+        //        FlashActivityVO activityVOOri = new FlashActivityVO();
+        //        //数据库中的现有数据
+        //        Integer statusOri = storeFlashActivityOri.getStatus();  //目测这也是可以控制活动是否开启的 也对应对应m_store_combination.isshow
+        //        String contentOri = storeFlashActivityOri.getContent();  //解析出来对应 `effective_time`拼团订单有效时间(小时)', `people` stock
+        //        if(!ObjectUtils.isEmpty(contentOri)) {
+        //             activityVOOri = JSONObject.parseObject(storeFlashActivityOri.getContent(), FlashActivityVO.class);
+        //        }
+        //        Date startTimeOri = storeFlashActivityOri.getStartTime();
+        //        Date endTimeOri = storeFlashActivityOri.getEndTime();
+        //        Integer isDeleteOri = storeFlashActivityOri.getIsDelete();
+        //        Integer activeStateOri = storeFlashActivityOri.getActiveState();//活动状态目测是定时任务来时时修改的  对应m_store_combination.isshow
+        
+        //        storeCombination.setPeople(activityVO.getGroupNumber());
+        //        storeCombination.setEffectiveTime(activityVO.getCountdownTime());
+        //        if (activityVO.getInventory() != null) {
+        //            storeCombination.setStock(activityVO.getInventory());
+        //        }
+        
+        
         StoreFlashActivity storeFlashActivity = new StoreFlashActivity();
         BeanUtils.copyProperties(dto, storeFlashActivity);
         FlashActivityVO contentNow = dto.getContent();
         storeFlashActivity.setContent(JSONObject.toJSONString(dto.getContent()));
-
+        
         JSONObject tokenUser = UserUtil.getTokenUser(null);
         Long tokenUserId = 0L;
-
-
-        if(!ObjectUtils.isEmpty(tokenUser)){
-            if(!ObjectUtils.isEmpty(tokenUser.getLongValue("id"))){
+        
+        
+        if (!ObjectUtils.isEmpty(tokenUser)) {
+            if (!ObjectUtils.isEmpty(tokenUser.getLongValue("id"))) {
                 tokenUserId = tokenUser.getLongValue("id");
             }
         }
         Date date = new Date();
-
-        if((!ObjectUtils.isEmpty(storeFlashActivity.getStartTime())) && (!ObjectUtils.isEmpty(storeFlashActivity.getEndTime()))) {
-
+        
+        if ((!ObjectUtils.isEmpty(storeFlashActivity.getStartTime())) && (!ObjectUtils.isEmpty(storeFlashActivity.getEndTime()))) {
+            
             if (date.compareTo(storeFlashActivity.getStartTime()) < 0) {
                 storeFlashActivity.setActiveState(0);
             } else if (date.compareTo(storeFlashActivity.getStartTime()) >= 0 && date.compareTo(storeFlashActivity.getEndTime()) <= 0) {
@@ -133,78 +150,76 @@ public class StoreFlashActivityServiceImpl extends AbstractService<StoreFlashAct
         }
         storeFlashActivity.setUpdateTime(date);
         storeFlashActivity.setUpdateUserId(tokenUserId);
-
-
-
+        
+        
         update(storeFlashActivity);
-
-        //活动商品信息联动
-
+        
+        // 活动商品信息联动
+        
         Example exampleStoreCombination = new Example(StoreCombination.class);
         exampleStoreCombination.createCriteria()
-                .andEqualTo("activityId",dto.getId());
-
+                .andEqualTo("activityId", dto.getId());
+        
         StoreCombination storeCombination = new StoreCombination();
-       // storeCombination.setStock();
+        // storeCombination.setStock();
         storeCombination.setEffectiveTime(contentNow.getCountdownTime());
         storeCombination.setPeople(contentNow.getGroupNumber());
         Integer statusOne = 1;
         Integer statusZero = 0;
-
-
+        
+        
         //
-        if(statusOne.equals(storeFlashActivity.getActiveState())
-               //  && statusOne.equals(storeFlashActivity.getStatus())
-                &&  statusZero.equals(storeFlashActivity.getIsDelete())
-        ){
+        if (statusOne.equals(storeFlashActivity.getActiveState())
+                //  && statusOne.equals(storeFlashActivity.getStatus())
+                && statusZero.equals(storeFlashActivity.getIsDelete())
+        ) {
             storeCombination.setIsShow(1);
-        }else{
+        } else {
             storeCombination.setIsShow(0);
         }
         storeCombination.setStartTime(storeFlashActivity.getStartTime());
         storeCombination.setStopTime(storeFlashActivity.getEndTime());
-//        storeCombination.setIsDelete(storeFlashActivity.getIsDelete());
+        //        storeCombination.setIsDelete(storeFlashActivity.getIsDelete());
         storeCombination.setUpdateUserId(storeFlashActivity.getUpdateUserId());
-        storeCombinationMapper.updateByConditionSelective(storeCombination,exampleStoreCombination);
-
-
-
+        storeCombinationMapper.updateByConditionSelective(storeCombination, exampleStoreCombination);
+        
+        
     }
-
-
+    
+    
     @Override
     public void delete(StoreFlashActivity storeFlashActivity) {
-
+        
         StoreFlashActivity storeFlashActivityOri = findById(storeFlashActivity.getId());
-        if(ObjectUtils.isEmpty(storeFlashActivityOri)){
-            throw new ServiceException(I18nUtil.get("activity.does.not.exist.id")+storeFlashActivityOri.getId());
+        if (ObjectUtils.isEmpty(storeFlashActivityOri)) {
+            throw new ServiceException(I18nUtil.get("activity.does.not.exist.id") + storeFlashActivityOri.getId());
         }
-
+        
         JSONObject tokenUser = UserUtil.getTokenUser(null);
         Long tokenUserId = 0L;
-
-        if(!ObjectUtils.isEmpty(tokenUser)){
-            if(!ObjectUtils.isEmpty(tokenUser.getLongValue("id"))){
+        
+        if (!ObjectUtils.isEmpty(tokenUser)) {
+            if (!ObjectUtils.isEmpty(tokenUser.getLongValue("id"))) {
                 tokenUserId = tokenUser.getLongValue("id");
             }
         }
         Date date = new Date();
-
+        
         storeFlashActivity.setUpdateTime(date);
         storeFlashActivity.setUpdateUserId(tokenUserId);
-
+        
         update(storeFlashActivity);
-
-        //活动商品信息联动
-
+        
+        // 活动商品信息联动
+        
         Example exampleStoreCombination = new Example(StoreCombination.class);
         exampleStoreCombination.createCriteria()
-                .andEqualTo("activityId",storeFlashActivity.getId());
-
+                .andEqualTo("activityId", storeFlashActivity.getId());
+        
         StoreCombination storeCombination = new StoreCombination();
         storeCombination.setIsShow(0);
         storeCombination.setIsDelete(storeFlashActivity.getIsDelete());
         storeCombination.setUpdateUserId(storeFlashActivity.getUpdateUserId());
-        storeCombinationMapper.updateByConditionSelective(storeCombination,exampleStoreCombination);
+        storeCombinationMapper.updateByConditionSelective(storeCombination, exampleStoreCombination);
     }
 }