Przeglądaj źródła

修改头像和昵称

黄远 5 lat temu
rodzic
commit
d390300282

+ 4 - 3
lift-common/src/main/java/cn.com.ty.lift.common/model/TimeyMessage.java

@@ -53,18 +53,19 @@ public class TimeyMessage implements Serializable {
 
     /**
      * @param pushToUserId 要推送的用户id
-     * @param createUserId 申请的用户id
+     * @param msgType      消息类型
+     * @param content      消息类型
      * @return 返回推送消息
      * @description 推送消息创建
      * @date 2020/4/30 5:13 下午
      */
-    public static TimeyMessage create(long pushToUserId, long createUserId, int msgType, String content) {
+    public static TimeyMessage create(long pushToUserId, int msgType, String content) {
         TimeyMessage timeyMessage = new TimeyMessage();
         timeyMessage.setContent(content);
         timeyMessage.setUserId(pushToUserId);
         timeyMessage.setType(msgType);
         timeyMessage.setCreateTime(LocalDate.now());
-        timeyMessage.setCreateUserId(createUserId);
+        timeyMessage.setCreateUserId(10000L);
         timeyMessage.setViewFlag(WebSocketConstants.IS_NOT_VIEW);
         return timeyMessage;
     }

+ 2 - 3
lift-common/src/main/java/cn.com.ty.lift.common/utils/SendMessageUtil.java

@@ -20,18 +20,17 @@ public class SendMessageUtil {
      * @param jmsMessagingTemplate 推送消息模板
      * @param sendToUserIdList     要推送的用户id
      * @param content              推送的消息内容
-     * @param createUserId         消息创建人id
      * @return 是否推送成功 false 失败 true 成功
      * @description
      * @date 2020/5/2 4:11 下午
      */
     public static boolean sendMessageToPC(JmsMessagingTemplate jmsMessagingTemplate, List<Long> sendToUserIdList,
-                                          String content, long createUserId) {
+                                          String content) {
         if (sendToUserIdList != null && sendToUserIdList.size() > 0) {
             //组合消息
             List<TimeyMessage> timeyMessageList = new ArrayList<>();
             sendToUserIdList.forEach(sendToUserId -> {
-                timeyMessageList.add(TimeyMessage.create(sendToUserId, createUserId,
+                timeyMessageList.add(TimeyMessage.create(sendToUserId,
                         WebSocketConstants.MessageType.TEAM_MSG, content));
             });
             //推送消息

+ 2 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/user/dao/entity/model/ProjectInfo.java

@@ -11,6 +11,8 @@ import lombok.Data;
 public class ProjectInfo {
     private Long projectId;//项目id
     private String projectName;//项目名称
+    private Long companyId;//公司id
     private Long regionId;//区域id
     private String areaName;//区域名称
+    private Long regionDirectorId;//区域主管id
 }

+ 10 - 1
lift-system-service/src/main/java/cn/com/ty/lift/system/user/dao/mapper/MtCompanyUserMapper.java

@@ -1,8 +1,9 @@
 package cn.com.ty.lift.system.user.dao.mapper;
 
+import cn.com.ty.lift.system.user.dao.entity.MtCompanyUser;
 import cn.com.ty.lift.system.user.dao.entity.model.LiftCertificate;
+import cn.com.ty.lift.system.user.dao.entity.model.ProjectInfo;
 import cn.com.ty.lift.system.user.dao.entity.model.ProjectUser;
-import cn.com.ty.lift.system.user.dao.entity.MtCompanyUser;
 import cn.com.xwy.boot.mybatis.MyBatisMapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
@@ -46,4 +47,12 @@ public interface MtCompanyUserMapper extends BaseMapper<MtCompanyUser> {
      * @date 2019-12-28 16:34
      */
     LiftCertificate getLiftCertificateByUserIdAndCompanyId(ProjectUser projectUser);
+
+    /**
+     * @param projectId
+     * @return 项目信息
+     * @description 通过项目id获取项目信息
+     * @date 2020/5/2 11:00 下午
+     */
+    ProjectInfo getProjectById(Long projectId);
 }

+ 10 - 2
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/IProjectService.java

@@ -88,10 +88,18 @@ public interface IProjectService {
     Map<Long, ProjectInfo> getProjectIdToProjectByProjectIdList(List<Long> projectIdList);
 
     /**
-     * @description  删除项目用户
-     * @date 2020-01-06 17:13
      * @param
      * @return
+     * @description 删除项目用户
+     * @date 2020-01-06 17:13
      */
     Long deleteProjectUser(PropertyUserRequest propertyUserRequest);
+
+    /**
+     * @param projectId 项目id
+     * @return 项目信息
+     * @description 通过id获取项目信息
+     * @date 2020/5/2 10:54 下午
+     */
+    ProjectInfo getProjectById(Long projectId);
 }

+ 5 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/ProjectService.java

@@ -115,4 +115,9 @@ public class ProjectService implements IProjectService {
         return userAccountMapper.deleteProjectUser(propertyUserRequest);
     }
 
+    @Override
+    public ProjectInfo getProjectById(Long projectId) {
+        return null;
+    }
+
 }

+ 39 - 1
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/PushUserService.java

@@ -12,6 +12,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
 
@@ -42,6 +43,27 @@ public class PushUserService extends BaseServiceImpl<IPushUserMapper, PushUserIn
         return null;
     }
 
+    /**
+     * @param
+     * @return
+     * @description
+     * @date 2020/5/2 10:46 下午
+     */
+    public List<PushUserInfo> getCompanyUserInfoByRoleCode(Long companyId, String roleCode) {
+        return this.baseMapper.getPushUserInfoByRoleCodes(companyId, Arrays.asList(roleCode));
+    }
+
+    /**
+     * @param companyId 指定公司id
+     * @param roleCodes 角色编码集合
+     * @return 用户信息
+     * @description 推送消息给指定公司指定角色
+     * @date 2020/5/2 10:24 下午
+     */
+    public List<PushUserInfo> getCompanyUserInfoByRoleCodes(Long companyId, List<String> roleCodes) {
+        return this.baseMapper.getPushUserInfoByRoleCodes(companyId, roleCodes);
+    }
+
     /**
      * @param roleCodes 角色编码集合
      * @return 要推送的用户信息
@@ -54,13 +76,29 @@ public class PushUserService extends BaseServiceImpl<IPushUserMapper, PushUserIn
         return this.baseMapper.getPushUserInfoByRoleCodes(companyId, roleCodes);
     }
 
+    /**
+     * @param companyId 当前公司id
+     * @param userId 用户id
+     * @return 推送用户信息
+     * @description
+     * @date 2020/5/2 11:33 下午
+     */
+    public PushUserInfo getCompanyUserInfoByUserId(Long companyId, Long userId) {
+        List<PushUserInfo> pushUserInfoList = this.baseMapper.getPushUserInfoByUserIds(companyId,
+                Collections.singletonList(userId));
+        if (pushUserInfoList != null && pushUserInfoList.size() > 0) {
+            return pushUserInfoList.get(0);
+        }
+        return null;
+    }
+
     /**
      * @param userIdList 用户id集合
      * @return 用户信息
      * @description
      * @date 2020/4/18 7:16 下午
      */
-    public List<PushUserInfo> getPushUserInfoByUserIds(List<Long> userIdList) {
+    public List<PushUserInfo> getUserInfoByUserIds(List<Long> userIdList) {
         //获取当前公司id
         Long companyId = getCurrentCompanyId();
         return this.baseMapper.getPushUserInfoByUserIds(companyId, userIdList);

+ 82 - 44
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/UserApplicationService.java

@@ -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, "操作成功");
     }
 
 }

+ 2 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/UserService.java

@@ -409,6 +409,7 @@ public class UserService implements IUserService {
     public RestResponse modifyAvatar(UserRequest userRequest) {
         UserInfo userInfo = userInfoService.getByUserId(userRequest.getUserId());
         userInfo.setAvatarUrl(userRequest.getAvatarUrl());
+        userInfoService.updateById(userInfo);
         return RestResponse.success(ApiConstants.RESULT_SUCCESS, "修改用户头像成功");
     }
 
@@ -416,6 +417,7 @@ public class UserService implements IUserService {
     public RestResponse modifyName(UserRequest userRequest) {
         UserInfo userInfo = userInfoService.getByUserId(userRequest.getUserId());
         userInfo.setName(userRequest.getName());
+        userInfoService.updateById(userInfo);
         return RestResponse.success(ApiConstants.RESULT_SUCCESS, "修改用户昵称成功");
     }
 

+ 12 - 0
lift-system-service/src/main/resources/mapper/MtCompanyUserMapper.xml

@@ -79,4 +79,16 @@
 		and mt_company_id = #{companyId,jdbcType=BIGINT}
 	</select>
 
+    <!-- 通过项目id获取项目信息 -->
+    <select id="getProjectById"
+            parameterType="java.lang.Long"
+            resultType="cn.com.ty.lift.system.user.dao.entity.model.ProjectInfo">
+        select
+            p.id as projectId,
+            p.name as projectName
+        from project as p
+        where p.id = #{projectId}
+
+    </select>
+
 </mapper>