|
|
@@ -25,6 +25,7 @@ import com.jeesite.modules.file.utils.FileUploadUtils;
|
|
|
import com.jeesite.modules.sys.entity.DictData;
|
|
|
import com.jeesite.modules.sys.entity.DictType;
|
|
|
import com.jeesite.modules.sys.service.DictDataService;
|
|
|
+import com.jeesite.modules.sys.utils.DictUtils;
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
@@ -33,9 +34,26 @@ import org.springframework.ui.Model;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import com.jeesite.common.codec.EncodeUtils;
|
|
|
import com.jeesite.common.config.Global;
|
|
|
import com.jeesite.common.entity.Page;
|
|
|
+import com.jeesite.common.lang.DateUtils;
|
|
|
+import com.jeesite.common.utils.excel.ExcelExport;
|
|
|
import com.jeesite.common.web.BaseController;
|
|
|
+import org.apache.poi.ss.usermodel.BorderStyle;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.CellStyle;
|
|
|
+import org.apache.poi.ss.usermodel.FillPatternType;
|
|
|
+import org.apache.poi.ss.usermodel.Font;
|
|
|
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
|
+import org.apache.poi.ss.usermodel.IndexedColors;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.VerticalAlignment;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
+import org.apache.poi.ss.util.RegionUtil;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
|
/**
|
|
|
* 来料检查记录表Controller
|
|
|
@@ -108,6 +126,43 @@ public class MesMaterialCheckRecordController extends BaseController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 导出检测数据(勾选记录展开检查明细)
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesMaterialCheckRecord:view")
|
|
|
+ @RequestMapping(value = "exportData")
|
|
|
+ public void exportData(MesMaterialCheckRecord mesMaterialCheckRecord, String ids, HttpServletResponse response) {
|
|
|
+ List<MesMaterialCheckRecordItems> exportList = buildCheckDataExportList(mesMaterialCheckRecord, ids);
|
|
|
+ String fileName = "来料检查检测数据" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
|
|
|
+ try (ExcelExport ee = new ExcelExport("来料检查检测数据", MesMaterialCheckRecordItems.class)) {
|
|
|
+ ee.setDataList(exportList).write(response, fileName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 详情页导出:基本信息只写一次,下方为检测明细
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesMaterialCheckRecord:view")
|
|
|
+ @RequestMapping(value = "exportInfoData")
|
|
|
+ public void exportInfoData(MesMaterialCheckRecord mesMaterialCheckRecord, HttpServletResponse response) throws Exception {
|
|
|
+ if (mesMaterialCheckRecord == null || StringUtils.isBlank(mesMaterialCheckRecord.getId())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ MesMaterialCheckRecord record = mesMaterialCheckRecordService.get(mesMaterialCheckRecord.getId());
|
|
|
+ if (record == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ MesMaterialCheckRecordItems itemQuery = new MesMaterialCheckRecordItems();
|
|
|
+ itemQuery.setRecordId(record.getId());
|
|
|
+ List<MesMaterialCheckRecordItems> items = mesMaterialCheckRecordItemsService.findList(itemQuery);
|
|
|
+ for (MesMaterialCheckRecordItems item : items) {
|
|
|
+ fillOrgName(item);
|
|
|
+ }
|
|
|
+ String fileName = "来料检查检测数据_" + StringUtils.defaultString(record.getSn()) + "_"
|
|
|
+ + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
|
|
|
+ writeDetailCheckExcel(record, items, response, fileName);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 查看编辑表单
|
|
|
*/
|
|
|
@RequiresPermissions("mes:mesMaterialCheckRecord:view")
|
|
|
@@ -126,6 +181,7 @@ public class MesMaterialCheckRecordController extends BaseController {
|
|
|
mesMaterialCheckRecordItems.setRecordId(mesMaterialCheckRecord.getId());
|
|
|
List<MesMaterialCheckRecordItems> items = mesMaterialCheckRecordItemsService.findList(mesMaterialCheckRecordItems);
|
|
|
model.addAttribute("MesMaterialCheckRecordItems", items);
|
|
|
+ model.addAttribute("sampleCount", resolveRecordSampleCount(mesMaterialCheckRecord, items));
|
|
|
|
|
|
return "modules/mes/mesMaterialCheckRecordForm2";
|
|
|
}
|
|
|
@@ -152,6 +208,8 @@ public class MesMaterialCheckRecordController extends BaseController {
|
|
|
}
|
|
|
|
|
|
mesMaterialCheckRecord.setState(result);
|
|
|
+ int sampleCount = mesMaterialCheckRecordService.resolveSampleCount(mesMaterialCheckRecord.getMaterialId());
|
|
|
+ mesMaterialCheckRecord.setSampleCount(sampleCount);
|
|
|
mesMaterialCheckRecordService.save(mesMaterialCheckRecord);
|
|
|
|
|
|
// 更新报检编号相同的都更新
|
|
|
@@ -179,6 +237,9 @@ public class MesMaterialCheckRecordController extends BaseController {
|
|
|
mesMaterialCheckRecordItems.setA3(mecheck.getJSONObject(i).getString("a3"));
|
|
|
mesMaterialCheckRecordItems.setA4(mecheck.getJSONObject(i).getString("a4"));
|
|
|
mesMaterialCheckRecordItems.setA5(mecheck.getJSONObject(i).getString("a5"));
|
|
|
+ mesMaterialCheckRecordItems.setA6(mecheck.getJSONObject(i).getString("a6"));
|
|
|
+ mesMaterialCheckRecordItems.setA7(mecheck.getJSONObject(i).getString("a7"));
|
|
|
+ mesMaterialCheckRecordItems.setA8(mecheck.getJSONObject(i).getString("a8"));
|
|
|
mesMaterialCheckRecordItems.setResult(mecheck.getJSONObject(i).getString("result"));
|
|
|
mesMaterialCheckRecordItemsService.save(mesMaterialCheckRecordItems);
|
|
|
String org = mecheck.getJSONObject(i).getString("org");
|
|
|
@@ -203,6 +264,7 @@ public class MesMaterialCheckRecordController extends BaseController {
|
|
|
MesApproval approval = mesApprovalService.get(approvalId);
|
|
|
MesMaterialBlpRecord mesMaterialBlpRecord = new MesMaterialBlpRecord();
|
|
|
mesMaterialBlpRecord.setCheckRecordId(mesMaterialCheckRecord.getId());
|
|
|
+ mesMaterialBlpRecord.setState("1");
|
|
|
mesMaterialBlpRecordService.save(mesMaterialBlpRecord);
|
|
|
if(!approval.getNodes().isEmpty()){
|
|
|
String[] ids = approval.getNodes().split(",");
|
|
|
@@ -237,6 +299,16 @@ public class MesMaterialCheckRecordController extends BaseController {
|
|
|
}
|
|
|
|
|
|
model.addAttribute("mitList", mitList);
|
|
|
+ model.addAttribute("sampleCount", resolveRecordSampleCount(mesMaterialCheckRecord, mitList));
|
|
|
+
|
|
|
+ List teCaiFiles = loadBizFiles(mesMaterialCheckRecord.getId(), "mesMaterialCheckRecord_teCai_file", host);
|
|
|
+ if (!ListUtils.isEmpty(teCaiFiles)) {
|
|
|
+ model.addAttribute("teCaiFiles", teCaiFiles);
|
|
|
+ }
|
|
|
+ List fuCeFiles = loadBizFiles(mesMaterialCheckRecord.getId(), "mesMaterialCheckRecord_fuCe_file", host);
|
|
|
+ if (!ListUtils.isEmpty(fuCeFiles)) {
|
|
|
+ model.addAttribute("fuCeFiles", fuCeFiles);
|
|
|
+ }
|
|
|
|
|
|
return "modules/mes/mesMaterialCheckRecordInfo";
|
|
|
}
|
|
|
@@ -418,12 +490,16 @@ public class MesMaterialCheckRecordController extends BaseController {
|
|
|
nums = Long.valueOf(result[2]); // 新规则下默认为0
|
|
|
}
|
|
|
|
|
|
+ int sampleCount = mesMaterialCheckRecordService.resolveSampleCount(ma.getId());
|
|
|
+
|
|
|
Map<String, Object> map = MapUtils.newHashMap();
|
|
|
map.put("sn", sn);
|
|
|
map.put("nums", nums);
|
|
|
map.put("result", result);
|
|
|
map.put("info", ma);
|
|
|
map.put("mitList", mitList);
|
|
|
+ map.put("sampleCount", sampleCount);
|
|
|
+ map.put("tightened", sampleCount >= MesMaterialCheckRecordService.SAMPLE_COUNT_TIGHTENED);
|
|
|
resp.setData(map);
|
|
|
resp.setResult(Global.TRUE);
|
|
|
return resp;
|
|
|
@@ -436,39 +512,10 @@ public class MesMaterialCheckRecordController extends BaseController {
|
|
|
@RequestMapping(value = "edit")
|
|
|
public String edit(MesMaterialCheckRecord mesMaterialCheckRecord, Model model,HttpServletRequest req) {
|
|
|
model.addAttribute("mesMaterialCheckRecord", mesMaterialCheckRecord);
|
|
|
-// MesMaterialCheckRecordItems mci = new MesMaterialCheckRecordItems();
|
|
|
-// mci.setRecordId(mesMaterialCheckRecord.getId());
|
|
|
-// List<MesMaterialCheckRecordItems> mitList = mesMaterialCheckRecordItemsService.findList(mci);
|
|
|
-// model.addAttribute("mitList", mitList);
|
|
|
-// String host = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort() + "/js";
|
|
|
-//
|
|
|
-// for (MesMaterialCheckRecordItems item:mitList){
|
|
|
-// DictData dictData = new DictData();
|
|
|
-// dictData.setDictType("mes_material_org");
|
|
|
-// dictData.setDictValue(item.getOrg());
|
|
|
-// List<DictData> dic = dictDataService.findList(dictData);
|
|
|
-// if(!ListUtils.isEmpty(dic)){
|
|
|
-// item.setOrgName(dic.get(0).getDictLabel());
|
|
|
-// }
|
|
|
-//
|
|
|
-// FileUpload fu = new FileUpload();
|
|
|
-// fu.setBizKey(item.getCheckId());
|
|
|
-// fu.setBizType("mesMaterialCheck_image");
|
|
|
-// List<FileUpload> finfo = fileUploadService.findList(fu);
|
|
|
-// List imgList = ListUtils.newArrayList();
|
|
|
-// for (FileUpload fi:finfo){
|
|
|
-// Map<String, Object> map1 = MapUtils.newHashMap();
|
|
|
-// map1.put("id",fi.getFileEntity().getFileId());
|
|
|
-// map1.put("url",host + fi.getFileUrl());
|
|
|
-// map1.put("name",fi.getFileName());
|
|
|
-// map1.put("size",fi.getFileEntity().getFileSize());
|
|
|
-//
|
|
|
-// imgList.add(map1);
|
|
|
-// }
|
|
|
-// item.setImg(imgList);
|
|
|
-// }
|
|
|
-//
|
|
|
-// model.addAttribute("mitList", mitList);
|
|
|
+ MesMaterialCheckRecordItems sampleQuery = new MesMaterialCheckRecordItems();
|
|
|
+ sampleQuery.setRecordId(mesMaterialCheckRecord.getId());
|
|
|
+ List<MesMaterialCheckRecordItems> sampleItems = mesMaterialCheckRecordItemsService.findList(sampleQuery);
|
|
|
+ model.addAttribute("sampleCount", resolveRecordSampleCount(mesMaterialCheckRecord, sampleItems));
|
|
|
return "modules/mes/mesMaterialCheckRecordFormEdit";
|
|
|
}
|
|
|
@RequestMapping(value = "getSnInfo2")
|
|
|
@@ -546,6 +593,289 @@ public class MesMaterialCheckRecordController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 组装检测明细导出数据:优先按勾选 ids,其次单条 id
|
|
|
+ */
|
|
|
+ private List<MesMaterialCheckRecordItems> buildCheckDataExportList(MesMaterialCheckRecord query, String ids) {
|
|
|
+ List<MesMaterialCheckRecord> records = ListUtils.newArrayList();
|
|
|
+ if (StringUtils.isNotBlank(ids)) {
|
|
|
+ String[] idArr = ids.split(",");
|
|
|
+ MesMaterialCheckRecord idQuery = new MesMaterialCheckRecord();
|
|
|
+ idQuery.getSqlMap().getWhere().and("id", QueryType.IN, idArr);
|
|
|
+ records = mesMaterialCheckRecordService.findList(idQuery);
|
|
|
+ } else if (query != null && StringUtils.isNotBlank(query.getId())) {
|
|
|
+ MesMaterialCheckRecord record = mesMaterialCheckRecordService.get(query.getId());
|
|
|
+ if (record != null) {
|
|
|
+ records.add(record);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<MesMaterialCheckRecordItems> exportList = ListUtils.newArrayList();
|
|
|
+ if (ListUtils.isEmpty(records)) {
|
|
|
+ return exportList;
|
|
|
+ }
|
|
|
+ for (MesMaterialCheckRecord record : records) {
|
|
|
+ MesMaterialCheckRecordItems itemQuery = new MesMaterialCheckRecordItems();
|
|
|
+ itemQuery.setRecordId(record.getId());
|
|
|
+ List<MesMaterialCheckRecordItems> items = mesMaterialCheckRecordItemsService.findList(itemQuery);
|
|
|
+ if (ListUtils.isEmpty(items)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String recordStateLabel = DictUtils.getDictLabel("mes_material_check_record_state", record.getState(), "未知");
|
|
|
+ for (MesMaterialCheckRecordItems item : items) {
|
|
|
+ fillOrgName(item);
|
|
|
+ item.setSn(record.getSn());
|
|
|
+ item.setMaterialTitle(record.getMaterialTitle());
|
|
|
+ item.setFaDate(record.getFaDate());
|
|
|
+ item.setNums(record.getNums());
|
|
|
+ item.setFaNums(record.getFaNums());
|
|
|
+ item.setRecordState(recordStateLabel);
|
|
|
+ item.setCheckBy(record.getCreateBy());
|
|
|
+ item.setCheckDate(record.getCreateDate());
|
|
|
+ if ("1".equals(item.getResult())) {
|
|
|
+ item.setResult("合格");
|
|
|
+ } else {
|
|
|
+ item.setResult("不合格");
|
|
|
+ }
|
|
|
+ exportList.add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return exportList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 详情页专用导出:上方基本信息(不重复),下方检测明细表
|
|
|
+ */
|
|
|
+ private void writeDetailCheckExcel(MesMaterialCheckRecord record, List<MesMaterialCheckRecordItems> items,
|
|
|
+ HttpServletResponse response, String fileName) throws Exception {
|
|
|
+ try (Workbook wb = new XSSFWorkbook()) {
|
|
|
+ Sheet sheet = wb.createSheet("来料检查检测数据");
|
|
|
+ int sampleCount = resolveRecordSampleCount(record, items);
|
|
|
+ // 项目 + 检查内容 + 实测值N + 项目结果
|
|
|
+ final int colCount = 2 + sampleCount + 1;
|
|
|
+
|
|
|
+ Font titleFont = wb.createFont();
|
|
|
+ titleFont.setBold(true);
|
|
|
+ titleFont.setFontHeightInPoints((short) 16);
|
|
|
+ titleFont.setFontName("微软雅黑");
|
|
|
+
|
|
|
+ Font sectionFont = wb.createFont();
|
|
|
+ sectionFont.setBold(true);
|
|
|
+ sectionFont.setFontHeightInPoints((short) 12);
|
|
|
+ sectionFont.setFontName("微软雅黑");
|
|
|
+
|
|
|
+ Font boldFont = wb.createFont();
|
|
|
+ boldFont.setBold(true);
|
|
|
+ boldFont.setFontName("微软雅黑");
|
|
|
+ boldFont.setFontHeightInPoints((short) 10);
|
|
|
+
|
|
|
+ Font normalFont = wb.createFont();
|
|
|
+ normalFont.setFontName("微软雅黑");
|
|
|
+ normalFont.setFontHeightInPoints((short) 10);
|
|
|
+
|
|
|
+ short lightGray = IndexedColors.GREY_25_PERCENT.getIndex();
|
|
|
+ CellStyle titleStyle = createBorderedStyle(wb, titleFont, HorizontalAlignment.CENTER, true, lightGray);
|
|
|
+ CellStyle sectionStyle = createBorderedStyle(wb, sectionFont, HorizontalAlignment.LEFT, true, lightGray);
|
|
|
+ CellStyle labelStyle = createBorderedStyle(wb, boldFont, HorizontalAlignment.CENTER, true, lightGray);
|
|
|
+ CellStyle valueStyle = createBorderedStyle(wb, normalFont, HorizontalAlignment.LEFT, false, null);
|
|
|
+ CellStyle headerStyle = createBorderedStyle(wb, boldFont, HorizontalAlignment.CENTER, true, lightGray);
|
|
|
+ headerStyle.setWrapText(true);
|
|
|
+ CellStyle centerStyle = createBorderedStyle(wb, normalFont, HorizontalAlignment.CENTER, false, null);
|
|
|
+ centerStyle.setWrapText(true);
|
|
|
+ CellStyle leftWrapStyle = createBorderedStyle(wb, normalFont, HorizontalAlignment.LEFT, false, null);
|
|
|
+ leftWrapStyle.setWrapText(true);
|
|
|
+
|
|
|
+ int rowIdx = 0;
|
|
|
+ Row titleRow = sheet.createRow(rowIdx++);
|
|
|
+ titleRow.setHeightInPoints(30);
|
|
|
+ fillRowCells(titleRow, colCount, titleStyle);
|
|
|
+ titleRow.getCell(0).setCellValue("来料检查检测数据");
|
|
|
+ CellRangeAddress titleRegion = new CellRangeAddress(0, 0, 0, colCount - 1);
|
|
|
+ sheet.addMergedRegion(titleRegion);
|
|
|
+ applyRegionBorder(sheet, titleRegion);
|
|
|
+
|
|
|
+ rowIdx++;
|
|
|
+ Row baseSection = sheet.createRow(rowIdx++);
|
|
|
+ baseSection.setHeightInPoints(20);
|
|
|
+ fillRowCells(baseSection, colCount, sectionStyle);
|
|
|
+ baseSection.getCell(0).setCellValue("一、基本信息");
|
|
|
+ CellRangeAddress baseSectionRegion = new CellRangeAddress(baseSection.getRowNum(), baseSection.getRowNum(), 0, colCount - 1);
|
|
|
+ sheet.addMergedRegion(baseSectionRegion);
|
|
|
+ applyRegionBorder(sheet, baseSectionRegion);
|
|
|
+
|
|
|
+ String recordStateLabel = DictUtils.getDictLabel("mes_material_check_record_state", record.getState(), "未知");
|
|
|
+ String checkDate = record.getCreateDate() == null ? "" : DateUtils.formatDateTime(record.getCreateDate());
|
|
|
+ String[][] basePairs = new String[][]{
|
|
|
+ {"来料码", StringUtils.defaultString(record.getSn()), "物料", StringUtils.defaultString(record.getMaterialTitle())},
|
|
|
+ {"发货日期", StringUtils.defaultString(record.getFaDate()), "报检数量", record.getNums() == null ? "" : String.valueOf(record.getNums())},
|
|
|
+ {"参与抽检数量", record.getFaNums() == null ? "" : String.valueOf(record.getFaNums()), "整单结果", recordStateLabel},
|
|
|
+ {"检查人", StringUtils.defaultString(record.getCreateBy()), "检查日期", checkDate},
|
|
|
+ {"抽样数", String.valueOf(sampleCount), "", ""},
|
|
|
+ };
|
|
|
+ int mid = Math.max(3, colCount / 2);
|
|
|
+ for (String[] pair : basePairs) {
|
|
|
+ Row row = sheet.createRow(rowIdx++);
|
|
|
+ row.setHeightInPoints(20);
|
|
|
+ fillRowCells(row, colCount, valueStyle);
|
|
|
+ row.getCell(0).setCellValue(pair[0]);
|
|
|
+ row.getCell(0).setCellStyle(labelStyle);
|
|
|
+ row.getCell(1).setCellValue(pair[1]);
|
|
|
+ row.getCell(1).setCellStyle(valueStyle);
|
|
|
+ if (mid - 1 >= 2) {
|
|
|
+ CellRangeAddress leftValueRegion = new CellRangeAddress(row.getRowNum(), row.getRowNum(), 1, mid - 1);
|
|
|
+ sheet.addMergedRegion(leftValueRegion);
|
|
|
+ applyRegionBorder(sheet, leftValueRegion);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(pair[2])) {
|
|
|
+ row.getCell(mid).setCellValue(pair[2]);
|
|
|
+ row.getCell(mid).setCellStyle(labelStyle);
|
|
|
+ row.getCell(mid + 1).setCellValue(pair[3]);
|
|
|
+ row.getCell(mid + 1).setCellStyle(valueStyle);
|
|
|
+ if (colCount - 1 > mid + 1) {
|
|
|
+ CellRangeAddress rightValueRegion = new CellRangeAddress(row.getRowNum(), row.getRowNum(), mid + 1, colCount - 1);
|
|
|
+ sheet.addMergedRegion(rightValueRegion);
|
|
|
+ applyRegionBorder(sheet, rightValueRegion);
|
|
|
+ }
|
|
|
+ } else if (colCount - 1 > 1) {
|
|
|
+ CellRangeAddress leftOnlyRegion = new CellRangeAddress(row.getRowNum(), row.getRowNum(), 1, colCount - 1);
|
|
|
+ sheet.addMergedRegion(leftOnlyRegion);
|
|
|
+ applyRegionBorder(sheet, leftOnlyRegion);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ rowIdx++;
|
|
|
+ Row detailSection = sheet.createRow(rowIdx++);
|
|
|
+ detailSection.setHeightInPoints(20);
|
|
|
+ fillRowCells(detailSection, colCount, sectionStyle);
|
|
|
+ detailSection.getCell(0).setCellValue("二、检测明细");
|
|
|
+ CellRangeAddress detailSectionRegion = new CellRangeAddress(detailSection.getRowNum(), detailSection.getRowNum(), 0, colCount - 1);
|
|
|
+ sheet.addMergedRegion(detailSectionRegion);
|
|
|
+ applyRegionBorder(sheet, detailSectionRegion);
|
|
|
+
|
|
|
+ String[] headers = new String[colCount];
|
|
|
+ headers[0] = "项目";
|
|
|
+ headers[1] = "检查内容";
|
|
|
+ for (int i = 1; i <= sampleCount; i++) {
|
|
|
+ headers[1 + i] = "实测值" + i;
|
|
|
+ }
|
|
|
+ headers[colCount - 1] = "项目结果";
|
|
|
+ Row headerRow = sheet.createRow(rowIdx++);
|
|
|
+ headerRow.setHeightInPoints(22);
|
|
|
+ for (int i = 0; i < headers.length; i++) {
|
|
|
+ Cell cell = headerRow.createCell(i);
|
|
|
+ cell.setCellValue(headers[i]);
|
|
|
+ cell.setCellStyle(headerStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!ListUtils.isEmpty(items)) {
|
|
|
+ for (MesMaterialCheckRecordItems item : items) {
|
|
|
+ Row row = sheet.createRow(rowIdx++);
|
|
|
+ row.setHeightInPoints(20);
|
|
|
+ String resultLabel = "1".equals(item.getResult()) ? "合格" : "不合格";
|
|
|
+ String[] sampleValues = {
|
|
|
+ StringUtils.defaultString(item.getA1()),
|
|
|
+ StringUtils.defaultString(item.getA2()),
|
|
|
+ StringUtils.defaultString(item.getA3()),
|
|
|
+ StringUtils.defaultString(item.getA4()),
|
|
|
+ StringUtils.defaultString(item.getA5()),
|
|
|
+ StringUtils.defaultString(item.getA6()),
|
|
|
+ StringUtils.defaultString(item.getA7()),
|
|
|
+ StringUtils.defaultString(item.getA8())
|
|
|
+ };
|
|
|
+ String[] values = new String[colCount];
|
|
|
+ values[0] = StringUtils.defaultString(item.getOrgName());
|
|
|
+ values[1] = StringUtils.defaultString(item.getMaterialCheckTitle());
|
|
|
+ for (int i = 0; i < sampleCount; i++) {
|
|
|
+ values[2 + i] = sampleValues[i];
|
|
|
+ }
|
|
|
+ values[colCount - 1] = resultLabel;
|
|
|
+ for (int i = 0; i < values.length; i++) {
|
|
|
+ Cell cell = row.createCell(i);
|
|
|
+ cell.setCellValue(values[i]);
|
|
|
+ cell.setCellStyle(i == 1 ? leftWrapStyle : centerStyle);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Row emptyRow = sheet.createRow(rowIdx++);
|
|
|
+ emptyRow.setHeightInPoints(20);
|
|
|
+ fillRowCells(emptyRow, colCount, centerStyle);
|
|
|
+ emptyRow.getCell(0).setCellValue("暂无检测明细");
|
|
|
+ CellRangeAddress emptyRegion = new CellRangeAddress(emptyRow.getRowNum(), emptyRow.getRowNum(), 0, colCount - 1);
|
|
|
+ sheet.addMergedRegion(emptyRegion);
|
|
|
+ applyRegionBorder(sheet, emptyRegion);
|
|
|
+ }
|
|
|
+
|
|
|
+ sheet.setColumnWidth(0, 3500);
|
|
|
+ sheet.setColumnWidth(1, 12000);
|
|
|
+ for (int i = 0; i < sampleCount; i++) {
|
|
|
+ sheet.setColumnWidth(2 + i, 3200);
|
|
|
+ }
|
|
|
+ sheet.setColumnWidth(colCount - 1, 3500);
|
|
|
+ sheet.createFreezePane(0, headerRow.getRowNum() + 1);
|
|
|
+
|
|
|
+ response.reset();
|
|
|
+ response.setContentType("application/octet-stream; charset=utf-8");
|
|
|
+ response.addHeader("Content-Disposition", "attachment; filename*=utf-8'zh_cn'" + EncodeUtils.encodeUrl(fileName));
|
|
|
+ wb.write(response.getOutputStream());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析历史记录的抽样数:优先用记录字段;旧数据则根据是否存在 a6~a8 推断。
|
|
|
+ */
|
|
|
+ private int resolveRecordSampleCount(MesMaterialCheckRecord record, List<MesMaterialCheckRecordItems> items) {
|
|
|
+ if (record != null && record.getSampleCount() != null && record.getSampleCount() > 0) {
|
|
|
+ return record.getSampleCount();
|
|
|
+ }
|
|
|
+ if (!ListUtils.isEmpty(items)) {
|
|
|
+ for (MesMaterialCheckRecordItems item : items) {
|
|
|
+ if (StringUtils.isNotBlank(item.getA6())
|
|
|
+ || StringUtils.isNotBlank(item.getA7())
|
|
|
+ || StringUtils.isNotBlank(item.getA8())) {
|
|
|
+ return MesMaterialCheckRecordService.SAMPLE_COUNT_TIGHTENED;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return MesMaterialCheckRecordService.SAMPLE_COUNT_NORMAL;
|
|
|
+ }
|
|
|
+
|
|
|
+ private CellStyle createBorderedStyle(Workbook wb, Font font, HorizontalAlignment align, boolean fill, Short fillColor) {
|
|
|
+ CellStyle style = wb.createCellStyle();
|
|
|
+ style.setFont(font);
|
|
|
+ style.setAlignment(align);
|
|
|
+ style.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ style.setBorderTop(BorderStyle.THIN);
|
|
|
+ style.setBorderBottom(BorderStyle.THIN);
|
|
|
+ style.setBorderLeft(BorderStyle.THIN);
|
|
|
+ style.setBorderRight(BorderStyle.THIN);
|
|
|
+ style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
|
|
|
+ style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
|
|
|
+ style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
|
|
|
+ style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
|
|
|
+ if (fill && fillColor != null) {
|
|
|
+ style.setFillForegroundColor(fillColor);
|
|
|
+ style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
+ }
|
|
|
+ return style;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void fillRowCells(Row row, int colCount, CellStyle style) {
|
|
|
+ for (int i = 0; i < colCount; i++) {
|
|
|
+ Cell cell = row.createCell(i);
|
|
|
+ cell.setCellStyle(style);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void applyRegionBorder(Sheet sheet, CellRangeAddress region) {
|
|
|
+ RegionUtil.setBorderTop(BorderStyle.THIN, region, sheet);
|
|
|
+ RegionUtil.setBorderBottom(BorderStyle.THIN, region, sheet);
|
|
|
+ RegionUtil.setBorderLeft(BorderStyle.THIN, region, sheet);
|
|
|
+ RegionUtil.setBorderRight(BorderStyle.THIN, region, sheet);
|
|
|
+ RegionUtil.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex(), region, sheet);
|
|
|
+ RegionUtil.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex(), region, sheet);
|
|
|
+ RegionUtil.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex(), region, sheet);
|
|
|
+ RegionUtil.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex(), region, sheet);
|
|
|
+ }
|
|
|
+
|
|
|
private void loadCheckTemplateImages(MesMaterialCheckRecordItems item, String host) {
|
|
|
FileUpload fu = new FileUpload();
|
|
|
fu.setBizKey(item.getCheckId());
|
|
|
@@ -598,6 +928,9 @@ public class MesMaterialCheckRecordController extends BaseController {
|
|
|
items.setA3(mecheck.getJSONObject(i).getString("a3"));
|
|
|
items.setA4(mecheck.getJSONObject(i).getString("a4"));
|
|
|
items.setA5(mecheck.getJSONObject(i).getString("a5"));
|
|
|
+ items.setA6(mecheck.getJSONObject(i).getString("a6"));
|
|
|
+ items.setA7(mecheck.getJSONObject(i).getString("a7"));
|
|
|
+ items.setA8(mecheck.getJSONObject(i).getString("a8"));
|
|
|
items.setResult(mecheck.getJSONObject(i).getString("result"));
|
|
|
mesMaterialCheckRecordItemsService.save(items);
|
|
|
String org = mecheck.getJSONObject(i).getString("org");
|
|
|
@@ -609,4 +942,189 @@ public class MesMaterialCheckRecordController extends BaseController {
|
|
|
return renderResult(Global.TRUE, text("保存成功!"));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 特采表单
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesMaterialCheckRecord:edit")
|
|
|
+ @RequestMapping(value = "teCai")
|
|
|
+ public String teCai(MesMaterialCheckRecord mesMaterialCheckRecord, Model model) {
|
|
|
+ model.addAttribute("mesMaterialCheckRecord", mesMaterialCheckRecord);
|
|
|
+ return "modules/mes/mesMaterialCheckRecordTeCaiForm";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 特采保存:上传附件后标注为特采,并生成让步入库单
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesMaterialCheckRecord:edit")
|
|
|
+ @PostMapping(value = "teCaiSave")
|
|
|
+ @ResponseBody
|
|
|
+ @Transactional
|
|
|
+ public String teCaiSave(MesMaterialCheckRecord mesMaterialCheckRecord) {
|
|
|
+ if (mesMaterialCheckRecord == null || StringUtils.isBlank(mesMaterialCheckRecord.getId())) {
|
|
|
+ return renderResult(Global.FALSE, text("记录不存在"));
|
|
|
+ }
|
|
|
+ MesMaterialCheckRecord record = mesMaterialCheckRecordService.get(mesMaterialCheckRecord.getId());
|
|
|
+ if (record == null) {
|
|
|
+ return renderResult(Global.FALSE, text("记录不存在"));
|
|
|
+ }
|
|
|
+ if (!"2".equals(record.getState())) {
|
|
|
+ return renderResult(Global.FALSE, text("仅不合格记录可进行特采"));
|
|
|
+ }
|
|
|
+
|
|
|
+ MesMaterialRkRecord rkQuery = new MesMaterialRkRecord();
|
|
|
+ rkQuery.getSqlMap().getWhere().and("check_record_id", QueryType.EQ, record.getId());
|
|
|
+ List<MesMaterialRkRecord> existRk = mesMaterialRkRecordService.findList(rkQuery);
|
|
|
+ if (!ListUtils.isEmpty(existRk)) {
|
|
|
+ return renderResult(Global.FALSE, text("该记录已生成入库单,不能重复特采"));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 先保存附件,再校验是否已上传
|
|
|
+ FileUploadUtils.saveFileUpload(mesMaterialCheckRecord, record.getId(), "mesMaterialCheckRecord_teCai_file");
|
|
|
+ FileUpload fu = new FileUpload();
|
|
|
+ fu.setBizKey(record.getId());
|
|
|
+ fu.setBizType("mesMaterialCheckRecord_teCai_file");
|
|
|
+ List<FileUpload> teCaiFiles = fileUploadService.findList(fu);
|
|
|
+ if (ListUtils.isEmpty(teCaiFiles)) {
|
|
|
+ return renderResult(Global.FALSE, text("请先上传特采文件"));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 标注为特采
|
|
|
+ record.setState("3");
|
|
|
+ mesMaterialCheckRecordService.update(record);
|
|
|
+
|
|
|
+ // 生成让步入库单(与不良品审批通过逻辑一致)
|
|
|
+ MesMaterialRkRecord mesMaterialRkRecord = new MesMaterialRkRecord();
|
|
|
+ mesMaterialRkRecord.setCheckRecordId(record.getId());
|
|
|
+ mesMaterialRkRecord.setType("2");
|
|
|
+ mesMaterialRkRecord.setRemark("特采入库");
|
|
|
+ mesMaterialRkRecordService.save(mesMaterialRkRecord);
|
|
|
+
|
|
|
+ MesMaterialRkRecordItems mesMaterialRkRecordItems = new MesMaterialRkRecordItems();
|
|
|
+ mesMaterialRkRecordItems.setRecordId(mesMaterialRkRecord.getId());
|
|
|
+ mesMaterialRkRecordItems.setMaterialId(record.getMaterialId());
|
|
|
+ mesMaterialRkRecordItems.setNums(record.getNums());
|
|
|
+ mesMaterialRkRecordItemsService.save(mesMaterialRkRecordItems);
|
|
|
+
|
|
|
+ // 关闭关联不良品待审记录,避免重复审批入库
|
|
|
+ closePendingBlp(record.getId(), "特采自动关闭");
|
|
|
+
|
|
|
+ return renderResult(Global.TRUE, text("特采成功,已生成让步入库单!"));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 复测表单
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesMaterialCheckRecord:edit")
|
|
|
+ @RequestMapping(value = "fuCe")
|
|
|
+ public String fuCe(MesMaterialCheckRecord mesMaterialCheckRecord, Model model) {
|
|
|
+ model.addAttribute("mesMaterialCheckRecord", mesMaterialCheckRecord);
|
|
|
+ return "modules/mes/mesMaterialCheckRecordFuCeForm";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 复测保存:上传附件并选择合格/不合格
|
|
|
+ */
|
|
|
+ @RequiresPermissions("mes:mesMaterialCheckRecord:edit")
|
|
|
+ @PostMapping(value = "fuCeSave")
|
|
|
+ @ResponseBody
|
|
|
+ @Transactional
|
|
|
+ public String fuCeSave(MesMaterialCheckRecord mesMaterialCheckRecord, HttpServletRequest request) {
|
|
|
+ if (mesMaterialCheckRecord == null || StringUtils.isBlank(mesMaterialCheckRecord.getId())) {
|
|
|
+ return renderResult(Global.FALSE, text("记录不存在"));
|
|
|
+ }
|
|
|
+ MesMaterialCheckRecord record = mesMaterialCheckRecordService.get(mesMaterialCheckRecord.getId());
|
|
|
+ if (record == null) {
|
|
|
+ return renderResult(Global.FALSE, text("记录不存在"));
|
|
|
+ }
|
|
|
+ if (!"2".equals(record.getState())) {
|
|
|
+ return renderResult(Global.FALSE, text("仅不合格记录可进行复测"));
|
|
|
+ }
|
|
|
+
|
|
|
+ String retestResult = request.getParameter("retestResult");
|
|
|
+ if (!"1".equals(retestResult) && !"2".equals(retestResult)) {
|
|
|
+ return renderResult(Global.FALSE, text("请选择复测结果"));
|
|
|
+ }
|
|
|
+
|
|
|
+ FileUploadUtils.saveFileUpload(mesMaterialCheckRecord, record.getId(), "mesMaterialCheckRecord_fuCe_file");
|
|
|
+ FileUpload fu = new FileUpload();
|
|
|
+ fu.setBizKey(record.getId());
|
|
|
+ fu.setBizType("mesMaterialCheckRecord_fuCe_file");
|
|
|
+ List<FileUpload> fuCeFiles = fileUploadService.findList(fu);
|
|
|
+ if (ListUtils.isEmpty(fuCeFiles)) {
|
|
|
+ return renderResult(Global.FALSE, text("请先上传复测文件"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if ("1".equals(retestResult)) {
|
|
|
+ MesMaterialRkRecord rkQuery = new MesMaterialRkRecord();
|
|
|
+ rkQuery.getSqlMap().getWhere().and("check_record_id", QueryType.EQ, record.getId());
|
|
|
+ List<MesMaterialRkRecord> existRk = mesMaterialRkRecordService.findList(rkQuery);
|
|
|
+ if (!ListUtils.isEmpty(existRk)) {
|
|
|
+ return renderResult(Global.FALSE, text("该记录已生成入库单,不能重复提交合格"));
|
|
|
+ }
|
|
|
+
|
|
|
+ record.setState("1");
|
|
|
+ mesMaterialCheckRecordService.update(record);
|
|
|
+
|
|
|
+ MesMaterialRkRecord mesMaterialRkRecord = new MesMaterialRkRecord();
|
|
|
+ mesMaterialRkRecord.setCheckRecordId(record.getId());
|
|
|
+ mesMaterialRkRecord.setType("1");
|
|
|
+ mesMaterialRkRecord.setRemark("复测合格入库");
|
|
|
+ mesMaterialRkRecordService.save(mesMaterialRkRecord);
|
|
|
+
|
|
|
+ MesMaterialRkRecordItems mesMaterialRkRecordItems = new MesMaterialRkRecordItems();
|
|
|
+ mesMaterialRkRecordItems.setRecordId(mesMaterialRkRecord.getId());
|
|
|
+ mesMaterialRkRecordItems.setMaterialId(record.getMaterialId());
|
|
|
+ mesMaterialRkRecordItems.setNums(record.getNums());
|
|
|
+ mesMaterialRkRecordItemsService.save(mesMaterialRkRecordItems);
|
|
|
+
|
|
|
+ closePendingBlp(record.getId(), "复测合格自动关闭");
|
|
|
+ return renderResult(Global.TRUE, text("复测合格,已生成入库单!"));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 复测仍不合格:仅保存附件,结果保持不合格
|
|
|
+ return renderResult(Global.TRUE, text("复测结果已提交(仍不合格)!"));
|
|
|
+ }
|
|
|
+
|
|
|
+ private List loadBizFiles(String bizKey, String bizType, String host) {
|
|
|
+ FileUpload fu = new FileUpload();
|
|
|
+ fu.setBizKey(bizKey);
|
|
|
+ fu.setBizType(bizType);
|
|
|
+ List<FileUpload> finfo = fileUploadService.findList(fu);
|
|
|
+ List fileList = ListUtils.newArrayList();
|
|
|
+ for (FileUpload fi : finfo) {
|
|
|
+ Map<String, Object> map1 = MapUtils.newHashMap();
|
|
|
+ map1.put("id", fi.getFileEntity().getFileId());
|
|
|
+ map1.put("url", host + fi.getFileUrl());
|
|
|
+ map1.put("name", fi.getFileName());
|
|
|
+ map1.put("size", fi.getFileEntity().getFileSize());
|
|
|
+ fileList.add(map1);
|
|
|
+ }
|
|
|
+ return fileList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void closePendingBlp(String checkRecordId, String remark) {
|
|
|
+ MesMaterialBlpRecord blpQuery = new MesMaterialBlpRecord();
|
|
|
+ blpQuery.getSqlMap().getWhere().and("check_record_id", QueryType.EQ, checkRecordId);
|
|
|
+ List<MesMaterialBlpRecord> blpList = mesMaterialBlpRecordService.findList(blpQuery);
|
|
|
+ if (ListUtils.isEmpty(blpList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (MesMaterialBlpRecord blp : blpList) {
|
|
|
+ if (StringUtils.isBlank(blp.getState()) || "1".equals(blp.getState())) {
|
|
|
+ blp.setState("2");
|
|
|
+ mesMaterialBlpRecordService.update(blp);
|
|
|
+ List<MesApply> applyList = mesApplyService.getApplyData("2", blp.getId(), 0);
|
|
|
+ if (!ListUtils.isEmpty(applyList)) {
|
|
|
+ for (MesApply apply : applyList) {
|
|
|
+ if ("0".equals(apply.getState())) {
|
|
|
+ apply.setState("3");
|
|
|
+ apply.setRemark(remark);
|
|
|
+ mesApplyService.update(apply);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|