|
@@ -0,0 +1,152 @@
|
|
|
+package com.fjhx.victoriatourist.service.order.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.area.service.AreaInfoService;
|
|
|
+import com.fjhx.area.utils.AreaUtil;
|
|
|
+import com.fjhx.customer.entity.customer.po.Customer;
|
|
|
+import com.fjhx.customer.service.customer.CustomerService;
|
|
|
+import com.fjhx.item.service.product.ProductInfoService;
|
|
|
+import com.fjhx.victoriatourist.entity.order.dto.OrderInfoDto;
|
|
|
+import com.fjhx.victoriatourist.entity.order.dto.OrderInfoSelectDto;
|
|
|
+import com.fjhx.victoriatourist.entity.order.po.OrderDetails;
|
|
|
+import com.fjhx.victoriatourist.entity.order.po.OrderInfo;
|
|
|
+import com.fjhx.victoriatourist.entity.order.vo.OrderDetailsVo;
|
|
|
+import com.fjhx.victoriatourist.entity.order.vo.OrderInfoVo;
|
|
|
+import com.fjhx.victoriatourist.mapper.order.OrderInfoMapper;
|
|
|
+import com.fjhx.victoriatourist.service.order.OrderDetailsService;
|
|
|
+import com.fjhx.victoriatourist.service.order.OrderInfoService;
|
|
|
+import com.fjhx.victoriatourist.utils.Assert;
|
|
|
+import com.fjhx.victoriatourist.utils.CodeEnum;
|
|
|
+import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 订单 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2023-04-17
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo> implements OrderInfoService {
|
|
|
+ @Autowired
|
|
|
+ CustomerService customerService;
|
|
|
+ @Autowired
|
|
|
+ AreaInfoService areaInfoService;
|
|
|
+ @Autowired
|
|
|
+ OrderDetailsService orderDetailsService;
|
|
|
+ @Autowired
|
|
|
+ ProductInfoService productInfoService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<OrderInfoVo> getPage(OrderInfoSelectDto dto) {
|
|
|
+ IWrapper<OrderInfo> wrapper = getWrapper();
|
|
|
+ wrapper.like(OrderInfo::getCode, dto.getKeyword());
|
|
|
+ if (ObjectUtil.isEmpty(dto.getType())) {
|
|
|
+ //默认销售订单
|
|
|
+ wrapper.in("oi", OrderInfo::getType, 1, 2);
|
|
|
+ } else {
|
|
|
+ wrapper.eq("oi", OrderInfo::getType, dto.getType());
|
|
|
+ }
|
|
|
+ wrapper.eq("oi", OrderInfo::getStatus, dto.getStatus());//根据状态过滤
|
|
|
+ wrapper.orderByDesc("oi", OrderInfo::getId);
|
|
|
+ Page<OrderInfoVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
+ List<OrderInfoVo> records = page.getRecords();
|
|
|
+ if (ObjectUtil.isEmpty(records)) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+ //赋值客户名称
|
|
|
+ customerService.attributeAssign(records, OrderInfoVo::getCustomerInfoId, (item, customerInfo) -> {
|
|
|
+ item.setCustomerName(customerInfo.getName());
|
|
|
+ });
|
|
|
+ //赋值赋值国省市
|
|
|
+ AreaUtil.setAreaName(records);
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public OrderInfoVo detail(Long id) {
|
|
|
+ OrderInfo OrderInfo = this.getById(id);
|
|
|
+ OrderInfoVo result = BeanUtil.toBean(OrderInfo, OrderInfoVo.class);
|
|
|
+ //赋值客户名称
|
|
|
+ Customer customer = customerService.getById(result.getCustomerInfoId());
|
|
|
+ if (ObjectUtil.isNotEmpty(customer)) {
|
|
|
+ result.setCustomerName(customer.getName());
|
|
|
+ }
|
|
|
+ //赋值赋值国省市
|
|
|
+ AreaUtil.setAreaName(result);
|
|
|
+ //赋值明细
|
|
|
+ List<OrderDetails> list = orderDetailsService.list(q -> q.eq(OrderDetails::getOrderId, result.getId()));
|
|
|
+ List<OrderDetailsVo> orderDetailsVoList = BeanUtil.copyToList(list, OrderDetailsVo.class);
|
|
|
+ //给明细赋值产品信息
|
|
|
+ productInfoService.attributeAssign(orderDetailsVoList, OrderDetails::getProductId, (item, productInfo) -> {
|
|
|
+ item.setProductCode(productInfo.getCode());
|
|
|
+ item.setProductName(productInfo.getName());
|
|
|
+ item.setProductUnit(productInfo.getUnit());
|
|
|
+ });
|
|
|
+ result.setOrderDetailsList(orderDetailsVoList);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void add(OrderInfoDto orderInfoDto) {
|
|
|
+ // 订单明细
|
|
|
+ List<OrderDetails> orderDetailsList = orderInfoDto.getOrderDetailsList();
|
|
|
+ Assert.notEmpty(orderDetailsList, "订单明细不能为空");
|
|
|
+
|
|
|
+// Integer type = orderInfoDto.getType();
|
|
|
+// if (type == 3) {
|
|
|
+// // 获取京东客户id
|
|
|
+// Long jdCustomerId = systemConfigService.getValue(SystemConfigKeyConstant.JD_CUSTOMER_ID, Long.class);
|
|
|
+// orderInfoDto.setCustomerInfoId(jdCustomerId);
|
|
|
+// }
|
|
|
+
|
|
|
+ // 订单时间
|
|
|
+ orderInfoDto.setOrderTime(ObjectUtil.defaultIfNull(orderInfoDto.getOrderTime(), new Date()));
|
|
|
+
|
|
|
+ // 统计订单金额
|
|
|
+ BigDecimal amountMoney = orderDetailsList.stream()
|
|
|
+ .map(item -> item.getPrice().multiply(item.getQuantity())).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ orderInfoDto.setAmountMoney(amountMoney);
|
|
|
+
|
|
|
+ orderInfoDto.setStatus(1);
|
|
|
+ orderInfoDto.setIssueStatus(1);
|
|
|
+
|
|
|
+ synchronized (this) {
|
|
|
+// if (type == 3) {
|
|
|
+// orderInfoDto.setCode(CodeEnum.ORDER_JD.getCode(orderInfoDto.getCode()));
|
|
|
+// } else {
|
|
|
+ orderInfoDto.setCode(CodeEnum.ORDER_SALES.getCode(orderInfoDto.getCode()));
|
|
|
+// }
|
|
|
+ this.save(orderInfoDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加订单明细
|
|
|
+ for (OrderDetails orderDetails : orderDetailsList) {
|
|
|
+ orderDetails.setOrderId(orderInfoDto.getId());
|
|
|
+ orderDetails.setNotIssuedQuantity(orderDetails.getQuantity());
|
|
|
+ }
|
|
|
+ orderDetailsService.saveBatch(orderDetailsList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void edit(OrderInfoDto orderInfoDto) {
|
|
|
+ this.updateById(orderInfoDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delete(Long id) {
|
|
|
+ this.removeById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|