春风项目四线(合箱线、总装线)
wujian
2024-03-22 9e6d86cfea30f99668cde150b49abae780239a55
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package com.jcdm.main.bs.orderScheduling.service.impl;
 
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.jcdm.common.utils.DateUtils;
import com.jcdm.common.utils.StringUtils;
import com.jcdm.main.bs.orderScheduling.Query.PrepareOnlineQuery;
import com.jcdm.main.bs.orderScheduling.common.Constants;
import com.jcdm.main.bs.orderScheduling.domain.BsOrderScheduling;
import com.jcdm.main.bs.orderScheduling.mapper.BsOrderSchedulingMapper;
import com.jcdm.main.bs.orderScheduling.service.IBsOrderSchedulingService;
import com.jcdm.main.bs.orderScheduling.vo.FollowReportVO;
import com.jcdm.main.bs.orderScheduling.vo.LineChartVO;
import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
import com.jcdm.main.da.paramCollection.mapper.DaParamCollectionMapper;
import com.jcdm.main.da.paramCollection.service.impl.DaParamCollectionServiceImpl;
import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
import com.jcdm.main.da.passingStationCollection.mapper.DaPassingStationCollectionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * 订单排产Service业务层处理
 * 
 * @author jiang
 * @date 2024-01-13
 */
@Service
public class BsOrderSchedulingServiceImpl implements IBsOrderSchedulingService
{
    @Autowired
    private BsOrderSchedulingMapper bsOrderSchedulingMapper;
 
    @Resource
    private DaParamCollectionMapper daParamCollectionMapper;
 
    @Resource
    private DaPassingStationCollectionMapper daPassingStationCollectionMapper;
 
    /**
     * 查询订单排产
     * 
     * @param id 订单排产主键
     * @return 订单排产
     */
    @Override
    public BsOrderScheduling selectBsOrderSchedulingById(Long id)
    {
        return bsOrderSchedulingMapper.selectBsOrderSchedulingById(id);
    }
 
    /**
     * 查询订单排产列表
     * 
     * @param bsOrderScheduling 订单排产
     * @return 订单排产
     */
    @Override
    public List<BsOrderScheduling> selectBsOrderSchedulingList(BsOrderScheduling bsOrderScheduling)
    {
        if(bsOrderScheduling.getDateConditions()!=null){
            String[] conditions = bsOrderScheduling.getDateConditions();
            bsOrderScheduling.setStartTime(conditions[0]);
            bsOrderScheduling.setEndTime(conditions[1]);
        }
        return bsOrderSchedulingMapper.selectBsOrderSchedulingList(bsOrderScheduling);
    }
 
    @Override
    public FollowReportVO getFollowReportList(BsOrderScheduling bsOrderScheduling)
    {
        FollowReportVO vo = new FollowReportVO();
        if(bsOrderScheduling.getDateConditions()!=null){
            String[] conditions = bsOrderScheduling.getDateConditions();
            bsOrderScheduling.setStartTime(conditions[0]);
            bsOrderScheduling.setEndTime(conditions[1]);
        }
        //主表数据
        List<BsOrderScheduling> mainList = bsOrderSchedulingMapper.selectBsOrderSchedulingList(bsOrderScheduling);
        vo.setMainList(mainList);
        List<String> engineNoList = mainList.stream().map(BsOrderScheduling::getEngineNo).distinct().collect(Collectors.toList());
        List<DaParamCollection> allChildList = new ArrayList<>();
        List<DaPassingStationCollection> collect5 = new ArrayList<>();
        if (CollUtil.isNotEmpty(engineNoList)){
            allChildList = daParamCollectionMapper.getListBySfcCode(engineNoList);
            collect5 = daPassingStationCollectionMapper.getListBySfcCode(engineNoList);
        }
        if (CollUtil.isNotEmpty(allChildList)){
            //拿到所有子数据
            List<DaParamCollection> collect1 = allChildList.stream().filter(x -> Constants.DATA1.equals(x.getType())).collect(Collectors.toList());
            List<DaParamCollection> collect2 = allChildList.stream().filter(x -> Constants.DATA2.equals(x.getType())).collect(Collectors.toList());
            List<DaParamCollection> collect3 = allChildList.stream().filter(x -> Constants.DATA3.equals(x.getType())).collect(Collectors.toList());
            List<DaParamCollection> collect4 = allChildList.stream().filter(x -> Constants.DATA4.equals(x.getType())).collect(Collectors.toList());
            vo.setList1(collect1);
            vo.setList2(collect2);
            vo.setList3(collect3);
            vo.setList4(collect4);
        }
        vo.setList5(collect5);
        return vo;
 
    }
 
    @Override
    public List<LineChartVO> getOffLineNum()
    {
        List<LineChartVO> result = new ArrayList<>();
        BsOrderScheduling bsOrderScheduling =  new BsOrderScheduling();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime startTime = LocalDateTime.of(now.getYear(),now.getMonthValue(),now.getDayOfMonth(),8,0,0);
        LocalDateTime endTime = LocalDateTime.of(now.getYear(),now.getMonthValue(),now.plusDays(1).getDayOfMonth(),22,0,0);
        String s1 = startTime.format(formatter);
        String s2 = endTime.format(formatter);
        bsOrderScheduling.setStartTime(s1);
        bsOrderScheduling.setEndTime(s2);
        List<BsOrderScheduling> todayList = bsOrderSchedulingMapper.selectBsOrderSchedulingList(bsOrderScheduling);
        todayList = todayList.stream().filter(x -> ObjectUtil.isNotEmpty(x.getCvtOfflineTime())).collect(Collectors.toList());
        if (CollUtil.isNotEmpty(todayList)){
            List<String> allModel = todayList.stream().map(BsOrderScheduling::getModel).distinct().collect(Collectors.toList());
            Map<String, List<BsOrderScheduling>> collect = new HashMap<>();
            for (String s : allModel) {
                LineChartVO vo = new LineChartVO();
                List<Integer> arr = new ArrayList<>();
                vo.setName(s);
                collect = todayList.stream().filter(x -> s.equals(x.getModel())).collect(Collectors.groupingBy(item -> new SimpleDateFormat("yyyy-MM-dd HH").format(item
                        .getCvtOfflineTime())));
                Map<Integer,Integer> temp = new HashMap<>();
                if (CollUtil.isNotEmpty(collect)){
                    for (String string : collect.keySet()) {
                        int size = collect.get(string).size();
                        String s3 = string.split(StringUtils.SPACE)[1];
                        if (StringUtils.isNotEmpty(s3)){
                            int i = Integer.parseInt(s3);
                            temp.put(i+1,size);
                        }
                    }
                }
                for (int i = 8; i < 23; i++) {
                    if (i==8){
                        arr.add(0);
                    }else {
                        arr.add(temp.getOrDefault(i, 0));
                    }
                }
                vo.setData(arr);
                vo.setType("line");
                result.add(vo);
            }
 
        }
        return result;
    }
 
 
    /**
     * 查询合箱上线列表
     * @param prepareOnlineQuery
     * @return list
     */
    public List<BsOrderScheduling> getPrepareOnlineList(PrepareOnlineQuery prepareOnlineQuery){
        return bsOrderSchedulingMapper.getPrepareOnlineList(prepareOnlineQuery);
    }
    /**
     * 新增订单排产
     * 
     * @param bsOrderScheduling 订单排产
     * @return 结果
     */
    @Override
    public int insertBsOrderScheduling(BsOrderScheduling bsOrderScheduling)
    {
        bsOrderScheduling.setCreateTime(DateUtils.getNowDate());
        return bsOrderSchedulingMapper.insertBsOrderScheduling(bsOrderScheduling);
    }
 
    /**
     * 修改订单排产
     * 
     * @param bsOrderScheduling 订单排产
     * @return 结果
     */
    @Override
    public int updateBsOrderScheduling(BsOrderScheduling bsOrderScheduling)
    {
        bsOrderScheduling.setUpdateTime(DateUtils.getNowDate());
        return bsOrderSchedulingMapper.updateBsOrderScheduling(bsOrderScheduling);
    }
 
    /**
     * 批量删除订单排产
     * 
     * @param ids 需要删除的订单排产主键
     * @return 结果
     */
    @Override
    public int deleteBsOrderSchedulingByIds(Long[] ids)
    {
        return bsOrderSchedulingMapper.deleteBsOrderSchedulingByIds(ids);
    }
 
    /**
     * 删除订单排产信息
     * 
     * @param id 订单排产主键
     * @return 结果
     */
    @Override
    public int deleteBsOrderSchedulingById(Long id)
    {
        return bsOrderSchedulingMapper.deleteBsOrderSchedulingById(id);
    }
}