Browse Source

政策-总监手动转审

yangzian 3 years ago
parent
commit
b1c066e343

+ 124 - 119
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/controller/CwjsPolicyInfoController.java

@@ -132,10 +132,10 @@ public class CwjsPolicyInfoController {
 	 public Result policyApproval(@RequestParam(name="id") Integer id,
 	 							@RequestParam(name="type") Integer type,
 								  @RequestParam(name="userId") String userId,
-								@RequestParam(name="approvalContent",required=false) String approvalContent){
+								@RequestParam(name="approvalContent",required=false) String approvalContent) {
 
-		CwjsPolicyInfo cwjsPolicyInfo = cwjsPolicyInfoService.getById(id);
-		 if(cwjsPolicyInfo==null) {
+		 CwjsPolicyInfo cwjsPolicyInfo = cwjsPolicyInfoService.getById(id);
+		 if (cwjsPolicyInfo == null) {
 			 return Result.error("政策不存在或已被删除,请重新选择要审核的政策。");
 		 }
 		 cwjsPolicyInfo.setLoginUserId(userId);
@@ -151,32 +151,32 @@ public class CwjsPolicyInfoController {
 		 String approvalUser = cwjsPolicyInfo.getApprovedProgress();
 
 		 //政策所属销售的部门 和 上级
-		 JSONObject examineUser = cwjsPolicyInfoMapper.getUserLeaderAndDirectorByRoleName(cwjsPolicyInfo.getCreateUserId(),"分公司总经理");
+		 JSONObject examineUser = cwjsPolicyInfoMapper.getUserLeaderAndDirectorByRoleName(cwjsPolicyInfo.getCreateUserId(), "分公司总经理");
 		 String firstAudit = "";//第一次审核人
 
 		 // 提交 - 待审核
 		 //华北==> 法务  其他===> 销售上级
-		 if(type == 1){
-		 	if (cwjsPolicyInfo.getAdvancePay() == 0 && cwjsPolicyInfo.getCustomerFlag() == 0){
-				//第一次审核人 -- 法务(法务有多个用户 无法判断审核人 所以 法务审核人为 角色code legalAffairs 占位)
-				//firstAudit = examineUser.getString("directorId");
-				firstAudit = "legalAffairs";
-			}else {
-				//查询创建人角色 -- 自己创建的
-				String createUserRole = roleService.getRoleCodeByUserId(cwjsPolicyInfo.getCreateUserId());
-				if (StringUtils.equals("saleDirector",createUserRole)){
-					firstAudit = cwjsPolicyInfo.getCreateUserId();
-				}else {
-					//销售的 上级
-					firstAudit = examineUser.getString("leaderId");
-				}
-			}
+		 if (type == 1) {
+			 if (cwjsPolicyInfo.getAdvancePay() == 0 && cwjsPolicyInfo.getCustomerFlag() == 0) {
+				 //第一次审核人 -- 法务(法务有多个用户 无法判断审核人 所以 法务审核人为 角色code legalAffairs 占位)
+				 //firstAudit = examineUser.getString("directorId");
+				 firstAudit = "legalAffairs";
+			 } else {
+				 //查询创建人角色 -- 自己创建的
+				 String createUserRole = roleService.getRoleCodeByUserId(cwjsPolicyInfo.getCreateUserId());
+				 if (StringUtils.equals("saleDirector", createUserRole)) {
+					 firstAudit = cwjsPolicyInfo.getCreateUserId();
+				 } else {
+					 //销售的 上级
+					 firstAudit = examineUser.getString("leaderId");
+				 }
+			 }
 
 			 cwjsPolicyInfo.setApprovedStatus(1);
 			 cwjsPolicyInfo.setApprovedProgress(firstAudit);
 
 
-			 if(StringUtils.equals(firstAudit,"legalAffairs")){
+			 if (StringUtils.equals(firstAudit, "legalAffairs")) {
 				 List<JSONObject> legalUserList = cwjsPolicyInfoService.getLegalAffairsUsers();
 				 for (JSONObject jsonObject : legalUserList) {
 					 JSONObject wChatIdByUserId = mailLogMapper.getWChatIdByUserId(jsonObject.getString("userId"));
@@ -184,7 +184,7 @@ public class CwjsPolicyInfoController {
 					 text.append("您有一条销售政策需要审核,该客户为:");
 					 text.append(cwjsPolicyInfo.getCompanyName());
 					 text.append(",请及时登录助手平台-销售政策页面进行审核,谢谢!");
-					 corpWexinUtils.sendMessageByWeChatId(wChatIdByUserId,text.toString());
+					 corpWexinUtils.sendMessageByWeChatId(wChatIdByUserId, text.toString());
 				 }
 			 } else {
 				 JSONObject wChatIdByUserId = mailLogMapper.getWChatIdByUserId(cwjsPolicyInfo.getApprovedProgress());
@@ -192,7 +192,7 @@ public class CwjsPolicyInfoController {
 				 text.append("您有一条销售政策需要审核,该客户为:");
 				 text.append(cwjsPolicyInfo.getCompanyName());
 				 text.append(",请及时登录助手平台-销售政策页面进行审核,谢谢!");
-				 corpWexinUtils.sendMessageByWeChatId(wChatIdByUserId,text.toString());
+				 corpWexinUtils.sendMessageByWeChatId(wChatIdByUserId, text.toString());
 			 }
 
 			 //添加记录
@@ -204,78 +204,77 @@ public class CwjsPolicyInfoController {
 			 policyApprovalLog.setCreateTime(new Date());
 			 policyApprovalLogService.save(policyApprovalLog);
 
-		}
+		 }
 		 //审核通过 是不是终审,不是就给当前的下一个人发企业微信
-		 if(type == 2){
+		 if (type == 2) {
 
 
 			 //第一个审核人 - 法务
-		 	if(approvalUser.equals("legalAffairs")){
-				//查询创建人角色 -- 自己创建的
-				String createUserRole = roleService.getRoleCodeByUserId(cwjsPolicyInfo.getCreateUserId());
-				if (StringUtils.equals("saleDirector",createUserRole)){
-					cwjsPolicyInfo.setApprovedStatus(1);
-					cwjsPolicyInfo.setApprovedProgress(cwjsPolicyInfo.getCreateUserId());	//设置一下个审核人员  是自己
-				}else{
-					cwjsPolicyInfo.setApprovedStatus(1);
-					cwjsPolicyInfo.setApprovedProgress(examineUser.getString("leaderId"));	//设置一下个审核人员  上级
-				}
-		 	}
-
+			 if (approvalUser.equals("legalAffairs")) {
+				 //查询创建人角色 -- 自己创建的
+				 String createUserRole = roleService.getRoleCodeByUserId(cwjsPolicyInfo.getCreateUserId());
+				 if (StringUtils.equals("saleDirector", createUserRole)) {
+					 cwjsPolicyInfo.setApprovedStatus(1);
+					 cwjsPolicyInfo.setApprovedProgress(cwjsPolicyInfo.getCreateUserId());    //设置一下个审核人员  是自己
+				 } else {
+					 cwjsPolicyInfo.setApprovedStatus(1);
+					 cwjsPolicyInfo.setApprovedProgress(examineUser.getString("leaderId"));    //设置一下个审核人员  上级
+				 }
+			 }
 
 
 			 //查询审核人角色
 			 String roleCode = roleService.getRoleCodeByUserId(approvalUser);
 
 			 //第二个审核人 = 上级 = 销售总监
-		 	//if(approvalUser.equals(examineUser.getString("leaderId"))){
-		 	if(StringUtils.equals("saleDirector",roleCode)){//审核人角色为销售总监
-		 		if(examineUser.getString("departName").contains("渠道")){
-					cwjsPolicyInfo.setApprovedStatus(3);
-					cwjsPolicyInfoService.updateById(cwjsPolicyInfo);
-
-					/**
-					 * 终审通过后 添加 起始时间
-					 */
-					reportSettlementService.cwjsPRofit(cwjsPolicyInfo);
-					return Result.successMsg("审核通过",cwjsPolicyInfo);
-				}
-
-				if(examineUser.getString("departName").contains("销售")){
-					//华北 ---> 自动转老板
-					if (cwjsPolicyInfo.getCompanyId().equals("d57fecdcf7a94d009736d9c850731582")){
-						//查询 是否符合条件
-						List<JSONObject> autoConveryList = cwjsPolicyInfoMapper.selAutoConveryInfo(cwjsPolicyInfo.getAccountingPeriod(),cwjsPolicyInfo.getMediaType(),
-								cwjsPolicyInfo.getAdvancePay(),cwjsPolicyInfo.getRebateType(),cwjsPolicyInfo.getRebateRate());
-						if (!Check.isNull(autoConveryList)){
-							cwjsPolicyInfoService.automaticConveyBossExamine(cwjsPolicyInfo);
-							cwjsPolicyInfoService.updateById(cwjsPolicyInfo);
-							log.info("-----自动转老板");
-							return Result.successMsg("审核通过",cwjsPolicyInfo);
-						}else {
-							//结束
-							cwjsPolicyInfo.setApprovedStatus(3);
-							cwjsPolicyInfoService.updateById(cwjsPolicyInfo);
-
-							/**
-							 * 终审通过后 添加 起始时间
-							 */
-							reportSettlementService.cwjsPRofit(cwjsPolicyInfo);
-							return Result.successMsg("审核通过",cwjsPolicyInfo);
-
-						}
-					}else {
-						// 下一步审核 分公司总经理
-						cwjsPolicyInfo.setApprovedStatus(1);
-						cwjsPolicyInfo.setApprovedProgress(examineUser.getString("directorId"));	//设置一下个审核人员  分公司总经理
+			 //if(approvalUser.equals(examineUser.getString("leaderId"))){
+			 if (StringUtils.equals("saleDirector", roleCode)) {//审核人角色为销售总监
+				 if (examineUser.getString("departName").contains("渠道")) {
+					 cwjsPolicyInfo.setApprovedStatus(3);
+					 cwjsPolicyInfoService.updateById(cwjsPolicyInfo);
+
+					 /**
+					  * 终审通过后 添加 起始时间
+					  */
+					 reportSettlementService.cwjsPRofit(cwjsPolicyInfo);
+					 return Result.successMsg("审核通过", cwjsPolicyInfo);
+				 }
 
-					}
-				}
+				 if (examineUser.getString("departName").contains("销售")) {
+					 //华北 ---> 自动转老板
+					 if (cwjsPolicyInfo.getCompanyId().equals("d57fecdcf7a94d009736d9c850731582")) {
+						 //查询 是否符合条件
+						 List<JSONObject> autoConveryList = cwjsPolicyInfoMapper.selAutoConveryInfo(cwjsPolicyInfo.getAccountingPeriod(), cwjsPolicyInfo.getMediaType(),
+								 cwjsPolicyInfo.getAdvancePay(), cwjsPolicyInfo.getRebateType(), cwjsPolicyInfo.getRebateRate());
+						 if (!Check.isNull(autoConveryList)) {
+							 cwjsPolicyInfoService.automaticConveyBossExamine(cwjsPolicyInfo);
+							 cwjsPolicyInfoService.updateById(cwjsPolicyInfo);
+							 log.info("-----自动转老板");
+							 return Result.successMsg("审核通过", cwjsPolicyInfo);
+						 } else {
+							 //结束
+							 cwjsPolicyInfo.setApprovedStatus(3);
+							 cwjsPolicyInfoService.updateById(cwjsPolicyInfo);
+
+							 /**
+							  * 终审通过后 添加 起始时间
+							  */
+							 reportSettlementService.cwjsPRofit(cwjsPolicyInfo);
+							 return Result.successMsg("审核通过", cwjsPolicyInfo);
+
+						 }
+					 } else {
+						 // 下一步审核 分公司总经理
+						 cwjsPolicyInfo.setApprovedStatus(1);
+						 cwjsPolicyInfo.setApprovedProgress(examineUser.getString("directorId"));    //设置一下个审核人员  分公司总经理
+
+					 }
+				 }
 
-			}
+			 }
 
-		 	//第三个审核人- 分公司总经理
-			 if(approvalUser.equals(examineUser.getString("directorId"))){
+			 //第三个审核人- 分公司总经理
+			 if (approvalUser.equals(examineUser.getString("directorId"))) {
 				 cwjsPolicyInfo.setApprovedStatus(3);
 				 cwjsPolicyInfoService.updateById(cwjsPolicyInfo);
 
@@ -284,11 +283,11 @@ public class CwjsPolicyInfoController {
 				  * 终审通过后 添加 起始时间
 				  */
 				 reportSettlementService.cwjsPRofit(cwjsPolicyInfo);
-				 return Result.successMsg("审核通过",cwjsPolicyInfo);
+				 return Result.successMsg("审核通过", cwjsPolicyInfo);
 			 }
 
 			 //老板
-			 if (approvalUser.equals(userId) && userId.equals("80e747cdea6f41dbbc8cde23046fd4e0")){
+			 if (approvalUser.equals(userId) && userId.equals("80e747cdea6f41dbbc8cde23046fd4e0")) {
 				 cwjsPolicyInfo.setApprovedStatus(3);
 				 cwjsPolicyInfoService.updateById(cwjsPolicyInfo);
 
@@ -296,60 +295,66 @@ public class CwjsPolicyInfoController {
 				  * 终审通过后 添加 起始时间
 				  */
 				 reportSettlementService.cwjsPRofit(cwjsPolicyInfo);
-				 return Result.successMsg("审核通过",cwjsPolicyInfo);
+				 return Result.successMsg("审核通过", cwjsPolicyInfo);
 			 }
 
 
-
-
 			 JSONObject wChatIdByUserId = mailLogMapper.getWChatIdByUserId(cwjsPolicyInfo.getApprovedProgress());
 			 StringBuilder text = new StringBuilder();
 			 text.append("您有一条销售政策需要审核,该客户为:");
 			 text.append(cwjsPolicyInfo.getCompanyName());
 			 text.append(",请及时登录助手平台-销售政策页面进行审核,谢谢!");
-			 corpWexinUtils.sendMessageByWeChatId(wChatIdByUserId,text.toString());
+			 corpWexinUtils.sendMessageByWeChatId(wChatIdByUserId, text.toString());
 
-			CwjsPolicyApprovalLog policyApprovalLog = new CwjsPolicyApprovalLog();
-			policyApprovalLog.setPolicyId(id);
-			policyApprovalLog.setCreateUserId(userId);
-			policyApprovalLog.setApprovalStatus(0);
+			 CwjsPolicyApprovalLog policyApprovalLog = new CwjsPolicyApprovalLog();
+			 policyApprovalLog.setPolicyId(id);
+			 policyApprovalLog.setCreateUserId(userId);
+			 policyApprovalLog.setApprovalStatus(0);
 			 policyApprovalLog.setApprovalContent(Check.isNull(approvalContent) ? "审核通过" : approvalContent);
 			 policyApprovalLog.setCreateTime(new Date());
-			policyApprovalLogService.save(policyApprovalLog);
+			 policyApprovalLogService.save(policyApprovalLog);
 
-		}
-	 	if(type == 3){	//审核拒绝	给申请人发企业微信
-			cwjsPolicyInfo.setApprovedStatus(4);
+		 }
+		 if (type == 3) {    //审核拒绝	给申请人发企业微信
+			 cwjsPolicyInfo.setApprovedStatus(4);
 
-			CwjsPolicyApprovalLog policyApprovalLog = new CwjsPolicyApprovalLog();
-			policyApprovalLog.setApprovalStatus(1);
-			policyApprovalLog.setPolicyId(id);
-			policyApprovalLog.setCreateUserId(userId);
-			policyApprovalLog.setApprovalContent(Check.isNull(approvalContent) ? "审核拒绝" : approvalContent);
-			policyApprovalLog.setCreateTime(new Date());
-			policyApprovalLogService.save(policyApprovalLog);
+			 CwjsPolicyApprovalLog policyApprovalLog = new CwjsPolicyApprovalLog();
+			 policyApprovalLog.setApprovalStatus(1);
+			 policyApprovalLog.setPolicyId(id);
+			 policyApprovalLog.setCreateUserId(userId);
+			 policyApprovalLog.setApprovalContent(Check.isNull(approvalContent) ? "审核拒绝" : approvalContent);
+			 policyApprovalLog.setCreateTime(new Date());
+			 policyApprovalLogService.save(policyApprovalLog);
 
 
-			JSONObject wChatIdByUserId = mailLogMapper.getWChatIdByUserId(cwjsPolicyInfo.getCreateUserId());
-			StringBuilder text = new StringBuilder();
-			text.append("您有一条销售政策审核未通过,客户为:");
-			text.append(cwjsPolicyInfo.getCompanyName());
-			text.append(",请及时登录助手平台-销售政策页面进行政策修改,谢谢!");
-			corpWexinUtils.sendMessageByWeChatId(wChatIdByUserId,text.toString());
-		}
+			 JSONObject wChatIdByUserId = mailLogMapper.getWChatIdByUserId(cwjsPolicyInfo.getCreateUserId());
+			 StringBuilder text = new StringBuilder();
+			 text.append("您有一条销售政策审核未通过,客户为:");
+			 text.append(cwjsPolicyInfo.getCompanyName());
+			 text.append(",请及时登录助手平台-销售政策页面进行政策修改,谢谢!");
+			 corpWexinUtils.sendMessageByWeChatId(wChatIdByUserId, text.toString());
+		 }
 
-	 	//手动-转领导审批 只有审核人是最后一个人的时候 才可以转领导
-	 	if (type == 4){
-			// 最后一个审核人员
-			if (!approvalUser.equals(examineUser.getString("leaderId")) && !approvalUser.equals(examineUser.getString("directorId"))){
-				return Result.errorMsg("当前审核人不是最后一个审核人员,无法转领导审批。");
-			}
+		 //手动-转领导审批 只有审核人是最后一个人的时候 才可以转领导
+		 if (type == 4) {
+			 //查询创建人角色
+			 String createUserRole = roleService.getRoleCodeByUserId(cwjsPolicyInfo.getCreateUserId());
+			 if (StringUtils.equals("saleDirector", createUserRole)) {
+				 if (approvalUser.equals(userId)) {
+					 cwjsPolicyInfoService.automaticConveyBossExamine(cwjsPolicyInfo);
+				 }
+			 } else {
+				 // 最后一个审核人员
+				 if (!approvalUser.equals(examineUser.getString("leaderId")) && !approvalUser.equals(examineUser.getString("directorId"))) {
+					 return Result.errorMsg("当前审核人不是最后一个审核人员,无法转领导审批。");
+				 }
 
-			cwjsPolicyInfoService.automaticConveyBossExamine(cwjsPolicyInfo);
-		}
+				 cwjsPolicyInfoService.automaticConveyBossExamine(cwjsPolicyInfo);
+			 }
+		 }
+			 cwjsPolicyInfoService.updateById(cwjsPolicyInfo);
+			 return Result.successMsg(type == 3 ? "审核拒绝" : "审核通过", cwjsPolicyInfo);
 
-		cwjsPolicyInfoService.updateById(cwjsPolicyInfo);
-	 	return Result.successMsg(type ==  3 ? "审核拒绝" : "审核通过",cwjsPolicyInfo);
 	 }