oms-gw推送-物料管理 修改企业国别字段类型
This commit is contained in:
+1
-1
@@ -177,7 +177,7 @@ public class ErpCountryApplicationService{
|
||||
entity.setPushTime(pushTime);
|
||||
}
|
||||
if (pushBy != null) {
|
||||
entity.setPushBy(String.valueOf(pushBy));
|
||||
entity.setPushBy(pushBy);
|
||||
}
|
||||
erpCountryMapper.updateById(entity);
|
||||
}
|
||||
|
||||
+133
@@ -1,19 +1,42 @@
|
||||
package com.mhd.oms.application.service.materialInfo;
|
||||
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.mhd.common.core.exception.ServiceException;
|
||||
import com.mhd.common.core.web.domain.AjaxResult;
|
||||
import com.mhd.common.core.web.page.TableDataInfo;
|
||||
import com.mhd.common.security.utils.SecurityUtils;
|
||||
import com.mhd.oms.domain.gwLog.entity.GwLog;
|
||||
import com.mhd.oms.domain.gwLog.repository.mapper.GwLogMapper;
|
||||
import com.mhd.system.api.WmsServiceFeign;
|
||||
import com.mhd.system.api.domain.MaterialInfoDTO;
|
||||
import com.mhd.system.api.model.LoginUser;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class MaterialInfoApplicationService {
|
||||
|
||||
private static final String PUSH_API_URL = "http://10.33.0.100/ktms-erp-api/transfer/pushData";
|
||||
private static final String API_NAME = "saveOrgGoods";
|
||||
|
||||
@Resource
|
||||
private GwLogMapper gwLogMapper;
|
||||
|
||||
private final WmsServiceFeign wmsServiceFeign;
|
||||
|
||||
@@ -35,4 +58,114 @@ public class MaterialInfoApplicationService {
|
||||
tableDataInfo.setMsg("查询失败");
|
||||
return tableDataInfo;
|
||||
}
|
||||
|
||||
public AjaxResult batchPush(List<MaterialInfoDTO> dtoList) {
|
||||
if (dtoList == null || dtoList.isEmpty()) {
|
||||
return AjaxResult.error("没有数据需要推送");
|
||||
}
|
||||
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
Long pushBy = loginUser != null ? loginUser.getUserid() : null;
|
||||
Long organizationId = loginUser != null ? loginUser.getUserPo().getOrganizationId() : null;
|
||||
Long topOrganizationId = loginUser != null ? loginUser.getUserPo().getTopOrganizationId() : null;
|
||||
String organizationName = loginUser != null ? loginUser.getUserPo().getOrganizationName() : null;
|
||||
|
||||
int successCount = 0;
|
||||
int failCount = 0;
|
||||
StringBuilder failMsg = new StringBuilder();
|
||||
|
||||
for (MaterialInfoDTO dto : dtoList) {
|
||||
Map<String, String> body = new HashMap<>();
|
||||
body.put("goodsCode", dto.getMaterialCode());
|
||||
|
||||
String goodsTypeString;
|
||||
if(dto.getGoodsType() == 0){
|
||||
goodsTypeString = "0";
|
||||
}else if(dto.getGoodsType() == 1){
|
||||
goodsTypeString = "1";
|
||||
}else if(dto.getGoodsType() == 2){
|
||||
goodsTypeString = "2";
|
||||
}else{
|
||||
throw new ServiceException("货物类型不存在");
|
||||
}
|
||||
body.put("goodsType", goodsTypeString);
|
||||
body.put("erpName", dto.getMaterialName());
|
||||
|
||||
|
||||
GwLog gwLog = new GwLog();
|
||||
gwLog.setType("物料管理");
|
||||
gwLog.setBusinessId(String.valueOf(dto.getMaterialBaseInfoId()));
|
||||
gwLog.setRequestBody(JSONObject.toJSONString(body));
|
||||
gwLog.setResponseBody("");
|
||||
gwLog.setStatus(1);
|
||||
gwLog.setSendTime(new Date());
|
||||
gwLog.setOrganizationId(organizationId);
|
||||
gwLog.setTopOrganizationId(topOrganizationId);
|
||||
gwLog.setOrganizationName(organizationName);
|
||||
gwLog.setCreateBy(pushBy);
|
||||
gwLog.setCreateTime(new Date());
|
||||
gwLog.setDelFlag(1);
|
||||
gwLogMapper.insert(gwLog);
|
||||
|
||||
updatePushStatus(dto.getMaterialBaseInfoId(), 2, new Date(), pushBy);
|
||||
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
HttpPost httpPost = new HttpPost(PUSH_API_URL);
|
||||
StringEntity postingString = new StringEntity(JSONObject.toJSONString(body), "UTF-8");
|
||||
httpPost.setEntity(postingString);
|
||||
httpPost.setHeader("Content-type", "application/json");
|
||||
httpPost.setHeader("apiName", API_NAME);
|
||||
|
||||
try {
|
||||
CloseableHttpResponse response = httpClient.execute(httpPost);
|
||||
String responseString = EntityUtils.toString(response.getEntity());
|
||||
gwLog.setResponseBody(responseString);
|
||||
|
||||
if (response.getStatusLine().getStatusCode() == 200) {
|
||||
gwLog.setStatus(2);
|
||||
updatePushStatus(dto.getMaterialBaseInfoId(), 3, new Date(), pushBy);
|
||||
successCount++;
|
||||
} else {
|
||||
gwLog.setStatus(3);
|
||||
gwLog.setErrorMsg(responseString);
|
||||
updatePushStatus(dto.getMaterialBaseInfoId(), 4, new Date(), pushBy);
|
||||
failCount++;
|
||||
failMsg.append("materialCode:").append(dto.getMaterialCode()).append("失败;");
|
||||
}
|
||||
gwLogMapper.updateById(gwLog);
|
||||
response.close();
|
||||
} catch (IOException e) {
|
||||
gwLog.setStatus(3);
|
||||
gwLog.setErrorMsg(e.getMessage());
|
||||
gwLogMapper.updateById(gwLog);
|
||||
updatePushStatus(dto.getMaterialBaseInfoId(), 4, new Date(), pushBy);
|
||||
failCount++;
|
||||
failMsg.append("materialCode:").append(dto.getMaterialCode()).append("异常:").append(e.getMessage()).append(";");
|
||||
log.error("物料推送异常: id={}, error={}", dto.getMaterialBaseInfoId(), e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
httpClient.close();
|
||||
} catch (Exception e) {
|
||||
log.error("关闭httpClient异常: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String resultMsg = "推送完成: 成功" + successCount + "条, 失败" + failCount + "条";
|
||||
if (failCount > 0) {
|
||||
resultMsg += "[" + failMsg.toString() + "]";
|
||||
}
|
||||
return AjaxResult.success(resultMsg);
|
||||
}
|
||||
|
||||
private void updatePushStatus(Long materialBaseInfoId, Integer pushStatus, Date pushTime, Long pushBy) {
|
||||
try {
|
||||
String pushTimeStr = pushTime != null ? DateUtil.format(pushTime, "yyyy-MM-dd HH:mm:ss") : null;
|
||||
wmsServiceFeign.updateMaterialPushStatus(materialBaseInfoId, pushStatus, pushTimeStr, pushBy);
|
||||
log.info("更新返回结果: materialBaseInfoId={}", materialBaseInfoId);
|
||||
} catch (Exception e) {
|
||||
log.info("更新推送状态失败: materialBaseInfoId={}, error={}", materialBaseInfoId, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class ErpCountry implements Serializable {
|
||||
private Date pushTime;
|
||||
|
||||
@ApiModelProperty("推送人")
|
||||
private String pushBy;
|
||||
private Long pushBy;
|
||||
|
||||
@ApiModelProperty("所属组织ID")
|
||||
private Long organizationId;
|
||||
|
||||
@@ -31,7 +31,7 @@ public class ErpCountryPO {
|
||||
private Date pushTime;
|
||||
|
||||
@ApiModelProperty("推送人")
|
||||
private String pushBy;
|
||||
private Long pushBy;
|
||||
|
||||
@ApiModelProperty("所属组织ID")
|
||||
private Long organizationId;
|
||||
|
||||
+8
-3
@@ -2,16 +2,16 @@ package com.mhd.oms.interfaces.facade.materialInfo;
|
||||
|
||||
|
||||
import com.mhd.common.core.web.controller.BaseController;
|
||||
import com.mhd.common.core.web.domain.AjaxResult;
|
||||
import com.mhd.common.core.web.page.TableDataInfo;
|
||||
import com.mhd.oms.application.service.materialInfo.MaterialInfoApplicationService;
|
||||
import com.mhd.system.api.domain.MaterialInfoDTO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Api(tags = "物料信息管理")
|
||||
@@ -30,6 +30,11 @@ public class MaterialInfoApi extends BaseController {
|
||||
return materialInfoApplicationService.queryList(materialInfoDTO);
|
||||
}
|
||||
|
||||
@ApiOperation("批量推送物料")
|
||||
@PostMapping("/batchPush")
|
||||
public AjaxResult batchPush(@RequestBody List<MaterialInfoDTO> dtoList) {
|
||||
return materialInfoApplicationService.batchPush(dtoList);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user