2026-06-06 15:52:29 +08:00
|
|
|
|
package com.klp.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
|
import com.klp.common.core.page.TableDataInfo;
|
|
|
|
|
|
import com.klp.common.core.domain.PageQuery;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
|
import com.klp.common.utils.StringUtils;
|
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
2026-06-06 16:24:35 +08:00
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2026-06-06 15:52:29 +08:00
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.klp.domain.bo.WmsMaterialWarningBo;
|
|
|
|
|
|
import com.klp.domain.vo.WmsMaterialWarningVo;
|
2026-06-06 16:24:35 +08:00
|
|
|
|
import com.klp.domain.WmsMaterialCoil;
|
2026-06-06 15:52:29 +08:00
|
|
|
|
import com.klp.domain.WmsMaterialWarning;
|
|
|
|
|
|
import com.klp.mapper.WmsMaterialWarningMapper;
|
|
|
|
|
|
import com.klp.service.IWmsMaterialWarningService;
|
|
|
|
|
|
|
2026-06-06 16:24:35 +08:00
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
import java.math.RoundingMode;
|
|
|
|
|
|
import java.util.ArrayList;
|
2026-06-06 15:52:29 +08:00
|
|
|
|
import java.util.List;
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 钢卷通用维度告警(长度/厚度/宽度)Service业务层处理
|
|
|
|
|
|
*
|
|
|
|
|
|
* @author klp
|
|
|
|
|
|
* @date 2026-06-06
|
|
|
|
|
|
*/
|
2026-06-06 16:24:35 +08:00
|
|
|
|
@Slf4j
|
2026-06-06 15:52:29 +08:00
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
|
@Service
|
|
|
|
|
|
public class WmsMaterialWarningServiceImpl implements IWmsMaterialWarningService {
|
|
|
|
|
|
|
|
|
|
|
|
private final WmsMaterialWarningMapper baseMapper;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 查询钢卷通用维度告警(长度/厚度/宽度)
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public WmsMaterialWarningVo queryById(Long warningId){
|
|
|
|
|
|
return baseMapper.selectVoById(warningId);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 查询钢卷通用维度告警(长度/厚度/宽度)列表
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public TableDataInfo<WmsMaterialWarningVo> queryPageList(WmsMaterialWarningBo bo, PageQuery pageQuery) {
|
|
|
|
|
|
LambdaQueryWrapper<WmsMaterialWarning> lqw = buildQueryWrapper(bo);
|
|
|
|
|
|
Page<WmsMaterialWarningVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
|
|
|
return TableDataInfo.build(result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 查询钢卷通用维度告警(长度/厚度/宽度)列表
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public List<WmsMaterialWarningVo> queryList(WmsMaterialWarningBo bo) {
|
|
|
|
|
|
LambdaQueryWrapper<WmsMaterialWarning> lqw = buildQueryWrapper(bo);
|
|
|
|
|
|
return baseMapper.selectVoList(lqw);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private LambdaQueryWrapper<WmsMaterialWarning> buildQueryWrapper(WmsMaterialWarningBo bo) {
|
|
|
|
|
|
Map<String, Object> params = bo.getParams();
|
|
|
|
|
|
LambdaQueryWrapper<WmsMaterialWarning> lqw = Wrappers.lambdaQuery();
|
|
|
|
|
|
lqw.eq(bo.getCoilId() != null, WmsMaterialWarning::getCoilId, bo.getCoilId());
|
|
|
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getWarningType()), WmsMaterialWarning::getWarningType, bo.getWarningType());
|
|
|
|
|
|
lqw.eq(bo.getTheoreticalVal() != null, WmsMaterialWarning::getTheoreticalVal, bo.getTheoreticalVal());
|
|
|
|
|
|
lqw.eq(bo.getActualVal() != null, WmsMaterialWarning::getActualVal, bo.getActualVal());
|
|
|
|
|
|
lqw.eq(bo.getAllowDeviation() != null, WmsMaterialWarning::getAllowDeviation, bo.getAllowDeviation());
|
|
|
|
|
|
lqw.eq(bo.getDeviationValue() != null, WmsMaterialWarning::getDeviationValue, bo.getDeviationValue());
|
|
|
|
|
|
lqw.eq(bo.getDeviationRate() != null, WmsMaterialWarning::getDeviationRate, bo.getDeviationRate());
|
|
|
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getWarningLevel()), WmsMaterialWarning::getWarningLevel, bo.getWarningLevel());
|
|
|
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getWarningMsg()), WmsMaterialWarning::getWarningMsg, bo.getWarningMsg());
|
|
|
|
|
|
lqw.eq(bo.getWarningStatus() != null, WmsMaterialWarning::getWarningStatus, bo.getWarningStatus());
|
|
|
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getHandleBy()), WmsMaterialWarning::getHandleBy, bo.getHandleBy());
|
|
|
|
|
|
lqw.eq(bo.getHandleTime() != null, WmsMaterialWarning::getHandleTime, bo.getHandleTime());
|
|
|
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getHandleRemark()), WmsMaterialWarning::getHandleRemark, bo.getHandleRemark());
|
|
|
|
|
|
return lqw;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 新增钢卷通用维度告警(长度/厚度/宽度)
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Boolean insertByBo(WmsMaterialWarningBo bo) {
|
|
|
|
|
|
WmsMaterialWarning add = BeanUtil.toBean(bo, WmsMaterialWarning.class);
|
|
|
|
|
|
validEntityBeforeSave(add);
|
|
|
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
|
|
|
if (flag) {
|
|
|
|
|
|
bo.setWarningId(add.getWarningId());
|
|
|
|
|
|
}
|
|
|
|
|
|
return flag;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 修改钢卷通用维度告警(长度/厚度/宽度)
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Boolean updateByBo(WmsMaterialWarningBo bo) {
|
|
|
|
|
|
WmsMaterialWarning update = BeanUtil.toBean(bo, WmsMaterialWarning.class);
|
|
|
|
|
|
validEntityBeforeSave(update);
|
|
|
|
|
|
return baseMapper.updateById(update) > 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 保存前的数据校验
|
|
|
|
|
|
*/
|
|
|
|
|
|
private void validEntityBeforeSave(WmsMaterialWarning entity){
|
|
|
|
|
|
//TODO 做一些数据校验,如唯一约束
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 批量删除钢卷通用维度告警(长度/厚度/宽度)
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
|
|
|
if(isValid){
|
|
|
|
|
|
//TODO 做一些业务上的校验,判断是否需要校验
|
|
|
|
|
|
}
|
|
|
|
|
|
return baseMapper.deleteBatchIds(ids) > 0;
|
|
|
|
|
|
}
|
2026-06-06 16:24:35 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 检查钢卷长度/厚度偏差并批量插入告警记录
|
|
|
|
|
|
*
|
|
|
|
|
|
* 长度规则:ABS((实测长度 - 理论长度) / 理论长度) > 0.1 → 告警
|
|
|
|
|
|
* 厚度规则:
|
|
|
|
|
|
* 1. 实测厚度 < 理论厚度 → 偏薄告警(ERROR)
|
|
|
|
|
|
* 2. (实测厚度 - 理论厚度) / 理论厚度 > 0.1 → 偏厚告警(WARNING)
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void checkAndInsertWarnings(WmsMaterialCoil coil) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
doCheckAndInsertWarnings(coil);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
log.error("钢卷告警检查异常, coilId={}, 不影响原流程", coil != null ? coil.getCoilId() : null, e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void doCheckAndInsertWarnings(WmsMaterialCoil coil) {
|
|
|
|
|
|
if (coil == null || coil.getCoilId() == null) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<WmsMaterialWarning> warnings = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
// ========== 长度检查 ==========
|
|
|
|
|
|
checkLength(coil, warnings);
|
|
|
|
|
|
|
|
|
|
|
|
// ========== 厚度检查 ==========
|
|
|
|
|
|
checkThickness(coil, warnings);
|
|
|
|
|
|
|
|
|
|
|
|
// 批量插入
|
|
|
|
|
|
if (!warnings.isEmpty()) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
baseMapper.insertBatch(warnings);
|
|
|
|
|
|
log.info("批量插入钢卷告警记录成功, coilId={}, 告警数={}", coil.getCoilId(), warnings.size());
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
log.error("批量插入钢卷告警记录失败, coilId={}", coil.getCoilId(), e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 长度偏差检查
|
|
|
|
|
|
* ABS((actualLength - theoreticalLength) / theoreticalLength) > 0.1 → WARNING
|
|
|
|
|
|
*/
|
|
|
|
|
|
private void checkLength(WmsMaterialCoil coil, List<WmsMaterialWarning> warnings) {
|
|
|
|
|
|
Long actualLength = coil.getActualLength();
|
|
|
|
|
|
BigDecimal theoreticalLength = coil.getTheoreticalLength();
|
|
|
|
|
|
|
|
|
|
|
|
if (actualLength == null || theoreticalLength == null
|
|
|
|
|
|
|| theoreticalLength.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BigDecimal actual = new BigDecimal(actualLength);
|
|
|
|
|
|
BigDecimal diff = actual.subtract(theoreticalLength).abs();
|
|
|
|
|
|
BigDecimal rate = diff.divide(theoreticalLength, 10, RoundingMode.HALF_UP);
|
|
|
|
|
|
|
|
|
|
|
|
// 偏差率 > 0.1(即超过10%)
|
|
|
|
|
|
BigDecimal threshold = new BigDecimal("0.1");
|
|
|
|
|
|
if (rate.compareTo(threshold) > 0) {
|
|
|
|
|
|
WmsMaterialWarning warning = new WmsMaterialWarning();
|
|
|
|
|
|
warning.setCoilId(coil.getCoilId());
|
|
|
|
|
|
warning.setWarningType("LENGTH");
|
|
|
|
|
|
warning.setTheoreticalVal(theoreticalLength);
|
|
|
|
|
|
warning.setActualVal(actual);
|
|
|
|
|
|
warning.setAllowDeviation(threshold);
|
|
|
|
|
|
warning.setDeviationValue(actual.subtract(theoreticalLength));
|
|
|
|
|
|
warning.setDeviationRate(rate.multiply(new BigDecimal("100")).setScale(4, RoundingMode.HALF_UP));
|
|
|
|
|
|
warning.setWarningLevel("WARNING");
|
|
|
|
|
|
warning.setWarningMsg("钢卷长度偏差超过10%,理论长度=" + theoreticalLength + "m,实测长度=" + actualLength + "mm");
|
|
|
|
|
|
warning.setWarningStatus(0);
|
|
|
|
|
|
warnings.add(warning);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 厚度偏差检查
|
|
|
|
|
|
* 1. 实测厚度 < 理论厚度 → ERROR(不能比原来薄)
|
|
|
|
|
|
* 2. (实测厚度 - 理论厚度) / 理论厚度 > 0.1 → WARNING(不能厚太多)
|
|
|
|
|
|
*/
|
|
|
|
|
|
private void checkThickness(WmsMaterialCoil coil, List<WmsMaterialWarning> warnings) {
|
|
|
|
|
|
String actualThicknessStr = coil.getActualThickness();
|
|
|
|
|
|
BigDecimal theoreticalThickness = coil.getTheoreticalThickness();
|
|
|
|
|
|
|
|
|
|
|
|
if (actualThicknessStr == null || theoreticalThickness == null
|
|
|
|
|
|
|| theoreticalThickness.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BigDecimal actualThickness;
|
|
|
|
|
|
try {
|
|
|
|
|
|
actualThickness = new BigDecimal(actualThicknessStr.trim());
|
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
|
log.warn("实测厚度无法解析为数值, coilId={}, actualThickness={}", coil.getCoilId(), actualThicknessStr);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BigDecimal threshold = new BigDecimal("0.1");
|
|
|
|
|
|
|
|
|
|
|
|
// 规则1:实测厚度 < 理论厚度 → 偏薄 ERROR
|
|
|
|
|
|
if (actualThickness.compareTo(theoreticalThickness) < 0) {
|
|
|
|
|
|
WmsMaterialWarning warning = new WmsMaterialWarning();
|
|
|
|
|
|
warning.setCoilId(coil.getCoilId());
|
|
|
|
|
|
warning.setWarningType("THICKNESS");
|
|
|
|
|
|
warning.setTheoreticalVal(theoreticalThickness);
|
|
|
|
|
|
warning.setActualVal(actualThickness);
|
|
|
|
|
|
warning.setAllowDeviation(BigDecimal.ZERO);
|
|
|
|
|
|
warning.setDeviationValue(actualThickness.subtract(theoreticalThickness));
|
|
|
|
|
|
BigDecimal rate = theoreticalThickness.subtract(actualThickness)
|
|
|
|
|
|
.divide(theoreticalThickness, 10, RoundingMode.HALF_UP)
|
|
|
|
|
|
.multiply(new BigDecimal("100")).setScale(4, RoundingMode.HALF_UP);
|
|
|
|
|
|
warning.setDeviationRate(rate);
|
|
|
|
|
|
warning.setWarningLevel("ERROR");
|
|
|
|
|
|
warning.setWarningMsg("钢卷实测厚度偏薄,理论厚度=" + theoreticalThickness + "mm,实测厚度=" + actualThickness + "mm");
|
|
|
|
|
|
warning.setWarningStatus(0);
|
|
|
|
|
|
warnings.add(warning);
|
|
|
|
|
|
return; // 偏薄已经足够严重,不再重复判断偏厚
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 规则2:(实测厚度 - 理论厚度) / 理论厚度 > 0.1 → 偏厚超10%
|
|
|
|
|
|
BigDecimal diff = actualThickness.subtract(theoreticalThickness);
|
|
|
|
|
|
BigDecimal rate = diff.divide(theoreticalThickness, 10, RoundingMode.HALF_UP);
|
|
|
|
|
|
if (rate.compareTo(threshold) > 0) {
|
|
|
|
|
|
WmsMaterialWarning warning = new WmsMaterialWarning();
|
|
|
|
|
|
warning.setCoilId(coil.getCoilId());
|
|
|
|
|
|
warning.setWarningType("THICKNESS");
|
|
|
|
|
|
warning.setTheoreticalVal(theoreticalThickness);
|
|
|
|
|
|
warning.setActualVal(actualThickness);
|
|
|
|
|
|
warning.setAllowDeviation(threshold);
|
|
|
|
|
|
warning.setDeviationValue(diff);
|
|
|
|
|
|
warning.setDeviationRate(rate.multiply(new BigDecimal("100")).setScale(4, RoundingMode.HALF_UP));
|
|
|
|
|
|
warning.setWarningLevel("WARNING");
|
|
|
|
|
|
warning.setWarningMsg("钢卷实测厚度偏厚超过10%,理论厚度=" + theoreticalThickness + "mm,实测厚度=" + actualThickness + "mm");
|
|
|
|
|
|
warning.setWarningStatus(0);
|
|
|
|
|
|
warnings.add(warning);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-06-06 15:52:29 +08:00
|
|
|
|
}
|