whyclj
2019-10-29 1c0469e45346d464e0c5672ee68f9ecd4fb6be7c
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package com.fgkj.actions;
 
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Blob;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import com.fgkj.dao.UinfDaoFactory;
import com.fgkj.dto.BattDischarge_plan;
import com.fgkj.dto.ServiceModel;
import com.fgkj.dto.User_Chart;
import com.fgkj.dto.User_inf;
import com.fgkj.dto.User_log;
import com.fgkj.services.BattDischarge_planService;
import com.fgkj.services.User_ChartService;
import com.fgkj.services.User_logService;
 
public class User_ChartAction extends ActionUtil{
    private User_ChartService service = new User_ChartService();
    private User_logService uservice=new User_logService();
    private List<File> file;
    private List<String> fileFileName;
    private List<String> filetype;
    private String json;
    private String result;
    private User_Chart uc;
    private static Map<String,String> fileUtil = new HashMap<String, String>(){
        {
            put("logo","logo.png");
            put("normal","home_normal.gif");
            put("behind","home_behind.gif");
            put("timeout","home_timeout.gif");
            put("warn","home_warn.gif");
            //添加61850设备对应的kk  --》文件名称
            put("nuclear","home_warn.gif");
            put("devalarm","home_warn.gif");
            put("precharge","home_warn.gif");
            put("onlinecharge","home_warn.gif");
        }        
    };
    
    //添加图标
    public String add(){
        User_Chart uchart = ActionUtil.getGson().fromJson(json, User_Chart.class);
        suitFiles(file,filetype,uchart);
        ServiceModel model =service.add(uchart);
        {
            String msg="添加"+uchart.getChart_name()+"班组图表";
            User_log ulog=UinfDaoFactory.CreateULog(UinfDaoFactory.Increase, msg);
            uservice.add(ulog);//将用户的操作记录下来
        }
        result = tojson(model);
        return SUCCESS;
    }
    
    
    //修改图标信息
    public String update(){
        User_Chart uchart = ActionUtil.getGson().fromJson(json, User_Chart.class);
        suitFiles(file,filetype,uchart);            //设置对象的属性值
        ServiceModel model =service.update(uchart);
        {
            String msg="修改"+uchart.getChart_name()+"班组图表";
            User_log ulog=UinfDaoFactory.CreateULog(UinfDaoFactory.Alter, msg);
            uservice.add(ulog);//将用户的操作记录下来
        }
        result = tojson(model);
        return SUCCESS;
    }
    //删除图标
    public String del(){
        User_Chart uchart = ActionUtil.getGson("yyyy-MM-dd HH:mm:ss").fromJson(json, User_Chart.class);
        ServiceModel model =service.del(uchart);
        {
            String msg="删除"+uchart.getChart_name()+"班组图表";
            User_log ulog=UinfDaoFactory.CreateULog(UinfDaoFactory.Delete, msg);
            uservice.add(ulog);//将用户的操作记录下来
        }
        result = tojson(model);
        return SUCCESS;
    }
    
    //查询所有图标
    public String searchAll(){
        ServiceModel model =service.searchAll();
        result = tojson(model);
        return SUCCESS;
    }
    
    //根据用户id查图表
    public String serchByCondition(){
        User_inf uinf = ActionUtil.getGson("yyyy-MM-dd HH:mm:ss").fromJson(json, User_inf.class);
        ServiceModel model =service.serchByCondition(uinf);
        result = tojson(model);
        return SUCCESS;
    }
 
    //根据chartfile和列名查具体的图片
    public void serchByInfo(){
        //System.out.println(json);
        InputStream is = null;
        OutputStream os =null;
        User_Chart uc = getGson().fromJson(json, User_Chart.class);
        ServiceModel model = service.serchByInfo(uc);
        if(model.code == 1){
            List list = (List) model.getData();
            Blob blob = (Blob) list.get(0);
            try {
                is = blob.getBinaryStream();
                os = ActionUtil.getResponse().getOutputStream();
                byte[] image = IStoByteArr(is);
                os.write(image);
                os.flush();
            } catch (SQLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally{
                if(os != null){
                    try {
                        os.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
    
    /**
     * 将文件设置到指定的对象中去
     * @param files
     * @param ftype
     * @param uc
     */
    private void suitFiles(List<File> files,List<String> ftype,User_Chart uc){
        for(int i=0;i<files.size() && i<ftype.size();i++){
            if("logo".equals(ftype.get(i))){
                uc.setChart_logo(files.get(i));
            }else if("normal".equals(ftype.get(i))){
                uc.setChart_normal(files.get(i));
            }else if("behind".equals(ftype.get(i))){
                uc.setChart_behind(files.get(i));
            }else if("timeout".equals(ftype.get(i))){
                uc.setChart_timeout(files.get(i));
            }else if("warn".equals(ftype.get(i))){
                uc.setChart_warn(files.get(i));
            }else if("nuclear".equals(ftype.get(i))){
                uc.setChart_nuclear_cap(files.get(i));
            }else if("devalarm".equals(ftype.get(i))){
                uc.setChart_dev_alarm(files.get(i));
            }else if("precharge".equals(ftype.get(i))){
                uc.setChart_pre_charge(files.get(i));
            }else if("onlinecharge".equals(ftype.get(i))){
                uc.setChart_online_charge(files.get(i));
            }
            
        }
    }
    
    public String getResult() {
        return result;
    }
    
    
    
    public void setResult(String result) {
        this.result = result;
    }
 
 
    public void setJson(String json) {
        this.json = json;
    }
 
 
    public void setUc(User_Chart uc) {
        this.uc = uc;
    }
 
    public void setFile(List<File> file) {
        this.file = file;
    }
 
    public void setFileFileName(List<String> fileFileName) {
        this.fileFileName = fileFileName;
    }
 
 
    public void setFiletype(List<String> filetype) {
        this.filetype = filetype;
    }
}