|
|
|
@ -2,18 +2,12 @@ package com.logpm.factory.mt.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
|
import cn.hutool.http.HttpRequest; |
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.alibaba.nacos.shaded.com.google.gson.Gson; |
|
|
|
|
import com.alibaba.nacos.shaded.com.google.gson.GsonBuilder; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.logpm.factory.comfac.dto.OrderInfoDTO; |
|
|
|
|
import com.logpm.factory.comfac.dto.OrderStatusDTO; |
|
|
|
|
import com.logpm.factory.comfac.dto.ReceiveBodyDTO; |
|
|
|
|
import com.logpm.factory.comfac.dto.ReceiveInfoDTO; |
|
|
|
|
import com.logpm.factory.mt.dto.MtFactoryDataDTO; |
|
|
|
|
import com.logpm.factory.mt.dto.MtFactoryOrderDTO; |
|
|
|
|
import com.logpm.factory.mt.dto.MtPackageInfoDTO; |
|
|
|
|
import com.logpm.factory.comfac.dto.*; |
|
|
|
|
import com.logpm.factory.mt.dto.*; |
|
|
|
|
import com.logpm.factory.mt.service.IMtFactoryDataService; |
|
|
|
|
import com.logpm.factory.mt.service.IMtFactoryOrderMainService; |
|
|
|
|
import com.logpm.factory.mt.service.IMtFactoryOrderService; |
|
|
|
@ -23,19 +17,21 @@ import com.logpm.factory.snm.bean.Resp;
|
|
|
|
|
import com.logpm.factory.snm.entity.MtFactoryOrder; |
|
|
|
|
import com.logpm.factory.snm.entity.MtFactoryOrderMain; |
|
|
|
|
import com.logpm.factory.snm.entity.MtPackageInfo; |
|
|
|
|
import com.logpm.oldproject.entity.NewDistributionContactEntity; |
|
|
|
|
import com.logpm.oldproject.feign.IAdvanceDetailClient; |
|
|
|
|
import com.logpm.oldproject.feign.INewDistributionContactClient; |
|
|
|
|
import com.logpm.oldproject.feign.IWarehouseClient; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
import org.springblade.common.exception.CustomerException; |
|
|
|
|
import org.springblade.common.utils.CommonUtil; |
|
|
|
|
import org.springblade.core.redis.cache.BladeRedis; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.core.tool.utils.StringUtil; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
@ -56,6 +52,8 @@ public class MtFactoryDataServiceImpl implements IMtFactoryDataService {
|
|
|
|
|
|
|
|
|
|
private final MtFactoryProperties mtFactoryProperties; |
|
|
|
|
|
|
|
|
|
private final INewDistributionContactClient newDistributionContactClient; |
|
|
|
|
|
|
|
|
|
@Transactional |
|
|
|
|
@Override |
|
|
|
|
public R dealWithData(MtFactoryDataDTO mtFactoryDataDTO) { |
|
|
|
@ -234,14 +232,13 @@ public class MtFactoryDataServiceImpl implements IMtFactoryDataService {
|
|
|
|
|
|
|
|
|
|
String status = orderStatusDTO.getStatus(); |
|
|
|
|
String orderNo = orderStatusDTO.getOrderNo(); |
|
|
|
|
if("1".equals(status)||"2".equals(status)||"3".equals(status)||"6".equals(status)||"7".equals(status)||"8".equals(status)||"9".equals(status)){ |
|
|
|
|
if("1".equals(status)||"2".equals(status)||"3".equals(status)||"5".equals(status)||"6".equals(status)||"7".equals(status)||"8".equals(status)||"9".equals(status)){ |
|
|
|
|
logger.info("#############handleStatusData: 当前数据的状态不推送 status={}",status); |
|
|
|
|
return Resp.fail(400,"当前数据的状态不推送"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//通过包件码查询是否是要推送的订单
|
|
|
|
|
String unitNo = orderStatusDTO.getUnitNo();//包件码
|
|
|
|
|
String currentWarehouse = orderStatusDTO.getCurrentWarehouse(); |
|
|
|
|
QueryWrapper<MtPackageInfo> packageInfoQueryWrapper = new QueryWrapper<>(); |
|
|
|
|
packageInfoQueryWrapper.eq("package_code",unitNo); |
|
|
|
|
MtPackageInfo one = mtPackageInfoService.getOne(packageInfoQueryWrapper); |
|
|
|
@ -262,44 +259,39 @@ public class MtFactoryDataServiceImpl implements IMtFactoryDataService {
|
|
|
|
|
return Resp.fail(400,"未找到对应订单"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//根据仓库ID查询仓库名字
|
|
|
|
|
currentWarehouse = warehouseClient.selectNameById(Integer.parseInt(currentWarehouse)); |
|
|
|
|
|
|
|
|
|
//拼接参数
|
|
|
|
|
Map<String,Object> map = new HashMap<>(); |
|
|
|
|
map.put("发运单编号", mtFactoryOrderMain.getInvoiceOrderCode()); |
|
|
|
|
map.put("订单编号", orderNo); |
|
|
|
|
map.put("包条码", unitNo); |
|
|
|
|
map.put("操作时间", orderStatusDTO.getOperationTime()); |
|
|
|
|
map.put("仓库", currentWarehouse); |
|
|
|
|
map.put("生产单号", mtFactoryOrder.getProduceOrderCode()); |
|
|
|
|
map.put("经销商名称", mtFactoryOrder.getDealerName()); |
|
|
|
|
map.put("状态", orderStatusDTO.getStatus()); |
|
|
|
|
|
|
|
|
|
Gson gson = new GsonBuilder().setPrettyPrinting().create(); |
|
|
|
|
String s = gson.toJson(map); |
|
|
|
|
MtOrderStatusDTO mtOrderStatusDTO = new MtOrderStatusDTO(); |
|
|
|
|
mtOrderStatusDTO.setInvoiceOrderCode(mtFactoryOrderMain.getInvoiceOrderCode()); |
|
|
|
|
mtOrderStatusDTO.setOrderNo(orderNo); |
|
|
|
|
mtOrderStatusDTO.setUnitNo(unitNo); |
|
|
|
|
mtOrderStatusDTO.setOperationTime(CommonUtil.StringToDate(orderStatusDTO.getOperationTime())); |
|
|
|
|
mtOrderStatusDTO.setWarehouse(mtFactoryOrderMain.getCenterWarehouseCode()); |
|
|
|
|
mtOrderStatusDTO.setDealerName(mtFactoryOrder.getDealerName()); |
|
|
|
|
|
|
|
|
|
//先获取token
|
|
|
|
|
String panToken = "getPanToken()"; |
|
|
|
|
String token = getMtToken(); |
|
|
|
|
|
|
|
|
|
//请求参数
|
|
|
|
|
logger.info("##############handleStatusData: 推送包件状态请求参数 {}",s); |
|
|
|
|
logger.info("##############handleStatusData: 推送包件状态请求参数 {}",mtOrderStatusDTO); |
|
|
|
|
|
|
|
|
|
//处理逻辑
|
|
|
|
|
String result = HttpRequest.post("URL"+"/hitf/v1/rest/invoke?namespace=HZERO&serverCode=OPEN&interfaceCode=HUITONG_RECEIVE") |
|
|
|
|
.header("Authorization","Bearer "+panToken) |
|
|
|
|
String result = HttpRequest.post(mtFactoryProperties.getUrl()+"/Auth/text") |
|
|
|
|
.header("APPKEY",mtFactoryProperties.getAppkey()) |
|
|
|
|
.header("Authorization",token) |
|
|
|
|
.header("USERID",mtFactoryProperties.getUserid()) |
|
|
|
|
.header("USERPWD",mtFactoryProperties.getUserpwd()) |
|
|
|
|
.header("Content-Type","application/json") |
|
|
|
|
.body(s).timeout(5 * 1000) |
|
|
|
|
.body(JSONObject.toJSONString(mtOrderStatusDTO)).timeout(5 * 1000) |
|
|
|
|
.execute().body(); |
|
|
|
|
|
|
|
|
|
logger.info("##############handleStatusData: 推送包件状态返回参数 {}",result); |
|
|
|
|
|
|
|
|
|
//把结果字符串转为json对象
|
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(result); |
|
|
|
|
JSONObject payload = jsonObject.getJSONObject("payload"); |
|
|
|
|
if(!Objects.isNull(payload)){ |
|
|
|
|
Integer code = payload.getInteger("code"); |
|
|
|
|
String message = payload.getString("data"); |
|
|
|
|
if(code.equals(1)){ |
|
|
|
|
if(!Objects.isNull(jsonObject)){ |
|
|
|
|
Integer code = jsonObject.getInteger("Result"); |
|
|
|
|
String message = jsonObject.getString("Message"); |
|
|
|
|
if(code.equals(0)){ |
|
|
|
|
logger.info("##########handleStatusData: 物流状态传递成功"); |
|
|
|
|
}else{ |
|
|
|
|
return Resp.fail(405,message); |
|
|
|
@ -312,36 +304,103 @@ public class MtFactoryDataServiceImpl implements IMtFactoryDataService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional |
|
|
|
|
@Override |
|
|
|
|
public R sendReceiveInfo(ReceiveInfoDTO receiveInfoDTO) { |
|
|
|
|
log.info("###########sendReceiveInfo: 处理签收图片数据开始"); |
|
|
|
|
Integer newDistributionContactId = receiveInfoDTO.getNewDistributionContactId(); |
|
|
|
|
List<ReceiveBodyDTO> receiveBodyList = receiveInfoDTO.getReceiveBodyList(); |
|
|
|
|
Long mainId = null; |
|
|
|
|
List<ReceivePhotoDTO> receivePhotoList = receiveInfoDTO.getReceivePhotoList(); |
|
|
|
|
//查询签收人
|
|
|
|
|
NewDistributionContactEntity newDistributionContactEntity = newDistributionContactClient.fingById(newDistributionContactId); |
|
|
|
|
String receiver = null; |
|
|
|
|
if (!Objects.isNull(newDistributionContactEntity)){ |
|
|
|
|
receiver = newDistributionContactEntity.getContact(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//处理头部数
|
|
|
|
|
MtReceiveDTO mtReceiveDTO = new MtReceiveDTO(); |
|
|
|
|
mtReceiveDTO.setReceiver(receiver); |
|
|
|
|
mtReceiveDTO.setSendTaskId(receiveInfoDTO.getSendTaskId()); |
|
|
|
|
|
|
|
|
|
//循环处理签收信息
|
|
|
|
|
List<MtReceiveContentDTO> mtReceiveContentDTOList = new ArrayList<>(); |
|
|
|
|
for(ReceiveBodyDTO receiveBodyDTO:receiveBodyList){ |
|
|
|
|
String orderCode = receiveBodyDTO.getOrderCode();//订单自编号
|
|
|
|
|
QueryWrapper<MtFactoryOrder> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
queryWrapper.eq("order_code",orderCode); |
|
|
|
|
MtFactoryOrder one = mtFactoryOrderService.getOne(queryWrapper); |
|
|
|
|
String unitNo = receiveBodyDTO.getUnitNo();//包条码
|
|
|
|
|
//通过订单编号查询总单信息
|
|
|
|
|
QueryWrapper<MtPackageInfo> packageInfoQueryWrapper = new QueryWrapper<>(); |
|
|
|
|
packageInfoQueryWrapper.eq("package_code",unitNo); |
|
|
|
|
MtPackageInfo one = mtPackageInfoService.getOne(packageInfoQueryWrapper); |
|
|
|
|
if(Objects.isNull(one)){ |
|
|
|
|
log.warn("################sendReceiveInfo: 订单数据不存在 orderCode={}",orderCode); |
|
|
|
|
return R.fail(400,"订单数据不存在"); |
|
|
|
|
logger.info("#############sendReceiveInfo: 当前包条码未找到对应数据unitNo={}",unitNo); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
Long orderId = one.getOrderId(); |
|
|
|
|
MtFactoryOrder mtFactoryOrder = mtFactoryOrderService.getById(orderId); |
|
|
|
|
if(Objects.isNull(mtFactoryOrder)){ |
|
|
|
|
logger.info("#############sendReceiveInfo: 未找到对应订单orderId={}",orderId); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
receiveBodyDTO.setProduceOrderCode(one.getProduceOrderCode()); |
|
|
|
|
mainId = one.getMainId(); |
|
|
|
|
Long mainId = mtFactoryOrder.getMainId(); |
|
|
|
|
MtFactoryOrderMain mtFactoryOrderMain = mtFactoryOrderMainService.getById(mainId); |
|
|
|
|
if(Objects.isNull(mtFactoryOrderMain)){ |
|
|
|
|
logger.info("#############sendReceiveInfo: 未找到对应订单mainId={}",mainId); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
MtReceiveContentDTO mtReceiveContentDTO = new MtReceiveContentDTO(); |
|
|
|
|
mtReceiveContentDTO.setInvoiceOrderCode(mtFactoryOrderMain.getInvoiceOrderCode()); |
|
|
|
|
mtReceiveContentDTO.setWarehouseCode(mtFactoryOrderMain.getCenterWarehouseCode()); |
|
|
|
|
mtReceiveContentDTO.setOrderCode(mtFactoryOrder.getOrderCode()); |
|
|
|
|
mtReceiveContentDTO.setUnitNo(unitNo); |
|
|
|
|
mtReceiveContentDTO.setOperateDate(CommonUtil.StringToDate(receiveBodyDTO.getOperateDate())); |
|
|
|
|
mtReceiveContentDTOList.add(mtReceiveContentDTO); |
|
|
|
|
} |
|
|
|
|
MtFactoryOrderMain mtFactoryOrderMain = mtFactoryOrderMainService.getById(mainId); |
|
|
|
|
if(Objects.isNull(mtFactoryOrderMain)){ |
|
|
|
|
log.warn("################sendReceiveInfo: 主订单数据不存在 mainId={}",mainId); |
|
|
|
|
return R.fail(400,"主订单数据不存在"); |
|
|
|
|
//签收信息数据存入头部数据
|
|
|
|
|
mtReceiveDTO.setReceiveContentList(mtReceiveContentDTOList); |
|
|
|
|
|
|
|
|
|
//处理签收图片数据
|
|
|
|
|
List<MtReceiveImagesDTO> mtReceiveImagesDTOList = new ArrayList<>(); |
|
|
|
|
for (ReceivePhotoDTO receivePhotoDTO:receivePhotoList){ |
|
|
|
|
MtReceiveImagesDTO mtReceiveImagesDTO = new MtReceiveImagesDTO(); |
|
|
|
|
mtReceiveImagesDTO.setImage(receivePhotoDTO.getUrl()); |
|
|
|
|
mtReceiveImagesDTOList.add(mtReceiveImagesDTO); |
|
|
|
|
} |
|
|
|
|
receiveInfoDTO.setInvoiceOrderCode(mtFactoryOrderMain.getInvoiceOrderCode()); |
|
|
|
|
receiveInfoDTO.setWarehouse(mtFactoryOrderMain.getCenterWarehouseName()); |
|
|
|
|
receiveInfoDTO.setWarehouseCode(mtFactoryOrderMain.getCenterWarehouseCode()); |
|
|
|
|
receiveInfoDTO.setReceiveBodyList(receiveBodyList); |
|
|
|
|
//签收图片数据存入头部数据
|
|
|
|
|
mtReceiveDTO.setReceiveImagesList(mtReceiveImagesDTOList); |
|
|
|
|
|
|
|
|
|
//推送数据到梦天
|
|
|
|
|
//先获取token
|
|
|
|
|
String token = getMtToken(); |
|
|
|
|
|
|
|
|
|
//拼装参数 ,推送数据到梦天
|
|
|
|
|
//请求参数
|
|
|
|
|
logger.info("##############sendReceiveInfo: 推送包件状态请求参数 {}",mtReceiveDTO); |
|
|
|
|
|
|
|
|
|
//处理逻辑
|
|
|
|
|
String result = HttpRequest.post(mtFactoryProperties.getUrl()+"/Auth/text2") |
|
|
|
|
.header("APPKEY",mtFactoryProperties.getAppkey()) |
|
|
|
|
.header("Authorization",token) |
|
|
|
|
.header("USERID",mtFactoryProperties.getUserid()) |
|
|
|
|
.header("USERPWD",mtFactoryProperties.getUserpwd()) |
|
|
|
|
.header("Content-Type","application/json") |
|
|
|
|
.body(JSONObject.toJSONString(mtReceiveDTO)).timeout(5 * 1000) |
|
|
|
|
.execute().body(); |
|
|
|
|
|
|
|
|
|
logger.info("##############sendReceiveInfo: 推送包件状态返回参数 {}",result); |
|
|
|
|
|
|
|
|
|
//把结果字符串转为json对象
|
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(result); |
|
|
|
|
if(!Objects.isNull(jsonObject)){ |
|
|
|
|
Integer code = jsonObject.getInteger("Result"); |
|
|
|
|
String message = jsonObject.getString("Message"); |
|
|
|
|
if(code.equals(0)){ |
|
|
|
|
logger.info("##########sendReceiveInfo: 物流状态传递成功"); |
|
|
|
|
}else{ |
|
|
|
|
return Resp.fail(405,message); |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
return Resp.fail(405,"返回格式有误:"+result); |
|
|
|
|
} |
|
|
|
|
return R.success("处理签收数据完成"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|