From 47a751cb301d05276ae5d75145d57b2d090fe4e1 Mon Sep 17 00:00:00 2001
From: kongzy <kongzy>
Date: Mon, 01 Jul 2024 10:58:35 +0800
Subject: [PATCH] change
---
src/main/java/com/nanometer/smartlab/controller/HazardousWasteController.java | 184 ++++++++++++++++++++++++++++++++++++++-------
1 files changed, 153 insertions(+), 31 deletions(-)
diff --git a/src/main/java/com/nanometer/smartlab/controller/HazardousWasteController.java b/src/main/java/com/nanometer/smartlab/controller/HazardousWasteController.java
index 92b6237..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,7 +36,7 @@
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<> ();
@@ -37,9 +44,86 @@
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) {
@@ -52,15 +136,15 @@
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);
@@ -112,15 +196,15 @@
try {
if (getUser().getWaster() != null){
if (getUser().getWaster().equals(Waster.MANAGE)){
- int pageCount = hazardousWasteService.countStatistics(startTime,endTime,status,applyPerson,project,department);
+ int pageCount = hazardousWasteService.countStatistics(startTime,endTime,status,applyPerson,projectId,department);
this.setRowCount(pageCount);
if (pageCount > 0)
- list = hazardousWasteService.selectStatistics(startTime,endTime,status,applyPerson,project,department,first, pageSize);
- }else if (StringUtils.isNotBlank(getUser().getProject())){
- int pageCount = hazardousWasteService.countStatistics(startTime,endTime,status,applyPerson,getUser().getProject(),department);
+ 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().getProject(),department,first, pageSize);
+ list = hazardousWasteService.selectStatistics(startTime,endTime,status,applyPerson,getUser().getProjectId(),department,first, pageSize);
}
}else {
this.setRowCount(0);
@@ -201,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() {
@@ -232,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);
}
}
@@ -250,9 +334,9 @@
List<Map> list = new ArrayList<>();
if (getUser().getWaster() != null){
if (getUser().getWaster().equals(Waster.MANAGE)){
- list = hazardousWasteService.exportStatisticsList(startTime,endTime,status,applyPerson,project,department);
- }else if (StringUtils.isNotBlank(getUser().getProject())){
- list = hazardousWasteService.exportStatisticsList(startTime,endTime,status,applyPerson,getUser().getProject(),department);
+ 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{
@@ -265,17 +349,22 @@
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();
@@ -284,17 +373,22 @@
}
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();
@@ -317,4 +411,32 @@
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