OMS-GW-企业单位
This commit is contained in:
+125
@@ -1,29 +1,48 @@
|
||||
package com.mhd.oms.application.service.erpEnterpriseUnit;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.mhd.common.core.utils.bean.BeanUtils;
|
||||
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.erpEnterpriseUnit.entity.ErpEnterpriseUnit;
|
||||
import com.mhd.oms.domain.erpEnterpriseUnit.repository.mapper.ErpEnterpriseUnitMapper;
|
||||
import com.mhd.oms.domain.erpEnterpriseUnit.repository.po.ErpEnterpriseUnitPO;
|
||||
import com.mhd.oms.domain.erpEnterpriseUnit.repository.todo.ErpEnterpriseUnitDO;
|
||||
import com.mhd.oms.domain.gwLog.entity.GwLog;
|
||||
import com.mhd.oms.domain.gwLog.repository.mapper.GwLogMapper;
|
||||
import com.mhd.oms.interfaces.dto.erpEnterpriseUnit.ErpEnterpriseUnitDTO;
|
||||
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 ErpEnterpriseUnitApplicationService {
|
||||
|
||||
private static final String PUSH_API_URL = "http://10.33.0.100/ktms-erp-api/transfer/pushData";
|
||||
private static final String API_NAME = "saveUnit";
|
||||
|
||||
@Resource
|
||||
private ErpEnterpriseUnitMapper erpEnterpriseUnitMapper;
|
||||
|
||||
@Resource
|
||||
private GwLogMapper gwLogMapper;
|
||||
|
||||
public TableDataInfo queryList(ErpEnterpriseUnitDO erpEnterpriseUnitDO) {
|
||||
List<ErpEnterpriseUnitPO> list = erpEnterpriseUnitMapper.queryList(erpEnterpriseUnitDO);
|
||||
TableDataInfo tableDataInfo = new TableDataInfo();
|
||||
@@ -60,4 +79,110 @@ public class ErpEnterpriseUnitApplicationService {
|
||||
return erpEnterpriseUnitMapper.insert(erpEnterpriseUnit);
|
||||
|
||||
}
|
||||
|
||||
public AjaxResult batchPush(List<ErpEnterpriseUnitDTO> 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 (ErpEnterpriseUnitDTO dto : dtoList) {
|
||||
Map<String, String> body = new HashMap<>();
|
||||
body.put("erpUnitCode", dto.getErpCode());
|
||||
body.put("erpUnitName", dto.getErpName());
|
||||
|
||||
GwLog gwLog = new GwLog();
|
||||
gwLog.setType("企业单位");
|
||||
gwLog.setBusinessId(String.valueOf(dto.getId()));
|
||||
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.getId(), 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.getId(), 3, new Date(), pushBy);
|
||||
successCount++;
|
||||
} else {
|
||||
gwLog.setStatus(3);
|
||||
gwLog.setErrorMsg(responseString);
|
||||
updatePushStatus(dto.getId(), 4, new Date(), pushBy);
|
||||
failCount++;
|
||||
failMsg.append("erpUnitCode:").append(dto.getErpCode()).append("失败;");
|
||||
}
|
||||
gwLogMapper.updateById(gwLog);
|
||||
response.close();
|
||||
} catch (IOException e) {
|
||||
gwLog.setStatus(3);
|
||||
gwLog.setErrorMsg(e.getMessage());
|
||||
gwLogMapper.updateById(gwLog);
|
||||
updatePushStatus(dto.getId(), 4, new Date(), pushBy);
|
||||
failCount++;
|
||||
failMsg.append("erpUnitCode:").append(dto.getErpCode()).append("异常:").append(e.getMessage()).append(";");
|
||||
log.error("企业单位推送异常: id={}, error={}", dto.getId(), 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 id, Integer pushStatus, Date pushTime, Long pushBy) {
|
||||
ErpEnterpriseUnit entity = new ErpEnterpriseUnit();
|
||||
entity.setId(id);
|
||||
entity.setPushStatus(pushStatus);
|
||||
if (pushTime != null) {
|
||||
entity.setPushTime(pushTime);
|
||||
}
|
||||
if (pushBy != null) {
|
||||
entity.setPushBy(String.valueOf(pushBy));
|
||||
}
|
||||
erpEnterpriseUnitMapper.updateById(entity);
|
||||
}
|
||||
|
||||
public int deleteByIds(List<Long> idList) {
|
||||
if(idList == null || idList.isEmpty()){
|
||||
return 0;
|
||||
}
|
||||
return erpEnterpriseUnitMapper.deleteByIds(idList);
|
||||
}
|
||||
}
|
||||
|
||||
+8
@@ -19,4 +19,12 @@ public interface ErpEnterpriseUnitMapper extends BaseMapper<ErpEnterpriseUnit> {
|
||||
* @return
|
||||
*/
|
||||
List<ErpEnterpriseUnitPO> queryList(@Param("erpEnterpriseUnitDO")ErpEnterpriseUnitDO erpEnterpriseUnitDO);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param idList
|
||||
* @return
|
||||
*/
|
||||
int deleteByIds(@Param("idList") List<Long> idList);
|
||||
|
||||
}
|
||||
|
||||
+23
-1
@@ -14,7 +14,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Api(tags = "企业单位管理")
|
||||
@@ -50,4 +51,25 @@ public class ErpEnterpriseUnitApi extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("批量推送企业单位")
|
||||
@PostMapping("/batchPush")
|
||||
public AjaxResult batchPush(@RequestBody List<ErpEnterpriseUnitDTO> dtoList) {
|
||||
return erpEnterpriseUnitApplicationService.batchPush(dtoList);
|
||||
}
|
||||
|
||||
@ApiOperation("批量删除企业单位")
|
||||
@DeleteMapping("/deleteBatch")
|
||||
public AjaxResult deleteBatch(@RequestParam("ids") String ids) {
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
return AjaxResult.error("没有选择要删除的数据");
|
||||
}
|
||||
List<Long> idList = new ArrayList<>();
|
||||
for (String id : ids.split(",")) {
|
||||
idList.add(Long.parseLong(id));
|
||||
}
|
||||
return toAjax(erpEnterpriseUnitApplicationService.deleteByIds(idList));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user