chen.lin
14 小时以前 a56420ff2042a3f6b1e824341a717a28c692cad4
rsf-open-api/src/main/java/com/vincent/rsf/openApi/controller/phyz/ERPController.java
@@ -3,21 +3,26 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.vincent.rsf.framework.common.R;
import com.vincent.rsf.framework.exception.CoolException;
import com.vincent.rsf.openApi.entity.dto.CommonResponse;
import com.vincent.rsf.openApi.entity.phyz.*;
import com.vincent.rsf.openApi.feign.wms.WmsServerFeignClient;
import com.vincent.rsf.openApi.service.phyz.ErpReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import static com.vincent.rsf.openApi.controller.AuthController.SIMULATED_DATA_ENABLE;
@@ -32,6 +37,9 @@
    @Resource
    private ErpReportService erpReportService;
    @Autowired(required = false)
    private WmsServerFeignClient wmsServerFeignClient;
    @ApiOperation("仓库信息同步")
@@ -116,10 +124,16 @@
        JSONArray params = paramsFormat(objParams);
        List<Order> orderList = JSON.parseArray(params.toJSONString(), Order.class);
        // 数据处理,转发server
        StringBuffer errorMsg = new StringBuffer();
        for (Order order : orderList) {
            erpReportService.addOrderToServer(order);
            String i = erpReportService.addOrderToServer(order);
            if (i.equals("200")){
                errorMsg.append(order.getOrderNo()+"下发成功;");
            } else {
                errorMsg.append(order.getOrderNo()+"下发失败,原因:"+i+";");
            }
        }
        return CommonResponse.ok();
        return CommonResponse.ok(errorMsg.toString());
    }
    @ApiOperation("入/出库任务通知单取消")
@@ -141,7 +155,7 @@
    @ApiOperation("库存查询明细")
    @PostMapping("/inventory/details")
    public CommonResponse queryInventoryDetails(@RequestBody JSONObject params) {
    public CommonResponse queryInventoryDetails(@RequestBody InventoryQueryCondition condition) {
        if (SIMULATED_DATA_ENABLE.equals("1")) {
            String x = "[\n" +
                    "  {\n" +
@@ -187,10 +201,77 @@
            return CommonResponse.ok(JSONArray.parseArray(map.toJSONString(), InventoryDetails.class));
        }
        InventoryQueryCondition condition = JSON.parseObject(params.toJSONString(), InventoryQueryCondition.class);
        // 数据处理,转发server
        List<InventoryDetails> inventoryDetails = Lists.newArrayList();
        return new CommonResponse().setCode(200).setData(inventoryDetails);
        try {
            if (wmsServerFeignClient == null) {
                log.warn("WmsServerFeignClient未注入,无法进行调用");
                return CommonResponse.error("服务未初始化");
            }
            // 参数验证
            if (condition == null) {
                return CommonResponse.error("查询条件不能为空");
            }
            log.info("库存查询明细请求参数: {}", JSON.toJSONString(condition));
            // 直接传递实体类,Feign会自动序列化为JSON
            R result = wmsServerFeignClient.queryInventoryDetails(condition);
            log.info("库存查询明细返回结果: {}", JSON.toJSONString(result));
            if (result != null) {
                // R类继承自HashMap,使用get方法获取值
                Integer code = (Integer) result.get("code");
                String msg = (String) result.get("msg");
                Object data = result.get("data");
                if (code != null && code == 200) {
                    // 将Map列表转换为InventoryDetails列表
                    if (data != null) {
                        @SuppressWarnings("unchecked")
                        List<Map<String, Object>> dataList = (List<Map<String, Object>>) data;
                        List<InventoryDetails> inventoryDetails = new ArrayList<>();
                        for (Map<String, Object> item : dataList) {
                            InventoryDetails details = JSON.parseObject(JSON.toJSONString(item), InventoryDetails.class);
                            inventoryDetails.add(details);
                        }
                        return CommonResponse.ok(inventoryDetails);
                    } else {
                        return CommonResponse.ok(new ArrayList<>());
                    }
                } else {
                    return CommonResponse.error(msg != null ? msg : "查询失败");
                }
            } else {
                return CommonResponse.error("查询失败:返回结果为空");
            }
        } catch (Exception e) {
            log.error("库存查询明细失败", e);
            // 过滤错误消息中的URL,只保留错误类型
            String errorMessage = e.getMessage();
            if (errorMessage != null) {
                // 如果包含"executing",说明是HTTP请求错误,去掉URL部分
                if (errorMessage.contains("executing")) {
                    int executingIndex = errorMessage.indexOf("executing");
                    if (executingIndex > 0) {
                        // 提取"executing"之前的部分(如"Read timed out")
                        errorMessage = errorMessage.substring(0, executingIndex).trim();
                    } else {
                        // 如果"executing"在开头,使用默认错误消息
                        errorMessage = "请求超时";
                    }
                }
                // 如果包含"http://"或"https://",也尝试去掉URL部分
                else if (errorMessage.contains("http://") || errorMessage.contains("https://")) {
                    // 使用正则表达式去掉URL
                    errorMessage = errorMessage.replaceAll("https?://[^\\s]+", "").trim();
                    if (errorMessage.isEmpty()) {
                        errorMessage = "请求失败";
                    }
                }
            }
            return CommonResponse.error("查询失败:" + (errorMessage != null && !errorMessage.isEmpty() ? errorMessage : "未知错误"));
        }
    }
    @ApiOperation("库存查询汇总")