From da20e2a6164e1f01eae96968474e0ac8220e0091 Mon Sep 17 00:00:00 2001 From: zhaoqing <1670883518@qq.com> Date: Thu, 7 May 2026 15:25:23 +0800 Subject: [PATCH] =?UTF-8?q?OMS-GW-=E4=BC=81=E4=B8=9A=E5=8D=95=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ErpEnterpriseUnitApplicationService.java | 125 ++++++++++++++++++ .../mapper/ErpEnterpriseUnitMapper.java | 8 ++ .../ErpEnterpriseUnitApi.java | 24 +++- .../ErpEnterpriseUnitMapper.xml | 7 + 4 files changed, 163 insertions(+), 1 deletion(-) diff --git a/mhd_oms/src/main/java/com/mhd/oms/application/service/erpEnterpriseUnit/ErpEnterpriseUnitApplicationService.java b/mhd_oms/src/main/java/com/mhd/oms/application/service/erpEnterpriseUnit/ErpEnterpriseUnitApplicationService.java index 5c956715e..07a24d3e6 100644 --- a/mhd_oms/src/main/java/com/mhd/oms/application/service/erpEnterpriseUnit/ErpEnterpriseUnitApplicationService.java +++ b/mhd_oms/src/main/java/com/mhd/oms/application/service/erpEnterpriseUnit/ErpEnterpriseUnitApplicationService.java @@ -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 list = erpEnterpriseUnitMapper.queryList(erpEnterpriseUnitDO); TableDataInfo tableDataInfo = new TableDataInfo(); @@ -60,4 +79,110 @@ public class ErpEnterpriseUnitApplicationService { return erpEnterpriseUnitMapper.insert(erpEnterpriseUnit); } + + public AjaxResult batchPush(List 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 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 idList) { + if(idList == null || idList.isEmpty()){ + return 0; + } + return erpEnterpriseUnitMapper.deleteByIds(idList); + } } diff --git a/mhd_oms/src/main/java/com/mhd/oms/domain/erpEnterpriseUnit/repository/mapper/ErpEnterpriseUnitMapper.java b/mhd_oms/src/main/java/com/mhd/oms/domain/erpEnterpriseUnit/repository/mapper/ErpEnterpriseUnitMapper.java index c44aaf297..7d70ef7f2 100644 --- a/mhd_oms/src/main/java/com/mhd/oms/domain/erpEnterpriseUnit/repository/mapper/ErpEnterpriseUnitMapper.java +++ b/mhd_oms/src/main/java/com/mhd/oms/domain/erpEnterpriseUnit/repository/mapper/ErpEnterpriseUnitMapper.java @@ -19,4 +19,12 @@ public interface ErpEnterpriseUnitMapper extends BaseMapper { * @return */ List queryList(@Param("erpEnterpriseUnitDO")ErpEnterpriseUnitDO erpEnterpriseUnitDO); + + /** + * + * @param idList + * @return + */ + int deleteByIds(@Param("idList") List idList); + } diff --git a/mhd_oms/src/main/java/com/mhd/oms/interfaces/facade/erpEnterpriseUnit/ErpEnterpriseUnitApi.java b/mhd_oms/src/main/java/com/mhd/oms/interfaces/facade/erpEnterpriseUnit/ErpEnterpriseUnitApi.java index c5ce46abd..9ab418e71 100644 --- a/mhd_oms/src/main/java/com/mhd/oms/interfaces/facade/erpEnterpriseUnit/ErpEnterpriseUnitApi.java +++ b/mhd_oms/src/main/java/com/mhd/oms/interfaces/facade/erpEnterpriseUnit/ErpEnterpriseUnitApi.java @@ -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 dtoList) { + return erpEnterpriseUnitApplicationService.batchPush(dtoList); + } + + @ApiOperation("批量删除企业单位") + @DeleteMapping("/deleteBatch") + public AjaxResult deleteBatch(@RequestParam("ids") String ids) { + if (ids == null || ids.isEmpty()) { + return AjaxResult.error("没有选择要删除的数据"); + } + List idList = new ArrayList<>(); + for (String id : ids.split(",")) { + idList.add(Long.parseLong(id)); + } + return toAjax(erpEnterpriseUnitApplicationService.deleteByIds(idList)); + } + + } diff --git a/mhd_oms/src/main/resources/mapper/erpEnterpriseUnit/ErpEnterpriseUnitMapper.xml b/mhd_oms/src/main/resources/mapper/erpEnterpriseUnit/ErpEnterpriseUnitMapper.xml index 26c60b791..828884083 100644 --- a/mhd_oms/src/main/resources/mapper/erpEnterpriseUnit/ErpEnterpriseUnitMapper.xml +++ b/mhd_oms/src/main/resources/mapper/erpEnterpriseUnit/ErpEnterpriseUnitMapper.xml @@ -36,4 +36,11 @@ ORDER BY create_time DESC + + UPDATE erp_enterprise_unit set del_flag = 0 where id IN + + #{id} + + + \ No newline at end of file