kongzy
2024-07-01 47a751cb301d05276ae5d75145d57b2d090fe4e1
src/main/java/com/nanometer/smartlab/controller/ApplyMngController.java
@@ -5,6 +5,8 @@
import com.nanometer.smartlab.entity.SysReagent;
import com.nanometer.smartlab.entity.SysUser;
import com.nanometer.smartlab.entity.enumtype.ApplyStatus;
import com.nanometer.smartlab.entity.enumtype.ValidFlag;
import com.nanometer.smartlab.exception.BusinessException;
import com.nanometer.smartlab.service.*;
import com.nanometer.smartlab.util.Constants;
import com.nanometer.smartlab.util.FacesUtils;
@@ -15,6 +17,7 @@
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.primefaces.context.RequestContext;
import org.primefaces.event.FileUploadEvent;
import org.primefaces.event.SelectEvent;
import org.primefaces.event.TabChangeEvent;
import org.primefaces.model.LazyDataModel;
@@ -71,6 +74,8 @@
    private Integer status;
    private Integer favor;
    private List<ApplyStatus> statusSelectList;
    private String controlProduct;
    private LazyDataModel<SysReagent> reagentDataModel;
    private LazyDataModel<SysReagent> reagentFavorDataModel;
@@ -116,7 +121,7 @@
    }
    private List<SysUser> approveUserSelectList;
    private SysReagent sysReagent;
    private SysReagent sysReagent=new SysReagent();
    private LazyDataModel<OpeApply> applyHistoryDataModel;
@@ -138,7 +143,7 @@
    }
    public void initApproveUserSelectList() {
        this.approveUserSelectList = this.sysUserService.getHasProjectSysUserList(this.getUserDepartment());
        this.approveUserSelectList = this.sysUserService.getHasProjectSysUserList(this.getUserDepartment(),this.getUserProject());
        if (!CollectionUtils.isEmpty(this.approveUserSelectList)){
            if(this.selectedList == null){
                this.sysProjectList = sysProjectService.getSysProjectList(this.approveUserSelectList.get(0).getId());
@@ -237,7 +242,7 @@
            if(selectedList!=null&&selectedList.size()>0){
                realDataList=selectedList;
            }else {
                realDataList=opeApplyService.getOpeApplyList(reagentName, startDeadline, endDeadline, status, getUserId(), null, queryCAS, null, null,null,applyUserName);
                realDataList=opeApplyService.getOpeApplyList(reagentName, startDeadline,controlProduct, endDeadline, status, getUserId(), null, queryCAS, null, null,null,applyUserName,(byte)1);
            }
             List<String> headerList = new ArrayList<>();
@@ -250,15 +255,19 @@
            headerList.add("含税售价");
            headerList.add("CAS号");
            headerList.add("危险性质");
            headerList.add("供应商");
            headerList.add("厂家");
            headerList.add("试剂类型");
            headerList.add("申购数量");
            headerList.add("申购人");
            headerList.add("申购人课题组");
            headerList.add("申购人部门");
            headerList.add("申购日期");
            headerList.add("一级审批者");
            headerList.add("二级审批者");
            headerList.add("订单状态");
            headerList.add("审批批注");
            HSSFWorkbook hssfWorkbook =exportExcelNew(headerList, realDataList);
            hssfWorkbook.write(out);
            out.flush();
@@ -297,6 +306,22 @@
        }
    }
    public void uploadApply(FileUploadEvent event){
        try {
            opeApplyService.importApply(event, getUser());
            FacesUtils.info("导入成功");
        } catch (BusinessException e) {
            FacesUtils.warn(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            FacesUtils.warn("导入失败,请联系管理员");
        }
    }
    public  HSSFWorkbook exportExcelNew(List<String> headerList, List<OpeApply> dataList) {
        HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
@@ -308,31 +333,37 @@
            titlerRow.createCell(i).setCellValue(headerList.get(i));
        }
        for (int i = 0; i < dataList.size(); i++) {
            System.out.println(dataList.get(i));
            HSSFRow dataRow = sheet.createRow(i + 1);
            dataRow.createCell(0).setCellValue(dataList.get(i).getApplyCode()== null ? "": String.valueOf(dataList.get(i).getApplyCode()));
            dataRow.createCell(1).setCellValue(dataList.get(i).getReagent().getProductSn()== null ? "": String.valueOf(dataList.get(i).getReagent().getProductSn()));
            dataRow.createCell(2).setCellValue(dataList.get(i).getReagent().getName()== null ? "": String.valueOf(dataList.get(i).getReagent().getName()));
            dataRow.createCell(3).setCellValue(dataList.get(i).getReagent().getControlProducts()== null ? "": String.valueOf(baseMetaService.getBaseMetaValue(dataList.get(i).getReagent().getControlProducts())));
            dataRow.createCell(4).setCellValue(dataList.get(i).getReagent().getReagentFormat()== null ? "": String.valueOf(baseMetaService.getBaseMetaValue(dataList.get(i).getReagent().getReagentFormat())));
            dataRow.createCell(5).setCellValue(dataList.get(i).getReagent().getMainMetering()== null ? "": String.valueOf(dataList.get(i).getReagent().getMainMetering())+baseMetaService.getBaseMetaValue(dataList.get(i).getReagent().getReagentUnit()));
            dataRow.createCell(3).setCellValue(dataList.get(i).getReagent().getControlProducts()== null ? "": String.valueOf(dataList.get(i).getReagent().getControlProducts()));
            dataRow.createCell(4).setCellValue(dataList.get(i).getReagent().getReagentFormat()== null ? "": String.valueOf(dataList.get(i).getReagent().getReagentFormat()));
            dataRow.createCell(5).setCellValue(dataList.get(i).getReagent().getMainMetering()== null ? "": String.valueOf(dataList.get(i).getReagent().getMainMetering())+dataList.get(i).getReagent().getReagentUnit());
            dataRow.createCell(6).setCellValue(dataList.get(i).getReagent().getPrice()== null ? "": String.valueOf(dataList.get(i).getReagent().getPrice()));
            dataRow.createCell(7).setCellValue(dataList.get(i).getReagent().getCas()== null ? "": String.valueOf(dataList.get(i).getReagent().getCas()));
            dataRow.createCell(8).setCellValue(dataList.get(i).getReagent().getReagentCharacter()== null ? "": String.valueOf(baseMetaService.getBaseMetaValue(dataList.get(i).getReagent().getReagentCharacter())));
            dataRow.createCell(9).setCellValue(dataList.get(i).getReagent().getProductHomeName()== null ? "": String.valueOf(dataList.get(i).getReagent().getProductHomeName()));
            dataRow.createCell(10).setCellValue(dataList.get(i).getReagent().getReagentType()== null ? "": String.valueOf(baseMetaService.getBaseMetaValue(dataList.get(i).getReagent().getReagentType())));
            dataRow.createCell(11).setCellValue(String.valueOf(dataList.get(i).getNum()));
            dataRow.createCell(12).setCellValue(String.valueOf(dataList.get(i).getApplyUserName()));
            dataRow.createCell(13).setCellValue(String.valueOf(dataList.get(i).getCreateTime()));
            dataRow.createCell(8).setCellValue(dataList.get(i).getReagent().getReagentCharacter()== null ? "": String.valueOf(dataList.get(i).getReagent().getReagentCharacter()));
            dataRow.createCell(9).setCellValue(dataList.get(i).getReagent().getSupplierName()== null ? "": String.valueOf(dataList.get(i).getReagent().getSupplierName()));
            dataRow.createCell(10).setCellValue(dataList.get(i).getReagent().getProductHome()== null ? "": String.valueOf(dataList.get(i).getReagent().getProductHome()));
            dataRow.createCell(11).setCellValue(dataList.get(i).getReagent().getReagentType()== null ? "": String.valueOf(dataList.get(i).getReagent().getReagentType()));
            dataRow.createCell(12).setCellValue(String.valueOf(dataList.get(i).getNum()));
            dataRow.createCell(13).setCellValue(String.valueOf(dataList.get(i).getApplyUserName()));
            dataRow.createCell(14).setCellValue(dataList.get(i).getApplyUserProject() == null?"":String.valueOf(dataList.get(i).getApplyUserProject()));
            dataRow.createCell(15).setCellValue(dataList.get(i).getApplyUserDepartment() == null?"":String.valueOf(dataList.get(i).getApplyUserDepartment()));
            dataRow.createCell(16).setCellValue(String.valueOf(dataList.get(i).getCreateTime()));
           // SysUser u=sysUserService.getSysUser(dataList.get(i).getApproveUserId());
            dataRow.createCell(14).setCellValue(String.valueOf(dataList.get(i).getFirName()));
            if(dataList.get(i).getBeforeApproveUserId()!=null && !dataList.get(i).getBeforeApproveUserId().equals("")){
            dataRow.createCell(17).setCellValue(String.valueOf(dataList.get(i).getFirName()));
            if(dataList.get(i).getBeforeApproveUserId()!=null){
                //u=sysUserService.getSysUser(dataList.get(i).getBeforeApproveUserId());
                dataRow.createCell(15).setCellValue(String.valueOf(dataList.get(i).getApproveUserName()));
                dataRow.createCell(18).setCellValue(String.valueOf(dataList.get(i).getApproveUserName()));
            }
            //dataRow.createCell(14).setCellValue(String.valueOf(u.getName()));
            dataRow.createCell(16).setCellValue(String.valueOf(dataList.get(i).getStatus().getText()));
            dataRow.createCell(17).setCellValue(dataList.get(i).getMemo()==null ?"":String.valueOf(dataList.get(i).getMemo()));
            dataRow.createCell(19).setCellValue(String.valueOf(dataList.get(i).getStatus().getText()));
            dataRow.createCell(20).setCellValue(dataList.get(i).getMemo()==null ?"":String.valueOf(dataList.get(i).getMemo()));
        }
        return hssfWorkbook;
@@ -381,7 +412,7 @@
                    return;
                }
                if (this.opeApply.getReagent() == null
                        || StringUtils.isBlank(this.opeApply.getReagent().getId())) {
                        || this.opeApply.getReagent().getId()!=null) {
                    FacesUtils.warn("请选择申购产品。");
                    return;
                }
@@ -394,8 +425,13 @@
                this.opeApply.setApplyCode(this.sysSequenceService.getApplyCode());
                this.opeApply.setApplyUserId(applyUser.getId());
                this.opeApply.setStatus(ApplyStatus.PENDING_APPROVAL);
                //this.opeApply.setStatus(ApplyStatus.PENDING_APPROVAL);
                this.opeApplyService.insertOpeApply(this.opeApply);
                if(getActiveEnv().equalsIgnoreCase("gslab")){//姑苏实验室先进入待审批状态,然后再进入价格确认状态
                    this.opeApply.setStatus(ApplyStatus.PENDING_APPROVAL);
                }else{
                    this.opeApply.setStatus(ApplyStatus.Price_CONFIRM);
                }
                FacesUtils.info("新建成功。");
                this.menuController.backToPage();
@@ -405,7 +441,7 @@
                    return;
                }
                if (this.opeApply.getReagent() == null
                        || StringUtils.isBlank(this.opeApply.getReagent().getId())) {
                        || this.opeApply.getReagent().getId()!=null) {
                    FacesUtils.warn("请选择申购产品。");
                    return;
                }
@@ -444,8 +480,6 @@
                FacesUtils.warn("新建对象为空。");
                return;
            }
            this.sysReagent.setId(IDUtils.uuid());
            this.sysReagentService.insertSysReagent(this.sysReagent);
            FacesUtils.info("新建成功。");
@@ -483,10 +517,10 @@
                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, endDeadline, status, getUserId(), null, queryCAS,null,applyUserName);
                        int count = opeApplyService.getOpeApplyTotalCount(reagentName, startDeadline,controlProduct, endDeadline, status, getUserId(), null, queryCAS,null,applyUserName,(byte)1);
                        this.setRowCount(count);
                        if (count > 0) {
                            list = opeApplyService.getOpeApplyList(reagentName, startDeadline, endDeadline, status, getUserId(), null, queryCAS, first, pageSize,null,applyUserName);
                            list = opeApplyService.getOpeApplyList(reagentName, startDeadline,controlProduct, endDeadline, status, getUserId(), null, queryCAS, first, pageSize,null,applyUserName,(byte)1);
                            for(int i=0;i<list.size();i++){
                                if(list.get(i).getBeforeApproveUserId()!=null&&!list.get(i).getBeforeApproveUserId().equals("")){
                                    String name=list.get(i).getApproveUserName();
@@ -501,22 +535,24 @@
                    } 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;
                            }
                        }
                    }
                    return null;
//                    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);
                }
            };
        }
@@ -544,17 +580,18 @@
                @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;
//                            }
//                        }
//                    }
                    Long id=Long.valueOf(rowKey);
                    return sysReagentService.getRowData(id);
                }
            };
        }
@@ -583,17 +620,18 @@
                @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;
//                            }
//                        }
//                    }
                    Long id=Long.valueOf(rowKey);
                    return sysReagentService.getRowData(id);
                }
            };
        }
@@ -608,15 +646,16 @@
                public List<OpeApply> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
                    List<OpeApply> list = null;
                    try {
                        String applyUserId = getUserId();
                        Long applyUserId = getUserId();
                        int count = 0;
                        if (StringUtils.isNotBlank(applyUserId)) {
                            count = opeApplyService.getOpeApplyTotalCount(null, null, null, null, applyUserId, null, null,applyCode,null);
                        if (applyUserId!=null) {
                            count = opeApplyService.getOpeApplyTotalCount(null, null, null,null, null, applyUserId, null, null,applyCode,null,(byte)1);
                        }
                        this.setRowCount(count);
                        if (count > 0) {
                            list = opeApplyService.getOpeApplyList(null, null, null, null, applyUserId, null, null, first, pageSize,applyCode,null);
                            list = opeApplyService.getOpeApplyList(null, null,null, null, null, applyUserId, null, null, first, pageSize,applyCode,null,(byte)1);
                        }
                        selectedList = null;
                    } catch (Exception e) {
                        logger.error(e);
                    }
@@ -625,17 +664,18 @@
                @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;
                            }
                        }
                    }
                    return null;
//                    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);
                }
            };
        }
@@ -681,7 +721,7 @@
            return;
        }
        List<String> selectedIds = new ArrayList<String>();
        List<Long> selectedIds = new ArrayList<Long>();
        for (OpeApply oa : this.applyNewSelectedList) {
            selectedIds.add(oa.getReagent().getId());
@@ -720,14 +760,23 @@
                return;
            }
            //申请一个申购编号
            String applyCode = this.sysSequenceService.getApplyCode();
            for (OpeApply opeApply : this.applyNewList) {
                opeApply.setId(IDUtils.uuid());
                if (opeApply.getReagent().getValidFlag() == null
                        ||opeApply.getReagent().getValidFlag().equals(ValidFlag.INVALID)){
                    FacesUtils.warn(opeApply.getReagent().getName()+",该试剂已删除,请选择其他试剂");
                    return;
                }
                if (opeApply.getReagent().getType() == 1
                        && (opeApply.getReagent().getSupplierFlag() == null
                        || opeApply.getReagent().getSupplierFlag().equals(ValidFlag.INVALID))){
                    FacesUtils.warn(opeApply.getReagent().getName()+",该试剂供应商已删除,请选择其他试剂");
                    return;
                }
                //申请一个申购编号
                String applyCode = this.sysSequenceService.getApplyCode();
                opeApply.setApplyCode(applyCode);
                opeApply.setApplyUserId(applyUser.getId());
                opeApply.setStatus(ApplyStatus.PENDING_APPROVAL);
                opeApply.setStatus(ApplyStatus.Price_CONFIRM);
            }
            this.opeApplyService.insertOpeApplyList(this.applyNewList);
@@ -755,7 +804,7 @@
    public void onSaveBtnClickNew() {
        if (this.opeApply.getReagent() == null
                || StringUtils.isBlank(this.opeApply.getReagent().getId())) {
                || this.opeApply.getReagent().getId()==null) {
            FacesUtils.warn("请选择申购产品。");
            RequestContext.getCurrentInstance().execute("PF('applyDialog').hide()");
            return;
@@ -816,10 +865,21 @@
        return "";
    }
    public String getProjectName(String projectId) {
//    public String getProjectName(String projectId) {
//        String projectName = null;
//        if (!CollectionUtils.isEmpty(this.sysProjectList)) {
//            Optional<SysProject> first = this.sysProjectList.parallelStream().filter(sysProject -> StringUtils.isNotBlank(projectId) && StringUtils.isNotBlank(sysProject.getProjectId()) && projectId.equals(sysProject.getProjectId())).findFirst();
//            if (first.isPresent()) {
//                projectName = first.get().getProjectName();
//            }
//        }
//        return projectName;
//    }
    public String getProjectName(Long projectId) {
        String projectName = null;
        if (!CollectionUtils.isEmpty(this.sysProjectList)) {
            Optional<SysProject> first = this.sysProjectList.parallelStream().filter(sysProject -> StringUtils.isNotBlank(projectId) && StringUtils.isNotBlank(sysProject.getProjectId()) && projectId.equals(sysProject.getProjectId())).findFirst();
            Optional<SysProject> first = this.sysProjectList.parallelStream().filter(sysProject -> projectId!=null && sysProject.getId()!=null && projectId.equals(sysProject.getId())).findFirst();
            if (first.isPresent()) {
                projectName = first.get().getProjectName();
            }
@@ -973,4 +1033,12 @@
    public void setTabValue(int tabValue) {
        this.tabValue = tabValue;
    }
    public String getControlProduct() {
        return controlProduct;
    }
    public void setControlProduct(String controlProduct) {
        this.controlProduct = controlProduct;
    }
}