|
@@ -0,0 +1,311 @@
|
|
|
|
|
+package com.jeesite.modules.mes.web;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+
|
|
|
|
|
+import com.jeesite.common.lang.DateUtils;
|
|
|
|
|
+import com.jeesite.modules.sys.utils.UserUtils;
|
|
|
|
|
+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.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.collect.ListUtils;
|
|
|
|
|
+import com.jeesite.common.collect.MapUtils;
|
|
|
|
|
+import com.jeesite.common.entity.Page;
|
|
|
|
|
+import com.jeesite.common.lang.StringUtils;
|
|
|
|
|
+import com.jeesite.common.web.BaseController;
|
|
|
|
|
+import com.jeesite.modules.file.entity.FileUpload;
|
|
|
|
|
+import com.jeesite.modules.file.service.FileUploadService;
|
|
|
|
|
+import com.jeesite.modules.file.utils.FileUploadUtils;
|
|
|
|
|
+import com.jeesite.modules.mes.entity.MesInspection;
|
|
|
|
|
+import com.jeesite.modules.mes.service.MesInspectionService;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * mes_inspectionController
|
|
|
|
|
+ * @author system
|
|
|
|
|
+ * @version 2026-05-26
|
|
|
|
|
+ */
|
|
|
|
|
+@Controller
|
|
|
|
|
+@RequestMapping(value = "${adminPath}/mes/mesInspection")
|
|
|
|
|
+public class MesInspectionController extends BaseController {
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private MesInspectionService mesInspectionService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private FileUploadService fileUploadService;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取数据
|
|
|
|
|
+ */
|
|
|
|
|
+ @ModelAttribute
|
|
|
|
|
+ public MesInspection get(String id, boolean isNewRecord) {
|
|
|
|
|
+ return mesInspectionService.get(id, isNewRecord);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询列表
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequiresPermissions("mes:mesInspection:view")
|
|
|
|
|
+ @RequestMapping(value = {"list", ""})
|
|
|
|
|
+ public String list(MesInspection mesInspection, Model model) {
|
|
|
|
|
+ model.addAttribute("mesInspection", mesInspection);
|
|
|
|
|
+ return "modules/mes/mesInspectionList";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询列表数据
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequiresPermissions("mes:mesInspection:view")
|
|
|
|
|
+ @RequestMapping(value = "listData")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public Page<MesInspection> listData(MesInspection mesInspection, HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
|
+ mesInspection.setPage(new Page<>(request, response));
|
|
|
|
|
+ Page<MesInspection> page = mesInspectionService.findPage(mesInspection);
|
|
|
|
|
+ return page;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查看编辑表单
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequiresPermissions("mes:mesInspection:view")
|
|
|
|
|
+ @RequestMapping(value = "form")
|
|
|
|
|
+ public String form(MesInspection mesInspection, Model model) {
|
|
|
|
|
+ model.addAttribute("mesInspection", mesInspection);
|
|
|
|
|
+ return "modules/mes/mesInspectionForm";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 保存数据
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequiresPermissions("mes:mesInspection:edit")
|
|
|
|
|
+ @PostMapping(value = "save")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public String save(@Validated MesInspection mesInspection) {
|
|
|
|
|
+ mesInspectionService.save(mesInspection);
|
|
|
|
|
+ return renderResult(Global.TRUE, text("保存mes_inspection成功!"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 删除数据
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequiresPermissions("mes:mesInspection:delete")
|
|
|
|
|
+ @RequestMapping(value = "delete")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public String delete(MesInspection mesInspection) {
|
|
|
|
|
+ mesInspectionService.delete(mesInspection);
|
|
|
|
|
+ return renderResult(Global.TRUE, text("删除mes_inspection成功!"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 上传文件页面(仅 states=0 待上传 状态可以进入)
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequiresPermissions("mes:mesInspection:uploadForm")
|
|
|
|
|
+ @RequestMapping(value = "uploadForm")
|
|
|
|
|
+ public String uploadForm(MesInspection mesInspection, Model model) {
|
|
|
|
|
+ model.addAttribute("mesInspection", mesInspection);
|
|
|
|
|
+ return "modules/mes/mesInspectionUpload";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 详情页
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequiresPermissions("mes:mesInspection:view")
|
|
|
|
|
+ @RequestMapping(value = "detail")
|
|
|
|
|
+ public String detail(MesInspection mesInspection, Model model) {
|
|
|
|
|
+ model.addAttribute("mesInspection", mesInspection);
|
|
|
|
|
+ return "modules/mes/mesInspectionDetail";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 保存上传文件,文件保存后将状态置为 1(待判定)
|
|
|
|
|
+ */
|
|
|
|
|
+ @PostMapping(value = "uploadSave")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public String uploadSave(MesInspection mesInspection) {
|
|
|
|
|
+ // 重新查询,避免前端漏传字段被覆盖
|
|
|
|
|
+ MesInspection db = mesInspectionService.get(mesInspection.getId());
|
|
|
|
|
+ if (db == null) {
|
|
|
|
|
+ return renderResult(Global.FALSE, text("记录不存在!"));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!"0".equals(db.getStates())) {
|
|
|
|
|
+ return renderResult(Global.FALSE, text("当前状态不允许上传文件!"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 关联前端上传的附件
|
|
|
|
|
+ FileUploadUtils.saveFileUpload(mesInspection, db.getId(), "mesInspection_file");
|
|
|
|
|
+
|
|
|
|
|
+ // 状态改为 1(待判定)
|
|
|
|
|
+ db.setStates("1");
|
|
|
|
|
+ db.setInspector(UserUtils.getUser().getUserName());
|
|
|
|
|
+ db.setEndDetectionTime( new Date());
|
|
|
|
|
+ mesInspectionService.save(db);
|
|
|
|
|
+
|
|
|
|
|
+ return renderResult(Global.TRUE, text("上传成功!"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 结果判定页面
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequiresPermissions("mes:mesInspection:judgeForm")
|
|
|
|
|
+ @RequestMapping(value = "judgeForm")
|
|
|
|
|
+ public String judgeForm(MesInspection mesInspection, Model model) {
|
|
|
|
|
+ model.addAttribute("mesInspection", mesInspection);
|
|
|
|
|
+ return "modules/mes/mesInspectionJudge";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 保存判定结果
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequiresPermissions("mes:mesInspection:edit")
|
|
|
|
|
+ @PostMapping(value = "judgeSave")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public String judgeSave(MesInspection mesInspection) {
|
|
|
|
|
+ MesInspection db = mesInspectionService.get(mesInspection.getId());
|
|
|
|
|
+ if (db == null) {
|
|
|
|
|
+ return renderResult(Global.FALSE, text("记录不存在!"));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!"1".equals(db.getStates())) {
|
|
|
|
|
+ return renderResult(Global.FALSE, text("当前状态不允许判定!"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //
|
|
|
|
|
+ db.setResult(mesInspection.getResult());
|
|
|
|
|
+// db.setRemark(mesInspection.getRemark());
|
|
|
|
|
+ db.setResultBy(UserUtils.getUser().getUserName());
|
|
|
|
|
+ db.setStates("2");
|
|
|
|
|
+ mesInspectionService.save(db);
|
|
|
|
|
+
|
|
|
|
|
+ return renderResult(Global.TRUE, text("判定成功!"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查看
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequestMapping(value = "fileList")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public java.util.List<java.util.Map<String, Object>> fileList(String bizKey, String bizType) {
|
|
|
|
|
+ java.util.List<java.util.Map<String, Object>> result = ListUtils.newArrayList();
|
|
|
|
|
+ if (StringUtils.isBlank(bizKey) || StringUtils.isBlank(bizType)) {
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+ FileUpload fu = new FileUpload();
|
|
|
|
|
+ fu.setBizKey(bizKey);
|
|
|
|
|
+ fu.setBizType(bizType);
|
|
|
|
|
+ java.util.List<FileUpload> list = fileUploadService.findList(fu);
|
|
|
|
|
+ if (ListUtils.isEmpty(list)) {
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (FileUpload fi : list) {
|
|
|
|
|
+ java.util.Map<String, Object> map = MapUtils.newHashMap();
|
|
|
|
|
+ map.put("fileName", fi.getFileName());
|
|
|
|
|
+ map.put("fileUrl", fi.getFileUrl());
|
|
|
|
|
+ result.add(map);
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 内联预览附件
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+ @RequestMapping(value = "viewFile")
|
|
|
|
|
+ public void viewFile(String bizKey, String bizType, String fileUrl,
|
|
|
|
|
+ javax.servlet.http.HttpServletResponse response) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (StringUtils.isBlank(bizKey) || StringUtils.isBlank(bizType) || StringUtils.isBlank(fileUrl)) {
|
|
|
|
|
+ response.sendError(404, "params missing");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ FileUpload q = new FileUpload();
|
|
|
|
|
+ q.setBizKey(bizKey);
|
|
|
|
|
+ q.setBizType(bizType);
|
|
|
|
|
+ java.util.List<FileUpload> list = fileUploadService.findList(q);
|
|
|
|
|
+ if (ListUtils.isEmpty(list)) {
|
|
|
|
|
+ response.sendError(404, "file not found");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ FileUpload fu = null;
|
|
|
|
|
+ for (FileUpload f : list) {
|
|
|
|
|
+ if (fileUrl.equals(f.getFileUrl())) {
|
|
|
|
|
+ fu = f;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (fu == null) {
|
|
|
|
|
+ response.sendError(404, "file not found");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ String url = fu.getFileUrl();
|
|
|
|
|
+ String baseDir = Global.getConfig("file.baseDir");
|
|
|
|
|
+ if (StringUtils.isBlank(baseDir)) {
|
|
|
|
|
+ baseDir = System.getProperty("user.home");
|
|
|
|
|
+ }
|
|
|
|
|
+ java.io.File file = new java.io.File(baseDir, url);
|
|
|
|
|
+ if (!file.exists() || !file.isFile()) {
|
|
|
|
|
+ response.sendError(404, "file not exist on disk");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ String contentType = getContentType(file.getName());
|
|
|
|
|
+ response.setContentType(contentType);
|
|
|
|
|
+ response.setContentLengthLong(file.length());
|
|
|
|
|
+ String encodedName = java.net.URLEncoder.encode(fu.getFileName(), "UTF-8").replace("+", "%20");
|
|
|
|
|
+ response.setHeader("Content-Disposition", "inline; filename*=UTF-8''" + encodedName);
|
|
|
|
|
+
|
|
|
|
|
+ try (java.io.InputStream in = new java.io.FileInputStream(file);
|
|
|
|
|
+ java.io.OutputStream out = response.getOutputStream()) {
|
|
|
|
|
+ byte[] buf = new byte[8192];
|
|
|
|
|
+ int len;
|
|
|
|
|
+ while ((len = in.read(buf)) != -1) {
|
|
|
|
|
+ out.write(buf, 0, len);
|
|
|
|
|
+ }
|
|
|
|
|
+ out.flush();
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("内联预览文件失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据文件扩展名获取 Content-Type
|
|
|
|
|
+ */
|
|
|
|
|
+ private String getContentType(String fileName) {
|
|
|
|
|
+ if (StringUtils.isBlank(fileName)) return "application/octet-stream";
|
|
|
|
|
+ String ext = fileName.substring(fileName.lastIndexOf('.') + 1).toLowerCase();
|
|
|
|
|
+ switch (ext) {
|
|
|
|
|
+ case "pdf": return "application/pdf";
|
|
|
|
|
+ case "png": return "image/png";
|
|
|
|
|
+ case "jpg": case "jpeg": return "image/jpeg";
|
|
|
|
|
+ case "gif": return "image/gif";
|
|
|
|
|
+ case "bmp": return "image/bmp";
|
|
|
|
|
+ case "svg": return "image/svg+xml";
|
|
|
|
|
+ case "mp4": return "video/mp4";
|
|
|
|
|
+ case "webm": return "video/webm";
|
|
|
|
|
+ case "mp3": return "audio/mpeg";
|
|
|
|
|
+ case "wav": return "audio/wav";
|
|
|
|
|
+ case "txt": case "csv": case "log": return "text/plain; charset=utf-8";
|
|
|
|
|
+ case "html": case "htm": return "text/html; charset=utf-8";
|
|
|
|
|
+ case "xml": return "text/xml; charset=utf-8";
|
|
|
|
|
+ case "json": return "application/json; charset=utf-8";
|
|
|
|
|
+ case "doc": return "application/msword";
|
|
|
|
|
+ case "docx": return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
|
|
|
+ case "xls": return "application/vnd.ms-excel";
|
|
|
|
|
+ case "xlsx": return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
|
|
|
+ case "ppt": return "application/vnd.ms-powerpoint";
|
|
|
|
|
+ case "pptx": return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
|
|
|
|
+ default:
|
|
|
|
|
+ String guess = java.net.URLConnection.guessContentTypeFromName(fileName);
|
|
|
|
|
+ return StringUtils.isNotBlank(guess) ? guess : "application/octet-stream";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|