package cn.iocoder.yudao.module.mes.service.qc;
|
|
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
import cn.iocoder.yudao.module.system.api.storage.StorageAttachmentApi;
|
import jakarta.annotation.Resource;
|
import org.springframework.stereotype.Component;
|
import java.math.BigDecimal;
|
|
/** 按数量汇总质检结果,不推断不合格品的后续处置方式。 */
|
@Component
|
public class MesQcCompletionHelper {
|
@Resource private StorageAttachmentApi storageApi;
|
@Resource private org.springframework.jdbc.core.JdbcTemplate jdbcTemplate;
|
|
public void lockDocument(String type, Long id) {
|
String table = switch (type) {
|
case "iqc", "ipqc", "oqc", "rqc" -> "mes_qc_" + type;
|
default -> throw new ServiceException(400, "质检类型无效");
|
};
|
var rows = jdbcTemplate.queryForList("SELECT id FROM " + table + " WHERE id = ? AND deleted = 0 FOR UPDATE", Long.class, id);
|
if (rows.isEmpty()) throw new ServiceException(400, "质检单不存在");
|
}
|
|
public int validateAndGetResult(String type, Long id, BigDecimal qualified, BigDecimal unqualified, BigDecimal checked) {
|
if (qualified == null || unqualified == null || qualified.signum() < 0 || unqualified.signum() < 0) {
|
throw new ServiceException(400, "请填写大于等于零的合格数量和不合格数量");
|
}
|
BigDecimal total = qualified.add(unqualified);
|
if (total.signum() <= 0 || checked == null || total.compareTo(checked) != 0) {
|
throw new ServiceException(400, "合格数量与不合格数量之和须大于零且等于检测数量");
|
}
|
var attachments = storageApi.listAttachments("mes_qc_" + type + "_attachment", id);
|
if (attachments == null || attachments.isEmpty()) throw new ServiceException(400, "请先上传检验附件");
|
// 与现有 mes_qc_check_result 字典一致:1 通过,2 不通过。
|
return unqualified.signum() == 0 ? 1 : 2;
|
}
|
}
|