157 lines
		
	
	
		
			7.5 KiB
		
	
	
	
		
			Java
		
	
	
	
			
		
		
	
	
			157 lines
		
	
	
		
			7.5 KiB
		
	
	
	
		
			Java
		
	
	
	
| package tqq9.lc123.cloud.app.api.controller;
 | ||
| 
 | ||
| import com.alibaba.fastjson.JSONObject;
 | ||
| import com.drew.lang.annotations.NotNull;
 | ||
| import com.google.gson.Gson;
 | ||
| import kd.bos.dataentity.entity.DynamicObject;
 | ||
| import kd.bos.dataentity.entity.DynamicObjectCollection;
 | ||
| import kd.bos.logging.Log;
 | ||
| import kd.bos.logging.LogFactory;
 | ||
| import kd.bos.openapi.common.custom.annotation.ApiController;
 | ||
| import kd.bos.openapi.common.custom.annotation.ApiParam;
 | ||
| import kd.bos.openapi.common.custom.annotation.ApiPostMapping;
 | ||
| import kd.bos.openapi.common.result.CustomApiResult;
 | ||
| import kd.bos.orm.query.QCP;
 | ||
| import kd.bos.orm.query.QFilter;
 | ||
| import kd.bos.servicehelper.BusinessDataServiceHelper;
 | ||
| import kd.bos.servicehelper.operation.SaveServiceHelper;
 | ||
| import tqq9.lc123.cloud.app.api.model.WMSXmlReturn;
 | ||
| import tqq9.lc123.cloud.app.api.utils.ApiResultExt;
 | ||
| import tqq9.lc123.cloud.app.api.utils.Constants;
 | ||
| 
 | ||
| import java.util.ArrayList;
 | ||
| import java.util.List;
 | ||
| import java.util.Map;
 | ||
| 
 | ||
| /**
 | ||
|  * WMS物流信息同步接口
 | ||
|  */
 | ||
| @ApiController(value = "WMSLogiSyncController", desc = "WMS物流信息同步接口,自定义插件")
 | ||
| 
 | ||
| public class WMSLogiSyncController {
 | ||
|     private final static Log logger = LogFactory.getLog(WMSLogiSyncController.class);
 | ||
|     @ApiPostMapping(value = "/WMS_LogiSync", desc = "WMS物流信息同步api插件")
 | ||
|     public CustomApiResult<ApiResultExt> WMS_LogiSync
 | ||
|             (
 | ||
|                     @NotNull @ApiParam(value = "发运单号", required = true) String cDPCode,
 | ||
|                     @NotNull @ApiParam(value = "快递公司", required = true) String ExpressCompany,
 | ||
|                     @NotNull @ApiParam(value = "快递单号", required = true) String cWayBillCode
 | ||
|             ) {
 | ||
|         ApiResultExt resultExt = new ApiResultExt();
 | ||
|         List<ApiResultExt.ResultBean> results = new ArrayList<>();
 | ||
|         resultExt.setResult(results);
 | ||
|         String billno = cDPCode;
 | ||
|         ApiResultExt.ResultBean resultBean = new ApiResultExt.ResultBean();
 | ||
|         results.add(resultBean);
 | ||
|         JSONObject keys = new JSONObject();
 | ||
|         keys.put("billno", billno);
 | ||
|         resultBean.setKeys(keys);
 | ||
|         ApiResultExt.Error error =new ApiResultExt.Error();
 | ||
|         resultBean.setErrors(error);
 | ||
|         ArrayList<String> rowmsg = new ArrayList<>();
 | ||
|         error.setRowMsg(rowmsg);
 | ||
|         String errorMsg=null;
 | ||
|         resultBean.setBillIndex(0);
 | ||
|         resultBean.setKeys(keys);
 | ||
|         resultBean.setNumber(billno);
 | ||
|         resultBean.setType(Constants.TYPE_UPDATE);
 | ||
|         String entityType = Constants.IM_PURINBILL;
 | ||
|         //必填项校验
 | ||
|         if (ApiResultExt.validateRequired(billno, "String")) {
 | ||
|             errorMsg="传入参数 cDPCode 为空";
 | ||
|             resultExt = ApiResultExt.errorRetrun(entityType, errorMsg, error, resultExt);
 | ||
|         }
 | ||
|         if (ApiResultExt.validateRequired(ExpressCompany, "String")) {
 | ||
|             errorMsg="传入参数 ExpressCompany 为空";
 | ||
| 
 | ||
|             resultExt = ApiResultExt.errorRetrun(entityType, errorMsg, error, resultExt);
 | ||
|         }
 | ||
|         if (ApiResultExt.validateRequired(cWayBillCode, "String")) {
 | ||
|             errorMsg="传入参数 cWayBillCode 为空";
 | ||
|             resultExt = ApiResultExt.errorRetrun(entityType, errorMsg, error, resultExt);
 | ||
|         }
 | ||
|         rowmsg = resultExt.getResult().get(0).getErrors().getRowMsg();
 | ||
|         if (!rowmsg.isEmpty()) {
 | ||
|             return CustomApiResult.success(resultExt);
 | ||
|         }
 | ||
|         QFilter qFilter = new QFilter("billno", QCP.in, billno);
 | ||
|         qFilter.and("billstatus", QCP.equals, "C");
 | ||
|         DynamicObject sm_delivernotice = BusinessDataServiceHelper.loadSingle(Constants.SM_DELIVERNOTICE, qFilter.toArray());
 | ||
|         if (sm_delivernotice!=null) {
 | ||
|             String id= sm_delivernotice.getString("id");//发货通知单id
 | ||
|             resultBean.setId(id);
 | ||
|             resultBean.setBillStatus(true);
 | ||
|             DynamicObjectCollection tqq9_logisticsinfo = sm_delivernotice.getDynamicObjectCollection("tqq9_logisticsinfo");
 | ||
|             DynamicObject dynamicObject = tqq9_logisticsinfo.addNew();
 | ||
|             dynamicObject.set("tqq9_carrier",ExpressCompany);
 | ||
|             dynamicObject.set("tqq9_shipmentid",cWayBillCode);
 | ||
|             SaveServiceHelper.save(new DynamicObject[]{sm_delivernotice});
 | ||
|         } else {
 | ||
|             rowmsg.add("根据传入发运单号未找到对应的发货通知单");
 | ||
|             resultExt = ApiResultExt.errorRetrun(entityType, errorMsg, error, resultExt);
 | ||
|             return CustomApiResult.success(resultExt);
 | ||
|         }
 | ||
|         resultBean.setErrors(error);
 | ||
| //        results.add(resultBean);
 | ||
|         int failCount = 0;//失败数量
 | ||
|         int successCount = 1;//成功数量
 | ||
|         resultExt.setFailCount(failCount);
 | ||
|         resultExt.setSuccessCount(successCount);
 | ||
|         resultExt.setResult(results);
 | ||
|         return CustomApiResult.success(resultExt);
 | ||
|     }
 | ||
| 
 | ||
|     @ApiPostMapping(value = "/WMS_LogiSync_SH", desc = "WMS物流信息同步api插件_SH")
 | ||
|     public CustomApiResult<WMSXmlReturn> WMS_LogiSync_SH
 | ||
|             (@NotNull @ApiParam(value = "入参", required = true) Map<String, Object> dataMap) {
 | ||
|         //返回值初始化
 | ||
|         Gson gson = new Gson();
 | ||
|         JSONObject data = gson.fromJson(dataMap.toString(), JSONObject.class);
 | ||
|         JSONObject request = data.getJSONObject("request");
 | ||
|         String billno = request.getString("orderCode");//单据编号
 | ||
|         String logisticsName = request.getString("logisticsName");//物流公司名称
 | ||
|         String expressCode = request.getString("expressCode");//物流单据编号
 | ||
| 
 | ||
|         WMSXmlReturn wmsXmlReturn = new WMSXmlReturn();
 | ||
|         WMSXmlReturn.Response response = new WMSXmlReturn.Response();
 | ||
|         wmsXmlReturn.setResponse(response);
 | ||
|         response.setCode("0");
 | ||
|         response.setFlag("success");
 | ||
|         response.setMessage("成功");
 | ||
|         StringBuilder errormsg = new StringBuilder();
 | ||
| 
 | ||
|         //必填项校验
 | ||
|         if (ApiResultExt.validateRequired(billno, "String")) {
 | ||
|             errormsg = errormsg.append(";").append("传入参数 orderCode 为空");
 | ||
|         }
 | ||
|         if (ApiResultExt.validateRequired(logisticsName, "String")) {
 | ||
|             errormsg = errormsg.append(";").append("传入参数 logisticsName 为空");
 | ||
|         }
 | ||
|         if (ApiResultExt.validateRequired(expressCode, "String")) {
 | ||
|             errormsg = errormsg.append(";").append("传入参数 expressCode 为空");
 | ||
|         }
 | ||
|         if (errormsg.length() > 0) {
 | ||
|             response.setMessage(errormsg.substring(1));
 | ||
|             response.setCode("-1");
 | ||
|             response.setFlag("failure");
 | ||
|             return CustomApiResult.success(wmsXmlReturn);
 | ||
|         }
 | ||
|         QFilter qFilter = new QFilter("billno", QCP.in, billno);
 | ||
|         qFilter.and("billstatus", QCP.equals, "C");
 | ||
|         DynamicObject sm_delivernotice = BusinessDataServiceHelper.loadSingle(Constants.SM_DELIVERNOTICE, qFilter.toArray());
 | ||
|         if (sm_delivernotice!=null) {
 | ||
|             DynamicObjectCollection tqq9_logisticsinfo = sm_delivernotice.getDynamicObjectCollection("tqq9_logisticsinfo");
 | ||
|             DynamicObject dynamicObject = tqq9_logisticsinfo.addNew();
 | ||
|             dynamicObject.set("tqq9_carrier",logisticsName);
 | ||
|             dynamicObject.set("tqq9_shipmentid",expressCode);
 | ||
|             SaveServiceHelper.save(new DynamicObject[]{sm_delivernotice});
 | ||
|         } else {
 | ||
|             errormsg = errormsg.append(";").append("根据传入发运单号未找到对应的发货通知单");
 | ||
|             response.setMessage(errormsg.substring(1));
 | ||
|             response.setCode("-1");
 | ||
|             response.setFlag("failure");
 | ||
|             return CustomApiResult.success(wmsXmlReturn);
 | ||
|         }
 | ||
|         return CustomApiResult.success(wmsXmlReturn);
 | ||
|     }
 | ||
| } |