|
@@ -0,0 +1,367 @@
|
|
|
|
|
+package com.jeesite.modules.mes.web;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.LinkedHashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.jeesite.common.lang.StringUtils;
|
|
|
|
|
+import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+import org.springframework.ui.Model;
|
|
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
|
|
+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.jeesite.common.config.Global;
|
|
|
|
|
+import com.jeesite.common.entity.Page;
|
|
|
|
|
+import com.jeesite.common.web.BaseController;
|
|
|
|
|
+import com.jeesite.modules.mes.entity.MesProductCncParam;
|
|
|
|
|
+import com.jeesite.modules.mes.service.MesProductCncParamService;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * CNC过程参数记录表Controller
|
|
|
|
|
+ * @author sxl
|
|
|
|
|
+ * @version 2026-07-24
|
|
|
|
|
+ */
|
|
|
|
|
+@Controller
|
|
|
|
|
+@RequestMapping(value = "${adminPath}/mes/mesProductCncParam")
|
|
|
|
|
+public class MesProductCncParamController extends BaseController {
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private MesProductCncParamService mesProductCncParamService;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取数据
|
|
|
|
|
+ */
|
|
|
|
|
+ @ModelAttribute
|
|
|
|
|
+ public MesProductCncParam get(String id, boolean isNewRecord) {
|
|
|
|
|
+ return mesProductCncParamService.get(id, isNewRecord);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询列表
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequiresPermissions("mes:mesProductCncParam:view")
|
|
|
|
|
+ @RequestMapping(value = {"list", ""})
|
|
|
|
|
+ public String list(MesProductCncParam mesProductCncParam, Model model) {
|
|
|
|
|
+ model.addAttribute("mesProductCncParam", mesProductCncParam);
|
|
|
|
|
+ return "modules/mes/mesProductCncParamList";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询列表数据
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequiresPermissions("mes:mesProductCncParam:view")
|
|
|
|
|
+ @RequestMapping(value = "listData")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public Page<MesProductCncParam> listData(MesProductCncParam mesProductCncParam, HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
|
+ mesProductCncParam.setPage(new Page<>(request, response));
|
|
|
|
|
+ Page<MesProductCncParam> page = mesProductCncParamService.findPage(mesProductCncParam);
|
|
|
|
|
+ return page;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查看编辑表单
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequiresPermissions("mes:mesProductCncParam:view")
|
|
|
|
|
+ @RequestMapping(value = "form")
|
|
|
|
|
+ public String form(MesProductCncParam mesProductCncParam, Model model) {
|
|
|
|
|
+ model.addAttribute("mesProductCncParam", mesProductCncParam);
|
|
|
|
|
+ return "modules/mes/mesProductCncParamForm";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查看详情(解析CNC参数内容)
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequiresPermissions("mes:mesProductCncParam:view")
|
|
|
|
|
+ @RequestMapping(value = "detail")
|
|
|
|
|
+ public String detail(MesProductCncParam mesProductCncParam, Model model) {
|
|
|
|
|
+ model.addAttribute("mesProductCncParam", mesProductCncParam);
|
|
|
|
|
+ List<JSONObject> paramRows = parseCncContent(mesProductCncParam.getContent());
|
|
|
|
|
+ normalizeAliasKeys(paramRows);
|
|
|
|
|
+ model.addAttribute("paramRows", paramRows);
|
|
|
|
|
+ model.addAttribute("paramLabels", CNC_PARAM_LABELS);
|
|
|
|
|
+ model.addAttribute("paramCodes", new ArrayList<>(CNC_PARAM_LABELS.keySet()));
|
|
|
|
|
+ model.addAttribute("paramItems", buildParamItems(paramRows));
|
|
|
|
|
+ return "modules/mes/mesProductCncParamDetail";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** CNC参数代码与中文名称映射(展示用主代码 = 实际字段名) */
|
|
|
|
|
+ private static final Map<String, String> CNC_PARAM_LABELS = new LinkedHashMap<>();
|
|
|
|
|
+ /** 同一参数的别名(旧字段名 → 主代码),用于取值兼容 */
|
|
|
|
|
+ private static final Map<String, String> CNC_PARAM_ALIASES = new LinkedHashMap<>();
|
|
|
|
|
+ static {
|
|
|
|
|
+ CNC_PARAM_LABELS.put("spindleActSpeed", "主轴转速");
|
|
|
|
|
+ CNC_PARAM_LABELS.put("machineX", "X轴机械坐标");
|
|
|
|
|
+ CNC_PARAM_LABELS.put("machineY", "Y轴机械坐标");
|
|
|
|
|
+ CNC_PARAM_LABELS.put("machineZ", "Z轴机械坐标");
|
|
|
|
|
+ CNC_PARAM_LABELS.put("actPressure", "实际压力值");
|
|
|
|
|
+ CNC_PARAM_LABELS.put("aaOffValZ", "Z轴叠加总量");
|
|
|
|
|
+ CNC_PARAM_LABELS.put("cutActSpeedX", "X轴进给率实际值");
|
|
|
|
|
+ CNC_PARAM_LABELS.put("cutActSpeedY", "Y轴进给率实际值");
|
|
|
|
|
+ CNC_PARAM_LABELS.put("cutActSpeedZ", "Z轴进给率实际值");
|
|
|
|
|
+ CNC_PARAM_LABELS.put("r210", "参数R210-恒压力开启延时");
|
|
|
|
|
+ CNC_PARAM_LABELS.put("r211", "参数R211-设定压力值");
|
|
|
|
|
+ CNC_PARAM_LABELS.put("r212", "参数R212-调整下限值");
|
|
|
|
|
+ CNC_PARAM_LABELS.put("r213", "参数R213-调整速度");
|
|
|
|
|
+ CNC_PARAM_LABELS.put("r214", "参数R214-叠加极限值");
|
|
|
|
|
+ CNC_PARAM_LABELS.put("r215", "参数R215-压力波动值");
|
|
|
|
|
+ CNC_PARAM_LABELS.put("r216", "参数R216-采集取样次数");
|
|
|
|
|
+ CNC_PARAM_LABELS.put("r217", "参数R217-手动调整值");
|
|
|
|
|
+ CNC_PARAM_LABELS.put("r218", "参数R218-暂停再启动延时");
|
|
|
|
|
+ CNC_PARAM_LABELS.put("r999", "参数R999-投影半径");
|
|
|
|
|
+
|
|
|
|
|
+ // 旧字段名兼容
|
|
|
|
|
+ CNC_PARAM_ALIASES.put("SP_SPEED", "spindleActSpeed");
|
|
|
|
|
+ CNC_PARAM_ALIASES.put("X_MCS", "machineX");
|
|
|
|
|
+ CNC_PARAM_ALIASES.put("Y_MCS", "machineY");
|
|
|
|
|
+ CNC_PARAM_ALIASES.put("Z_MCS", "machineZ");
|
|
|
|
|
+ CNC_PARAM_ALIASES.put("Actual_Pressure", "actPressure");
|
|
|
|
|
+ CNC_PARAM_ALIASES.put("AA_OFF_VAL_Z", "aaOffValZ");
|
|
|
|
|
+ CNC_PARAM_ALIASES.put("X_Feed", "cutActSpeedX");
|
|
|
|
|
+ CNC_PARAM_ALIASES.put("Y_Feed", "cutActSpeedY");
|
|
|
|
|
+ CNC_PARAM_ALIASES.put("Z_Feed", "cutActSpeedZ");
|
|
|
|
|
+ CNC_PARAM_ALIASES.put("R210", "r210");
|
|
|
|
|
+ CNC_PARAM_ALIASES.put("R211", "r211");
|
|
|
|
|
+ CNC_PARAM_ALIASES.put("R212", "r212");
|
|
|
|
|
+ CNC_PARAM_ALIASES.put("R213", "r213");
|
|
|
|
|
+ CNC_PARAM_ALIASES.put("R214", "r214");
|
|
|
|
|
+ CNC_PARAM_ALIASES.put("R215", "r215");
|
|
|
|
|
+ CNC_PARAM_ALIASES.put("R216", "r216");
|
|
|
|
|
+ CNC_PARAM_ALIASES.put("R217", "r217");
|
|
|
|
|
+ CNC_PARAM_ALIASES.put("R218", "r218");
|
|
|
|
|
+ CNC_PARAM_ALIASES.put("R999", "r999");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 单条记录时,构建参数代码/名称/值列表(含未映射字段)
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<Map<String, Object>> buildParamItems(List<JSONObject> paramRows) {
|
|
|
|
|
+ List<Map<String, Object>> items = new ArrayList<>();
|
|
|
|
|
+ if (paramRows == null || paramRows.size() != 1) {
|
|
|
|
|
+ return items;
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONObject row = paramRows.get(0);
|
|
|
|
|
+ for (Map.Entry<String, String> labelEntry : CNC_PARAM_LABELS.entrySet()) {
|
|
|
|
|
+ Map<String, Object> item = new LinkedHashMap<>();
|
|
|
|
|
+ item.put("code", labelEntry.getKey());
|
|
|
|
|
+ item.put("label", labelEntry.getValue());
|
|
|
|
|
+ Object val = getParamValue(row, labelEntry.getKey());
|
|
|
|
|
+ item.put("value", val != null ? val : "-");
|
|
|
|
|
+ items.add(item);
|
|
|
|
|
+ }
|
|
|
|
|
+ for (Map.Entry<String, Object> entry : row.entrySet()) {
|
|
|
|
|
+ String key = entry.getKey();
|
|
|
|
|
+ if (CNC_PARAM_LABELS.containsKey(key) || CNC_PARAM_ALIASES.containsKey(key)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String, Object> item = new LinkedHashMap<>();
|
|
|
|
|
+ item.put("code", key);
|
|
|
|
|
+ item.put("label", key);
|
|
|
|
|
+ item.put("value", entry.getValue());
|
|
|
|
|
+ items.add(item);
|
|
|
|
|
+ }
|
|
|
|
|
+ return items;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 按主代码取值,同时兼容别名字段
|
|
|
|
|
+ */
|
|
|
|
|
+ private Object getParamValue(JSONObject row, String code) {
|
|
|
|
|
+ if (row == null || StringUtils.isBlank(code)) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ Object val = row.get(code);
|
|
|
|
|
+ if (val != null) {
|
|
|
|
|
+ return val;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (Map.Entry<String, String> alias : CNC_PARAM_ALIASES.entrySet()) {
|
|
|
|
|
+ if (code.equals(alias.getValue()) && row.get(alias.getKey()) != null) {
|
|
|
|
|
+ return row.get(alias.getKey());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 将别名字段归一到主代码,避免重复展示
|
|
|
|
|
+ */
|
|
|
|
|
+ private void normalizeAliasKeys(List<JSONObject> paramRows) {
|
|
|
|
|
+ if (paramRows == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (JSONObject row : paramRows) {
|
|
|
|
|
+ for (Map.Entry<String, String> alias : CNC_PARAM_ALIASES.entrySet()) {
|
|
|
|
|
+ String aliasKey = alias.getKey();
|
|
|
|
|
+ String primaryKey = alias.getValue();
|
|
|
|
|
+ if (row.get(primaryKey) == null && row.get(aliasKey) != null) {
|
|
|
|
|
+ row.put(primaryKey, row.get(aliasKey));
|
|
|
|
|
+ }
|
|
|
|
|
+ row.remove(aliasKey);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 解析CNC参数内容为对象列表(支持JSON对象、JSON数组、键值对数组)
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<JSONObject> parseCncContent(String content) {
|
|
|
|
|
+ List<JSONObject> rows = new ArrayList<>();
|
|
|
|
|
+ if (StringUtils.isBlank(content)) {
|
|
|
|
|
+ return rows;
|
|
|
|
|
+ }
|
|
|
|
|
+ String text = content.trim();
|
|
|
|
|
+ try {
|
|
|
|
|
+ Object parsed = JSON.parse(text);
|
|
|
|
|
+ if (parsed instanceof JSONObject) {
|
|
|
|
|
+ rows.add(normalizeParamObject((JSONObject) parsed));
|
|
|
|
|
+ } else if (parsed instanceof JSONArray) {
|
|
|
|
|
+ JSONArray arr = (JSONArray) parsed;
|
|
|
|
|
+ for (int i = 0; i < arr.size(); i++) {
|
|
|
|
|
+ Object item = arr.get(i);
|
|
|
|
|
+ if (item instanceof JSONObject) {
|
|
|
|
|
+ JSONObject obj = (JSONObject) item;
|
|
|
|
|
+ // 键值对形式:{"name":"SP_SPEED","value":100} / {"key":"..."} / {"code":"..."}
|
|
|
|
|
+ if (isKeyValuePair(obj)) {
|
|
|
|
|
+ JSONObject merged = rows.isEmpty() ? new JSONObject(true) : rows.get(0);
|
|
|
|
|
+ if (rows.isEmpty()) {
|
|
|
|
|
+ rows.add(merged);
|
|
|
|
|
+ }
|
|
|
|
|
+ String code = firstNonBlank(obj.getString("name"), obj.getString("key"), obj.getString("code"));
|
|
|
|
|
+ merged.put(code, obj.get("value"));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ rows.add(normalizeParamObject(obj));
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (item != null) {
|
|
|
|
|
+ // 兼容 "SP_SPEED:100|X_MCS:1.2" 或纯字符串
|
|
|
|
|
+ JSONObject fromStr = parseParamString(String.valueOf(item));
|
|
|
|
|
+ if (!fromStr.isEmpty()) {
|
|
|
|
|
+ rows.add(fromStr);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 非标准JSON时,尝试按分隔符解析
|
|
|
|
|
+ JSONObject fromStr = parseParamString(text);
|
|
|
|
|
+ if (!fromStr.isEmpty()) {
|
|
|
|
|
+ rows.add(fromStr);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return rows;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean isKeyValuePair(JSONObject obj) {
|
|
|
|
|
+ boolean hasCode = StringUtils.isNotBlank(obj.getString("name"))
|
|
|
|
|
+ || StringUtils.isNotBlank(obj.getString("key"))
|
|
|
|
|
+ || StringUtils.isNotBlank(obj.getString("code"));
|
|
|
|
|
+ return hasCode && obj.containsKey("value") && obj.size() <= 4;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private JSONObject normalizeParamObject(JSONObject src) {
|
|
|
|
|
+ JSONObject dest = new JSONObject(true);
|
|
|
|
|
+ for (Map.Entry<String, Object> entry : src.entrySet()) {
|
|
|
|
|
+ dest.put(entry.getKey(), entry.getValue());
|
|
|
|
|
+ }
|
|
|
|
|
+ return dest;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private JSONObject parseParamString(String text) {
|
|
|
|
|
+ JSONObject obj = new JSONObject(true);
|
|
|
|
|
+ if (StringUtils.isBlank(text)) {
|
|
|
|
|
+ return obj;
|
|
|
|
|
+ }
|
|
|
|
|
+ String[] parts = text.split("[,;|\\n]");
|
|
|
|
|
+ for (String part : parts) {
|
|
|
|
|
+ String p = part.trim();
|
|
|
|
|
+ if (p.isEmpty()) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ int idx = p.indexOf(':');
|
|
|
|
|
+ if (idx < 0) {
|
|
|
|
|
+ idx = p.indexOf('=');
|
|
|
|
|
+ }
|
|
|
|
|
+ if (idx > 0) {
|
|
|
|
|
+ String key = p.substring(0, idx).trim();
|
|
|
|
|
+ String val = p.substring(idx + 1).trim();
|
|
|
|
|
+ obj.put(key, val);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return obj;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String firstNonBlank(String... values) {
|
|
|
|
|
+ for (String v : values) {
|
|
|
|
|
+ if (StringUtils.isNotBlank(v)) {
|
|
|
|
|
+ return v;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 保存数据
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequiresPermissions("mes:mesProductCncParam:edit")
|
|
|
|
|
+ @PostMapping(value = "save")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public String save(@Validated MesProductCncParam mesProductCncParam) {
|
|
|
|
|
+ mesProductCncParamService.save(mesProductCncParam);
|
|
|
|
|
+ return renderResult(Global.TRUE, text("保存CNC过程参数记录表成功!"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 删除数据
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequiresPermissions("mes:mesProductCncParam:edit")
|
|
|
|
|
+ @RequestMapping(value = "delete")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public String delete(MesProductCncParam mesProductCncParam) {
|
|
|
|
|
+ mesProductCncParamService.delete(mesProductCncParam);
|
|
|
|
|
+ return renderResult(Global.TRUE, text("删除CNC过程参数记录表成功!"));
|
|
|
|
|
+ }
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 接口批量保存数据(供客户端调用)
|
|
|
|
|
+ * 参考CMT的batchsave接口
|
|
|
|
|
+ */
|
|
|
|
|
+ @PostMapping(value = "batchsave")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public String batchsave(HttpServletRequest request) {
|
|
|
|
|
+ String params = request.getParameter("params");
|
|
|
|
|
+ if(StringUtils.isEmpty(params)){
|
|
|
|
|
+ return renderResult(Global.FALSE, text("参数错误!"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ JSONArray jsonArr = JSON.parseArray(params);
|
|
|
|
|
+ if(jsonArr.size() <= 0){
|
|
|
|
|
+ return renderResult(Global.FALSE, text("参数错误!"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for (int i=0; i<jsonArr.size(); i++) {
|
|
|
|
|
+ JSONObject obj = jsonArr.getJSONObject(i);
|
|
|
|
|
+
|
|
|
|
|
+ MesProductCncParam mesProductCncParam = new MesProductCncParam();
|
|
|
|
|
+ mesProductCncParam.setSn(obj.getString("sn"));
|
|
|
|
|
+ mesProductCncParam.setOprno(obj.getString("oprno"));
|
|
|
|
|
+ mesProductCncParam.setLineSn(obj.getString("lineSn"));
|
|
|
|
|
+ mesProductCncParam.setDeviceCode(obj.getString("deviceCode"));
|
|
|
|
|
+ mesProductCncParam.setContent(obj.getString("content"));
|
|
|
|
|
+
|
|
|
|
|
+ mesProductCncParamService.save(mesProductCncParam);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return renderResult(Global.TRUE, text("操作成功!"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|