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
package com.nanometer.smartlab.controller;
 
import com.nanometer.smartlab.dao.SysProjectDao;
import com.nanometer.smartlab.entity.OpeApply;
import com.nanometer.smartlab.entity.OpeOrder;
import com.nanometer.smartlab.entity.SysProject;
import com.nanometer.smartlab.entity.enumtype.ApplyStatus;
import com.nanometer.smartlab.service.OpeApplyService;
import com.nanometer.smartlab.service.OpeOrderService;
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.math.BigDecimal;
import java.sql.Timestamp;
import java.util.*;
 
/**
 * Created by johnny on 17/12/14.
 */
@Controller
@Scope("session")
public class RequireMngController extends BaseController {
 
    private static Logger logger = Logger.getLogger(RequireMngController.class);
 
    @Resource
    private OpeApplyService opeApplyService;
    @Resource
    private MenuController menuController;
    @Resource
    private OpeOrderService opeOrderService;
    @Resource
    private SysProjectDao sysProjectDao;
 
    private LazyDataModel<OpeApply> dataModel;
    private LazyDataModel<OpeApply> supplerRequireMngDataModel;
    private OpeOrder opeOrder;
    private List<OpeApply> selectedList;
    private String reagentName;
    private Timestamp startDeadline;
    private Timestamp endDeadline;
    private OpeApply opeApply;
 
    public void onNewBtnClick() {
        if (selectedList == null
                || selectedList.size() == 0) {
            FacesUtils.warn("请选择数据。");
            return;
        }
 
        Set<Long> results = new HashSet<>();
        for(OpeApply item : selectedList)
        {
                results.add(item.getReagent().getSupplierId());
        }
        if(results.size() > 1)
        {
                FacesUtils.warn("请选择试剂供应商一样的数据。");
            return;
        }
 
        this.opeOrder = new OpeOrder();
        this.menuController.goToPage(Constants.PAGE_REQUIRE_MNG_NEW, Constants.PAGE_REQUIRE_MNG);
    }
 
    public void onCancelApplyClick(){
        if (this.selectedList == null
                || this.selectedList.size() == 0) {
            FacesUtils.warn("请选择数据。");
            return;
        }
 
 
        try {
            for (OpeApply ope:this.selectedList) {
                this.opeApplyService.cancelApply(ApplyStatus.CANCEL,ope.getId());
            }
            FacesUtils.info("取消成功。");
        }catch(Exception e){
            logger.error("操作失败。", e);
            FacesUtils.warn("操作失败。");
        }
    }
    public void onViewBtnClick() {
        if (this.selectedList == null
                || this.selectedList.size() == 0) {
            FacesUtils.warn("请选择数据。");
            return;
        }
        if (this.selectedList.size() > 1) {
            FacesUtils.warn("只能选择一个数据进行查看。");
            return;
        }
 
        this.opeApply = this.opeApplyService.getOpeApply(this.selectedList.get(0).getId());
        RequestContext.getCurrentInstance().execute("PF('dialog').show()");
    }
 
    public void onCancelBtnClick() {
        this.menuController.backToPage();
    }
 
    public void onSaveBtnClick() {
        try {
            if (this.opeOrder == null) {
                FacesUtils.warn("订单数据为空。");
                return;
            }
 
            if (this.selectedList == null
                    || this.selectedList.size() == 0) {
                FacesUtils.warn("申购数据为空。");
                return;
            }
 
            //判断所有供应商是不是同一个
            //Set<String> supplierIdCheckSet = new HashSet<>();
            //for (OpeApply opeApply : this.selectedList) {
               // supplierIdCheckSet.add(opeApply.getReagent().getSupplierId());
            //}
 
            //if (supplierIdCheckSet.size() > 1) {
               // FacesUtils.warn("选择的供应商不为同一个供应商,订单生产失败!");
                //return;
            //}
 
            this.opeOrderService.createOpeOrder(this.opeOrder, this.selectedList, this.getUser());
 
            FacesUtils.info("生成订单成功。");
            this.menuController.backToPage();
        } catch (Exception e) {
            logger.error("操作失败。", e);
            FacesUtils.warn("操作失败,message="+e.getMessage());
        }
    }
 
    public LazyDataModel<OpeApply> getDataModel() {
        if (this.dataModel == null) {
            this.dataModel = new LazyDataModel<OpeApply>() {
                @Override
                public List<OpeApply> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
                    List<OpeApply> list = null;
                    try {
                        int count = opeApplyService.getOpeApplyTotalCount(reagentName, startDeadline,null, endDeadline, ApplyStatus.APPROVED.getKey(), null, null, null,null,null,(byte)1);
                        this.setRowCount(count);
                        if (count > 0) {
                            list = opeApplyService.getOpeApplyList(reagentName, startDeadline,null, endDeadline, ApplyStatus.APPROVED.getKey(), null, null, null, first, pageSize,null,null,(byte)1);
                        }
                    } catch (Exception e) {
                        logger.error(e);
                    }
                    selectedList = null;
                    return list;
                }
 
                @Override
                public OpeApply getRowData(String rowKey) {
                    Iterator<OpeApply> iterator = this.iterator();
//                    if (iterator != null) {
//                        OpeApply oa = null;
//                        while (iterator.hasNext()) {
//                            oa = iterator.next();
//                            if (rowKey.equals(oa.getId())) {
//                                return oa;
//                            }
//                        }
//                    }
                    Long id=Long.valueOf(rowKey);
                    return opeApplyService.getOpeApply(id);
                }
            };
        }
        return dataModel;
    }
 
    public LazyDataModel<OpeApply> getSupplerRequireMngDataModel() {
        return new LazyDataModel<OpeApply>() {
            @Override
            public List<OpeApply> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
                List<OpeApply> list = null;
                try {
                    int count = opeApplyService.getOpeApplySupplerRequireMngTotalCount(getUser(),reagentName, startDeadline, endDeadline, ApplyStatus.APPROVED.getKey(),(byte)1);
                    this.setRowCount(count);
                    if (count > 0) {
                        list = opeApplyService.getOpeApplySupplerRequireMngList(getUser(),reagentName, startDeadline, endDeadline, ApplyStatus.APPROVED.getKey(), first, pageSize,(byte)1);
                    }
                } catch (Exception e) {
                    logger.error(e);
                }
                selectedList = null;
                return list;
            }
 
            @Override
            public OpeApply getRowData(String rowKey) {
                Long id=Long.valueOf(rowKey);
                return opeApplyService.getOpeApply(id);
            }
        };
    }
 
    public String getProjectName(Long projectId){
        if(projectId==null){
            return "";
        }
        SysProject project= this.sysProjectDao.getSysProject(projectId);
        return project!=null?project.getProjectName():"";
    }
 
    public OpeOrder getOpeOrder() {
        return opeOrder;
    }
 
    public void setOpeOrder(OpeOrder opeOrder) {
        this.opeOrder = opeOrder;
    }
 
    public List<OpeApply> getSelectedList() {
        return selectedList;
    }
 
    public void setSelectedList(List<OpeApply> selectedList) {
        this.selectedList = selectedList;
    }
 
    public String getReagentName() {
        return reagentName;
    }
 
    public void setReagentName(String reagentName) {
        this.reagentName = reagentName;
    }
 
    public Timestamp getStartDeadline() {
        return startDeadline;
    }
 
    public void setStartDeadline(Timestamp startDeadline) {
        this.startDeadline = startDeadline;
    }
 
    public Timestamp getEndDeadline() {
        return endDeadline;
    }
 
    public void setEndDeadline(Timestamp endDeadline) {
        this.endDeadline = endDeadline;
    }
 
    public OpeApply getOpeApply() {
        return opeApply;
    }
 
    public void setOpeApply(OpeApply opeApply) {
        this.opeApply = opeApply;
    }
 
    public BigDecimal calTotal(OpeApply opeApply) {
        if (opeApply != null
                && opeApply.getReagent() != null) {
            BigDecimal count = new BigDecimal(0);
            BigDecimal price = new BigDecimal(0);
 
            if (opeApply.getNum() != null && opeApply.getNum() != 0) {
                count = new BigDecimal(opeApply.getNum());
            }
            if (opeApply.getReagent().getPrice() != null) {
                price = opeApply.getReagent().getPrice();
            }
 
            return count.multiply(price);
        }
 
        return new BigDecimal(0);
    }
 
    public BigDecimal calTotalList(List<OpeApply> opeApplyList) {
        BigDecimal total = new BigDecimal(0);
        if (opeApplyList != null && opeApplyList.size() > 0) {
            for (OpeApply apply : opeApplyList) {
                total = total.add(this.calTotal(apply));
            }
        }
 
        return total;
    }
}