This commit is contained in:
Cauchy
2023-10-18 13:02:54 +08:00
parent 113243e918
commit 5dee4b619e
27 changed files with 386 additions and 216 deletions

View File

@@ -1,13 +1,9 @@
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.modules.book.entity.ActivityEntity;
import com.peanut.modules.book.entity.BuyOrderEntity;
import java.util.List;
import java.util.Map;
/**

View File

@@ -3,7 +3,7 @@ package com.peanut.modules.book.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.common.utils.PageUtils;
import com.peanut.modules.book.entity.BuyOrderEntity;
import com.peanut.modules.book.entity.BuyOrder;
import java.util.List;
import java.util.Map;
@@ -15,7 +15,7 @@ import java.util.Map;
* @email yl328572838@163.com
* @date 2022-08-29 15:27:44
*/
public interface BuyOrderService extends IService<BuyOrderEntity> {
public interface BuyOrderService extends IService<BuyOrder> {
PageUtils queryPage(Map<String, Object> params) throws Exception;
@@ -32,9 +32,7 @@ public interface BuyOrderService extends IService<BuyOrderEntity> {
* 订单拆分发货
*
* @param expressCompanyCode 快递公司代码
* @param userAddressId 用户地址 ID
* @param buyOrderDetailId 订单详情 ID 列表
* @throws Exception exception
*/
void createSplitPackageOrder(String expressCompanyCode, Integer userAddressId, List<Integer> buyOrderDetailId) throws Exception;
void createSplitPackageOrder(String expressCompanyCode, List<Integer> buyOrderDetailId);
}

View File

@@ -2,22 +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 com.peanut.modules.book.vo.ExpressQueryResponseVo;
import com.peanut.modules.book.vo.ExpressOrderResponseVo;
import com.peanut.modules.book.entity.ExpressQueryResponse;
import org.springframework.stereotype.Service;
import java.util.Map;
@Service
public interface ExpressOrderService extends IService<ExpressOrder> {
/**
* 下单生成面单
*
* @param userAddress
* @param expressOrder
* @throws Exception
*/
Map<String, String> placeExpressOrder(UserAddress userAddress, ExpressOrder expressOrder);
ExpressOrderResponseVo placeExpressOrder(ExpressOrder expressOrder);
ExpressQueryResponseVo queryExpressOrder(String ShipperCode, String LogisticCode);
ExpressQueryResponse queryExpressOrder(String ShipperCode, String LogisticCode);
}

View File

@@ -12,6 +12,7 @@ import com.peanut.modules.book.dao.BuyOrderDao;
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.ExpressOrderResponseVo;
import com.peanut.modules.book.vo.UserOrderVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -26,22 +27,22 @@ import java.util.stream.Collectors;
@Service("buyOrderService")
public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity> implements BuyOrderService {
public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> implements BuyOrderService {
@Autowired
private BuyOrderDetailService buyOrderDetailService;
@Autowired
private MyUserService myUserService;
@Autowired
private UserAddressService userAddressService;
@Autowired
private ExpressFeeService expressFeeService;
@Autowired
private ExpressOrderService expressOrderService;
@Autowired
CountyService countyService;
protected Logger logger = LoggerFactory.getLogger(BuyOrderServiceImpl.class);
@@ -51,7 +52,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
@Override
public PageUtils queryPage(Map<String, Object> params) throws Exception {
IPage<BuyOrderEntity> page;
IPage<BuyOrder> page;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String startTime = null;
String endTime = null;
@@ -61,8 +62,8 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
}
if (ObjectUtils.isEmpty(params.get("orderStatus"))) {
page = this.page(
new Query<BuyOrderEntity>().getPage(params),
new ExcludeEmptyQueryWrapper<BuyOrderEntity>().eq("user_phone", params.get("key")).
new Query<BuyOrder>().getPage(params),
new ExcludeEmptyQueryWrapper<BuyOrder>().eq("user_phone", params.get("key")).
or().like("order_sn", params.get("key")).or().like("shipping_user", params.get("key"))
.apply(startTime != null, "date_format (create_time,'%Y-%m-%d') >= date_format ({0},'%Y-%m-%d')", startTime)
.apply(endTime != null, "date_format (create_time,'%Y-%m-%d') <= date_format ({0},'%Y-%m-%d')", endTime).orderByDesc("create_time")
@@ -70,8 +71,8 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
);
} else {
page = this.page(
new Query<BuyOrderEntity>().getPage(params),
new ExcludeEmptyQueryWrapper<BuyOrderEntity>().eq("order_status", params.get("orderStatus")).eq("user_phone", params.get("key"))
new Query<BuyOrder>().getPage(params),
new ExcludeEmptyQueryWrapper<BuyOrder>().eq("order_status", params.get("orderStatus")).eq("user_phone", params.get("key"))
.or().like("order_sn", params.get("key")).or().like("shipping_user", params.get("key"))
.apply(startTime != null, "date_format (create_time,'%Y-%m-%d') >= date_format ({0},'%Y-%m-%d')", startTime)
.apply(endTime != null, "date_format (create_time,'%Y-%m-%d') <= date_format ({0},'%Y-%m-%d')", endTime).orderByDesc("create_time")
@@ -79,8 +80,8 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
}
List<BuyOrderEntity> records = page.getRecords();
for (BuyOrderEntity record : records) {
List<BuyOrder> records = page.getRecords();
for (BuyOrder record : records) {
Integer userId = record.getUserId();
MyUserEntity myUserEntity = myUserService.getById(userId);
if (!ObjectUtils.isEmpty(myUserEntity)) {
@@ -105,7 +106,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
// 交易成功 2
// 交易失败 9
BuyOrderEntity orderEntity = this.getOne(new QueryWrapper<BuyOrderEntity>().eq("user_id", userId)
BuyOrder orderEntity = this.getOne(new QueryWrapper<BuyOrder>().eq("user_id", userId)
.eq("order_sn", orderSn));
if (type.equals("0")) {
orderEntity.setOrderStatus("1");
@@ -130,18 +131,18 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
public List checkOrder(Integer[] orderIds) {
// 查询出所有的订单信息(携带订单商品)
List<BuyOrderEntity> orderList = new ArrayList<>();
List<BuyOrderEntity> buyOrderList = this.list(
new QueryWrapper<BuyOrderEntity>().eq("del_flag", "0").eq("order_status", "1")
List<BuyOrder> orderList = new ArrayList<>();
List<BuyOrder> buyOrderList = this.list(
new QueryWrapper<BuyOrder>().eq("del_flag", "0").eq("order_status", "1")
);
for (BuyOrderEntity order : buyOrderList) {
for (BuyOrder order : buyOrderList) {
order.setProducts(buyOrderDetailService.list(new QueryWrapper<BuyOrderDetail>()
.eq("order_id", order.getOrderId())));
orderList.add(order);
}
// 清洗数据 (与前端传来的id对比后)
List<BuyOrderEntity> washOrderList = new ArrayList<>();
for (BuyOrderEntity order : orderList) {
List<BuyOrder> washOrderList = new ArrayList<>();
for (BuyOrder order : orderList) {
for (int o : orderIds) {
if (o == order.getOrderId()) {
washOrderList.add(order);
@@ -151,7 +152,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
Map<Integer, Object> map = new HashMap<>();
// 使用清洗后的List获得其中有多少个用户
for (BuyOrderEntity o : washOrderList) {
for (BuyOrder o : washOrderList) {
map.put(o.getUserId(), o);
}
//获取map的所有key转为list
@@ -159,8 +160,8 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
List<UserOrderVo> userOrderVoList = new ArrayList<>();
for (int key : keys) {
UserOrderVo userOrderVo = new UserOrderVo();
List<BuyOrderEntity> orderEntityList = new ArrayList<>();
for (BuyOrderEntity o : buyOrderList) {
List<BuyOrder> orderEntityList = new ArrayList<>();
for (BuyOrder o : buyOrderList) {
if (o.getUserId().equals(key)) {
userOrderVo.setTel(o.getUserPhone());
userOrderVo.setUserName(o.getShippingUser());
@@ -195,16 +196,16 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
public Page checkOrder(Map<String, Object> params) {
// 查询所有订单信息
List<BuyOrderEntity> orderList = new ArrayList<>();
List<BuyOrder> orderList = new ArrayList<>();
List<UserOrderVo> userOrderVoList = new ArrayList<>();
// 返回的list
List<UserOrderVo> rntList = new ArrayList<>();
Page<UserOrderVo> rntPage = new Page<>();
IPage<BuyOrderEntity> buyOrderList = this.page(
new Query<BuyOrderEntity>().getPage(params),
new QueryWrapper<BuyOrderEntity>().eq("del_flag", "0").eq("order_status", "1").eq("is_send", "0")
IPage<BuyOrder> buyOrderList = this.page(
new Query<BuyOrder>().getPage(params),
new QueryWrapper<BuyOrder>().eq("del_flag", "0").eq("order_status", "1").eq("is_send", "0")
);
for (BuyOrderEntity order : buyOrderList.getRecords()) {
for (BuyOrder order : buyOrderList.getRecords()) {
order.setProducts(buyOrderDetailService.list(new QueryWrapper<BuyOrderDetail>()
.eq("order_id", order.getOrderId())));
orderList.add(order);
@@ -212,7 +213,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
// 获取有订单的所有用户
Map<Integer, Object> map = new HashMap<>();
for (BuyOrderEntity order : orderList) {
for (BuyOrder order : orderList) {
map.put(order.getUserId(), order);
}
//获取map的所有key转为list
@@ -220,8 +221,8 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
for (int key : keys) {
UserOrderVo userOrderVo = new UserOrderVo();
List<BuyOrderEntity> orderEntityList = new ArrayList<>();
for (BuyOrderEntity o : buyOrderList.getRecords()) {
List<BuyOrder> orderEntityList = new ArrayList<>();
for (BuyOrder o : buyOrderList.getRecords()) {
if (o.getUserId().equals(key)) {
userOrderVo.setUserName(o.getShippingUser());
userOrderVo.setTel(o.getUserPhone());
@@ -244,7 +245,7 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
}
@Override
public void createSplitPackageOrder(String expressCompanyCode, Integer userAddressId, List<Integer> buyOrderDetailId) {
public void createSplitPackageOrder(String expressCompanyCode, List<Integer> buyOrderDetailId) {
QueryWrapper<BuyOrderDetail> queryWrapper = new QueryWrapper<>();
queryWrapper.in("id", buyOrderDetailId);
List<BuyOrderDetail> buyOrderDetailList = buyOrderDetailService.list(queryWrapper);
@@ -262,9 +263,13 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
}
// 获取用户地址
UserAddress address = userAddressService.getById(userAddressId);
Integer orderId = buyOrderDetailList.get(0).getOrderId();
BuyOrder buyOrder = getById(orderId);
QueryWrapper<CountyEntity> countyQueryWrapper = new QueryWrapper<>();
countyQueryWrapper.eq("county_name", buyOrder.getDistrict());
CountyEntity county = countyService.getOne(countyQueryWrapper);
// 计算快递费用
BigDecimal expressFee = expressFeeService.calculateExpressFee(expressCompanyCode, totalWeight, address.getRegionCode());
BigDecimal expressFee = expressFeeService.calculateExpressFee(expressCompanyCode, totalWeight, county.getRegionCode());
ExpressOrder expressOrder = new ExpressOrder();
expressOrder.setOrderId(buyOrderDetailList.get(0).getOrderId());
expressOrder.setExpressFee(expressFee);
@@ -272,11 +277,20 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrderEntity
expressOrder.setTotalWeight(totalWeight);
expressOrder.setCommodity(commodityList);
expressOrder.setExpressCompanyCode(expressCompanyCode);
expressOrder.setName(buyOrder.getShippingUser());
expressOrder.setMobile(buyOrder.getUserPhone());
expressOrder.setProvince(buyOrder.getProvince());
expressOrder.setCity(buyOrder.getCity());
expressOrder.setCounty(buyOrder.getDistrict());
expressOrder.setAddress(buyOrder.getAddress());
// 生成快递面单
Map<String, String> result = expressOrderService.placeExpressOrder(address, expressOrder);
ExpressOrderResponseVo response = expressOrderService.placeExpressOrder(expressOrder);
String expressBillNo = response.getOrder().getLogisticCode();
String expressBillTemplate = response.getPrintTemplate();
for (BuyOrderDetail buyOrderDetail : buyOrderDetailList) {
buyOrderDetail.setExpressBill(result.get("expressBill"));
buyOrderDetail.setExpressBillNo(result.get("expressBillNo"));
buyOrderDetail.setExpressBillNo(expressBillNo);
buyOrderDetail.setExpressBillTemplate(expressBillTemplate);
buyOrderDetail.setExpressCompanyCode(expressCompanyCode);
}
buyOrderDetailService.saveBatch(buyOrderDetailList);
}

View File

@@ -1,19 +1,15 @@
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.ExpressOrderRequestVo;
import com.peanut.modules.book.vo.ExpressOrderResponseVo;
import com.peanut.modules.book.vo.ExpressQueryResponseVo;
import com.peanut.modules.book.vo.ExpressUserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import com.peanut.modules.book.entity.ExpressOrder;
import com.peanut.modules.book.entity.ExpressQueryResponse;
import com.peanut.modules.book.service.ExpressOrderService;
import com.peanut.modules.book.vo.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@@ -41,18 +37,9 @@ public class ExpressOrderServiceImpl extends ServiceImpl<ExpressOrderDao, Expres
@Value("${express.sender.address}")
private String senderAddress;
@Autowired
private CountyService countyService;
@Autowired
private CityService cityService;
@Autowired
private ProvinceService provinceService;
@Override
public Map<String, String> placeExpressOrder(UserAddress userAddress, ExpressOrder expressOrder) {
public ExpressOrderResponseVo placeExpressOrder(ExpressOrder expressOrder) {
ExpressOrderRequestVo orderRequestVo = new ExpressOrderRequestVo();
// 订单号
orderRequestVo.setOrderCode(expressOrder.getOrderId().toString());
@@ -74,20 +61,25 @@ public class ExpressOrderServiceImpl extends ServiceImpl<ExpressOrderDao, Expres
sender.setExpAreaName(senderExpAreaName);
sender.setAddress(senderAddress);
// 收货人
ExpressUserInfoVo receiver = buildReceiverBasedOnUserAddress(userAddress);
ExpressUserInfoVo receiver = new ExpressUserInfoVo();
receiver.setName(expressOrder.getName());
receiver.setMobile(expressOrder.getMobile());
receiver.setProvinceName(expressOrder.getProvince());
receiver.setCityName(expressOrder.getCity());
receiver.setAddress(expressOrder.getAddress());
orderRequestVo.setSender(sender);
orderRequestVo.setReceiver(receiver);
orderRequestVo.setCommodity(expressOrder.getCommodity());
orderRequestVo.setWeight(expressOrder.getTotalWeight().doubleValue());
orderRequestVo.setRemark(expressOrder.getRemark());
String RequestData = JSONObject.toJSONString(orderRequestVo);
String requestData = JSONObject.toJSONString(orderRequestVo);
Map<String, String> params = new HashMap<>();
params.put("RequestData", RequestData);
params.put("RequestData", requestData);
params.put("EBusinessID", Constants.EXPRESS_BUSINESS_ID);
params.put("RequestType", Constants.EXPRESS_REQUEST_TYPE_PLACE_ORDER);
try {
String dataSign = KdUtils.encrypt(RequestData, Constants.EXPRESS_API_KEY, "UTF-8");
String dataSign = KdUtils.encrypt(requestData, Constants.EXPRESS_API_KEY, "UTF-8");
params.put("DataSign", KdUtils.urlEncoder(dataSign, "UTF-8"));
} catch (Exception e) {
e.printStackTrace();
@@ -96,44 +88,29 @@ public class ExpressOrderServiceImpl extends ServiceImpl<ExpressOrderDao, Expres
params.put("DataType", "2");
String response = HttpClientUtils.kdSendPost(Constants.EXPRESS_PLACE_ORDER_URL, params);
ExpressOrderResponseVo responseVo = JSONObject.parseObject(response, ExpressOrderResponseVo.class);
String expressBillNo = responseVo.getOrder().getLogisticCode();
Map<String, String> result = new HashMap<>();
result.put("expressBillNo", expressBillNo);
result.put("template", responseVo.getPrintTemplate());
return result;
return responseVo;
}
@Override
public ExpressQueryResponseVo queryExpressOrder(String ShipperCode, String LogisticCode) {
return null;
}
private ExpressUserInfoVo buildReceiverBasedOnUserAddress(UserAddress userAddress) {
ExpressUserInfoVo vo = new ExpressUserInfoVo();
vo.setName(userAddress.getConsigneeName());
vo.setMobile(userAddress.getConsigneePhone());
vo.setAddress(userAddress.getDetailAddress());
String regionCode = userAddress.getRegionCode();
QueryWrapper<CountyEntity> countyQueryWrapper = new QueryWrapper<>();
countyQueryWrapper.eq("region_code", regionCode);
CountyEntity county = countyService.getOne(countyQueryWrapper);
vo.setExpAreaName(county.getCountyName());
String cityRegionCode;
if (regionCode.startsWith("11") || regionCode.startsWith("12") || regionCode.startsWith("31") || regionCode.startsWith("50")) {
cityRegionCode = regionCode.substring(0, 2).concat("0000");
} else {
cityRegionCode = regionCode.substring(0, 4).concat("00");
public ExpressQueryResponse queryExpressOrder(String shipperCode, String logisticCode) {
ExpressQueryRequestVo requestVo = new ExpressQueryRequestVo();
requestVo.setLogisticCode(logisticCode);
requestVo.setShipperCode(shipperCode);
String requestData = JSONObject.toJSONString(requestVo);
Map<String, String> params = new HashMap<>();
params.put("RequestData", requestData);
params.put("EBusinessID", Constants.EXPRESS_BUSINESS_ID);
params.put("RequestType", Constants.EXPRESS_REQUEST_TYPE_QUERY);
try {
String dataSign = KdUtils.encrypt(requestData, Constants.EXPRESS_API_KEY, "UTF-8");
params.put("DataSign", KdUtils.urlEncoder(dataSign, "UTF-8"));
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage());
}
QueryWrapper<CityEntity> cityQueryWrapper = new QueryWrapper<>();
cityQueryWrapper.eq("region_code", cityRegionCode);
CityEntity city = cityService.getOne(cityQueryWrapper);
vo.setCityName(city.getCityName());
String provinceRegionCode = regionCode.substring(0, 2).concat("0000");
QueryWrapper<ProvinceEntity> provinceQueryWrapper = new QueryWrapper<>();
provinceQueryWrapper.eq("region_code", provinceRegionCode);
ProvinceEntity province = provinceService.getOne(provinceQueryWrapper);
vo.setProvinceName(province.getProvName());
return vo;
params.put("DateType", "2");
String response = HttpClientUtils.kdSendPost(Constants.EXPRESS_QUERY_URL, params);
return JSONObject.parseObject(response, ExpressQueryResponse.class);
}
}

View File

@@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.Query;
import com.peanut.modules.book.dao.PayWechatOrderDao;
import com.peanut.modules.book.entity.BuyOrderEntity;
import com.peanut.modules.book.entity.BuyOrder;
import com.peanut.modules.book.entity.PayWechatOrderEntity;
import com.peanut.modules.book.service.BuyOrderService;
import com.peanut.modules.book.service.PayWechatOrderService;
@@ -35,9 +35,9 @@ public class PayWechatOrderServiceImpl extends ServiceImpl<PayWechatOrderDao, Pa
@Override
public void add(String orderSn, String prepayId) {
QueryWrapper<BuyOrderEntity> wrapper = new QueryWrapper<>();
QueryWrapper<BuyOrder> wrapper = new QueryWrapper<>();
wrapper.eq("order_sn", orderSn);
BuyOrderEntity buyOrder = buyOrderService.getOne(wrapper);
BuyOrder buyOrder = buyOrderService.getOne(wrapper);
PayWechatOrderEntity entity = new PayWechatOrderEntity();
entity.setCustomerId(buyOrder.getUserId());
entity.setCreateTime(new Date());