| | |
| | | |
| | | |
| | | 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 |
| | |
| | | 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 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) { |
| | |
| | | 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) { |
| | |
| | | |
| | | 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) { |
| | |
| | | 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() { |
| | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | 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){ |
| | |
| | | |
| | | public void cancelOne(){ |
| | | //待确认状态的才能取消 |
| | | if (this.selectedOne == null) { |
| | | FacesUtils.warn("请选择"); |
| | | if (this.selectedList == null || this.selectedList.size() == 0) { |
| | | FacesUtils.warn("请选择数据。"); |
| | | return; |
| | | } |
| | | if (!"待确认".equals(this.selectedOne.getStatus())) { |
| | | if (this.selectedList.size() > 1) { |
| | | FacesUtils.warn("只能选择一个数据进行修改。"); |
| | | return; |
| | | } |
| | | HazardousWaste hwaste=this.selectedList.get(0); |
| | | if (!"待确认".equals(hwaste.getStatus())) { |
| | | FacesUtils.warn("非待确认不能取消"); |
| | | return; |
| | | } |
| | | try { |
| | | this.selectedOne.setStatus("已取消"); |
| | | hazardousWasteService.updateWaste(this.selectedOne); |
| | | hwaste.setStatus("已取消"); |
| | | hazardousWasteService.updateWaste(hwaste); |
| | | FacesUtils.warn("操作成功"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | } |
| | | |
| | | public void recoverOne(){ |
| | | if (this.selectedOne == null) { |
| | | FacesUtils.warn("请选择"); |
| | | if (this.selectedList == null || this.selectedList.size() == 0) { |
| | | FacesUtils.warn("请选择数据。"); |
| | | return; |
| | | } |
| | | if (!"已取消".equals(this.selectedOne.getStatus())) { |
| | | if (this.selectedList.size() > 1) { |
| | | FacesUtils.warn("只能选择一个数据进行修改。"); |
| | | return; |
| | | } |
| | | HazardousWaste hwaste=this.selectedList.get(0); |
| | | if (!"已取消".equals(hwaste.getStatus())) { |
| | | FacesUtils.warn("非已取消不能恢复"); |
| | | return; |
| | | } |
| | | try { |
| | | this.selectedOne.setStatus("待确认"); |
| | | hazardousWasteService.updateWaste(this.selectedOne); |
| | | hwaste.setStatus("待确认"); |
| | | hazardousWasteService.updateWaste(hwaste); |
| | | FacesUtils.warn("操作成功"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | 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; |
| | | } |
| | | } |