flow finished need to test
This commit is contained in:
@@ -43,8 +43,7 @@ public class KdUtils {
|
||||
}
|
||||
|
||||
public static String urlEncoder(String str, String charset) throws UnsupportedEncodingException{
|
||||
String result = URLEncoder.encode(str, charset);
|
||||
return result;
|
||||
return URLEncoder.encode(str, charset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,7 +54,7 @@ public class KdUtils {
|
||||
* @throws UnsupportedEncodingException ,Exception
|
||||
* @return DataSign签名
|
||||
*/
|
||||
public static String encrypt (String content, String keyValue, String charset) throws UnsupportedEncodingException, Exception
|
||||
public static String encrypt (String content, String keyValue, String charset) throws Exception
|
||||
{
|
||||
if (keyValue != null)
|
||||
{
|
||||
|
||||
@@ -56,4 +56,33 @@ public class Constants {
|
||||
* 购买方式 - 购物车
|
||||
*/
|
||||
public static final String BUY_TYPE_CART = "1";
|
||||
|
||||
/**
|
||||
* 快递鸟 API key
|
||||
*/
|
||||
public static final String EXPRESS_API_KEY = "f4342e6c-5cfa-458f-997b-f973eb29eb1d";
|
||||
/**
|
||||
* business ID
|
||||
*/
|
||||
public static final String EXPRESS_BUSINESS_ID = "1788532";
|
||||
/**
|
||||
* 顺丰月付码
|
||||
*/
|
||||
public static final String EXPRESS_SF_MONTH_CODE = "0226032007";
|
||||
/**
|
||||
* 快递接口指令-下单
|
||||
*/
|
||||
public static final String EXPRESS_REQUEST_TYPE_PLACE_ORDER = "1007";
|
||||
/**
|
||||
* 快递接口指令-下单
|
||||
*/
|
||||
public static final String EXPRESS_REQUEST_TYPE_QUERY = "1002";
|
||||
/**
|
||||
* 快递接口 - 下单 URL
|
||||
*/
|
||||
public static final String EXPRESS_PLACE_ORDER_URL = "https://api.kdniao.com/api/EOrderService";
|
||||
/**
|
||||
* 快递接口 - 查询 URL
|
||||
*/
|
||||
public static final String EXPRESS_QUERY_URL = "https://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx";
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public class BuyOrderDetailEntity implements Serializable {
|
||||
/**
|
||||
* 商品重量
|
||||
*/
|
||||
private Float weight;
|
||||
private Double weight;
|
||||
/**
|
||||
* 商品类型
|
||||
*/
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.peanut.modules.book.vo;
|
||||
package com.peanut.modules.book.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@@ -8,7 +8,7 @@ import lombok.Data;
|
||||
* @CreateTime: 2023/10/16
|
||||
*/
|
||||
@Data
|
||||
public class ExpressCommodityVo {
|
||||
public class ExpressCommodity {
|
||||
/**
|
||||
* 商品名称
|
||||
*/
|
||||
@@ -5,6 +5,7 @@ import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 快递订单
|
||||
@@ -45,7 +46,7 @@ public class ExpressOrder {
|
||||
/**
|
||||
* 总重量
|
||||
*/
|
||||
private int totalWeight;
|
||||
private BigDecimal totalWeight;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@@ -54,4 +55,8 @@ public class ExpressOrder {
|
||||
* 删除标识
|
||||
*/
|
||||
private int delFlag;
|
||||
/**
|
||||
* 物品信息
|
||||
*/
|
||||
private List<ExpressCommodity> Commodity;
|
||||
}
|
||||
|
||||
@@ -28,5 +28,5 @@ public interface BuyOrderService extends IService<BuyOrderEntity> {
|
||||
// 查询所有订单是否有可合并
|
||||
Page checkOrder(Map<String, Object> params);
|
||||
|
||||
void createSplitPackageOrder(String expressCompanyCode, Integer userAddressId, List<Integer> shopProductIdList);
|
||||
void createSplitPackageOrder(String expressCompanyCode, Integer userAddressId, List<Integer> shopProductIdList) throws Exception;
|
||||
}
|
||||
@@ -16,5 +16,5 @@ public interface ExpressFeeService extends IService<ExpressFee> {
|
||||
* @param regionCode 地区代码
|
||||
* @return BigDecimal 费用
|
||||
*/
|
||||
BigDecimal calculateExpressFee(String expressCompanyCode, int weight, String regionCode);
|
||||
BigDecimal calculateExpressFee(String expressCompanyCode, BigDecimal weight, String regionCode);
|
||||
}
|
||||
|
||||
@@ -2,23 +2,19 @@ package com.peanut.modules.book.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.modules.book.entity.ExpressOrder;
|
||||
import com.peanut.modules.book.entity.UserAddress;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public interface ExpressOrderService extends IService<ExpressOrder> {
|
||||
/**
|
||||
* 新增快递订单信息
|
||||
* 下单生成面单
|
||||
*
|
||||
* @param expressOrder 快递订单
|
||||
* @return object - id
|
||||
* @param userAddress
|
||||
* @param expressOrder
|
||||
* @throws Exception
|
||||
*/
|
||||
int insertNewExpressOrder(ExpressOrder expressOrder);
|
||||
|
||||
void placeExpressOrder(Integer userAddressId, ExpressOrder expressOrder);
|
||||
|
||||
// void printDeliveryBill();
|
||||
//
|
||||
// void expressRealTimeQuery();
|
||||
void placeExpressOrder(UserAddress userAddress, ExpressOrder expressOrder) throws Exception;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -31,14 +31,6 @@ public class BuyOrderDetailServiceImpl extends ServiceImpl<BuyOrderDetailDao, Bu
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 去重查询未打印的面单信息
|
||||
* @param params
|
||||
@@ -70,7 +62,7 @@ public class BuyOrderDetailServiceImpl extends ServiceImpl<BuyOrderDetailDao, Bu
|
||||
|
||||
@Override
|
||||
public void batchUpdateByShippingSns(String[] shippingSnList) {
|
||||
List<BuyOrderDetailEntity> buyOrderDetailEntityList = this.list(new QueryWrapper<BuyOrderDetailEntity>());
|
||||
List<BuyOrderDetailEntity> buyOrderDetailEntityList = this.list(new QueryWrapper<>());
|
||||
for(String sn : shippingSnList){
|
||||
for(BuyOrderDetailEntity buyOrderDetailEntity : buyOrderDetailEntityList){
|
||||
if(StringUtil.isNotEmpty(buyOrderDetailEntity.getShippingSn()) && buyOrderDetailEntity.getShippingSn().equals(sn)){
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.peanut.modules.book.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||
@@ -13,6 +12,7 @@ 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;
|
||||
import com.peanut.modules.book.vo.UserOrderVo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -55,7 +55,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) throws Exception {
|
||||
|
||||
IPage<BuyOrderEntity> page = null;
|
||||
IPage<BuyOrderEntity> page;
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String startTime = null;
|
||||
String endTime = null;
|
||||
@@ -248,9 +248,24 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createSplitPackageOrder(String expressCompanyCode, Integer userAddressId, List<Integer> shopProductIdList) {
|
||||
// 根据商品 id 获取总重量
|
||||
int totalWeight = shopProductDao.getTotalWeight(shopProductIdList);
|
||||
public void createSplitPackageOrder(String expressCompanyCode, Integer userAddressId, List<Integer> buyOrderDetailId) throws Exception {
|
||||
QueryWrapper<BuyOrderDetailEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("id", buyOrderDetailId);
|
||||
List<BuyOrderDetailEntity> buyOrderDetailList = buyOrderDetailService.list(queryWrapper);
|
||||
BigDecimal totalWeight = new BigDecimal(0);
|
||||
List<ExpressCommodity> commodityList = new ArrayList<>();
|
||||
for (BuyOrderDetailEntity buyOrderDetail : buyOrderDetailList) {
|
||||
ExpressCommodity commodity = new ExpressCommodity();
|
||||
commodity.setGoodsName(buyOrderDetail.getProductName());
|
||||
commodity.setGoodsquantity(buyOrderDetail.getQuantity());
|
||||
commodity.setGoodsWeight(buyOrderDetail.getWeight());
|
||||
totalWeight = totalWeight.add(
|
||||
BigDecimal.valueOf(buyOrderDetail.getWeight()).multiply(new BigDecimal(buyOrderDetail.getQuantity()))
|
||||
);
|
||||
commodityList.add(commodity);
|
||||
}
|
||||
|
||||
|
||||
// 获取用户地址
|
||||
UserAddress address = userAddressService.getById(userAddressId);
|
||||
// 计算快递费用
|
||||
@@ -259,9 +274,9 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
|
||||
expressOrder.setExpressFee(expressFee);
|
||||
expressOrder.setCreateTime(new Date());
|
||||
expressOrder.setTotalWeight(totalWeight);
|
||||
expressOrder.setCommodity(commodityList);
|
||||
// 生成快递面单
|
||||
|
||||
int expressOrderId = expressOrderService.insertNewExpressOrder(expressOrder);
|
||||
expressOrderService.placeExpressOrder(address, expressOrder);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -17,20 +17,14 @@ import java.math.RoundingMode;
|
||||
*/
|
||||
public class ExpressFeeServiceImpl extends ServiceImpl<ExpressFeeDao, ExpressFee> implements ExpressFeeService {
|
||||
@Override
|
||||
public BigDecimal calculateExpressFee(String expressCompanyCode, int weight, String regionCode) {
|
||||
int integerPart = weight / 100;
|
||||
int decimalPart = weight % 100;
|
||||
// 将重量转换为公斤
|
||||
BigDecimal realWeight = BigDecimal.valueOf(integerPart).add(BigDecimal.valueOf(decimalPart)
|
||||
.divide(new BigDecimal(100), MathContext.DECIMAL64));
|
||||
realWeight = realWeight.setScale(0, RoundingMode.UP);
|
||||
public BigDecimal calculateExpressFee(String expressCompanyCode, BigDecimal weight, String regionCode) {
|
||||
BigDecimal fee = null;
|
||||
switch (expressCompanyCode) {
|
||||
case "SF":
|
||||
fee = calculateSFExpressFee(realWeight, regionCode);
|
||||
fee = calculateSFExpressFee(weight, regionCode);
|
||||
break;
|
||||
case "YD":
|
||||
fee = calculateYDExpressFee(realWeight, regionCode);
|
||||
fee = calculateYDExpressFee(weight, regionCode);
|
||||
break;
|
||||
}
|
||||
return fee;
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
package com.peanut.modules.book.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.common.utils.HttpClientUtils;
|
||||
import com.peanut.common.utils.KdUtils;
|
||||
import com.peanut.config.Constants;
|
||||
import com.peanut.modules.book.dao.ExpressOrderDao;
|
||||
import com.peanut.modules.book.entity.*;
|
||||
import com.peanut.modules.book.service.*;
|
||||
import com.peanut.modules.book.vo.ExpressCommodityVo;
|
||||
import com.peanut.modules.book.vo.ExpressOrderRequestVo;
|
||||
import com.peanut.modules.book.vo.ExpressUserInfoVo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 快递订单 Service 实现
|
||||
@@ -36,12 +39,6 @@ public class ExpressOrderServiceImpl extends ServiceImpl<ExpressOrderDao, Expres
|
||||
@Value("${express.sender.address}")
|
||||
private String senderAddress;
|
||||
|
||||
@Autowired
|
||||
private ExpressOrderDao expressOrderDao;
|
||||
|
||||
@Autowired
|
||||
private UserAddressService userAddressService;
|
||||
|
||||
@Autowired
|
||||
private CountyService countyService;
|
||||
|
||||
@@ -51,45 +48,47 @@ public class ExpressOrderServiceImpl extends ServiceImpl<ExpressOrderDao, Expres
|
||||
@Autowired
|
||||
private ProvinceService provinceService;
|
||||
|
||||
@Override
|
||||
public int insertNewExpressOrder(ExpressOrder expressOrder) {
|
||||
expressOrderDao.insertNewExpressOrder(expressOrder);
|
||||
return expressOrder.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeExpressOrder(Integer userAddressId, ExpressOrder expressOrder) {
|
||||
public void placeExpressOrder(UserAddress userAddress, ExpressOrder expressOrder) throws Exception {
|
||||
ExpressOrderRequestVo orderRequestVo = new ExpressOrderRequestVo();
|
||||
// 订单号
|
||||
orderRequestVo.setOrderCode(expressOrder.getOrderId());
|
||||
orderRequestVo.setShipperCode(expressOrder.getExpressCompanyCode());
|
||||
orderRequestVo.setPayType(3);
|
||||
orderRequestVo.setExpType(1);
|
||||
orderRequestVo.setCost(expressOrder.getExpressFee().doubleValue());
|
||||
// 发货人
|
||||
ExpressUserInfoVo sender = new ExpressUserInfoVo();
|
||||
sender.setName(senderName);
|
||||
sender.setCompany(senderName);
|
||||
sender.setMobile(senderMobile);
|
||||
sender.setProvinceName(senderProvinceName);
|
||||
sender.setCityName(senderCityName);
|
||||
sender.setExpAreaName(senderExpAreaName);
|
||||
sender.setAddress(senderAddress);
|
||||
// 收货人
|
||||
UserAddress userAddress = userAddressService.getById(userAddressId);
|
||||
ExpressUserInfoVo receiver = buildReceiverBasedOnUserAddress(userAddress);
|
||||
orderRequestVo.setSender(sender);
|
||||
orderRequestVo.setReceiver(receiver);
|
||||
ExpressCommodityVo commodityVo = new ExpressCommodityVo();
|
||||
commodityVo.setGoodsName("书籍");
|
||||
List<ExpressCommodityVo> commodityVoList = new ArrayList<>();
|
||||
orderRequestVo.setCommodity(commodityVoList);
|
||||
//orderRequestVo.setWeight(expressOrder.getTotalWeight());
|
||||
orderRequestVo.setCommodity(expressOrder.getCommodity());
|
||||
orderRequestVo.setWeight(expressOrder.getTotalWeight().doubleValue());
|
||||
orderRequestVo.setRemark(expressOrder.getRemark());
|
||||
String RequestData = JSONObject.toJSONString(orderRequestVo);
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("RequestData", RequestData);
|
||||
params.put("EBusinessID", Constants.EXPRESS_BUSINESS_ID);
|
||||
params.put("RequestType", Constants.EXPRESS_REQUEST_TYPE_PLACE_ORDER);
|
||||
String dataSign = KdUtils.encrypt(RequestData, Constants.EXPRESS_API_KEY, "UTF-8");
|
||||
params.put("DataSign", KdUtils.urlEncoder(dataSign, "UTF-8"));
|
||||
params.put("DataType", "2");
|
||||
String response = HttpClientUtils.kdSendPost(Constants.EXPRESS_PLACE_ORDER_URL, params);
|
||||
System.out.println(response);
|
||||
}
|
||||
|
||||
private ExpressUserInfoVo buildReceiverBasedOnUserAddress(UserAddress userAddress) {
|
||||
ExpressUserInfoVo vo = new ExpressUserInfoVo();
|
||||
vo.setName(userAddress.getConsigneeName());
|
||||
vo.setCompany(userAddress.getConsigneeName());
|
||||
vo.setMobile(userAddress.getConsigneePhone());
|
||||
vo.setAddress(userAddress.getDetailAddress());
|
||||
String regionCode = userAddress.getRegionCode();
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.peanut.modules.book.vo;
|
||||
|
||||
import com.peanut.modules.book.entity.ExpressCommodity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List ;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 快递请求 Value Object
|
||||
@@ -28,6 +29,18 @@ public class ExpressOrderRequestVo {
|
||||
* 快递公司业务类型
|
||||
*/
|
||||
private int ExpType;
|
||||
/**
|
||||
* 月付款账号
|
||||
*/
|
||||
private String MonthCode;
|
||||
/**
|
||||
* 快递运费
|
||||
*/
|
||||
private Double Cost;
|
||||
/**
|
||||
* 其他费用
|
||||
*/
|
||||
private Double OtherCost;
|
||||
/**
|
||||
* 发货人
|
||||
*/
|
||||
@@ -39,11 +52,19 @@ public class ExpressOrderRequestVo {
|
||||
/**
|
||||
* 货物信息
|
||||
*/
|
||||
private List<ExpressCommodityVo> Commodity;
|
||||
private List<ExpressCommodity> Commodity;
|
||||
/**
|
||||
* 重量
|
||||
*/
|
||||
private Double Weight;
|
||||
/**
|
||||
* 包裹数量
|
||||
*/
|
||||
private Integer Quantity;
|
||||
/**
|
||||
* 包裹体积
|
||||
*/
|
||||
private Double Volume;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
|
||||
@@ -12,7 +12,7 @@ public class ExpressUserInfoVo {
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
private String Name;
|
||||
private String Company;
|
||||
/**
|
||||
* 电话
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user