|
@@ -2,16 +2,16 @@ package com.hcloud.microserver.system.bank.service.impl;
|
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
-import com.hcloud.microserver.system.bank.bo.OrderInfoBO;
|
|
|
-import com.hcloud.microserver.system.bank.dao.GoodsOrderInfoMapper;
|
|
|
+import com.hcloud.microserver.security.util.SecurityUtils;
|
|
|
+import com.hcloud.microserver.system.bank.bo.*;
|
|
|
+import com.hcloud.microserver.system.bank.dao.*;
|
|
|
import com.hcloud.microserver.system.bank.events.CredentialInfoEvent;
|
|
|
import com.hcloud.microserver.commoncore.base.PageBean;
|
|
|
import com.hcloud.microserver.commoncore.util.BeanCopyUtil;
|
|
|
import com.hcloud.microserver.commoncore.util.GeneratorIdUtils;
|
|
|
import com.hcloud.microserver.commoncore.util.GetUUID;
|
|
|
import com.hcloud.microserver.system.bank.service.*;
|
|
|
-import com.hcloud.microserver.system.facade.carbon.entity.GoodsInfo;
|
|
|
-import com.hcloud.microserver.system.facade.carbon.entity.GoodsOrderInfo;
|
|
|
+import com.hcloud.microserver.system.facade.carbon.entity.*;
|
|
|
import com.hcloud.microserver.system.facade.carbon.forms.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -20,10 +20,9 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.security.auth.Subject;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @author xiezt
|
|
@@ -35,35 +34,27 @@ public class OrderInfoServiceImpl implements OrderInfoService {
|
|
|
|
|
|
@Resource
|
|
|
private GoodsOrderInfoMapper goodsOrderInfoMapper;
|
|
|
-
|
|
|
@Autowired
|
|
|
private OrderDetailInfoService orderDetailInfoService;
|
|
|
-
|
|
|
+ @Resource
|
|
|
+ private GoodsOrderDetailMapper goodsOrderDetailMapper;
|
|
|
+ @Resource
|
|
|
+ private GoodsSaleInfoMapper goodsSaleInfoMapper;
|
|
|
@Autowired
|
|
|
private OrderPayApplyService orderPayApplyService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private OrderPayService orderPayService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private CustomerInfoService customerInfoService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private ApplicationContext applicationContext;
|
|
|
-
|
|
|
@Autowired
|
|
|
private OrderSaleInfoService orderSaleInfoService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private FarmerInfoService farmerInfoService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CollectiveFarmerService collectiveFarmerService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private GoodsInfoService goodsInfoService;
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 分页查询订单信息
|
|
|
*
|
|
@@ -369,6 +360,141 @@ public class OrderInfoServiceImpl implements OrderInfoService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 后台生成订单
|
|
|
+ *
|
|
|
+ * @param createOrderBO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public int createOrder(CreateOrderBO createOrderBO) {
|
|
|
+ //查询商品信息
|
|
|
+ Map<String,String> queryParam = new HashMap<String,String>();
|
|
|
+ queryParam.put("productTypeId",createOrderBO.getProductTypeGuid());
|
|
|
+ queryParam.put("villageId",createOrderBO.getVillageId());
|
|
|
+ List<QueryGoodsInfoBO> goodsList = goodsInfoService.queryGoodsInfoByProductTypeAndArea(queryParam);
|
|
|
+ if(goodsList.size()==0){
|
|
|
+ throw new RuntimeException("没有满足要求的商品");
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询客户信息
|
|
|
+ CustomerInfoForm customer = customerInfoService.getCustomerInfoById(createOrderBO.getApplyCostomerId());
|
|
|
+ //保存主订单
|
|
|
+ GoodsOrderInfo order = new GoodsOrderInfo();
|
|
|
+ order.setCustomerName(customer.getCustomerName());
|
|
|
+ order.setFkCustomerGuid(customer.getGuid());
|
|
|
+ order.setCustomerType(customer.getCustomerType().toString());
|
|
|
+
|
|
|
+ order.setOrderCarbonAmount(createOrderBO.getOrderCarbonAmount());
|
|
|
+ order.setOrderStatus(1);
|
|
|
+ order.setCreateUser(SecurityUtils.getUserId()==null?"1":SecurityUtils.getUserId().toString());
|
|
|
+ order.setOrderType(createOrderBO.getOrderType());
|
|
|
+
|
|
|
+ GeneratorIdUtils generatorIdUtils = new GeneratorIdUtils();
|
|
|
+ String orderNum = generatorIdUtils.nextId();
|
|
|
+ order.setOrderNo(orderNum);
|
|
|
+
|
|
|
+ order.setGuid(GetUUID.getUUID());
|
|
|
+ order.setState(1);
|
|
|
+ order.setCreateTime(new Date());
|
|
|
+ order.setModifiedTime(new Date());
|
|
|
+
|
|
|
+
|
|
|
+ //保存订单详情
|
|
|
+ BigDecimal difference = createOrderBO.getOrderCarbonAmount();
|
|
|
+ BigDecimal totalAmount = new BigDecimal(0);
|
|
|
+ for (QueryGoodsInfoBO goods:goodsList) {
|
|
|
+ GoodsSaleInfo saleInfo = goodsSaleInfoMapper.getGoodsSaleInfoByGoodsId(goods.getGoodsId());
|
|
|
+ GoodsOrderDetail orderDetail = new GoodsOrderDetail();
|
|
|
+ orderDetail.setGuid(GetUUID.getUUID());
|
|
|
+ orderDetail.setFkOrderGuid(order.getGuid());
|
|
|
+ orderDetail.setFkGoodsGuid(goods.getGoodsId());
|
|
|
+ orderDetail.setGoodsName(goods.getGoodsName());
|
|
|
+ BigDecimal salePrice = saleInfo.getSalePrice();
|
|
|
+ orderDetail.setGoodsPrice(salePrice);
|
|
|
+ orderDetail.setState(1);
|
|
|
+ orderDetail.setCreateUser(SecurityUtils.getUserId()==null?"1":SecurityUtils.getUserId().toString());
|
|
|
+ orderDetail.setCreateTime(new Date());
|
|
|
+
|
|
|
+ BigDecimal carbonVal = saleInfo.getUnsaledCarbonSkin();
|
|
|
+ BigDecimal subtractResult = difference.subtract(carbonVal);
|
|
|
+ if(subtractResult.doubleValue()>=0){
|
|
|
+ difference = subtractResult;
|
|
|
+ orderDetail.setSaleNum(carbonVal);
|
|
|
+ BigDecimal amount = salePrice.multiply(carbonVal);
|
|
|
+ orderDetail.setAmount(amount);
|
|
|
+ totalAmount.add(amount);
|
|
|
+ goodsOrderDetailMapper.insertSelective(orderDetail);
|
|
|
+ //更新销售表
|
|
|
+ saleInfo.setUnsaledCarbonSkin(new BigDecimal(0));
|
|
|
+ BigDecimal saleCarbonSkin = saleInfo.getSaledCarbonSkin();
|
|
|
+ BigDecimal newSaleCarbonSkin = saleCarbonSkin.add(carbonVal);
|
|
|
+ saleInfo.setSaledCarbonSkin(newSaleCarbonSkin);
|
|
|
+ goodsSaleInfoMapper.updateByPrimaryKeySelective(saleInfo);
|
|
|
+
|
|
|
+ continue;
|
|
|
+ }else{
|
|
|
+ orderDetail.setSaleNum(difference);
|
|
|
+ BigDecimal amount = salePrice.multiply(difference);
|
|
|
+ orderDetail.setAmount(amount);
|
|
|
+ totalAmount.add(amount);
|
|
|
+ goodsOrderDetailMapper.insertSelective(orderDetail);
|
|
|
+
|
|
|
+ //更新销售表
|
|
|
+ BigDecimal unsaledCarbonSkin = saleInfo.getUnsaledCarbonSkin();
|
|
|
+ BigDecimal newUnsaledCarbonSkin = unsaledCarbonSkin.subtract(difference);
|
|
|
+ saleInfo.setUnsaledCarbonSkin(newUnsaledCarbonSkin);
|
|
|
+ BigDecimal saleCarbonSkin = saleInfo.getSaledCarbonSkin();
|
|
|
+ BigDecimal newSaleCarbonSkin = saleCarbonSkin.add(difference);
|
|
|
+ saleInfo.setSaledCarbonSkin(newSaleCarbonSkin);
|
|
|
+
|
|
|
+ goodsSaleInfoMapper.updateByPrimaryKeySelective(saleInfo);
|
|
|
+ difference = new BigDecimal(0);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(difference.intValue()>0){
|
|
|
+ throw new RuntimeException("满足的条件的商品的库存不足");
|
|
|
+ }
|
|
|
+
|
|
|
+ order.setOrderAmount(totalAmount);
|
|
|
+ //保存
|
|
|
+ int saveOrderResult = goodsOrderInfoMapper.insertSelective(order);
|
|
|
+
|
|
|
+ return saveOrderResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询线下订单
|
|
|
+ *
|
|
|
+ * @param condidtionForm
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public PageInfo offlineOrderList(OfflineOrderCondidtionForm condidtionForm) {
|
|
|
+ PageBean pageBean = new PageBean(condidtionForm);
|
|
|
+ PageHelper.startPage(condidtionForm.getPageNo(),condidtionForm.getPageSize());
|
|
|
+ List<OfflineOrderBO> list =goodsOrderInfoMapper.offlineOrderList(pageBean);
|
|
|
+ return new PageInfo(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据订单guid查询订单详情
|
|
|
+ *
|
|
|
+ * @param guid
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public OfflineOrderDetailBO queryOfflineOrderDetial(String guid) {
|
|
|
+ //获取主订单信息
|
|
|
+ OfflineOrderDetailBO order = goodsOrderInfoMapper.queryOfflineOrderDetial(guid);
|
|
|
+ //获取订单项
|
|
|
+ List<OfflineOrderItemBO> items = goodsOrderDetailMapper.queryOrderDetail(guid);
|
|
|
+ order.setItems(items);
|
|
|
+ return order;
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public int delByPrimaryKey(String guid) {
|