| | |
| | | package com.nanometer.smartlab.controller; |
| | | |
| | | import java.util.Date; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | 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.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.stereotype.Controller; |
| | | |
| | |
| | | |
| | | @Resource |
| | | private SysReagentService sysReagentService; |
| | | @Resource |
| | | private SysLaboratoryService sysLaboratoryService; |
| | | @Value("${institute.name}") |
| | | String instituteName; |
| | | |
| | | /** |
| | | * 数据源 |
| | | */ |
| | | private LazyDataModel<OpeReagentStatus> dataModel; |
| | | private String reagentId; |
| | | private Long 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 void reagentReturn(){ |
| | | |
| | | try { |
| | | List<OpeReagentStatus> list=this.selectedList; |
| | | opeReagentStatusService.batchUpdateStatusByCode(list); |
| | | 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.getKey()); |
| | | 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", StringUtils.isBlank(selectOne.getPhone())?"":selectOne.getPhone()); |
| | | printTable.put("receiptNumber", selectOne.getReceiptNumber()); |
| | | printTable.put("project", selectOne.getProjectName()); |
| | | |
| | | SysLaboratory sysLaboratory = sysLaboratoryService.getSysLaboratorySimpleInfo(selectOne.getHouseId()); |
| | | printTable.put("lab", sysLaboratory.getName()); |
| | | printTable.put("note",selectOne.getNote() == null?"":selectOne.getNote()); |
| | | //整理数据 |
| | | 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()); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * @Description: 导出详情 |
| | | */ |
| | | public void exportDetail() throws Exception { |
| | | try { |
| | | if (startTime == null || endTime == null){ FacesUtils.warn("请选择日期范围");return;} |
| | | |
| | | List<Map> list = opeUseFlowService.selectExportDetail(reagentCode, getUserId(), startTime, endTime, receiptNumber, department, project, applyPerson, reagentName); |
| | | if (list == null || list.size() < 1) {FacesUtils.warn("没有数据导出");return;} |
| | | opeUseFlowService.export22Excel(list); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | FacesUtils.warn("导出失败"); |
| | | } |
| | | |
| | | } |
| | | |
| | | @SuppressWarnings("serial") |
| | | public LazyDataModel<OpeReagentStatus> getDataModel() { |
| | |
| | | return dataModel; |
| | | } |
| | | |
| | | public String getReagentId() { |
| | | 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); |
| | | } |
| | | selectOne = null; |
| | | } 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 opeUseFlowService.selectByReceiptNumber(rowKey,getUserId()); |
| | | } |
| | | }; |
| | | } |
| | | return dataModel2; |
| | | } |
| | | |
| | | public Long getReagentId() { |
| | | return reagentId; |
| | | } |
| | | |
| | | public void setReagentId(String reagentId) { |
| | | public void setReagentId(Long reagentId) { |
| | | this.reagentId = reagentId; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | public Date getStartTime() { |
| | | return startTime; |
| | | if (null == startTime){ |
| | | Date now = new Date(); |
| | | Calendar cal = Calendar.getInstance(); |
| | | cal.setTime(now); |
| | | cal.add(Calendar.DATE, -7); |
| | | return cal.getTime(); |
| | | }else { |
| | | return startTime; |
| | | } |
| | | } |
| | | |
| | | public void setStartTime(Date startTime) { |
| | | this.startTime = startTime; |
| | | } |
| | | |
| | | |
| | | public Date getEndTime() { |
| | | return endTime; |
| | | if (null == endTime){ |
| | | return new Date(); |
| | | }else { |
| | | 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; |
| | | } |
| | | } |