|
|
@@ -0,0 +1,155 @@
|
|
|
+package com.jeesite.modules.mes.web;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.ui.Model;
|
|
|
+import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+
|
|
|
+import com.alibaba.druid.util.StringUtils;
|
|
|
+import com.jeesite.common.config.Global;
|
|
|
+import com.jeesite.common.entity.Page;
|
|
|
+import com.jeesite.common.web.BaseController;
|
|
|
+import com.jeesite.modules.mes.entity.MesProductCncToolGeo;
|
|
|
+import com.jeesite.modules.mes.service.MesProductCncToolGeoService;
|
|
|
+
|
|
|
+/**
|
|
|
+ * CNC刀长半径采集Controller
|
|
|
+ * 库中一次提交存一条(# 拼串);列表一行对应一次提交,默认展示 1 号刀刀长/半径
|
|
|
+ * @author system
|
|
|
+ * @version 2026-08-11
|
|
|
+ */
|
|
|
+@Controller
|
|
|
+@RequestMapping(value = "${adminPath}/mes/mesProductCncToolGeo")
|
|
|
+public class MesProductCncToolGeoController extends BaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MesProductCncToolGeoService mesProductCncToolGeoService;
|
|
|
+
|
|
|
+ @ModelAttribute
|
|
|
+ public MesProductCncToolGeo get(String id, boolean isNewRecord) {
|
|
|
+ return mesProductCncToolGeoService.get(id, isNewRecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequiresPermissions("mes:mesProductCncToolGeo:view")
|
|
|
+ @RequestMapping(value = {"list", ""})
|
|
|
+ public String list(MesProductCncToolGeo mesProductCncToolGeo, Model model) {
|
|
|
+ model.addAttribute("mesProductCncToolGeo", mesProductCncToolGeo);
|
|
|
+ return "modules/mes/mesProductCncToolGeoList";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 列表数据:一次提交一行;刀长/半径取指定刀号(默认 1 号)的段值
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesProductCncToolGeo:view")
|
|
|
+ @RequestMapping(value = "listData")
|
|
|
+ @ResponseBody
|
|
|
+ public Page<MesProductCncToolGeo> listData(MesProductCncToolGeo mesProductCncToolGeo,
|
|
|
+ HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ Integer displayToolNo = mesProductCncToolGeo.getToolNo();
|
|
|
+ if (displayToolNo == null || displayToolNo <= 0) {
|
|
|
+ displayToolNo = 1;
|
|
|
+ }
|
|
|
+ mesProductCncToolGeo.setToolNo(null);
|
|
|
+ mesProductCncToolGeo.setPage(new Page<>(request, response));
|
|
|
+ Page<MesProductCncToolGeo> page = mesProductCncToolGeoService.findPage(mesProductCncToolGeo);
|
|
|
+ if (page.getList() != null) {
|
|
|
+ for (MesProductCncToolGeo row : page.getList()) {
|
|
|
+ fillToolSegment(row, displayToolNo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequiresPermissions("mes:mesProductCncToolGeo:view")
|
|
|
+ @RequestMapping(value = "detail")
|
|
|
+ public String detail(MesProductCncToolGeo mesProductCncToolGeo, Model model) {
|
|
|
+ model.addAttribute("mesProductCncToolGeo", mesProductCncToolGeo);
|
|
|
+ model.addAttribute("toolRows", parseToolGeo(mesProductCncToolGeo.getToolLength(),
|
|
|
+ mesProductCncToolGeo.getToolRadius()));
|
|
|
+ return "modules/mes/mesProductCncToolGeoDetail";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 供工机客户端上传(匿名)
|
|
|
+ */
|
|
|
+ @PostMapping(value = "saveToolGeo")
|
|
|
+ @ResponseBody
|
|
|
+ public String saveToolGeo(HttpServletRequest request) {
|
|
|
+ String deviceCode = request.getParameter("deviceCode");
|
|
|
+ String ucode = request.getParameter("ucode");
|
|
|
+ String toolLength = request.getParameter("toolLength");
|
|
|
+ String toolRadius = request.getParameter("toolRadius");
|
|
|
+ if (StringUtils.isEmpty(deviceCode) || toolLength == null || toolRadius == null) {
|
|
|
+ return renderResult(Global.FALSE, text("参数错误!"));
|
|
|
+ }
|
|
|
+ String[] lens = toolLength.split("#", -1);
|
|
|
+ String[] rads = toolRadius.split("#", -1);
|
|
|
+ if (lens.length == 0 || lens.length != rads.length) {
|
|
|
+ return renderResult(Global.FALSE, text("刀长/半径段数不一致!"));
|
|
|
+ }
|
|
|
+ boolean allEmpty = true;
|
|
|
+ for (int i = 0; i < lens.length; i++) {
|
|
|
+ if ((lens[i] != null && !lens[i].trim().isEmpty())
|
|
|
+ || (rads[i] != null && !rads[i].trim().isEmpty())) {
|
|
|
+ allEmpty = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (allEmpty) {
|
|
|
+ return renderResult(Global.FALSE, text("刀长半径数据为空!"));
|
|
|
+ }
|
|
|
+
|
|
|
+ MesProductCncToolGeo entity = new MesProductCncToolGeo();
|
|
|
+ entity.setDeviceCode(deviceCode.trim());
|
|
|
+ entity.setToolLength(toolLength);
|
|
|
+ entity.setToolRadius(toolRadius);
|
|
|
+ entity.setCreateBy(StringUtils.isEmpty(ucode) ? "system" : ucode);
|
|
|
+ mesProductCncToolGeoService.save(entity);
|
|
|
+ return renderResult(Global.TRUE, text("操作成功!"));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 列表展示:用指定刀号的段值覆盖 toolLength/toolRadius,并写入 toolNo
|
|
|
+ */
|
|
|
+ private void fillToolSegment(MesProductCncToolGeo row, int toolNo) {
|
|
|
+ String lengthRaw = row.getToolLength();
|
|
|
+ String radiusRaw = row.getToolRadius();
|
|
|
+ String[] lens = lengthRaw == null ? new String[0] : lengthRaw.split("#", -1);
|
|
|
+ String[] rads = radiusRaw == null ? new String[0] : radiusRaw.split("#", -1);
|
|
|
+ int idx = toolNo - 1;
|
|
|
+ row.setToolNo(toolNo);
|
|
|
+ row.setToolLength(idx >= 0 && idx < lens.length ? nullToEmpty(lens[idx]) : "");
|
|
|
+ row.setToolRadius(idx >= 0 && idx < rads.length ? nullToEmpty(rads[idx]) : "");
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 详情页:全部刀号段(含空) */
|
|
|
+ private List<Map<String, String>> parseToolGeo(String toolLength, String toolRadius) {
|
|
|
+ List<Map<String, String>> rows = new ArrayList<>();
|
|
|
+ String[] lens = toolLength == null ? new String[0] : toolLength.split("#", -1);
|
|
|
+ String[] rads = toolRadius == null ? new String[0] : toolRadius.split("#", -1);
|
|
|
+ int n = Math.max(lens.length, rads.length);
|
|
|
+ for (int i = 0; i < n; i++) {
|
|
|
+ Map<String, String> row = new HashMap<>();
|
|
|
+ row.put("toolNo", String.valueOf(i + 1));
|
|
|
+ row.put("length", i < lens.length ? nullToEmpty(lens[i]) : "");
|
|
|
+ row.put("radius", i < rads.length ? nullToEmpty(rads[i]) : "");
|
|
|
+ rows.add(row);
|
|
|
+ }
|
|
|
+ return rows;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String nullToEmpty(String s) {
|
|
|
+ return s == null ? "" : s.trim();
|
|
|
+ }
|
|
|
+}
|