81041
2019-11-18 86397b404b0f18da000b2eb9ad64a5cbedb4cc93
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
package com.fgkj.service;
 
import android.database.sqlite.SQLiteDatabase;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
 
import com.fgkj.action.ServiceModel;
import com.fgkj.dao.ActionUtil;
import com.fgkj.dao.BaseDAO;
import com.fgkj.dao.BaseDAOFactory;
import com.fgkj.dao.DBHelper;
import com.fgkj.dto.Battinf;
import com.fgkj.dto.Batttestdata;
import com.fgkj.impl.BatttestdataDAOImpl;
import com.google.gson.reflect.TypeToken;
 
import java.util.List;
 
public class BatttestdataService {
    private BaseDAO dao;
    private ServiceModel model;
    private WebView webView;
    public static final String BATTTESTDATASERVICE_NAME = "BatttestdataService";//JS调用类名
    private  DBHelper dbHelper;
 
    public BatttestdataService(WebView webView,DBHelper dbHelper) {
        this.dao = BaseDAOFactory.getBaseDAO(BaseDAO.BATTTESTDATA);
        this.model =new ServiceModel();
        this.webView = webView;
        this.dbHelper=dbHelper;
    }
    //批量插入修改
    @JavascriptInterface
    public void updatePro(String obj) {
        // 获取数据库对象
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        List<Batttestdata> list= ActionUtil.getGson("yyyy-MM-dd HH:mm:ss").fromJson(obj, new TypeToken<List<Batttestdata>>(){}.getType());
        boolean bl=((BatttestdataDAOImpl)dao).updatePro(db,list);
        if(bl){
            model.code=1;
            model.msg="修改成功";
        }else{
            model.code=0;
            model.msg="修改失败";
        }
        db.close();
        ActionUtil.SendCallDataToJS("updatePro",model,webView,ActionUtil.getGson("yyyy-MM-dd HH:mm:ss"));
    }
    //批量插入放电记录
    @JavascriptInterface
    public void add(String obj) {
        // 获取数据库对象
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        List<Batttestdata> list= ActionUtil.getGson("yyyy-MM-dd HH:mm:ss").fromJson(obj, new TypeToken<List<Batttestdata>>(){}.getType());
        boolean bl=dao.add(db,list);
        if(bl){
            model.code=1;
            model.msg="添加成功";
        }else{
            model.code=0;
            model.msg="添加失败";
        }
        db.close();
        ActionUtil.SendCallDataToJS("add",model,webView,ActionUtil.getGson("yyyy-MM-dd HH:mm:ss"));
    }
    //删除放电记录(battgroupid,test_record_count)
    @JavascriptInterface
    public void delPro(String obj) {
        // 获取数据库对象
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        List<Batttestdata> list= ActionUtil.getGson("yyyy-MM-dd HH:mm:ss").fromJson(obj, new TypeToken<List<Batttestdata>>(){}.getType());
        boolean bl=((BatttestdataDAOImpl)dao).delPro(db,list);
        if(bl){
            model.code=1;
            model.msg="删除成功";
        }else{
            model.code=0;
            model.msg="删除失败";
        }
        db.close();
        ActionUtil.SendCallDataToJS("delPro",model,webView,ActionUtil.getGson("yyyy-MM-dd HH:mm:ss"));
    }
    //历史监测根据battgroupid查询
    @JavascriptInterface
    public void serchByCondition(String obj) {
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        Batttestdata bdata=ActionUtil.getGson("yyyy-MM-dd HH:mm:ss").fromJson(obj,Batttestdata.class);
        List list=((BatttestdataDAOImpl)dao).serchMaxAndMintime(db,bdata);
        if(list!=null&&list.size()>0){
            Batttestdata b=(Batttestdata)list.get(list.size()-1);
            b.setBattGroupId(bdata.getBattGroupId());
            b.setTest_record_count(bdata.getTest_record_count());
            List listT=dao.serchByCondition(db,b);
            if(listT!=null&&listT.size()>0){
                model.code=1;
                model.data=listT;
                model.msg="查询成功";
            }else{
                model.code=0;
                model.msg="查询失败";
            }
        }else{
            model.code=0;
            model.msg="查询失败";
        }
        db.close();
        ActionUtil.SendCallDataToJS("serchByCondition",model,webView,ActionUtil.getGson("yyyy-MM-dd HH:mm:ss"));
    }
}