| | |
| | | return success(true); |
| | | } |
| | | |
| | | // ==================== 过程检验「检验行」附件 ==================== |
| | | |
| | | /** 过程检验行附件:recordId 为检验结果明细 ID,每行独立上传 */ |
| | | @GetMapping("/ipqc-detail/list") |
| | | @PreAuthorize("@ss.hasPermission('mes:qc-ipqc:query')") |
| | | public CommonResult<List<StorageBlobRespDTO>> listIpqcDetail(@RequestParam @NotNull Long detailId) { |
| | | validateIpqcDetail(detailId); |
| | | var files = storageApi.listAttachments(IPQC_DETAIL_RECORD_TYPE, detailId); |
| | | return success(files == null ? List.of() : files); |
| | | } |
| | | |
| | | @PostMapping("/ipqc-detail/save") |
| | | @PreAuthorize("@ss.hasPermission('mes:qc-ipqc:update')") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public CommonResult<Boolean> saveIpqcDetail(@Valid @RequestBody IpqcDetailSaveReq req) { |
| | | validateIpqcDetail(req.getDetailId()); |
| | | storageApi.bindAttachments("file", IPQC_DETAIL_RECORD_TYPE, req.getDetailId(), |
| | | req.getBlobIds().stream().distinct().toList()); |
| | | return success(true); |
| | | } |
| | | |
| | | @DeleteMapping("/ipqc-detail/remove") |
| | | @PreAuthorize("@ss.hasPermission('mes:qc-ipqc:update')") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public CommonResult<Boolean> removeIpqcDetail(@RequestParam @NotNull Long detailId, |
| | | @RequestParam @NotNull Long blobId) { |
| | | validateIpqcDetail(detailId); |
| | | storageApi.removeReference("file", IPQC_DETAIL_RECORD_TYPE, detailId, blobId); |
| | | return success(true); |
| | | } |
| | | |
| | | private static final String IPQC_DETAIL_RECORD_TYPE = "mes_qc_ipqc_detail_attachment"; |
| | | |
| | | /** 校验明细存在且属于过程检验结果 */ |
| | | private void validateIpqcDetail(Long detailId) { |
| | | var ids = jdbcTemplate.queryForList( |
| | | "SELECT d.id FROM mes_qc_indicator_result_detail d " |
| | | + "JOIN mes_qc_indicator_result r ON r.id = d.result_id " |
| | | + "WHERE d.id = ? AND r.qc_type = ? AND d.deleted = 0 AND r.deleted = 0", |
| | | Long.class, detailId, cn.iocoder.yudao.module.mes.enums.qc.MesQcTypeEnum.IPQC.getType()); |
| | | if (ids.isEmpty()) { |
| | | throw new ServiceException(400, "过程检验行不存在或不属于过程检验单,无法上传附件"); |
| | | } |
| | | } |
| | | |
| | | @Data public static class IpqcDetailSaveReq { |
| | | @NotNull private Long detailId; |
| | | /** 允许空列表:表示清空该行附件 */ |
| | | @NotNull @Size(max = 50) private List<@NotNull Long> blobIds; |
| | | } |
| | | |
| | | private String recordType(String type) { |
| | | return switch (type) { |
| | | case "iqc", "ipqc", "oqc", "rqc", "patrol" -> "mes_qc_" + type + "_attachment"; |