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
package com.nanometer.smartlab.controller;
 
import com.nanometer.smartlab.entity.LaboratoryReagentReserve;
import com.nanometer.smartlab.entity.SysController;
import com.nanometer.smartlab.service.LabReagentReserveService;
import com.nanometer.smartlab.service.SysControllerService;
import com.nanometer.smartlab.util.Constants;
import com.nanometer.smartlab.util.FacesUtils;
import org.apache.log4j.Logger;
import org.primefaces.context.RequestContext;
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 java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
 
/**
 * Created by johnny on 17/11/20.
 */
@Controller
@Scope("session")
public class LaboratoryReagentReserveController extends BaseController {
 
    private static Logger logger = Logger.getLogger(LaboratoryReagentReserveController.class);
 
    @Resource
    private LabReagentReserveService labReagentReserveService;
 
    private LazyDataModel<LaboratoryReagentReserve> dataModel;
    private List<LaboratoryReagentReserve> selectedList;
 
    private String labName;
    private String reagentName;
 
    public String getLabName() {
        return labName;
    }
 
    public void setLabName(String labName) {
        this.labName = labName;
    }
 
    public String getReagentName() {
        return reagentName;
    }
 
    public void setReagentName(String reagentName) {
        this.reagentName = reagentName;
    }
 
    private int action;
 
    public void onNewBtnClick() {
        this.action = Constants.ACTION_ADD;
    }
 
    /*public void onEditBtnClick() {
        if (this.selectedList == null
                || this.selectedList.size() == 0) {
            FacesUtils.warn("请选择数据。");
            return;
        }
        if (this.selectedList.size() > 1) {
            FacesUtils.warn("只能选择一个数据进行修改。");
            return;
        }
        this.controller = this.laboratoryReagentReserve.getSysController(this.selectedList.get(0).getId());
        this.action = Constants.ACTION_EDIT;
        RequestContext.getCurrentInstance().execute("PF('dialog').show()");
    }*/
 
   /* public void onSaveBtnClick() {
        try {
                if (this.controller == null) {
                FacesUtils.warn("新建对象为空。");
                return;
            }
 
            // 新建
            if (this.action == Constants.ACTION_ADD) {
                    if (this.sysControllerService.getSysControllerByCode(controller.getControllerCode())) {
                    FacesUtils.warn("设备代码已存在。");
                    return;
                }
 
                if (this.sysControllerService.getSysControllerByName(controller.getControllerName())) {
                    FacesUtils.warn("设备名称已存在。");
                    return;
                }
 
                this.sysControllerService.insertSysController(controller);
 
                FacesUtils.info("新建成功。");
                RequestContext.getCurrentInstance().execute("PF('dialog').hide()");
            // 修改
            } else if (this.action == Constants.ACTION_EDIT) {
 
 
                this.sysControllerService.updateSysController(controller);
 
                FacesUtils.info("修改成功。");
                RequestContext.getCurrentInstance().execute("PF('dialog').hide()");
            }
        } catch (Exception e) {
            logger.error("操作失败。", e);
            FacesUtils.warn("操作失败。");
        }
    }*/
 
    public void onDeleteBtnClick() {
        /*try {
            if (this.selectedList == null
                    || this.selectedList.size() == 0) {
                FacesUtils.warn("请选择数据。");
                return;
            }
            List<Integer> ids = new ArrayList<>();
            for(SysController controller : this.selectedList)
            {
                     ids.add(controller.getId());
            }
            this.sysControllerService.deleteSysControllers(ids);
 
            FacesUtils.info("删除成功。");
        } catch (Exception e) {
            logger.error("操作失败。", e);
            FacesUtils.warn("操作失败。");
        }*/
    }
 
    public LazyDataModel<LaboratoryReagentReserve> getDataModel() {
        if (this.dataModel == null) {
            this.dataModel = new LazyDataModel<LaboratoryReagentReserve>() {
                @Override
                public List<LaboratoryReagentReserve> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
                    List<LaboratoryReagentReserve> list = null;
                    try {
                        int count = labReagentReserveService.getCount(labName,reagentName);
                        this.setRowCount(count);
                        if (count > 0) {
                            list = labReagentReserveService.getList(first, pageSize,labName,reagentName);
                        }
                    } catch (Exception e) {
                        logger.error(e);
                    }
                    return list;
                }
 
                @Override
                public LaboratoryReagentReserve getRowData(String rowKey) {
//                    Iterator<LaboratoryReagentReserve> iterator = this.iterator();
//                    if (iterator != null) {
//                        LaboratoryReagentReserve br = null;
//                        while (iterator.hasNext()) {
//                            br = iterator.next();
//                            if (rowKey.equals(br.getId())) {
//                                return br;
//                            }
//                        }
//                    }
                    return null;
                }
            };
        }
 
        return dataModel;
    }
 
 
 
 
 
 
 
    public List<LaboratoryReagentReserve> getSelectedList() {
        return selectedList;
    }
 
    public void setSelectedList(List<LaboratoryReagentReserve> selectedList) {
        this.selectedList = selectedList;
    }
 
    public int getAction() {
        return action;
    }
}