|
|
@@ -1,5 +1,10 @@
|
|
|
package com.jeesite.modules.mes.web;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -9,9 +14,12 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.jeesite.common.collect.ListUtils;
|
|
|
import com.jeesite.common.collect.MapUtils;
|
|
|
+import com.jeesite.common.lang.DateUtils;
|
|
|
import com.jeesite.common.lang.ObjectUtils;
|
|
|
import com.jeesite.common.lang.StringUtils;
|
|
|
import com.jeesite.common.mybatis.mapper.query.QueryType;
|
|
|
+import com.jeesite.modules.mes.dao.MesLineDao;
|
|
|
+import com.jeesite.modules.mes.dao.MesLineProcessDao;
|
|
|
import com.jeesite.modules.mes.dao.MesLineProcessUserDao;
|
|
|
import com.jeesite.modules.mes.entity.*;
|
|
|
import com.jeesite.modules.mes.resp.CommonResp;
|
|
|
@@ -29,14 +37,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
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 org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import com.jeesite.common.config.Global;
|
|
|
import com.jeesite.common.entity.Page;
|
|
|
import com.jeesite.common.web.BaseController;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
/**
|
|
|
* 生成工序表Controller
|
|
|
@@ -63,8 +69,14 @@ public class MesLineProcessController extends BaseController {
|
|
|
@Autowired
|
|
|
private MesUserSkillService mesUserSkillService;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+ /**
|
|
|
+ * JAR管理页面
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "jarManagement")
|
|
|
+ public String jarManagement(MesLineProcess mesLineProcess, Model model) {
|
|
|
+ model.addAttribute("mesLineProcess", mesLineProcess);
|
|
|
+ return "modules/mes/mesLineProcessJarManagement";
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 获取数据
|
|
|
@@ -538,5 +550,179 @@ public class MesLineProcessController extends BaseController {
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
+ @Autowired
|
|
|
+ MesLineProcessDao mesLineProcessDao;
|
|
|
+ @Autowired
|
|
|
+ MesLineDao mesLineDao;
|
|
|
+
|
|
|
+ //上传jar包
|
|
|
+ @PostMapping(value = "uploadjar")
|
|
|
+ @ResponseBody
|
|
|
+ public CommonResp upload(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
|
|
|
+ CommonResp resp = new CommonResp();
|
|
|
+ try {
|
|
|
+ if (file.isEmpty()) {
|
|
|
+ resp.setResult(Global.FALSE);
|
|
|
+ resp.setMessage("上传文件不能为空");
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
+ if (fileName == null || !fileName.endsWith(".jar")) {
|
|
|
+ resp.setResult(Global.FALSE);
|
|
|
+ resp.setMessage("只能上传jar文件");
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
+ String id = request.getParameter("id");//工位主键ID
|
|
|
+ // 1. 获取旧的jar包路径,以便后续清理
|
|
|
+ MesLineProcess oldProcess = mesLineProcessService.get(id);
|
|
|
+ String oldJarPath = (oldProcess != null) ? oldProcess.getJarPath() : null;
|
|
|
+
|
|
|
+ // 2. 准备保存路径 (D:/mescloud/userfiles/jar/yyyyMMdd/)
|
|
|
+ String baseDir = Global.getConfig("file.baseDir", "D:/mescloud");
|
|
|
+ String relativePath = "userfiles/jar/" + DateUtils.getDate("yyyyMMdd") + "/";
|
|
|
+ String realPath = baseDir + (baseDir.endsWith("/") ? "" : "/") + relativePath;
|
|
|
|
|
|
+ File dir = new File(realPath);
|
|
|
+ if (!dir.exists()) {
|
|
|
+ dir.mkdirs();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 生成新文件名并保存到本地
|
|
|
+ String saveFileName = System.currentTimeMillis() + "_" + fileName;
|
|
|
+ String pathname = realPath + saveFileName;
|
|
|
+ logger.info("上传文件保存路径:" + pathname);
|
|
|
+ File dest = new File(pathname);
|
|
|
+ file.transferTo(dest);
|
|
|
+
|
|
|
+ // 4. 更新数据库记录,确保主键唯一对应
|
|
|
+ mesLineProcessDao.updateJarPathById(id, pathname);
|
|
|
+
|
|
|
+ // 5. 上传成功后,清理旧的物理文件
|
|
|
+ if (StringUtils.isNotBlank(oldJarPath)) {
|
|
|
+ File oldFile = new File(oldJarPath);
|
|
|
+ if (oldFile.exists()) {
|
|
|
+ if (oldFile.delete()) {
|
|
|
+ logger.info("旧JAR包物理文件删除成功: " + oldJarPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ resp.setData("/" + relativePath + saveFileName);
|
|
|
+ resp.setResult(Global.TRUE);
|
|
|
+ resp.setMessage("上传成功");
|
|
|
+ return resp;
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("上传jar包失败", e);
|
|
|
+ resp.setResult(Global.FALSE);
|
|
|
+ resp.setMessage("上传失败: " + e.getMessage());
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载jar包
|
|
|
+ */
|
|
|
+ @PostMapping(value = "downloadJar")
|
|
|
+ public void downloadJar(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ try {
|
|
|
+ String sn = request.getParameter("sn"); // 生产线编号
|
|
|
+ String oprno = request.getParameter("oprno"); // 生产工位号
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(sn) || StringUtils.isBlank(oprno)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据产线编号查询产线id
|
|
|
+ MesLine mesLine = mesLineDao.selectIdBysn(sn);
|
|
|
+ if (mesLine == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 从数据库获取jar包路径
|
|
|
+ String jarPath = mesLineProcessDao.getJarPath(mesLine.getId(), oprno);
|
|
|
+ if (StringUtils.isBlank(jarPath)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ File file = new File(jarPath);
|
|
|
+ if (!file.exists()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置响应头
|
|
|
+ String fileName = file.getName();
|
|
|
+ // 去掉时间戳前缀 (如 1715760000000_test.jar -> test.jar)
|
|
|
+ if (fileName.contains("_")) {
|
|
|
+ fileName = fileName.substring(fileName.indexOf("_") + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ response.reset();
|
|
|
+ response.setContentType("application/octet-stream");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
|
|
|
+
|
|
|
+ // 读取文件并写入响应流
|
|
|
+ try (InputStream is = new FileInputStream(file);
|
|
|
+ OutputStream os = response.getOutputStream()) {
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ int len;
|
|
|
+ while ((len = is.read(buffer)) != -1) {
|
|
|
+ os.write(buffer, 0, len);
|
|
|
+ }
|
|
|
+ os.flush();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("下载jar包失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除jar包
|
|
|
+ */
|
|
|
+ @PostMapping(value = "deleteJar")
|
|
|
+ @ResponseBody
|
|
|
+ public CommonResp deleteJar(HttpServletRequest request) {
|
|
|
+ CommonResp resp = new CommonResp();
|
|
|
+ try {
|
|
|
+ String id = request.getParameter("id"); // 工位主键ID
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(id)) {
|
|
|
+ resp.setResult(Global.FALSE);
|
|
|
+ resp.setMessage("ID不能为空");
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1. 获取当前工位信息
|
|
|
+ MesLineProcess mesLineProcess = mesLineProcessService.get(id);
|
|
|
+ if (mesLineProcess == null) {
|
|
|
+ resp.setResult(Global.FALSE);
|
|
|
+ resp.setMessage("工位不存在");
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
+ String jarPath = mesLineProcess.getJarPath();
|
|
|
+
|
|
|
+ // 2. 尝试删除物理文件
|
|
|
+ if (StringUtils.isNotBlank(jarPath)) {
|
|
|
+ File file = new File(jarPath);
|
|
|
+ if (file.exists()) {
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 清除数据库记录
|
|
|
+ mesLineProcessDao.updateJarPathById(id, null);
|
|
|
+
|
|
|
+ resp.setResult(Global.TRUE);
|
|
|
+ resp.setMessage("删除成功");
|
|
|
+ return resp;
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("删除jar包失败", e);
|
|
|
+ resp.setResult(Global.FALSE);
|
|
|
+ resp.setMessage("删除失败: " + e.getMessage());
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|