liukangdong
2025-02-24 9a66d3a382406eda71b09ed06ddb5d4a0dc95989
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
package com.doumee.service.business.impl;
 
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.service.business.third.model.LoginUserInfo;
import com.doumee.service.business.third.model.PageData;
import com.doumee.service.business.third.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.PlatformGroupMapper;
import com.doumee.dao.business.PlatformShowParamMapper;
import com.doumee.dao.business.join.PlatformJobJoinMapper;
import com.doumee.dao.business.join.PlatformJoinMapper;
import com.doumee.dao.business.model.*;
import com.doumee.dao.web.reqeust.PlatformDataDTO;
import com.doumee.dao.web.response.PlatformGroupWorkVO;
import com.doumee.dao.web.response.PlatformWorkVO;
import com.doumee.service.business.PlatformGroupService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
 
/**
 * 月台_分组信息表Service实现
 * @author 江蹄蹄
 * @date 2024/06/28 10:03
 */
@Service
public class PlatformGroupServiceImpl implements PlatformGroupService {
 
    @Autowired
    private PlatformGroupMapper platformGroupMapper;
 
    @Autowired
    private PlatformJoinMapper platformJoinMapper;
 
    @Autowired
    private PlatformShowParamMapper platformShowParamMapper;
 
    @Autowired
    private PlatformJobJoinMapper platformJobJoinMapper;
 
    @Override
    public Integer create(PlatformGroup platformGroup) {
        if(platformGroup.getType() ==null
                || platformGroup.getType()>2
                || platformGroup.getType()<0){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        if(platformGroupMapper.selectCount(new QueryWrapper<PlatformGroup>().lambda()
                .eq(PlatformGroup::getIsdeleted,Constants.ZERO)
                .eq(PlatformGroup::getType,platformGroup.getType())
        )>0){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,该类型分组已经创建,请返回刷新页面查看!");
        }
        platformGroup.setStatus(Constants.ZERO);
        platformGroup.setIsdeleted(Constants.ZERO);
        platformGroup.setCreator(platformGroup.getLoginUserInfo().getId());
        platformGroup.setCreateDate(new Date());
        platformGroup.setEditDate(platformGroup.getCreateDate());
        platformGroup.setEditor(platformGroup.getCreator());
        platformGroupMapper.insert(platformGroup);
        return platformGroup.getId();
    }
 
    @Override
    public void deleteById(Integer id) {
        PlatformGroup param = new PlatformGroup();
        param.setId(id);
        param.setIsdeleted(Constants.ONE);
        platformGroupMapper.updateById(param);
    }
    @Override
    public void deleteById(Integer id,LoginUserInfo user) {
//        platformGroupMapper.deleteById(id);
        PlatformGroup param = new PlatformGroup();
        param.setId(id);
        param.setIsdeleted(Constants.ONE);
        param.setEditor(user.getId());
        param.setEditDate(new Date());
        platformGroupMapper.updateById(param);
    }
 
    @Override
    public void delete(PlatformGroup platformGroup) {
        UpdateWrapper<PlatformGroup> deleteWrapper = new UpdateWrapper<>(platformGroup);
        platformGroupMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        for(Integer id : ids){
            deleteById(id);
        }
    }
    @Override
    public void deleteByIdInBatch(List<Integer> ids,LoginUserInfo user) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        for(Integer id : ids){
            deleteById(id,user);
        }
    }
 
    @Override
    public void updateById(PlatformGroup platformGroup) {
        if(platformGroup.getType() ==null
                || platformGroup.getType()>2
                || platformGroup.getType()<0){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        if(platformGroupMapper.selectCount(new QueryWrapper<PlatformGroup>().lambda()
                .eq(PlatformGroup::getIsdeleted,Constants.ZERO)
                .eq(PlatformGroup::getType,platformGroup.getType())
                .ne(PlatformGroup::getId,platformGroup.getId())
        )>0){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,该类型分组已经创建,请返回刷新页面查看!");
        }
        platformGroup.setEditDate(new Date());
        platformGroup.setEditor(platformGroup.getLoginUserInfo().getId());
        platformGroupMapper.updateById(platformGroup);
    }
 
    @Override
    public void updateByIdInBatch(List<PlatformGroup> platformGroups) {
        if (CollectionUtils.isEmpty(platformGroups)) {
            return;
        }
        for (PlatformGroup platformGroup: platformGroups) {
            this.updateById(platformGroup);
        }
    }
 
    @Override
    public PlatformGroup findById(Integer id) {
        return platformGroupMapper.selectById(id);
    }
 
    @Override
    public PlatformGroup findOne(PlatformGroup platformGroup) {
        QueryWrapper<PlatformGroup> wrapper = new QueryWrapper<>(platformGroup);
        return platformGroupMapper.selectOne(wrapper);
    }
 
    @Override
    public List<PlatformGroup> findList(PlatformGroup platformGroup) {
        QueryWrapper<PlatformGroup> wrapper = new QueryWrapper<>(platformGroup);
        return platformGroupMapper.selectList(wrapper);
    }
  
    @Override
    public PageData<PlatformGroup> findPage(PageWrap<PlatformGroup> pageWrap) {
        IPage<PlatformGroup> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        QueryWrapper<PlatformGroup> queryWrapper = new QueryWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        queryWrapper.lambda()
                .eq(pageWrap.getModel().getId() != null, PlatformGroup::getId, pageWrap.getModel().getId())
                .eq(pageWrap.getModel().getCreator() != null, PlatformGroup::getCreator, pageWrap.getModel().getCreator())
                .ge(pageWrap.getModel().getCreateDate() != null, PlatformGroup::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate()))
                .le(pageWrap.getModel().getCreateDate() != null, PlatformGroup::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate()))
                .eq(pageWrap.getModel().getEditor() != null, PlatformGroup::getEditor, pageWrap.getModel().getEditor())
                .ge(pageWrap.getModel().getEditDate() != null, PlatformGroup::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate()))
                .le(pageWrap.getModel().getEditDate() != null, PlatformGroup::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate()))
                .eq(pageWrap.getModel().getIsdeleted() != null, PlatformGroup::getIsdeleted, pageWrap.getModel().getIsdeleted())
                .eq(pageWrap.getModel().getName() != null, PlatformGroup::getName, pageWrap.getModel().getName())
                .eq(pageWrap.getModel().getRemark() != null, PlatformGroup::getRemark, pageWrap.getModel().getRemark())
                .eq(pageWrap.getModel().getStatus() != null, PlatformGroup::getStatus, pageWrap.getModel().getStatus())
                .eq(pageWrap.getModel().getSortnum() != null, PlatformGroup::getSortnum, pageWrap.getModel().getSortnum())
        ;
        for(PageWrap.SortData sortData: pageWrap.getSorts()) {
            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
                queryWrapper.orderByDesc(sortData.getProperty());
            } else {
                queryWrapper.orderByAsc(sortData.getProperty());
            }
        }
        return PageData.from(platformGroupMapper.selectPage(page, queryWrapper));
    }
 
    @Override
    public long count(PlatformGroup platformGroup) {
        QueryWrapper<PlatformGroup> wrapper = new QueryWrapper<>(platformGroup);
        return platformGroupMapper.selectCount(wrapper);
    }
 
 
    @Override
    public List<PlatformGroup> getAllPlatformGroup(PlatformDataDTO platformDataDTO, LoginUserInfo loginUserInfo) {
        if(Objects.isNull(platformDataDTO)
        || Objects.isNull(platformDataDTO.getQueryType())
        || Objects.isNull(platformDataDTO.getQueryData())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        List<PlatformGroup> platformGroups = platformGroupMapper.selectList(
                new QueryWrapper<PlatformGroup>()
                        .lambda()
                        .eq(PlatformGroup::getIsdeleted, Constants.ZERO)
                        .orderByAsc(PlatformGroup::getSortnum)
        );
        //查询月台组下所有月台
        List<Platform> allPlatformList = platformJoinMapper.selectJoinList(Platform.class,
                new MPJLambdaWrapper<Platform>()
                        .selectAll(Platform.class)
                        .select(" ( select count(1) from platform_job pj where t.id = pj.PLATFORM_ID and pj.STATUS = "+Constants.PlatformJobStatus.WORKING.getKey()+" ) as workStatus ")
                        .eq(Platform::getIsdeleted, Constants.ZERO)
                        .eq(Objects.nonNull(platformDataDTO.getQueryType())&&!Constants.equalsInteger(platformDataDTO.getQueryType(),Constants.ZERO),
                                Platform::getStatus,Constants.ZERO)
        );
        //处理我的月台信息 是否配置隐藏
        if(Constants.equalsInteger(platformDataDTO.getQueryType(),Constants.ONE)){
            //查询当前登录人配置的可查看月台
            List<PlatformShowParam> platformShowParamList = platformShowParamMapper.selectList(new QueryWrapper<PlatformShowParam>()
                    .lambda()
                    .eq(PlatformShowParam::getIsdeleted, Constants.ZERO)
                    .eq(PlatformShowParam::getMemberId,loginUserInfo.getMemberId())
            );
            //如果未配置该数据 则全部显示
            if(CollectionUtils.isEmpty(platformShowParamList)){
                for (Platform platform:allPlatformList) {
                    platform.setShowConfig(true);
                }
            }else{
                //根据配置显示数据
                for (PlatformShowParam platformShowParam:platformShowParamList) {
                    for (Platform platform:allPlatformList) {
                        if(Constants.equalsInteger(platform.getId(),platformShowParam.getPlatformId())){
                            platform.setShowConfig(true);
                            break;
                        }
                    }
                }
            }
        }
        if(Constants.equalsInteger(platformDataDTO.getQueryData(),Constants.ONE)){
            //查询今天所有的任务数据
            List<PlatformJob> platformJobList =  platformJobJoinMapper.selectJoinList(PlatformJob.class,new MPJLambdaWrapper<PlatformJob>()
                            .selectAll(PlatformJob.class)
                            .select(" ( select pl.CREATE_DATE from platform_log pl where t.id = pl.obj_id and pl.OBJ_TYPE = "+Constants.PlatformJobLogType.WORKING.getKey()+"  order by pl.CREATE_DATE desc  limit 1  ) as newStartDate  ")
                            .select(" ( select pl.CREATE_DATE from platform_log pl where t.id = pl.obj_id and pl.OBJ_TYPE = "+Constants.PlatformJobLogType.CALLED.getKey()+" order by pl.CREATE_DATE desc  limit 1  ) as newCallDate  ")
                            .select(" case when t.total_num is null  then ( select sum(pwd.IO_QTY) from platform_wms_detail pwd where pwd.JOB_ID = t.id  ) else t.total_num end ioQty ")
                            .selectAs(PlatformWmsJob::getCarrierName,PlatformJob::getCarrierName)
                            .selectAs(PlatformBooks::getId,PlatformJob::getBookId)
                            .leftJoin(Platform.class,Platform::getId,PlatformJob::getPlatformId)
                            .leftJoin(PlatformWmsJob.class,PlatformWmsJob::getCarryBillCode,PlatformJob::getBillCode)
                            .leftJoin(PlatformBooks.class,PlatformBooks::getJobId,PlatformJob::getId)
                            .eq(PlatformJob::getIsdeleted,Constants.ZERO)
                            .apply(" ( t1.isdeleted = 0 or t.PLATFORM_ID is null  ) ")
                            .in(PlatformJob::getStatus,
                                    Constants.PlatformJobStatus.WAIT_CALL.getKey(),
                                    Constants.PlatformJobStatus.IN_WAIT.getKey(),
                                    Constants.PlatformJobStatus.CALLED.getKey(),
                                    Constants.PlatformJobStatus.WORKING.getKey(),
                                    Constants.PlatformJobStatus.EXCEPTION.getKey(),
                                    Constants.PlatformJobStatus.OVER_NUMBER.getKey(),
                                    Constants.PlatformJobStatus.TRANSFERING.getKey()
                            )
//                    .like(PlatformJob::getArriveDate,DateUtil.getCurrDate())
                    .orderByDesc(PlatformJob::getCreateDate)
            );
            for (Platform platform:allPlatformList) {
                PlatformWorkVO platformWorkVO = PlatformGroupServiceImpl.getPlatformWorkVO(platform,platformJobList);
                platform.setPlatformWorkVO(platformWorkVO);
            }
            for (PlatformGroup platformGroup:platformGroups) {
                platformGroup.setPlatformList(allPlatformList.stream().filter(m->m.getShowConfig()&&Constants.equalsInteger(m.getGroupId(),platformGroup.getId())).collect(Collectors.toList()));
            }
        }else{
            for (PlatformGroup platformGroup:platformGroups) {
                platformGroup.setPlatformList(allPlatformList.stream().filter(m->Constants.equalsInteger(m.getGroupId(),platformGroup.getId())).collect(Collectors.toList()));
            }
        }
        return platformGroups;
    }
 
 
    public static PlatformWorkVO getPlatformWorkVO(Platform platform,List<PlatformJob> platformJobList){
        PlatformWorkVO platformWorkVO = new PlatformWorkVO();
        platformWorkVO.setCurrentDate(new Date());
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(platformJobList)){
            //获取月台组下的所有作业数据
            List<PlatformJob> platformJobs = platformJobList.stream().filter(
                    i->Constants.equalsInteger(i.getPlatformId(),platform.getId())
                    || Constants.equalsInteger(i.getPlatformGroupId(),platform.getGroupId())
            ).collect(Collectors.toList());
            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(platformJobs)){
                platformWorkVO.setWorkNum(
                        platformJobs.stream().filter(i->Constants.equalsInteger(i.getPlatformId(),platform.getId())  && Constants.equalsInteger(i.getStatus(),Constants.PlatformJobStatus.WORKING.getKey())).collect(Collectors.toList()).size()
                );
                platformWorkVO.setCallNum(
                        platformJobs.stream().filter(i->Constants.equalsInteger(i.getPlatformId(),platform.getId())  && Constants.equalsInteger(i.getStatus(),Constants.PlatformJobStatus.CALLED.getKey())).collect(Collectors.toList()).size()
                );
                platformWorkVO.setWaitNum(
 
                        platformJobs.stream().filter(i->
                                 Constants.equalsInteger(i.getStatus(),Constants.PlatformJobStatus.WAIT_CALL.getKey())
                        ).collect(Collectors.toList()).size()
                        +
                        platformJobList.stream().filter(i->
                                (  Constants.equalsInteger(i.getStatus(),Constants.PlatformJobStatus.IN_WAIT.getKey()) && Constants.equalsInteger(i.getPlatformGroupId(),platform.getGroupId()) )||
                                 ( Constants.equalsInteger(platform.getId(),i.getPlatformId()) &&
                                 Constants.equalsInteger(i.getStatus(),Constants.PlatformJobStatus.TRANSFERING.getKey())
                               )
                        ).collect(Collectors.toList()).size()
                );
                platformWorkVO.setExceptionNum(
                        platformJobs.stream().filter(i->Constants.equalsInteger(platform.getId(),i.getPlatformId())
                                && Constants.equalsInteger(i.getStatus(),Constants.PlatformJobStatus.EXCEPTION.getKey())).collect(Collectors.toList()).size()
                );
                platformWorkVO.setPlatformJobList(platformJobs.stream().filter(
                        i->Constants.equalsInteger(platform.getId(),i.getPlatformId()) && !Constants.equalsInteger(i.getStatus(),Constants.PlatformJobStatus.WAIT_CALL.getKey())
                ).collect(Collectors.toList()));
            }
        }
        return platformWorkVO;
    }
 
 
 
    @Override
    public PlatformGroupWorkVO getPlatformGroupWork(Integer platformGroupId){
        PlatformGroupWorkVO platformGroupWorkVO = new PlatformGroupWorkVO();
        platformGroupWorkVO.setExceptionNum(platformJobJoinMapper.selectJoinCount(new MPJLambdaWrapper<PlatformJob>()
                .leftJoin(Platform.class,Platform::getId,PlatformJob::getPlatformId)
                .eq(PlatformJob::getIsdeleted,Constants.ZERO)
                .eq(Platform::getIsdeleted,Constants.ZERO)
                .eq(PlatformJob::getPlatformGroupId,platformGroupId)
                .eq(PlatformJob::getStatus,Constants.PlatformJobStatus.EXCEPTION.getKey())
            )
        );
        platformGroupWorkVO.setWaitNum(platformJobJoinMapper.selectJoinCount(new MPJLambdaWrapper<PlatformJob>()
                        .leftJoin(Platform.class,Platform::getId,PlatformJob::getPlatformId)
                        .eq(PlatformJob::getIsdeleted,Constants.ZERO)
                        .apply(" ( t1.isdeleted = 0 or t.PLATFORM_ID is null  ) ")
                        .eq(PlatformJob::getPlatformGroupId,platformGroupId)
                        .and( i->i.eq(PlatformJob::getStatus,Constants.PlatformJobStatus.WAIT_CALL.getKey()).or()
                                        .eq(PlatformJob::getStatus,Constants.PlatformJobStatus.IN_WAIT.getKey()).or()
                                        .apply(" ( t.status = "+Constants.PlatformJobStatus.TRANSFERING.getKey()+" and t.PLATFORM_GROUP_ID = "+platformGroupId+" ) ")
                        )
                )
        );
        return platformGroupWorkVO;
    }
 
 
}