package com.ruoyi.sales.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.ruoyi.common.exception.ServiceException;
|
import com.ruoyi.sales.mapper.SalesLedgerProductProcessBindMapper;
|
import com.ruoyi.sales.pojo.SalesLedgerProductProcess;
|
import com.ruoyi.sales.mapper.SalesLedgerProductProcessMapper;
|
import com.ruoyi.sales.pojo.SalesLedgerProductProcessBind;
|
import com.ruoyi.sales.service.ISalesLedgerProductProcessService;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.util.StringUtils;
|
|
/**
|
* <p>
|
* 销售产品加工明细 服务实现类
|
* </p>
|
*
|
* @author deslrey
|
* @since 2026-03-25
|
*/
|
@Service
|
public class SalesLedgerProductProcessServiceImpl extends ServiceImpl<SalesLedgerProductProcessMapper, SalesLedgerProductProcess> implements ISalesLedgerProductProcessService {
|
|
@Autowired
|
private SalesLedgerProductProcessBindMapper salesLedgerProductProcessBindMapper;
|
|
@Override
|
public Page<SalesLedgerProductProcess> salesLedgerProductProcessList(Page<SalesLedgerProductProcess> page, String name) {
|
LambdaQueryWrapper<SalesLedgerProductProcess> wrapper = new LambdaQueryWrapper<>();
|
if (StringUtils.hasText(name)) {
|
wrapper.like(SalesLedgerProductProcess::getProcessName, name);
|
}
|
return this.page(page, wrapper);
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void addProcess(SalesLedgerProductProcess process) {
|
checkDuplicate(process.getProcessName(), null, process.getProcessName());
|
this.save(process);
|
if (!StringUtils.hasText(process.getCode())) {
|
process.setCode("P" + process.getId());
|
this.updateById(process);
|
}
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void updateProcess(SalesLedgerProductProcess process) {
|
checkDuplicate(process.getProcessName(), process.getId(), process.getProcessName());
|
this.updateById(process);
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void deleteProcess(Integer id) {
|
if (id == null) {
|
throw new ServiceException("删除失败,删除数据不能为空");
|
}
|
SalesLedgerProductProcess salesLedgerProductProcess = baseMapper.selectById(id);
|
if (salesLedgerProductProcess == null) {
|
throw new ServiceException("删除失败,该额外加工需求不存在");
|
}
|
// 查看是否被引用
|
Long selectedCount = salesLedgerProductProcessBindMapper.selectCount(new LambdaQueryWrapper<SalesLedgerProductProcessBind>().eq(SalesLedgerProductProcessBind::getSalesLedgerProductProcessId, salesLedgerProductProcess.getId()));
|
if (selectedCount > 0) {
|
throw new ServiceException("删除失败,该额外加工已被引用,禁止删除");
|
}
|
|
this.removeById(id);
|
}
|
|
private void checkDuplicate(String processName, Integer excludeId, String code) {
|
LambdaQueryWrapper<SalesLedgerProductProcess> wrapper = new LambdaQueryWrapper<>();
|
|
wrapper.and(w -> w
|
.eq(SalesLedgerProductProcess::getProcessName, processName)
|
.or()
|
.eq(SalesLedgerProductProcess::getCode, code));
|
|
if (excludeId != null) {
|
wrapper.ne(SalesLedgerProductProcess::getId, excludeId);
|
}
|
|
if (this.count(wrapper) > 0) {
|
throw new RuntimeException("工序名称或编码已存在");
|
}
|
}
|
}
|