|
|
@@ -0,0 +1,198 @@
|
|
|
+package com.jeesite.modules.mes.web;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.net.URLEncoder;
|
|
|
+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.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
+
|
|
|
+import com.jeesite.common.entity.Page;
|
|
|
+import com.jeesite.common.mybatis.mapper.query.QueryType;
|
|
|
+import com.jeesite.common.web.BaseController;
|
|
|
+import com.jeesite.modules.mes.entity.MesProductRecord;
|
|
|
+import com.jeesite.modules.mes.entity.MesTemplateItems;
|
|
|
+import com.jeesite.modules.mes.req.MesSearchDateReq;
|
|
|
+import com.jeesite.modules.mes.service.MesProductRecordService;
|
|
|
+import com.jeesite.modules.mes.service.MesTemplateItemsService;
|
|
|
+import com.jeesite.modules.mes.util.CommonUitl;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 探伤记录Controller(仅展示OP070工位的生产记录)
|
|
|
+ * @author system
|
|
|
+ * @version 2025-06-25
|
|
|
+ */
|
|
|
+@Controller
|
|
|
+@RequestMapping(value = "${adminPath}/mes/mesFlawRecord")
|
|
|
+public class MesFlawRecordController extends BaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MesProductRecordService mesProductRecordService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MesTemplateItemsService mesTemplateItemsService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取数据
|
|
|
+ */
|
|
|
+ @ModelAttribute
|
|
|
+ public MesProductRecord get(String id, boolean isNewRecord) {
|
|
|
+ return mesProductRecordService.get(id, isNewRecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询列表
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesProductRecord:view")
|
|
|
+ @RequestMapping(value = {"list", ""})
|
|
|
+ public String list(MesProductRecord mesProductRecord, Model model) {
|
|
|
+ MesSearchDateReq dateMap = CommonUitl.getSearchDate();
|
|
|
+
|
|
|
+ if(mesProductRecord.getUpdateDate_gte() == null){
|
|
|
+ mesProductRecord.setUpdateDate_gte(dateMap.getStartDate());
|
|
|
+ }
|
|
|
+ if(mesProductRecord.getUpdateDate_lte() == null){
|
|
|
+ mesProductRecord.setUpdateDate_lte(dateMap.getEndtDate());
|
|
|
+ }
|
|
|
+ // 固定过滤OP070工位
|
|
|
+ mesProductRecord.setOprno("OP070");
|
|
|
+ model.addAttribute("mesProductRecord", mesProductRecord);
|
|
|
+ return "modules/mes/mesFlawRecordList";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询列表数据
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesProductRecord:view")
|
|
|
+ @RequestMapping(value = "listData")
|
|
|
+ @ResponseBody
|
|
|
+ public Page<MesProductRecord> listData(MesProductRecord mesProductRecord, HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ Page page1 = new Page<>(request, response);
|
|
|
+ mesProductRecord.setPage(page1);
|
|
|
+ mesProductRecord.getSqlMap().getOrder().setOrderBy("a.id DESC");
|
|
|
+ // 固定过滤OP070工位
|
|
|
+ mesProductRecord.getSqlMap().getWhere().and("oprno", QueryType.EQ, "OP070");
|
|
|
+ // 如果查询状态的值为 1, 表示用户选择查询 已加工
|
|
|
+ if("1".equals(mesProductRecord.getProcessState()) && "".equals(mesProductRecord.getContent()))
|
|
|
+ mesProductRecord.getSqlMap().getWhere().and("content", QueryType.NE, "UDF");
|
|
|
+ // 如果查询状态的值为 0, 表示用户选择查询 未加工
|
|
|
+ else if ("0".equals(mesProductRecord.getProcessState()) && "".equals(mesProductRecord.getContent()))
|
|
|
+ mesProductRecord.getSqlMap().getWhere().and("content", QueryType.EQ, "UDF");
|
|
|
+ Page<MesProductRecord> page = mesProductRecordService.findPage(mesProductRecord);
|
|
|
+ for (int i = 0; i < page.getList().size(); i++) {
|
|
|
+ MesTemplateItems mesTemplateItems = new MesTemplateItems();
|
|
|
+ mesTemplateItems.setId(page.getList().get(i).getTid());
|
|
|
+ MesTemplateItems mt = mesTemplateItemsService.get(mesTemplateItems);
|
|
|
+ if (!ObjectUtils.isEmpty(mt)) {
|
|
|
+ page.getList().get(i).setMessageType(mt.getCate());
|
|
|
+ page.getList().get(i).setTitle(mt.getTitle());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出数据
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesProductRecord:view")
|
|
|
+ @RequestMapping(value = "exportData")
|
|
|
+ public void exportData(MesProductRecord mesProductRecord, HttpServletResponse response) {
|
|
|
+ mesProductRecord.getSqlMap().getWhere().and("oprno", QueryType.EQ, "OP070");
|
|
|
+ java.util.List<MesProductRecord> list = mesProductRecordService.findList(mesProductRecord);
|
|
|
+ String fileName = "探伤记录" + com.jeesite.common.lang.DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
|
|
|
+ try (com.jeesite.common.utils.excel.ExcelExport ee = new com.jeesite.common.utils.excel.ExcelExport("探伤记录", MesProductRecord.class)) {
|
|
|
+ ee.setDataList(list).write(response, fileName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查看详情
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesProductRecord:view")
|
|
|
+ @RequestMapping(value = "info")
|
|
|
+ public String info(MesProductRecord mesProductRecord, Model model) {
|
|
|
+ model.addAttribute("mesProductRecord", mesProductRecord);
|
|
|
+ return "modules/mes/mesFlawRecordInfo";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取工件码对应的jpg图片列表
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesProductRecord:view")
|
|
|
+ @RequestMapping(value = "imageList")
|
|
|
+ @ResponseBody
|
|
|
+ public List<Map<String, String>> imageList(String sn) {
|
|
|
+ List<Map<String, String>> result = new ArrayList<>();
|
|
|
+ if (sn == null || sn.trim().isEmpty()) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ // 图片存储目录:D:/mescloud/{工件码}/
|
|
|
+ File dir = new File("D:/mescloud/" + sn);
|
|
|
+ if (!dir.exists() || !dir.isDirectory()) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ File[] files = dir.listFiles((d, name) -> {
|
|
|
+ String lower = name.toLowerCase();
|
|
|
+ return lower.endsWith(".jpg") || lower.endsWith(".jpeg");
|
|
|
+ });
|
|
|
+ if (files == null) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ for (File file : files) {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("name", file.getName());
|
|
|
+ map.put("size", String.valueOf(file.length()));
|
|
|
+ result.add(map);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 输出指定工件码的指定图片
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesProductRecord:view")
|
|
|
+ @RequestMapping(value = "viewImage")
|
|
|
+ public void viewImage(String sn, String fileName, HttpServletResponse response) {
|
|
|
+ if (sn == null || sn.trim().isEmpty() || fileName == null || fileName.trim().isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 安全检查:防止路径穿越
|
|
|
+ if (sn.contains("..") || fileName.contains("..") || fileName.contains("/") || fileName.contains("\\")) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String lower = fileName.toLowerCase();
|
|
|
+ if (!lower.endsWith(".jpg") && !lower.endsWith(".jpeg")) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ File file = new File("D:/mescloud/" + sn + "/" + fileName);
|
|
|
+ if (!file.exists() || !file.isFile()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ response.setContentType("image/jpeg");
|
|
|
+ response.setContentLengthLong(file.length());
|
|
|
+ try (FileInputStream fis = new FileInputStream(file);
|
|
|
+ OutputStream os = response.getOutputStream()) {
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ int len;
|
|
|
+ while ((len = fis.read(buffer)) != -1) {
|
|
|
+ os.write(buffer, 0, len);
|
|
|
+ }
|
|
|
+ os.flush();
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("输出探伤图片失败: " + file.getPath(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|