Lius
2025-01-22 1a075513907e055a4a5e0affe1f2a2832734de7e
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
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.lang.StringUtils;
import org.jeecg.modules.mdc.entity.MdcDownTime;
import org.jeecg.modules.mdc.entity.MdcRepairInfo;
import org.jeecg.modules.mdc.mapper.MdcRepairInfoMapper;
import org.jeecg.modules.mdc.service.IMdcEquipmentService;
import org.jeecg.modules.mdc.service.IMdcRepairInfoService;
import org.jeecg.modules.mdc.vo.MdcRepairInfoVo;
import org.springframework.beans.BeanUtils;
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-01-22
 */
@Service
public class MdcRepairInfoServiceImpl extends ServiceImpl<MdcRepairInfoMapper, MdcRepairInfo> implements IMdcRepairInfoService {
 
    @Resource
    private IMdcEquipmentService mdcEquipmentService;
 
    /**
     * 分页列表
     *
     * @param userId
     * @param page
     * @param mdcRepairInfoVo
     * @param req
     * @return
     */
    @Override
    public IPage<MdcRepairInfo> pageList(String userId, Page<MdcRepairInfo> page, MdcRepairInfoVo mdcRepairInfoVo, HttpServletRequest req) {
        List<String> equipmentIds = new ArrayList<>();
        if (StringUtils.isNotEmpty(mdcRepairInfoVo.getParentId()) && StringUtils.isEmpty(mdcRepairInfoVo.getEquipmentId())) {
            if ("2".equals(mdcRepairInfoVo.getTypeTree())) {
                //部门层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, mdcRepairInfoVo.getParentId());
            } else {
                //产线层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcRepairInfoVo.getParentId());
            }
        } else if (StringUtils.isNotEmpty(mdcRepairInfoVo.getEquipmentId())) {
            //单台设备信息
            mdcRepairInfoVo.setEquipmentIdList(Collections.singletonList(mdcRepairInfoVo.getEquipmentId()));
        } else {
            //查询用户拥有的所有设备信息
            if ("2".equals(mdcRepairInfoVo.getTypeTree())) {
                //部门层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null);
            } else {
                //产线层级
                equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null);
            }
        }
 
        if (mdcRepairInfoVo.getEquipmentIdList() == null || mdcRepairInfoVo.getEquipmentIdList().isEmpty()) {
            mdcRepairInfoVo.setEquipmentIdList(equipmentIds);
        }
 
        if (mdcRepairInfoVo.getEquipmentIdList() == null || mdcRepairInfoVo.getEquipmentIdList().isEmpty()) {
            return null;
        }
        return this.baseMapper.pageList(page, mdcRepairInfoVo);
    }
 
    /**
     * 添加
     *
     * @param mdcRepairInfoVo
     * @return
     */
    @Override
    public boolean addRepair(MdcRepairInfoVo mdcRepairInfoVo) {
        String[] equipmentIdList = mdcRepairInfoVo.getEquipmentIds().split(",");
        List<MdcRepairInfo> repairInfoList = new ArrayList<>();
        for (String equipmentId : equipmentIdList) {
            MdcRepairInfo mdcRepairInfo = new MdcRepairInfo();
            BeanUtils.copyProperties(mdcRepairInfoVo, mdcRepairInfo);
            mdcRepairInfo.setEquipmentId(equipmentId);
            repairInfoList.add(mdcRepairInfo);
        }
        this.saveBatch(repairInfoList);
        return true;
    }
}