| @@ -1,9 +1,12 @@ | |||||
| package com.iformall.schedule; | package com.iformall.schedule; | ||||
| import com.iformall.domain.po.WxOrder; | import com.iformall.domain.po.WxOrder; | ||||
| import com.iformall.domain.po.WxOrderGroup; | |||||
| import com.iformall.enums.EnumOrderStatus; | import com.iformall.enums.EnumOrderStatus; | ||||
| import com.iformall.enums.EnumOrderType; | import com.iformall.enums.EnumOrderType; | ||||
| import com.iformall.mapper.WxOrderGroupMapper; | |||||
| import com.iformall.mapper.WxOrderMapper; | import com.iformall.mapper.WxOrderMapper; | ||||
| import com.iformall.service.WxOrderGroupService; | |||||
| import com.iformall.service.WxOrderService; | import com.iformall.service.WxOrderService; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| @@ -30,6 +33,12 @@ public class OrderExpiringSchedule { | |||||
| @Autowired | @Autowired | ||||
| WxOrderService wxOrderService; | WxOrderService wxOrderService; | ||||
| @Autowired | |||||
| WxOrderGroupMapper wxOrderGroupMapper; | |||||
| @Autowired | |||||
| WxOrderGroupService wxOrderGroupService; | |||||
| @Scheduled(cron = "0 */5 * * * *?") // 每5分钟检查一次 | @Scheduled(cron = "0 */5 * * * *?") // 每5分钟检查一次 | ||||
| //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | ||||
| @@ -54,6 +63,12 @@ public class OrderExpiringSchedule { | |||||
| orderPresss.parallelStream().forEach( o -> { | orderPresss.parallelStream().forEach( o -> { | ||||
| orderPressExpired(o); | orderPressExpired(o); | ||||
| }); | }); | ||||
| //拼团 | |||||
| List<WxOrderGroup> orderGroups = wxOrderGroupService.findList(null); | |||||
| orderGroups.parallelStream().forEach(g -> { | |||||
| wxOrderGroupService.updateGroupStatus(g); | |||||
| }); | |||||
| } | } | ||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | ||||
| @@ -84,4 +99,5 @@ public class OrderExpiringSchedule { | |||||
| logger.info("\n砍价订单: " + order.getId() + " create at " + order.getCreateDate() + " expired at " + curDate); | logger.info("\n砍价订单: " + order.getId() + " create at " + order.getCreateDate() + " expired at " + curDate); | ||||
| } | } | ||||
| } | } | ||||
| @@ -6,6 +6,7 @@ import com.iformall.domain.po.WxCoupon; | |||||
| import com.iformall.domain.po.WxOrder; | import com.iformall.domain.po.WxOrder; | ||||
| import com.iformall.domain.po.WxOrderGroup; | import com.iformall.domain.po.WxOrderGroup; | ||||
| import java.util.List; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| /** | /** | ||||
| @@ -25,4 +26,8 @@ public interface WxOrderGroupService { | |||||
| ResultData queryAttendStatus(WxOrderGroup wxOrderGroup); | ResultData queryAttendStatus(WxOrderGroup wxOrderGroup); | ||||
| void updateGroupStatus(WxOrderGroup wxOrderGroup); | |||||
| List<WxOrderGroup> findList(WxOrderGroup group); | |||||
| } | } | ||||
| @@ -239,6 +239,8 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService { | |||||
| return new ResultData(result); | return new ResultData(result); | ||||
| } | } | ||||
| @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) | |||||
| @Override | |||||
| public void updateGroupStatus(WxOrderGroup wxOrderGroup) { | public void updateGroupStatus(WxOrderGroup wxOrderGroup) { | ||||
| Long id = wxOrderGroup.getId(); | Long id = wxOrderGroup.getId(); | ||||
| WxOrderGroup group = wxOrderGroupMapper.selectByPrimaryKey(id); | WxOrderGroup group = wxOrderGroupMapper.selectByPrimaryKey(id); | ||||
| @@ -258,6 +260,11 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService { | |||||
| } | } | ||||
| } | } | ||||
| @Override | |||||
| public List<WxOrderGroup> findList(WxOrderGroup group) { | |||||
| return wxOrderGroupMapper.select(group); | |||||
| } | |||||
| public void returnMoney(WxOrderGroup group) { | public void returnMoney(WxOrderGroup group) { | ||||
| //券失效或拼团超时 修改 拼团的状态 | //券失效或拼团超时 修改 拼团的状态 | ||||
| wxOrderGroupMapper.updateByPrimaryKeySelective(group); | wxOrderGroupMapper.updateByPrimaryKeySelective(group); | ||||
| @@ -277,9 +284,12 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService { | |||||
| wxOrder.setOrderGroupId(group.getId()); | wxOrder.setOrderGroupId(group.getId()); | ||||
| List<WxOrder> list = wxOrderMapper.findList(wxOrder); | List<WxOrder> list = wxOrderMapper.findList(wxOrder); | ||||
| for (WxOrder temp : list) { | for (WxOrder temp : list) { | ||||
| if (!temp.getOrderStatus().equals(EnumOrderStatus.ORDER_STATUS_REFUND_SUCCESS.getCode())) { | |||||
| if (temp.getOrderStatus().equals(EnumOrderStatus.ORDER_STATUS_COOPERATING_OVERTIME.getCode()) | |||||
| || temp.getOrderStatus().equals(EnumOrderStatus.ORDER_STATUS_COOPERATING_CANCEL.getCode())) { | |||||
| ResultData resultData = WxRefundOrderService.returnMoney(appinfo, temp.getId()); | ResultData resultData = WxRefundOrderService.returnMoney(appinfo, temp.getId()); | ||||
| logger.info("拼团不成功时的退款返回信息:" + resultData + "resultData.code == ResultData.SUCCESS" + (resultData.code == ResultData.SUCCESS)); | |||||
| if (resultData.code == ResultData.SUCCESS) { | if (resultData.code == ResultData.SUCCESS) { | ||||
| logger.info("修改订单的状态为已退款"); | |||||
| temp.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PENDING_REFUND.getCode()); | temp.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PENDING_REFUND.getCode()); | ||||
| wxOrderMapper.updateByPrimaryKeySelective(order); | wxOrderMapper.updateByPrimaryKeySelective(order); | ||||
| } | } | ||||