whycxzp
2021-02-05 8cf143a196e20ddd68cbf9855290f2d3a0b78da0
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
package com.fgkj.services;
 
import com.fgkj.dto.*;
import com.fgkj.mapper.impl.BattInfMapper;
import com.fgkj.mapper.impl.BattPowerOffMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
 
@Service
public class BattPower_offService {
 
    @Resource
    private BattPowerOffMapper mapper;
    @Resource
    private BattInfMapper battInfMapper;
 
    public ServiceModel add(BattPower_off battPowerOff) {
        ServiceModel model = new ServiceModel();
        int flag = mapper.insert(battPowerOff);
        if (flag > 0) {
            model.setCode(1);
            model.setMsg("添加成功!");
        } else {
            model.setMsg("添加失败!");
        }
        return model;
 
    }
 
    public ServiceModel update(BattPower_off battPowerOff) {
        ServiceModel model = new ServiceModel();
 
        int flag = mapper.updateById(battPowerOff);
        if (flag > 0) {
            model.setCode(1);
            model.setMsg("修改成功!");
        } else {
            model.setMsg("修改失败!");
        }
        return model;
    }
 
    public ServiceModel delete(int id) {
        ServiceModel model = new ServiceModel();
 
        int flag = mapper.deleteById(id);
        if (flag > 0) {
            model.setCode(1);
            model.setMsg("删除成功!");
        } else {
            model.setMsg("删除失败!");
        }
        return model;
    }
 
    //机房断电统计查询
    public ServiceModel getByCondition(BattInf battInf, PageBean page) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize(), true);
        List<BattPower_off> powerOffs = mapper.getByCondition(battInf);
        PageInfo<BattPower_off> pageInfo = new PageInfo<>(powerOffs);
        return new ServiceModel().set(1,pageInfo);
    }
 
    //机房断电统计(首页上的饼状图)
    public ServiceModel serchPowerOff(User_inf userInf) {
        int powerNum = mapper.serchPowerOff(userInf);    //断电实时数
        int devNum = battInfMapper.serchByDeviceId(userInf);        //总设备数
        //TODO perry
        // model.setSum(powerNum);
        // model.setNewsum(devNum);
        HashMap<String, Integer> map = new HashMap<>();
        map.put("powerNum",powerNum);
        map.put("devNum",devNum);
        return new ServiceModel().set(1,map);
    }
 
}