李宇
2021-01-13 5ce314bb05eef373bd25b0b2e289a01bf6e5b6c4
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package com.nanometer.smartlab.controller;
 
 
import com.nanometer.smartlab.entity.HazardousWaste;
import com.nanometer.smartlab.service.HazardousWasteService;
import com.nanometer.smartlab.util.FacesUtils;
import org.apache.log4j.Logger;
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
 
import javax.annotation.Resource;
import javax.faces.event.ActionListener;
import java.util.*;
 
@Controller
@Scope("session")
public class HazardousWasteController extends BaseController{
 
    private static Logger logger = Logger.getLogger(HazardousWasteController.class);
 
    private LazyDataModel<HazardousWaste> dataModel;
 
    private Date startTime;
    private Date endTime;
    private String status;
    private String applyPerson;
    private String project;
    private String department;
    private String tid;
    private List<String> statusList = new ArrayList<> ();
    private boolean isSearch = false;
    private boolean isAnalysSearch = false;
    private LazyDataModel<HazardousWaste> analysisDataModel;
 
    @Resource
    private HazardousWasteService hazardousWasteService;
 
    public LazyDataModel<HazardousWaste> getDataModel() {
        if (this.dataModel == null) {
            this.dataModel = new LazyDataModel<HazardousWaste>() {
 
                public List<HazardousWaste> load
                        (int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
 
                    List<HazardousWaste> list = null;
                    try {
                        int pageCount = hazardousWasteService.countAll(startTime,endTime,status,applyPerson,project,department,tid);
 
                        this.setRowCount(pageCount);
                        if (pageCount > 0)
                            list = hazardousWasteService.selectAll(startTime,endTime,status,applyPerson,project,department,tid,first, pageSize);
                        //查询更换模式
                        if (isSearch) {
                            isSearch = false;
                        }
                    } catch (Exception e) {
                        logger.error("error occured.", e);
                    }
                    return list;
                }
 
                @Override
                public HazardousWaste getRowData(String rowKey) {
                    Iterator<HazardousWaste> iterator = this.iterator();
                    HazardousWaste su = null;
                    while (iterator.hasNext()) {
                        su = iterator.next();
                        if ( su.getId().equals(Long.parseLong(rowKey))) {
                            return su;
                        }
                    }
                    return null;
                }
            };
        }
        return dataModel;
    }
 
    public void modelChange() {
        this.isSearch = true;
    }
 
    public void setDataModel(LazyDataModel<HazardousWaste> dataModel) {
        this.dataModel = dataModel;
    }
 
    public LazyDataModel<HazardousWaste> getAnalysisDataModel() {
        if (this.analysisDataModel == null) {
            this.analysisDataModel = new LazyDataModel<HazardousWaste>() {
 
                public List<HazardousWaste> load
                        (int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
 
                    List<HazardousWaste> list = null;
                    try {
                        int pageCount = hazardousWasteService.countStatistics(startTime,endTime,status,applyPerson,project,department);
 
                        this.setRowCount(pageCount);
                        if (pageCount > 0)
                            list = hazardousWasteService.selectStatistics(startTime,endTime,status,applyPerson,project,department,first, pageSize);
 
                        //查询更换模式
                        if (isAnalysSearch) {
                            isAnalysSearch = false;
                        }
                    } catch (Exception e) {
                        logger.error("error occured.", e);
                    }
                    return list;
                }
 
                @Override
                public HazardousWaste getRowData(String rowKey) {
                    Iterator<HazardousWaste> iterator = this.iterator();
                    HazardousWaste su = null;
                    while (iterator.hasNext()) {
                        su = iterator.next();
                        if ( su.getId().equals(Long.parseLong(rowKey))) {
                            return su;
                        }
                    }
                    return null;
                }
            };
        }
        return analysisDataModel;
    }
 
    public void modelAnalysisChange() {
        this.isAnalysSearch = true;
    }
 
    public void setAnalysisDataModel(LazyDataModel<HazardousWaste> dataModel) {
        this.analysisDataModel = dataModel;
    }
 
    public Date getStartTime() {
        return startTime;
    }
 
    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }
 
    public Date getEndTime() {
        return endTime;
    }
 
    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }
 
    public boolean isSearch() {
        return isSearch;
    }
 
    public void setSearch(boolean search) {
        isSearch = search;
    }
 
    public String getStatus() {
        return status;
    }
 
    public void setStatus(String status) {
        this.status = status;
    }
 
    public String getApplyPerson() {
        return applyPerson;
    }
 
    public void setApplyPerson(String applyPerson) {
        this.applyPerson = applyPerson;
    }
 
    public String getProject() {
        return project;
    }
 
    public void setProject(String project) {
        this.project = project;
    }
 
    public String getDepartment() {
        return department;
    }
 
    public void setDepartment(String department) {
        this.department = department;
    }
 
    public List<String> getStatusList() {
        statusList = new ArrayList<> ();
        statusList.add("全部");
        statusList.add("待解决");
        statusList.add("已解决");
        statusList.add("已拒绝");
        return statusList;
    }
 
 
    public void export2Excel() {
        List<Map> list = hazardousWasteService.exportList(startTime,endTime,status,applyPerson,project,department,tid);
        try{
            hazardousWasteService.export2Excel(list);
        }catch (Exception e){
            e.printStackTrace();
            FacesUtils.warn("导出失败");
        }
    }
 
    public void exportStatistics2Excel(){
        List<Map> list = hazardousWasteService.exportStatisticsList(startTime,endTime,status,applyPerson,project,department);
        try{
            hazardousWasteService.exportStatistics2Excel(list);
        }catch (Exception e){
            e.printStackTrace();
            FacesUtils.warn("导出失败");
        }
    }
 
    public String getTid() {
        return tid;
    }
 
    public void setTid(String tid) {
        this.tid = tid;
    }
}