Lius
2025-03-03 c89ca4524fa8311ebb415a2f225d2f95da780603
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
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.MdcPassRate;
import org.jeecg.modules.mdc.entity.MdcPlanClose;
import org.jeecg.modules.mdc.mapper.MdcPlanCloseMapper;
import org.jeecg.modules.mdc.service.IMdcEquipmentService;
import org.jeecg.modules.mdc.service.IMdcPlanCloseService;
import org.jeecg.modules.mdc.vo.MdcPlanCloseVo;
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.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
 
 
/**
 * @Description: mdc计划停机维护表
 * @Author: Lius
 * @Date: 2023-07-13
 * @Version: V1.0
 */
@Service
public class MdcPlanCloseServiceImpl extends ServiceImpl<MdcPlanCloseMapper, MdcPlanClose> implements IMdcPlanCloseService {
 
    @Resource
    private IMdcEquipmentService mdcEquipmentService;
 
    /**
     * 分页查询
     *
     * @param userId
     * @param page
     * @param mdcPlanClose
     * @param req
     * @return
     */
    @Override
    public IPage<MdcPlanClose> pageList(String userId, Page<MdcPlanClose> page, MdcPlanCloseVo mdcPlanClose, HttpServletRequest req) {
        List<String> equipmentIds = new ArrayList<>();
        if (StringUtils.isNotEmpty(mdcPlanClose.getParentId()) && StringUtils.isEmpty(mdcPlanClose.getEquipmentId())) {
            if ("2".equals(mdcPlanClose.getTypeTree())) {
                //部门层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, mdcPlanClose.getParentId());
            } else {
                //产线层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcPlanClose.getParentId());
            }
        } else if (StringUtils.isNotEmpty(mdcPlanClose.getEquipmentId())) {
            //单台设备信息
            mdcPlanClose.setEquipmentIdList(Collections.singletonList(mdcPlanClose.getEquipmentId()));
        } else {
            //查询用户拥有的所有设备信息
            if ("2".equals(mdcPlanClose.getTypeTree())) {
                //部门层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null);
            } else {
                //产线层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null);
            }
        }
 
        if (mdcPlanClose.getEquipmentIdList() == null || mdcPlanClose.getEquipmentIdList().isEmpty()) {
            mdcPlanClose.setEquipmentIdList(equipmentIds);
        }
 
        if (mdcPlanClose.getEquipmentIdList() == null || mdcPlanClose.getEquipmentIdList().isEmpty()) {
            return null;
        }
        return this.baseMapper.pageList(page, mdcPlanClose);
    }
 
    /**
     * 添加
     *
     * @param mdcPlanCloseVo
     * @return
     */
    @Override
    public boolean addPlanClose(MdcPlanCloseVo mdcPlanCloseVo) {
        String[] equipmentIdList = mdcPlanCloseVo.getEquipmentIds().split(",");
        List<MdcPlanClose> planCloseList = new ArrayList<>();
        for (String equipmentId : equipmentIdList) {
            MdcPlanClose mdcPlanClose = new MdcPlanClose();
            mdcPlanClose.setEquipmentId(equipmentId);
            mdcPlanClose.setPlanCloseType(mdcPlanCloseVo.getPlanCloseType());
            mdcPlanClose.setPlanCloseTimeLong(mdcPlanCloseVo.getPlanCloseTimeLong());
            mdcPlanClose.setTheDate(mdcPlanCloseVo.getTheDate());
            mdcPlanClose.setCloseType(mdcPlanCloseVo.getCloseType());
            mdcPlanClose.setRemark(mdcPlanClose.getRemark());
            planCloseList.add(mdcPlanClose);
        }
        this.saveBatch(planCloseList);
        return true;
    }
 
    @Override
    public ModelAndView exportXls(String userId, MdcPlanCloseVo mdcPlanClose, String title) {
        LambdaQueryWrapper<MdcPlanClose> queryWrapper = new LambdaQueryWrapper<>();
        List<String> equipmentIds = new ArrayList<>();
        if (StringUtils.isNotEmpty(mdcPlanClose.getParentId()) && StringUtils.isEmpty(mdcPlanClose.getEquipmentId())) {
            if ("2".equals(mdcPlanClose.getTypeTree())) {
                //部门层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, mdcPlanClose.getParentId());
            } else {
                //产线层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcPlanClose.getParentId());
            }
        } else if (StringUtils.isNotEmpty(mdcPlanClose.getEquipmentId())) {
            //单台设备信息
            mdcPlanClose.setEquipmentIdList(Collections.singletonList(mdcPlanClose.getEquipmentId()));
        } else {
            //查询用户拥有的所有设备信息
            if ("2".equals(mdcPlanClose.getTypeTree())) {
                //部门层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null);
            } else {
                //产线层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null);
            }
        }
        if (mdcPlanClose.getEquipmentIdList() == null || mdcPlanClose.getEquipmentIdList().isEmpty()) {
            mdcPlanClose.setEquipmentIdList(equipmentIds);
        }
 
        if (mdcPlanClose.getEquipmentIdList() == null || mdcPlanClose.getEquipmentIdList().isEmpty()) {
            return null;
        } else {
            queryWrapper.in(MdcPlanClose::getEquipmentId, mdcPlanClose.getEquipmentIdList());
        }
        if (StringUtils.isNotEmpty(mdcPlanClose.getEquipmentId())) {
            queryWrapper.eq(MdcPlanClose::getEquipmentId, mdcPlanClose.getEquipmentId());
        }
        if (StringUtils.isNotEmpty(mdcPlanClose.getPlanCloseType())) {
            queryWrapper.eq(MdcPlanClose::getPlanCloseType, mdcPlanClose.getPlanCloseType());
        }
        if (StringUtils.isNotEmpty(mdcPlanClose.getStartTime()) && StringUtils.isNotEmpty(mdcPlanClose.getEndTime())) {
            queryWrapper.between(MdcPlanClose::getTheDate, mdcPlanClose.getStartTime(), mdcPlanClose.getEndTime());
        }
        queryWrapper.eq(MdcPlanClose::getCloseType, mdcPlanClose.getCloseType());
        queryWrapper.orderByDesc(MdcPlanClose::getTheDate).orderByDesc(MdcPlanClose::getEquipmentId);
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        List<MdcPlanClose> mdcPlanCloses = this.baseMapper.selectList(queryWrapper);
        // 导出文件名称
        mv.addObject(NormalExcelConstants.FILE_NAME, title + "列表");
        mv.addObject(NormalExcelConstants.CLASS, MdcPlanClose.class);
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams(title + "列表数据", "导出人:" + user.getRealname(), title));
        //update-end---author:wangshuai ---date:20211227  for:[JTC-116]导出人写死了------------
        mv.addObject(NormalExcelConstants.DATA_LIST, mdcPlanCloses);
        return mv;
    }
 
    /**
     * 计算 计划/非计划停机当天总时长
     * @param equipmentId
     * @param validDate
     * @param closeType
     * @return
     */
    @Override
    public Integer findPlanTimeDuration(String equipmentId, String validDate, String closeType) {
        Integer planTimeDuration = this.baseMapper.findPlanTimeDuration(equipmentId, validDate, closeType);
        if (planTimeDuration == null) {
            return 0;
        } else {
            return planTimeDuration;
        }
    }
 
}