lyfO_o
2021-04-22 3ef5a9d0aba195d77aa22591b55a9ce9e43372ca
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
package com.nanometer.smartlab.controller;
 
import java.util.Iterator;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
 
import org.apache.commons.lang.StringUtils;
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 com.nanometer.smartlab.entity.OpeOrder;
import com.nanometer.smartlab.entity.OpeReagentStatus;
import com.nanometer.smartlab.entity.SysLaboratory;
import com.nanometer.smartlab.entity.SysLaboratoryContainer;
import com.nanometer.smartlab.entity.SysReagent;
import com.nanometer.smartlab.entity.enumtype.ApplyStatus;
import com.nanometer.smartlab.entity.enumtype.ArrivalStatus;
import com.nanometer.smartlab.service.OpeReagentStatusService;
import com.nanometer.smartlab.service.SysLaboratoryContainerService;
import com.nanometer.smartlab.service.SysReagentService;
import com.nanometer.smartlab.util.Constants;
import com.nanometer.smartlab.util.FacesUtils;
 
/**
 * Created by cmower on 17/11/20.
 */
@Controller
@Scope("session")
public class LaboratoryStockMngController extends BaseController {
 
    private static final long serialVersionUID = 101543880938627455L;
 
    private static Logger logger = Logger.getLogger(LaboratoryStockMngController.class);
 
    @Resource
    private OpeReagentStatusService opeReagentStatusService;
    @Resource
    private SysReagentService sysReagentService;
    @Resource
    private SysLaboratoryContainerService sysLaboratoryContainerService;
    @Resource
    private MenuController menuController;
 
    private LazyDataModel<OpeReagentStatus> reagentStatusDataModel;
    /**
     * 使用记录用
     */
    private LazyDataModel<OpeReagentStatus> reagentStoreDataModel;
 
    private String reagentId;
    private List<SysReagent> reagentSelectList;
    private List<OpeReagentStatus> selectedStoreList;
 
    private List<SysLaboratoryContainer> laboratoryContainers;
 
    private String reagentCode;
    private String labName;
 
    /**
     * 数据模型
     */
    private String laboratoryId;
    private String laboratoryContainerId;
 
    /**
     * SpringMenu中初始化
     */
    public void initPage() {
        this.initReagentSelectList();
    }
 
    public void initStorePage() {
    }
 
    private void initReagentSelectList() {
        //this.setReagentSelectList(this.sysReagentService.getSysReagentList(null, null, null, null, null));
    }
 
    private int action;
 
    @SuppressWarnings("serial")
    public LazyDataModel<OpeReagentStatus> getReagentStatusDataModel() {
        if (this.reagentStatusDataModel == null) {
            this.reagentStatusDataModel = new LazyDataModel<OpeReagentStatus>() {
                @Override
                public List<OpeReagentStatus> load(int first, int pageSize, String sortField, SortOrder sortOrder,
                        Map<String, Object> filters) {
                    List<OpeReagentStatus> list = null;
                    System.out.println(reagentId);
                    try {
                        int count = opeReagentStatusService.getOpeReagentStatusTotalCountForLab(reagentId, null,
                                ArrivalStatus.LABORATORY.getKey(), reagentCode, getUserId(),labName);
                        this.setRowCount(count);
                        if (count > 0) {
                            list = opeReagentStatusService.getOpeReagentStatusListForLab(reagentId, null,
                                    ArrivalStatus.LABORATORY.getKey(), reagentCode, getUserId(),labName, first, pageSize);
                        }
                    } catch (Exception e) {
                        logger.error(e);
                    }
                    return list;
                }
 
                @Override
                public OpeReagentStatus getRowData(String rowKey) {
                    Iterator<OpeReagentStatus> iterator = this.iterator();
                    if (iterator != null) {
                        OpeReagentStatus su = null;
                        while (iterator.hasNext()) {
                            su = iterator.next();
                            if (rowKey.equals(su.getId())) {
                                return su;
                            }
                        }
                    }
                    return null;
                }
            };
        }
        return reagentStatusDataModel;
    }
 
    @SuppressWarnings("serial")
    public LazyDataModel<OpeReagentStatus> getReagentStoreDataModel() {
        if (this.reagentStoreDataModel == null) {
            this.reagentStoreDataModel = new LazyDataModel<OpeReagentStatus>() {
                @Override
                public List<OpeReagentStatus> load(int first, int pageSize, String sortField, SortOrder sortOrder,
                        Map<String, Object> filters) {
                    List<OpeReagentStatus> list = null;
                    try {
                        int count = opeReagentStatusService.getOpeReagentStatusTotalCount(null, null,
                                ArrivalStatus.PERSONAL.getKey(), null, getUserId());
                        this.setRowCount(count);
                        if (count > 0) {
                            list = opeReagentStatusService.getOpeReagentStatusList(null, null,
                                    ArrivalStatus.PERSONAL.getKey(), null, getUserId(), first, pageSize);
                        }
                    } catch (Exception e) {
                        logger.error(e);
                    }
                    return list;
                }
 
                @Override
                public OpeReagentStatus getRowData(String rowKey) {
                    Iterator<OpeReagentStatus> iterator = this.iterator();
                    if (iterator != null) {
                        OpeReagentStatus su = null;
                        while (iterator.hasNext()) {
                            su = iterator.next();
                            if (rowKey.equals(su.getId())) {
                                return su;
                            }
                        }
                    }
                    return null;
                }
            };
        }
        return reagentStoreDataModel;
    }
 
 
    public void exportLabStock() {
        try {
            List<Map> list = opeReagentStatusService.selectExportList(reagentId, null,
                    ArrivalStatus.LABORATORY.getKey(), reagentCode, getUserId(),labName);
            opeReagentStatusService.exportLabStock2Excel(list);
            FacesUtils.info("导出成功");
        }catch (Exception e){
            e.printStackTrace();
            FacesUtils.warn("导出失败");
        }
    }
 
    public int getAction() {
        return action;
    }
 
    public List<SysReagent> getReagentSelectList() {
        if (this.reagentSelectList == null) {
            this.initReagentSelectList();
        }
        return reagentSelectList;
    }
 
    public void setReagentSelectList(List<SysReagent> reagentSelectList) {
        this.reagentSelectList = reagentSelectList;
    }
 
    public String getReagentId() {
        return reagentId;
    }
 
    public void setReagentId(String reagentId) {
        this.reagentId = reagentId;
    }
 
    public String getReagentCode() {
        return reagentCode;
    }
 
    public void setReagentCode(String reagentCode) {
        this.reagentCode = reagentCode;
    }
 
    public String getLaboratoryId() {
        return laboratoryId;
    }
 
    public void setLaboratoryId(String laboratoryId) {
        this.laboratoryId = laboratoryId;
    }
 
    public String getLaboratoryContainerId() {
        return laboratoryContainerId;
    }
 
    public void setLaboratoryContainerId(String laboratoryContainerId) {
        this.laboratoryContainerId = laboratoryContainerId;
    }
 
    public void onCancelBtnClick() {
        this.menuController.backToPage();
    }
 
    // 现在试剂柜多了操作状态字段,
    // 实验室临时存放的操作状态无法判断
    // 是试剂柜入库,还是错误入库
    // 暂定是试剂柜入库
    public void onSaveBtnClick() {
        if (StringUtils.isBlank(laboratoryId)) {
            FacesUtils.warn("请选择实验室。");
            return;
        }
        if (StringUtils.isBlank(laboratoryContainerId)) {
            FacesUtils.warn("请选择临时存储库。");
            return;
        }
        if (this.selectedStoreList == null || this.selectedStoreList.size() == 0) {
            FacesUtils.warn("请选择试剂。");
            return;
        }
 
        for (OpeReagentStatus opeReagentStatus : selectedStoreList) {
            if (opeReagentStatus.getStatus().getKey() != ArrivalStatus.PERSONAL.getKey()) {
                FacesUtils.warn("只能存放个人领用中的试剂。");
                return;
            }
        }
 
        this.opeReagentStatusService.store(selectedStoreList, laboratoryId, laboratoryContainerId);
 
        FacesUtils.info("存放成功。");
    }
 
    public List<OpeReagentStatus> getSelectedStoreList() {
        return selectedStoreList;
    }
 
    public void setSelectedStoreList(List<OpeReagentStatus> selectedStoreList) {
        this.selectedStoreList = selectedStoreList;
    }
 
    public void onStoreBtnClick() {
        this.menuController.goToPage(Constants.PAGE_LABARATORY_STORE, Constants.PAGE_LABARATORY_STOCK_MNG);
    }
 
    public void onLaboratoryChange() {
        laboratoryContainers = sysLaboratoryContainerService.getSysLaboratoryContainerList(laboratoryId);
    }
 
    public List<SysLaboratoryContainer> getLaboratoryContainers() {
        return laboratoryContainers;
    }
 
    public void setLaboratoryContainers(List<SysLaboratoryContainer> laboratoryContainers) {
        this.laboratoryContainers = laboratoryContainers;
    }
 
    public String getLabName() {
        return labName;
    }
 
    public void setLabName(String labName) {
        this.labName = labName;
    }
}