Lius
2024-11-07 81eae83295642387de38a97fdc5a35f485307587
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
package org.jeecg.modules.mdc.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 org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.mdc.dto.EquipmentAlarmDto;
import org.jeecg.modules.mdc.entity.EquipmentAlarm;
import org.jeecg.modules.mdc.entity.MdcAlarmInfo;
import org.jeecg.modules.mdc.entity.MdcEquipmentOvertime;
import org.jeecg.modules.mdc.mapper.EquipmentAlarmMapper;
import org.jeecg.modules.mdc.service.IEquipmentAlarmService;
import org.jeecg.modules.mdc.service.IMdcAlarmInfoService;
import org.jeecg.modules.mdc.service.IMdcEquipmentService;
import org.jeecg.modules.mdc.vo.EquipmentAlarmVo;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
 
/**
 * @author: LiuS
 * @create: 2023-04-12 16:39
 */
@Service
public class EquipmentAlarmServiceImpl extends ServiceImpl<EquipmentAlarmMapper, EquipmentAlarm> implements IEquipmentAlarmService {
 
    @Resource
    private IMdcEquipmentService mdcEquipmentService;
 
    @Resource
    private IMdcAlarmInfoService mdcAlarmInfoService;
 
    @Override
    public List<EquipmentAlarm> findEquipmentAlarmByDate(String equipmentId, Date startTime, Date endTime) {
        return this.list(new LambdaQueryWrapper<EquipmentAlarm>()
                .ge(EquipmentAlarm::getCollecttime, startTime).le(EquipmentAlarm::getCollecttime, endTime)
                .eq(EquipmentAlarm::getEquipmentid, equipmentId).orderByDesc(EquipmentAlarm::getCollecttime));
    }
 
    /**
     * 分页列表
     *
     * @param userId
     * @param page
     * @param equipmentAlarmVo
     * @param req
     * @return
     */
    @Override
    public IPage<EquipmentAlarmDto> pageList(String userId, Page<EquipmentAlarmDto> page, EquipmentAlarmVo equipmentAlarmVo, HttpServletRequest req) {
        List<String> equipmentIds = new ArrayList<>();
        if (StringUtils.isNotEmpty(equipmentAlarmVo.getParentId()) && StringUtils.isEmpty(equipmentAlarmVo.getEquipmentId())) {
            if ("2".equals(equipmentAlarmVo.getTypeTree())) {
                //部门层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, equipmentAlarmVo.getParentId());
            } else {
                //产线层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, equipmentAlarmVo.getParentId());
            }
        } else if (StringUtils.isNotEmpty(equipmentAlarmVo.getEquipmentId())) {
            //单台设备信息
            equipmentAlarmVo.setEquipmentIdList(Collections.singletonList(equipmentAlarmVo.getEquipmentId()));
        } else {
            //查询用户拥有的所有设备信息
            if ("2".equals(equipmentAlarmVo.getTypeTree())) {
                //部门层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null);
            } else {
                //产线层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null);
            }
        }
 
        if (equipmentAlarmVo.getEquipmentIdList() == null || equipmentAlarmVo.getEquipmentIdList().isEmpty()) {
            equipmentAlarmVo.setEquipmentIdList(equipmentIds);
        }
 
        if (equipmentAlarmVo.getEquipmentIdList() == null || equipmentAlarmVo.getEquipmentIdList().isEmpty()) {
            return null;
        }
        IPage<EquipmentAlarmDto> pageList = this.baseMapper.pageList(page, equipmentAlarmVo);
        pageList.getRecords().forEach(item -> {
            if (StringUtils.isBlank(item.getAlarmContent())) {
                List<MdcAlarmInfo> mdcAlarmInfoList = mdcAlarmInfoService.list(new LambdaQueryWrapper<MdcAlarmInfo>().eq(MdcAlarmInfo::getAlarmCode, item.getAlarmNo()).eq(MdcAlarmInfo::getDriveType, item.getDriveType()).eq(MdcAlarmInfo::getIsUse, CommonConstant.STATUS_0));
                if (mdcAlarmInfoList != null && !mdcAlarmInfoList.isEmpty()) {
                    item.setAlarmContent(mdcAlarmInfoList.get(0).getAlarmContent());
                }
            }
        });
        return pageList;
    }
 
    @Override
    public ModelAndView exportXls(String userId, EquipmentAlarmVo equipmentAlarmVo) {
        List<String> equipmentIds = new ArrayList<>();
        if (StringUtils.isNotEmpty(equipmentAlarmVo.getParentId()) && StringUtils.isEmpty(equipmentAlarmVo.getEquipmentId())) {
            if ("2".equals(equipmentAlarmVo.getTypeTree())) {
                //部门层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, equipmentAlarmVo.getParentId());
            } else {
                //产线层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, equipmentAlarmVo.getParentId());
            }
        } else if (StringUtils.isNotEmpty(equipmentAlarmVo.getEquipmentId())) {
            //单台设备信息
            equipmentAlarmVo.setEquipmentIdList(Collections.singletonList(equipmentAlarmVo.getEquipmentId()));
        } else {
            //查询用户拥有的所有设备信息
            if ("2".equals(equipmentAlarmVo.getTypeTree())) {
                //部门层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null);
            } else {
                //产线层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null);
            }
        }
 
        if (equipmentAlarmVo.getEquipmentIdList() == null || equipmentAlarmVo.getEquipmentIdList().isEmpty()) {
            equipmentAlarmVo.setEquipmentIdList(equipmentIds);
        }
 
        if (equipmentAlarmVo.getEquipmentIdList() == null || equipmentAlarmVo.getEquipmentIdList().isEmpty()) {
            return null;
        }
        // Step.2 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        List<EquipmentAlarmDto> equipmentAlarmDtos = this.baseMapper.list(equipmentAlarmVo);
        if (equipmentAlarmDtos != null && !equipmentAlarmDtos.isEmpty()) {
            for (EquipmentAlarmDto equipmentAlarmDto : equipmentAlarmDtos) {
                if (StringUtils.isBlank(equipmentAlarmDto.getAlarmContent())) {
                    List<MdcAlarmInfo> mdcAlarmInfoList = mdcAlarmInfoService.list(new LambdaQueryWrapper<MdcAlarmInfo>().eq(MdcAlarmInfo::getAlarmCode, equipmentAlarmDto.getAlarmNo()).eq(MdcAlarmInfo::getDriveType, equipmentAlarmDto.getDriveType()).eq(MdcAlarmInfo::getIsUse, CommonConstant.STATUS_0));
                    if (mdcAlarmInfoList != null && !mdcAlarmInfoList.isEmpty()) {
                        equipmentAlarmDto.setAlarmContent(mdcAlarmInfoList.get(0).getAlarmContent());
                    }
                }
            }
        }
        // 导出文件名称
        mv.addObject(NormalExcelConstants.FILE_NAME, "设备报警列表");
        mv.addObject(NormalExcelConstants.CLASS, EquipmentAlarmDto.class);
        //获取当前登录用户
        //update-begin---author:wangshuai ---date:20211227  for:[JTC-116]导出人写死了------------
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("设备报警列表数据", "导出人:" + user.getRealname(), "设备报警"));
        //update-end---author:wangshuai ---date:20211227  for:[JTC-116]导出人写死了------------
        mv.addObject(NormalExcelConstants.DATA_LIST, equipmentAlarmDtos);
        return mv;
    }
}