diff --git a/op-api/op-api-system/src/main/java/com/op/system/api/RemoteSapService.java b/op-api/op-api-system/src/main/java/com/op/system/api/RemoteSapService.java index d1785bcf..11354e6b 100644 --- a/op-api/op-api-system/src/main/java/com/op/system/api/RemoteSapService.java +++ b/op-api/op-api-system/src/main/java/com/op/system/api/RemoteSapService.java @@ -150,6 +150,8 @@ public interface RemoteSapService { public R sapProductOutboundCostTW(@RequestBody(required = false) List mapList) ; @PostMapping("/sap/ObtainSapInventory") public R ObtainSapInventory(@RequestBody(required = false) SapZmesGetMchb sapZmesGetMchb); + @PostMapping("/sap/sapZmesAnlaGet") + public R sapZmesAnlaGet(@RequestBody(required = false) Map paramMap); } diff --git a/op-api/op-api-system/src/main/java/com/op/system/api/factory/RemoteSapFallbackFactory.java b/op-api/op-api-system/src/main/java/com/op/system/api/factory/RemoteSapFallbackFactory.java index 1a8cb289..eeaa3b62 100644 --- a/op-api/op-api-system/src/main/java/com/op/system/api/factory/RemoteSapFallbackFactory.java +++ b/op-api/op-api-system/src/main/java/com/op/system/api/factory/RemoteSapFallbackFactory.java @@ -183,6 +183,11 @@ public class RemoteSapFallbackFactory implements FallbackFactory selectEquipmentListByCategory(BaseEquipment baseEquipment); List getEquipmentTypeDeptList(BaseEquipment baseEquipment); + + AjaxResult sapSyncBaseEquipment(Long equipmentId); } diff --git a/op-modules/op-wms/src/main/java/com/op/wms/service/impl/BaseEquipmentServiceImpl.java b/op-modules/op-wms/src/main/java/com/op/wms/service/impl/BaseEquipmentServiceImpl.java index b8f9b583..34e8c279 100644 --- a/op-modules/op-wms/src/main/java/com/op/wms/service/impl/BaseEquipmentServiceImpl.java +++ b/op-modules/op-wms/src/main/java/com/op/wms/service/impl/BaseEquipmentServiceImpl.java @@ -1,10 +1,14 @@ package com.op.wms.service.impl; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; +import com.alibaba.nacos.shaded.com.google.common.reflect.TypeToken; +import com.alibaba.nacos.shaded.com.google.gson.Gson; +import com.alibaba.nacos.shaded.com.google.gson.JsonSyntaxException; +import com.op.common.core.constant.Constants; +import com.op.common.core.domain.R; +import com.op.system.api.RemoteSapService; import com.op.wms.mapper.BaseTeamUserMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,6 +35,7 @@ import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServletRequest; + import static com.op.common.core.web.domain.AjaxResult.error; import static com.op.common.core.web.domain.AjaxResult.success; @@ -48,7 +53,8 @@ public class BaseEquipmentServiceImpl implements IBaseEquipmentService { @Autowired private BaseTeamUserMapper baseTeamUserMapper; - + @Autowired + private RemoteSapService remoteSapService; /** * 查询设备管理 * @@ -633,4 +639,58 @@ public class BaseEquipmentServiceImpl implements IBaseEquipmentService { public List getEquipmentTypeDeptList(BaseEquipment baseEquipment) { return baseEquipmentMapper.getEquipmentTypeDeptList(baseEquipment); } + + @Override + @DS("#header.poolName") + public AjaxResult sapSyncBaseEquipment(Long equipmentId) { + + /**查询设备信息*/ + BaseEquipment baseEquipment = baseEquipmentMapper.selectBaseEquipmentByEquipmentId(equipmentId); + + Map P_SERNR=new HashMap<>(); + P_SERNR.put("P_SERNR",baseEquipment.getEquipmentCode()); + R r = remoteSapService.sapZmesAnlaGet(P_SERNR); + if (Constants.SUCCESS.equals(r.getCode())) { + Object data = r.getData(); + + // 条件1:data 不为空 + if (data != null) { + Gson gson = new Gson(); + try { + // 将 data 转换为 Map + Map map = gson.fromJson( + gson.toJson(data), + new TypeToken>(){}.getType() + ); + + // 条件2:map 不为空且包含 ANLN1 字段 + if (map != null && map.containsKey("ANLN1")) { + Object anln1Obj = map.get("ANLN1"); + // 条件3:ANLN1 字段值不为空且可转为字符串 + if (anln1Obj != null) { + String ANLN1 = anln1Obj.toString(); + if (StringUtils.isNotEmpty(ANLN1)) { + baseEquipment.setFixedAssetCode( + ANLN1.substring(Math.max(0, ANLN1.length() - 6)) + ); + } + } + baseEquipmentMapper.updateBaseEquipment(baseEquipment); + } + } catch (JsonSyntaxException e) { + e.printStackTrace(); + return AjaxResult.error("同步失败"+e.getMessage()); + // 处理 JSON 转换异常 + + } + return AjaxResult.success("同步成功"); + } else { + // data 为空时的处理(如日志警告) + System.out.println("data is null"); + } + }else { + return AjaxResult.error(r.getMsg()); + } + return AjaxResult.success("同步成功"); + } }