express refactor
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package com.peanut.modules.book.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.peanut.modules.book.entity.ExpressOrder;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface ExpressOrderDao extends BaseMapper<ExpressOrder> {
|
||||
int insertNewExpressOrder(ExpressOrder expressOrder);
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public class ExpressOrder {
|
||||
/**
|
||||
* 总重量
|
||||
*/
|
||||
private BigDecimal totalWeight;
|
||||
private int totalWeight;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
|
||||
@@ -167,4 +167,6 @@ public class ShopProductEntity implements Serializable {
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<String> shoproudLabels;
|
||||
|
||||
private int expressOrderId;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package com.peanut.modules.book.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.book.entity.BuyOrderEntity;
|
||||
|
||||
import java.util.List;
|
||||
@@ -24,9 +22,6 @@ public interface BuyOrderService extends IService<BuyOrderEntity> {
|
||||
//更新订单状态
|
||||
void updateOrderStatus(Integer userId, String orderSn, String type);
|
||||
|
||||
// 及时查询
|
||||
JSONObject queryFMS(String shipperCode, String expNo);
|
||||
|
||||
// 查询勾选的订单是否有可合并
|
||||
List checkOrder(Integer[] orderIds);
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.peanut.modules.book.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.modules.book.entity.ExpressOrder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public interface ExpressOrderService extends IService<ExpressOrder> {
|
||||
/**
|
||||
* 新增快递订单信息
|
||||
*
|
||||
* @param expressOrder 快递订单
|
||||
* @return object - id
|
||||
*/
|
||||
int insertNewExpressOrder(ExpressOrder expressOrder);
|
||||
|
||||
|
||||
}
|
||||
@@ -1,23 +1,18 @@
|
||||
package com.peanut.modules.book.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
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.IdWorker;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.common.Interface.KdApiEOrder;
|
||||
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.BuyOrderDetailDao;
|
||||
import com.peanut.modules.book.dao.ShopProductDao;
|
||||
import com.peanut.modules.book.entity.*;
|
||||
import com.peanut.modules.book.service.*;
|
||||
import com.peanut.modules.book.vo.ProductVo;
|
||||
import com.peanut.modules.book.vo.UserOrderVo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -25,7 +20,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
@@ -38,15 +32,8 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
|
||||
@Autowired
|
||||
private BuyOrderDetailService buyOrderDetailService;
|
||||
@Autowired
|
||||
private ShopProductService shopProductService;
|
||||
@Autowired
|
||||
private MyUserService myUserService;
|
||||
|
||||
@Resource
|
||||
private BuyOrderDao buyOrderDao;
|
||||
@Resource
|
||||
private BuyOrderDetailDao buyOrderDetailDao;
|
||||
|
||||
@Autowired
|
||||
private ShopProductDao shopProductDao;
|
||||
|
||||
@@ -56,9 +43,15 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
|
||||
@Autowired
|
||||
private ExpressFeeService expressFeeService;
|
||||
|
||||
@Autowired
|
||||
private ExpressOrderService expressOrderService;
|
||||
|
||||
|
||||
protected Logger logger = LoggerFactory.getLogger(BuyOrderServiceImpl.class);
|
||||
|
||||
public BuyOrderServiceImpl() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) throws Exception {
|
||||
|
||||
@@ -130,45 +123,6 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
|
||||
updateById(orderEntity);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 及时查询快递信息
|
||||
*
|
||||
* @param shipperCode 快递公司编码
|
||||
* @param expNo 快递单号
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public JSONObject queryFMS(String shipperCode, String expNo) {
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("ShipperCode", shipperCode);
|
||||
param.put("LogisticCode", expNo);
|
||||
try {
|
||||
if (!expNo.equals(1)) {
|
||||
String rntStr = KdApiEOrder.queryOrderOnlineByJson(param);
|
||||
JSONObject jsonObject = JSONObject.parseObject(rntStr);
|
||||
if ("true".equals(jsonObject.getString("Success"))) {
|
||||
return jsonObject;
|
||||
}
|
||||
} else {
|
||||
String rntStr = KdApiEOrder.queryOrderOnlineByJson(param);
|
||||
JSONObject jsonObject = JSONObject.parseObject(rntStr);
|
||||
if ("true".equals(jsonObject.getString("Success"))) {
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
||||
|
||||
String rntStr = KdApiEOrder.queryOrderOnlineByJson(param);
|
||||
JSONObject jsonObject = JSONObject.parseObject(rntStr);
|
||||
if ("true".equals(jsonObject.getString("Success"))) {
|
||||
return jsonObject;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询勾选的订单是否有可合并
|
||||
*
|
||||
@@ -301,136 +255,14 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
|
||||
UserAddress address = userAddressService.getById(userAddressId);
|
||||
// 计算快递费用
|
||||
BigDecimal expressFee = expressFeeService.calculateExpressFee(expressCompanyCode, totalWeight, address.getRegionCode());
|
||||
// 打印面单
|
||||
ExpressOrder expressOrder = new ExpressOrder();
|
||||
expressOrder.setExpressFee(expressFee);
|
||||
expressOrder.setCreateTime(new Date());
|
||||
expressOrder.setTotalWeight(totalWeight);
|
||||
// 生成快递面单
|
||||
|
||||
int expressOrderId = expressOrderService.insertNewExpressOrder(expressOrder);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static String getRandom(int len) {
|
||||
Random r = new Random();
|
||||
StringBuilder rs = new StringBuilder();
|
||||
for (int i = 0; i < len; i++) {
|
||||
rs.append(r.nextInt(10));
|
||||
}
|
||||
return rs.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 计算仪器,预售快递费用
|
||||
*
|
||||
* @param productList
|
||||
* @return
|
||||
*/
|
||||
public int getTransPrice(List<ProductVo> productList) {
|
||||
|
||||
// 首重
|
||||
int amount = 0;
|
||||
// 续重
|
||||
int continuousWeight = 0;
|
||||
// 费用
|
||||
int fare = 0;
|
||||
for (ProductVo p : productList) {
|
||||
String prov = p.getArea().substring(0, p.getArea().indexOf("_"));
|
||||
float weight = p.getNum() * p.getWeight();
|
||||
// 韵达计费规则
|
||||
if ("YD".equals(p.getKdCode())) {
|
||||
// 如果ID等于71 说明是天津发天津
|
||||
if ("71".equals(prov)) {
|
||||
amount = 6;
|
||||
continuousWeight = 3;
|
||||
}
|
||||
// 首重十元 续重四元
|
||||
String tenStr[] = {"70", "73", "75", "76", "77", "79", "81", "82", "83", "84", "85", "86", "87", "88", "91", "92", "96", "80", "78"};
|
||||
boolean tenBoolean = Arrays.asList(tenStr).contains(prov);
|
||||
if (tenBoolean) {
|
||||
amount = 10;
|
||||
continuousWeight = 4;
|
||||
}
|
||||
// 首重十二元
|
||||
String twelveStr[] = {"74", "89", "90", "93", "94", "97", "98", "99"};
|
||||
boolean twelveBoolean = Arrays.asList(twelveStr).contains(prov);
|
||||
if (twelveBoolean) {
|
||||
amount = 12;
|
||||
continuousWeight = 5;
|
||||
// 甘肃 97,青海 98,内蒙古 74 ,海南90 续重 6元
|
||||
if (prov.equals("97") || prov.equals("98") || prov.equals("74") || prov.equals("90")) {
|
||||
continuousWeight = 6;
|
||||
}
|
||||
}
|
||||
// 首重二十元,续重二十元
|
||||
if ("100".equals(prov)) {
|
||||
amount = 20;
|
||||
continuousWeight = 20;
|
||||
}
|
||||
|
||||
if (weight <= 1000) {
|
||||
fare += amount;
|
||||
} else {
|
||||
fare += (int) (amount + (continuousWeight * Math.floor(weight / 1000)));
|
||||
}
|
||||
}
|
||||
}
|
||||
return fare;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 计算快递费用
|
||||
*
|
||||
* @param param
|
||||
*/
|
||||
public int getTransPrice(Map<String, Object> param) {
|
||||
|
||||
int fare = 0;
|
||||
String KDCode = param.get("kdCode").toString();
|
||||
String area = param.get("area").toString();
|
||||
String prov = area.substring(0, area.indexOf("_"));
|
||||
float weight = (float) param.get("weight");
|
||||
// 韵达计费规则
|
||||
if ("YD".equals(KDCode)) {
|
||||
// 如果ID等于71 说明是天津发天津
|
||||
int amount = 0;
|
||||
int continuousWeight = 0;
|
||||
if ("71".equals(prov)) {
|
||||
amount = 6;
|
||||
continuousWeight = 3;
|
||||
}
|
||||
// 首重十元 续重四元
|
||||
String tenStr[] = {"70", "73", "75", "76", "77", "79", "81", "82", "83", "84", "85", "86", "87", "88", "91", "92", "96", "80", "78"};
|
||||
boolean tenBoolean = Arrays.asList(tenStr).contains(prov);
|
||||
if (tenBoolean) {
|
||||
amount = 10;
|
||||
continuousWeight = 4;
|
||||
}
|
||||
// 首重十二元
|
||||
String twelveStr[] = {"74", "89", "90", "93", "94", "97", "98", "99"};
|
||||
boolean twelveBoolean = Arrays.asList(twelveStr).contains(prov);
|
||||
if (twelveBoolean) {
|
||||
amount = 12;
|
||||
continuousWeight = 5;
|
||||
// 甘肃 97,青海 98,内蒙古 74 ,海南90 续重 6元
|
||||
if (prov.equals("97") || prov.equals("98") || prov.equals("74") || prov.equals("90")) {
|
||||
continuousWeight = 6;
|
||||
}
|
||||
}
|
||||
// 首重二十元,续重二十元
|
||||
if ("100".equals(prov)) {
|
||||
amount = 20;
|
||||
continuousWeight = 20;
|
||||
}
|
||||
// 如果重量等于0 说明是包邮
|
||||
if (weight == 0) {
|
||||
return 0;
|
||||
} else if (weight <= 1000) {
|
||||
return amount;
|
||||
} else {
|
||||
return (int) (amount + (continuousWeight * Math.floor(weight / 1000)));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.peanut.modules.book.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.modules.book.dao.ExpressOrderDao;
|
||||
import com.peanut.modules.book.entity.ExpressOrder;
|
||||
import com.peanut.modules.book.service.ExpressOrderService;
|
||||
import com.peanut.modules.book.vo.ExpressOrderRequestVo;
|
||||
import com.peanut.modules.book.vo.ExpressUserInfoVo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @Description: 快递订单 Service 实现
|
||||
* @Author: Cauchy
|
||||
* @CreateTime: 2023/10/16
|
||||
*/
|
||||
@Service
|
||||
public class ExpressOrderServiceImpl extends ServiceImpl<ExpressOrderDao, ExpressOrder> implements ExpressOrderService {
|
||||
@Autowired
|
||||
private ExpressOrderDao expressOrderDao;
|
||||
|
||||
@Override
|
||||
public int insertNewExpressOrder(ExpressOrder expressOrder) {
|
||||
expressOrderDao.insertNewExpressOrder(expressOrder);
|
||||
return expressOrder.getId();
|
||||
}
|
||||
|
||||
public void createExpressOrder() throws Exception {
|
||||
ExpressUserInfoVo receiver = new ExpressUserInfoVo();
|
||||
receiver.setName("张三");
|
||||
receiver.setMobile("12345678910");
|
||||
receiver.setPrintAddr("广东省深圳市南山区科技南十二路");
|
||||
|
||||
ExpressUserInfoVo sender = new ExpressUserInfoVo();
|
||||
sender.setName("李四");
|
||||
sender.setMobile("12345678910");
|
||||
sender.setPrintAddr("北京市海淀区xxx路");
|
||||
|
||||
ExpressOrderRequestVo request = new ExpressOrderRequestVo();
|
||||
request.setKuaidicom(CompanyConstant.ZJS);
|
||||
request.setCount(1);
|
||||
request.setSiid(siid);
|
||||
request.setTempId("60f6c17c7c223700131d8bc3");
|
||||
request.setSendMan(sender);
|
||||
request.setRecMan(receiver);
|
||||
request.setPrintType(PrintType.CLOUD);
|
||||
|
||||
String param = new Gson().toJson(request);
|
||||
String t = System.currentTimeMillis() + "";
|
||||
|
||||
PrintReq printReq = new PrintReq();
|
||||
printReq.setT(t);
|
||||
printReq.setKey(key);
|
||||
printReq.setSign(SignUtils.printSign(param, t, key, secret));
|
||||
printReq.setMethod(ApiInfoConstant.ORDER);
|
||||
printReq.setParam(param);
|
||||
|
||||
IBaseClient baseClient = new LabelV2();
|
||||
System.out.println(baseClient.execute(printReq));
|
||||
}
|
||||
|
||||
public void testPrintOld() throws Exception {
|
||||
RepeatPrintReq repeatPrintReq = new RepeatPrintReq();
|
||||
|
||||
repeatPrintReq.setTaskId("027B34AD22DE4F299643A13642B70D5F");
|
||||
|
||||
String param = new Gson().toJson(repeatPrintReq);
|
||||
String t = System.currentTimeMillis() + "";
|
||||
|
||||
PrintReq printReq = new PrintReq();
|
||||
printReq.setT(t);
|
||||
printReq.setKey(key);
|
||||
printReq.setSign(SignUtils.printSign(param, t, key, secret));
|
||||
printReq.setMethod(ApiInfoConstant.CLOUD_PRINT_OLD_METHOD);
|
||||
printReq.setParam(param);
|
||||
|
||||
IBaseClient baseClient = new LabelV2();
|
||||
System.out.println(baseClient.execute(printReq));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.peanut.modules.book.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Description: 货品 Value Object
|
||||
* @Author: Cauchy
|
||||
* @CreateTime: 2023/10/16
|
||||
*/
|
||||
@Data
|
||||
public class ExpressCommodityVo {
|
||||
private String GoodsName;
|
||||
private String GoodsCode;
|
||||
private int Goodsquantity;
|
||||
private double GoodsPrice;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.peanut.modules.book.vo;
|
||||
|
||||
import com.kuaidi100.sdk.contant.PrintType;
|
||||
import com.kuaidi100.sdk.request.ManInfo;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 快递请求 Value Object
|
||||
* @Author: Cauchy
|
||||
* @CreateTime: 2023/10/16
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class ExpressOrderRequestVo {
|
||||
/**
|
||||
* 订单号
|
||||
*/
|
||||
private String OrderCode;
|
||||
/**
|
||||
* 快递公司编码
|
||||
*/
|
||||
private String ShipperCode;
|
||||
/**
|
||||
* 支付类型 1 - 现付 2 - 到付 3 - 月结 4 - 第三方付
|
||||
*/
|
||||
private int payType;
|
||||
/**
|
||||
* 快递公司业务类型
|
||||
*/
|
||||
private int ExpType;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.peanut.modules.book.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Description: 快递收/发件人 Value Object
|
||||
* @Author: Cauchy
|
||||
* @CreateTime: 2023/10/16
|
||||
*/
|
||||
@Data
|
||||
public class ExpressUserInfoVo {
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
private String Name;
|
||||
/**
|
||||
* 电话
|
||||
*/
|
||||
private String Mobile;
|
||||
/**
|
||||
* 省份
|
||||
*/
|
||||
private String ProvinceName;
|
||||
/**
|
||||
* 城市
|
||||
*/
|
||||
private String cityName;
|
||||
/**
|
||||
* 区
|
||||
*/
|
||||
private String ExpAreaName;
|
||||
/**
|
||||
* 详细地址
|
||||
*/
|
||||
private String Address;
|
||||
}
|
||||
Reference in New Issue
Block a user