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 reagentStatusDataModel; /** * 使用记录用 */ private LazyDataModel reagentStoreDataModel; private Long reagentId; private List reagentSelectList; private List selectedStoreList; private List laboratoryContainers; private String reagentCode; private String labName; /** * 数据模型 */ private Long laboratoryId; private Long 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 getReagentStatusDataModel() { if (this.reagentStatusDataModel == null) { this.reagentStatusDataModel = new LazyDataModel() { @Override public List load(int first, int pageSize, String sortField, SortOrder sortOrder, Map filters) { List list = null; System.out.println(reagentId); try { int count = opeReagentStatusService.getOpeReagentStatusTotalCountForLab(reagentId,null, null, ArrivalStatus.LABORATORY.getKey(), reagentCode, getUserId(),labName); this.setRowCount(count); if (count > 0) { list = opeReagentStatusService.getOpeReagentStatusListForLab(reagentId,null, null, ArrivalStatus.LABORATORY.getKey(), reagentCode, getUserId(),labName, first, pageSize); } } catch (Exception e) { logger.error(e); } return list; } @Override public OpeReagentStatus getRowData(String rowKey) { // Iterator 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 getReagentStoreDataModel() { if (this.reagentStoreDataModel == null) { this.reagentStoreDataModel = new LazyDataModel() { @Override public List load(int first, int pageSize, String sortField, SortOrder sortOrder, Map filters) { List 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); } selectedStoreList = null; return list; } @Override public OpeReagentStatus getRowData(String rowKey) { // Iterator iterator = this.iterator(); // if (iterator != null) { // OpeReagentStatus su = null; // while (iterator.hasNext()) { // su = iterator.next(); // if (rowKey.equals(su.getId())) { // return su; // } // } // } Long id=Long.valueOf(rowKey); return opeReagentStatusService.getOpeReagentStatusById(id); } }; } return reagentStoreDataModel; } public void exportLabStock() { try { List list = opeReagentStatusService.selectExportList(null, 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 getReagentSelectList() { if (this.reagentSelectList == null) { this.initReagentSelectList(); } return reagentSelectList; } public void setReagentSelectList(List reagentSelectList) { this.reagentSelectList = reagentSelectList; } public Long getReagentId() { return reagentId; } public void setReagentId(Long reagentId) { this.reagentId = reagentId; } public String getReagentCode() { return reagentCode; } public void setReagentCode(String reagentCode) { this.reagentCode = reagentCode; } public Long getLaboratoryId() { return laboratoryId; } public void setLaboratoryId(Long laboratoryId) { this.laboratoryId = laboratoryId; } public Long getLaboratoryContainerId() { return laboratoryContainerId; } public void setLaboratoryContainerId(Long laboratoryContainerId) { this.laboratoryContainerId = laboratoryContainerId; } public void onCancelBtnClick() { this.menuController.backToPage(); } // 现在试剂柜多了操作状态字段, // 实验室临时存放的操作状态无法判断 // 是试剂柜入库,还是错误入库 // 暂定是试剂柜入库 public void onSaveBtnClick() { if (laboratoryId==null) { FacesUtils.warn("请选择实验室。"); return; } if (laboratoryContainerId==null) { FacesUtils.warn("请选择临时存储库。"); return; } if (this.selectedStoreList == null || this.selectedStoreList.size() == 0) { FacesUtils.warn("请选择试剂。"); return; } for (OpeReagentStatus opeReagentStatus : selectedStoreList) { if (opeReagentStatus.getStatus() != ArrivalStatus.PERSONAL.getKey()) { FacesUtils.warn("只能存放个人领用中的试剂。"); return; } } this.opeReagentStatusService.store(selectedStoreList, laboratoryId, laboratoryContainerId); FacesUtils.info("存放成功。"); } public List getSelectedStoreList() { return selectedStoreList; } public void setSelectedStoreList(List 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 getLaboratoryContainers() { return laboratoryContainers; } public void setLaboratoryContainers(List laboratoryContainers) { this.laboratoryContainers = laboratoryContainers; } public String getLabName() { return labName; } public void setLabName(String labName) { this.labName = labName; } }