From 47a751cb301d05276ae5d75145d57b2d090fe4e1 Mon Sep 17 00:00:00 2001 From: kongzy <kongzy> Date: 星期一, 01 七月 2024 10:58:35 +0800 Subject: [PATCH] change --- src/main/java/com/nanometer/smartlab/controller/HazardousWasteController.java | 267 +++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 229 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/nanometer/smartlab/controller/HazardousWasteController.java b/src/main/java/com/nanometer/smartlab/controller/HazardousWasteController.java index a6cea3a..71eff66 100644 --- a/src/main/java/com/nanometer/smartlab/controller/HazardousWasteController.java +++ b/src/main/java/com/nanometer/smartlab/controller/HazardousWasteController.java @@ -2,19 +2,26 @@ import com.nanometer.smartlab.entity.HazardousWaste; +import com.nanometer.smartlab.entity.SysLaboratory; +import com.nanometer.smartlab.entity.SysUser; import com.nanometer.smartlab.entity.dto.HazardousWasteUser; import com.nanometer.smartlab.entity.enumtype.Waster; import com.nanometer.smartlab.service.HazardousWasteService; +import com.nanometer.smartlab.service.SysUserService; +import com.nanometer.smartlab.util.Constants; import com.nanometer.smartlab.util.FacesUtils; 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.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import javax.annotation.Resource; import javax.faces.event.ActionListener; +import java.text.SimpleDateFormat; import java.util.*; @Controller @@ -29,16 +36,94 @@ private Date endTime; private String status; private String applyPerson; - private String project; + private Long projectId; private String department; private String tid; private List<String> statusList = new ArrayList<> (); private boolean isSearch = false; private boolean isAnalysSearch = false; private LazyDataModel<HazardousWaste> analysisDataModel; + private HazardousWaste selectedOne; + /** + * 选中的list + */ + private List<HazardousWaste> selectedList; + + private HazardousWaste hazardousWaste=new HazardousWaste(); + + private int action; + @Autowired + private SysUserService sysUserService; + + private List<SysUser> userSelectList; @Resource private HazardousWasteService hazardousWasteService; + + public List<SysUser> getUserSelectList() { + if (userSelectList == null) { + this.initUserSelectList(); + } + return userSelectList; + } + + private void initUserSelectList() { + this.setUserSelectList(this.sysUserService.getSysUserList(null, null, null, null, null,null,null)); + } + + public SysUser getSelectedUserById(Long userId) { + SysUser sysUser=this.sysUserService.getSysUser(userId); + if(sysUser==null){ + return new SysUser(); + } + return sysUser; + } + + public void addHazardousWaste(){ + this.hazardousWaste = new HazardousWaste(); + this.action = Constants.ACTION_ADD; + RequestContext.getCurrentInstance().execute("PF('wastedialog').show()"); + } + + public void editHazardousWaste(){ + if (this.selectedList == null || this.selectedList.size() == 0) { + FacesUtils.warn("请选择数据。"); + return; + } + if (this.selectedList.size() > 1) { + FacesUtils.warn("只能选择一个数据进行修改。"); + return; + } + this.hazardousWaste=this.hazardousWasteService.selectById(this.selectedList.get(0).getId()); + this.action = Constants.ACTION_EDIT; + RequestContext.getCurrentInstance().execute("PF('wastedialog').show()"); + } + + public void onSaveBtnClick(){ + try { + Long userId = this.hazardousWaste.getApplyPerson(); + SysUser sysUser = sysUserService.getSysUser(userId); + this.hazardousWaste.setUnit(sysUser.getCompany()); + String userName = getUserName(); + if (this.action == Constants.ACTION_ADD) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); + this.hazardousWaste.setCreator(userName); + this.hazardousWaste.setTid(sdf.format(new Date())); + this.hazardousWaste.setStatus("待确认"); + hazardousWasteService.insertInfo(this.hazardousWaste); + FacesUtils.info("新建成功。"); + RequestContext.getCurrentInstance().execute("PF('wastedialog').hide()"); + } else { + this.hazardousWaste.setUpdator(userName); + hazardousWasteService.updateWaste(this.hazardousWaste); + FacesUtils.info("修改成功。"); + RequestContext.getCurrentInstance().execute("PF('wastedialog').hide()"); + } + }catch (Exception e){ + logger.error("操作失败。", e); + FacesUtils.warn("操作失败。"); + } + } public LazyDataModel<HazardousWaste> getDataModel() { if (this.dataModel == null) { @@ -51,21 +136,24 @@ try { if (getUser().getWaster() != null){ if (getUser().getWaster().equals(Waster.MANAGE)){ - int pageCount = hazardousWasteService.countAll(startTime,endTime,status,applyPerson,project,department,tid); + int pageCount = hazardousWasteService.countAll(startTime,endTime,status,applyPerson,projectId,department,tid); this.setRowCount(pageCount); if (pageCount > 0) - list = hazardousWasteService.selectAll(startTime,endTime,status,applyPerson,project,department,tid,first, pageSize); - }else if (StringUtils.isNotBlank(getUser().getProject())){ - int pageCount = hazardousWasteService.countAll(startTime,endTime,status,applyPerson,getUser().getProject(),department,tid); + list = hazardousWasteService.selectAll(startTime,endTime,status,applyPerson,projectId,department,tid,first, pageSize); + }else if (getUser().getProjectId()!=null){ + int pageCount = hazardousWasteService.countAll(startTime,endTime,status,applyPerson,getUser().getProjectId(),department,tid); this.setRowCount(pageCount); if (pageCount > 0) - list = hazardousWasteService.selectAll(startTime,endTime,status,applyPerson,getUser().getProject(),department,tid,first, pageSize); + list = hazardousWasteService.selectAll(startTime,endTime,status,applyPerson,getUser().getProjectId(),department,tid,first, pageSize); } + }else { + this.setRowCount(0); } //查询更换模式 if (isSearch) { isSearch = false; } + selectedOne = null; } catch (Exception e) { logger.error("error occured.", e); } @@ -74,15 +162,15 @@ @Override public HazardousWaste getRowData(String rowKey) { - Iterator<HazardousWaste> iterator = this.iterator(); - HazardousWaste su = null; - while (iterator.hasNext()) { - su = iterator.next(); - if ( su.getId().equals(Long.parseLong(rowKey))) { - return su; - } - } - return null; +// Iterator<HazardousWaste> iterator = this.iterator(); +// HazardousWaste su = null; +// while (iterator.hasNext()) { +// su = iterator.next(); +// if ( su.getId().equals(Long.parseLong(rowKey))) { +// return su; +// } +// } + return hazardousWasteService.selectById(Long.parseLong(rowKey)); } }; } @@ -106,11 +194,21 @@ List<HazardousWaste> list = null; try { - int pageCount = hazardousWasteService.countStatistics(startTime,endTime,status,applyPerson,project,department); - - this.setRowCount(pageCount); - if (pageCount > 0) - list = hazardousWasteService.selectStatistics(startTime,endTime,status,applyPerson,project,department,first, pageSize); + if (getUser().getWaster() != null){ + if (getUser().getWaster().equals(Waster.MANAGE)){ + int pageCount = hazardousWasteService.countStatistics(startTime,endTime,status,applyPerson,projectId,department); + this.setRowCount(pageCount); + if (pageCount > 0) + list = hazardousWasteService.selectStatistics(startTime,endTime,status,applyPerson,projectId,department,first, pageSize); + }else if (getUser().getProjectId()!=null){ + int pageCount = hazardousWasteService.countStatistics(startTime,endTime,status,applyPerson,getUser().getProjectId(),department); + this.setRowCount(pageCount); + if (pageCount > 0) + list = hazardousWasteService.selectStatistics(startTime,endTime,status,applyPerson,getUser().getProjectId(),department,first, pageSize); + } + }else { + this.setRowCount(0); + } //查询更换模式 if (isAnalysSearch) { @@ -124,14 +222,14 @@ @Override public HazardousWaste getRowData(String rowKey) { - Iterator<HazardousWaste> iterator = this.iterator(); - HazardousWaste su = null; - while (iterator.hasNext()) { - su = iterator.next(); - if ( su.getId().equals(Long.parseLong(rowKey))) { - return su; - } - } +// Iterator<HazardousWaste> iterator = this.iterator(); +// HazardousWaste su = null; +// while (iterator.hasNext()) { +// su = iterator.next(); +// if ( su.getId().equals(Long.parseLong(rowKey))) { +// return su; +// } +// } return null; } }; @@ -187,12 +285,12 @@ this.applyPerson = applyPerson; } - public String getProject() { - return project; + public Long getProjectId() { + return projectId; } - public void setProject(String project) { - this.project = project; + public void setProject(Long projectId) { + this.projectId = projectId; } public String getDepartment() { @@ -206,9 +304,10 @@ public List<String> getStatusList() { statusList = new ArrayList<> (); statusList.add("全部"); - statusList.add("待解决"); - statusList.add("已解决"); + statusList.add("待确认"); + statusList.add("已确认"); statusList.add("已拒绝"); + statusList.add("已取消"); return statusList; } @@ -217,9 +316,9 @@ List<Map> list = new ArrayList<>(); if (getUser().getWaster() != null){ if (getUser().getWaster().equals(Waster.MANAGE)){ - list = hazardousWasteService.exportList(startTime,endTime,status,applyPerson,project,department,tid); - }else if (StringUtils.isNotBlank(getUser().getProject())){ - list = hazardousWasteService.exportList(startTime,endTime,status,applyPerson,getUser().getProject(),department,tid); + list = hazardousWasteService.exportList(startTime,endTime,status,applyPerson,projectId,department,tid); + }else if (getUser().getProjectId()!=null){ + list = hazardousWasteService.exportList(startTime,endTime,status,applyPerson,getUser().getProjectId(),department,tid); } } @@ -232,12 +331,68 @@ } public void exportStatistics2Excel(){ - List<Map> list = hazardousWasteService.exportStatisticsList(startTime,endTime,status,applyPerson,project,department); + List<Map> list = new ArrayList<>(); + if (getUser().getWaster() != null){ + if (getUser().getWaster().equals(Waster.MANAGE)){ + list = hazardousWasteService.exportStatisticsList(startTime,endTime,status,applyPerson,projectId,department); + }else if (getUser().getProjectId()!=null){ + list = hazardousWasteService.exportStatisticsList(startTime,endTime,status,applyPerson,getUser().getProjectId(),department); + } + } try{ hazardousWasteService.exportStatistics2Excel(list); }catch (Exception e){ e.printStackTrace(); FacesUtils.warn("导出失败"); + } + } + + public void cancelOne(){ + //待确认状态的才能取消 + if (this.selectedList == null || this.selectedList.size() == 0) { + FacesUtils.warn("请选择数据。"); + return; + } + if (this.selectedList.size() > 1) { + FacesUtils.warn("只能选择一个数据进行修改。"); + return; + } + HazardousWaste hwaste=this.selectedList.get(0); + if (!"待确认".equals(hwaste.getStatus())) { + FacesUtils.warn("非待确认不能取消"); + return; + } + try { + hwaste.setStatus("已取消"); + hazardousWasteService.updateWaste(hwaste); + FacesUtils.warn("操作成功"); + } catch (Exception e) { + e.printStackTrace(); + FacesUtils.warn("操作失败"); + } + } + + public void recoverOne(){ + if (this.selectedList == null || this.selectedList.size() == 0) { + FacesUtils.warn("请选择数据。"); + return; + } + if (this.selectedList.size() > 1) { + FacesUtils.warn("只能选择一个数据进行修改。"); + return; + } + HazardousWaste hwaste=this.selectedList.get(0); + if (!"已取消".equals(hwaste.getStatus())) { + FacesUtils.warn("非已取消不能恢复"); + return; + } + try { + hwaste.setStatus("待确认"); + hazardousWasteService.updateWaste(hwaste); + FacesUtils.warn("操作成功"); + } catch (Exception e) { + e.printStackTrace(); + FacesUtils.warn("操作失败"); } } @@ -248,4 +403,40 @@ public void setTid(String tid) { this.tid = tid; } + + public HazardousWaste getSelectedOne() { + return selectedOne; + } + + public void setSelectedOne(HazardousWaste selectedOne) { + this.selectedOne = selectedOne; + } + + public List<HazardousWaste> getSelectedList() { + return selectedList; + } + + public void setSelectedList(List<HazardousWaste> selectedList) { + this.selectedList = selectedList; + } + + public HazardousWaste getHazardousWaste() { + return hazardousWaste; + } + + public void setHazardousWaste(HazardousWaste hazardousWaste) { + this.hazardousWaste = hazardousWaste; + } + + public int getAction() { + return action; + } + + public void setAction(int action) { + this.action = action; + } + + public void setUserSelectList(List<SysUser> userSelectList) { + this.userSelectList = userSelectList; + } } -- Gitblit v1.9.2