zhangherong
2025-06-25 23855599412c4d61b38d78f0f3abd3430a48b5b1
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProductDepartmentServiceImpl.java
对比新文件
@@ -0,0 +1,62 @@
package org.jeecg.modules.dnc.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.dnc.entity.ProductDepartment;
import org.jeecg.modules.dnc.mapper.ProductDepartmentMapper;
import org.jeecg.modules.dnc.utils.ValidateUtil;
import org.jeecg.modules.dnc.service.IProductDepartmentService;
import org.jeecg.modules.system.entity.MdcProduction;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
@Service
public class ProductDepartmentServiceImpl extends ServiceImpl<ProductDepartmentMapper, ProductDepartment> implements IProductDepartmentService {
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean deleteByProductId(String productId) {
        if(!ValidateUtil.validateString(productId))
            return false;
        LambdaQueryWrapper<ProductDepartment> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(ProductDepartment::getProductId, productId);
        return super.remove(lambdaQueryWrapper);
    }
    @Override
    public List<MdcProduction> getDepartPermsByProductId(String productId) {
        return super.getBaseMapper().getDepartPermsByProductId(productId);
    }
    @Override
    public List<MdcProduction> getDepartNonPermsByProductId(String productId) {
        return super.getBaseMapper().getDepartNonPermsByProductId(productId);
    }
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean removeByCollection(List<ProductDepartment> productDepartmentList) {
        if(productDepartmentList == null || productDepartmentList.isEmpty())
            return false;
        if(productDepartmentList.size() == 1)
            return super.removeById(productDepartmentList.get(0).getProductDepartId());
        List<String> ids = new ArrayList<>();
        productDepartmentList.forEach(item -> {
            ids.add(item.getProductDepartId());
        });
        return super.removeByIds(ids);
    }
    @Override
    public ProductDepartment getByProductIdAndDepartId(String productId, String departId) {
        if(!ValidateUtil.validateString(productId) || !ValidateUtil.validateString(departId))
            return null;
        List<ProductDepartment> list = super.lambdaQuery().eq(ProductDepartment::getProductId, productId).eq(ProductDepartment::getDepartId, departId).list();
        if(list == null || list.isEmpty())
            return null;
        return list.get(0);
    }
}