|
@@ -2,6 +2,8 @@ package cn.com.ty.lift.system.user.service.impl;
|
|
|
|
|
|
import cn.com.ty.lift.common.constants.ApiConstants;
|
|
|
import cn.com.ty.lift.common.constants.CommonEnum;
|
|
|
+import cn.com.ty.lift.common.model.PushMessage;
|
|
|
+import cn.com.ty.lift.common.model.PushUserInfo;
|
|
|
import cn.com.ty.lift.common.utils.ProjectUtils;
|
|
|
import cn.com.ty.lift.common.utils.SendMessageUtil;
|
|
|
import cn.com.ty.lift.system.constants.CommonConstants;
|
|
@@ -24,11 +26,11 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.jms.core.JmsMessagingTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -59,9 +61,19 @@ public class UserApplicationService extends ServiceImpl<UserApplicationMapper, U
|
|
|
@Resource
|
|
|
private IProjectService projectService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private PushUserService pushUserService;
|
|
|
+
|
|
|
@Resource
|
|
|
private JmsMessagingTemplate jmsMessagingTemplate;
|
|
|
|
|
|
+ private static final Map<Integer, String> permission = new HashMap<>();
|
|
|
+
|
|
|
+ static {
|
|
|
+ permission.put(21, "查看权限");
|
|
|
+ permission.put(22, "评价权限");
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public RestResponse apply(UserApplyRequest userApplyRequest, int applyTypeTeam) {
|
|
|
//申请公司id
|
|
@@ -97,17 +109,15 @@ public class UserApplicationService extends ServiceImpl<UserApplicationMapper, U
|
|
|
//申请加入项目时需要设置的信息
|
|
|
userApplication.setPowerType(userApplyRequest.getPowerType());
|
|
|
boolean result = this.saveOrUpdate(userApplication);
|
|
|
-
|
|
|
+ //组合消息内容
|
|
|
+ UserInfo userInfo = userInfoService.getByUserId(applyUserId);
|
|
|
+ String applyName = userInfo.getName();
|
|
|
if (result) {
|
|
|
//申请操作成功,推送消息
|
|
|
if (ApiConstants.ApplicationConstants.APPLY_TYPE_TEAM == applyTypeTeam) {
|
|
|
- RestResponse pushMessageResponse = applyTeamPushMessage(companyId, applyUserId);
|
|
|
- if (pushMessageResponse != null) {
|
|
|
- return pushMessageResponse;
|
|
|
- }
|
|
|
+ applyTeamPushMessage(companyId, applyName);
|
|
|
} else {
|
|
|
- //申请加入团队,将消息推送到app端
|
|
|
-
|
|
|
+ applyProjectPushMessage(userApplyRequest, companyId, applyName);
|
|
|
}
|
|
|
} else {
|
|
|
return RestResponse.fail(ApiConstants.RESULT_ERROR, "申请失败");
|
|
@@ -115,26 +125,6 @@ public class UserApplicationService extends ServiceImpl<UserApplicationMapper, U
|
|
|
return RestResponse.success(null, ApiConstants.RESULT_SUCCESS, "申请成功");
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- @Transactional
|
|
|
- public RestResponse applyPass(UserApplyRequest userApplyRequest) {
|
|
|
- //加入团队审核通过
|
|
|
- UserApplication userApplication = this.getById(userApplyRequest.getId());
|
|
|
- //设置申请信息
|
|
|
- userApplication.setStatus(ApiConstants.ApplicationConstants.APPLY_PASS);
|
|
|
- userApplication.setDealDate(LocalDateTime.now());
|
|
|
- userApplication.setDealUserId(userApplyRequest.getUserId());
|
|
|
- if (ApiConstants.ApplicationConstants.APPLY_TYPE_TEAM == userApplication.getType()) {
|
|
|
- //团队审核通过
|
|
|
- teamPass(userApplyRequest, userApplication);
|
|
|
- } else {
|
|
|
- //项目审核通过
|
|
|
- projectPass(userApplication);
|
|
|
- }
|
|
|
- this.updateById(userApplication);
|
|
|
- return RestResponse.success(null, ApiConstants.RESULT_SUCCESS, "操作成功");
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public RestResponse applyFail(UserApplyRequest userApplyRequest) {
|
|
|
UserApplication userApplication = this.getById(userApplyRequest.getId());
|
|
@@ -338,30 +328,78 @@ public class UserApplicationService extends ServiceImpl<UserApplicationMapper, U
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param companyId 公司id
|
|
|
- * @param applyUserId 申请人id
|
|
|
+ * @param companyId 公司id
|
|
|
+ * @param applyName 申请人名称
|
|
|
* @return 推送信息
|
|
|
* @description 申请加入团队将消息推送给pc端文员
|
|
|
* @date 2020/5/2 4:18 下午
|
|
|
*/
|
|
|
- private RestResponse applyTeamPushMessage(long companyId, long applyUserId) {
|
|
|
- //组合消息内容
|
|
|
- UserInfo userInfo = userInfoService.getByUserId(applyUserId);
|
|
|
- if (userInfo == null) {
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
- return RestResponse.fail(ApiConstants.RESULT_ERROR, "用户信息不存在,无法申请");
|
|
|
- }
|
|
|
+ private boolean applyTeamPushMessage(long companyId, String applyName) {
|
|
|
MaintenanceCompany maintenanceCompany = maintenanceCompanyService.getById(companyId);
|
|
|
- if (maintenanceCompany == null) {
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
- return RestResponse.fail(ApiConstants.RESULT_ERROR, "申请加入的团队不存在");
|
|
|
- }
|
|
|
- String content = userInfo.getName() + "申请加入" + maintenanceCompany.getName();
|
|
|
+ String teamName = maintenanceCompany.getName();
|
|
|
+ String content = applyName + "申请加入" + teamName;
|
|
|
//申请加入团队成功,给公司所有文员推送信息
|
|
|
List<Long> clerkIds = userService.getUserIdByCompanyIdAndRoleCode(companyId,
|
|
|
CommonEnum.DefaultRole.CLERK.getCode());
|
|
|
- SendMessageUtil.sendMessageToPC(jmsMessagingTemplate, clerkIds, content, applyUserId);
|
|
|
- return null;
|
|
|
+ return SendMessageUtil.sendMessageToPC(jmsMessagingTemplate, clerkIds, content);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param userApplyRequest 申请信息
|
|
|
+ * @param companyId 申请的项目所在的公司
|
|
|
+ * @param applyName 申请名称
|
|
|
+ * @return false 失败 true 成功
|
|
|
+ * @description 申请加入项目成功后推送消息
|
|
|
+ * @date 2020/5/2 11:50 下午
|
|
|
+ */
|
|
|
+ private boolean applyProjectPushMessage(UserApplyRequest userApplyRequest, long companyId, String applyName) {
|
|
|
+ //申请加入项目,推送消息
|
|
|
+ //项目所在区域的区域主管,以及所有文员
|
|
|
+ List<PushUserInfo> pushUserInfoList = pushUserService.getCompanyUserInfoByRoleCode(companyId,
|
|
|
+ CommonEnum.DefaultRole.CLERK.getCode());
|
|
|
+ //获取项目所在的区域主管的信息
|
|
|
+ ProjectInfo projectInfo = projectService.getProjectById(userApplyRequest.getProjectId());
|
|
|
+ if (projectInfo.getRegionDirectorId() != null) {
|
|
|
+ PushUserInfo regionDirector = pushUserService.getCompanyUserInfoByUserId(companyId,
|
|
|
+ projectInfo.getRegionDirectorId());
|
|
|
+ if (regionDirector != null) {
|
|
|
+ pushUserInfoList.add(regionDirector);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (pushUserInfoList != null && pushUserInfoList.size() > 0) {
|
|
|
+ //将消息推送到app端
|
|
|
+ PushMessage pushMessage = PushMessage.workApplyPermission(applyName, projectInfo.getProjectName(),
|
|
|
+ permission.get(userApplyRequest.getPowerType()));
|
|
|
+ //消息内容
|
|
|
+ String content = pushMessage.getContent();
|
|
|
+ pushMessage.sendTokenOnPlatform(jmsMessagingTemplate, pushUserInfoList);
|
|
|
+ //将消息推送到pc端
|
|
|
+ List<Long> userIdList = pushUserInfoList.stream().map(PushUserInfo::getUserId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ SendMessageUtil.sendMessageToPC(jmsMessagingTemplate, userIdList, content);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public RestResponse applyPass(UserApplyRequest userApplyRequest) {
|
|
|
+ //加入团队审核通过
|
|
|
+ UserApplication userApplication = this.getById(userApplyRequest.getId());
|
|
|
+ //设置申请信息
|
|
|
+ userApplication.setStatus(ApiConstants.ApplicationConstants.APPLY_PASS);
|
|
|
+ userApplication.setDealDate(LocalDateTime.now());
|
|
|
+ userApplication.setDealUserId(userApplyRequest.getUserId());
|
|
|
+ if (ApiConstants.ApplicationConstants.APPLY_TYPE_TEAM == userApplication.getType()) {
|
|
|
+ //团队审核通过
|
|
|
+ teamPass(userApplyRequest, userApplication);
|
|
|
+ } else {
|
|
|
+ //项目审核通过
|
|
|
+ projectPass(userApplication);
|
|
|
+ }
|
|
|
+ this.updateById(userApplication);
|
|
|
+ return RestResponse.success(null, ApiConstants.RESULT_SUCCESS, "操作成功");
|
|
|
}
|
|
|
|
|
|
}
|