104 lines
		
	
	
		
			4.9 KiB
		
	
	
	
		
			Java
		
	
	
	
			
		
		
	
	
			104 lines
		
	
	
		
			4.9 KiB
		
	
	
	
		
			Java
		
	
	
	
| package tqq9.lc123.cloud.app.api.controller;
 | ||
| 
 | ||
| import com.alibaba.fastjson.JSONObject;
 | ||
| import com.drew.lang.annotations.NotNull;
 | ||
| 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.utils.ApiResultExt;
 | ||
| import tqq9.lc123.cloud.app.api.utils.Constants;
 | ||
| 
 | ||
| import java.util.ArrayList;
 | ||
| import java.util.List;
 | ||
| 
 | ||
| /**
 | ||
|  * 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);
 | ||
| //        Gson gson = new Gson();
 | ||
| //        HashMap<String, Object> data = gson.fromJson(dataString, HashMap.class);
 | ||
|         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;
 | ||
| //        String ExpressCompany =  data.get("ExpressCompany").toString();//快递公司
 | ||
| //        String cWayBillCode =  data.get("cWayBillCode").toString();//快递单号
 | ||
|         //必填项校验
 | ||
|         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);
 | ||
|     }
 | ||
| } |