gdg
2021-02-03 94e89a3391c7f28d9002fbcc0cafdbf6d05d7e73
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
package com.nanometer.smartlab.controller;
 
import java.text.SimpleDateFormat;
import java.util.*;
 
import javax.annotation.Resource;
 
import com.nanometer.smartlab.entity.OpeUseFlow;
import com.nanometer.smartlab.entity.SysLaboratory;
import com.nanometer.smartlab.entity.dto.ApplyListDto;
import com.nanometer.smartlab.entity.dto.PersonUseDetail;
import com.nanometer.smartlab.entity.enumtype.ArrivalStatus;
import com.nanometer.smartlab.service.SysLaboratoryService;
import com.nanometer.smartlab.util.FacesUtils;
import com.nanometer.smartlab.util.Utils;
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.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
 
import com.nanometer.smartlab.entity.OpeReagentStatus;
import com.nanometer.smartlab.entity.SysReagent;
import com.nanometer.smartlab.service.OpeReagentStatusService;
import com.nanometer.smartlab.service.OpeUseFlowService;
import com.nanometer.smartlab.service.SysReagentService;
 
/**
 * Created by cmower on 17/11/20.
 */
@Controller
@Scope("session")
public class PersonalUseInfoController extends BaseController {
 
    private static final long serialVersionUID = 101543880938627455L;
 
    private static Logger logger = Logger.getLogger(PersonalUseInfoController.class);
 
    @Resource
    private OpeUseFlowService opeUseFlowService;
    @Resource
    private OpeReagentStatusService opeReagentStatusService;
 
    @Resource
    private SysReagentService sysReagentService;
    @Resource
    private SysLaboratoryService sysLaboratoryService;
    @Value("${institute.name}")
    String instituteName;
 
    /**
     * 数据源
     */
    private LazyDataModel<OpeReagentStatus> dataModel;
    private String reagentId;
    private String reagentName;
    private String reagentCode;
    private String applyPerson;
    private Date startTime;
    private Date endTime;
    private String project;
    private String department;
    private String receiptNumber;
    private LazyDataModel<OpeUseFlow> dataModel2;
    private OpeUseFlow selectOne;
    private List<PersonUseDetail> personUseDetail;
    private Hashtable<String,Object> printTable;
 
    private List<OpeReagentStatus> selectedList;
    private List<SysReagent> reagentSelectList;
 
    public List<OpeReagentStatus> getSelectedList() {
        return selectedList;
    }
 
    public void setSelectedList(List<OpeReagentStatus> selectedList) {
        this.selectedList = selectedList;
    }
 
    public List<SysReagent> getReagentSelectList() {
        if (this.reagentSelectList == null) {
            this.initReagentSelectList();
        }
        return reagentSelectList;
    }
 
    public void setReagentSelectList(List<SysReagent> reagentSelectList) {
        this.reagentSelectList = reagentSelectList;
    }
 
    private void initReagentSelectList() {
        this.setReagentSelectList(this.sysReagentService.getSysReagentList(null,null, null, null, null, null));
    }
 
    public void initPage() {
        this.initReagentSelectList();
    }
 
    public void updateTimeByCode(){
        List<OpeReagentStatus> list=this.selectedList;
        if(list!=null&&list.size()>0){
            for(int i=0;i<list.size();i++){
                this.opeReagentStatusService.updateTimeByCode(list.get(i).getReagentCode());
                this.opeUseFlowService.updateTimeByCode(list.get(i).getReagentCode());
            }
            FacesUtils.info("更新成功。");
        }else {
            FacesUtils.info("请选择数据。");
        }
    }
 
    /**
    *@description 取消试剂认领
    *@date 2020/7/20
    *@author celin
    */
    public void reagentReturn(){
 
        try {
            if (selectOne == null) {
                FacesUtils.warn("请选择单号");
                return;
            }
            //判断单子下的试剂是否全部 为 领用待入库-1,不是就不能取消领用
            List<PersonUseDetail> applyList = opeUseFlowService.getApplyInfo(selectOne.getReceiptNumber());
            boolean flag = applyList.stream().allMatch(pu ->
                        opeReagentStatusService.getOpeReagentStatusByReagentCode(pu.getReagentCode() ).getStatus()== ArrivalStatus.NOREGISTER);
            if (!flag) {
                FacesUtils.warn("试剂当前状态不可以取消领用");
                return;
            }
 
            //没有批次号不可以取消领用
            boolean flag1 = applyList.stream().allMatch(pu -> pu.getArticleNumber() != null);
            if (!flag1) {
                FacesUtils.warn("没有批次号不可以取消领用");
                return;
            }
 
            //取消领用
            opeReagentStatusService.batchUpdateStatusByCode(applyList);
            FacesUtils.info("已取消试剂");
        }catch (Exception e){
            FacesUtils.info("请选择数据");
        }
 
 
    }
    /**
    * 生成领用单
    */
 
    public void generateReceipt() {
        if (this.selectOne == null) {
            FacesUtils.warn("请选择数据");
            return;
        }
 
        printTable = new Hashtable<>();
        printTable.put("head", instituteName);
        printTable.put("title", "领用单");
        printTable.put("applyPerson", selectOne.getUserName());
        printTable.put("department", selectOne.getDepartment());
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        printTable.put("date", dateFormat.format(selectOne.getCreateTime()));
        printTable.put("phone", selectOne.getPhone());
        printTable.put("receiptNumber", selectOne.getReceiptNumber());
        printTable.put("project", selectOne.getProject());
        SysLaboratory sysLaboratory = sysLaboratoryService.getSysLaboratory(selectOne.getHouseId());
        printTable.put("lab", sysLaboratory.getName());
        //整理数据
        List<PersonUseDetail> applyInfo = opeUseFlowService.getApplyInfo(selectOne.getReceiptNumber());
        assert applyInfo.size() > 0;
        List<ApplyListDto> applyList = new ArrayList<>();
        Map<String, Integer> map = new HashMap<>();
        for (PersonUseDetail pud : applyInfo) {
            if (map.containsKey(pud.getReagentId())) {
                map.put(pud.getReagentId(), map.get(pud.getReagentId()) + 1);
            }else{
                map.put(pud.getReagentId(), 1);
            }
        }
        int sum = 0;
        for (Map.Entry<String,Integer> entry : map.entrySet()) {
            ApplyListDto apply = new ApplyListDto();
            for (PersonUseDetail pud : applyInfo) {
                if (entry.getKey().equals(pud.getReagentId())) {
                    apply.setControlProducts(pud.getControlProducts());
                    apply.setMainMetering(pud.getPerInfo());
                    apply.setNum(entry.getValue().toString());
                    apply.setProductCode(pud.getProductSn());
                    apply.setProductName(pud.getReagentName());
                    apply.setReagentFormat(pud.getReagentFormat());
                    applyList.add(apply);
                    sum += entry.getValue();
                    break;
                }
            }
        }
 
        applyList.add(new ApplyListDto("合计", "", "", "", "", String.valueOf(sum), ""));
        printTable.put("applyList", applyList);
        RequestContext.getCurrentInstance().execute("PF('printDialog').show()");
    }
 
    /**
    * 查看详情
    */
 
    public void detailInfo() {
        if (this.selectOne == null) {
            FacesUtils.warn("请选择数据");
        }
 
        personUseDetail = opeUseFlowService.getApplyInfo(selectOne.getReceiptNumber());
 
    }
 
    @SuppressWarnings("serial")
    public LazyDataModel<OpeReagentStatus> getDataModel() {
        if (this.dataModel == null) {
            this.dataModel = 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.getPersonReagentStatusTotalCountByName(reagentId, null, reagentCode, getUserId(),applyPerson,startTime,endTime);
                        this.setRowCount(count);
                        if (count > 0) {
                            list = opeReagentStatusService.getPersonReagentStatusListByName(reagentId, null, reagentCode, getUserId(),applyPerson,startTime,endTime ,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 dataModel;
    }
 
    public LazyDataModel<OpeUseFlow> getDataModel2() {
        if (this.dataModel2 == null) {
            this.dataModel2 = new LazyDataModel<OpeUseFlow>() {
                @Override
                public List<OpeUseFlow> load(int first, int pageSize, String sortField, SortOrder sortOrder,
                                                   Map<String, Object> filters) {
                    List<OpeUseFlow> list = null;
                    try {
                        int count = opeUseFlowService.getPersonalUseInfoCount(reagentCode, getUserId(),startTime,endTime,receiptNumber,department,project,applyPerson,reagentName);
                        this.setRowCount(count);
                        if (count > 0) {
                            list = opeUseFlowService.getPersonalUseInfoList
                                    (reagentCode,  getUserId(),startTime,endTime ,receiptNumber,department,project,applyPerson,reagentName,first,pageSize);
                        }
                    } catch (Exception e) {
                        logger.error(e);
                    }
                    return list;
                }
 
                @Override
                public OpeUseFlow getRowData(String rowKey) {
                    Iterator<OpeUseFlow> iterator = this.iterator();
                    if (iterator != null) {
                        OpeUseFlow su = null;
                        while (iterator.hasNext()) {
                            su = iterator.next();
                            if (rowKey.equals(su.getReceiptNumber())) {
                                return su;
                            }
                        }
                    }
                    return null;
                }
            };
        }
        return dataModel2;
    }
 
    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 getApplyPerson() {
        return applyPerson;
    }
 
    public void setApplyPerson(String applyPerson) {
        this.applyPerson = applyPerson;
    }
 
    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 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 String getReceiptNumber() {
        return receiptNumber;
    }
 
    public void setReceiptNumber(String receiptNumber) {
        this.receiptNumber = receiptNumber;
    }
 
 
    public OpeUseFlow getSelectOne() {
        return selectOne;
    }
 
    public void setSelectOne(OpeUseFlow selectOne) {
        this.selectOne = selectOne;
    }
 
 
    public List<PersonUseDetail> getPersonUseDetail() {
        return personUseDetail;
    }
 
    public void setPersonUseDetail(List<PersonUseDetail> personUseDetail) {
        this.personUseDetail = personUseDetail;
    }
 
    public Hashtable getPrintTable() {
        return printTable;
    }
 
    public void setPrintTable(Hashtable printTable) {
        this.printTable = printTable;
    }
 
    public String getReagentName() {
        return reagentName;
    }
 
    public void setReagentName(String reagentName) {
        this.reagentName = reagentName;
    }
}