From fc500457599f77a019d4d6fd9a61a306c5bf2c95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8C=AB=E7=8C=ABguowen?= <9290821+guowen-the-cat@user.noreply.gitee.com> Date: Tue, 24 Jun 2025 10:34:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=A3=E9=80=89=E5=A4=A7=E5=B1=8F=E5=90=8E?= =?UTF-8?q?=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WarehousePortController.java | 129 ++++++++++++++++++ .../api/service/IProductPortService.java | 29 ++++ .../service/impl/ProductPortServiceImpl.java | 46 +++++++ 3 files changed, 204 insertions(+) create mode 100644 ruoyi-admin/src/main/java/com/ruoyi/api/controller/WarehousePortController.java create mode 100644 ruoyi-admin/src/main/java/com/ruoyi/api/service/IProductPortService.java create mode 100644 ruoyi-admin/src/main/java/com/ruoyi/api/service/impl/ProductPortServiceImpl.java diff --git a/ruoyi-admin/src/main/java/com/ruoyi/api/controller/WarehousePortController.java b/ruoyi-admin/src/main/java/com/ruoyi/api/controller/WarehousePortController.java new file mode 100644 index 0000000..2d525c8 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/api/controller/WarehousePortController.java @@ -0,0 +1,129 @@ +package com.ruoyi.api.controller; + +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.api.service.IProductPortService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +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 io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.HashMap; + +/** + * 仓库和点位API接口 + * + * @author lsy + * @date 2025-06-23 + */ +@Api(tags = "仓库和点位接口") +@RestController +@RequestMapping("/api/warehouse") +public class WarehousePortController extends BaseController { + + @Autowired + private JdbcTemplate jdbcTemplate; + + @Autowired + private IProductPortService productPortService; + + /** + * 获取仓库列表 + */ + @ApiOperation("获取仓库列表") + @GetMapping("/list") + public AjaxResult getWarehouseList() { + try { + String sql = "SELECT warehouse_id, warehouse_no, warehouse_name, address, c_desc " + + "FROM bas_warehouse " + + "WHERE is_current = 'Y' " + + "ORDER BY warehouse_no"; + + List> list = jdbcTemplate.queryForList(sql); + return success(list); + } catch (Exception e) { + logger.error("查询仓库列表失败:", e); + return error("查询仓库列表失败"); + } + } + + /** + * 根据仓库ID获取点位列表 + */ + @ApiOperation("获取点位列表") + @GetMapping("/port/{warehouseId}") + public AjaxResult getPortList(@ApiParam(value = "仓库ID", required = true) @PathVariable("warehouseId") String warehouseId) { + if (warehouseId == null || warehouseId.trim().isEmpty()) { + return error("仓库ID不能为空"); + } + try { + Map params = new HashMap<>(); + params.put("warehouseId", warehouseId); + params.put("portType", 2); + List> portList = productPortService.selectPortListByParams(params); + return success(portList); + } catch (Exception e) { + logger.error("查询点位列表失败:", e); + return error("查询点位列表失败"); + } + } + + /** + * 根据工位号数组查询任务数据 + */ + @ApiOperation("根据工位号查询任务数据") + @PostMapping("/workstation/jobs") + public AjaxResult getJobsByWorkstations(@RequestBody Map request) { + try { + @SuppressWarnings("unchecked") + List workstationNumbers = (List) request.get("workstationNumbers"); + String warehouseId = (String) request.get("warehouseId"); + if (workstationNumbers == null || workstationNumbers.isEmpty()) { + return error("工位号数组不能为空"); + } + if (warehouseId == null || warehouseId.trim().isEmpty()) { + return error("仓库ID不能为空"); + } + + StringBuilder placeholders = new StringBuilder(); + for (int i = 0; i < workstationNumbers.size(); i++) { + placeholders.append(i == 0 ? "?" : ", ?"); + } + + String sql = "SELECT j.*, jd.out_quantity, jd.product_id, bp.product_name " + + "FROM mydo_job j " + + "LEFT JOIN mydo_job_detail jd ON j.job_id = jd.job_id " + + "LEFT JOIN bas_product bp ON jd.product_id = bp.product_id " + + "WHERE j.exit_id IN (" + placeholders.toString() + ") " + + "AND j.warehouse_id = ? "; + + Object[] params = new Object[workstationNumbers.size() + 1]; + for (int i = 0; i < workstationNumbers.size(); i++) { + params[i] = workstationNumbers.get(i); + } + params[workstationNumbers.size()] = warehouseId; + List> queryResult = jdbcTemplate.queryForList(sql, params); + + // 按工位号分组 + Map>> groupedResult = new HashMap<>(); + for (Map job : queryResult) { + String exitId = (String) job.get("exit_id"); + groupedResult.computeIfAbsent(exitId, k -> new ArrayList<>()).add(job); + } + + return success(groupedResult); + } catch (Exception e) { + logger.error("查询工位任务数据失败:", e); + return error("查询工位任务数据失败"); + } + } +} \ No newline at end of file diff --git a/ruoyi-admin/src/main/java/com/ruoyi/api/service/IProductPortService.java b/ruoyi-admin/src/main/java/com/ruoyi/api/service/IProductPortService.java new file mode 100644 index 0000000..b8bd37b --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/api/service/IProductPortService.java @@ -0,0 +1,29 @@ +package com.ruoyi.api.service; + +import java.util.List; +import java.util.Map; + +/** + * 点位查询Service接口 + * + * @author lsy + * @date 2025-06-23 + */ +public interface IProductPortService { + + /** + * 根据仓库ID查询点位列表 + * + * @param warehouseId 仓库ID + * @return 点位列表 + */ + public List> selectPortListByWarehouseId(String warehouseId); + + /** + * 根据查询条件获取点位列表 + * + * @param params 查询参数,包含 warehouseId(仓库ID)和 portType(点位类型) + * @return 点位列表 + */ + public List> selectPortListByParams(Map params); +} \ No newline at end of file diff --git a/ruoyi-admin/src/main/java/com/ruoyi/api/service/impl/ProductPortServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/api/service/impl/ProductPortServiceImpl.java new file mode 100644 index 0000000..8c855e7 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/api/service/impl/ProductPortServiceImpl.java @@ -0,0 +1,46 @@ +package com.ruoyi.api.service.impl; + +import com.ruoyi.api.service.IProductPortService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Map; + +/** + * 点位查询Service实现 + * + * @author lsy + * @date 2025-06-23 + */ +@Service +public class ProductPortServiceImpl implements IProductPortService { + + @Autowired + private JdbcTemplate jdbcTemplate; + + /** + * 根据仓库ID查询点位列表 + * + * @param warehouseId 仓库ID + * @return 点位列表 + */ + @Override + public List> selectPortListByWarehouseId(String warehouseId) { + String sql = "SELECT port_name, port_desc FROM bas_product_port WHERE warehouse_id = ?"; + return jdbcTemplate.queryForList(sql, warehouseId); + } + + /** + * 根据查询条件获取点位列表 + * + * @param params 查询参数 + * @return 点位列表 + */ + @Override + public List> selectPortListByParams(Map params) { + String sql = "SELECT port_name, port_desc FROM bas_product_port WHERE warehouse_id = ? AND port_type = ?"; + return jdbcTemplate.queryForList(sql, params.get("warehouseId"), params.get("portType")); + } +} \ No newline at end of file