订单发货物流信息
public void orderDelivery(Integ]er adminId, Integer orderId, GoodsDeliveryParam deliveryParam, String ip) {
//校验订单是否存在
Example goodsOrderExample = new Example(GoodsOrder.class);
goodsOrderExample.createCriteria().andEqualTo("id", orderId)
.andEqualTo("orderStatus", GoodsOrderStatusEnum.waitDelivery.getCode()) // waitDelivery(0,"待发货"),
.andEqualTo("deleteFlag", DeleteFlagEnum.NotDeleted.getCode()); //未删除 条件
GoodsOrder goodsOrder = goodsOrderMapper.selectOneByExample(goodsOrderExample);
AssertUtil.notNull(goodsOrder, ExceptionEnum.GoodsOrderNoExists);
// GoodsOrderNoExists(3005, "订单不存在,请刷新重试!"),
GoodsDelivery goodsDelivery = getGoodsDelivery(orderId);
logsService.addLogs(adminId,ip,"处理"+goodsOrder.getOrderNo()+"订单发货");//日志
GoodsOrderDelivery goodsOrderDelivery = new GoodsOrderDelivery();
AssertUtil.notNull(goodsDelivery, ExceptionEnum.NeedSetExpress);
// NeedSetExpress(3012, "请先设置快递发货信息!"),
//更新发货信息(物流即时查询,订阅)
String expressCode = deliveryParam.getExpressCode();
String expressName = deliveryParam.getExpressName();
String expressNo = deliveryParam.getExpressNo();
goodsOrderDelivery.setExpressName(expressName);
goodsOrderDelivery.setExpressNo(expressNo);
goodsOrderDelivery.setExpressCode(expressCode);
String logisticsInfo = ExpressUtil.realtime(expressCode, expressNo);
Map
//物流状态
int status = 0;
Object statusObj = logisticsInfoMap.get("State");
if (statusObj != null) {
status = Integer.parseInt(String.valueOf(statusObj));
}
List
//物流轨迹
Object trace = logisticsInfoMap.get("Traces");
if (trace != null) {
System.out.println(trace);
System.out.println(JsonUtil.getInstance().toJsonString(trace));
List
data.forEach(obj -> {
ExpressDetailDto expressDetailDto = new ExpressDetailDto();
expressDetailDto.setMsg(obj.getAcceptStation());
expressDetailDto.setTime(obj.getAcceptTime());
expressDetailList.add(expressDetailDto);
});
}
ExpressDto expressDto = new ExpressDto();
expressDto.setTraces(expressDetailList);
expressDto.setStatus(status);
goodsOrderDelivery.setLogisticsInfo(JsonUtil.getInstance().toJsonString(expressDto));
goodsOrderDelivery.setDeliveryTime(new Date());
Example example = new Example(GoodsOrderDelivery.class);
example.createCriteria().andEqualTo("orderId", orderId)
.andEqualTo("deleteFlag", DeleteFlagEnum.NotDeleted.getCode());
goodsOrderDeliveryMapper.updateByExampleSelective(goodsOrderDelivery, example);
//更新订单状态为已发货
GoodsOrder order = new GoodsOrder();
order.setOrderStatus(GoodsOrderStatusEnum.waitReceipt.getCode());
Example orderExample = new Example(GoodsOrder.class);
orderExample.createCriteria().andEqualTo("orderStatus",GoodsOrderStatusEnum.waitDelivery.getCode())
.andEqualTo("deleteFlag", DeleteFlagEnum.NotDeleted.getCode());
goodsOrderMapper.updateByExampleSelective(order,orderExample);
***// waitReceipt(1,"待收货"),***
String consigneeAreas = goodsOrderDelivery.getAreas();
if (StringUtils.isNotBlank(consigneeAreas)) {
//收货区域信息 xx省xx市xx区
String[] area = consigneeAreas.split(",");
String deliveryInfo = goodsDelivery.getDeliveryInfo();
DeliveryExpressDto deliveryExpress =
JsonUtil.getInstance().toJsonObj(deliveryInfo, DeliveryExpressDto.class);
String[] mchArea = deliveryExpress.getArea().replaceAll(" ", "").split("/");
AdminUser adminUser = adminUserMapper.selectByPrimaryKey(adminId);
ExpressUtil.subscribe(
goodsOrderDelivery.getConsignee(),
goodsOrderDelivery.getPhone(),
area[0], area[1], area[2],
goodsOrderDelivery.getAddress(),
adminUser.getName(),
adminUser.getPhone(),
mchArea[0], mchArea[1], mchArea[2],
deliveryExpress.getAddress(), deliveryParam.getExpressCode(), deliveryParam.getExpressNo()
);
}
}
private GoodsDelivery getGoodsDelivery(Integer orderId) {
GoodsDelivery goodsDelivery = new GoodsDelivery();
goodsDelivery.setOrderId(orderId);
goodsDelivery.setDeleteFlag(DeleteFlagEnum.NotDeleted.getCode());
return goodsDeliveryMapper.selectOne(goodsDelivery);
}
/**
*实体类
* @author okayic
* @date 2019/7/21
*/
@Data
@ApiModel("物流轨迹信息")
public class ExpressDetailDto implements Serializable {
@ApiModelProperty("轨迹信息")
private String msg;
@ApiModelProperty("轨迹改变时间")
private String time;
}
``/**
* @author qcdl
* @date 2019/7/22
*/
@Data
public class LogisticsTraceBo implements Serializable {
@JsonProperty("AcceptStation")
private String acceptStation;
@JsonProperty("AcceptTime")
private String acceptTime;
}