java110 5 gadi atpakaļ
vecāks
revīzija
9d1ff25cbd

+ 41 - 22
java110-bean/src/main/java/com/java110/po/groupBuyBatch/GroupBuyBatchPo.java

@@ -1,60 +1,79 @@
 package com.java110.po.groupBuyBatch;
 
 import java.io.Serializable;
-import java.util.Date;
 
 public class GroupBuyBatchPo implements Serializable {
 
     private String batchEndTime;
-private String statusCd = "0";
-private String batchId;
-private String storeId;
-private String settingId;
-private String batchStartTime;
-private String curBatch;
-public String getBatchEndTime() {
+    private String statusCd = "0";
+    private String batchId;
+    private String storeId;
+    private String settingId;
+    private String batchStartTime;
+    private String curBatch;
+    private String defaultCurBatch;
+
+    public String getBatchEndTime() {
         return batchEndTime;
     }
-public void setBatchEndTime(String batchEndTime) {
+
+    public void setBatchEndTime(String batchEndTime) {
         this.batchEndTime = batchEndTime;
     }
-public String getStatusCd() {
+
+    public String getStatusCd() {
         return statusCd;
     }
-public void setStatusCd(String statusCd) {
+
+    public void setStatusCd(String statusCd) {
         this.statusCd = statusCd;
     }
-public String getBatchId() {
+
+    public String getBatchId() {
         return batchId;
     }
-public void setBatchId(String batchId) {
+
+    public void setBatchId(String batchId) {
         this.batchId = batchId;
     }
-public String getStoreId() {
+
+    public String getStoreId() {
         return storeId;
     }
-public void setStoreId(String storeId) {
+
+    public void setStoreId(String storeId) {
         this.storeId = storeId;
     }
-public String getSettingId() {
+
+    public String getSettingId() {
         return settingId;
     }
-public void setSettingId(String settingId) {
+
+    public void setSettingId(String settingId) {
         this.settingId = settingId;
     }
-public String getBatchStartTime() {
+
+    public String getBatchStartTime() {
         return batchStartTime;
     }
-public void setBatchStartTime(String batchStartTime) {
+
+    public void setBatchStartTime(String batchStartTime) {
         this.batchStartTime = batchStartTime;
     }
-public String getCurBatch() {
+
+    public String getCurBatch() {
         return curBatch;
     }
-public void setCurBatch(String curBatch) {
+
+    public void setCurBatch(String curBatch) {
         this.curBatch = curBatch;
     }
 
+    public String getDefaultCurBatch() {
+        return defaultCurBatch;
+    }
 
-
+    public void setDefaultCurBatch(String defaultCurBatch) {
+        this.defaultCurBatch = defaultCurBatch;
+    }
 }

+ 11 - 6
java110-db/src/main/resources/mapper/goods/GroupBuyBatchServiceDaoImplMapper.xml

@@ -61,12 +61,7 @@
         <if test="batchEndTime !=null and batchEndTime != ''">
             , t.batch_end_time= #{batchEndTime}
         </if>
-        <if test="storeId !=null and storeId != ''">
-            , t.store_id= #{storeId}
-        </if>
-        <if test="settingId !=null and settingId != ''">
-            , t.setting_id= #{settingId}
-        </if>
+
         <if test="batchStartTime !=null and batchStartTime != ''">
             , t.batch_start_time= #{batchStartTime}
         </if>
@@ -77,6 +72,16 @@
         <if test="batchId !=null and batchId != ''">
             and t.batch_id= #{batchId}
         </if>
+        <if test="settingId !=null and settingId != ''">
+            and t.setting_id= #{settingId}
+        </if>
+        <if test="storeId !=null and storeId != ''">
+            and t.store_id= #{storeId}
+        </if>
+        <if test="defaultCurBatch !=null and defaultCurBatch != ''">
+            and t.cur_batch= #{defaultCurBatch}
+        </if>
+
 
     </update>
 

+ 5 - 6
java110-db/src/main/resources/mapper/goods/GroupBuyProductServiceDaoImplMapper.xml

@@ -65,9 +65,7 @@
     <!-- 修改拼团产品信息 add by wuxw 2018-07-03 -->
     <update id="updateGroupBuyProductInfo" parameterType="Map">
         update group_buy_product t set t.status_cd = #{statusCd}
-        <if test="newBId != null and newBId != ''">
-            ,t.b_id = #{newBId}
-        </if>
+
         <if test="groupProdName !=null and groupProdName != ''">
             , t.group_prod_name= #{groupProdName}
         </if>
@@ -86,9 +84,7 @@
         <if test="state !=null and state != ''">
             , t.state= #{state}
         </if>
-        <if test="storeId !=null and storeId != ''">
-            , t.store_id= #{storeId}
-        </if>
+
         <if test="batchId !=null and batchId != ''">
             , t.batch_id= #{batchId}
         </if>
@@ -96,6 +92,9 @@
         <if test="groupId !=null and groupId != ''">
             and t.group_id= #{groupId}
         </if>
+        <if test="storeId !=null and storeId != ''">
+            and t.store_id= #{storeId}
+        </if>
 
     </update>
 

+ 0 - 3
java110-db/src/main/resources/mapper/goods/GroupBuySettingServiceDaoImplMapper.xml

@@ -57,9 +57,6 @@
     <!-- 修改拼团设置信息 add by wuxw 2018-07-03 -->
     <update id="updateGroupBuySettingInfo" parameterType="Map">
         update group_buy_setting t set t.status_cd = #{statusCd}
-        <if test="newBId != null and newBId != ''">
-            ,t.b_id = #{newBId}
-        </if>
         <if test="groupBuyName !=null and groupBuyName != ''">
             , t.group_buy_name= #{groupBuyName}
         </if>

+ 1 - 1
service-goods/src/main/java/com/java110/goods/dao/IGroupBuyBatchServiceDao.java

@@ -47,7 +47,7 @@ public interface IGroupBuyBatchServiceDao {
      * @param info 修改信息
      * @throws DAOException DAO异常
      */
-    void updateGroupBuyBatchInfo(Map info) throws DAOException;
+    int updateGroupBuyBatchInfo(Map info) throws DAOException;
 
 
     /**

+ 22 - 22
service-goods/src/main/java/com/java110/goods/dao/impl/GroupBuyBatchServiceDaoImpl.java

@@ -1,15 +1,13 @@
 package com.java110.goods.dao.impl;
 
 import com.alibaba.fastjson.JSONObject;
-import com.java110.utils.constant.ResponseConstant;
-import com.java110.utils.exception.DAOException;
-import com.java110.utils.util.DateUtil;
 import com.java110.core.base.dao.BaseServiceDao;
 import com.java110.goods.dao.IGroupBuyBatchServiceDao;
+import com.java110.utils.constant.ResponseConstant;
+import com.java110.utils.exception.DAOException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 import java.util.Map;
@@ -25,37 +23,36 @@ public class GroupBuyBatchServiceDaoImpl extends BaseServiceDao implements IGrou
     private static Logger logger = LoggerFactory.getLogger(GroupBuyBatchServiceDaoImpl.class);
 
 
-
-
-
     /**
      * 保存拼团批次信息 到 instance
-     * @param info   bId 信息
+     *
+     * @param info bId 信息
      * @throws DAOException DAO异常
      */
     @Override
     public void saveGroupBuyBatchInfo(Map info) throws DAOException {
-        logger.debug("保存拼团批次信息Instance 入参 info : {}",info);
+        logger.debug("保存拼团批次信息Instance 入参 info : {}", info);
 
-        int saveFlag = sqlSessionTemplate.insert("groupBuyBatchServiceDaoImpl.saveGroupBuyBatchInfo",info);
+        int saveFlag = sqlSessionTemplate.insert("groupBuyBatchServiceDaoImpl.saveGroupBuyBatchInfo", info);
 
-        if(saveFlag < 1){
-            throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR,"保存拼团批次信息Instance数据失败:"+ JSONObject.toJSONString(info));
+        if (saveFlag < 1) {
+            throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR, "保存拼团批次信息Instance数据失败:" + JSONObject.toJSONString(info));
         }
     }
 
 
     /**
      * 查询拼团批次信息(instance)
+     *
      * @param info bId 信息
      * @return List<Map>
      * @throws DAOException DAO异常
      */
     @Override
     public List<Map> getGroupBuyBatchInfo(Map info) throws DAOException {
-        logger.debug("查询拼团批次信息 入参 info : {}",info);
+        logger.debug("查询拼团批次信息 入参 info : {}", info);
 
-        List<Map> businessGroupBuyBatchInfos = sqlSessionTemplate.selectList("groupBuyBatchServiceDaoImpl.getGroupBuyBatchInfo",info);
+        List<Map> businessGroupBuyBatchInfos = sqlSessionTemplate.selectList("groupBuyBatchServiceDaoImpl.getGroupBuyBatchInfo", info);
 
         return businessGroupBuyBatchInfos;
     }
@@ -63,28 +60,31 @@ public class GroupBuyBatchServiceDaoImpl extends BaseServiceDao implements IGrou
 
     /**
      * 修改拼团批次信息
+     *
      * @param info 修改信息
      * @throws DAOException DAO异常
      */
     @Override
-    public void updateGroupBuyBatchInfo(Map info) throws DAOException {
-        logger.debug("修改拼团批次信息Instance 入参 info : {}",info);
+    public int updateGroupBuyBatchInfo(Map info) throws DAOException {
+        logger.debug("修改拼团批次信息Instance 入参 info : {}", info);
 
-        int saveFlag = sqlSessionTemplate.update("groupBuyBatchServiceDaoImpl.updateGroupBuyBatchInfo",info);
+        int saveFlag = sqlSessionTemplate.update("groupBuyBatchServiceDaoImpl.updateGroupBuyBatchInfo", info);
 
-        if(saveFlag < 1){
-            throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR,"修改拼团批次信息Instance数据失败:"+ JSONObject.toJSONString(info));
-        }
+//        if(saveFlag < 1){
+//            throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR,"修改拼团批次信息Instance数据失败:"+ JSONObject.toJSONString(info));
+//        }
+        return saveFlag;
     }
 
-     /**
+    /**
      * 查询拼团批次数量
+     *
      * @param info 拼团批次信息
      * @return 拼团批次数量
      */
     @Override
     public int queryGroupBuyBatchsCount(Map info) {
-        logger.debug("查询拼团批次数据 入参 info : {}",info);
+        logger.debug("查询拼团批次数据 入参 info : {}", info);
 
         List<Map> businessGroupBuyBatchInfos = sqlSessionTemplate.selectList("groupBuyBatchServiceDaoImpl.queryGroupBuyBatchsCount", info);
         if (businessGroupBuyBatchInfos.size() < 1) {

+ 19 - 1
service-job/src/main/java/com/java110/job/quartz/TaskSystemQuartz.java

@@ -1,9 +1,11 @@
 package com.java110.job.quartz;
 
-import com.java110.intf.community.ICommunityInnerServiceSMO;
 import com.java110.dto.community.CommunityDto;
+import com.java110.dto.store.StoreDto;
 import com.java110.dto.task.TaskDto;
 import com.java110.dto.taskAttr.TaskAttrDto;
+import com.java110.intf.community.ICommunityInnerServiceSMO;
+import com.java110.intf.store.IStoreInnerServiceSMO;
 import com.java110.job.dao.ITaskServiceDao;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -26,6 +28,9 @@ public abstract class TaskSystemQuartz {
     @Autowired
     private ICommunityInnerServiceSMO communityInnerServiceSMOImpl;
 
+    @Autowired
+    private IStoreInnerServiceSMO storeInnerServiceSMOImpl;
+
 
     public void initTask() {
 
@@ -112,8 +117,21 @@ public abstract class TaskSystemQuartz {
         return communityDtos;
     }
 
+    /**
+     * 查询商户信息
+     *
+     * @return
+     */
+    protected List<StoreDto> getAllStore(String storeTypeCd) {
+        StoreDto storeDto = new StoreDto();
+        storeDto.setStoreTypeCd(storeTypeCd);
+        List<StoreDto> storeDtos = storeInnerServiceSMOImpl.getStores(storeDto);
+        return storeDtos;
+    }
+
     /**
      * 获取当前属性
+     *
      * @param taskDto
      * @param specCd
      * @return

+ 153 - 0
service-job/src/main/java/com/java110/job/task/groupBuy/GeneratorGroupBuyBatchTemplate.java

@@ -0,0 +1,153 @@
+package com.java110.job.task.groupBuy;
+
+import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.dto.groupBuySetting.GroupBuySettingDto;
+import com.java110.dto.store.StoreDto;
+import com.java110.dto.task.TaskDto;
+import com.java110.intf.IGroupBuyBatchInnerServiceSMO;
+import com.java110.intf.IGroupBuyProductInnerServiceSMO;
+import com.java110.intf.IGroupBuySettingInnerServiceSMO;
+import com.java110.job.quartz.TaskSystemQuartz;
+import com.java110.po.groupBuyBatch.GroupBuyBatchPo;
+import com.java110.po.groupBuyProduct.GroupBuyProductPo;
+import com.java110.po.groupBuySetting.GroupBuySettingPo;
+import com.java110.utils.util.Assert;
+import com.java110.utils.util.DateUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @program: MicroCommunity
+ * @description: 定时任务 定时生成批次
+ * @author: wuxw
+ * @create: 2020-06-15 13:35
+ **/
+@Component
+public class GeneratorGroupBuyBatchTemplate extends TaskSystemQuartz {
+
+    private static Logger logger = LoggerFactory.getLogger(GeneratorGroupBuyBatchTemplate.class);
+
+    private static final int EXPIRE_IN = 7200;
+
+    @Autowired
+    private IGroupBuySettingInnerServiceSMO groupBuySettingInnerServiceSMOImpl;
+
+    @Autowired
+    private IGroupBuyBatchInnerServiceSMO groupBuyBatchInnerServiceSMOImpl;
+
+    @Autowired
+    private IGroupBuyProductInnerServiceSMO groupBuyProductInnerServiceSMOImpl;
+
+
+    @Override
+    protected void process(TaskDto taskDto) {
+        logger.debug("开始生成拼团批次" + taskDto.toString());
+
+        // 获取小区
+        List<StoreDto> storeDtos = getAllStore(StoreDto.STORE_ADMIN);
+
+        for (StoreDto storeDto : storeDtos) {
+            try {
+                generatorGroupBuyBatch(taskDto, storeDto);
+            } catch (Exception e) {
+                logger.error("推送消息失败", e);
+            }
+        }
+    }
+
+    /**
+     * 轮训派单
+     *
+     * @param taskDto
+     * @param storeDto
+     */
+    private void generatorGroupBuyBatch(TaskDto taskDto, StoreDto storeDto) {
+
+        //查询需要程序轮训派单 订单
+        GroupBuySettingDto groupBuySettingDto = new GroupBuySettingDto();
+        groupBuySettingDto.setStoreId(storeDto.getStoreId());
+        List<GroupBuySettingDto> groupBuySettingDtos = groupBuySettingInnerServiceSMOImpl.queryGroupBuySettings(groupBuySettingDto);
+
+        Assert.listOnlyOne(groupBuySettingDtos, "未配置 拼团设置");
+
+        for (GroupBuySettingDto tmpGroupBuySettingDto : groupBuySettingDtos) {
+            try {
+                doGeneratorGroupBuyBatch(tmpGroupBuySettingDto);
+            } catch (Exception e) {
+                logger.error("生成批次", e);
+            }
+
+        }
+
+    }
+
+    /**
+     * 生成批次
+     *
+     * @param tmpGroupBuySettingDto
+     */
+    private void doGeneratorGroupBuyBatch(GroupBuySettingDto tmpGroupBuySettingDto) throws Exception {
+
+        Date endTime = DateUtil.getDateFromString(tmpGroupBuySettingDto.getEndTime(), DateUtil.DATE_FORMATE_STRING_A);
+        Date nowTime = DateUtil.getCurrentDate();
+
+        if (endTime.getTime() > nowTime.getTime()) { // 还没有到 批次结束
+            return;
+        }
+
+        Date startTime = endTime;
+
+        int validHours = Integer.parseInt(tmpGroupBuySettingDto.getValidHours());
+
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(endTime);
+        calendar.add(Calendar.HOUR_OF_DAY, validHours);
+
+        endTime = calendar.getTime();
+
+        GroupBuyBatchPo groupBuyBatchPo = new GroupBuyBatchPo();
+        groupBuyBatchPo.setSettingId(tmpGroupBuySettingDto.getSettingId());
+        groupBuyBatchPo.setStoreId(tmpGroupBuySettingDto.getStoreId());
+        groupBuyBatchPo.setCurBatch("F");
+        groupBuyBatchPo.setDefaultCurBatch("Y");
+        groupBuyBatchInnerServiceSMOImpl.updateGroupBuyBatch(groupBuyBatchPo);
+
+
+        groupBuyBatchPo.setCurBatch("Y");
+        groupBuyBatchPo.setBatchStartTime(DateUtil.getFormatTimeString(startTime, DateUtil.DATE_FORMATE_STRING_A));
+        groupBuyBatchPo.setBatchEndTime(DateUtil.getFormatTimeString(endTime,DateUtil.DATE_FORMATE_STRING_A));
+        groupBuyBatchPo.setBatchId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_batchId));
+        int flag = groupBuyBatchInnerServiceSMOImpl.saveGroupBuyBatch(groupBuyBatchPo);
+
+        if(flag < 1){
+            throw new IllegalArgumentException("保存批次失败");
+        }
+
+        //更新 setting 表
+        GroupBuySettingPo groupBuySettingPo = new GroupBuySettingPo();
+        groupBuySettingPo.setStartTime(DateUtil.getFormatTimeString(startTime, DateUtil.DATE_FORMATE_STRING_A));
+        groupBuySettingPo.setEndTime(DateUtil.getFormatTimeString(endTime,DateUtil.DATE_FORMATE_STRING_A));
+        groupBuySettingPo.setSettingId(tmpGroupBuySettingDto.getSettingId());
+        flag = groupBuySettingInnerServiceSMOImpl.updateGroupBuySetting(groupBuySettingPo);
+        if(flag < 1){
+            throw new IllegalArgumentException("保存批次失败");
+        }
+
+        GroupBuyProductPo groupBuyProductPo = new GroupBuyProductPo();
+        groupBuyProductPo.setStoreId(tmpGroupBuySettingDto.getStoreId());
+        groupBuyProductPo.setBatchId(groupBuyBatchPo.getBatchId());
+
+        flag = groupBuyProductInnerServiceSMOImpl.updateGroupBuyProduct(groupBuyProductPo);
+        if(flag < 1){
+            throw new IllegalArgumentException("保存批次失败");
+        }
+    }
+
+
+}