Lius
2025-03-18 423c836f9a0b15033b048c9d2666d3440fecdca0
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
package org.jeecg.modules.mdc.service.impl;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.mdc.dto.MdcDowntimeDto;
import org.jeecg.modules.mdc.entity.MdcDowntime;
import org.jeecg.modules.mdc.mapper.MdcDowntimeMapper;
import org.jeecg.modules.mdc.service.IMdcDowntimeService;
import org.jeecg.modules.mdc.service.IMdcEquipmentService;
import org.jeecg.modules.mdc.util.DateUtils;
import org.jeecg.modules.mdc.vo.MdcDowntimeVo;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
 
/**
 * @Description: 待机停机表
 * @Author: lius
 * @Date: 2025-03-12
 */
@Service
public class MdcDowntimeServiceImpl extends ServiceImpl<MdcDowntimeMapper, MdcDowntime> implements IMdcDowntimeService {
 
    @Resource
    private IMdcEquipmentService mdcEquipmentService;
 
    /**
     * 分页列表查询
     *
     * @param userId
     * @param page
     * @param mdcDowntimeVo
     * @param req
     * @return
     */
    @Override
    public IPage<MdcDowntimeDto> pageList(String userId, Page<MdcDowntimeDto> page, MdcDowntimeVo mdcDowntimeVo, HttpServletRequest req) {
        // 获取设备ID列表
        List<String> equipmentIds = getEquipmentIds(userId, mdcDowntimeVo);
 
        // 如果设备ID列表为空,直接返回空分页
        if (equipmentIds == null || equipmentIds.isEmpty()) {
            return new Page<>(page.getCurrent(), page.getSize(), 0);
        }
 
        // 设置设备ID列表到查询条件中
        mdcDowntimeVo.setEquipmentIdList(equipmentIds);
 
        // 执行分页查询
        return this.baseMapper.pageList(page, mdcDowntimeVo);
    }
 
    @Override
    public Integer findPlanTimeDuration(String equipmentId, String validDate, String closeType) {
        int result = 0;
        List<MdcDowntime> mdcDowntimeList = this.baseMapper.findPlanTimeDuration(equipmentId, validDate, closeType);
        if (mdcDowntimeList != null && !mdcDowntimeList.isEmpty()) {
            for (MdcDowntime mdcDowntime : mdcDowntimeList) {
                result = DateUtils.differentMinutes(mdcDowntime.getStartDate(), mdcDowntime.getEndDate()) + result;
            }
        }
        return result;
    }
 
    private List<String> getEquipmentIds(String userId, MdcDowntimeVo mdcDowntimeVo) {
        if (StringUtils.isNotEmpty(mdcDowntimeVo.getEquipmentId())) {
            return Collections.singletonList(mdcDowntimeVo.getEquipmentId());
        }
 
        if (StringUtils.isNotEmpty(mdcDowntimeVo.getParentId())) {
            return "2".equals(mdcDowntimeVo.getTypeTree())
                    ? mdcEquipmentService.getEquipmentIdsByDepart(userId, mdcDowntimeVo.getParentId())
                    : mdcEquipmentService.getEquipmentIdsProduction(userId, mdcDowntimeVo.getParentId());
        }
 
        return "2".equals(mdcDowntimeVo.getTypeTree())
                ? mdcEquipmentService.getEquipmentIdsByDepart(userId, null)
                : mdcEquipmentService.getEquipmentIdsProduction(userId, null);
    }
 
}