| | |
| | | import com.nanometer.smartlab.util.Constants; |
| | | import com.nanometer.smartlab.util.FacesUtils; |
| | | import com.nanometer.smartlab.util.IDUtils; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.apache.log4j.Logger; |
| | | import org.apache.poi.hssf.usermodel.HSSFRow; |
| | | import org.apache.poi.hssf.usermodel.HSSFSheet; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.faces.context.FacesContext; |
| | | import javax.faces.event.ActionListener; |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | |
| | | |
| | | |
| | | public void query(){ |
| | | System.out.println("start===================="); |
| | | List<SysReagent> list=this.sysReagentService.query(); |
| | | Map<String,SysReagent> map=new HashMap<>(); |
| | | List<SysReagent> list2 =new ArrayList<>(); |
| | |
| | | Sheet sheet=wb.getSheetAt(0); |
| | | List<SysReagent> sysReagentsList = new ArrayList<>(); |
| | | int totalRows = sheet.getPhysicalNumberOfRows(); |
| | | |
| | | Row row=null; |
| | | int totalCells=0; |
| | | String dangours = ""; |
| | | totalCells=sheet.getRow(0).getLastCellNum(); |
| | | if(totalCells>7){ |
| | | FacesUtils.warn("导入表格格式不正确"); |
| | | return; |
| | | } |
| | | for (int i = 1; i < totalRows; i++) { |
| | | SysReagent sysReagent = new SysReagent(); |
| | | List<String> valuesList=new ArrayList<String>(); |
| | | row=sheet.getRow(i); |
| | | |
| | | totalCells= row.getLastCellNum(); |
| | | // totalCells= row.getLastCellNum(); |
| | | // if(totalCells>7){ |
| | | // FacesUtils.warn("导入表格格式不正确"); |
| | | // return; |
| | | // } |
| | | for (int t = 0; t < totalCells; t++) { |
| | | String cellInfo=""; |
| | | String groupId = ""; |
| | |
| | | this.codeList.add(baseMeta); |
| | | } |
| | | valuesList.add(id); |
| | | }else if(t==5){ |
| | | String id=""; |
| | | if(!StringUtils.isBlank(cellInfo)){ |
| | | SysSupplier sysSupplier=sysSupplierService.getSysSupplierByName(cellInfo); |
| | | if(sysSupplier==null){//新建供应商 |
| | | FacesUtils.warn("未查询到供该应商信息-"+cellInfo); |
| | | return; |
| | | } |
| | | id=sysSupplier.getId(); |
| | | } |
| | | valuesList.add(id); |
| | | }else if(t==6){ |
| | | String id=""; |
| | | if(!StringUtils.isBlank(cellInfo)){ |
| | | groupId = "reagent_format"; |
| | | id=getId(groupId,cellInfo); |
| | | if(StringUtils.isBlank(id)){ |
| | | BaseMeta baseMeta = new BaseMeta(); |
| | | baseMeta.setId(IDUtils.uuid()); |
| | | baseMeta.setGroupId(groupId); |
| | | baseMeta.setMetaValue(cellInfo); |
| | | baseMeta.setMetaKey(cellInfo); |
| | | baseMetaService.insertBaseMeta(baseMeta); |
| | | id = baseMeta.getId(); |
| | | this.codeList.add(baseMeta); |
| | | } |
| | | } |
| | | valuesList.add(id); |
| | | }else { |
| | | valuesList.add(cellInfo); |
| | | } |
| | | |
| | | } |
| | | if (valuesList.size() != 8){ |
| | | FacesUtils.warn("excel数据解析格式失败"); |
| | | return; |
| | | } |
| | | System.out.println("value : "+valuesList); |
| | | sysReagent.setName(valuesList.get(0));//试剂名称 |
| | |
| | | if(!valuesList.get(5).equals("")){ |
| | | sysReagent.setPrice(BigDecimal.valueOf(Double.parseDouble(valuesList.get(5))));//含税单价 |
| | | } |
| | | if(StringUtils.isNotBlank(valuesList.get(6))){ |
| | | sysReagent.setSupplierId(valuesList.get(6));//供应商id |
| | | } |
| | | if(StringUtils.isNotBlank(valuesList.get(7))){ |
| | | sysReagent.setReagentFormat(valuesList.get(7));//规格id |
| | | } |
| | | DangerousFlag d; |
| | | d = DangerousFlag.NORMAL; |
| | | sysReagent.setDangerousFlag(d); |
| | |
| | | sysReagentsList.add(sysReagent); |
| | | } |
| | | sysReagentService.insertSysReagentList2(sysReagentsList); |
| | | System.out.println("=========导入结束====="); |
| | | FacesUtils.info("导入成功。"); |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | | FacesUtils.info("导入失败。"); |
| | | FacesUtils.info("导入失败,"+ex.getMessage()); |
| | | } |
| | | } |
| | | //导入 |
| | | public void uploadFile(FileUploadEvent event) { |
| | | System.out.println("=========导入开始====="); |
| | | this.codeList=baseMetaService.getAllBaseMeta(); |
| | | this.sysSupplierList=sysSupplierService.getSysSupplierList(); |
| | | try{ |
| | |
| | | }/*else if(t == 9){ |
| | | valuesList.add(sysSupplierService.getSysSupplierIdByname(cellInfo)); |
| | | }*/else{ |
| | | valuesList.add(cellInfo); |
| | | if(cellInfo!=null) |
| | | valuesList.add(cellInfo); |
| | | } |
| | | } |
| | | /* if (valuesList.size() != 13){ |
| | | break; |
| | | }*/ |
| | | |
| | | System.out.println("value : "+valuesList); |
| | | sysReagent.setProductSn(valuesList.get(0));//产品编号 |
| | | sysReagent.setName(valuesList.get(1));//试剂名称 |
| | | sysReagent.setControlProducts(valuesList.get(2));//管制品 |
| | |
| | | sysReagentsList.add(sysReagent); |
| | | } |
| | | sysReagentService.insertSysReagentList(sysReagentsList); |
| | | System.out.println("=========导入结束====="); |
| | | FacesUtils.info("导入成功。"); |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | |
| | | if (count > 0) { |
| | | list = sysReagentService.getSysReagentListNew(name, cas, supplierId,getType(), first, pageSize,productSn); |
| | | } |
| | | selectedList = new ArrayList<> (); |
| | | } catch (Exception e) { |
| | | logger.error(e); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public SysReagent getRowData(String rowKey) { |
| | | Iterator<SysReagent> iterator = this.iterator(); |
| | | if (iterator != null) { |
| | | SysReagent sr = null; |
| | | while (iterator.hasNext()) { |
| | | sr = iterator.next(); |
| | | if (rowKey.equals(sr.getId())) { |
| | | return sr; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | // Iterator<SysReagent> iterator = this.iterator(); |
| | | // if (iterator != null) { |
| | | // SysReagent sr = null; |
| | | // while (iterator.hasNext()) { |
| | | // sr = iterator.next(); |
| | | // if (rowKey.equals(sr.getId())) { |
| | | // return sr; |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | return sysReagentService.getSysReagent(rowKey); |
| | | } |
| | | }; |
| | | } |
| | | |
| | | return dataModel; |
| | | } |
| | | |
| | | public void export2Excel() { |
| | | |
| | | List<Map> list = sysReagentService.selectAll(name, cas, supplierId,getType(), productSn); |
| | | try{ |
| | | boolean isexport = sysReagentService.export2Excel(list,getType()); |
| | | if (isexport){ |
| | | |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | FacesUtils.warn("导出失败"); |
| | | } |
| | | } |
| | | |
| | | public SysReagent getSysReagent() { |
| | |
| | | public void setProductSn(String productSn) { |
| | | this.productSn = productSn; |
| | | } |
| | | |
| | | public void openUpdateSafetyNumDialog() { |
| | | if (this.selectedList == null |
| | | || this.selectedList.size() == 0) { |
| | | FacesUtils.warn("请选择数据。"); |
| | | return; |
| | | } |
| | | if (this.selectedList.size() > 1) { |
| | | FacesUtils.warn("只能选择一个数据进行修改。"); |
| | | return; |
| | | } |
| | | this.sysReagent = this.sysReagentService.getSysReagent(this.selectedList.get(0).getId()); |
| | | if (this.sysReagent.getType() != 1) { |
| | | FacesUtils.warn("只能选择试剂设置安全库存。"); |
| | | return; |
| | | } |
| | | RequestContext.getCurrentInstance().execute("PF('dialog-setSafetynum').show()"); |
| | | } |
| | | |
| | | public void updateSafetyNum(){ |
| | | if (this.sysReagent.getSafetynum() == null) { |
| | | FacesUtils.warn("请输入安全库存。"); |
| | | return; |
| | | } |
| | | sysReagentService.updateSafetyNum(this.sysReagent); |
| | | FacesUtils.warn("修改成功。"); |
| | | RequestContext.getCurrentInstance().execute("PF('dialog-setSafetynum').hide()"); |
| | | |
| | | } |
| | | } |