订单关联商品服务数量随子单状态修改而修改
This commit is contained in:
parent
7659b3de48
commit
1910bf35b7
|
|
@ -59,6 +59,11 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.temporal.TemporalAdjusters;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
@ -511,33 +516,18 @@ public class OrderController extends BaseController {
|
||||||
List<OrderListResponse> overTimeList = (List)overTimeRes.get("data");
|
List<OrderListResponse> overTimeList = (List)overTimeRes.get("data");
|
||||||
response.setOverTimeOrderNum(overTimeList.size());
|
response.setOverTimeOrderNum(overTimeList.size());
|
||||||
// 统计今日单量
|
// 统计今日单量
|
||||||
Calendar today = Calendar.getInstance();
|
LocalDateTime today = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
|
||||||
today.set(Calendar.SECOND, 0);
|
|
||||||
today.set(Calendar.MINUTE, 0);
|
|
||||||
today.set(Calendar.HOUR_OF_DAY, 0);
|
|
||||||
today.set(Calendar.MILLISECOND, 0);
|
|
||||||
orderDetail.setOrderStatus(OrderStatus.GOING.code());
|
orderDetail.setOrderStatus(OrderStatus.GOING.code());
|
||||||
orderDetail.setExpectTimeStart(today.getTime());
|
orderDetail.setExpectTimeStart(Date.from(today.atZone(ZoneId.systemDefault()).toInstant()));
|
||||||
today.set(Calendar.SECOND, 23);
|
today = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
|
||||||
today.set(Calendar.MINUTE, 59);
|
orderDetail.setExpectTimeEnd(Date.from(today.atZone(ZoneId.systemDefault()).toInstant()));
|
||||||
today.set(Calendar.HOUR_OF_DAY, 59);
|
|
||||||
today.set(Calendar.MILLISECOND, 0);
|
|
||||||
orderDetail.setExpectTimeEnd(today.getTime());
|
|
||||||
response.setTodayOrderNum(orderDetailService.countOrderDetailList(orderDetail));
|
response.setTodayOrderNum(orderDetailService.countOrderDetailList(orderDetail));
|
||||||
// 统计明日单量
|
// 统计明日单量
|
||||||
Calendar tomorrow = Calendar.getInstance();
|
LocalDateTime tomorrow = LocalDateTime.of(LocalDate.now().plusDays(1), LocalTime.MIN);
|
||||||
tomorrow.add(Calendar.DATE, 1);
|
|
||||||
tomorrow.set(Calendar.SECOND, 0);
|
|
||||||
tomorrow.set(Calendar.MINUTE, 0);
|
|
||||||
tomorrow.set(Calendar.HOUR_OF_DAY, 0);
|
|
||||||
tomorrow.set(Calendar.MILLISECOND, 0);
|
|
||||||
orderDetail.setOrderStatus(OrderStatus.GOING.code());
|
orderDetail.setOrderStatus(OrderStatus.GOING.code());
|
||||||
orderDetail.setExpectTimeStart(today.getTime());
|
orderDetail.setExpectTimeStart(Date.from(tomorrow.atZone(ZoneId.systemDefault()).toInstant()));
|
||||||
tomorrow.set(Calendar.SECOND, 23);
|
tomorrow = LocalDateTime.of(LocalDate.now().plusDays(1), LocalTime.MAX);
|
||||||
tomorrow.set(Calendar.MINUTE, 59);
|
orderDetail.setExpectTimeEnd(Date.from(tomorrow.atZone(ZoneId.systemDefault()).toInstant()));
|
||||||
tomorrow.set(Calendar.HOUR_OF_DAY, 59);
|
|
||||||
tomorrow.set(Calendar.MILLISECOND, 0);
|
|
||||||
orderDetail.setExpectTimeEnd(today.getTime());
|
|
||||||
response.setTomorrowOrderNum(orderDetailService.countOrderDetailList(orderDetail));
|
response.setTomorrowOrderNum(orderDetailService.countOrderDetailList(orderDetail));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,12 @@ import com.ghy.common.utils.AdapayUtils;
|
||||||
import com.ghy.common.utils.ObjectUtils;
|
import com.ghy.common.utils.ObjectUtils;
|
||||||
import com.ghy.common.utils.StringUtils;
|
import com.ghy.common.utils.StringUtils;
|
||||||
import com.ghy.order.domain.OrderDetail;
|
import com.ghy.order.domain.OrderDetail;
|
||||||
|
import com.ghy.order.domain.OrderGoods;
|
||||||
import com.ghy.order.domain.OrderMaster;
|
import com.ghy.order.domain.OrderMaster;
|
||||||
import com.ghy.order.mapper.OrderDetailMapper;
|
import com.ghy.order.mapper.OrderDetailMapper;
|
||||||
import com.ghy.order.mapper.OrderMasterMapper;
|
import com.ghy.order.mapper.OrderMasterMapper;
|
||||||
import com.ghy.order.service.OrderDetailService;
|
import com.ghy.order.service.OrderDetailService;
|
||||||
|
import com.ghy.order.service.OrderGoodsService;
|
||||||
import com.ghy.order.service.OrderMasterService;
|
import com.ghy.order.service.OrderMasterService;
|
||||||
import com.ghy.payment.domain.FinancialChangeRecord;
|
import com.ghy.payment.domain.FinancialChangeRecord;
|
||||||
import com.ghy.payment.domain.FinancialDetail;
|
import com.ghy.payment.domain.FinancialDetail;
|
||||||
|
|
@ -47,6 +49,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static java.time.temporal.ChronoField.*;
|
import static java.time.temporal.ChronoField.*;
|
||||||
|
|
||||||
|
|
@ -78,6 +81,8 @@ public class OrderDetailServiceImpl implements OrderDetailService {
|
||||||
private FinancialDetailService financialDetailService;
|
private FinancialDetailService financialDetailService;
|
||||||
@Resource
|
@Resource
|
||||||
private FinancialChangeRecordService financialChangeRecordService;
|
private FinancialChangeRecordService financialChangeRecordService;
|
||||||
|
@Resource
|
||||||
|
private OrderGoodsService orderGoodsService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int insertOrderDetail(OrderDetail orderDetail) {
|
public int insertOrderDetail(OrderDetail orderDetail) {
|
||||||
|
|
@ -85,14 +90,44 @@ public class OrderDetailServiceImpl implements OrderDetailService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public int updateOrderDetail(OrderDetail orderDetail) {
|
public int updateOrderDetail(OrderDetail orderDetail) {
|
||||||
if (orderDetail.getOrderStatus() == null) {
|
if (orderDetail.getOrderStatus() == null) {
|
||||||
return orderDetailMapper.updateOrderDetail(orderDetail);
|
return orderDetailMapper.updateOrderDetail(orderDetail);
|
||||||
}
|
}
|
||||||
int orderStatus = orderDetail.getOrderStatus();
|
int orderStatus = orderDetail.getOrderStatus();
|
||||||
boolean flag = Boolean.TRUE;
|
boolean flag = Boolean.TRUE;
|
||||||
int result = orderDetailMapper.updateOrderDetail(orderDetail);
|
|
||||||
// 查子单信息
|
// 查子单信息
|
||||||
|
OrderDetail originOrderDetail = this.orderDetailMapper.selectById(orderDetail.getId());
|
||||||
|
int result = orderDetailMapper.updateOrderDetail(orderDetail);
|
||||||
|
// 查询主单关联商品
|
||||||
|
List<OrderGoods> masterOrderGoodsList = orderGoodsService.selectByOrderMasterId(originOrderDetail.getOrderMasterId());
|
||||||
|
Map<Long, OrderGoods> masterGoodsMap = masterOrderGoodsList.stream().collect(Collectors.toMap(OrderGoods::getGoodsStandardId, obj -> obj));
|
||||||
|
// 子单修改从服务中到确认中需要修改已服务商品数量,从确认中到服务中需要重置已服务商品数量
|
||||||
|
if (OrderStatus.FINISH_CHECK.code() == orderDetail.getOrderStatus() && originOrderDetail.getOrderStatus() < OrderStatus.FINISH_CHECK.code()) {
|
||||||
|
List<OrderGoods> orderGoodsList = orderGoodsService.selectByOrderDetailId(orderDetail.getId());
|
||||||
|
orderGoodsList.stream().forEach(orderGoods -> {
|
||||||
|
orderGoods.setServerGoodsNum(orderGoods.getGoodsNum());
|
||||||
|
orderGoodsService.updateOrderGoods(orderGoods);
|
||||||
|
// 主单关联商品相应修改已服务数量
|
||||||
|
Integer masterServerGoodsNum = masterGoodsMap.get(orderGoods.getGoodsStandardId()).getServerGoodsNum();
|
||||||
|
masterGoodsMap.get(orderGoods.getGoodsStandardId()).setServerGoodsNum(masterServerGoodsNum += orderGoods.getServerGoodsNum());
|
||||||
|
});
|
||||||
|
} else if (OrderStatus.FINISH_CHECK.code() == originOrderDetail.getOrderStatus() && orderDetail.getOrderStatus() < OrderStatus.FINISH_CHECK.code()){
|
||||||
|
List<OrderGoods> orderGoodsList = orderGoodsService.selectByOrderDetailId(orderDetail.getId());
|
||||||
|
orderGoodsList.stream().forEach(orderGoods -> {
|
||||||
|
orderGoods.setServerGoodsNum(0);
|
||||||
|
orderGoodsService.updateOrderGoods(orderGoods);
|
||||||
|
// 主单关联商品相应修改已服务数量
|
||||||
|
Integer masterServerGoodsNum = masterGoodsMap.get(orderGoods.getGoodsStandardId()).getServerGoodsNum();
|
||||||
|
masterGoodsMap.get(orderGoods.getGoodsStandardId()).setServerGoodsNum(masterServerGoodsNum -= orderGoods.getGoodsNum());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// 更新主单关联商品
|
||||||
|
masterOrderGoodsList.stream().forEach(masterOrderGoods ->{
|
||||||
|
orderGoodsService.updateOrderGoods(masterOrderGoods);
|
||||||
|
});
|
||||||
|
|
||||||
OrderDetail detailInfo = this.orderDetailMapper.selectById(orderDetail.getId());
|
OrderDetail detailInfo = this.orderDetailMapper.selectById(orderDetail.getId());
|
||||||
// 判断是否需要更新主单状态.即是否有
|
// 判断是否需要更新主单状态.即是否有
|
||||||
// 1.更新大于当前 detail 1/2/3
|
// 1.更新大于当前 detail 1/2/3
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue