批量生成子单功能以及维护客户的code码
parent
6247b1eba6
commit
11f69ca5f0
|
|
@ -31,6 +31,10 @@ public class BizCustomer
|
|||
@Excel(name = "客户全称")
|
||||
private String fullName;
|
||||
|
||||
/** 客户代码(对接邮政系统) */
|
||||
@Excel(name = "客户代码(对接邮政系统)")
|
||||
private String code;
|
||||
|
||||
/** 联系人 */
|
||||
@Excel(name = "联系人")
|
||||
private String linkman;
|
||||
|
|
|
|||
|
|
@ -6,11 +6,12 @@ import cn.hutool.http.HttpRequest;
|
|||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.cpxt.biz.domain.BizCustomer;
|
||||
import com.cpxt.biz.domain.BizOrder;
|
||||
import com.cpxt.biz.domain.BizOrderSub;
|
||||
import com.cpxt.biz.domain.SysArea;
|
||||
import com.cpxt.biz.mapper.BizCustomerMapper;
|
||||
import com.cpxt.biz.mapper.SysAreaMapper;
|
||||
import com.cpxt.common.annotation.Anonymous;
|
||||
import com.cpxt.common.utils.DateUtils;
|
||||
import com.cpxt.common.utils.Helper;
|
||||
import com.cpxt.system.mapper.SysDictDataMapper;
|
||||
|
|
@ -18,9 +19,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
|
|
@ -46,6 +44,9 @@ public class CityDelivery {
|
|||
@Autowired
|
||||
private SysAreaMapper sysAreaMapper;
|
||||
|
||||
@Autowired
|
||||
private BizCustomerMapper bizCustomerMapper;
|
||||
|
||||
// test
|
||||
String clientKey = "7480617400984563";//accessKey
|
||||
String clientSecret = "91wCEvn82CeyMg3k";
|
||||
|
|
@ -152,6 +153,9 @@ public class CityDelivery {
|
|||
* 同城急送平台工具,post接口
|
||||
*/
|
||||
public String addOrder(BizOrder bizOrder,BizOrderSub bizOrderSub) {
|
||||
BizCustomer bizCustomer = bizCustomerMapper.selectByName(bizOrder.getCustomerName());
|
||||
String code = bizCustomer.getCode();
|
||||
|
||||
String url = "https://wyjcs.gdwyj.cn/szelec/city-delivery-api/api/base/order/add";
|
||||
String goodsType = bizOrderSub.getGoodsType();
|
||||
String goodsTypeLabel = sysDictDataMapper.selectDictLabel("sys_goods_type", goodsType);
|
||||
|
|
@ -279,7 +283,7 @@ public class CityDelivery {
|
|||
Map<String, Object> sortedMap = new TreeMap<>();
|
||||
//下单接口
|
||||
String body = "{\n" +
|
||||
" \"customerCode\": \"HFCP\",\n" +
|
||||
" \"customerCode\": \"" + code + "\",\n" +
|
||||
" \"payTypeFirst\": \"" + payType + "\",\n" +
|
||||
" \"channelOrderNo\": \"" + subOrderSn + "\",\n" +
|
||||
" \"platformOrderNo\": \"\",\n" +
|
||||
|
|
|
|||
|
|
@ -361,61 +361,99 @@ public class BizOrderServiceImpl implements IBizOrderService {
|
|||
@Override
|
||||
@Transactional
|
||||
public void insertBizOrderSub(Map map) {
|
||||
String orderSn = (String) map.get("orderSn");
|
||||
String orderSn = (String) map.get("orderSn"); // 订单号
|
||||
Integer orderFee; // 订单总价
|
||||
Integer totalQuantity = (Integer) map.get("totalQuantity"); // 运单总件数
|
||||
if (ObjectUtil.isEmpty(map.get("orderFee"))) orderFee = 0;
|
||||
else orderFee = (Integer) map.get("orderFee");
|
||||
List<Map> subList = (List<Map>) map.get("sublist");
|
||||
for (Map map1 : subList) {
|
||||
if (map1.get("orderSn").equals(orderSn)){
|
||||
BizOrderSub bizOrderSub = new BizOrderSub();
|
||||
bizOrderSub.setOrderSn(orderSn);
|
||||
bizOrderSub.setSubOrderSn((String) map1.get("subOrderSn"));
|
||||
if (ObjectUtil.isNotEmpty(map1.get("weight"))) bizOrderSub.setWeight(BigDecimal.valueOf(Helper.FDouble( map1.get("weight"))));
|
||||
if (ObjectUtil.isNotEmpty(map1.get("length"))) bizOrderSub.setLength(BigDecimal.valueOf(Helper.FDouble( map1.get("length"))));
|
||||
if (ObjectUtil.isNotEmpty(map1.get("width"))) bizOrderSub.setWidth(BigDecimal.valueOf(Helper.FDouble( map1.get("width"))));
|
||||
if (ObjectUtil.isNotEmpty(map1.get("height"))) bizOrderSub.setHeight(BigDecimal.valueOf(Helper.FDouble( map1.get("height"))));
|
||||
if (ObjectUtil.isNotEmpty(map1.get("length")) && ObjectUtil.isNotEmpty(map1.get("width")) && ObjectUtil.isNotEmpty(map1.get("height"))){
|
||||
bizOrderSub.setVolume(BigDecimal.valueOf(Helper.FDouble( map1.get("length"))).multiply(BigDecimal.valueOf(Helper.FDouble( map1.get("width")))).multiply(BigDecimal.valueOf(Helper.FDouble( map1.get("height")))));
|
||||
}
|
||||
bizOrderSub.setGoodsType((String) map1.get("goodsType"));
|
||||
bizOrderSub.setGoodsName((String) map1.get("goodsName"));
|
||||
if (ObjectUtil.isNotEmpty(map1.get("orderFee"))) bizOrderSub.setOrderFee(BigDecimal.valueOf(Helper.FDouble( map1.get("orderFee"))));
|
||||
bizOrderSub.setRemark((String) map1.get("remark"));
|
||||
bizOrderSubMapper.insert(bizOrderSub);
|
||||
// 同步更新订单表的运单状态
|
||||
BizOrder bizOrder = bizOrderMapper.selectByOrderSn(orderSn);
|
||||
bizOrder.setSubStatus(1);
|
||||
bizOrderMapper.updateById(bizOrder);
|
||||
|
||||
// 同步更新订单表的运单状态、订单费用、运单总件数
|
||||
BizOrder bizOrder = bizOrderMapper.selectByOrderSn(orderSn);
|
||||
bizOrder.setSubStatus(1);
|
||||
bizOrder.setOrderFee(BigDecimal.valueOf(Helper.FDouble(orderFee)));
|
||||
bizOrder.setTotalQuantity(totalQuantity);
|
||||
bizOrderMapper.updateById(bizOrder);
|
||||
|
||||
// 同步调用同城急送平台入口
|
||||
String response = cityDelivery.addOrder(bizOrder, bizOrderSub);
|
||||
JSONObject jsonObject = JSON.parseObject(response);
|
||||
if (jsonObject.get("code").equals("200")){
|
||||
// 同步更新运单信息
|
||||
BizOrderSub orderSub = bizOrderSubMapper.selectBySubOrderSn((String) map1.get("subOrderSn"));
|
||||
Map<String,Object> result = (Map<String, Object>) jsonObject.get("result");
|
||||
// 预计送达时间(时间戳)
|
||||
Long expectTime = (Long) result.get("expectTime");
|
||||
// 配送距离
|
||||
Long distance = (Long) result.get("distance");
|
||||
String costFee = (String) result.get("costFee");
|
||||
String tipFee = (String) result.get("tipFee");
|
||||
String insuredFee = (String) result.get("insuredFee");
|
||||
String otherFee1 = (String) result.get("otherFee1");
|
||||
String otherFee2 = (String) result.get("otherFee2");
|
||||
String totalFee = (String) result.get("totalFee");
|
||||
String postageFee = (String) result.get("postageFee");
|
||||
orderSub.setExpectTime(new Date(expectTime));
|
||||
orderSub.setDistance(String.valueOf(distance));
|
||||
orderSub.setCostFee(costFee);
|
||||
orderSub.setTipFee(tipFee);
|
||||
orderSub.setInsuredFee(insuredFee);
|
||||
orderSub.setOtherFee1(otherFee1);
|
||||
orderSub.setOtherFee2(otherFee2);
|
||||
orderSub.setTotalFee(totalFee);
|
||||
orderSub.setPostageFee(postageFee);
|
||||
bizOrderSubMapper.updateById(orderSub);
|
||||
// 判断是否是批量生成
|
||||
Boolean showlist = (Boolean) map.get("showlist");
|
||||
if (!showlist){ // 批量生成
|
||||
if (totalQuantity != 0){
|
||||
for (int i = 1; i <= totalQuantity; i++) {
|
||||
BizOrderSub bizOrderSub = new BizOrderSub();
|
||||
bizOrderSub.setOrderSn(orderSn);
|
||||
bizOrderSub.setSubOrderSn(orderSn + "-" + i);
|
||||
if (ObjectUtil.isNotEmpty(subList.get(0).get("weight"))) bizOrderSub.setWeight(BigDecimal.valueOf(Helper.FDouble( subList.get(0).get("weight"))));
|
||||
if (ObjectUtil.isNotEmpty(subList.get(0).get("length"))) bizOrderSub.setLength(BigDecimal.valueOf(Helper.FDouble( subList.get(0).get("length"))));
|
||||
if (ObjectUtil.isNotEmpty(subList.get(0).get("width"))) bizOrderSub.setWidth(BigDecimal.valueOf(Helper.FDouble( subList.get(0).get("width"))));
|
||||
if (ObjectUtil.isNotEmpty(subList.get(0).get("height"))) bizOrderSub.setHeight(BigDecimal.valueOf(Helper.FDouble( subList.get(0).get("height"))));
|
||||
if (ObjectUtil.isNotEmpty(subList.get(0).get("length")) && ObjectUtil.isNotEmpty(subList.get(0).get("width")) && ObjectUtil.isNotEmpty(subList.get(0).get("height"))){
|
||||
bizOrderSub.setVolume(BigDecimal.valueOf(Helper.FDouble( subList.get(0).get("length"))).multiply(BigDecimal.valueOf(Helper.FDouble( subList.get(0).get("width")))).multiply(BigDecimal.valueOf(Helper.FDouble( subList.get(0).get("height")))));
|
||||
}
|
||||
bizOrderSub.setGoodsType((String) subList.get(0).get("goodsType"));
|
||||
bizOrderSub.setGoodsName((String) subList.get(0).get("goodsName"));
|
||||
if (ObjectUtil.isNotEmpty(subList.get(0).get("orderFee"))) bizOrderSub.setOrderFee(BigDecimal.valueOf(Helper.FDouble( subList.get(0).get("orderFee"))));
|
||||
bizOrderSub.setRemark((String) subList.get(0).get("remark"));
|
||||
bizOrderSubMapper.insert(bizOrderSub);
|
||||
|
||||
// 同步调用同城急送平台入口
|
||||
// callThirdPartyInterface(bizOrder, subList.get(0), bizOrderSub);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
for (Map map1 : subList) {
|
||||
if (map1.get("orderSn").equals(orderSn)){
|
||||
BizOrderSub bizOrderSub = new BizOrderSub();
|
||||
bizOrderSub.setOrderSn(orderSn);
|
||||
bizOrderSub.setSubOrderSn((String) map1.get("subOrderSn"));
|
||||
if (ObjectUtil.isNotEmpty(map1.get("weight"))) bizOrderSub.setWeight(BigDecimal.valueOf(Helper.FDouble( map1.get("weight"))));
|
||||
if (ObjectUtil.isNotEmpty(map1.get("length"))) bizOrderSub.setLength(BigDecimal.valueOf(Helper.FDouble( map1.get("length"))));
|
||||
if (ObjectUtil.isNotEmpty(map1.get("width"))) bizOrderSub.setWidth(BigDecimal.valueOf(Helper.FDouble( map1.get("width"))));
|
||||
if (ObjectUtil.isNotEmpty(map1.get("height"))) bizOrderSub.setHeight(BigDecimal.valueOf(Helper.FDouble( map1.get("height"))));
|
||||
if (ObjectUtil.isNotEmpty(map1.get("length")) && ObjectUtil.isNotEmpty(map1.get("width")) && ObjectUtil.isNotEmpty(map1.get("height"))){
|
||||
bizOrderSub.setVolume(BigDecimal.valueOf(Helper.FDouble( map1.get("length"))).multiply(BigDecimal.valueOf(Helper.FDouble( map1.get("width")))).multiply(BigDecimal.valueOf(Helper.FDouble( map1.get("height")))));
|
||||
}
|
||||
bizOrderSub.setGoodsType((String) map1.get("goodsType"));
|
||||
bizOrderSub.setGoodsName((String) map1.get("goodsName"));
|
||||
if (ObjectUtil.isNotEmpty(map1.get("orderFee"))) bizOrderSub.setOrderFee(BigDecimal.valueOf(Helper.FDouble( map1.get("orderFee"))));
|
||||
bizOrderSub.setRemark((String) map1.get("remark"));
|
||||
bizOrderSubMapper.insert(bizOrderSub);
|
||||
|
||||
// 同步调用同城急送平台入口
|
||||
// callThirdPartyInterface(bizOrder, map1, bizOrderSub);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void callThirdPartyInterface(BizOrder bizOrder, Map map1, BizOrderSub bizOrderSub) {
|
||||
String response = cityDelivery.addOrder(bizOrder, bizOrderSub);
|
||||
JSONObject jsonObject = JSON.parseObject(response);
|
||||
if (jsonObject.get("code").equals("200")) {
|
||||
// 同步更新运单信息
|
||||
BizOrderSub orderSub = bizOrderSubMapper.selectBySubOrderSn((String) map1.get("subOrderSn"));
|
||||
Map<String, Object> result = (Map<String, Object>) jsonObject.get("result");
|
||||
// 预计送达时间(时间戳)
|
||||
Long expectTime = (Long) result.get("expectTime");
|
||||
// 配送距离
|
||||
Long distance = (Long) result.get("distance");
|
||||
String costFee = (String) result.get("costFee");
|
||||
String tipFee = (String) result.get("tipFee");
|
||||
String insuredFee = (String) result.get("insuredFee");
|
||||
String otherFee1 = (String) result.get("otherFee1");
|
||||
String otherFee2 = (String) result.get("otherFee2");
|
||||
String totalFee = (String) result.get("totalFee");
|
||||
String postageFee = (String) result.get("postageFee");
|
||||
orderSub.setExpectTime(new Date(expectTime));
|
||||
orderSub.setDistance(String.valueOf(distance));
|
||||
orderSub.setCostFee(costFee);
|
||||
orderSub.setTipFee(tipFee);
|
||||
orderSub.setInsuredFee(insuredFee);
|
||||
orderSub.setOtherFee1(otherFee1);
|
||||
orderSub.setOtherFee2(otherFee2);
|
||||
orderSub.setTotalFee(totalFee);
|
||||
orderSub.setPostageFee(postageFee);
|
||||
bizOrderSubMapper.updateById(orderSub);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue