Merge branch '0.8.X' of http://49.232.154.205:10100/DeXun/klp-oa into 0.8.X
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
package com.klp.controller;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.constraints.*;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import com.klp.common.annotation.RepeatSubmit;
|
||||
import com.klp.common.annotation.Log;
|
||||
import com.klp.common.core.controller.BaseController;
|
||||
import com.klp.common.core.domain.PageQuery;
|
||||
import com.klp.common.core.domain.R;
|
||||
import com.klp.common.core.validate.AddGroup;
|
||||
import com.klp.common.core.validate.EditGroup;
|
||||
import com.klp.common.enums.BusinessType;
|
||||
import com.klp.common.utils.poi.ExcelUtil;
|
||||
import com.klp.domain.vo.WmsMaterialWarningVo;
|
||||
import com.klp.domain.bo.WmsMaterialWarningBo;
|
||||
import com.klp.service.IWmsMaterialWarningService;
|
||||
import com.klp.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 钢卷通用维度告警(长度/厚度/宽度)
|
||||
*
|
||||
* @author klp
|
||||
* @date 2026-06-06
|
||||
*/
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/wms/materialWarning")
|
||||
public class WmsMaterialWarningController extends BaseController {
|
||||
|
||||
private final IWmsMaterialWarningService iWmsMaterialWarningService;
|
||||
|
||||
/**
|
||||
* 查询钢卷通用维度告警(长度/厚度/宽度)列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<WmsMaterialWarningVo> list(WmsMaterialWarningBo bo, PageQuery pageQuery) {
|
||||
return iWmsMaterialWarningService.queryPageList(bo, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出钢卷通用维度告警(长度/厚度/宽度)列表
|
||||
*/
|
||||
@Log(title = "钢卷通用维度告警(长度/厚度/宽度)", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(WmsMaterialWarningBo bo, HttpServletResponse response) {
|
||||
List<WmsMaterialWarningVo> list = iWmsMaterialWarningService.queryList(bo);
|
||||
ExcelUtil.exportExcel(list, "钢卷通用维度告警(长度/厚度/宽度)", WmsMaterialWarningVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取钢卷通用维度告警(长度/厚度/宽度)详细信息
|
||||
*
|
||||
* @param warningId 主键
|
||||
*/
|
||||
@GetMapping("/{warningId}")
|
||||
public R<WmsMaterialWarningVo> getInfo(@NotNull(message = "主键不能为空")
|
||||
@PathVariable Long warningId) {
|
||||
return R.ok(iWmsMaterialWarningService.queryById(warningId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增钢卷通用维度告警(长度/厚度/宽度)
|
||||
*/
|
||||
@Log(title = "钢卷通用维度告警(长度/厚度/宽度)", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit()
|
||||
@PostMapping()
|
||||
public R<Void> add(@Validated(AddGroup.class) @RequestBody WmsMaterialWarningBo bo) {
|
||||
return toAjax(iWmsMaterialWarningService.insertByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改钢卷通用维度告警(长度/厚度/宽度)
|
||||
*/
|
||||
@Log(title = "钢卷通用维度告警(长度/厚度/宽度)", businessType = BusinessType.UPDATE)
|
||||
@RepeatSubmit()
|
||||
@PutMapping()
|
||||
public R<Void> edit(@Validated(EditGroup.class) @RequestBody WmsMaterialWarningBo bo) {
|
||||
return toAjax(iWmsMaterialWarningService.updateByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除钢卷通用维度告警(长度/厚度/宽度)
|
||||
*
|
||||
* @param warningIds 主键串
|
||||
*/
|
||||
@Log(title = "钢卷通用维度告警(长度/厚度/宽度)", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{warningIds}")
|
||||
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||
@PathVariable Long[] warningIds) {
|
||||
return toAjax(iWmsMaterialWarningService.deleteWithValidByIds(Arrays.asList(warningIds), true));
|
||||
}
|
||||
}
|
||||
92
klp-wms/src/main/java/com/klp/domain/WmsMaterialWarning.java
Normal file
92
klp-wms/src/main/java/com/klp/domain/WmsMaterialWarning.java
Normal file
@@ -0,0 +1,92 @@
|
||||
package com.klp.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.klp.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
/**
|
||||
* 钢卷通用维度告警(长度/厚度/宽度)对象 wms_material_warning
|
||||
*
|
||||
* @author klp
|
||||
* @date 2026-06-06
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("wms_material_warning")
|
||||
public class WmsMaterialWarning extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
/**
|
||||
* 告警ID
|
||||
*/
|
||||
@TableId(value = "warning_id")
|
||||
private Long warningId;
|
||||
/**
|
||||
* 钢卷ID
|
||||
*/
|
||||
private Long coilId;
|
||||
/**
|
||||
* 告警类型(LENGTH=长度, THICKNESS=厚度, WIDTH=宽度)
|
||||
*/
|
||||
private String warningType;
|
||||
/**
|
||||
* 理论值
|
||||
*/
|
||||
private BigDecimal theoreticalVal;
|
||||
/**
|
||||
* 实测值
|
||||
*/
|
||||
private BigDecimal actualVal;
|
||||
/**
|
||||
* 允许偏差(数值/百分比)
|
||||
*/
|
||||
private BigDecimal allowDeviation;
|
||||
/**
|
||||
* 实际偏差值
|
||||
*/
|
||||
private BigDecimal deviationValue;
|
||||
/**
|
||||
* 偏差率(%)
|
||||
*/
|
||||
private BigDecimal deviationRate;
|
||||
/**
|
||||
* 告警级别(WARNING/ERROR/CRITICAL)
|
||||
*/
|
||||
private String warningLevel;
|
||||
/**
|
||||
* 告警说明
|
||||
*/
|
||||
private String warningMsg;
|
||||
/**
|
||||
* 告警状态(0=未处理,1=已处理,2=已忽略)
|
||||
*/
|
||||
private Integer warningStatus;
|
||||
/**
|
||||
* 处理人
|
||||
*/
|
||||
private String handleBy;
|
||||
/**
|
||||
* 处理时间
|
||||
*/
|
||||
private Date handleTime;
|
||||
/**
|
||||
* 处理备注
|
||||
*/
|
||||
private String handleRemark;
|
||||
/**
|
||||
* 删除标志(0=正常,1=已删除)
|
||||
*/
|
||||
@TableLogic
|
||||
private Integer delFlag;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.klp.domain.bo;
|
||||
|
||||
import com.klp.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
/**
|
||||
* 钢卷通用维度告警(长度/厚度/宽度)业务对象 wms_material_warning
|
||||
*
|
||||
* @author klp
|
||||
* @date 2026-06-06
|
||||
*/
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class WmsMaterialWarningBo extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 告警ID
|
||||
*/
|
||||
private Long warningId;
|
||||
|
||||
/**
|
||||
* 钢卷ID
|
||||
*/
|
||||
private Long coilId;
|
||||
|
||||
/**
|
||||
* 告警类型(LENGTH=长度, THICKNESS=厚度, WIDTH=宽度)
|
||||
*/
|
||||
private String warningType;
|
||||
|
||||
/**
|
||||
* 理论值
|
||||
*/
|
||||
private BigDecimal theoreticalVal;
|
||||
|
||||
/**
|
||||
* 实测值
|
||||
*/
|
||||
private BigDecimal actualVal;
|
||||
|
||||
/**
|
||||
* 允许偏差(数值/百分比)
|
||||
*/
|
||||
private BigDecimal allowDeviation;
|
||||
|
||||
/**
|
||||
* 实际偏差值
|
||||
*/
|
||||
private BigDecimal deviationValue;
|
||||
|
||||
/**
|
||||
* 偏差率(%)
|
||||
*/
|
||||
private BigDecimal deviationRate;
|
||||
|
||||
/**
|
||||
* 告警级别(WARNING/ERROR/CRITICAL)
|
||||
*/
|
||||
private String warningLevel;
|
||||
|
||||
/**
|
||||
* 告警说明
|
||||
*/
|
||||
private String warningMsg;
|
||||
|
||||
/**
|
||||
* 告警状态(0=未处理,1=已处理,2=已忽略)
|
||||
*/
|
||||
private Integer warningStatus;
|
||||
|
||||
/**
|
||||
* 处理人
|
||||
*/
|
||||
private String handleBy;
|
||||
|
||||
/**
|
||||
* 处理时间
|
||||
*/
|
||||
private Date handleTime;
|
||||
|
||||
/**
|
||||
* 处理备注
|
||||
*/
|
||||
private String handleRemark;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.klp.domain.vo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.klp.common.annotation.ExcelDictFormat;
|
||||
import com.klp.common.convert.ExcelDictConvert;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
/**
|
||||
* 钢卷通用维度告警(长度/厚度/宽度)视图对象 wms_material_warning
|
||||
*
|
||||
* @author klp
|
||||
* @date 2026-06-06
|
||||
*/
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class WmsMaterialWarningVo {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 告警ID
|
||||
*/
|
||||
@ExcelProperty(value = "告警ID")
|
||||
private Long warningId;
|
||||
|
||||
/**
|
||||
* 钢卷ID
|
||||
*/
|
||||
@ExcelProperty(value = "钢卷ID")
|
||||
private Long coilId;
|
||||
|
||||
/**
|
||||
* 告警类型(LENGTH=长度, THICKNESS=厚度, WIDTH=宽度)
|
||||
*/
|
||||
@ExcelProperty(value = "告警类型(LENGTH=长度, THICKNESS=厚度, WIDTH=宽度)")
|
||||
private String warningType;
|
||||
|
||||
/**
|
||||
* 理论值
|
||||
*/
|
||||
@ExcelProperty(value = "理论值")
|
||||
private BigDecimal theoreticalVal;
|
||||
|
||||
/**
|
||||
* 实测值
|
||||
*/
|
||||
@ExcelProperty(value = "实测值")
|
||||
private BigDecimal actualVal;
|
||||
|
||||
/**
|
||||
* 允许偏差(数值/百分比)
|
||||
*/
|
||||
@ExcelProperty(value = "允许偏差(数值/百分比)")
|
||||
private BigDecimal allowDeviation;
|
||||
|
||||
/**
|
||||
* 实际偏差值
|
||||
*/
|
||||
@ExcelProperty(value = "实际偏差值")
|
||||
private BigDecimal deviationValue;
|
||||
|
||||
/**
|
||||
* 偏差率(%)
|
||||
*/
|
||||
@ExcelProperty(value = "偏差率(%)")
|
||||
private BigDecimal deviationRate;
|
||||
|
||||
/**
|
||||
* 告警级别(WARNING/ERROR/CRITICAL)
|
||||
*/
|
||||
@ExcelProperty(value = "告警级别(WARNING/ERROR/CRITICAL)")
|
||||
private String warningLevel;
|
||||
|
||||
/**
|
||||
* 告警说明
|
||||
*/
|
||||
@ExcelProperty(value = "告警说明")
|
||||
private String warningMsg;
|
||||
|
||||
/**
|
||||
* 告警状态(0=未处理,1=已处理,2=已忽略)
|
||||
*/
|
||||
@ExcelProperty(value = "告警状态(0=未处理,1=已处理,2=已忽略)")
|
||||
private Integer warningStatus;
|
||||
|
||||
/**
|
||||
* 处理人
|
||||
*/
|
||||
@ExcelProperty(value = "处理人")
|
||||
private String handleBy;
|
||||
|
||||
/**
|
||||
* 处理时间
|
||||
*/
|
||||
@ExcelProperty(value = "处理时间")
|
||||
private Date handleTime;
|
||||
|
||||
/**
|
||||
* 处理备注
|
||||
*/
|
||||
@ExcelProperty(value = "处理备注")
|
||||
private String handleRemark;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@ExcelProperty(value = "备注")
|
||||
private String remark;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.klp.mapper;
|
||||
|
||||
import com.klp.domain.WmsMaterialWarning;
|
||||
import com.klp.domain.vo.WmsMaterialWarningVo;
|
||||
import com.klp.common.core.mapper.BaseMapperPlus;
|
||||
|
||||
/**
|
||||
* 钢卷通用维度告警(长度/厚度/宽度)Mapper接口
|
||||
*
|
||||
* @author klp
|
||||
* @date 2026-06-06
|
||||
*/
|
||||
public interface WmsMaterialWarningMapper extends BaseMapperPlus<WmsMaterialWarningMapper, WmsMaterialWarning, WmsMaterialWarningVo> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.klp.service;
|
||||
|
||||
import com.klp.domain.WmsMaterialCoil;
|
||||
import com.klp.domain.WmsMaterialWarning;
|
||||
import com.klp.domain.vo.WmsMaterialWarningVo;
|
||||
import com.klp.domain.bo.WmsMaterialWarningBo;
|
||||
import com.klp.common.core.page.TableDataInfo;
|
||||
import com.klp.common.core.domain.PageQuery;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 钢卷通用维度告警(长度/厚度/宽度)Service接口
|
||||
*
|
||||
* @author klp
|
||||
* @date 2026-06-06
|
||||
*/
|
||||
public interface IWmsMaterialWarningService {
|
||||
|
||||
/**
|
||||
* 查询钢卷通用维度告警(长度/厚度/宽度)
|
||||
*/
|
||||
WmsMaterialWarningVo queryById(Long warningId);
|
||||
|
||||
/**
|
||||
* 查询钢卷通用维度告警(长度/厚度/宽度)列表
|
||||
*/
|
||||
TableDataInfo<WmsMaterialWarningVo> queryPageList(WmsMaterialWarningBo bo, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询钢卷通用维度告警(长度/厚度/宽度)列表
|
||||
*/
|
||||
List<WmsMaterialWarningVo> queryList(WmsMaterialWarningBo bo);
|
||||
|
||||
/**
|
||||
* 新增钢卷通用维度告警(长度/厚度/宽度)
|
||||
*/
|
||||
Boolean insertByBo(WmsMaterialWarningBo bo);
|
||||
|
||||
/**
|
||||
* 修改钢卷通用维度告警(长度/厚度/宽度)
|
||||
*/
|
||||
Boolean updateByBo(WmsMaterialWarningBo bo);
|
||||
|
||||
/**
|
||||
* 校验并批量删除钢卷通用维度告警(长度/厚度/宽度)信息
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
/**
|
||||
* 检查钢卷长度/厚度偏差并批量插入告警记录
|
||||
* 在 calculateTheoretical 计算出理论长度和理论厚度后调用
|
||||
*
|
||||
* @param coil 钢卷实体(需已填充 theoreticalLength/theoreticalThickness/actualLength/actualThickness/coilId)
|
||||
*/
|
||||
void checkAndInsertWarnings(WmsMaterialCoil coil);
|
||||
}
|
||||
@@ -78,6 +78,7 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
// private final WmsDeliveryPlanMapper deliveryPlanMapper;
|
||||
private final WmsProductMapper productMapper;
|
||||
private final WmsRawMaterialMapper rawMaterialMapper;
|
||||
private final IWmsMaterialWarningService materialWarningService;
|
||||
private final WmsDeliveryWaybillDetailMapper deliveryWaybillDetailMapper;
|
||||
private final WmsCoilWarehouseOperationLogMapper wmsCoilWarehouseOperationLogMapper;
|
||||
private final IWmsCoilAbnormalService coilAbnormalService;
|
||||
@@ -1117,7 +1118,7 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
BigDecimal volume = weight.multiply(new BigDecimal("1000")).divide(new BigDecimal("7.85"), 10, RoundingMode.HALF_UP);
|
||||
|
||||
// 计算理论厚度(需要实测长度)
|
||||
if (bo.getTheoreticalThickness() == null && bo.getActualLength() != null && bo.getActualWidth().compareTo(BigDecimal.ZERO) > 0) {
|
||||
if (bo.getTheoreticalThickness() == null && bo.getActualLength() != null) {
|
||||
BigDecimal length = new BigDecimal(bo.getActualLength());
|
||||
BigDecimal theoreticalThickness = volume.divide(length, 10, RoundingMode.HALF_UP).divide(width, 10, RoundingMode.HALF_UP).multiply(new BigDecimal("1000"));
|
||||
bo.setTheoreticalThickness(theoreticalThickness);
|
||||
@@ -1521,6 +1522,9 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
throw new RuntimeException("新增钢卷失败");
|
||||
}
|
||||
|
||||
// 检查长度/厚度偏差并插入告警
|
||||
materialWarningService.checkAndInsertWarnings(add);
|
||||
|
||||
// 设置返回用的ID并更新二维码内容中的coilId
|
||||
bo.setCoilId(add.getCoilId());
|
||||
updateQrcodeCoilId(qrcodeRecordId, add.getCoilId());
|
||||
@@ -1732,6 +1736,10 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
updateWrapper.set(WmsMaterialCoil::getSaleId, (Long)null);
|
||||
baseMapper.update(null, updateWrapper);
|
||||
}
|
||||
|
||||
// 检查长度/厚度偏差并插入告警
|
||||
materialWarningService.checkAndInsertWarnings(updateCoil);
|
||||
|
||||
// 如果实际库区id为-1或状态为1,则清空钢卷上的实际库区绑定
|
||||
if ((bo.getActualWarehouseId() != null && bo.getActualWarehouseId().equals(-1L))
|
||||
|| (bo.getStatus() != null && bo.getStatus().equals(1))) {
|
||||
@@ -1839,6 +1847,9 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
throw new RuntimeException("创建新钢卷失败");
|
||||
}
|
||||
|
||||
// 检查长度/厚度偏差并插入告警
|
||||
materialWarningService.checkAndInsertWarnings(newCoil);
|
||||
|
||||
// 如果实际库区id为-1,则清空钢卷上的实际库区绑定
|
||||
if (bo.getActualWarehouseId() != null && bo.getActualWarehouseId().equals(-1L)) {
|
||||
clearActualWarehouseBinding(newCoil.getActualWarehouseId(), newCoil.getCoilId());
|
||||
@@ -2096,6 +2107,10 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
// 把老记录的coilId赋值给新纪录的parentCoilId
|
||||
newCoil.setParentCoilId(String.valueOf(oldCoil.getCoilId()));
|
||||
baseMapper.insert(newCoil);
|
||||
|
||||
// 检查长度/厚度偏差并插入告警
|
||||
materialWarningService.checkAndInsertWarnings(newCoil);
|
||||
|
||||
newCoils.add(newCoil);
|
||||
|
||||
// 更新二维码内容中的coilId
|
||||
@@ -2234,6 +2249,10 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
newCoil.setParentCoilId(parentCoilIdsStr);
|
||||
|
||||
baseMapper.insert(newCoil);
|
||||
|
||||
// 检查长度/厚度偏差并插入告警
|
||||
materialWarningService.checkAndInsertWarnings(newCoil);
|
||||
|
||||
newCoils.add(newCoil);
|
||||
|
||||
// 更新二维码内容中的coilId
|
||||
@@ -5085,6 +5104,9 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
childCoil.setParentCoilId(String.valueOf(parentCoilId));
|
||||
baseMapper.insert(childCoil);
|
||||
|
||||
// 检查长度/厚度偏差并插入告警
|
||||
materialWarningService.checkAndInsertWarnings(childCoil);
|
||||
|
||||
// 插入子钢卷的异常信息
|
||||
if (childCoilBo.getAbnormals() != null && !childCoilBo.getAbnormals().isEmpty()) {
|
||||
for (WmsCoilAbnormalBo abnormalBo : childCoilBo.getAbnormals()) {
|
||||
|
||||
@@ -0,0 +1,266 @@
|
||||
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;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.klp.domain.bo.WmsMaterialWarningBo;
|
||||
import com.klp.domain.vo.WmsMaterialWarningVo;
|
||||
import com.klp.domain.WmsMaterialCoil;
|
||||
import com.klp.domain.WmsMaterialWarning;
|
||||
import com.klp.mapper.WmsMaterialWarningMapper;
|
||||
import com.klp.service.IWmsMaterialWarningService;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 钢卷通用维度告警(长度/厚度/宽度)Service业务层处理
|
||||
*
|
||||
* @author klp
|
||||
* @date 2026-06-06
|
||||
*/
|
||||
@Slf4j
|
||||
@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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查钢卷长度/厚度偏差并批量插入告警记录
|
||||
*
|
||||
* 长度规则: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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user