郑永安
2023-09-19 69185134fcfaf913ea45f1255677225a2cc311a4
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
package com.gk.hotwork.Service.ServiceImpl;
 
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 com.gk.hotwork.Domain.MajorEquipment;
import com.gk.hotwork.Domain.Exception.BusinessException;
import com.gk.hotwork.Domain.MajorEquipmentAlarm;
import com.gk.hotwork.Domain.MajorEquipmentData;
import com.gk.hotwork.Domain.UserInfo;
import com.gk.hotwork.Domain.Utils.StringUtils;
import com.gk.hotwork.Mapper.MajorEquipmentAlarmMapper;
import com.gk.hotwork.Mapper.MajorEquipmentDataMapper;
import com.gk.hotwork.Mapper.MajorEquipmentMapper;
import com.gk.hotwork.Service.MajorEquipmentService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.Date;
import java.util.List;
import java.util.Map;
 
@Service("MajorEquipmentService")
@Transactional
public class MajorEquipmentImpl extends ServiceImpl<MajorEquipmentMapper,MajorEquipment> implements MajorEquipmentService {
 
    @Autowired
    private MajorEquipmentMapper majorEquipmentMapper;
 
    @Autowired
    private MajorEquipmentAlarmMapper majorEquipmentAlarmMapper;
 
    @Autowired
    private MajorEquipmentDataMapper majorEquipmentDataMapper;
 
    /**
     * @Description: 分页
     */
    @Override
    public IPage<MajorEquipment> selectPage(Page<MajorEquipment> page, Map<String, Object> filter, UserInfo user) {
        return majorEquipmentMapper.selectPages(page,filter);
    }
 
 
    /**
     * @Description: 新增
     */
    @Override
    public void addOne(MajorEquipment param, UserInfo user) {
        requiredVerification(param);
 
        List<MajorEquipment> list = majorEquipmentMapper.getBySerialNumber(param);
        if (CollectionUtils.isEmpty(list)){
            param.setValidFlag(Boolean.TRUE);
            param.setUpdateBy(user.getRealname());
            param.setCreateBy(user.getRealname());
            param.setUpdateTime(new Date());
            param.setCreateTime(new Date());
            this.save(param);
        } else{
            throw new BusinessException("该设备编号已存在对应的设备!");
        }
    }
 
 
    /**
     * @Description: 修改
     */
    @Override
    public void modOne(MajorEquipment param, UserInfo user) {
        selectVerification(param.getId());
        requiredVerification(param);
 
        List<MajorEquipment> list = majorEquipmentMapper.getBySerialNumber(param);
        if (CollectionUtils.isEmpty(list)){
            param.setUpdateTime(new Date());
            param.setUpdateBy(user.getRealname());
            this.updateById(param);
        } else{
            throw new BusinessException("该设备编号已存在对应的设备!");
        }
 
    }
 
    /**
     * @Description: 删除
     * 删除数据表
     * 删除报警信息表
     */
    @Override
    public void delOne(Long id, UserInfo user) {
        selectVerification(id);
 
        MajorEquipment delOne = new MajorEquipment();
        delOne.setId(id);
        delOne.setUpdateTime(new Date());
        delOne.setUpdateBy(user.getRealname());
        delOne.setValidFlag(Boolean.FALSE);
        this.updateById(delOne);
 
//        majorEquipmentAlarmMapper.deleteByEquipmentId(id,user.getRealname(),new Date());
//        majorEquipmentDataMapper.deleteByEquipmentId(id,user.getRealname(),new Date());
    }
 
    @Override
    public List<MajorEquipment> getMajorEquipment() {
        return majorEquipmentMapper.getMajorEquipment();
    }
 
    /**
     * 查询验证
     * 验证对象存在
     */
    public void selectVerification(Long id){
        if (id == null) throw new BusinessException("id传参不能为空");
        MajorEquipment MajorEquipment = this.getById(id);
        if (MajorEquipment ==  null) throw new BusinessException("找不到对应实体");
    }
 
    /**
     * 操作验证
     * 验证必填项
     *
     */
    public void requiredVerification(MajorEquipment param){
        if(StringUtils.isBlank(param.getName())) throw new BusinessException("请填写要素名称");
        if(StringUtils.isBlank(param.getSerialNumber())) throw new BusinessException("请填写设备编号");
        if (param.getStatus() == null) throw new BusinessException("请选择设备状态");
        if (param.getVolume() == null) throw new BusinessException("请填写设备容积");
        if (param.getUserId() == null) throw new BusinessException("请选择设备负责人");
    }
 
}