maven
2025-11-26 da8d45df31aebdf0eda2c57155d1a915e2e1e89f
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package com.ruoyi.production.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.production.dto.DaiDto;
import com.ruoyi.production.dto.SalesLedgerSchedulingDto;
import com.ruoyi.production.mapper.ProductionOrderMapper;
import com.ruoyi.production.mapper.SalesLedgerSchedulingMapper;
import com.ruoyi.production.mapper.SalesLedgerWorkMapper;
import com.ruoyi.production.pojo.ProductionOrder;
import com.ruoyi.production.pojo.SalesLedgerScheduling;
import com.ruoyi.production.pojo.SalesLedgerWork;
import com.ruoyi.production.service.ProductionOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
 
/**
 * @author :yys
 * @date : 2025/11/26 14:20
 */
@Service
@Slf4j
public class ProductionOrderServiceImpl extends ServiceImpl<ProductionOrderMapper, ProductionOrder> implements ProductionOrderService {
 
    @Autowired
    private ProductionOrderMapper productionOrderMapper;
 
    @Autowired
    private SalesLedgerWorkMapper salesLedgerWorkMapper;
 
    @Autowired
    private SalesLedgerSchedulingMapper salesLedgerSchedulingMapper;
 
    @Override
    public AjaxResult listPage(Page page, ProductionOrder productionOrder) {
        LambdaQueryWrapper<ProductionOrder> productionOrderLambdaQueryWrapper = new LambdaQueryWrapper<>();
        if(productionOrder != null){
            if(StringUtils.isNotEmpty(productionOrder.getOrderNo())){
                productionOrderLambdaQueryWrapper.like(ProductionOrder::getOrderNo, productionOrder.getOrderNo());
            }
            if(StringUtils.isNotEmpty(productionOrder.getProductCategory())){
                productionOrderLambdaQueryWrapper.like(ProductionOrder::getProductCategory, productionOrder.getProductCategory());
            }
            if(StringUtils.isNotEmpty(productionOrder.getEntryDateStart()) && StringUtils.isNotEmpty(productionOrder.getEntryDateEnd())){
                productionOrderLambdaQueryWrapper.ge(ProductionOrder::getRegisterDate, productionOrder.getEntryDateStart())
                        .le(ProductionOrder::getRegisterDate, productionOrder.getEntryDateEnd());
            }
 
        }
        IPage<ProductionOrder> list = productionOrderMapper.selectPage(page,productionOrderLambdaQueryWrapper);
        if(CollectionUtils.isEmpty(list.getRecords())){
            return AjaxResult.success(list);
        }
        Set<Long> collect = list.getRecords().stream().map(ProductionOrder::getId).collect(Collectors.toSet());
        // 获取排产数量
        LambdaQueryWrapper<SalesLedgerScheduling> salesLedgerSchedulingLambdaQueryWrapper = new LambdaQueryWrapper<>();
        salesLedgerSchedulingLambdaQueryWrapper.in(SalesLedgerScheduling::getSalesLedgerProductId, collect);
        List<SalesLedgerScheduling> salesLedgerSchedulings = salesLedgerSchedulingMapper.selectList(salesLedgerSchedulingLambdaQueryWrapper);
        // 计算完工数量
        LambdaQueryWrapper<SalesLedgerWork> salesLedgerWorkLambdaQueryWrapper = new LambdaQueryWrapper<>();
        salesLedgerWorkLambdaQueryWrapper.in(SalesLedgerWork::getSalesLedgerProductId, collect)
                .ne(SalesLedgerWork::getStatus, 1);
        List<SalesLedgerWork> salesLedgerWorks = salesLedgerWorkMapper.selectList(salesLedgerWorkLambdaQueryWrapper);
        list.getRecords().forEach(i -> {
            // 获取排产数量
            i.setSchedulingNum(salesLedgerSchedulings
                    .stream()
                    .filter(j -> j.getSalesLedgerProductId().equals(i.getId()))
                    .map(SalesLedgerScheduling::getSchedulingNum)
                    .reduce(BigDecimal.ZERO, BigDecimal::add));
            // 获取完成数量
            i.setSuccessNum(salesLedgerWorks
                    .stream()
                    .filter(j -> j.getSalesLedgerProductId().equals(i.getId()))
                    .map(SalesLedgerWork::getFinishedNum)
                    .reduce(BigDecimal.ZERO, BigDecimal::add));
            // 状态 = 数量和完工数量比较
            if(i.getSchedulingNum().compareTo(i.getSuccessNum()) == 0){
                i.setStatus("已完成");
            }else{
                i.setStatus("未完成");
            }
        });
        return AjaxResult.success(list);
    }
 
    @Override
    public void export(HttpServletResponse response) {
        List<ProductionOrder> list = this.list();
        if(CollectionUtils.isEmpty(list)){
            throw new RuntimeException("无导出数据");
        }
        Set<Long> collect = list.stream().map(ProductionOrder::getId).collect(Collectors.toSet());
        LambdaQueryWrapper<SalesLedgerWork> salesLedgerWorkLambdaQueryWrapper = new LambdaQueryWrapper<>();
        salesLedgerWorkLambdaQueryWrapper.in(SalesLedgerWork::getSalesLedgerProductId, collect)
                .ne(SalesLedgerWork::getStatus, 1);
        List<SalesLedgerWork> salesLedgerWorks = salesLedgerWorkMapper.selectList(salesLedgerWorkLambdaQueryWrapper);
        list.forEach(i -> {
            // 获取完成数量
            i.setSuccessNum(salesLedgerWorks
                    .stream()
                    .filter(j -> j.getSalesLedgerProductId().equals(i.getId()))
                    .map(SalesLedgerWork::getFinishedNum)
                    .reduce(BigDecimal.ZERO, BigDecimal::add));
            // 状态 = 数量和完工数量比较
            if(i.getQuantity().compareTo(i.getSuccessNum()) == 0){
                i.setStatus("已完成");
            }else{
                i.setStatus("未完成");
            }
        });
        ExcelUtil<ProductionOrder> util = new ExcelUtil<>(ProductionOrder.class);
        util.exportExcel(response, list, "生产订单");
    }
 
    @Override
    public void exportOne(HttpServletResponse response) {
        List<ProductionOrder> list = this.list();
        if(CollectionUtils.isEmpty(list)){
            throw new RuntimeException("无导出数据");
        }
        List<DaiDto> dais = new ArrayList<>();
        list.forEach(i -> {
            DaiDto daiDto = new DaiDto();
            BeanUtils.copyProperties(i, daiDto);
            // 获取待排产数量
            daiDto.setDaiNum(daiDto.getQuantity().subtract(i.getSuccessNum()));
            dais.add(daiDto);
        });
        ExcelUtil<DaiDto> util = new ExcelUtil<>(DaiDto.class);
        util.exportExcel(response, dais, "生产派工");
    }
}