kongzy
2023-10-11 374fb9d9369271b9b858e11a8612850ad3560936
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
package com.nanometer.smartlab.controller;
 
import java.text.SimpleDateFormat;
import java.util.*;
 
import javax.annotation.Resource;
 
import com.nanometer.smartlab.entity.SysUser;
import com.nanometer.smartlab.entity.dto.ApplyListDto;
import com.nanometer.smartlab.exception.BusinessException;
import com.nanometer.smartlab.service.SysUserService;
import com.nanometer.smartlab.util.FacesUtils;
import com.nanometer.smartlab.util.Utils;
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.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Controller;
 
import com.nanometer.smartlab.entity.OpeUseFlow;
import com.nanometer.smartlab.entity.SysReagent;
import com.nanometer.smartlab.service.OpeUseFlowService;
import com.nanometer.smartlab.service.SysReagentService;
 
@Controller
@Scope("session")
public class OpeUseFlowInfoController extends BaseController {
 
    /**
     *
     */
    private static final long serialVersionUID = -3727385333864550393L;
 
    private static Logger logger = Logger.getLogger(OpeUseFlowInfoController.class);
 
    private LazyDataModel<OpeUseFlow> dataModel;
 
    private String reagentId;
 
    private String reagentCode;
    private String houseName;
 
    private Date startDate;
 
    private Date endDate;
 
    private Hashtable printTable;
 
    private String containerCode;
 
    private String operatestate;
 
    public String getHouseName() {
        return houseName;
    }
 
    public void setHouseName(String houseName) {
        this.houseName = houseName;
    }
 
    @Value("${institute.name}")
    String instituteName;
 
    @Resource
    private OpeUseFlowService opeUseFlowService;
 
    @Resource
    private SysReagentService sysReagentService;
 
    @Resource
    private SysUserService sysUserService;
 
 
    private List<SysReagent> reagentSelectList;
 
    private OpeUseFlow selectedOne;
 
    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();
    }
 
    @SuppressWarnings("serial")
    public LazyDataModel<OpeUseFlow> getDataModel(){
        if (this.dataModel == null) {
            this.dataModel = 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.getOpeUseFlowTotalCountByName(houseName,reagentId, reagentCode, containerCode,null, getUserId(),startDate,endDate,operatestate);
                        this.setRowCount(count);
                        if (count > 0) {
                            list = opeUseFlowService.getOpeUseFlowListByName(houseName,reagentId, reagentCode, containerCode,null, getUserId(),startDate,endDate, first, pageSize,operatestate);
                        }
                        selectedOne = null;
                    } catch (Exception e) {
                        logger.error(e);
                    }
                    return list;
                }
 
                @Override
                public OpeUseFlow getRowData(String rowKey) {
//                    Iterator<OpeUseFlow> iterator = this.iterator();
//                    OpeUseFlow temp = null;
//                    if(iterator!= null)
//                    {
//                        while(iterator.hasNext())
//                        {
//                            temp=iterator.next();
//                            if(rowKey.equals(temp.getId()))
//                            {
//                                return temp;
//                            }
//                        }
//                    }
                    return opeUseFlowService.selectById(rowKey);
                }
            };
        }
 
        return dataModel;
    }
 
    public void export2Excel() {
 
        List<Map> list = opeUseFlowService.selectAll(houseName,reagentId, reagentCode, containerCode,getUserId(),startDate,endDate);
        try{
            boolean isexport = opeUseFlowService.export2Excel(list);
        }catch (Exception e){
            e.printStackTrace();
            FacesUtils.warn("导出失败");
        }
    }
 
    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 void generateRecipients(OpeUseFlow ouf) {
        String receiptNumber = ouf.getReceiptNumber();
        String code = ouf.getReagentCode();
        //id:个数
        Map<String, Integer> printInfo = opeUseFlowService.getRegentInfoFromReceiptNumber(receiptNumber);
        //无法得到当时的领用单的领用人,试剂状态表没有存入,userId会随时变化
        printTable = null;
        Integer sum = 0;
        printTable = new Hashtable();
        List<ApplyListDto> applyList = new ArrayList<>();
        //获取当时操作状态为领取的人员
        Map<String,String>  info= opeUseFlowService.getApplyUserByReagentCode(code);
        SysUser applyPersonInfo = sysUserService.getUser(info.get("user_id"));
        printTable.put("head", instituteName);
        printTable.put("title", "领用单");
        printTable.put("applyPerson", applyPersonInfo.getName());
        printTable.put("department", applyPersonInfo.getDepartment());
        String time = new SimpleDateFormat("yyyy-MM-dd").format(info.get("create_time"));
        printTable.put("date", time);
        if (StringUtils.isNotBlank(applyPersonInfo.getPhone())){
            printTable.put("phone", applyPersonInfo.getPhone());
        }
        if (StringUtils.isNotBlank(applyPersonInfo.getProject())){
            printTable.put("project", applyPersonInfo.getProject());
        }
 
        printTable.put("receiptNumber", receiptNumber);
        for (Map.Entry<String, Integer> map  : printInfo.entrySet()) {
            ApplyListDto lis = new ApplyListDto();
            Map reagentDetail = sysReagentService.getReagentDetail(map.getKey());
            lis.setNum(map.getValue().toString()); //数量
            lis.setMainMetering(String.format("%s%s", reagentDetail.get("main_metering"), reagentDetail.get("unit")));
            lis.setControlProducts((String) reagentDetail.get("controlProducts"));
            lis.setProductName((String) reagentDetail.get("name"));
            lis.setReagentFormat((String) reagentDetail.get("reagentFormat"));
            lis.setProductCode((String)reagentDetail.get("productCode"));
            lis.setMemo((String)reagentDetail.get("memo"));
            applyList.add(lis);
            sum += map.getValue();
        }
        applyList.add(new ApplyListDto("合计", "", "", "", "", String.valueOf(sum), ""));
        printTable.put("applyList", applyList);
 
    }
    public Date getStartDate() {
        if (null == startDate){
            Date now = new Date();
            Calendar cal = Calendar.getInstance();
            cal.setTime(now);
            cal.add(Calendar.DATE, -7);
            return cal.getTime();
        }else {
            return startDate;
        }
    }
 
    //报废试剂
    public void scrapReagent(){
        if (this.selectedOne == null) {
            FacesUtils.warn("请选择");
            return;
        }
        try {
            String reagentCode = this.selectedOne.getReagentCode();
            String reagentId = this.selectedOne.getReagent().getId();
            opeUseFlowService.scrapReagent(reagentId, reagentCode, getUserId());
            FacesUtils.warn("操作成功");
        } catch (BusinessException e) {
            FacesUtils.warn(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            FacesUtils.warn("操作失败");
        }
 
    }
 
    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }
 
    public Date getEndDate() {
        if (null == endDate){
            return new Date();
        }else {
            return endDate;
        }
    }
 
    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }
 
 
    public Hashtable getPrintTable() {
        return printTable;
    }
 
    public void setPrintTable(Hashtable printTable) {
        this.printTable = printTable;
    }
 
    public String getContainerCode() {
        return containerCode;
    }
 
    public void setContainerCode(String containerCode) {
        this.containerCode = containerCode;
    }
 
    public OpeUseFlow getSelectedOne() {
        return selectedOne;
    }
 
    public void setSelectedOne(OpeUseFlow selectedOne) {
        this.selectedOne = selectedOne;
    }
 
    public void setOperatestate(String operatestate) {
        this.operatestate = operatestate;
    }
 
    public String getOperatestate(){
        return operatestate;
    }
}