Browse Source

用户申请团队

黄远 5 years ago
parent
commit
29a268c23c

+ 18 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/constants/CommonConstants.java

@@ -0,0 +1,18 @@
+package cn.com.ty.lift.system.constants;
+
+/**
+ * @author huangyuan
+ * @date 2019-12-17
+ * @description 公共常量
+ */
+public class CommonConstants {
+    /**
+     * 返回码字段常量
+     */
+    public static final String RETURN_CODE_FIELD = "code";
+
+    /**
+     * 返回信息字段常量
+     */
+    public static final String RETURN_MSG_FIELD = "message";
+}

+ 14 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/user/controller/MtCompanyUserController.java

@@ -4,6 +4,7 @@ import cn.com.ty.lift.system.user.dao.entity.model.MtCompanyUserRequest;
 import cn.com.ty.lift.system.user.service.IMtCompanyUserService;
 import cn.com.xwy.boot.web.dto.RestResponse;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -20,6 +21,8 @@ public class MtCompanyUserController {
     @Autowired
     private IMtCompanyUserService mtCompanyUserService;
 
+
+
     /**
      * @description 企业分配角色
      * @date 2019/11/27 10:03 AM
@@ -41,4 +44,15 @@ public class MtCompanyUserController {
     public RestResponse getCompanyUser(@RequestBody MtCompanyUserRequest mtCompanyUserRequest){
         return mtCompanyUserService.getCompanyMembers(mtCompanyUserRequest);
     }
+
+    /***
+     * @description 踢出团队
+     * @date 2019-12-17 10:10
+     * @param mtCompanyUserRequest companyId:公司id, userId:用户id
+     * @return
+     */
+    @PostMapping("/kickOutTeam")
+    public RestResponse kickOutTeam(@RequestBody MtCompanyUserRequest mtCompanyUserRequest){
+        return mtCompanyUserService.kickOutTeam(mtCompanyUserRequest);
+    }
 }

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

@@ -9,6 +9,7 @@ import lombok.Data;
  */
 @Data
 public class MtCompanyUserRequest {
+    private Long id;
     private Long companyId;//公司id
     private Long userId;//用户id
     private Long roleId;//角色id

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

@@ -0,0 +1,29 @@
+package cn.com.ty.lift.system.user.dao.entity.model;
+
+import lombok.Data;
+
+/**
+ * @author huangyuan
+ * @date 2019-12-17
+ * @description 项目用户关联表
+ */
+@Data
+public class ProjectUser {
+
+    /**
+     * 用户id
+     */
+    private Long userId;
+
+    /**
+     * 公司id
+     */
+    private Long companyId;//维保公司id
+
+    public ProjectUser(){}
+
+    public ProjectUser(Long userId, Long companyId){
+        this.userId = userId;
+        this.companyId = companyId;
+    }
+}

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

@@ -1,5 +1,6 @@
 package cn.com.ty.lift.system.user.dao.mapper;
 
+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;
@@ -10,4 +11,19 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 @MyBatisMapper
 public interface MtCompanyUserMapper extends BaseMapper<MtCompanyUser> {
+    /***
+     * @description 获取用户在该公司关联的项目
+     * @date 2019-12-17 09:26
+     * @param
+     * @return
+     */
+    Long getCompanyUserProject(ProjectUser projectUser);
+
+    /***
+     * @description 获取用户在当前公司有没有正在进行的急修任务
+     * @date 2019-12-17 09:56
+     * @param
+     * @return
+     */
+    Long getCompanyUserEmergency(ProjectUser projectUser);
 }

+ 8 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/IMtCompanyUserService.java

@@ -26,4 +26,12 @@ public interface IMtCompanyUserService extends IService<MtCompanyUser> {
      * @return
      */
     RestResponse getCompanyMembers(MtCompanyUserRequest mtCompanyUserRequest);
+
+    /**
+     * @description 踢出团队
+     * @date 2019-12-16 17:52
+     * @param
+     * @return
+     */
+    RestResponse kickOutTeam(MtCompanyUserRequest mtCompanyUserRequest);
 }

+ 22 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/IProjectService.java

@@ -0,0 +1,22 @@
+package cn.com.ty.lift.system.user.service;
+
+import cn.com.ty.lift.system.user.dao.entity.model.ProjectUser;
+
+import java.util.Map;
+
+/**
+ * @author huangyuan
+ * @date 2019-12-17
+ * @description 项目处理
+ */
+public interface IProjectService {
+
+    /**
+     * @description 判断用户是否能踢出团队
+     * @date 2019-12-17 09:20
+     * @param projectUser userId:用户id,companyId:公司id
+     * @return
+     */
+    Map<String, String> judgeKickOutTeam(ProjectUser projectUser);
+
+}

+ 26 - 8
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/MtCompanyUserService.java

@@ -1,17 +1,19 @@
 package cn.com.ty.lift.system.user.service.impl;
 
 import cn.com.ty.lift.common.constants.ApiConstants;
+import cn.com.ty.lift.common.utils.ProjectUtils;
+import cn.com.ty.lift.system.constants.CommonConstants;
 import cn.com.ty.lift.system.user.dao.entity.MtCompanyUser;
 import cn.com.ty.lift.system.user.dao.entity.UserInfo;
 import cn.com.ty.lift.system.user.dao.entity.UserRole;
 import cn.com.ty.lift.system.user.dao.entity.model.MtCompanyUserRequest;
+import cn.com.ty.lift.system.user.dao.entity.model.ProjectUser;
 import cn.com.ty.lift.system.user.dao.entity.model.UserResponse;
 import cn.com.ty.lift.system.user.dao.mapper.MtCompanyUserMapper;
 import cn.com.ty.lift.system.user.service.IMtCompanyUserService;
-import cn.com.ty.lift.system.user.service.IUserAccountService;
+import cn.com.ty.lift.system.user.service.IProjectService;
 import cn.com.ty.lift.system.user.service.IUserInfoService;
 import cn.com.ty.lift.system.user.service.IUserRoleService;
-import cn.com.ty.lift.common.utils.ProjectUtils;
 import cn.com.xwy.boot.web.dto.RestResponse;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -35,10 +37,10 @@ public class MtCompanyUserService extends ServiceImpl<MtCompanyUserMapper, MtCom
     private IUserRoleService userRoleService;
 
     @Autowired
-    private IUserAccountService userAccountService;
+    private IUserInfoService userInfoService;
 
     @Autowired
-    private IUserInfoService userInfoService;
+    private IProjectService projectService;
 
     @Override
     @Transactional
@@ -78,19 +80,19 @@ public class MtCompanyUserService extends ServiceImpl<MtCompanyUserMapper, MtCom
         List<UserResponse> userResponseList = new ArrayList<>();
         List<MtCompanyUser> mtCompanyUserList = this.list(new QueryWrapper<MtCompanyUser>()
                 .eq("mt_company_id", mtCompanyUserRequest.getCompanyId()));
-        if(mtCompanyUserList != null && mtCompanyUserList.size() > 0){
+        if (mtCompanyUserList != null && mtCompanyUserList.size() > 0) {
             //获取用户id集合
             List<Long> userIdList = ProjectUtils.getAttrList(mtCompanyUserList, "userId", null);
             //获取用户信息集合
             List<UserInfo> userInfoList = (List<UserInfo>) userInfoService.listByIds(userIdList);
             Map<Long, UserInfo> userIdToUserInfo = ProjectUtils.attrToObjMap(userInfoList, "userId", null);
-            if(userIdToUserInfo != null && userIdToUserInfo.size() > 0){
-                for(Long userId: userIdList){
+            if (userIdToUserInfo != null && userIdToUserInfo.size() > 0) {
+                for (Long userId : userIdList) {
                     //封装用户信息
                     UserResponse userResponse = new UserResponse();
                     userResponse.setUserId(userId);
                     UserInfo userInfo = userIdToUserInfo.get(userId);
-                    if(userInfo != null){
+                    if (userInfo != null) {
                         userResponse.setName(userInfo.getName());
                     }
                     userResponseList.add(userResponse);
@@ -100,4 +102,20 @@ public class MtCompanyUserService extends ServiceImpl<MtCompanyUserMapper, MtCom
         return RestResponse.ok(userResponseList, ApiConstants.RESULT_SUCCESS, "获取团队用户成功");
     }
 
+    @Override
+    public RestResponse kickOutTeam(MtCompanyUserRequest mtCompanyUserRequest) {
+        //判断用户是否可以踢出团队
+        ProjectUser projectUser = new ProjectUser(mtCompanyUserRequest.getUserId(), mtCompanyUserRequest.getCompanyId());
+        Map<String, String> judgeMsg = projectService.judgeKickOutTeam(projectUser);
+        //获取判断返回的状态码
+        String code = judgeMsg.get(CommonConstants.RETURN_CODE_FIELD);
+        if(ApiConstants.RESULT_ERROR.equals(code)){
+            return RestResponse.error(ApiConstants.RESULT_ERROR, judgeMsg.get(CommonConstants.RETURN_MSG_FIELD));
+        }
+        MtCompanyUser mtCompanyUser = this.getById(mtCompanyUserRequest.getId());
+        mtCompanyUser.setStatus(ApiConstants.ApplicationConstants.COMPANY_USER_FAIL);
+        this.updateById(mtCompanyUser);
+        return RestResponse.ok(null, ApiConstants.RESULT_SUCCESS, "踢出用户成功");
+    }
+
 }

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

@@ -0,0 +1,46 @@
+package cn.com.ty.lift.system.user.service.impl;
+
+import cn.com.ty.lift.common.constants.ApiConstants;
+import cn.com.ty.lift.system.constants.CommonConstants;
+import cn.com.ty.lift.system.user.dao.entity.model.ProjectUser;
+import cn.com.ty.lift.system.user.dao.mapper.MtCompanyUserMapper;
+import cn.com.ty.lift.system.user.service.IProjectService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author huangyuan
+ * @date 2019-12-17
+ * @description
+ */
+@Service
+public class ProjectService implements IProjectService {
+
+    @Autowired
+    private MtCompanyUserMapper mtCompanyUserMapper;
+
+    @Override
+    public Map<String, String> judgeKickOutTeam(ProjectUser projectUser) {
+        Map<String, String> returnMsg = new HashMap<>();
+        //获取用户在当前公司的项目
+        Long companyProjectCount = mtCompanyUserMapper.getCompanyUserProject(projectUser);
+        if(companyProjectCount != null && companyProjectCount > 0L){
+            returnMsg.put(CommonConstants.RETURN_CODE_FIELD, ApiConstants.RESULT_ERROR);
+            returnMsg.put(CommonConstants.RETURN_MSG_FIELD, "无法踢出团队,请先取消用户关联项目");
+            return returnMsg;
+        }
+        //获取用户在当前公司有没有急修任务
+        Long companyEmergencyCount = mtCompanyUserMapper.getCompanyUserEmergency(projectUser);
+        if(companyEmergencyCount != null && companyEmergencyCount > 0L){
+            returnMsg.put(CommonConstants.RETURN_CODE_FIELD, ApiConstants.RESULT_ERROR);
+            returnMsg.put(CommonConstants.RETURN_MSG_FIELD, "无法踢出团队,用户有正在进行的急修项目");
+            return returnMsg;
+        }
+
+        returnMsg.put(CommonConstants.RETURN_CODE_FIELD, ApiConstants.RESULT_SUCCESS);
+        return returnMsg;
+    }
+}

+ 7 - 4
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/RoleService.java

@@ -126,7 +126,10 @@ public class RoleService extends ServiceImpl<RoleMapper, Role> implements IRoleS
                 .eq("user_id", userId)
                 .eq("company_id", companyId)
         );
-        return getById(userRole.getRoleId());
+        if (userRole != null) {
+            getById(userRole.getRoleId());
+        }
+        return null;
     }
 
     @Override
@@ -134,7 +137,7 @@ public class RoleService extends ServiceImpl<RoleMapper, Role> implements IRoleS
     public void saveDefaultMessage(Long companyId) {
         //默认角色列表
         List<Role> defaultRoleList = new ArrayList<>();
-        for (CommonEnum.DefaultRole defaultRole : DefaultMenuConstants.DEFAULT_ROLE){
+        for (CommonEnum.DefaultRole defaultRole : DefaultMenuConstants.DEFAULT_ROLE) {
             Role newRole = new Role(defaultRole);
             newRole.setCompanyId(companyId);
             newRole.setDescription(defaultRole.getLabel());
@@ -146,8 +149,8 @@ public class RoleService extends ServiceImpl<RoleMapper, Role> implements IRoleS
         List<RoleMenu> needSaveRoleMenuList = new ArrayList<>();
         //生成角色菜单关联关系
         for (Role role : defaultRoleList) {
-            Long [] menuIds = DefaultMenuConstants.DEFAULT_ROLE_MENUIDS.get(role.getCode());
-            for(Long menuId: menuIds){
+            Long[] menuIds = DefaultMenuConstants.DEFAULT_ROLE_MENUIDS.get(role.getCode());
+            for (Long menuId : menuIds) {
                 RoleMenu roleMenu = new RoleMenu();
                 roleMenu.setMenuId(menuId);
                 roleMenu.setRoleId(role.getId());

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

@@ -1,13 +1,20 @@
 package cn.com.ty.lift.system.user.service.impl;
 
 import cn.com.ty.lift.common.constants.ApiConstants;
+import cn.com.ty.lift.system.user.dao.entity.MtCompanyUser;
 import cn.com.ty.lift.system.user.dao.entity.UserApplication;
 import cn.com.ty.lift.system.user.dao.entity.model.UserApplyRequest;
 import cn.com.ty.lift.system.user.dao.mapper.UserApplicationMapper;
 import cn.com.ty.lift.system.user.service.IUserApplicationService;
 import cn.com.xwy.boot.web.dto.RestResponse;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.time.LocalDateTime;
+import java.util.Date;
 
 /**
  * <p>
@@ -20,6 +27,9 @@ import org.springframework.stereotype.Service;
 @Service
 public class UserApplicationService extends ServiceImpl<UserApplicationMapper, UserApplication> implements IUserApplicationService {
 
+    @Autowired
+    private MtCompanyUserService mtCompanyUserService;
+
     @Override
     public RestResponse applyTeam(UserApplyRequest userApplyRequest) {
         //判断用户是否申请过
@@ -34,13 +44,46 @@ public class UserApplicationService extends ServiceImpl<UserApplicationMapper, U
     }
 
     @Override
+    @Transactional
     public RestResponse teamPass(UserApplyRequest userApplyRequest) {
+        //操作者id
+        Long operatorId = userApplyRequest.getUserId();
+        //加入团队审核通过
+        UserApplication userApplication = this.getById(userApplyRequest.getId());
+        //1.设置申请信息
+        userApplication.setStatus(ApiConstants.ApplicationConstants.COMPANY_USER_PASS);
+        userApplication.setDealDate(LocalDateTime.now());
+        userApplication.setDealUserId(operatorId);
+        //2.更新公司用户信息
+        Long companyId = userApplication.getMtCompanyId();
+        Long userId = userApplication.getUserId();
+        //获取公司用户信息
+        MtCompanyUser mtCompanyUser = mtCompanyUserService.getOne(new QueryWrapper<MtCompanyUser>()
+            .eq("mt_company_id", companyId)
+            .eq("user_id", userId)
+        );
+        //如果公司用户信息不存在,新建信息
+        if(mtCompanyUser == null){
+            mtCompanyUser = new MtCompanyUser();
+            mtCompanyUser.setMtCompanyId(companyId);
+            mtCompanyUser.setUserId(userId);
+            mtCompanyUser.setCreateUserId(userId);
+            mtCompanyUser.setCreateTime(new Date());
+        }
+        mtCompanyUser.setUpdateTime(new Date());
+        mtCompanyUser.setUpdateUserId(userId);
+        //设置用户状态在团队中
+        mtCompanyUser.setStatus(ApiConstants.ApplicationConstants.COMPANY_USER_PASS);
+
+        this.updateById(userApplication);
+        mtCompanyUserService.saveOrUpdate(mtCompanyUser);
         return RestResponse.ok(null, ApiConstants.RESULT_SUCCESS, "操作成功");
     }
 
     @Override
     public RestResponse teamFail(UserApplyRequest userApplyRequest) {
         UserApplication userApplication = this.getById(userApplyRequest.getId());
+        //设置申请状态为审核不通过
         userApplication.setStatus(ApiConstants.ApplicationConstants.COMPANY_USER_FAIL);
         this.updateById(userApplication);
         return RestResponse.ok(null, ApiConstants.RESULT_SUCCESS, "操作成功");

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

@@ -32,4 +32,19 @@
 		update_user_id, delete_user_id
 	</sql>
 
+	<!-- 获取用户在当前公司所处的项目 -->
+	<select id="getCompanyUserProject" parameterType="cn.com.ty.lift.system.user.dao.entity.model.ProjectUser" resultType="java.lang.Long">
+		select count(1) from project_user pu
+		where pu.mt_company_id = #{companyId,jdbcType=BIGINT}
+		and pu.user_id = #{userId,jdbcType=BIGINT}
+	</select>
+
+	<!-- 获取用户在当前公司有没有正在进行的急修任务 -->
+	<select id="getCompanyUserEmergency" parameterType="cn.com.ty.lift.system.user.dao.entity.model.ProjectUser" resultType="java.lang.Long">
+		select count(1) from emergency_repair er
+		where er.mt_company_id = #{companyId,jdbcType=BIGINT}
+		and er.worker_id = #{userId, jdbcType=BIGINT}
+		and er.status <![CDATA[ <> ]]> 4
+	</select>
+
 </mapper>