kongzy
2024-07-01 47a751cb301d05276ae5d75145d57b2d090fe4e1
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
package com.nanometer.smartlab.controller;
 
 
import com.nanometer.smartlab.entity.HazardousWaste;
import com.nanometer.smartlab.entity.SysLaboratory;
import com.nanometer.smartlab.entity.SysUser;
import com.nanometer.smartlab.entity.dto.HazardousWasteUser;
import com.nanometer.smartlab.entity.enumtype.Waster;
import com.nanometer.smartlab.service.HazardousWasteService;
import com.nanometer.smartlab.service.SysUserService;
import com.nanometer.smartlab.util.Constants;
import com.nanometer.smartlab.util.FacesUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.primefaces.context.RequestContext;
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
 
import javax.annotation.Resource;
import javax.faces.event.ActionListener;
import java.text.SimpleDateFormat;
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 Long projectId;
    private String department;
    private String tid;
    private List<String> statusList = new ArrayList<> ();
    private boolean isSearch = false;
    private boolean isAnalysSearch = false;
    private LazyDataModel<HazardousWaste> analysisDataModel;
    private HazardousWaste selectedOne;
    /**
     * 选中的list
     */
    private List<HazardousWaste> selectedList;
 
    private HazardousWaste hazardousWaste=new HazardousWaste();
 
    private int action;
    @Autowired
    private SysUserService sysUserService;
 
    private List<SysUser> userSelectList;
 
    @Resource
    private HazardousWasteService hazardousWasteService;
 
    public List<SysUser> getUserSelectList() {
        if (userSelectList == null) {
            this.initUserSelectList();
        }
        return userSelectList;
    }
 
    private void initUserSelectList() {
        this.setUserSelectList(this.sysUserService.getSysUserList(null, null, null, null, null,null,null));
    }
 
    public SysUser getSelectedUserById(Long userId) {
        SysUser sysUser=this.sysUserService.getSysUser(userId);
        if(sysUser==null){
            return new SysUser();
        }
        return sysUser;
    }
 
    public void addHazardousWaste(){
        this.hazardousWaste = new HazardousWaste();
        this.action = Constants.ACTION_ADD;
        RequestContext.getCurrentInstance().execute("PF('wastedialog').show()");
    }
 
    public void editHazardousWaste(){
        if (this.selectedList == null || this.selectedList.size() == 0) {
            FacesUtils.warn("请选择数据。");
            return;
        }
        if (this.selectedList.size() > 1) {
            FacesUtils.warn("只能选择一个数据进行修改。");
            return;
        }
        this.hazardousWaste=this.hazardousWasteService.selectById(this.selectedList.get(0).getId());
        this.action = Constants.ACTION_EDIT;
        RequestContext.getCurrentInstance().execute("PF('wastedialog').show()");
    }
 
    public void onSaveBtnClick(){
        try {
            Long userId = this.hazardousWaste.getApplyPerson();
            SysUser sysUser = sysUserService.getSysUser(userId);
            this.hazardousWaste.setUnit(sysUser.getCompany());
            String userName = getUserName();
            if (this.action == Constants.ACTION_ADD) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
                this.hazardousWaste.setCreator(userName);
                this.hazardousWaste.setTid(sdf.format(new Date()));
                this.hazardousWaste.setStatus("待确认");
                hazardousWasteService.insertInfo(this.hazardousWaste);
                FacesUtils.info("新建成功。");
                RequestContext.getCurrentInstance().execute("PF('wastedialog').hide()");
            } else {
                this.hazardousWaste.setUpdator(userName);
                hazardousWasteService.updateWaste(this.hazardousWaste);
                FacesUtils.info("修改成功。");
                RequestContext.getCurrentInstance().execute("PF('wastedialog').hide()");
            }
        }catch (Exception e){
            logger.error("操作失败。", e);
            FacesUtils.warn("操作失败。");
        }
    }
 
    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 {
                        if (getUser().getWaster() != null){
                            if (getUser().getWaster().equals(Waster.MANAGE)){
                                int pageCount = hazardousWasteService.countAll(startTime,endTime,status,applyPerson,projectId,department,tid);
                                this.setRowCount(pageCount);
                                if (pageCount > 0)
                                    list = hazardousWasteService.selectAll(startTime,endTime,status,applyPerson,projectId,department,tid,first, pageSize);
                            }else if (getUser().getProjectId()!=null){
                                int pageCount = hazardousWasteService.countAll(startTime,endTime,status,applyPerson,getUser().getProjectId(),department,tid);
                                this.setRowCount(pageCount);
                                if (pageCount > 0)
                                    list = hazardousWasteService.selectAll(startTime,endTime,status,applyPerson,getUser().getProjectId(),department,tid,first, pageSize);
                            }
                        }else {
                            this.setRowCount(0);
                        }
                        //查询更换模式
                        if (isSearch) {
                            isSearch = false;
                        }
                        selectedOne = null;
                    } 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 hazardousWasteService.selectById(Long.parseLong(rowKey));
                }
            };
        }
        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 {
                        if (getUser().getWaster() != null){
                            if (getUser().getWaster().equals(Waster.MANAGE)){
                                int pageCount = hazardousWasteService.countStatistics(startTime,endTime,status,applyPerson,projectId,department);
                                this.setRowCount(pageCount);
                                if (pageCount > 0)
                                    list = hazardousWasteService.selectStatistics(startTime,endTime,status,applyPerson,projectId,department,first, pageSize);
                            }else if (getUser().getProjectId()!=null){
                                int pageCount = hazardousWasteService.countStatistics(startTime,endTime,status,applyPerson,getUser().getProjectId(),department);
                                this.setRowCount(pageCount);
                                if (pageCount > 0)
                                    list = hazardousWasteService.selectStatistics(startTime,endTime,status,applyPerson,getUser().getProjectId(),department,first, pageSize);
                            }
                        }else {
                            this.setRowCount(0);
                        }
 
                        //查询更换模式
                        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 Long getProjectId() {
        return projectId;
    }
 
    public void setProject(Long projectId) {
        this.projectId = projectId;
    }
 
    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("已拒绝");
        statusList.add("已取消");
        return statusList;
    }
 
 
    public void export2Excel() {
        List<Map> list = new ArrayList<>();
        if (getUser().getWaster() != null){
            if (getUser().getWaster().equals(Waster.MANAGE)){
                list = hazardousWasteService.exportList(startTime,endTime,status,applyPerson,projectId,department,tid);
            }else if (getUser().getProjectId()!=null){
                list = hazardousWasteService.exportList(startTime,endTime,status,applyPerson,getUser().getProjectId(),department,tid);
            }
        }
 
        try{
            hazardousWasteService.export2Excel(list);
        }catch (Exception e){
            e.printStackTrace();
            FacesUtils.warn("导出失败");
        }
    }
 
    public void exportStatistics2Excel(){
        List<Map> list = new ArrayList<>();
        if (getUser().getWaster() != null){
            if (getUser().getWaster().equals(Waster.MANAGE)){
                list = hazardousWasteService.exportStatisticsList(startTime,endTime,status,applyPerson,projectId,department);
            }else if (getUser().getProjectId()!=null){
                list = hazardousWasteService.exportStatisticsList(startTime,endTime,status,applyPerson,getUser().getProjectId(),department);
            }
        }
        try{
            hazardousWasteService.exportStatistics2Excel(list);
        }catch (Exception e){
            e.printStackTrace();
            FacesUtils.warn("导出失败");
        }
    }
 
    public void cancelOne(){
        //待确认状态的才能取消
        if (this.selectedList == null || this.selectedList.size() == 0) {
            FacesUtils.warn("请选择数据。");
            return;
        }
        if (this.selectedList.size() > 1) {
            FacesUtils.warn("只能选择一个数据进行修改。");
            return;
        }
        HazardousWaste hwaste=this.selectedList.get(0);
        if (!"待确认".equals(hwaste.getStatus())) {
            FacesUtils.warn("非待确认不能取消");
            return;
        }
        try {
            hwaste.setStatus("已取消");
            hazardousWasteService.updateWaste(hwaste);
            FacesUtils.warn("操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            FacesUtils.warn("操作失败");
        }
    }
 
    public void recoverOne(){
        if (this.selectedList == null || this.selectedList.size() == 0) {
            FacesUtils.warn("请选择数据。");
            return;
        }
        if (this.selectedList.size() > 1) {
            FacesUtils.warn("只能选择一个数据进行修改。");
            return;
        }
        HazardousWaste hwaste=this.selectedList.get(0);
        if (!"已取消".equals(hwaste.getStatus())) {
            FacesUtils.warn("非已取消不能恢复");
            return;
        }
        try {
            hwaste.setStatus("待确认");
            hazardousWasteService.updateWaste(hwaste);
            FacesUtils.warn("操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            FacesUtils.warn("操作失败");
        }
    }
 
    public String getTid() {
        return tid;
    }
 
    public void setTid(String tid) {
        this.tid = tid;
    }
 
    public HazardousWaste getSelectedOne() {
        return selectedOne;
    }
 
    public void setSelectedOne(HazardousWaste selectedOne) {
        this.selectedOne = selectedOne;
    }
 
    public List<HazardousWaste> getSelectedList() {
        return selectedList;
    }
 
    public void setSelectedList(List<HazardousWaste> selectedList) {
        this.selectedList = selectedList;
    }
 
    public HazardousWaste getHazardousWaste() {
        return hazardousWaste;
    }
 
    public void setHazardousWaste(HazardousWaste hazardousWaste) {
        this.hazardousWaste = hazardousWaste;
    }
 
    public int getAction() {
        return action;
    }
 
    public void setAction(int action) {
        this.action = action;
    }
 
    public void setUserSelectList(List<SysUser> userSelectList) {
        this.userSelectList = userSelectList;
    }
}