| | |
| | | |
| | | 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.feign.wms.fallback.WmsServerFeignClientFallback; |
| | | 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.RestController; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | return CommonResponse.ok(); |
| | | } |
| | | |
| | | @ApiOperation("库存查询明细(表单提交)") |
| | | @PostMapping(value = "/inventory/details", consumes = "application/x-www-form-urlencoded") |
| | | public CommonResponse queryInventoryDetailsForm(HttpServletRequest request) { |
| | | // 从表单参数构建查询条件 |
| | | InventoryQueryCondition condition = buildConditionFromRequestParams(request); |
| | | // 调用JSON处理方法 |
| | | return queryInventoryDetails(condition); |
| | | } |
| | | |
| | | @ApiOperation("库存查询明细") |
| | | @PostMapping("/inventory/details") |
| | | public CommonResponse queryInventoryDetails(@RequestBody InventoryQueryCondition condition) { |
| | | @PostMapping(value = "/inventory/details", consumes = "application/json") |
| | | public CommonResponse queryInventoryDetails(@RequestBody(required = false) InventoryQueryCondition condition) { |
| | | // JSON方式:支持不传递参数({}或null或空请求体),创建默认的空查询条件对象 |
| | | if (condition == null) { |
| | | condition = new InventoryQueryCondition(); |
| | | } |
| | | |
| | | if (SIMULATED_DATA_ENABLE.equals("1")) { |
| | | String x = "[\n" + |
| | | " {\n" + |
| | |
| | | return CommonResponse.error("服务未初始化"); |
| | | } |
| | | |
| | | // 参数验证 |
| | | if (condition == null) { |
| | | return CommonResponse.error("查询条件不能为空"); |
| | | } |
| | | |
| | | log.info("库存查询明细请求参数: {}", JSON.toJSONString(condition)); |
| | | |
| | | // 直接传递实体类,Feign会自动序列化为JSON |
| | |
| | | } |
| | | } 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 : "未知错误")); |
| | | String errorMessage = WmsServerFeignClientFallback.filterErrorMessage(e); |
| | | return CommonResponse.error(errorMessage); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation("库存查询汇总(表单提交)") |
| | | @PostMapping(value = "/inventory/summary", consumes = "application/x-www-form-urlencoded") |
| | | public CommonResponse queryInventorySummaryForm(HttpServletRequest request) { |
| | | // 从表单参数构建查询条件 |
| | | InventoryQueryCondition condition = buildConditionFromRequestParams(request); |
| | | // 调用JSON处理方法 |
| | | return queryInventorySummary(condition); |
| | | } |
| | | |
| | | @ApiOperation("库存查询汇总") |
| | | @PostMapping("/inventory/summary") |
| | | public CommonResponse queryInventorySummary(@RequestBody JSONObject params) { |
| | | @PostMapping(value = "/inventory/summary", consumes = "application/json") |
| | | public CommonResponse queryInventorySummary(@RequestBody(required = false) InventoryQueryCondition condition) { |
| | | // JSON方式:支持不传递参数({}或null或空请求体),创建默认的空查询条件对象 |
| | | if (condition == null) { |
| | | condition = new InventoryQueryCondition(); |
| | | } |
| | | |
| | | if (SIMULATED_DATA_ENABLE.equals("1")) { |
| | | String s = "{\n" + |
| | | " \"code\": 200,\n" + |
| | | " \"msg\": \"操作成功\",\n" + |
| | | " \"data\": [\n" + |
| | | " {\n" + |
| | | " \"wareHouseId\": \"WH001\",\n" + |
| | | " \"wareHouseName\": \"原料仓库\",\n" + |
| | | " \"matNr\": \"MAT10001\",\n" + |
| | | " \"makTx\": \"钢材Q235\",\n" + |
| | | " \"spec\": \"国标GB/T700-2006\",\n" + |
| | | " \"anfme\": 10.5,\n" + |
| | | " \"unit\": \"吨\",\n" + |
| | | " \"stockOrgId\": \"ORG001\",\n" + |
| | | " \"batch\": \"BATCH20260106001\",\n" + |
| | | " \"planNo\": \"Plan20260106006\"\n" + |
| | | " },\n" + |
| | | " {\n" + |
| | | " \"wareHouseId\": \"WH001\",\n" + |
| | | " \"wareHouseName\": \"原料仓库\",\n" + |
| | | " \"matNr\": \"MAT10002\",\n" + |
| | | " \"makTx\": \"铝型材6061\",\n" + |
| | | " \"spec\": \"国标GB/T3190-2008\",\n" + |
| | | " \"anfme\": 20.3,\n" + |
| | | " \"unit\": \"吨\",\n" + |
| | | " \"stockOrgId\": \"ORG001\",\n" + |
| | | " \"batch\": \"BATCH20260106002\",\n" + |
| | | " \"planNo\": \"Plan20260106005\"\n" + |
| | | " },\n" + |
| | | " {\n" + |
| | | " \"wareHouseId\": \"WH002\",\n" + |
| | | " \"wareHouseName\": \"成品仓库\",\n" + |
| | | " \"matNr\": \"MAT30001\",\n" + |
| | | " \"makTx\": \"电机成品\",\n" + |
| | | " \"spec\": \"380V 50Hz 15KW\",\n" + |
| | | " \"anfme\": 100,\n" + |
| | | " \"unit\": \"台\",\n" + |
| | | " \"stockOrgId\": \"ORG001\",\n" + |
| | | " \"batch\": \"BATCH20260106003\",\n" + |
| | | " \"planNo\": \"Plan20260106004\"\n" + |
| | | " }\n" + |
| | | " ]\n" + |
| | | "}"; |
| | | return JSONObject.parseObject(s, CommonResponse.class); |
| | | String x = "[\n" + |
| | | " {\n" + |
| | | " \"wareHouseId\": \"WH001\",\n" + |
| | | " \"wareHouseName\": \"原料仓库\",\n" + |
| | | " \"matNr\": \"MAT10001\",\n" + |
| | | " \"matTx\": \"钢材Q235\",\n" + |
| | | " \"spec\": \"国标GB/T700-2006\",\n" + |
| | | " \"anfme\": 10.5,\n" + |
| | | " \"unit\": \"吨\",\n" + |
| | | " \"stockOrgId\": \"ORG001\",\n" + |
| | | " \"batch\": \"BATCH20260106001\",\n" + |
| | | " \"planNo\": \"Plan20260106006\"\n" + |
| | | " },\n" + |
| | | " {\n" + |
| | | " \"wareHouseId\": \"WH001\",\n" + |
| | | " \"wareHouseName\": \"原料仓库\",\n" + |
| | | " \"matNr\": \"MAT10002\",\n" + |
| | | " \"matTx\": \"铝型材6061\",\n" + |
| | | " \"spec\": \"国标GB/T3190-2008\",\n" + |
| | | " \"anfme\": 20.3,\n" + |
| | | " \"unit\": \"吨\",\n" + |
| | | " \"stockOrgId\": \"ORG001\",\n" + |
| | | " \"batch\": \"BATCH20260106002\",\n" + |
| | | " \"planNo\": \"Plan20260106005\"\n" + |
| | | " },\n" + |
| | | " {\n" + |
| | | " \"wareHouseId\": \"WH002\",\n" + |
| | | " \"wareHouseName\": \"成品仓库\",\n" + |
| | | " \"matNr\": \"MAT30001\",\n" + |
| | | " \"matTx\": \"电机成品\",\n" + |
| | | " \"spec\": \"380V 50Hz 15KW\",\n" + |
| | | " \"anfme\": 100,\n" + |
| | | " \"unit\": \"台\",\n" + |
| | | " \"stockOrgId\": \"ORG001\",\n" + |
| | | " \"batch\": \"BATCH20260106003\",\n" + |
| | | " \"planNo\": \"Plan20260106004\"\n" + |
| | | " }\n" + |
| | | "]"; |
| | | return CommonResponse.ok(JSONArray.parseArray(x, InventorySummary.class)); |
| | | } |
| | | |
| | | InventoryQueryCondition condition = JSON.parseObject(params.toJSONString(), InventoryQueryCondition.class); |
| | | // 数据处理,转发server |
| | | List<InventorySummary> inventorySummaries = Lists.newArrayList(); |
| | | return new CommonResponse().setCode(200).setData(inventorySummaries); |
| | | |
| | | try { |
| | | if (wmsServerFeignClient == null) { |
| | | log.warn("WmsServerFeignClient未注入,无法进行调用"); |
| | | return CommonResponse.error("服务未初始化"); |
| | | } |
| | | |
| | | log.info("库存查询汇总请求参数: {}", JSON.toJSONString(condition)); |
| | | |
| | | // 直接传递实体类,Feign会自动序列化为JSON |
| | | R result = wmsServerFeignClient.queryInventorySummary(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列表转换为InventorySummary列表 |
| | | if (data != null) { |
| | | @SuppressWarnings("unchecked") |
| | | List<Map<String, Object>> dataList = (List<Map<String, Object>>) data; |
| | | List<InventorySummary> inventorySummaries = new ArrayList<>(); |
| | | for (Map<String, Object> item : dataList) { |
| | | InventorySummary summary = JSON.parseObject(JSON.toJSONString(item), InventorySummary.class); |
| | | inventorySummaries.add(summary); |
| | | } |
| | | return CommonResponse.ok(inventorySummaries); |
| | | } else { |
| | | return CommonResponse.ok(new ArrayList<>()); |
| | | } |
| | | } else { |
| | | return CommonResponse.error(msg != null ? msg : "查询失败"); |
| | | } |
| | | } else { |
| | | return CommonResponse.error("查询失败:返回结果为空"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("库存查询汇总失败", e); |
| | | String errorMessage = WmsServerFeignClientFallback.filterErrorMessage(e); |
| | | return CommonResponse.error(errorMessage); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation("盘点结果确认") |
| | |
| | | } |
| | | // endregion |
| | | |
| | | |
| | | /** |
| | | * 从请求参数(表单数据)构建查询条件对象 |
| | | * 支持 application/x-www-form-urlencoded 格式 |
| | | */ |
| | | private InventoryQueryCondition buildConditionFromRequestParams(HttpServletRequest request) { |
| | | InventoryQueryCondition condition = new InventoryQueryCondition(); |
| | | |
| | | // 从请求参数中获取字段值 |
| | | String wareHouseId = request.getParameter("wareHouseId"); |
| | | String locId = request.getParameter("locId"); |
| | | String matNr = request.getParameter("matNr"); |
| | | String matGroup = request.getParameter("matGroup"); |
| | | String orderNo = request.getParameter("orderNo"); |
| | | String planNo = request.getParameter("planNo"); |
| | | String batch = request.getParameter("batch"); |
| | | |
| | | // 设置字段值(如果存在) |
| | | if (wareHouseId != null && !wareHouseId.isEmpty()) { |
| | | condition.setWareHouseId(wareHouseId); |
| | | } |
| | | if (locId != null && !locId.isEmpty()) { |
| | | condition.setLocId(locId); |
| | | } |
| | | if (matNr != null && !matNr.isEmpty()) { |
| | | condition.setMatNr(matNr); |
| | | } |
| | | if (matGroup != null && !matGroup.isEmpty()) { |
| | | condition.setMatGroup(matGroup); |
| | | } |
| | | if (orderNo != null && !orderNo.isEmpty()) { |
| | | condition.setOrderNo(orderNo); |
| | | } |
| | | if (planNo != null && !planNo.isEmpty()) { |
| | | condition.setPlanNo(planNo); |
| | | } |
| | | if (batch != null && !batch.isEmpty()) { |
| | | condition.setBatch(batch); |
| | | } |
| | | |
| | | return condition; |
| | | } |
| | | |
| | | } |