Lius
2025-02-18 3423bb9ee5b25d270a00763b69ed73970d790f63
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
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.system.vo.LoginUser;
import org.jeecg.modules.mdc.entity.MdcMttrInfo;
import org.jeecg.modules.mdc.entity.MdcOeeInfo;
import org.jeecg.modules.mdc.mapper.MdcMttrInfoMapper;
import org.jeecg.modules.mdc.service.IMdcEquipmentService;
import org.jeecg.modules.mdc.service.IMdcMttrInfoService;
import org.jeecg.modules.mdc.vo.MdcMttrInfoVo;
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.List;
 
/**
 * @author Lius
 * @date 2025/2/18 13:52
 */
@Service
public class MdcMttrInfoServiceImpl extends ServiceImpl<MdcMttrInfoMapper, MdcMttrInfo> implements IMdcMttrInfoService {
 
    @Resource
    private IMdcEquipmentService mdcEquipmentService;
 
    /**
     * 分页列表
     *
     * @param userId
     * @param page
     * @param mdcMttrInfoVo
     * @param req
     * @return
     */
    @Override
    public IPage<MdcMttrInfo> pageList(String userId, Page<MdcMttrInfo> page, MdcMttrInfoVo mdcMttrInfoVo, HttpServletRequest req) {
        List<String> equipmentIds = new ArrayList<>();
        if (StringUtils.isNotEmpty(mdcMttrInfoVo.getParentId()) && StringUtils.isEmpty(mdcMttrInfoVo.getEquipmentId())) {
            if ("2".equals(mdcMttrInfoVo.getTypeTree())) {
                //部门层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, mdcMttrInfoVo.getParentId());
            } else {
                //产线层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcMttrInfoVo.getParentId());
            }
        } else if (StringUtils.isNotEmpty(mdcMttrInfoVo.getEquipmentId())) {
            //单台设备信息
            mdcMttrInfoVo.setEquipmentIdList(Collections.singletonList(mdcMttrInfoVo.getEquipmentId()));
        } else {
            //查询用户拥有的所有设备信息
            if ("2".equals(mdcMttrInfoVo.getTypeTree())) {
                //部门层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null);
            } else {
                //产线层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null);
            }
        }
 
        if (mdcMttrInfoVo.getEquipmentIdList() == null || mdcMttrInfoVo.getEquipmentIdList().isEmpty()) {
            mdcMttrInfoVo.setEquipmentIdList(equipmentIds);
        }
 
        if (mdcMttrInfoVo.getEquipmentIdList() == null || mdcMttrInfoVo.getEquipmentIdList().isEmpty()) {
            return null;
        }
        return this.baseMapper.pageList(page, mdcMttrInfoVo);
    }
 
    /**
     * 导出
     *
     * @param userId
     * @param mdcMttrInfoVo
     * @return
     */
    @Override
    public ModelAndView exportXls(String userId, MdcMttrInfoVo mdcMttrInfoVo) {
        LambdaQueryWrapper<MdcMttrInfo> queryWrapper = new LambdaQueryWrapper<>();
        List<String> equipmentIds = new ArrayList<>();
        if (StringUtils.isNotEmpty(mdcMttrInfoVo.getParentId()) && StringUtils.isEmpty(mdcMttrInfoVo.getEquipmentId())) {
            if ("2".equals(mdcMttrInfoVo.getTypeTree())) {
                //部门层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, mdcMttrInfoVo.getParentId());
            } else {
                //产线层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcMttrInfoVo.getParentId());
            }
        } else if (StringUtils.isNotEmpty(mdcMttrInfoVo.getEquipmentId())) {
            //单台设备信息
            mdcMttrInfoVo.setEquipmentIdList(Collections.singletonList(mdcMttrInfoVo.getEquipmentId()));
        } else {
            //查询用户拥有的所有设备信息
            if ("2".equals(mdcMttrInfoVo.getTypeTree())) {
                //部门层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null);
            } else {
                //产线层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null);
            }
        }
 
        if (mdcMttrInfoVo.getEquipmentIdList() == null || mdcMttrInfoVo.getEquipmentIdList().isEmpty()) {
            mdcMttrInfoVo.setEquipmentIdList(equipmentIds);
        }
 
        if (mdcMttrInfoVo.getEquipmentIdList() == null || mdcMttrInfoVo.getEquipmentIdList().isEmpty()) {
            return null;
        } else {
            queryWrapper.in(MdcMttrInfo::getEquipmentId, mdcMttrInfoVo.getEquipmentIdList());
        }
        if (StringUtils.isNotEmpty(mdcMttrInfoVo.getEquipmentId())) {
            queryWrapper.eq(MdcMttrInfo::getEquipmentId, mdcMttrInfoVo.getEquipmentId());
        }
        if (StringUtils.isNotEmpty(mdcMttrInfoVo.getStartTime()) && StringUtils.isNotEmpty(mdcMttrInfoVo.getEndTime())) {
            queryWrapper.between(MdcMttrInfo::getTheDate, mdcMttrInfoVo.getStartTime(), mdcMttrInfoVo.getEndTime());
        }
        queryWrapper.orderByDesc(MdcMttrInfo::getTheDate).orderByDesc(MdcMttrInfo::getEquipmentId);
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        List<MdcMttrInfo> mdcMttrInfos = this.baseMapper.selectList(queryWrapper);
        // 导出文件名称
        mv.addObject(NormalExcelConstants.FILE_NAME,  "设备MTTR表");
        mv.addObject(NormalExcelConstants.CLASS, MdcMttrInfo.class);
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("设备MTTR表数据", "导出人:" + user.getRealname(), "设备MTTR"));
        //update-end---author:wangshuai ---date:20211227  for:[JTC-116]导出人写死了------------
        mv.addObject(NormalExcelConstants.DATA_LIST, mdcMttrInfos);
        return mv;
    }
}