gongchunyi
8 小时以前 64c5103ed52d6c07a3abaaf8cc62a2b5b7b4d249
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductProcessServiceImpl.java
@@ -2,11 +2,16 @@
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;
/**
@@ -20,6 +25,9 @@
@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<>();
@@ -30,19 +38,39 @@
    }
    @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);
    }