生成商品订单

This commit is contained in:
HH 2022-05-17 21:19:41 +08:00
parent 9e31d58627
commit 6230095ebe
6 changed files with 67 additions and 7 deletions

View File

@ -5,22 +5,28 @@ import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.utils.StringUtils; import com.ghy.common.utils.StringUtils;
import com.ghy.customer.domain.Customer; import com.ghy.customer.domain.Customer;
import com.ghy.customer.service.CustomerService; import com.ghy.customer.service.CustomerService;
import com.ghy.goods.domain.Goods;
import com.ghy.goods.request.AppGoodsRequest;
import com.ghy.goods.service.GoodsService; import com.ghy.goods.service.GoodsService;
import com.ghy.order.domain.OrderGoods;
import com.ghy.order.domain.OrderMaster; import com.ghy.order.domain.OrderMaster;
import com.ghy.order.request.AppOrderRequest; import com.ghy.order.request.AppOrderRequest;
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.service.FinancialDetailService; import com.ghy.payment.service.FinancialDetailService;
import com.ghy.payment.service.FinancialMasterService; import com.ghy.payment.service.FinancialMasterService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.*;
import java.util.stream.Collectors;
/** /**
* @author clunt * @author clunt
@ -42,6 +48,9 @@ public class OrderController extends BaseController {
@Autowired @Autowired
private OrderDetailService orderDetailService; private OrderDetailService orderDetailService;
@Autowired
private OrderGoodsService orderGoodsService;
@Autowired @Autowired
private FinancialMasterService financialMasterService; private FinancialMasterService financialMasterService;
@ -57,13 +66,14 @@ public class OrderController extends BaseController {
if (StringUtils.isNull(customer)) { if (StringUtils.isNull(customer)) {
return AjaxResult.error("用户不存在!"); return AjaxResult.error("用户不存在!");
} }
List<AppGoodsRequest> appGoodsList = appOrderRequest.getGoodsList();
// 校验商品信息(库存) // 校验商品信息(库存)
boolean flag = goodsService.checkStore(appOrderRequest.getGoodsList()); boolean flag = goodsService.checkStore(appGoodsList);
if (!flag) { if (!flag) {
return AjaxResult.error("库存不足!"); return AjaxResult.error("库存不足!");
} }
// 计算商品费用 // 计算商品费用
BigDecimal totalPay = goodsService.calculate(appOrderRequest.getGoodsList()); BigDecimal totalPay = goodsService.calculate(appGoodsList);
// 生成主单 // 生成主单
OrderMaster orderMaster = new OrderMaster(); OrderMaster orderMaster = new OrderMaster();
orderMaster.setCode(orderMasterService.createOrderCode()); orderMaster.setCode(orderMasterService.createOrderCode());
@ -73,12 +83,24 @@ public class OrderController extends BaseController {
orderMaster.setPayStatus(0); orderMaster.setPayStatus(0);
orderMaster.setCreateTime(new Date()); orderMaster.setCreateTime(new Date());
orderMasterService.insertOrderMaster(orderMaster); orderMasterService.insertOrderMaster(orderMaster);
Assert.notNull(orderMaster.getId(), "OrderMaster ID is null!");
//TODO 生成财务主单 //TODO 生成财务主单
//TODO 生成细单 //TODO 生成细单
//TODO 生成财务细单(含分销等.) //TODO 生成财务细单(含分销等.)
// 生成商品订单
Set<Long> goodsIds = appGoodsList.stream().map(AppGoodsRequest::getGoodsId).collect(Collectors.toSet());
Map<Long, Goods> goodsMap = goodsService.selectByIds(goodsIds).stream().filter(Objects::nonNull)
.collect(Collectors.toMap(Goods::getGoodsId, x -> x));
for (AppGoodsRequest appGoods : appGoodsList) {
Goods goods = goodsMap.get(appGoods.getGoodsId());
OrderGoods orderGoods = new OrderGoods(orderMaster.getId(), goods.getGoodsId(), goods.getGoodsName(), appGoods.getNum(), 0);
orderGoodsService.insertOrderGoods(orderGoods);
}
return AjaxResult.success(orderMaster); return AjaxResult.success(orderMaster);
} }

View File

@ -4,6 +4,7 @@ import com.ghy.goods.domain.Goods;
import com.ghy.goods.request.AppGoodsRequest; import com.ghy.goods.request.AppGoodsRequest;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
@ -80,4 +81,11 @@ public interface GoodsMapper {
* @return * @return
*/ */
int setCode(@Param("goodsId") Long goodsId, @Param("goodsCode") String goodsCode); int setCode(@Param("goodsId") Long goodsId, @Param("goodsCode") String goodsCode);
/**
* 用商品ID批量查询
*
* @param ids 商品ID
*/
List<Goods> selectByIds(Collection<Long> ids);
} }

View File

@ -4,6 +4,7 @@ import com.ghy.goods.domain.Goods;
import com.ghy.goods.request.AppGoodsRequest; import com.ghy.goods.request.AppGoodsRequest;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
@ -72,4 +73,10 @@ public interface GoodsService {
*/ */
String checkGoodsCodeUnique(Goods goods); String checkGoodsCodeUnique(Goods goods);
/**
* 用商品ID批量查询
*
* @param ids 商品ID
*/
List<Goods> selectByIds(Collection<Long> ids);
} }

View File

@ -14,6 +14,7 @@ import org.springframework.util.Assert;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
@ -104,6 +105,11 @@ public class GoodsServiceImpl implements GoodsService {
return UserConstants.GOODS_CODE_UNIQUE; return UserConstants.GOODS_CODE_UNIQUE;
} }
@Override
public List<Goods> selectByIds(Collection<Long> ids) {
return goodsMapper.selectByIds(ids);
}
public int countUserGoodsById(Goods goods) { public int countUserGoodsById(Goods goods) {
//TODO 校验商品是否上架 //TODO 校验商品是否上架

View File

@ -138,4 +138,11 @@
WHERE dept_goods_category_id = #{deptGoodsCategoryId} LIMIT 1 WHERE dept_goods_category_id = #{deptGoodsCategoryId} LIMIT 1
</select> </select>
<select id="selectByIds" resultMap="GoodsResult">
<include refid="selectGoods"/>
goods_id IN
<foreach collection="ids" item="goodsId" open="(" separator="," close=")">
#{goodsId}
</foreach>
</select>
</mapper> </mapper>

View File

@ -38,4 +38,14 @@ public class OrderGoods extends BaseEntity {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date finishTime; private Date finishTime;
public OrderGoods() {
}
public OrderGoods(Long orderId, Long goodsId, String goodsName, Integer goodsNum, Integer serverGoodsNum) {
this.orderId = orderId;
this.goodsId = goodsId;
this.goodsName = goodsName;
this.goodsNum = goodsNum;
this.serverGoodsNum = serverGoodsNum;
}
} }