whycrzg
2021-02-23 351b9a53cb9ecebdf8f79db0117f540d9c42c2a4
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
package com.fgkj.services;
 
import com.fgkj.dto.BattInf;
import com.fgkj.dto.Batt_Devdischarge;
import com.fgkj.dto.Batt_Devdischarge_all;
import com.fgkj.dto.ServiceModel;
import com.fgkj.mapper.impl.Batt_DevdischargeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
import javax.annotation.Resource;
@Service
public class Batt_DevdischargeService {
 
 
    @Resource
    private Batt_DevdischargeMapper mapper;;
 
    public ServiceModel add(Batt_Devdischarge bd){
    ServiceModel model = new ServiceModel();
        Boolean bl= null;
        try {
            bl = mapper.add(bd)>0;
        } catch (Exception e) {
            e.printStackTrace();
            model.setCode(0);
            model.setMsg("添加失败!");
            return model;
        }
        if(bl){
            model.setCode(1);
            model.setMsg("添加成功!");
        }else{
            model.setCode(0);
            model.setMsg("添加失败!");
        }
        return model;
    }
    public ServiceModel update(Batt_Devdischarge obj){
        ServiceModel model = new ServiceModel();
        Boolean bl=mapper.update(obj)>0;
        if(bl){
            model.setCode(1);
            model.setMsg("修改成功!");
        }else{
            model.setCode(0);
            model.setMsg("修改失败!");
        }
        return model;
    }
    public ServiceModel del(Batt_Devdischarge obj){
        ServiceModel model = new ServiceModel();
        Boolean bl=mapper.del(obj)>0;
        if(bl){
            model.setCode(1);
            model.setMsg("删除成功!");
        }else{
            model.setCode(0);
            model.setMsg("删除失败!");
        }
        return model;
    }
    public ServiceModel searchAll(){
        ServiceModel model = new ServiceModel();
        List list=mapper.searchAll();
        if(list!=null&&list.size()>0){
            model.setCode(1);
            model.setMsg("查询成功!");
            model.setData(list);
        }else{
            model.setCode(0);
            model.setMsg("查询失败!");
        }
        return model;
    }
    //10.1根据设备id连battinf和batt_devdischarge表
    /*
     * 记录时间放在battinf的battproducer
     * MonCount:当前页
     * MonNum :页面的大小
     */
    public ServiceModel serchByCondition(BattInf binf) {
        ServiceModel model = new ServiceModel();
        binf.setNum(0);
        binf.setMonCount(0);
        binf.setMonNum(0);
        List<Batt_Devdischarge> listN = mapper.serchMaxAndMinNum(binf);
        boolean searchFlag=true;
        if (listN != null && listN.size() > 0) {
            System.out.println("listN = " + listN);
            Float dev_curr = listN.get(listN.size() - 1).getDev_curr();
            float number = -1;
            if (dev_curr != null) {
                number = dev_curr;
            }else{
                searchFlag=false;
            }
            Float dev_power = listN.get(listN.size() - 1).getDev_power();
            float maxnum = -1;
            if (dev_power != null) {
                maxnum = dev_power;
            }else{
                searchFlag=false;
            }
            Float dev_vol = listN.get(listN.size() - 1).getDev_vol();
            float minnum = -1;
            if (dev_vol != null) {
                minnum = dev_vol;
            }else{
                searchFlag=false;
            }
            binf.setNum((int) number);
            binf.setMonCount((int) maxnum);
            binf.setMonNum((int) minnum);
        }
        List<Batt_Devdischarge_all> list = null;
        if (searchFlag){
            list = mapper.serchByCondition(binf);
        }
        //System.out.println(list.size());
        if (list != null && list.size() > 0) {
            model.setCode(1);
            model.setMsg("查询成功!");
            model.setData(list);
        } else {
            model.setCode(0);
            model.setMsg("查询失败!");
        }
        //System.out.println(model);
        return model;
    }
 
    /*public static void main(String[] args) throws ParseException {
        Batt_DevdischargeService bservice=new Batt_DevdischargeService();
        Batt_DevdischargeImpl bimpl=new Batt_DevdischargeImpl();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date1 = sdf.parse("2000-01-01");
        Date date2 = sdf.parse("2020-01-01");
        BattInf binf=new BattInf();
        binf.setStationName("");
        binf.setStationName1("");
        binf.setStationId("42070450");
        binf.setMonCount(1);
        binf.setMonNum(100);
        binf.setBattProductDate(ActionUtil.getSimpDate(date1));
        binf.setBattProductDate1(ActionUtil.getSimpDate(date2));
        bservice.serchByCondition(binf);
    }*/
}