package com.zy.asrs.service.impl;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import com.core.common.Cools;
|
import com.core.exception.CoolException;
|
import com.zy.asrs.entity.DocType;
|
import com.zy.asrs.entity.Order;
|
import com.zy.asrs.entity.OrderDetl;
|
import com.zy.asrs.service.ApiLogService;
|
import com.zy.asrs.service.OrderService;
|
import com.zy.asrs.service.ReportToThirdService;
|
import com.zy.common.utils.HttpHandler;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Service;
|
|
import java.io.IOException;
|
import java.util.List;
|
|
@Service
|
@Slf4j
|
public class ReportToThirdServiceImpl implements ReportToThirdService {
|
|
@Autowired
|
private ApiLogService apiLogService;
|
|
@Autowired
|
private OrderService orderService;
|
|
@Value("${NYNC.ip}")
|
private String nyncIp;
|
|
@Value("${NYNC.port}")
|
private String port;
|
|
@Value("${NYNC.saveRefDelivery}")
|
private String saveRefDelivery;
|
|
|
@Override
|
public void report(Order order, List<OrderDetl> orderDetls, DocType docType) {
|
Boolean http = false;
|
switch (order.getDocType().toString()) {
|
case "销售发货":
|
http = http("", docType.getDocName(), nyncIp + port, saveRefDelivery);
|
if (Cools.isEmpty(order.getShipCode()) || order.getShipCode().equalsIgnoreCase("1")) {
|
|
}
|
break;
|
case "产成品入库":
|
break;
|
case "辅料采购入库":
|
break;
|
case "辅料及成品转库":
|
break;
|
case "自动包装入库":
|
break;
|
case "内部调拨":
|
break;
|
default:
|
break;
|
}
|
if (http) {
|
// 修改订单状态 4.完成 ===>> 6.已上报
|
if (!orderService.updateSettle(order.getId(), 6L, null)) {
|
throw new CoolException("服务器内部错误,请联系管理员");
|
}
|
}
|
}
|
|
private Boolean http(Object data, String docType, String url, String path) {
|
String response = "";
|
boolean success = false;
|
try {
|
response = new HttpHandler.Builder()
|
.setUri(url)
|
.setPath(path)
|
.setJson(JSON.toJSONString(data))
|
.build()
|
.doPost();
|
JSONObject jsonObject = JSON.parseObject(response);
|
if (jsonObject.getInteger("code").equals(1)) {
|
return true;
|
}
|
log.error("请求接口失败!!!url:{};request:{};response:{}", url + path, JSON.toJSONString(data), response);
|
} catch (IOException e) {
|
e.printStackTrace();
|
} finally {
|
apiLogService.save(
|
docType,
|
url + path,
|
null,
|
"127.0.0.1",
|
JSON.toJSONString(data),
|
response,
|
success
|
);
|
}
|
return false;
|
}
|
}
|