对比新文件 |
| | |
| | | package com.nanometer.smartlab.controller; |
| | | |
| | | import com.nanometer.smartlab.entity.OpeApply; |
| | | import com.nanometer.smartlab.entity.SysProject; |
| | | import com.nanometer.smartlab.entity.SysUser; |
| | | import com.nanometer.smartlab.entity.enumtype.ApplyStatus; |
| | | import com.nanometer.smartlab.entity.enumtype.SeeFlag; |
| | | import com.nanometer.smartlab.service.BaseMetaService; |
| | | import com.nanometer.smartlab.service.OpeApplyService; |
| | | import com.nanometer.smartlab.service.SysProjectService; |
| | | import com.nanometer.smartlab.service.SysUserService; |
| | | import com.nanometer.smartlab.util.FacesUtils; |
| | | 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 org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | 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 javax.faces.context.FacesContext; |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.sql.Timestamp; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * Created by johnny on 17/12/14. |
| | | */ |
| | | @Controller |
| | | @Scope("session") |
| | | public class PriceMngController extends BaseController { |
| | | |
| | | private static Logger logger = Logger.getLogger(PriceMngController.class); |
| | | |
| | | @Resource |
| | | private OpeApplyService opeApplyService; |
| | | @Resource |
| | | private SysUserService sysUserService; |
| | | @Resource |
| | | private BaseMetaService baseMetaService; |
| | | |
| | | @Resource |
| | | private SysProjectService sysProjectService; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | private String applyUserName; |
| | | private String approvaUserName; |
| | | |
| | | public String getApplyUserName() { |
| | | return applyUserName; |
| | | } |
| | | |
| | | public void setApplyUserName(String applyUserName) { |
| | | this.applyUserName = applyUserName; |
| | | } |
| | | |
| | | public String getApprovaUserName() { |
| | | return approvaUserName; |
| | | } |
| | | |
| | | public void setApprovaUserName(String approvaUserName) { |
| | | this.approvaUserName = approvaUserName; |
| | | } |
| | | |
| | | private LazyDataModel<OpeApply> dataModel; |
| | | private List<OpeApply> selectedList; |
| | | private OpeApply opeApply; |
| | | private String reagentName; |
| | | private Timestamp startDeadline; |
| | | private Timestamp endDeadline; |
| | | private String applyUserId; |
| | | private Integer status; |
| | | private List<ApplyStatus> statusSelectList; |
| | | private String memo; |
| | | private String approvalUserId; |
| | | private List<SysUser> approvalUserList; |
| | | private Boolean approvalFlag; |
| | | |
| | | public Boolean getApprovalFlag() { |
| | | String id=getUserId(); |
| | | SysUser sysUser = sysUserService.getSysUser(id); |
| | | // 不是管理员时 |
| | | if (sysUser.getSeeFlag().getKey() != SeeFlag.MANAGE.getKey() |
| | | && sysUser.getSeeFlag().getKey() != SeeFlag.LEADING.getKey()) { |
| | | this.approvalFlag=false; |
| | | }else { |
| | | this.approvalFlag=true; |
| | | } |
| | | return approvalFlag; |
| | | } |
| | | |
| | | |
| | | public void setApprovalFlag(Boolean approvalFlag) { |
| | | this.approvalFlag = approvalFlag; |
| | | } |
| | | |
| | | public String getApprovalUserId() { |
| | | return approvalUserId; |
| | | } |
| | | |
| | | public void setApprovalUserId(String approvalUserId) { |
| | | this.approvalUserId = approvalUserId; |
| | | } |
| | | |
| | | public List<SysUser> getApprovalUserList() { |
| | | if (this.approvalUserList == null) { |
| | | initApprovalUserList(); |
| | | } |
| | | return approvalUserList; |
| | | } |
| | | public void initApprovalUserList() { |
| | | this.approvalUserList = this.sysUserService.getApproverUserList(null); |
| | | } |
| | | public void setApprovalUserList(List<SysUser> approvalUserList) { |
| | | this.approvalUserList = approvalUserList; |
| | | } |
| | | |
| | | private String adminApproveUserId; |
| | | |
| | | private List<SysUser> adminApproveUserIdSelectList; |
| | | |
| | | private boolean dangerousFlag; |
| | | |
| | | public void initListPage() { |
| | | status = ApplyStatus.Price_CONFIRM.getKey(); |
| | | } |
| | | |
| | | |
| | | public void onApprovalBtnClick() { |
| | | if (this.selectedList == null |
| | | || this.selectedList.size() == 0) { |
| | | FacesUtils.warn("请选择数据。"); |
| | | return; |
| | | } |
| | | |
| | | this.dangerousFlag = false; |
| | | this.adminApproveUserId = null; |
| | | for (OpeApply opeApply : this.selectedList) { |
| | | if (!opeApply.getStatus().equals(ApplyStatus.Price_CONFIRM)) { |
| | | FacesUtils.warn("只有价格确认状态的数据可以操作。"); |
| | | return; |
| | | } |
| | | |
| | | String controlProducts = opeApply.getReagent().getControlProducts(); |
| | | if (StringUtils.isNotBlank(controlProducts)) { |
| | | String baseMetaValue = baseMetaService.getBaseMetaValue(controlProducts); |
| | | if (StringUtils.isNotBlank(baseMetaValue) && !"15fc90a1f7bf43bda01313904b543195".equals(this.getUser().getRoleId())) { |
| | | dangerousFlag = true; |
| | | } |
| | | } |
| | | } |
| | | |
| | | this.memo = null; |
| | | |
| | | RequestContext.getCurrentInstance().execute("PF('approvalDialog').show()"); |
| | | } |
| | | |
| | | public void onYesBtnClick() { |
| | | try { |
| | | if (this.selectedList == null |
| | | || this.selectedList.size() == 0) { |
| | | FacesUtils.warn("价格修改数据为空。"); |
| | | return; |
| | | } |
| | | |
| | | if (!getUser().getRoleName().equals("系统管理员")) { |
| | | FacesUtils.warn("请选择系统管理员修改。"); |
| | | return; |
| | | } |
| | | |
| | | for (OpeApply opeApply : this.selectedList) { |
| | | this.opeApplyService.updaetOpeApplyPrice(opeApply.getApplyPrice(),opeApply.getId()); |
| | | } |
| | | FacesUtils.info("价格修改成功。"); |
| | | RequestContext.getCurrentInstance().execute("PF('approvalDialog').hide()"); |
| | | RequestContext.getCurrentInstance().update("priceMngForm:priceMngDataTable"); |
| | | } catch (Exception e) { |
| | | logger.error("操作失败。", e); |
| | | FacesUtils.warn("操作失败。"); |
| | | } |
| | | } |
| | | |
| | | public void onExportFileBtnClickNew(){ |
| | | ServletOutputStream out = null; |
| | | InputStream is = null; |
| | | try { |
| | | FacesContext ctx = FacesContext.getCurrentInstance(); |
| | | ctx.responseComplete(); |
| | | String contentType = "application/x-download"; |
| | | HttpServletResponse response = (HttpServletResponse) ctx |
| | | .getExternalContext().getResponse(); |
| | | response.setContentType(contentType); |
| | | StringBuffer contentDisposition = new StringBuffer(); |
| | | contentDisposition.append("attachment;"); |
| | | contentDisposition.append("filename=\""); |
| | | contentDisposition.append("价格管理.xls"); |
| | | contentDisposition.append("\""); |
| | | response.setHeader( |
| | | "Content-Disposition", |
| | | new String(contentDisposition.toString().getBytes( |
| | | System.getProperty("file.encoding")), "ISO8859-1")); |
| | | out = response.getOutputStream(); |
| | | Map<String, Integer> tempMap = new HashMap<String,Integer>(); |
| | | List<OpeApply> realDataList = new ArrayList<>(); |
| | | //map=null; |
| | | String approveUserId = getUserId(); |
| | | if(selectedList!=null&selectedList.size()>0){ |
| | | realDataList=selectedList; |
| | | }else { |
| | | realDataList= opeApplyService.getOpeApplyListForApproval(applyUserName,approvaUserName,reagentName, startDeadline, endDeadline, status, null, approveUserId, null, null, null, null,null); |
| | | } |
| | | List<String> headerList = new ArrayList<>(); |
| | | headerList.add("申购编号"); |
| | | headerList.add("产品编号"); |
| | | headerList.add("试剂名称"); |
| | | headerList.add("管制品"); |
| | | headerList.add("规格型号"); |
| | | headerList.add("包装"); |
| | | headerList.add("含税售价"); |
| | | headerList.add("数量"); |
| | | headerList.add("CAS号"); |
| | | 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(); |
| | | ctx.responseComplete(); |
| | | }catch (Exception e) { |
| | | if(is!=null){ |
| | | try { |
| | | is.close(); |
| | | } catch (IOException e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | if(out!=null){ |
| | | try { |
| | | out.close(); |
| | | } catch (IOException e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | e.printStackTrace(); |
| | | }finally { |
| | | if (is != null) { |
| | | try { |
| | | is.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | if (out != null) { |
| | | try { |
| | | out.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | public HSSFWorkbook exportExcelNew(List<String> headerList, List<OpeApply> dataList) { |
| | | HSSFWorkbook hssfWorkbook = new HSSFWorkbook(); |
| | | |
| | | |
| | | Integer total = null; |
| | | HSSFSheet sheet = hssfWorkbook.createSheet("审批详情"); |
| | | HSSFRow titlerRow = sheet.createRow(0); |
| | | for(int i = 0; i < headerList.size(); i++) { |
| | | titlerRow.createCell(i).setCellValue(headerList.get(i)); |
| | | } |
| | | for (int i = 0; i < dataList.size(); 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(6).setCellValue(dataList.get(i).getReagent().getPrice()== null ? "": String.valueOf(dataList.get(i).getReagent().getPrice())); |
| | | dataRow.createCell(7).setCellValue(String.valueOf(dataList.get(i).getNum())); |
| | | dataRow.createCell(8).setCellValue(dataList.get(i).getReagent().getCas()== null ? "": String.valueOf(dataList.get(i).getReagent().getCas())); |
| | | dataRow.createCell(9).setCellValue(dataList.get(i).getReagent().getReagentCharacter()== null ? "": String.valueOf(baseMetaService.getBaseMetaValue(dataList.get(i).getReagent().getReagentCharacter()))); |
| | | dataRow.createCell(10).setCellValue(dataList.get(i).getReagent().getProductHomeName()== null ? "": String.valueOf(dataList.get(i).getReagent().getProductHomeName())); |
| | | dataRow.createCell(11).setCellValue(dataList.get(i).getReagent().getReagentType()== null ? "": String.valueOf(baseMetaService.getBaseMetaValue(dataList.get(i).getReagent().getReagentType()))); |
| | | |
| | | dataRow.createCell(12).setCellValue(String.valueOf(dataList.get(i).getApplyUserName())); |
| | | dataRow.createCell(13).setCellValue(String.valueOf(dataList.get(i).getCreateTime())); |
| | | /* SysUser u=sysUserService.getSysUser(dataList.get(i).getApproveUserId()); |
| | | *//*if(dataList.get(i).getBeforeApproveUserId()!=null){ |
| | | u=sysUserService.getSysUser(dataList.get(i).getBeforeApproveUserId()); |
| | | }*//* |
| | | dataRow.createCell(14).setCellValue(String.valueOf(u.getName()));*/ |
| | | dataRow.createCell(14).setCellValue(String.valueOf(dataList.get(i).getFirName())); |
| | | if(dataList.get(i).getBeforeApproveUserId()!=null && !dataList.get(i).getBeforeApproveUserId().equals("")){ |
| | | dataRow.createCell(15).setCellValue(String.valueOf(dataList.get(i).getApproveUserName())); |
| | | } |
| | | dataRow.createCell(16).setCellValue(String.valueOf(dataList.get(i).getStatus().getText())); |
| | | SysProject project = sysProjectService.getProjectByProId(dataList.get(i).getObjective()); |
| | | dataRow.createCell(17).setCellValue(project.getProjectName()==null ?"":String.valueOf(project.getProjectName())); |
| | | } |
| | | |
| | | return hssfWorkbook; |
| | | } |
| | | public void onConfirmBtnClick() { |
| | | try { |
| | | if (this.selectedList == null |
| | | || this.selectedList.size() == 0) { |
| | | FacesUtils.warn("请选择数据。"); |
| | | return; |
| | | } |
| | | |
| | | for (OpeApply oa : this.selectedList) { |
| | | if (!oa.getStatus().equals(ApplyStatus.Price_CONFIRM)) { |
| | | FacesUtils.warn("只有价格确认状态的数据可以操作。"); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | for (OpeApply oa : this.selectedList) { |
| | | oa.setStatus(ApplyStatus.PENDING_APPROVAL); |
| | | this.opeApplyService.updateOpeApply(oa); |
| | | } |
| | | |
| | | FacesUtils.info("确认成功。"); |
| | | } catch (Exception e) { |
| | | logger.error("操作失败。", e); |
| | | FacesUtils.warn("操作失败。"); |
| | | } |
| | | } |
| | | |
| | | 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 { |
| | | String approveUserId = getUserId(); |
| | | int count = 0; |
| | | if (StringUtils.isNotBlank(approveUserId)) { |
| | | count = opeApplyService.getOpeApplyTotalCountForApproval(applyUserName,approvaUserName,reagentName, startDeadline, endDeadline, status, null, approveUserId, null, null,null); |
| | | } |
| | | this.setRowCount(count); |
| | | if (count > 0) { |
| | | list = opeApplyService.getOpeApplyListForApproval(applyUserName,approvaUserName,reagentName, startDeadline, endDeadline, status, null, approveUserId, null, first, pageSize, null,null); |
| | | for(int i=0;i<list.size();i++){ |
| | | /* if(list.get(i).getSecondUserName()!=null&&!list.get(i).getSecondUserName().equals("")){ |
| | | String name=list.get(i).getApproveUserName(); |
| | | list.get(i).setApproveUserName(list.get(i).getSecondUserName()); |
| | | list.get(i).setSecondUserName(name); |
| | | }*/ |
| | | if(list.get(i).getBeforeApproveUserId()!=null&&!list.get(i).getBeforeApproveUserId().equals("")){ |
| | | String name=list.get(i).getApproveUserName(); |
| | | list.get(i).setFirst(list.get(i).getFirName()); |
| | | list.get(i).setSecond(name); |
| | | }else { |
| | | list.get(i).setFirst(list.get(i).getApproveUserName()); |
| | | list.get(i).setSecond(list.get(i).getSecondUserName()); |
| | | } |
| | | } |
| | | } |
| | | /*} 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 opeApplyService.getOpeApply(rowKey); |
| | | } |
| | | }; |
| | | } |
| | | |
| | | return dataModel; |
| | | } |
| | | |
| | | public OpeApply getOpeApply() { |
| | | return opeApply; |
| | | } |
| | | |
| | | public void setOpeApply(OpeApply opeApply) { |
| | | this.opeApply = opeApply; |
| | | } |
| | | |
| | | 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 String getApplyUserId() { |
| | | return applyUserId; |
| | | } |
| | | |
| | | public void setApplyUserId(String applyUserId) { |
| | | this.applyUserId = applyUserId; |
| | | } |
| | | |
| | | public Integer getStatus() { |
| | | return status; |
| | | } |
| | | |
| | | public void setStatus(Integer status) { |
| | | this.status = status; |
| | | } |
| | | |
| | | public List<OpeApply> getSelectedList() { |
| | | return selectedList; |
| | | } |
| | | |
| | | public void setSelectedList(List<OpeApply> selectedList) { |
| | | this.selectedList = selectedList; |
| | | } |
| | | |
| | | public List<ApplyStatus> getStatusSelectList() { |
| | | if (this.statusSelectList == null) { |
| | | this.statusSelectList = Arrays.asList(ApplyStatus.values()); |
| | | } |
| | | return statusSelectList; |
| | | } |
| | | |
| | | public String getMemo() { |
| | | return memo; |
| | | } |
| | | |
| | | public void setMemo(String memo) { |
| | | this.memo = memo; |
| | | } |
| | | |
| | | public String getAdminApproveUserId() { |
| | | return adminApproveUserId; |
| | | } |
| | | |
| | | public void setAdminApproveUserId(String adminApproveUserId) { |
| | | this.adminApproveUserId = adminApproveUserId; |
| | | } |
| | | |
| | | public List<SysUser> getAdminApproveUserIdSelectList() { |
| | | return adminApproveUserIdSelectList; |
| | | } |
| | | |
| | | public void setAdminApproveUserIdSelectList(List<SysUser> adminApproveUserIdSelectList) { |
| | | this.adminApproveUserIdSelectList = adminApproveUserIdSelectList; |
| | | } |
| | | |
| | | public boolean isDangerousFlag() { |
| | | return dangerousFlag; |
| | | } |
| | | |
| | | public void setDangerousFlag(boolean dangerousFlag) { |
| | | this.dangerousFlag = dangerousFlag; |
| | | } |
| | | } |