This commit is contained in:
Cauchy
2023-10-17 16:27:26 +08:00
parent 99484c90e0
commit 8daf30493c
23 changed files with 149 additions and 149 deletions

View File

@@ -1,6 +1,5 @@
package com.peanut.modules.book.controller;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
@@ -22,6 +21,7 @@ import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.*;
import java.util.stream.Collectors;
@@ -88,11 +88,11 @@ public class BuyOrderController {
@Transactional
public R buySave(@RequestBody BuyOrderEntity buyOrder) throws IOException {
// 获取订单详情
List<BuyOrderDetailEntity> products = buyOrder.getProducts();
List<BuyOrderDetail> products = buyOrder.getProducts();
// 订单总金额
BigDecimal totalPrice = new BigDecimal(0);
// 遍历商品总价计算
for (BuyOrderDetailEntity buyOrderDetail : products) {
for (BuyOrderDetail buyOrderDetail : products) {
Integer productId = buyOrderDetail.getProductId();
int quantity = buyOrderDetail.getQuantity();
ShopProductEntity product = shopProductService.getById(productId);
@@ -103,7 +103,11 @@ public class BuyOrderController {
totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(quantity)));
buyOrderDetail.setProductName(product.getProductName());
buyOrderDetail.setProductPrice(product.getPrice());
buyOrderDetail.setAddressId(buyOrder.getAddressId());
int originWeight = product.getWeight();
int originWeightIntValue = originWeight / 100;
int originWeightDecimalValue = originWeightIntValue % 100;
buyOrderDetail.setWeight(BigDecimal.valueOf(originWeightIntValue).add(BigDecimal.valueOf(originWeightDecimalValue).divide(new BigDecimal(100),
MathContext.DECIMAL64)));
buyOrderDetail.setProductUrl(product.getProductImages());
buyOrderDetail.setOrderStatus(Constants.ORDER_STATUS_TO_BE_PAID);
}
@@ -115,7 +119,7 @@ public class BuyOrderController {
buyOrder.setPaymentDate(new Date());
buyOrderService.save(buyOrder);
for (BuyOrderDetailEntity buyOrderDetail : products) {
for (BuyOrderDetail buyOrderDetail : products) {
buyOrderDetail.setOrderId(buyOrder.getOrderId());
buyOrderDetail.setUserId(buyOrder.getUserId());
if (Constants.BUY_TYPE_CART.equals(buyOrder.getBuyType())) {
@@ -182,27 +186,27 @@ public class BuyOrderController {
public R appGetOrderInfo(@PathVariable String type, @RequestParam("orderId") Integer orderId) {
BuyOrderEntity buyOrder = buyOrderService.getById(orderId);
buyOrder.setTimestamp(buyOrder.getCreateTime().getTime() / 1000);
List<BuyOrderDetailEntity> orderDetail = null;
List<BuyOrderDetail> orderDetail = null;
if ("1".equals(type)) {
orderDetail = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetailEntity>()
orderDetail = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetail>()
.eq("order_id", orderId));
} else {
orderDetail = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetailEntity>()
orderDetail = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetail>()
.eq("order_id", orderId));
}
for (BuyOrderDetailEntity buyOrderDetailEntity : orderDetail) {
for (BuyOrderDetail buyOrderDetail : orderDetail) {
ShopProductEntity prod = shopProductService.getById(buyOrderDetailEntity.getProductId());
ShopProductEntity prod = shopProductService.getById(buyOrderDetail.getProductId());
if (prod != null) {
buyOrderDetailEntity.setImage(prod.getProductImages());
buyOrderDetail.setImage(prod.getProductImages());
}
}
List<BuyOrderDetailEntity> resultOrder = new ArrayList<BuyOrderDetailEntity>();
List<BuyOrderDetail> resultOrder = new ArrayList<BuyOrderDetail>();
Set<String> sn_no = new HashSet<String>();
for (BuyOrderDetailEntity buyOrderDetailEntity : orderDetail) {
resultOrder.add(buyOrderDetailEntity);
sn_no.add(buyOrderDetailEntity.getShippingSn());
for (BuyOrderDetail buyOrderDetail : orderDetail) {
resultOrder.add(buyOrderDetail);
sn_no.add(buyOrderDetail.getExpressOrderId());
}
UserRecordEntity userRecordEntity = userRecordService.getBaseMapper().selectOne(new QueryWrapper<UserRecordEntity>()
@@ -222,22 +226,22 @@ public class BuyOrderController {
/**
* 及时查询快递信息
*/
@RequestMapping("/queryFMS")
public R queryFMS(@RequestParam Map<String, String> params) {
List<BuyOrderDetailEntity> detailList = this.buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetailEntity>().eq("order_id", params.get("orderId")));
List<JSONObject> jsonList = new ArrayList<>();
JSONObject jsonObj = null;
for (BuyOrderDetailEntity detail : detailList) {
jsonObj = buyOrderService.queryFMS(detail.getShipperCode(), detail.getShippingSn());
if (Objects.isNull(jsonObj)) {
return R.ok("暂未查到物流信息!");
}
jsonObj.put("ShipperName", detail.getShipperName());
jsonList.add(jsonObj);
}
return R.ok().put("rntStr", jsonList);
}
// @RequestMapping("/queryFMS")
// public R queryFMS(@RequestParam Map<String, String> params) {
// List<BuyOrderDetailEntity> detailList = this.buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetailEntity>().eq("order_id", params.get("orderId")));
// List<JSONObject> jsonList = new ArrayList<>();
// JSONObject jsonObj = null;
// for (BuyOrderDetailEntity detail : detailList) {
// jsonObj = buyOrderService.queryFMS(detail.getShipperCode(), detail.getShippingSn());
// if (Objects.isNull(jsonObj)) {
// return R.ok("暂未查到物流信息!");
// }
// jsonObj.put("ShipperName", detail.getShipperName());
// jsonList.add(jsonObj);
//
// }
// return R.ok().put("rntStr", jsonList);
// }
/**
* 检查可合并的订单信息
@@ -267,14 +271,14 @@ public class BuyOrderController {
*
* @param expressCompanyCode 快递公司编码
* @param userAddressId 用户地址 ID
* @param productIds 商品 ID 列表
* @param buyOrderDetailId 订单详情列表
* @return R
*/
@RequestMapping(value = "/createSplitPackages", method = RequestMethod.POST)
public R createSplitPackageOrder(@RequestParam("expressCompanyCode") String expressCompanyCode,
@RequestParam("userAddressId") Integer userAddressId,
@RequestBody List<Integer> productIds) {
buyOrderService.createSplitPackageOrder(expressCompanyCode, userAddressId, productIds);
@RequestBody List<Integer> buyOrderDetailId) throws Exception {
buyOrderService.createSplitPackageOrder(expressCompanyCode, userAddressId, buyOrderDetailId);
return R.ok();
}
@@ -297,7 +301,7 @@ public class BuyOrderController {
* @param product
* @return
*/
private boolean handleStock(BuyOrderDetailEntity buyOrderDetail, ShopProductEntity product) {
private boolean handleStock(BuyOrderDetail buyOrderDetail, ShopProductEntity product) {
int quantity = buyOrderDetail.getQuantity();
if (product.getProductStock() - quantity < 0) {
return false;
@@ -380,8 +384,8 @@ public class BuyOrderController {
* @param products
* @param buyOrder
*/
private void addEbookToUser(List<BuyOrderDetailEntity> products, BuyOrderEntity buyOrder) {
List<Integer> productIds = products.stream().map(BuyOrderDetailEntity::getProductId).collect(Collectors.toList());
private void addEbookToUser(List<BuyOrderDetail> products, BuyOrderEntity buyOrder) {
List<Integer> productIds = products.stream().map(BuyOrderDetail::getProductId).collect(Collectors.toList());
for (Integer productId : productIds) {
List<Integer> collect = shopProductBookService.getBaseMapper().selectList(new LambdaQueryWrapper<ShopProductBookEntity>()
.eq(ShopProductBookEntity::getProductId, productId)
@@ -396,7 +400,7 @@ public class BuyOrderController {
* @param buyOrder
* @param buyOrderDetail
*/
private void handleBuyCart(BuyOrderEntity buyOrder, BuyOrderDetailEntity buyOrderDetail) {
private void handleBuyCart(BuyOrderEntity buyOrder, BuyOrderDetail buyOrderDetail) {
List<OrderCartEntity> orderCartList = orderCartService.getBaseMapper().selectList(new QueryWrapper<OrderCartEntity>()
.eq("user_id", buyOrder.getUserId()).eq("product_id", buyOrderDetail.getProductId()));
if (orderCartList.size() > 0) {

View File

@@ -2,7 +2,7 @@ package com.peanut.modules.book.controller;
import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.R;
import com.peanut.modules.book.entity.BuyOrderDetailEntity;
import com.peanut.modules.book.entity.BuyOrderDetail;
import com.peanut.modules.book.service.BuyOrderDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -61,7 +61,7 @@ public class BuyOrderDetailController {
*/
@RequestMapping("/info/{allOrderId}")
public R info(@PathVariable("allOrderId") Long allOrderId) {
BuyOrderDetailEntity buyOrderDetail = buyOrderDetailService.getById(allOrderId);
BuyOrderDetail buyOrderDetail = buyOrderDetailService.getById(allOrderId);
return R.ok().put("buyOrderDetail", buyOrderDetail);
}
@@ -69,7 +69,7 @@ public class BuyOrderDetailController {
* 保存
*/
@RequestMapping("/save")
public R save(@RequestBody BuyOrderDetailEntity buyOrderDetail) {
public R save(@RequestBody BuyOrderDetail buyOrderDetail) {
buyOrderDetailService.save(buyOrderDetail);
return R.ok();
}
@@ -78,7 +78,7 @@ public class BuyOrderDetailController {
* 修改
*/
@RequestMapping("/update")
public R update(@RequestBody BuyOrderDetailEntity buyOrderDetail) {
public R update(@RequestBody BuyOrderDetail buyOrderDetail) {
buyOrderDetailService.updateById(buyOrderDetail);
return R.ok();
}
@@ -93,7 +93,7 @@ public class BuyOrderDetailController {
}
@RequestMapping("/updateOrderStatus")
public R updateOrderStatus(@RequestBody BuyOrderDetailEntity buyOrderDetail) {
public R updateOrderStatus(@RequestBody BuyOrderDetail buyOrderDetail) {
buyOrderDetail.setOrderStatus("2");
buyOrderDetailService.updateById(buyOrderDetail);
return R.ok();
@@ -108,7 +108,6 @@ public class BuyOrderDetailController {
*/
@RequestMapping("/batchUpdateByShippingSns")
public R batchUpdateByShippingSns(@RequestBody String[] shippingSnList) {
buyOrderDetailService.batchUpdateByShippingSns(shippingSnList);
return R.ok();
}
}

View File

@@ -98,17 +98,17 @@ public class ShopProductController {
public R bookList(@RequestParam("userId") Integer userId
) {
//查询已购买的书籍
List<BuyOrderDetailEntity> buyOrderDetailEntities = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetailEntity>()
List<BuyOrderDetail> buyOrderDetailEntities = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetail>()
.eq("user_id", userId));
//hashset不重复 且无序
Set<String> purchasedProductIds = new HashSet<>();
ArrayList<Object> list = new ArrayList<>();
Map<String, Object> map = new HashMap<>();
for (BuyOrderDetailEntity buyOrderDetailEntity : buyOrderDetailEntities) {
map.put("ProductId", String.valueOf(buyOrderDetailEntity.getProductId()));
for (BuyOrderDetail buyOrderDetail : buyOrderDetailEntities) {
map.put("ProductId", String.valueOf(buyOrderDetail.getProductId()));
list.add(map);
//去重取出以后买书籍的id
purchasedProductIds.add(String.valueOf(buyOrderDetailEntity.getProductId()));
purchasedProductIds.add(String.valueOf(buyOrderDetail.getProductId()));
}
//查询商品表并过滤已购买商品id,根据时间倒叙展示
List<ShopProductEntity> allProductEntities = shopProductService.getBaseMapper().selectList(new QueryWrapper<ShopProductEntity>()

View File

@@ -1,6 +1,5 @@
package com.peanut.modules.book.controller;
import cn.com.marsoft.tool.ToolObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.R;
@@ -126,7 +125,7 @@ public class UserFollowUpController {
Integer bookid = userRecord.getBookid();
Integer userid = userRecord.getUserid();
Integer id1 = userRecord.getId();
BuyOrderDetailEntity detailEntity = buyOrderDetailService.getBaseMapper().selectOne(new QueryWrapper<BuyOrderDetailEntity>()
BuyOrderDetail detailEntity = buyOrderDetailService.getBaseMapper().selectOne(new QueryWrapper<BuyOrderDetail>()
.eq("Order_id", orderId).eq("product_id",bookid));
UserFollowUpEntity followUpEntity = userFollowUpService.getBaseMapper().selectOne(new QueryWrapper<UserFollowUpEntity>().eq("userid", userid).eq("oid",id1).last("LIMIT 1"));

View File

@@ -204,7 +204,7 @@ public class UserRecordController {
);
Integer orderId = buyOrderEntity.getOrderId();
BuyOrderDetailEntity detailEntity = buyOrderDetailService.getBaseMapper().selectOne(new QueryWrapper<BuyOrderDetailEntity>().eq("Order_id", orderId).eq("product_id", recordEntity.getBookid()));
BuyOrderDetail detailEntity = buyOrderDetailService.getBaseMapper().selectOne(new QueryWrapper<BuyOrderDetail>().eq("Order_id", orderId).eq("product_id", recordEntity.getBookid()));
Integer orderId1 = detailEntity.getOrderId();
UserRecordEntity userRecordEntity = userRecordService.getBaseMapper().selectOne(new QueryWrapper<UserRecordEntity>().eq("orderSn", recordEntity.getOrderSn()).eq("userid", recordEntity.getUserid()).eq("orderdid", orderId1).last("LIMIT 1"));

View File

@@ -1,6 +1,6 @@
package com.peanut.modules.book.dao;
import com.peanut.modules.book.entity.BuyOrderDetailEntity;
import com.peanut.modules.book.entity.BuyOrderDetail;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@@ -14,8 +14,8 @@ import java.util.List;
* @date 2022-08-29 15:27:44
*/
@Mapper
public interface BuyOrderDetailDao extends BaseMapper<BuyOrderDetailEntity> {
public interface BuyOrderDetailDao extends BaseMapper<BuyOrderDetail> {
public List<BuyOrderDetailEntity> queryListByOrderIds(Integer[] ids);
public List<BuyOrderDetail> queryListByOrderIds(Integer[] ids);
}

View File

@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
import java.math.BigDecimal;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/**
@@ -21,14 +22,14 @@ import lombok.Data;
*/
@Data
@TableName("buy_order_detail")
public class BuyOrderDetailEntity implements Serializable {
public class BuyOrderDetail implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 订单详情id
*/
@TableId
private Long allOrderId;
private Long id;
/**
* 订单表id
*/
@@ -56,15 +57,11 @@ public class BuyOrderDetailEntity implements Serializable {
/**
* 商品重量
*/
private Double weight;
private BigDecimal weight;
/**
* 商品类型
*/
private String productType;
/**
* 物流单号
*/
private String shippingSn;
/**
* 订单状态 0-待支付 1-待发货 2-待收货
*/
@@ -81,28 +78,12 @@ public class BuyOrderDetailEntity implements Serializable {
/**
* 图片
*/
@TableField(exist = false)
@TableField(exist = false)
private String image;
/**
* 地址id
*/
private Integer addressId;
/**
* 面单html
*/
private String fmsHtml;
/**
* 快递公司编码
*/
private String shipperCode;
/**
* 快递公司名称
*/
private String shipperName;
/**
* 是否已打印 0: 未打印1已打印
*/
private String isPrint;
private String expressBill;
/**
* 商品图片地址
*/
@@ -110,10 +91,9 @@ public class BuyOrderDetailEntity implements Serializable {
/**
* 评价 ID
*/
@TableField("record_id")
private Integer recordId;
@TableField(exist = false)
private Long timestamp;
private Integer recordId;
/**
* 快递订单 ID
*/
private String expressOrderId;
}

View File

@@ -125,7 +125,7 @@ public class BuyOrderEntity implements Serializable {
private Integer delFlag;
@TableField(exist = false)
private List<BuyOrderDetailEntity> products;
private List<BuyOrderDetail> products;
@TableField(exist = false)
private String buyType;

View File

@@ -30,7 +30,7 @@ public class ExpressOrder {
/**
* 订单号
*/
private String orderId;
private Integer orderId;
/**
* 快递公司代码
*/

View File

@@ -45,7 +45,7 @@ public class ShopProductEntity implements Serializable {
/**
* 商品重量
*/
private int weight;
private Integer weight;
/**
* 上架状态
*/

View File

@@ -2,7 +2,7 @@ package com.peanut.modules.book.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.common.utils.PageUtils;
import com.peanut.modules.book.entity.BuyOrderDetailEntity;
import com.peanut.modules.book.entity.BuyOrderDetail;
import java.util.Map;
@@ -13,7 +13,7 @@ import java.util.Map;
* @email yl328572838@163.com
* @date 2022-08-29 15:27:44
*/
public interface BuyOrderDetailService extends IService<BuyOrderDetailEntity> {
public interface BuyOrderDetailService extends IService<BuyOrderDetail> {
PageUtils queryPage(Map<String, Object> params);
@@ -21,5 +21,5 @@ public interface BuyOrderDetailService extends IService<BuyOrderDetailEntity> {
PageUtils querybuy(Map<String,Object>params);
void batchUpdateByShippingSns(String[] shippingSnList);
// void batchUpdateByShippingSns(String[] shippingSnList);
}

View File

@@ -28,5 +28,13 @@ public interface BuyOrderService extends IService<BuyOrderEntity> {
// 查询所有订单是否有可合并
Page checkOrder(Map<String, Object> params);
void createSplitPackageOrder(String expressCompanyCode, Integer userAddressId, List<Integer> shopProductIdList) throws Exception;
/**
* 订单拆分发货
*
* @param expressCompanyCode 快递公司代码
* @param userAddressId 用户地址 ID
* @param buyOrderDetailId 订单详情 ID 列表
* @throws Exception exception
*/
void createSplitPackageOrder(String expressCompanyCode, Integer userAddressId, List<Integer> buyOrderDetailId) throws Exception;
}

View File

@@ -1,9 +1,8 @@
package com.peanut.modules.book.service.impl;
import jodd.util.StringUtil;
import com.peanut.modules.book.entity.BuyOrderDetail;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -12,19 +11,18 @@ import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.Query;
import com.peanut.modules.book.dao.BuyOrderDetailDao;
import com.peanut.modules.book.entity.BuyOrderDetailEntity;
import com.peanut.modules.book.service.BuyOrderDetailService;
@Service("buyOrderDetailService")
public class BuyOrderDetailServiceImpl extends ServiceImpl<BuyOrderDetailDao, BuyOrderDetailEntity> implements BuyOrderDetailService {
public class BuyOrderDetailServiceImpl extends ServiceImpl<BuyOrderDetailDao, BuyOrderDetail> implements BuyOrderDetailService {
@Override
public PageUtils queryPage(Map<String, Object> params) {
Integer orderId = Integer.valueOf((String) params.get("orderId"));
IPage<BuyOrderDetailEntity> page = this.page(
new Query<BuyOrderDetailEntity>().getPage(params),
new QueryWrapper<BuyOrderDetailEntity>()
IPage<BuyOrderDetail> page = this.page(
new Query<BuyOrderDetail>().getPage(params),
new QueryWrapper<BuyOrderDetail>()
.eq("order_id",orderId)
);
@@ -38,9 +36,9 @@ public class BuyOrderDetailServiceImpl extends ServiceImpl<BuyOrderDetailDao, Bu
*/
@Override
public PageUtils querySheet(Map<String, Object> params) {
IPage<BuyOrderDetailEntity> page = this.page(
new Query<BuyOrderDetailEntity>().getPage(params),
new QueryWrapper<BuyOrderDetailEntity>().eq("is_print","0")
IPage<BuyOrderDetail> page = this.page(
new Query<BuyOrderDetail>().getPage(params),
new QueryWrapper<BuyOrderDetail>().eq("is_print","0")
.groupBy("shipping_sn")
);
return new PageUtils(page);
@@ -49,9 +47,9 @@ public class BuyOrderDetailServiceImpl extends ServiceImpl<BuyOrderDetailDao, Bu
@Override
public PageUtils querybuy(Map<String, Object> params) {
Integer userid = Integer.valueOf((String) params.get("id"));
IPage<BuyOrderDetailEntity> page = this.page(
new Query<BuyOrderDetailEntity>().getPage(params),
new QueryWrapper<BuyOrderDetailEntity>()
IPage<BuyOrderDetail> page = this.page(
new Query<BuyOrderDetail>().getPage(params),
new QueryWrapper<BuyOrderDetail>()
.eq("user_id",userid)
);
@@ -60,17 +58,17 @@ public class BuyOrderDetailServiceImpl extends ServiceImpl<BuyOrderDetailDao, Bu
}
@Override
public void batchUpdateByShippingSns(String[] shippingSnList) {
List<BuyOrderDetailEntity> buyOrderDetailEntityList = this.list(new QueryWrapper<>());
for(String sn : shippingSnList){
for(BuyOrderDetailEntity buyOrderDetailEntity : buyOrderDetailEntityList){
if(StringUtil.isNotEmpty(buyOrderDetailEntity.getShippingSn()) && buyOrderDetailEntity.getShippingSn().equals(sn)){
buyOrderDetailEntity.setIsPrint("1");
}
}
}
this.updateBatchById(buyOrderDetailEntityList);
}
// @Override
// public void batchUpdateByShippingSns(String[] shippingSnList) {
// List<BuyOrderDetailEntity> buyOrderDetailEntityList = this.list(new QueryWrapper<>());
// for(String sn : shippingSnList){
// for(BuyOrderDetailEntity buyOrderDetailEntity : buyOrderDetailEntityList){
// if(StringUtil.isNotEmpty(buyOrderDetailEntity.getShippingSn()) && buyOrderDetailEntity.getShippingSn().equals(sn)){
// buyOrderDetailEntity.setIsPrint("1");
// }
// }
// }
// this.updateBatchById(buyOrderDetailEntityList);
// }
}

View File

@@ -9,7 +9,6 @@ import com.peanut.common.utils.ExcludeEmptyQueryWrapper;
import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.Query;
import com.peanut.modules.book.dao.BuyOrderDao;
import com.peanut.modules.book.dao.ShopProductDao;
import com.peanut.modules.book.entity.*;
import com.peanut.modules.book.service.*;
import com.peanut.modules.book.entity.ExpressCommodity;
@@ -34,9 +33,6 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
@Autowired
private MyUserService myUserService;
@Autowired
private ShopProductDao shopProductDao;
@Autowired
private UserAddressService userAddressService;
@@ -89,7 +85,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
MyUserEntity myUserEntity = myUserService.getById(userId);
if (!ObjectUtils.isEmpty(myUserEntity)) {
record.setUserName(myUserEntity.getName());
record.setProducts(buyOrderDetailService.list(new QueryWrapper<BuyOrderDetailEntity>()
record.setProducts(buyOrderDetailService.list(new QueryWrapper<BuyOrderDetail>()
.eq("order_id", record.getOrderId())));
}
@@ -139,7 +135,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
new QueryWrapper<BuyOrderEntity>().eq("del_flag", "0").eq("order_status", "1")
);
for (BuyOrderEntity order : buyOrderList) {
order.setProducts(buyOrderDetailService.list(new QueryWrapper<BuyOrderDetailEntity>()
order.setProducts(buyOrderDetailService.list(new QueryWrapper<BuyOrderDetail>()
.eq("order_id", order.getOrderId())));
orderList.add(order);
}
@@ -209,7 +205,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
new QueryWrapper<BuyOrderEntity>().eq("del_flag", "0").eq("order_status", "1").eq("is_send", "0")
);
for (BuyOrderEntity order : buyOrderList.getRecords()) {
order.setProducts(buyOrderDetailService.list(new QueryWrapper<BuyOrderDetailEntity>()
order.setProducts(buyOrderDetailService.list(new QueryWrapper<BuyOrderDetail>()
.eq("order_id", order.getOrderId())));
orderList.add(order);
}
@@ -249,34 +245,34 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
@Override
public void createSplitPackageOrder(String expressCompanyCode, Integer userAddressId, List<Integer> buyOrderDetailId) throws Exception {
QueryWrapper<BuyOrderDetailEntity> queryWrapper = new QueryWrapper<>();
QueryWrapper<BuyOrderDetail> queryWrapper = new QueryWrapper<>();
queryWrapper.in("id", buyOrderDetailId);
List<BuyOrderDetailEntity> buyOrderDetailList = buyOrderDetailService.list(queryWrapper);
List<BuyOrderDetail> buyOrderDetailList = buyOrderDetailService.list(queryWrapper);
BigDecimal totalWeight = new BigDecimal(0);
List<ExpressCommodity> commodityList = new ArrayList<>();
for (BuyOrderDetailEntity buyOrderDetail : buyOrderDetailList) {
for (BuyOrderDetail buyOrderDetail : buyOrderDetailList) {
ExpressCommodity commodity = new ExpressCommodity();
commodity.setGoodsName(buyOrderDetail.getProductName());
commodity.setGoodsquantity(buyOrderDetail.getQuantity());
commodity.setGoodsWeight(buyOrderDetail.getWeight());
commodity.setGoodsWeight(buyOrderDetail.getWeight().doubleValue());
totalWeight = totalWeight.add(
BigDecimal.valueOf(buyOrderDetail.getWeight()).multiply(new BigDecimal(buyOrderDetail.getQuantity()))
BigDecimal.valueOf(buyOrderDetail.getWeight().doubleValue()).multiply(new BigDecimal(buyOrderDetail.getQuantity()))
);
commodityList.add(commodity);
}
// 获取用户地址
UserAddress address = userAddressService.getById(userAddressId);
// 计算快递费用
BigDecimal expressFee = expressFeeService.calculateExpressFee(expressCompanyCode, totalWeight, address.getRegionCode());
ExpressOrder expressOrder = new ExpressOrder();
expressOrder.setOrderId(buyOrderDetailList.get(0).getOrderId());
expressOrder.setExpressFee(expressFee);
expressOrder.setCreateTime(new Date());
expressOrder.setTotalWeight(totalWeight);
expressOrder.setCommodity(commodityList);
expressOrder.setExpressCompanyCode(expressCompanyCode);
// 生成快递面单
expressOrderService.placeExpressOrder(address, expressOrder);
}
}

View File

@@ -5,16 +5,16 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.book.dao.ExpressFeeDao;
import com.peanut.modules.book.entity.ExpressFee;
import com.peanut.modules.book.service.ExpressFeeService;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
/**
* @Description: 快递费用服务接口实现类
* @Author: Cauchy
* @CreateTime: 2023/10/16
*/
@Service
public class ExpressFeeServiceImpl extends ServiceImpl<ExpressFeeDao, ExpressFee> implements ExpressFeeService {
@Override
public BigDecimal calculateExpressFee(String expressCompanyCode, BigDecimal weight, String regionCode) {
@@ -52,7 +52,9 @@ public class ExpressFeeServiceImpl extends ServiceImpl<ExpressFeeDao, ExpressFee
additionalWeight = weight.subtract(new BigDecimal(15));
}
QueryWrapper<ExpressFee> queryWrapper = new QueryWrapper<>();
regionCode = regionCode.substring(0, 3).concat("00");
if(!regionCode.startsWith("11") && !regionCode.startsWith("12") && !regionCode.startsWith("31") && !regionCode.startsWith("50")){
regionCode = regionCode.substring(0, 4).concat("00");
}
queryWrapper.eq("dest_code", regionCode);
queryWrapper.eq("weight_interval", weightInterval);
queryWrapper.eq("express_code", "SF");

View File

@@ -53,14 +53,19 @@ public class ExpressOrderServiceImpl extends ServiceImpl<ExpressOrderDao, Expres
public void placeExpressOrder(UserAddress userAddress, ExpressOrder expressOrder) throws Exception {
ExpressOrderRequestVo orderRequestVo = new ExpressOrderRequestVo();
// 订单号
orderRequestVo.setOrderCode(expressOrder.getOrderId());
orderRequestVo.setOrderCode(expressOrder.getOrderId().toString());
orderRequestVo.setIsReturnPrintTemplate(1);
orderRequestVo.setShipperCode(expressOrder.getExpressCompanyCode());
orderRequestVo.setPayType(3);
if (expressOrder.getExpressCompanyCode().equals("SF")) {
orderRequestVo.setMonthCode(Constants.EXPRESS_SF_MONTH_CODE);
}
orderRequestVo.setExpType(1);
orderRequestVo.setCost(expressOrder.getExpressFee().doubleValue());
// 发货人
ExpressUserInfoVo sender = new ExpressUserInfoVo();
sender.setCompany(senderName);
sender.setName(senderName);
sender.setMobile(senderMobile);
sender.setProvinceName(senderProvinceName);
sender.setCityName(senderCityName);
@@ -88,7 +93,7 @@ public class ExpressOrderServiceImpl extends ServiceImpl<ExpressOrderDao, Expres
private ExpressUserInfoVo buildReceiverBasedOnUserAddress(UserAddress userAddress) {
ExpressUserInfoVo vo = new ExpressUserInfoVo();
vo.setCompany(userAddress.getConsigneeName());
vo.setName(userAddress.getConsigneeName());
vo.setMobile(userAddress.getConsigneePhone());
vo.setAddress(userAddress.getDetailAddress());
String regionCode = userAddress.getRegionCode();
@@ -98,15 +103,15 @@ public class ExpressOrderServiceImpl extends ServiceImpl<ExpressOrderDao, Expres
vo.setExpAreaName(county.getCountyName());
String cityRegionCode;
if (regionCode.startsWith("11") || regionCode.startsWith("12") || regionCode.startsWith("31") || regionCode.startsWith("50")) {
cityRegionCode = regionCode.substring(0, 1).concat("0000");
cityRegionCode = regionCode.substring(0, 2).concat("0000");
} else {
cityRegionCode = regionCode.substring(0, 3).concat("00");
cityRegionCode = regionCode.substring(0, 4).concat("00");
}
QueryWrapper<CityEntity> cityQueryWrapper = new QueryWrapper<>();
cityQueryWrapper.eq("region_code", cityRegionCode);
CityEntity city = cityService.getOne(cityQueryWrapper);
vo.setCityName(city.getCityName());
String provinceRegionCode = regionCode.substring(0, 1).concat("0000");
String provinceRegionCode = regionCode.substring(0, 2).concat("0000");
QueryWrapper<ProvinceEntity> provinceQueryWrapper = new QueryWrapper<>();
provinceQueryWrapper.eq("region_code", provinceRegionCode);
ProvinceEntity province = provinceService.getOne(provinceQueryWrapper);

View File

@@ -69,5 +69,9 @@ public class ExpressOrderRequestVo {
* 备注
*/
private String Remark;
/**
* 是否返回电子面单模板
*/
private Integer IsReturnPrintTemplate;
}

View File

@@ -10,9 +10,13 @@ import lombok.Data;
@Data
public class ExpressUserInfoVo {
/**
* 姓名
* 公司
*/
private String Company;
/**
* 姓名
*/
private String Name;
/**
* 电话
*/

View File

@@ -17,9 +17,9 @@ spring:
type: com.alibaba.druid.pool.DruidDataSource
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://59.110.212.44:3306/e_book_test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
url: jdbc:mysql://127.0.0.1:3306/e_book_test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
username: root
password: HSXY1234hsxy
password: password
initial-size: 10
max-active: 100
min-idle: 10

View File

@@ -77,7 +77,7 @@ spring.jackson.serialization.FAIL_ON_EMPTY_BEANS: false
express:
sender:
senderName: 众妙之门
mobile:
mobile: 17602219785
provinceName: 天津
cityName: 天津
expAreaName: 南开

View File

@@ -37,7 +37,7 @@
<result property="paymentDate" column="payment_date" />
<collection property="products" ofType="com.peanut.modules.book.entity.BuyOrderDetailEntity">
<collection property="products" ofType="com.peanut.modules.book.entity.BuyOrderDetail">
<result property="orderId" column="order_id" />
<result property="productName" column="product_name" />
<result property="quantity" column="quantity" />
@@ -47,7 +47,7 @@
</collection>
</resultMap>
<!-- <resultMap id="OrderDetailResult" type="com.peanut.modules.book.entity.BuyOrderDetailEntity">-->
<!-- <resultMap id="OrderDetailResult" type="com.peanut.modules.book.entity.BuyOrderDetail">-->
<!-- </resultMap>-->

View File

@@ -4,7 +4,7 @@
<mapper namespace="com.peanut.modules.book.dao.BuyOrderDetailDao">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.peanut.modules.book.entity.BuyOrderDetailEntity" id="buyOrderDetailMap">
<resultMap type="com.peanut.modules.book.entity.BuyOrderDetail" id="buyOrderDetailMap">
<result property="allOrderId" column="all_order_id" />
<result property="orderId" column="order_id" />
<result property="userId" column="user_id" />
@@ -29,7 +29,7 @@
</resultMap>
<select id="queryListByOrderIds" resultType="com.peanut.modules.book.entity.BuyOrderDetailEntity">
<select id="queryListByOrderIds" resultType="com.peanut.modules.book.entity.BuyOrderDetail">
select
*
from buy_order_detail

View File

@@ -3,6 +3,7 @@
<mapper namespace="com.peanut.modules.book.dao.ExpressCompanyDao">
<select id="getExpressCompanyList" resultType="com.peanut.modules.book.vo.ExpressCompanyVo">
select name, code from express_company
select name as expressName, code as expressCode
from express_company
</select>
</mapper>