|
@@ -2,7 +2,14 @@ package com.hcloud.microserver.h5.service.impl;
|
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
+import com.hcloud.microserver.commoncore.base.ResultVO;
|
|
|
+import com.hcloud.microserver.commoncore.enums.ResultEnum;
|
|
|
+import com.hcloud.microserver.facade.carbon.entity.GoodsOrderDetail;
|
|
|
+import com.hcloud.microserver.facade.carbon.entity.from.CreateOrderDetailFrom;
|
|
|
+import com.hcloud.microserver.facade.carbon.entity.from.CreateOrderFrom;
|
|
|
import com.hcloud.microserver.h5.bo.OrderInfoBO;
|
|
|
+import com.hcloud.microserver.h5.dao.GoodsInfoMapper;
|
|
|
+import com.hcloud.microserver.h5.dao.GoodsOrderDetailMapper;
|
|
|
import com.hcloud.microserver.h5.dao.GoodsOrderInfoMapper;
|
|
|
import com.hcloud.microserver.h5.events.CredentialInfoEvent;
|
|
|
import com.hcloud.microserver.h5.service.*;
|
|
@@ -14,13 +21,17 @@ import com.hcloud.microserver.facade.carbon.entity.GoodsInfo;
|
|
|
import com.hcloud.microserver.facade.carbon.entity.GoodsOrderInfo;
|
|
|
import com.hcloud.microserver.facade.carbon.forms.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.redisson.api.RLock;
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
@@ -73,8 +84,8 @@ public class OrderInfoServiceImpl implements OrderInfoService {
|
|
|
@Override
|
|
|
public PageInfo searchOrderInfoByPage(GoodsOrderInfoForm goodsOrderInfoForm) {
|
|
|
PageBean pageBean = new PageBean(goodsOrderInfoForm);
|
|
|
- PageHelper.startPage(goodsOrderInfoForm.getPageNo(),goodsOrderInfoForm.getPageSize());
|
|
|
- List<OrderInfoBO> list =goodsOrderInfoMapper.searchOrderInfoByPage(pageBean);
|
|
|
+ PageHelper.startPage(goodsOrderInfoForm.getPageNo(), goodsOrderInfoForm.getPageSize());
|
|
|
+ List<OrderInfoBO> list = goodsOrderInfoMapper.searchOrderInfoByPage(pageBean);
|
|
|
return new PageInfo(list);
|
|
|
}
|
|
|
|
|
@@ -86,11 +97,11 @@ public class OrderInfoServiceImpl implements OrderInfoService {
|
|
|
*/
|
|
|
@Override
|
|
|
public PageInfo searchOrderInfoByCustomerId(GoodsOrderInfoForm goodsOrderInfoForm) {
|
|
|
- String customerId= goodsOrderInfoForm.getFkCustomerGuid();
|
|
|
+ String customerId = goodsOrderInfoForm.getFkCustomerGuid();
|
|
|
Integer orderStatus = goodsOrderInfoForm.getOrderStatus();
|
|
|
- log.info("page====================>{}",goodsOrderInfoForm.getPage());
|
|
|
- PageHelper.startPage(goodsOrderInfoForm.getPageNo(),goodsOrderInfoForm.getPageSize());
|
|
|
- List<OrderInfoBO> list = goodsOrderInfoMapper.searchOrderInfoByCustomerId(customerId,orderStatus);
|
|
|
+ log.info("page====================>{}", goodsOrderInfoForm.getPage());
|
|
|
+ PageHelper.startPage(goodsOrderInfoForm.getPageNo(), goodsOrderInfoForm.getPageSize());
|
|
|
+ List<OrderInfoBO> list = goodsOrderInfoMapper.searchOrderInfoByCustomerId(customerId, orderStatus);
|
|
|
return new PageInfo(list);
|
|
|
}
|
|
|
|
|
@@ -105,16 +116,16 @@ public class OrderInfoServiceImpl implements OrderInfoService {
|
|
|
GoodsOrderInfoForm goodsOrderInfoForm = new GoodsOrderInfoForm();
|
|
|
//查询订单信息
|
|
|
GoodsOrderInfo goodsOrderInfo = goodsOrderInfoMapper.selectByPrimaryKey(orderId);
|
|
|
- if(null!=goodsOrderInfo && !"".equals(goodsOrderInfo.getOrderNo())){
|
|
|
- BeanCopyUtil.copyBean(goodsOrderInfo,goodsOrderInfoForm);
|
|
|
+ if (null != goodsOrderInfo && !"".equals(goodsOrderInfo.getOrderNo())) {
|
|
|
+ BeanCopyUtil.copyBean(goodsOrderInfo, goodsOrderInfoForm);
|
|
|
}
|
|
|
//查询订单明细信息
|
|
|
List<GoodsOrderDetailForm> list = orderDetailInfoService.getOrderDetailListByOrderId(orderId);
|
|
|
goodsOrderInfoForm.setGoodsOrderDetailForm(list);
|
|
|
//查询支付流水信息
|
|
|
String payNo = goodsOrderInfoForm.getPayNo();
|
|
|
- if(null!=payNo && !"".equals(payNo)){
|
|
|
- GoodsPayOrderForm goodsPayOrderForm = orderPayService.getPayOrderByNo(payNo);
|
|
|
+ if (null != payNo && !"".equals(payNo)) {
|
|
|
+ GoodsPayOrderForm goodsPayOrderForm = orderPayService.getPayOrderByNo(payNo);
|
|
|
goodsOrderInfoForm.setPayOrderInfo(goodsPayOrderForm);
|
|
|
}
|
|
|
//客户信息
|
|
@@ -138,13 +149,15 @@ public class OrderInfoServiceImpl implements OrderInfoService {
|
|
|
goodsOrderInfo.setState(0);
|
|
|
goodsOrderInfo.setModifiedTime(new Date());
|
|
|
int i = goodsOrderInfoMapper.updateByPrimaryKeySelective(goodsOrderInfo);
|
|
|
- if(i>0){
|
|
|
+ if (i > 0) {
|
|
|
//更新离线支付申请
|
|
|
- OrderPayApplyForm orderPayApplyForm = orderPayApplyService.getPayApplyInfoByOrderId(orderId);
|
|
|
- if(Objects.nonNull(orderPayApplyForm)){
|
|
|
- int j = orderPayApplyService.modifyByPrimaryKeySelective(orderPayApplyForm);
|
|
|
- if(j==0){throw new RuntimeException();}
|
|
|
- }
|
|
|
+ OrderPayApplyForm orderPayApplyForm = orderPayApplyService.getPayApplyInfoByOrderId(orderId);
|
|
|
+ if (Objects.nonNull(orderPayApplyForm)) {
|
|
|
+ int j = orderPayApplyService.modifyByPrimaryKeySelective(orderPayApplyForm);
|
|
|
+ if (j == 0) {
|
|
|
+ throw new RuntimeException();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
return i;
|
|
@@ -156,58 +169,98 @@ public class OrderInfoServiceImpl implements OrderInfoService {
|
|
|
* @param goodsOrderInfoForm
|
|
|
* @return
|
|
|
*/
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedissonClient redissonClient;
|
|
|
+
|
|
|
+
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public String saveFullOrderInfo(GoodsOrderInfoForm goodsOrderInfoForm) {
|
|
|
- //生成订单信息
|
|
|
+ //生成订单信息插入数据库
|
|
|
int i = this.saveSelective(goodsOrderInfoForm);
|
|
|
- if(i>0){
|
|
|
- //生成订单明细
|
|
|
- List<GoodsOrderDetailForm> list = goodsOrderInfoForm.getGoodsOrderDetailForm();
|
|
|
- if(null!=list && list.size()>0){
|
|
|
- for (GoodsOrderDetailForm bean:list) {
|
|
|
- bean.setFkOrderGuid(goodsOrderInfoForm.getGuid());
|
|
|
- bean.setState(1);
|
|
|
- bean.setModifiedTime(new Date());
|
|
|
- bean.setCreateTime(new Date());
|
|
|
- }
|
|
|
- int j = orderDetailInfoService.batchSaveOrderDetailByList(list);
|
|
|
- if (j==0){throw new RuntimeException();}
|
|
|
- }else {
|
|
|
- throw new RuntimeException("order detail list is empty!!!!!");
|
|
|
- }
|
|
|
- //更新商品销售表
|
|
|
- if(null!=list && list.size()>0){
|
|
|
- for (GoodsOrderDetailForm bean:list) {
|
|
|
- BigDecimal saleCarbon = bean.getSaleNum();
|
|
|
- String goodsGuid = bean.getFkGoodsGuid();
|
|
|
- GoodsSaleInfoForm goodsSaleInfoForm = orderSaleInfoService.getGoodsSaleInfoByGoodsId(goodsGuid);
|
|
|
- if(Objects.isNull(goodsSaleInfoForm)){throw new RuntimeException("order sale info is null!!!!!!!");}
|
|
|
- BigDecimal saledCarbonSkin = goodsSaleInfoForm.getSaledCarbonSkin().add(saleCarbon);
|
|
|
- BigDecimal unSaleCarbonSkin = goodsSaleInfoForm.getUnsaledCarbonSkin().subtract(saleCarbon);
|
|
|
- //判断一下商品可售卖的碳汇量是否已经为0,如果为0应该把该商品进行下线操作
|
|
|
- if(unSaleCarbonSkin.intValue()==0){
|
|
|
- GoodsInfo goodsInfo = new GoodsInfo();
|
|
|
- goodsInfo.setGuid(goodsGuid);
|
|
|
- goodsInfo.setModifiedTime(new Date());
|
|
|
- goodsInfo.setIsSale(0);
|
|
|
- int k = goodsInfoService.modifyByPrimaryKeySelective(goodsInfo);
|
|
|
- if(k==0){throw new RuntimeException();}
|
|
|
- }
|
|
|
- goodsSaleInfoForm.setSaledCarbonSkin(saledCarbonSkin);
|
|
|
- goodsSaleInfoForm.setUnsaledCarbonSkin(unSaleCarbonSkin);
|
|
|
- goodsSaleInfoForm.setModifiedTime(new Date());
|
|
|
- int h =orderSaleInfoService.modifyByPrimaryKeySelective(goodsSaleInfoForm);
|
|
|
- if(h==0){
|
|
|
- throw new RuntimeException();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ if (i > 0) {
|
|
|
+ //批量生成订单明细插入数据库
|
|
|
+ List<GoodsOrderDetailForm> list = goodsOrderInfoForm.getGoodsOrderDetailForm();
|
|
|
+ boolean b = null != list && list.size() > 0;
|
|
|
+ //批量生成订单明细插入数据库
|
|
|
+ insertListData(goodsOrderInfoForm, list, b);
|
|
|
+ //批量更新商品销售表
|
|
|
+ updateListData(list, b);
|
|
|
return goodsOrderInfoForm.getGuid();
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ private void updateListData(List<GoodsOrderDetailForm> list, boolean b) {
|
|
|
+ if (b) {
|
|
|
+ for (GoodsOrderDetailForm bean : list) {
|
|
|
+ BigDecimal saleCarbon = bean.getSaleNum();
|
|
|
+ String goodsGuid = bean.getFkGoodsGuid();
|
|
|
+ String key = "dec_store_lock_" + goodsGuid;
|
|
|
+ RLock lock = redissonClient.getLock(key);
|
|
|
+ boolean locked = lock.isLocked();
|
|
|
+ try {
|
|
|
+ //加锁 操作很类似Java的ReentrantLock机制
|
|
|
+ lock.lock();
|
|
|
+ updateGoods(saleCarbon, goodsGuid);
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println(e.getMessage());
|
|
|
+ throw new RuntimeException("请重新抢购");
|
|
|
+ } finally {
|
|
|
+ //解锁
|
|
|
+ lock.unlock();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void insertListData(GoodsOrderInfoForm goodsOrderInfoForm, List<GoodsOrderDetailForm> list, boolean b) {
|
|
|
+ if (b) {
|
|
|
+ for (GoodsOrderDetailForm bean : list) {
|
|
|
+ bean.setFkOrderGuid(goodsOrderInfoForm.getGuid());
|
|
|
+ bean.setState(1);
|
|
|
+ bean.setModifiedTime(new Date());
|
|
|
+ bean.setCreateTime(new Date());
|
|
|
+ }
|
|
|
+ int j = orderDetailInfoService.batchSaveOrderDetailByList(list);
|
|
|
+ if (j == 0) {
|
|
|
+ throw new RuntimeException();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("order detail list is empty!!!!!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateGoods(BigDecimal saleCarbon, String goodsGuid) {
|
|
|
+ GoodsSaleInfoForm goodsSaleInfoForm = orderSaleInfoService.getGoodsSaleInfoByGoodsId(goodsGuid);
|
|
|
+ if (Objects.isNull(goodsSaleInfoForm)) {
|
|
|
+ throw new RuntimeException("order sale info is null!!!!!!!");
|
|
|
+ }
|
|
|
+ BigDecimal saledCarbonSkin = goodsSaleInfoForm.getSaledCarbonSkin().add(saleCarbon);
|
|
|
+ BigDecimal unSaleCarbonSkin = goodsSaleInfoForm.getUnsaledCarbonSkin().subtract(saleCarbon);
|
|
|
+ //判断一下商品可售卖的碳汇量是否已经为0,如果为0应该把该商品进行下线操作
|
|
|
+ if (unSaleCarbonSkin.intValue() == 0) {
|
|
|
+ GoodsInfo goodsInfo = new GoodsInfo();
|
|
|
+ goodsInfo.setGuid(goodsGuid);
|
|
|
+ goodsInfo.setModifiedTime(new Date());
|
|
|
+ goodsInfo.setIsSale(0);
|
|
|
+ int k = goodsInfoService.modifyByPrimaryKeySelective(goodsInfo);
|
|
|
+ if (k == 0) {
|
|
|
+ throw new RuntimeException();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ goodsSaleInfoForm.setSaledCarbonSkin(saledCarbonSkin);
|
|
|
+ goodsSaleInfoForm.setUnsaledCarbonSkin(unSaleCarbonSkin);
|
|
|
+ goodsSaleInfoForm.setModifiedTime(new Date());
|
|
|
+ int h = orderSaleInfoService.modifyByPrimaryKeySelective(goodsSaleInfoForm);
|
|
|
+ if (h == 0) {
|
|
|
+ throw new RuntimeException();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 支付成功后回调更新(订单信息,支付流水信息,证书信息,农户销售统计信息(集体户统计到集体户上))
|
|
|
*
|
|
@@ -216,49 +269,54 @@ public class OrderInfoServiceImpl implements OrderInfoService {
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public int updateFullOrderInfo(String payNo,Integer state) {
|
|
|
- if(null!=payNo && !"".equals(payNo)){
|
|
|
+ public int updateFullOrderInfo(String payNo, Integer state) {
|
|
|
+ if (null != payNo && !"".equals(payNo)) {
|
|
|
//查询支付订单
|
|
|
- GoodsPayOrderForm goodsPayOrderForm = orderPayService.getPayOrderByNo(payNo);
|
|
|
- if(goodsPayOrderForm!=null && !"".equals(goodsPayOrderForm.getFkOrderId())){
|
|
|
- //更新订单信息
|
|
|
- String orderId = goodsPayOrderForm.getFkOrderId();
|
|
|
- GoodsOrderInfo goodsOrderInfo = goodsOrderInfoMapper.selectByPrimaryKey(orderId);
|
|
|
- goodsOrderInfo.setOrderStatus(state);
|
|
|
- goodsOrderInfo.setModifiedTime(new Date());
|
|
|
- int i = goodsOrderInfoMapper.updateByPrimaryKeySelective(goodsOrderInfo);
|
|
|
- if(i>0){
|
|
|
- //更新支付订单信息
|
|
|
- goodsPayOrderForm.setPayStatus(state);
|
|
|
- goodsPayOrderForm.setPayTime(new Date());
|
|
|
- int j = orderPayService.modifyByPrimaryKeySelective(goodsPayOrderForm);
|
|
|
- if(j==0){throw new RuntimeException();}
|
|
|
- //更新农户收入信息
|
|
|
- updateFarmerSaleInfo(orderId);
|
|
|
- //生成证书信息
|
|
|
- applicationContext.publishEvent(new CredentialInfoEvent(new Object(),orderId));
|
|
|
- return i;
|
|
|
- }else{
|
|
|
- throw new RuntimeException();
|
|
|
- }
|
|
|
- }
|
|
|
+ GoodsPayOrderForm goodsPayOrderForm = orderPayService.getPayOrderByNo(payNo);
|
|
|
+ if (goodsPayOrderForm != null && !"".equals(goodsPayOrderForm.getFkOrderId())) {
|
|
|
+ //更新订单信息
|
|
|
+ String orderId = goodsPayOrderForm.getFkOrderId();
|
|
|
+ GoodsOrderInfo goodsOrderInfo = goodsOrderInfoMapper.selectByPrimaryKey(orderId);
|
|
|
+ goodsOrderInfo.setOrderStatus(state);
|
|
|
+ goodsOrderInfo.setModifiedTime(new Date());
|
|
|
+ int i = goodsOrderInfoMapper.updateByPrimaryKeySelective(goodsOrderInfo);
|
|
|
+ if (i > 0) {
|
|
|
+ //更新支付订单信息
|
|
|
+ goodsPayOrderForm.setPayStatus(state);
|
|
|
+ goodsPayOrderForm.setPayTime(new Date());
|
|
|
+ int j = orderPayService.modifyByPrimaryKeySelective(goodsPayOrderForm);
|
|
|
+ if (j == 0) {
|
|
|
+ throw new RuntimeException();
|
|
|
+ }
|
|
|
+ //更新农户收入信息
|
|
|
+ updateFarmerSaleInfo(orderId);
|
|
|
+ //生成证书信息
|
|
|
+ applicationContext.publishEvent(new CredentialInfoEvent(new Object(), orderId));
|
|
|
+ return i;
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 统计订单详情里商品关联的农户信息,在支付成功后更新农户销售信息
|
|
|
+ *
|
|
|
* @param orderId
|
|
|
* @throws RuntimeException
|
|
|
*/
|
|
|
- private void updateFarmerSaleInfo(String orderId) throws RuntimeException{
|
|
|
+ private void updateFarmerSaleInfo(String orderId) throws RuntimeException {
|
|
|
List<GoodsOrderDetailForm> detailList = orderDetailInfoService.getOrderDetailListByOrderId(orderId);
|
|
|
- if(null!=detailList && detailList.size()>0){
|
|
|
- for (GoodsOrderDetailForm bean:detailList) {
|
|
|
+ if (null != detailList && detailList.size() > 0) {
|
|
|
+ for (GoodsOrderDetailForm bean : detailList) {
|
|
|
String goodsGuid = bean.getFkGoodsGuid();
|
|
|
BigDecimal carbonAmount = bean.getAmount();
|
|
|
- int i =farmerInfoService.updateFarmerSaleInfoByGoodsId(carbonAmount,goodsGuid);
|
|
|
- if(i==0){throw new RuntimeException();}
|
|
|
+ int i = farmerInfoService.updateFarmerSaleInfoByGoodsId(carbonAmount, goodsGuid);
|
|
|
+ if (i == 0) {
|
|
|
+ throw new RuntimeException();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -266,22 +324,25 @@ public class OrderInfoServiceImpl implements OrderInfoService {
|
|
|
|
|
|
/**
|
|
|
* 支付失败或超过订单支付时间时,进行订单回滚操作
|
|
|
+ *
|
|
|
* @param orderId
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public int rollbackOrderInfo(String orderId){
|
|
|
+ public int rollbackOrderInfo(String orderId) {
|
|
|
GoodsOrderInfo goodsOrderInfo = goodsOrderInfoMapper.selectByPrimaryKey(orderId);
|
|
|
goodsOrderInfo.setOrderStatus(4);
|
|
|
goodsOrderInfo.setState(0);
|
|
|
goodsOrderInfo.setModifiedTime(new Date());
|
|
|
int i = goodsOrderInfoMapper.updateByPrimaryKeySelective(goodsOrderInfo);
|
|
|
- if(i==0){throw new RuntimeException();}
|
|
|
+ if (i == 0) {
|
|
|
+ throw new RuntimeException();
|
|
|
+ }
|
|
|
String guid = goodsOrderInfo.getGuid();
|
|
|
List<GoodsOrderDetailForm> orderDetailList = orderDetailInfoService.getOrderDetailListByOrderId(guid);
|
|
|
- if(null!=orderDetailList && orderDetailList.size()>0){
|
|
|
- for(GoodsOrderDetailForm bean:orderDetailList) {
|
|
|
+ if (null != orderDetailList && orderDetailList.size() > 0) {
|
|
|
+ for (GoodsOrderDetailForm bean : orderDetailList) {
|
|
|
BigDecimal saleCarbon = bean.getSaleNum();
|
|
|
String goodsGuid = bean.getFkGoodsGuid();
|
|
|
GoodsSaleInfoForm goodsSaleInfoForm = orderSaleInfoService.getGoodsSaleInfoByGoodsId(goodsGuid);
|
|
@@ -290,20 +351,22 @@ public class OrderInfoServiceImpl implements OrderInfoService {
|
|
|
goodsSaleInfoForm.setSaledCarbonSkin(saledCarbonSkin);
|
|
|
goodsSaleInfoForm.setUnsaledCarbonSkin(unSaleCarbonSkin);
|
|
|
goodsSaleInfoForm.setModifiedTime(new Date());
|
|
|
- int h =orderSaleInfoService.modifiedOrderSaleInfo(goodsSaleInfoForm);
|
|
|
- if(h==0){
|
|
|
+ int h = orderSaleInfoService.modifiedOrderSaleInfo(goodsSaleInfoForm);
|
|
|
+ if (h == 0) {
|
|
|
throw new RuntimeException();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//取消离线支付订单
|
|
|
OrderPayApplyForm payApplyForm = orderPayApplyService.getPayApplyInfoByOrderId(orderId);
|
|
|
- if(Objects.nonNull(payApplyForm)){
|
|
|
+ if (Objects.nonNull(payApplyForm)) {
|
|
|
payApplyForm.setState(0);
|
|
|
payApplyForm.setApplyStatus(4);
|
|
|
payApplyForm.setModifiedTime(new Date());
|
|
|
- int h = orderPayApplyService.modifyByPrimaryKeySelective(payApplyForm);
|
|
|
- if(h==0){throw new RuntimeException();}
|
|
|
+ int h = orderPayApplyService.modifyByPrimaryKeySelective(payApplyForm);
|
|
|
+ if (h == 0) {
|
|
|
+ throw new RuntimeException();
|
|
|
+ }
|
|
|
}
|
|
|
return i;
|
|
|
}
|
|
@@ -316,10 +379,10 @@ public class OrderInfoServiceImpl implements OrderInfoService {
|
|
|
*/
|
|
|
@Override
|
|
|
public GoodsOrderInfoForm getOrderInfoByNo(String orderNo) {
|
|
|
- GoodsOrderInfo orderInfo = goodsOrderInfoMapper.getOrderInfoByNo(orderNo);
|
|
|
- if(Objects.nonNull(orderInfo)){
|
|
|
- return BeanCopyUtil.convertBean(orderInfo,GoodsOrderInfoForm.class);
|
|
|
- }
|
|
|
+ GoodsOrderInfo orderInfo = goodsOrderInfoMapper.getOrderInfoByNo(orderNo);
|
|
|
+ if (Objects.nonNull(orderInfo)) {
|
|
|
+ return BeanCopyUtil.convertBean(orderInfo, GoodsOrderInfoForm.class);
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
|
|
@@ -332,24 +395,26 @@ public class OrderInfoServiceImpl implements OrderInfoService {
|
|
|
@Override
|
|
|
public GoodsOrderInfoForm saveOrderInfoForOffline(GoodsOrderInfoForm goodsOrderInfoForm) {
|
|
|
int i = this.saveSelective(goodsOrderInfoForm);
|
|
|
- if(i>0){
|
|
|
+ if (i > 0) {
|
|
|
//生成订单明细
|
|
|
- List<GoodsOrderDetailForm> detaillist = goodsOrderInfoForm.getGoodsOrderDetailForm();
|
|
|
- if(null!=detaillist && detaillist.size()>0){
|
|
|
- for (GoodsOrderDetailForm bean:detaillist) {
|
|
|
+ List<GoodsOrderDetailForm> detaillist = goodsOrderInfoForm.getGoodsOrderDetailForm();
|
|
|
+ if (null != detaillist && detaillist.size() > 0) {
|
|
|
+ for (GoodsOrderDetailForm bean : detaillist) {
|
|
|
bean.setFkOrderGuid(goodsOrderInfoForm.getGuid());
|
|
|
bean.setState(1);
|
|
|
bean.setModifiedTime(new Date());
|
|
|
bean.setCreateTime(new Date());
|
|
|
}
|
|
|
- int j = orderDetailInfoService.batchSaveOrderDetailByList(detaillist);
|
|
|
- if (j==0){throw new RuntimeException();}
|
|
|
- }else {
|
|
|
+ int j = orderDetailInfoService.batchSaveOrderDetailByList(detaillist);
|
|
|
+ if (j == 0) {
|
|
|
+ throw new RuntimeException();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
throw new RuntimeException("order detail list is empty!!!!!");
|
|
|
}
|
|
|
//更新商品销售表
|
|
|
- if(null!=detaillist && detaillist.size()>0){
|
|
|
- for (GoodsOrderDetailForm bean:detaillist) {
|
|
|
+ if (null != detaillist && detaillist.size() > 0) {
|
|
|
+ for (GoodsOrderDetailForm bean : detaillist) {
|
|
|
BigDecimal saleCarbon = bean.getSaleNum();
|
|
|
String goodsGuid = bean.getFkGoodsGuid();
|
|
|
GoodsSaleInfoForm goodsSaleInfoForm = orderSaleInfoService.queryByPrimaryKey(goodsGuid);
|
|
@@ -358,8 +423,8 @@ public class OrderInfoServiceImpl implements OrderInfoService {
|
|
|
goodsSaleInfoForm.setSaledCarbonSkin(saledCarbonSkin);
|
|
|
goodsSaleInfoForm.setUnsaledCarbonSkin(unSaleCarbonSkin);
|
|
|
goodsSaleInfoForm.setModifiedTime(new Date());
|
|
|
- int h =orderSaleInfoService.modifiedOrderSaleInfo(goodsSaleInfoForm);
|
|
|
- if(h==0){
|
|
|
+ int h = orderSaleInfoService.modifiedOrderSaleInfo(goodsSaleInfoForm);
|
|
|
+ if (h == 0) {
|
|
|
throw new RuntimeException();
|
|
|
}
|
|
|
}
|
|
@@ -377,7 +442,7 @@ public class OrderInfoServiceImpl implements OrderInfoService {
|
|
|
|
|
|
@Override
|
|
|
public int save(GoodsOrderInfoForm record) {
|
|
|
- GoodsOrderInfo goodsOrderInfo = BeanCopyUtil.convertBean(record,GoodsOrderInfo.class);
|
|
|
+ GoodsOrderInfo goodsOrderInfo = BeanCopyUtil.convertBean(record, GoodsOrderInfo.class);
|
|
|
GeneratorIdUtils generatorIdUtils = new GeneratorIdUtils();
|
|
|
String orderNum = generatorIdUtils.nextId();
|
|
|
goodsOrderInfo.setGuid(GetUUID.getUUID());
|
|
@@ -398,19 +463,19 @@ public class OrderInfoServiceImpl implements OrderInfoService {
|
|
|
record.setState(1);
|
|
|
record.setCreateTime(new Date());
|
|
|
record.setModifiedTime(new Date());
|
|
|
- GoodsOrderInfo goodsOrderInfo = BeanCopyUtil.convertBean(record,GoodsOrderInfo.class);
|
|
|
+ GoodsOrderInfo goodsOrderInfo = BeanCopyUtil.convertBean(record, GoodsOrderInfo.class);
|
|
|
return goodsOrderInfoMapper.insertSelective(goodsOrderInfo);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public GoodsOrderInfoForm queryByPrimaryKey(String guid) {
|
|
|
GoodsOrderInfo goodsOrderInfo = goodsOrderInfoMapper.selectByPrimaryKey(guid);
|
|
|
- return BeanCopyUtil.convertBean(goodsOrderInfo,GoodsOrderInfoForm.class);
|
|
|
+ return BeanCopyUtil.convertBean(goodsOrderInfo, GoodsOrderInfoForm.class);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int modifyByPrimaryKeySelective(GoodsOrderInfoForm record) {
|
|
|
- GoodsOrderInfo goodsOrderInfo = BeanCopyUtil.convertBean(record,GoodsOrderInfo.class);
|
|
|
+ GoodsOrderInfo goodsOrderInfo = BeanCopyUtil.convertBean(record, GoodsOrderInfo.class);
|
|
|
return goodsOrderInfoMapper.updateByPrimaryKeySelective(goodsOrderInfo);
|
|
|
}
|
|
|
|
|
@@ -422,7 +487,112 @@ public class OrderInfoServiceImpl implements OrderInfoService {
|
|
|
|
|
|
@Override
|
|
|
public int modifyByPrimaryKey(GoodsOrderInfoForm record) {
|
|
|
- GoodsOrderInfo goodsOrderInfo = BeanCopyUtil.convertBean(record,GoodsOrderInfo.class);
|
|
|
+ GoodsOrderInfo goodsOrderInfo = BeanCopyUtil.convertBean(record, GoodsOrderInfo.class);
|
|
|
return goodsOrderInfoMapper.updateByPrimaryKey(goodsOrderInfo);
|
|
|
}
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CustomerService customerService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GoodsInfoMapper goodsInfoMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GoodsOrderDetailMapper goodsOrderDetailMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void createOrder(CreateOrderFrom createOrderFrom) {
|
|
|
+ //获取登陆人信息
|
|
|
+ CustomerInfoForm customerInfo = customerService.getCurrentMember();
|
|
|
+ if (customerInfo == null) {
|
|
|
+ throw new RuntimeException("获取登陆信息失败");
|
|
|
+ }
|
|
|
+ String customerId = customerInfo.getGuid();
|
|
|
+
|
|
|
+ List<CreateOrderDetailFrom> goods = createOrderFrom.getGoods();
|
|
|
+ //全部订单总价
|
|
|
+ BigDecimal sumTotal = new BigDecimal(0);
|
|
|
+ //全部碳汇量
|
|
|
+ BigDecimal carbonTotal = new BigDecimal(0);
|
|
|
+ String orderId = GetUUID.getUUID();
|
|
|
+ List<GoodsOrderDetail> dataList = new ArrayList<>();
|
|
|
+ for (CreateOrderDetailFrom good : goods) {
|
|
|
+ String goodsId = good.getGoodsId();
|
|
|
+ //购买的碳汇量
|
|
|
+ BigDecimal carbonVal = good.getCarbonVal();
|
|
|
+ GoodsInfo goodsInfo = goodsInfoMapper.selectByPrimaryKey(goodsId);
|
|
|
+ String guid = goodsInfo.getGuid();
|
|
|
+ //还剩碳汇量
|
|
|
+ BigDecimal carbonValRe = goodsInfo.getCarbonVal();
|
|
|
+ if (StringUtils.isEmpty(carbonValRe)) {
|
|
|
+ throw new RuntimeException("碳汇量不够了");
|
|
|
+ }
|
|
|
+ if (carbonVal.compareTo(carbonValRe) == 1) {
|
|
|
+ throw new RuntimeException("购买的碳汇量大于剩余的碳汇量");
|
|
|
+ }
|
|
|
+ //商品单价
|
|
|
+ BigDecimal price = goodsInfo.getPrice();
|
|
|
+ //单个碳汇总价
|
|
|
+ BigDecimal sum = carbonVal.multiply(price);
|
|
|
+
|
|
|
+ sumTotal = sumTotal.add(sum);
|
|
|
+
|
|
|
+ carbonTotal = carbonTotal.add(carbonVal);
|
|
|
+ //剩余碳汇量
|
|
|
+ BigDecimal reCarbonVal = carbonValRe.subtract(carbonVal);
|
|
|
+ goodsInfo.setCarbonVal(reCarbonVal);
|
|
|
+ goodsInfoMapper.updateByPrimaryKeySelective(goodsInfo);
|
|
|
+
|
|
|
+ //获取小订单
|
|
|
+ addGoodsOrderDetail(customerId, orderId, dataList, good, goodsInfo, sum);
|
|
|
+ }
|
|
|
+ GoodsOrderInfo goodsOrderInfo = new GoodsOrderInfo();
|
|
|
+ //构建大订单参数
|
|
|
+ addGoodsOrderInfo(customerInfo, customerId, sumTotal, carbonTotal, orderId, goodsOrderInfo);
|
|
|
+ //新增大定单
|
|
|
+ goodsOrderInfoMapper.insertSelective(goodsOrderInfo);
|
|
|
+ //新增小定单
|
|
|
+ goodsOrderDetailMapper.batchSaveOrderDetailList(dataList);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addGoodsOrderInfo(CustomerInfoForm customerInfo, String customerId, BigDecimal sumTotal, BigDecimal carbonTotal, String orderId, GoodsOrderInfo goodsOrderInfo) {
|
|
|
+ GeneratorIdUtils generatorIdUtils = new GeneratorIdUtils();
|
|
|
+ String orderNum = generatorIdUtils.nextId();
|
|
|
+ //构建订单信息
|
|
|
+ goodsOrderInfo.setFkCustomerGuid(customerId);
|
|
|
+ goodsOrderInfo.setCustomerName(customerInfo.getCustomerName());
|
|
|
+ goodsOrderInfo.setCustomerType(customerInfo.getCustomerType().toString());
|
|
|
+ //返回生成的订单id和订单编号
|
|
|
+ goodsOrderInfo.setGuid(orderId);
|
|
|
+ goodsOrderInfo.setOrderNo(orderNum);
|
|
|
+ goodsOrderInfo.setCreateUser(customerId);
|
|
|
+ goodsOrderInfo.setCreateTime(new Date());
|
|
|
+ goodsOrderInfo.setOrderStatus(1);
|
|
|
+ //碳汇总价
|
|
|
+ goodsOrderInfo.setOrderAmount(sumTotal);
|
|
|
+ //碳汇总数量
|
|
|
+ goodsOrderInfo.setOrderCarbonAmount(carbonTotal);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addGoodsOrderDetail(String customerId, String orderId, List<GoodsOrderDetail> dataList, CreateOrderDetailFrom good, GoodsInfo goodsInfo, BigDecimal sum) {
|
|
|
+ GoodsOrderDetail goodsOrderDetail = new GoodsOrderDetail();
|
|
|
+ goodsOrderDetail.setGuid(GetUUID.getUUID());
|
|
|
+ goodsOrderDetail.setCreateUser(customerId);
|
|
|
+ goodsOrderDetail.setCreateTime(new Date());
|
|
|
+ goodsOrderDetail.setGoodsPrice(goodsInfo.getPrice());
|
|
|
+ //设置单个销售总价
|
|
|
+ goodsOrderDetail.setAmount(sum);
|
|
|
+ //设置谈汇量
|
|
|
+ goodsOrderDetail.setSaleNum(good.getCarbonVal());
|
|
|
+ //设置商品id
|
|
|
+ goodsOrderDetail.setFkGoodsGuid(goodsInfo.getGuid());
|
|
|
+ //设置商品名称
|
|
|
+ goodsOrderDetail.setGoodsName(goodsInfo.getGoodsName());
|
|
|
+ goodsOrderDetail.setFkOrderGuid(orderId);
|
|
|
+ goodsOrderDetail.setState(1);
|
|
|
+
|
|
|
+ dataList.add(goodsOrderDetail);
|
|
|
+ }
|
|
|
}
|