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
276 lines
9.6 KiB
package com.xujie.modules.inspection.controller;
|
|
|
|
import com.xujie.common.utils.PageUtils;
|
|
import com.xujie.common.utils.R;
|
|
import com.xujie.modules.inspection.data.*;
|
|
import com.xujie.modules.inspection.entity.InspectionRequestDetail;
|
|
import com.xujie.modules.inspection.entity.InspectionRequestDetailSub;
|
|
import com.xujie.modules.inspection.entity.InspectionRequestHeader;
|
|
import com.xujie.modules.inspection.entity.QcPersonList;
|
|
import com.xujie.modules.inspection.service.*;
|
|
import org.apache.poi.ss.usermodel.*;
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.core.io.ByteArrayResource;
|
|
import org.springframework.core.io.Resource;
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.net.URLEncoder;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
@RestController
|
|
@RequestMapping("/inspection")
|
|
public class InspectionController {
|
|
|
|
@Autowired
|
|
private InspectionRequestService inspectionRequestService;
|
|
|
|
@Autowired
|
|
private InspectionRequestDetailService inspectionRequestDetailService;
|
|
|
|
@Autowired
|
|
private InspectionRequestDetailSubService inspectionRequestDetailSubService;
|
|
|
|
/**
|
|
* 检验申请单头表分页查询
|
|
*/
|
|
@PostMapping(value = "/searchInspectionRequestHeaderList")
|
|
public R searchInspectionRequestHeaderList(@RequestBody InspectionRequestHeader data) {
|
|
PageUtils page = inspectionRequestService.myPage(data);
|
|
return R.ok().put("page", page);
|
|
}
|
|
|
|
/**
|
|
* 根据申请单号查询明细列表(分页)
|
|
*/
|
|
@PostMapping(value = "/getInspectionRequestDetailList")
|
|
public R getInspectionRequestDetailList(@RequestBody InspectionRequestDetail data) {
|
|
PageUtils page = new PageUtils(inspectionRequestDetailService.getPageList(data));
|
|
return R.ok().put("page", page);
|
|
}
|
|
|
|
/**
|
|
* 根据申请单号查询子表明细列表(分页)
|
|
*/
|
|
@PostMapping(value = "/getInspectionRequestDetailSubList")
|
|
public R getInspectionRequestDetailSubList(@RequestBody InspectionRequestDetailSub data) {
|
|
PageUtils page = new PageUtils(inspectionRequestDetailSubService.getPageList(data));
|
|
return R.ok().put("page", page);
|
|
}
|
|
|
|
/**
|
|
* 查询验货结果
|
|
*/
|
|
@PostMapping(value = "/getInspectionResultList")
|
|
public R getInspectionResultList(@RequestBody Map<String, String> params) {
|
|
String requestNo = params.get("requestNo");
|
|
String site = params.get("site");
|
|
List<InspectionResultVO> list = inspectionRequestDetailService.getInspectionResultList(requestNo, site);
|
|
return R.ok().put("list", list);
|
|
}
|
|
|
|
|
|
/**
|
|
* 查询可申请验货PO
|
|
*/
|
|
@PostMapping("/queryPoPage")
|
|
public R queryPoPage(@RequestBody InspectionRequestItemVO vo){
|
|
PageUtils page = inspectionRequestService.queryPoPage(vo);
|
|
return R.ok().put("page", page);
|
|
}
|
|
|
|
|
|
/**
|
|
* 保存验货申请
|
|
*/
|
|
@PostMapping("/save")
|
|
public R save(@RequestBody InspectionRequestSaveVO vo){
|
|
inspectionRequestService.saveRequest(vo);
|
|
return R.ok();
|
|
}
|
|
|
|
/**
|
|
* 修改验货申请(仅允许修改建议验货日期、验货地址和联系人)
|
|
*/
|
|
@PostMapping("/update")
|
|
public R update(@RequestBody InspectionRequestHeader header){
|
|
inspectionRequestService.updateRequest(header);
|
|
return R.ok();
|
|
}
|
|
|
|
/**
|
|
* 取消验货申请
|
|
*/
|
|
@PostMapping("/cancel/{requestNo}")
|
|
public R cancel(@PathVariable String requestNo){
|
|
inspectionRequestService.cancel(requestNo);
|
|
return R.ok();
|
|
}
|
|
|
|
/**
|
|
* 确认验货申请
|
|
*/
|
|
@PostMapping("/confirm/{requestNo}")
|
|
public R confirm(@PathVariable String requestNo){
|
|
inspectionRequestService.confirm(requestNo);
|
|
return R.ok();
|
|
}
|
|
|
|
/**
|
|
* 审核验货申请
|
|
*/
|
|
@PostMapping("/audit/{requestNo}")
|
|
public R audit(@PathVariable String requestNo){
|
|
inspectionRequestService.audit(requestNo);
|
|
return R.ok();
|
|
}
|
|
|
|
/**
|
|
* 删除验货申请
|
|
*/
|
|
@PostMapping("/delete/{requestNo}")
|
|
public R delete(@PathVariable String requestNo){
|
|
inspectionRequestService.delete(requestNo);
|
|
return R.ok();
|
|
}
|
|
|
|
/**
|
|
* 查询qc人员
|
|
*/
|
|
@PostMapping("/getQcPersonList")
|
|
public R getQcPersonList(@RequestBody QcPersonList qc ){
|
|
PageUtils page = inspectionRequestService.getQcPersonList(qc);
|
|
return R.ok().put("page", page);
|
|
}
|
|
|
|
/**
|
|
* 验货排程
|
|
*/
|
|
@PostMapping("/schedule")
|
|
public R schedule(@RequestBody InspectionScheduleVO vo){
|
|
inspectionRequestService.schedule(vo);
|
|
return R.ok();
|
|
}
|
|
|
|
/**
|
|
* 排程视图查询
|
|
*/
|
|
@GetMapping("/scheduleView")
|
|
public R scheduleView(@RequestParam String qcOperator){
|
|
|
|
List<InspectionScheduleViewVO> list =
|
|
inspectionRequestService.queryScheduleView(qcOperator);
|
|
|
|
return R.ok().put("list", list);
|
|
}
|
|
|
|
/**
|
|
* 下载验货申请导入模板
|
|
*/
|
|
@PostMapping("/downloadTemplate")
|
|
public ResponseEntity<Resource> downloadTemplate() {
|
|
try {
|
|
// 直接在内存中生成 Excel 模板
|
|
Workbook workbook = new XSSFWorkbook();
|
|
Sheet sheet = workbook.createSheet("验货申请数据");
|
|
|
|
// 创建表头样式
|
|
CellStyle headerStyle = workbook.createCellStyle();
|
|
Font headerFont = workbook.createFont();
|
|
headerFont.setBold(true);
|
|
headerStyle.setFont(headerFont);
|
|
headerStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
// 设置边框
|
|
headerStyle.setBorderTop(BorderStyle.THIN);
|
|
headerStyle.setBorderBottom(BorderStyle.THIN);
|
|
headerStyle.setBorderLeft(BorderStyle.THIN);
|
|
headerStyle.setBorderRight(BorderStyle.THIN);
|
|
// 设置背景色
|
|
headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
|
|
headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
|
// 创建表头行
|
|
Row headerRow = sheet.createRow(0);
|
|
String[] headers = {
|
|
"PO号", "PO行号","产品编码", "验货数量", "运输方式", "CRD", "建议验货日期"
|
|
};
|
|
for (int i = 0; i < headers.length; i++) {
|
|
Cell cell = headerRow.createCell(i);
|
|
cell.setCellValue(headers[i]);
|
|
cell.setCellStyle(headerStyle);
|
|
}
|
|
|
|
// 添加示例数据行
|
|
Row dataRow1 = sheet.createRow(1);
|
|
dataRow1.createCell(0).setCellValue("PO20260522001"); // PO号
|
|
dataRow1.createCell(1).setCellValue(1); // PO行号
|
|
dataRow1.createCell(2).setCellValue("TESTFX"); // 产品编码
|
|
dataRow1.createCell(3).setCellValue(200); // 验货数量
|
|
dataRow1.createCell(4).setCellValue("海运"); // 运输方式
|
|
dataRow1.createCell(5).setCellValue("2026-06-30"); // CRD
|
|
dataRow1.createCell(6).setCellValue("2026-05-29"); // 建议验货日期
|
|
|
|
// 设置列宽
|
|
sheet.setColumnWidth(0, 18 * 256); // PO号
|
|
sheet.setColumnWidth(1, 15 * 256); // 产品编码
|
|
sheet.setColumnWidth(2, 10 * 256); // PO行号
|
|
sheet.setColumnWidth(3, 12 * 256); // 验货数量
|
|
sheet.setColumnWidth(4, 12 * 256); // 运输方式
|
|
sheet.setColumnWidth(5, 15 * 256); // CRD
|
|
sheet.setColumnWidth(6, 18 * 256); // 建议验货日期
|
|
|
|
// 写入到字节数组
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
workbook.write(outputStream);
|
|
workbook.close();
|
|
|
|
byte[] bytes = outputStream.toByteArray();
|
|
ByteArrayResource resource = new ByteArrayResource(bytes);
|
|
|
|
String fileName = "验货申请导入模板.xlsx";
|
|
String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString())
|
|
.replaceAll("\\+", "%20");
|
|
|
|
return ResponseEntity.ok()
|
|
.header(HttpHeaders.CONTENT_DISPOSITION,
|
|
"attachment; filename*=UTF-8''" + encodedFileName)
|
|
.header(HttpHeaders.CONTENT_LENGTH, String.valueOf(bytes.length))
|
|
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
|
.body(resource);
|
|
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
return ResponseEntity.internalServerError().build();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 预览上传的 Excel 数据
|
|
*/
|
|
@PostMapping("/previewUpload")
|
|
public R previewUpload(@RequestParam("file") MultipartFile file) throws Exception {
|
|
List<InspectionRequestExcelDTO> list = inspectionRequestService.previewUpload(file);
|
|
return R.ok().put("data", list);
|
|
}
|
|
|
|
/**
|
|
* 批量保存上传的数据
|
|
*/
|
|
@PostMapping("/batchSave")
|
|
public R batchSave(@RequestParam("file") MultipartFile file) {
|
|
try {
|
|
inspectionRequestService.batchSave(file);
|
|
return R.ok();
|
|
} catch (Exception e) {
|
|
return R.error(e.getMessage());
|
|
}
|
|
}
|
|
}
|