Browse Source

单据删除和反提交时增加判断,只有已提交的单据才能进行反提交或删除

git-svn-id: svn+ssh://10.10.101.21/source/platform/platform-b2b@7645 f3bf4e98-0cf0-11e4-a00c-a99a8b9d557d
hejq 9 years ago
parent
commit
bef4ae984a

+ 102 - 47
src/main/java/com/uas/platform/b2b/mobile/service/impl/PublicInterForDetailServiceImpl.java

@@ -93,46 +93,80 @@ public class PublicInterForDetailServiceImpl implements PublicInterForDetailServ
 		if (whichpage.equals(MobileStatus.SIGNAPP.getValue())) {
 			caller = MobileStatus.SIGNAPP.getPhrase();
 		}
-		List<ApprovalLog> logs = approvalLogDao.getByKeyvalueAndCaller(id, caller);
-		if (!CollectionUtils.isEmpty(logs)) {// 先删除单据产生的审批相关记录
-			for (ApprovalLog log : logs) {
-				approvalLogDao.delete(log.getId());
-			}
-		}
-		List<AppFlowOperation> operations = appFlowOperationDao.findByKeyvalue(id);
-		if (!CollectionUtils.isEmpty(operations)) {
-			for (AppFlowOperation op : operations) {
-				appFlowOperationDao.delete(op.getId());
-			}
-		}
+		// 先判断个单据的状态
+		boolean flag = false;
 		if (whichpage.equals(MobileStatus.FEEPLEASE.getValue())) {
-			if (feePleaseDao.findOne(id) != null) {
-				feePleaseDao.delete(id);
-				map.put("success", true);
+			FeePlease fee = feePleaseDao.findOne(id);
+			if (fee != null) {
+				if (fee.getFp_statuscode().equals(MobileStatus.COMMITED.name())) {
+					feePleaseDao.delete(id);
+					map.put("success", true);
+					flag = true;
+				} else {
+					map.put("error", "只能对提交状态的单据进行删除");
+				}
 			}
 		}
 		if (whichpage.equals(MobileStatus.VACATION.getValue())) {
-			if (vacationDao.findOne(id) != null) {
-				vacationDao.delete(id);
-				map.put("success", true);
+			Vacation va = vacationDao.findOne(id);
+			if (va != null) {
+				if (va.getVa_statuscode().equals(MobileStatus.COMMITED.name())) {
+					vacationDao.delete(id);
+					map.put("success", true);
+					flag = true;
+				} else {
+					map.put("error", "只能对提交状态的单据进行删除");
+				}
 			}
 		}
 		if (whichpage.equals(MobileStatus.WORKDAILY.getValue())) {
-			if (workDailyDao.findOne(id) != null) {
-				workDailyDao.delete(id);
-				map.put("success", true);
+			WorkDaily wo = workDailyDao.findOne(id);
+			if (wo != null) {
+				if (wo.getWd_statuscode().equals(MobileStatus.COMMITED.name())) {
+					workDailyDao.delete(id);
+					map.put("success", true);
+					flag = true;
+				} else {
+					map.put("error", "只能对提交状态的单据进行删除");
+				}
 			}
 		}
 		if (whichpage.equals(MobileStatus.WORKOVERTIME.getValue())) {
-			if (workOvertimeDao.findOne(id) != null) {
-				workOvertimeDao.delete(id);
-				map.put("success", true);
+			WorkOvertime wo = workOvertimeDao.findOne(id);
+			if (wo != null) {
+				if (wo.getWo_statuscode().equals(MobileStatus.COMMITED.name())) {
+					workOvertimeDao.delete(id);
+					map.put("success", true);
+					flag = true;
+				} else {
+					map.put("error", "只能对提交状态的单据进行删除");
+				}
 			}
 		}
 		if (whichpage.equals(MobileStatus.SIGNAPP.getValue())) {
-			if (signAppDao.findOne(id) != null) {
-				signAppDao.delete(id);
-				map.put("success", true);
+			SignApp si = signAppDao.findOne(id);
+			if (si != null) {
+				if (si.getStatuscode().equals(MobileStatus.COMMITED.name())) {
+					signAppDao.delete(id);
+					map.put("success", true);
+					flag = true;
+				} else {
+					map.put("error", "只能对提交状态的单据进行删除");
+				}
+			}
+		}
+		if (flag) {
+			List<ApprovalLog> logs = approvalLogDao.getByKeyvalueAndCaller(id, caller);
+			if (!CollectionUtils.isEmpty(logs)) {// 先删除单据产生的审批相关记录
+				for (ApprovalLog log : logs) {
+					approvalLogDao.delete(log.getId());
+				}
+			}
+			List<AppFlowOperation> operations = appFlowOperationDao.findByKeyvalue(id);
+			if (!CollectionUtils.isEmpty(operations)) {
+				for (AppFlowOperation op : operations) {
+					appFlowOperationDao.delete(op.getId());
+				}
 			}
 		}
 		return map;
@@ -143,30 +177,36 @@ public class PublicInterForDetailServiceImpl implements PublicInterForDetailServ
 		ModelMap map = new ModelMap();
 		if (whichpage.equals(MobileStatus.FEEPLEASE.getValue())) {
 			FeePlease fee = feePleaseDao.findOne(id);
-			if (fee != null && fee.getFp_statuscode().equals(MobileStatus.COMMITED.name())) {// 已提交的单据才能反提交
-				List<ApprovalLog> logs = approvalLogDao.getBySourceid(id);
-				if (!CollectionUtils.isEmpty(logs)) {// 先删除单据产生的审批相关记录
-					for (ApprovalLog log : logs) {
-						approvalLogDao.delete(log.getId());
+			if (fee != null) {
+				if (fee.getFp_statuscode().equals(MobileStatus.COMMITED.name())) {// 已提交的单据才能反提交
+					List<ApprovalLog> logs = approvalLogDao.getBySourceid(id);
+					if (!CollectionUtils.isEmpty(logs)) {// 先删除单据产生的审批相关记录
+						for (ApprovalLog log : logs) {
+							approvalLogDao.delete(log.getId());
+						}
 					}
-				}
-				List<AppFlowOperation> operations = appFlowOperationDao.findBySourceidAndCaller(id,
-						MobileStatus.FEEPLEASE.getPhrase());
-				if (!CollectionUtils.isEmpty(operations)) {
-					for (AppFlowOperation op : operations) {
-						appFlowOperationDao.delete(op.getId());
+					List<AppFlowOperation> operations = appFlowOperationDao.findBySourceidAndCaller(id,
+							MobileStatus.FEEPLEASE.getPhrase());
+					if (!CollectionUtils.isEmpty(operations)) {
+						for (AppFlowOperation op : operations) {
+							appFlowOperationDao.delete(op.getId());
+						}
 					}
+					fee.setFp_status(MobileStatus.ENTERING.getPhrase());
+					fee.setFp_statuscode(MobileStatus.ENTERING.name());
+					fee.setFp_recorddate(new Date());
+					feePleaseDao.save(fee);
+					map.put("success", true);
+				} else {
+					map.put("error", "只能对提交状态的单据进行反提交");
 				}
-				fee.setFp_status(MobileStatus.ENTERING.getPhrase());
-				fee.setFp_statuscode(MobileStatus.ENTERING.name());
-				fee.setFp_recorddate(new Date());
-				feePleaseDao.save(fee);
-				map.put("success", true);
 			}
+
 		}
 		if (whichpage.equals(MobileStatus.VACATION.getValue())) {
 			Vacation va = vacationDao.findOne(id);
-			if (va != null && va.getVa_statuscode().equals(MobileStatus.COMMITED.name())) {// 已提交的单据才能反提交
+			if (va != null) {
+				if (va.getVa_statuscode().equals(MobileStatus.COMMITED.name())) {// 已提交的单据才能反提交
 				List<ApprovalLog> logs = approvalLogDao.getBySourceid(id);
 				if (!CollectionUtils.isEmpty(logs)) {// 先删除单据产生的审批相关记录
 					for (ApprovalLog log : logs) {
@@ -185,11 +225,15 @@ public class PublicInterForDetailServiceImpl implements PublicInterForDetailServ
 				va.setVa_date(new Date());
 				vacationDao.save(va);
 				map.put("success", true);
+				} else {
+					map.put("error", "只能对提交状态的单据进行反提交");
+				}
 			}
 		}
 		if (whichpage.equals(MobileStatus.WORKDAILY.getValue())) {
 			WorkDaily wo = workDailyDao.findOne(id);
-			if (wo != null && wo.getWd_statuscode().equals(MobileStatus.COMMITED.name())) {// 已提交的单据才能反提交
+			if (wo != null) {
+				if (wo.getWd_statuscode().equals(MobileStatus.COMMITED.name())) {// 已提交的单据才能反提交
 				List<ApprovalLog> logs = approvalLogDao.getBySourceid(id);
 				if (!CollectionUtils.isEmpty(logs)) {// 先删除单据产生的审批相关记录
 					for (ApprovalLog log : logs) {
@@ -208,11 +252,15 @@ public class PublicInterForDetailServiceImpl implements PublicInterForDetailServ
 				wo.setWd_date(new Date());
 				workDailyDao.save(wo);
 				map.put("success", true);
+				} else {
+					map.put("error", "只能对提交状态的单据进行反提交");
+				}
 			}
 		}
 		if (whichpage.equals(MobileStatus.WORKOVERTIME.getValue())) {
 			WorkOvertime wo = workOvertimeDao.findOne(id);
-			if (wo != null && wo.getWo_statuscode().equals(MobileStatus.COMMITED.name())) {// 已提交的单据才能反提交
+			if (wo != null) {
+				if (wo.getWo_statuscode().equals(MobileStatus.COMMITED.name())) {// 已提交的单据才能反提交
 				List<ApprovalLog> logs = approvalLogDao.getBySourceid(id);
 				if (!CollectionUtils.isEmpty(logs)) {// 先删除单据产生的审批相关记录
 					for (ApprovalLog log : logs) {
@@ -231,12 +279,16 @@ public class PublicInterForDetailServiceImpl implements PublicInterForDetailServ
 				wo.setWo_date(new Date());
 				workOvertimeDao.save(wo);
 				map.put("success", true);
+				} else {
+					map.put("error", "只能对提交状态的单据进行反提交");
+				}
 			}
 		}
 
 		if (whichpage.equals(MobileStatus.SIGNAPP.getValue())) {
 			SignApp app = signAppDao.findOne(id);
-			if (app != null && app.getStatuscode().equals(MobileStatus.COMMITED.name())) {// 已提交的单据才能反提交
+			if (app != null) {
+				if (app.getStatuscode().equals(MobileStatus.COMMITED.name())) {// 已提交的单据才能反提交
 				List<ApprovalLog> logs = approvalLogDao.getBySourceid(id);
 				if (!CollectionUtils.isEmpty(logs)) {// 先删除单据产生的审批相关记录
 					for (ApprovalLog log : logs) {
@@ -254,6 +306,9 @@ public class PublicInterForDetailServiceImpl implements PublicInterForDetailServ
 				app.setStatuscode(MobileStatus.ENTERING.name());
 				signAppDao.save(app);
 				map.put("success", true);
+				} else {
+					map.put("error", "只能对提交状态的单据进行反提交");
+				}
 			}
 		}
 		return map;