/*
|
* Copyright (c) 2018-2025, ztt All rights reserved.
|
*
|
* Redistribution and use in source and binary forms, with or without
|
* modification, are permitted provided that the following conditions are met:
|
*
|
* Redistributions of source code must retain the above copyright notice,
|
* this list of conditions and the following disclaimer.
|
* Redistributions in binary form must reproduce the above copyright
|
* notice, this list of conditions and the following disclaimer in the
|
* documentation and/or other materials provided with the distribution.
|
* Neither the name of the pig4cloud.com developer nor the names of its
|
* contributors may be used to endorse or promote products derived from
|
* this software without specific prior written permission.
|
* Author: ztt
|
*/
|
package com.chinaztt.mes.technology.service.impl;
|
|
import cn.hutool.core.util.StrUtil;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.chinaztt.mes.technology.entity.DocumentSamplingRule;
|
import com.chinaztt.mes.technology.mapper.DocumentSamplingRuleMapper;
|
import com.chinaztt.mes.technology.service.DocumentSamplingRuleService;
|
import lombok.AllArgsConstructor;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
/**
|
* 工艺文件抽检规则
|
*
|
* @author shz
|
* @date 2023-04-13 13:49:26
|
*/
|
@Service
|
@AllArgsConstructor
|
@Transactional(rollbackFor = Exception.class)
|
public class DocumentSamplingRuleServiceImpl extends ServiceImpl<DocumentSamplingRuleMapper, DocumentSamplingRule> implements DocumentSamplingRuleService {
|
|
@Override
|
public Boolean fullUpdate(DocumentSamplingRule documentSamplingRule) {
|
if (documentSamplingRule.getSamplingNumerator() > documentSamplingRule.getSamplingDenominator()) {
|
throw new RuntimeException("抽检分子不能大于分母");
|
}
|
|
checkSamplingPosition(documentSamplingRule);
|
|
int count = this.count(Wrappers.<DocumentSamplingRule>lambdaQuery()
|
.eq(DocumentSamplingRule::getDocBomId, documentSamplingRule.getDocBomId())
|
.eq(DocumentSamplingRule::getRoutingOperationId, documentSamplingRule.getRoutingOperationId())
|
.eq(DocumentSamplingRule::getSamplingOperationId, documentSamplingRule.getSamplingOperationId())
|
.eq(DocumentSamplingRule::getApplyType, documentSamplingRule.getApplyType())
|
.ne(DocumentSamplingRule::getId, documentSamplingRule.getId()));
|
if (count > 0) {
|
throw new RuntimeException("已存在相同类型抽检规则");
|
}
|
return this.updateById(documentSamplingRule);
|
}
|
|
private void checkSamplingPosition(DocumentSamplingRule documentSamplingRule) {
|
if (documentSamplingRule.getSamplingPosition() == null) {
|
return;
|
}
|
if (documentSamplingRule.getSamplingNumerator() == 1) {
|
documentSamplingRule.setSamplingPosition("1");
|
} else {
|
String[] split = documentSamplingRule.getSamplingPosition().split(",");
|
if (split.length != documentSamplingRule.getSamplingNumerator()) {
|
throw new RuntimeException("抽检位置个数与抽检分子不一致");
|
}
|
int previousNum = 0;
|
for (String samplingPosition : split) {
|
if (!samplingPosition.matches("^[1-9]\\d*$") || Integer.parseInt(samplingPosition) > documentSamplingRule.getSamplingDenominator() || Integer.parseInt(samplingPosition) <= previousNum) {
|
throw new RuntimeException("抽检位置不合法");
|
}
|
previousNum = Integer.parseInt(samplingPosition);
|
}
|
}
|
}
|
}
|