|
@@ -1,15 +1,27 @@
|
|
|
package com.txz.mall.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.txz.mall.core.AbstractService;
|
|
|
+import com.txz.mall.core.ServiceException;
|
|
|
+import com.txz.mall.core.UserUtil;
|
|
|
+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 dto.StoreFlashActivityDTO;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
import tk.mybatis.mapper.entity.Condition;
|
|
|
import tk.mybatis.mapper.entity.Example;
|
|
|
+import vo.FlashActivityVO;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.Date;
|
|
@@ -26,6 +38,10 @@ public class StoreFlashActivityServiceImpl extends AbstractService<StoreFlashAct
|
|
|
@Resource
|
|
|
private StoreFlashActivityMapper storeFlashActivityMapper;
|
|
|
|
|
|
+ @Lazy
|
|
|
+ @Resource
|
|
|
+ private StoreCombinationMapper storeCombinationMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public List<StoreFlashActivity> activityList(StoreFlashActivity storeFlashActivity, Integer page, Integer size) {
|
|
|
PageHelper.startPage(page, size);
|
|
@@ -60,4 +76,133 @@ public class StoreFlashActivityServiceImpl extends AbstractService<StoreFlashAct
|
|
|
}
|
|
|
return activityList;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void modify(StoreFlashActivityDTO dto) {
|
|
|
+
|
|
|
+ StoreFlashActivity storeFlashActivityOri = findById(dto.getId());
|
|
|
+ if(ObjectUtils.isEmpty(storeFlashActivityOri)){
|
|
|
+ throw new ServiceException("活动不存在id:"+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());
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ 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"))){
|
|
|
+ tokenUserId = tokenUser.getLongValue("id");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Date date = new Date();
|
|
|
+
|
|
|
+ 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) {
|
|
|
+ storeFlashActivity.setActiveState(1);
|
|
|
+ } else if (date.compareTo(storeFlashActivity.getEndTime()) > 0) {
|
|
|
+ storeFlashActivity.setActiveState(2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ storeFlashActivity.setUpdateTime(date);
|
|
|
+ storeFlashActivity.setUpdateUserId(tokenUserId);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ update(storeFlashActivity);
|
|
|
+
|
|
|
+ //活动商品信息联动
|
|
|
+
|
|
|
+ Example exampleStoreCombination = new Example(StoreCombination.class);
|
|
|
+ exampleStoreCombination.createCriteria()
|
|
|
+ .andEqualTo("activityId",dto.getId());
|
|
|
+
|
|
|
+ StoreCombination storeCombination = new StoreCombination();
|
|
|
+ // 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())
|
|
|
+ ){
|
|
|
+ storeCombination.setIsShow(1);
|
|
|
+ }else{
|
|
|
+ storeCombination.setIsShow(0);
|
|
|
+ }
|
|
|
+ storeCombination.setStartTime(storeFlashActivity.getStartTime());
|
|
|
+ storeCombination.setStopTime(storeFlashActivity.getEndTime());
|
|
|
+// storeCombination.setIsDelete(storeFlashActivity.getIsDelete());
|
|
|
+ storeCombination.setUpdateUserId(storeFlashActivity.getUpdateUserId());
|
|
|
+ storeCombinationMapper.updateByConditionSelective(storeCombination,exampleStoreCombination);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delete(StoreFlashActivity storeFlashActivity) {
|
|
|
+
|
|
|
+ StoreFlashActivity storeFlashActivityOri = findById(storeFlashActivity.getId());
|
|
|
+ if(ObjectUtils.isEmpty(storeFlashActivityOri)){
|
|
|
+ throw new ServiceException("活动不存在id:"+storeFlashActivityOri.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject tokenUser = UserUtil.getTokenUser(null);
|
|
|
+ Long tokenUserId = 0L;
|
|
|
+
|
|
|
+ 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());
|
|
|
+
|
|
|
+ StoreCombination storeCombination = new StoreCombination();
|
|
|
+ storeCombination.setIsShow(0);
|
|
|
+ storeCombination.setIsDelete(storeFlashActivity.getIsDelete());
|
|
|
+ storeCombination.setUpdateUserId(storeFlashActivity.getUpdateUserId());
|
|
|
+ storeCombinationMapper.updateByConditionSelective(storeCombination,exampleStoreCombination);
|
|
|
+ }
|
|
|
}
|