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
package com.fgkj.services;
 
import com.fgkj.dto.Batt_history;
import com.fgkj.dto.ServiceModel;
import com.fgkj.mapper.impl.Batt_historyMapper;
import com.fgkj.util.ActionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
import javax.annotation.Resource;
@Service
public class Batt_historyService {
 
    @Resource
    private Batt_historyMapper mapper;;
 
    ServiceModel model = new ServiceModel();
    
    //查询所有的历史实时数据
    public ServiceModel searchAll(){
        List<Batt_history> list=mapper.searchAll();
        /*for (Batt_history batt : list) {
            System.out.println(ActionUtil.getDateMonth(batt.getRec_datetime()));
        }*/
        if(list!=null && list.size()>0){
            model.setCode(1);
            model.setData(list);
            model.setMsg("查询成功!");
        }else{
            model.setCode(0);
            model.setMsg("查询失败!");
        }        
        return model;
    }
    //查询所有的历史实时数据
    // TODO tb_batt_realdata_1000003_2020_09  ip222 参数对不上
    //  tb_batt_910000001_2017_12
 
    //TODO 数据库表格字段不一致 使用这个表名测试 db_batt_history.tb_batt_910000001_2017_12
 
    /**
     * {
     *   "dev_id": 910000001,
     *   "battGroupId": 1005059,
     *   "rec_datetime": "2017-12-29 09:28:31",
     *   "rec_datetime1": "2018-12-29 09:28:31"
     * }
     * @param obj
     * @return
     */
    public ServiceModel serchByCondition(Batt_history obj){
        ServiceModel model = new ServiceModel();
        int year= ActionUtil.getDateYear(obj.getRec_datetime());
        int month=ActionUtil.getDateMonth(obj.getRec_datetime());
//        String tbname = "tb_batt_";
        String tbnamesuffix = "";
        tbnamesuffix+=obj.getDev_id()+"_"+year+"_"+month;
        System.out.println("tbnamesuffix = " + tbnamesuffix);
        obj.setTbname(tbnamesuffix);
//        obj.setTbname("910000001_2017_12");//TODO 测试用表名后缀
        List list=mapper.serchByCondition(obj);
        if(list!=null && list.size()>0){
            model.setCode(1);
            model.setData(list);
            model.setMsg("查询成功!");
        }else{
            model.setCode(0);
            model.setMsg("查询失败!");
        }        
        return model;
    }
    /*public static void main(String[] args) throws ParseException {
         Batt_historyService hservice=new Batt_historyService();
         Batt_history bh=new Batt_history();
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         Date date1 = sdf.parse("2018-01-01 00:00:00");
         Date date2 = sdf.parse("2018-01-03 23:59:59");
         bh.setRec_datetime(new Date());
         bh.setDev_id(910000001);
         bh.setBattGroupId(1005058);
         bh.setRec_datetime(ActionUtil.getSimpDate(date1));
         bh.setRec_datetime1(ActionUtil.getSimpDate(date2));
         System.out.println(bh);
         ServiceModel model=hservice.serchByCondition(bh);
         System.out.println(model.getData());
         //hservice.searchAll();
    }*/
}