| | |
| | | import cn.iocoder.yudao.module.mdm.dal.mysql.unit.MdmUnitMeasureMapper; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import java.util.*; |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void deleteUnitMeasure(Long id) { |
| | | // 校验存在 |
| | | validateUnitMeasureExists(id); |
| | | MdmUnitMeasureDO unitMeasure = validateUnitMeasureExists(id); |
| | | // 校验是否被物料使用(直接使用 Mapper 避免循环依赖) |
| | | if (itemMapper.selectCountByUnitMeasureId(id) > 0) { |
| | | throw exception(MDM_UNIT_MEASURE_EXISTS_ITEM); |
| | | } |
| | | // 先清理同编码的已软删除脏数据,避免当前记录软删时触发唯一键冲突 |
| | | unitMeasureMapper.physicalDeleteByCode(unitMeasure.getCode()); |
| | | // 删除 |
| | | unitMeasureMapper.deleteById(id); |
| | | } |