lyh
2025-04-17 990ad5f6db0bb3ad5a3795e77c5d6f3971c12ff3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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);
    }
}