You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

276 lines
9.6 KiB

  1. package com.xujie.modules.inspection.controller;
  2. import com.xujie.common.utils.PageUtils;
  3. import com.xujie.common.utils.R;
  4. import com.xujie.modules.inspection.data.*;
  5. import com.xujie.modules.inspection.entity.InspectionRequestDetail;
  6. import com.xujie.modules.inspection.entity.InspectionRequestDetailSub;
  7. import com.xujie.modules.inspection.entity.InspectionRequestHeader;
  8. import com.xujie.modules.inspection.entity.QcPersonList;
  9. import com.xujie.modules.inspection.service.*;
  10. import org.apache.poi.ss.usermodel.*;
  11. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.core.io.ByteArrayResource;
  14. import org.springframework.core.io.Resource;
  15. import org.springframework.http.HttpHeaders;
  16. import org.springframework.http.MediaType;
  17. import org.springframework.http.ResponseEntity;
  18. import org.springframework.web.bind.annotation.*;
  19. import org.springframework.web.multipart.MultipartFile;
  20. import java.io.ByteArrayOutputStream;
  21. import java.net.URLEncoder;
  22. import java.nio.charset.StandardCharsets;
  23. import java.util.List;
  24. import java.util.Map;
  25. @RestController
  26. @RequestMapping("/inspection")
  27. public class InspectionController {
  28. @Autowired
  29. private InspectionRequestService inspectionRequestService;
  30. @Autowired
  31. private InspectionRequestDetailService inspectionRequestDetailService;
  32. @Autowired
  33. private InspectionRequestDetailSubService inspectionRequestDetailSubService;
  34. /**
  35. * 检验申请单头表分页查询
  36. */
  37. @PostMapping(value = "/searchInspectionRequestHeaderList")
  38. public R searchInspectionRequestHeaderList(@RequestBody InspectionRequestHeader data) {
  39. PageUtils page = inspectionRequestService.myPage(data);
  40. return R.ok().put("page", page);
  41. }
  42. /**
  43. * 根据申请单号查询明细列表分页
  44. */
  45. @PostMapping(value = "/getInspectionRequestDetailList")
  46. public R getInspectionRequestDetailList(@RequestBody InspectionRequestDetail data) {
  47. PageUtils page = new PageUtils(inspectionRequestDetailService.getPageList(data));
  48. return R.ok().put("page", page);
  49. }
  50. /**
  51. * 根据申请单号查询子表明细列表分页
  52. */
  53. @PostMapping(value = "/getInspectionRequestDetailSubList")
  54. public R getInspectionRequestDetailSubList(@RequestBody InspectionRequestDetailSub data) {
  55. PageUtils page = new PageUtils(inspectionRequestDetailSubService.getPageList(data));
  56. return R.ok().put("page", page);
  57. }
  58. /**
  59. * 查询验货结果
  60. */
  61. @PostMapping(value = "/getInspectionResultList")
  62. public R getInspectionResultList(@RequestBody Map<String, String> params) {
  63. String requestNo = params.get("requestNo");
  64. String site = params.get("site");
  65. List<InspectionResultVO> list = inspectionRequestDetailService.getInspectionResultList(requestNo, site);
  66. return R.ok().put("list", list);
  67. }
  68. /**
  69. * 查询可申请验货PO
  70. */
  71. @PostMapping("/queryPoPage")
  72. public R queryPoPage(@RequestBody InspectionRequestItemVO vo){
  73. PageUtils page = inspectionRequestService.queryPoPage(vo);
  74. return R.ok().put("page", page);
  75. }
  76. /**
  77. * 保存验货申请
  78. */
  79. @PostMapping("/save")
  80. public R save(@RequestBody InspectionRequestSaveVO vo){
  81. inspectionRequestService.saveRequest(vo);
  82. return R.ok();
  83. }
  84. /**
  85. * 修改验货申请仅允许修改建议验货日期验货地址和联系人
  86. */
  87. @PostMapping("/update")
  88. public R update(@RequestBody InspectionRequestHeader header){
  89. inspectionRequestService.updateRequest(header);
  90. return R.ok();
  91. }
  92. /**
  93. * 取消验货申请
  94. */
  95. @PostMapping("/cancel/{requestNo}")
  96. public R cancel(@PathVariable String requestNo){
  97. inspectionRequestService.cancel(requestNo);
  98. return R.ok();
  99. }
  100. /**
  101. * 确认验货申请
  102. */
  103. @PostMapping("/confirm/{requestNo}")
  104. public R confirm(@PathVariable String requestNo){
  105. inspectionRequestService.confirm(requestNo);
  106. return R.ok();
  107. }
  108. /**
  109. * 审核验货申请
  110. */
  111. @PostMapping("/audit/{requestNo}")
  112. public R audit(@PathVariable String requestNo){
  113. inspectionRequestService.audit(requestNo);
  114. return R.ok();
  115. }
  116. /**
  117. * 删除验货申请
  118. */
  119. @PostMapping("/delete/{requestNo}")
  120. public R delete(@PathVariable String requestNo){
  121. inspectionRequestService.delete(requestNo);
  122. return R.ok();
  123. }
  124. /**
  125. * 查询qc人员
  126. */
  127. @PostMapping("/getQcPersonList")
  128. public R getQcPersonList(@RequestBody QcPersonList qc ){
  129. PageUtils page = inspectionRequestService.getQcPersonList(qc);
  130. return R.ok().put("page", page);
  131. }
  132. /**
  133. * 验货排程
  134. */
  135. @PostMapping("/schedule")
  136. public R schedule(@RequestBody InspectionScheduleVO vo){
  137. inspectionRequestService.schedule(vo);
  138. return R.ok();
  139. }
  140. /**
  141. * 排程视图查询
  142. */
  143. @GetMapping("/scheduleView")
  144. public R scheduleView(@RequestParam String qcOperator){
  145. List<InspectionScheduleViewVO> list =
  146. inspectionRequestService.queryScheduleView(qcOperator);
  147. return R.ok().put("list", list);
  148. }
  149. /**
  150. * 下载验货申请导入模板
  151. */
  152. @PostMapping("/downloadTemplate")
  153. public ResponseEntity<Resource> downloadTemplate() {
  154. try {
  155. // 直接在内存中生成 Excel 模板
  156. Workbook workbook = new XSSFWorkbook();
  157. Sheet sheet = workbook.createSheet("验货申请数据");
  158. // 创建表头样式
  159. CellStyle headerStyle = workbook.createCellStyle();
  160. Font headerFont = workbook.createFont();
  161. headerFont.setBold(true);
  162. headerStyle.setFont(headerFont);
  163. headerStyle.setAlignment(HorizontalAlignment.CENTER);
  164. headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
  165. // 设置边框
  166. headerStyle.setBorderTop(BorderStyle.THIN);
  167. headerStyle.setBorderBottom(BorderStyle.THIN);
  168. headerStyle.setBorderLeft(BorderStyle.THIN);
  169. headerStyle.setBorderRight(BorderStyle.THIN);
  170. // 设置背景色
  171. headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
  172. headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
  173. // 创建表头行
  174. Row headerRow = sheet.createRow(0);
  175. String[] headers = {
  176. "PO号", "PO行号","产品编码", "验货数量", "运输方式", "CRD", "建议验货日期"
  177. };
  178. for (int i = 0; i < headers.length; i++) {
  179. Cell cell = headerRow.createCell(i);
  180. cell.setCellValue(headers[i]);
  181. cell.setCellStyle(headerStyle);
  182. }
  183. // 添加示例数据行
  184. Row dataRow1 = sheet.createRow(1);
  185. dataRow1.createCell(0).setCellValue("PO20260522001"); // PO号
  186. dataRow1.createCell(1).setCellValue(1); // PO行号
  187. dataRow1.createCell(2).setCellValue("TESTFX"); // 产品编码
  188. dataRow1.createCell(3).setCellValue(200); // 验货数量
  189. dataRow1.createCell(4).setCellValue("海运"); // 运输方式
  190. dataRow1.createCell(5).setCellValue("2026-06-30"); // CRD
  191. dataRow1.createCell(6).setCellValue("2026-05-29"); // 建议验货日期
  192. // 设置列宽
  193. sheet.setColumnWidth(0, 18 * 256); // PO号
  194. sheet.setColumnWidth(1, 15 * 256); // 产品编码
  195. sheet.setColumnWidth(2, 10 * 256); // PO行号
  196. sheet.setColumnWidth(3, 12 * 256); // 验货数量
  197. sheet.setColumnWidth(4, 12 * 256); // 运输方式
  198. sheet.setColumnWidth(5, 15 * 256); // CRD
  199. sheet.setColumnWidth(6, 18 * 256); // 建议验货日期
  200. // 写入到字节数组
  201. ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  202. workbook.write(outputStream);
  203. workbook.close();
  204. byte[] bytes = outputStream.toByteArray();
  205. ByteArrayResource resource = new ByteArrayResource(bytes);
  206. String fileName = "验货申请导入模板.xlsx";
  207. String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString())
  208. .replaceAll("\\+", "%20");
  209. return ResponseEntity.ok()
  210. .header(HttpHeaders.CONTENT_DISPOSITION,
  211. "attachment; filename*=UTF-8''" + encodedFileName)
  212. .header(HttpHeaders.CONTENT_LENGTH, String.valueOf(bytes.length))
  213. .contentType(MediaType.APPLICATION_OCTET_STREAM)
  214. .body(resource);
  215. } catch (Exception e) {
  216. e.printStackTrace();
  217. return ResponseEntity.internalServerError().build();
  218. }
  219. }
  220. /**
  221. * 预览上传的 Excel 数据
  222. */
  223. @PostMapping("/previewUpload")
  224. public R previewUpload(@RequestParam("file") MultipartFile file) throws Exception {
  225. List<InspectionRequestExcelDTO> list = inspectionRequestService.previewUpload(file);
  226. return R.ok().put("data", list);
  227. }
  228. /**
  229. * 批量保存上传的数据
  230. */
  231. @PostMapping("/batchSave")
  232. public R batchSave(@RequestParam("file") MultipartFile file) {
  233. try {
  234. inspectionRequestService.batchSave(file);
  235. return R.ok();
  236. } catch (Exception e) {
  237. return R.error(e.getMessage());
  238. }
  239. }
  240. }