浏览代码

角色代码优化

黄远 5 年之前
父节点
当前提交
4df402ec0d

+ 3 - 0
lift-system-service/src/main/java/cn/com/ty/lift/system/settings/dao/entity/model/CompanyAttestationResponse.java

@@ -13,6 +13,7 @@ import java.time.LocalDateTime;
 @Data
 public class CompanyAttestationResponse {
     private Long id;//申请信息id
+    private Long mtCompanyId;//企业公司id
     private String logoImg;//logo路径
     private String attestationName;//公司名称
     private String contactsName;//联系人
@@ -20,6 +21,8 @@ public class CompanyAttestationResponse {
     private String businessLicenseAnnex;//企业营业执照路径
     private String taxRegistration;//资质证书
     private String createUser;//创建人
+    private Integer limitedNum;//电梯台量
+    private Integer vipFlag;//是否vip标识,0:不是vip,1:是vip
     private LocalDateTime createTime;//申请时间
     private LocalDateTime dealTime;//处理时间
     private String customerManagerName;//客户经理名称

+ 38 - 9
lift-system-service/src/main/java/cn/com/ty/lift/system/settings/service/impl/MtCompanyAttestationServiceImpl.java

@@ -76,6 +76,13 @@ public class MtCompanyAttestationServiceImpl extends ServiceImpl<MtCompanyAttest
             PojoUtils.pojoCopy(mtCompanyAttestationInfo, mtCompanyAttestation);
             mtCompanyAttestation = mtCompanyAttestationInfo;
         } else {
+            //如果是申请,判断是否重复申请
+            int companyAttestationCount = this.count(new QueryWrapper<MtCompanyAttestation>()
+                    .eq("mt_company_id", companyAttestationRequest.getMtCompanyId())
+            );
+            if (companyAttestationCount > 0) {
+                return RestResponse.fail(ApiConstants.RESULT_ERROR, "当前公司已经申请过了请勿重复申请");
+            }
             if (userInfo != null) {
                 //如果是新建,设置创建者名称
                 mtCompanyAttestation.setCreateUser(userInfo.getName());
@@ -164,18 +171,29 @@ public class MtCompanyAttestationServiceImpl extends ServiceImpl<MtCompanyAttest
                 .eq(currentUserId != null, "customer_manager_id", currentUserId)
                 //通过审核状态筛选申请信息
                 .eq("is_certificated", companyAttestationRequest.getIsCertificated())
-                .like(StringUtils.isNotBlank(companyAttestationRequest.getQueryCondition()), "contacts_name",
-                        companyAttestationRequest.getQueryCondition())
-                .or()
-                .like(StringUtils.isNotBlank(companyAttestationRequest.getQueryCondition()), "contacts_tel",
-                        companyAttestationRequest.getQueryCondition())
+                .and(i -> i
+                        .like(StringUtils.isNotBlank(companyAttestationRequest.getQueryCondition()), "contacts_name",
+                                companyAttestationRequest.getQueryCondition())
+                        .or()
+                        .like(StringUtils.isNotBlank(companyAttestationRequest.getQueryCondition()), "contacts_tel",
+                                companyAttestationRequest.getQueryCondition())
+                )
         );
         List<CompanyAttestationResponse> companyAttestationResponseList = new ArrayList<>();
         List<MtCompanyAttestation> mtCompanyAttestationList = mtCompanyAttestationPage.getRecords();
         if (mtCompanyAttestationList != null && mtCompanyAttestationList.size() > 0) {
-            List<Long> customerManagerIdList = ProjectUtils.getAttrList(mtCompanyAttestationList, "customerManagerId", null);
+            //获取客户经理信息
+            List<Long> customerManagerIdList = ProjectUtils.getAttrList(mtCompanyAttestationList,
+                    "customerManagerId", null);
             List<UserInfo> userInfoList = (List<UserInfo>) userInfoService.listByIds(customerManagerIdList);
-            Map<Long, UserInfo> customerManagerIdToUserInfo = ProjectUtils.attrToObjMap(userInfoList, "userId", null);
+            Map<Long, UserInfo> customerManagerIdToUserInfo = ProjectUtils.attrToObjMap(userInfoList,
+                    "userId", null);
+            //获取公司信息
+            List<Long> companyIdList = ProjectUtils.getAttrList(mtCompanyAttestationList,
+                    "mtCompanyId", null);
+            List<MaintenanceCompany> maintenanceCompanyList = (List<MaintenanceCompany>)
+                    maintenanceCompanyService.listByIds(companyIdList);
+            Map<Long, MaintenanceCompany> companyIdToMaintenanceCompany = ProjectUtils.attrToObjMap(maintenanceCompanyList, "id", null);
             for (MtCompanyAttestation mtCompanyAttestation : mtCompanyAttestationList) {
                 CompanyAttestationResponse companyAttestationResponse = new CompanyAttestationResponse(mtCompanyAttestation);
                 //设置客户经理名称
@@ -183,12 +201,22 @@ public class MtCompanyAttestationServiceImpl extends ServiceImpl<MtCompanyAttest
                 if (userInfo != null) {
                     companyAttestationResponse.setCustomerManagerName(userInfo.getName());
                 }
+                //设置公司信息
+                MaintenanceCompany maintenanceCompany = companyIdToMaintenanceCompany.get(mtCompanyAttestation.getMtCompanyId());
+                if (maintenanceCompany != null) {
+                    companyAttestationResponse.setMtCompanyId(maintenanceCompany.getId());
+                    //是否vip
+                    Integer vipFlag = maintenanceCompany.getVipFlag() != null ? maintenanceCompany.getVipFlag() : 0;
+                    //电梯台量
+                    Integer limitedNum = maintenanceCompany.getLimitedNum() != null ? maintenanceCompany.getLimitedNum() : 0;
+                    companyAttestationResponse.setVipFlag(vipFlag);
+                    companyAttestationResponse.setLimitedNum(limitedNum);
+                }
                 companyAttestationResponseList.add(companyAttestationResponse);
             }
             mtCompanyAttestationPage.setRecords(companyAttestationResponseList);
         }
         applyPageResponse.setPage(mtCompanyAttestationPage);
-        applyPageResponse.setCount(mtCompanyAttestationPage.getTotal());
         return RestResponse.success(applyPageResponse, ApiConstants.RESULT_SUCCESS, "获取公司申请信息成功");
     }
 
@@ -209,7 +237,8 @@ public class MtCompanyAttestationServiceImpl extends ServiceImpl<MtCompanyAttest
         //审核未通过
         applyPageResponse.setApplyFailCount(statusToCount.get(ApiConstants.CompanyConstants.MAINTENANCE_FAIL));
         //当前状态为筛选条数
-        applyPageResponse.setCount(statusToCount.get(isCertificated));
+        Long count = statusToCount.get(isCertificated) == null ? 0L : statusToCount.get(isCertificated);
+        applyPageResponse.setCount(count);
     }
 
     /***

+ 2 - 1
lift-system-service/src/main/java/cn/com/ty/lift/system/user/controller/PropertyUserController.java

@@ -5,6 +5,7 @@ import cn.com.ty.lift.system.user.service.IPropertyUserService;
 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;
 
@@ -27,7 +28,7 @@ public class PropertyUserController {
      * @date 2020-01-06 09:08
      */
     @RequestMapping("/list")
-    public RestResponse list(PropertyUserRequest propertyUserRequest) {
+    public RestResponse list(@RequestBody PropertyUserRequest propertyUserRequest) {
         return propertyUserService.list(propertyUserRequest);
     }
 

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

@@ -12,6 +12,7 @@ import java.util.List;
 @Data
 public class PropertyUserRequest {
     private String queryCondition;//查询条件
+    private Long projectId;//项目id
     private Long companyId;//当前所在公司id
     private Long userId;//用户id
     private List<Long> userIdList;//用户id集合

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

@@ -4,8 +4,6 @@ import cn.com.ty.lift.system.user.dao.entity.UserRole;
 import cn.com.xwy.boot.mybatis.MyBatisMapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
-import java.util.List;
-
 /**
  * MyBatis Mapper 接口 - 表:user_role
  * @since 2019-12-01 15:46:21
@@ -13,14 +11,6 @@ import java.util.List;
 @MyBatisMapper
 public interface UserRoleMapper extends BaseMapper<UserRole> {
 
-	/**
-	 * @description 通过角色获取用户角色关联信息
-	 * @date 2019/11/27 10:03 AM
-	 * @param roleId
-	 * @return
-	 */
-    List<UserRole> getByRoleId(Long roleId);
-
     /**
      * @description 通过用户id和公司id获取用户角色关联关系
      * @date 2019/11/27 10:03 AM

+ 1 - 2
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/IRoleMenuService.java

@@ -23,11 +23,10 @@ public interface IRoleMenuService extends IService<RoleMenu> {
 
     /**
      * @param roleId 角色id
-     * @return boolean是否成功,false失败,true成功
      * @description 删除角色菜单关联信息
      * @date 2019/11/27 10:03 AM
      */
-    boolean deleteRoleMenu(Long roleId);
+    void deleteRoleMenu(Long roleId);
 
     /**
      * @param

+ 0 - 9
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/IUserRoleService.java

@@ -3,21 +3,12 @@ package cn.com.ty.lift.system.user.service;
 import cn.com.ty.lift.system.user.dao.entity.UserRole;
 import com.baomidou.mybatisplus.extension.service.IService;
 
-import java.util.List;
-
 /**
  * @author huangyuan
  * @date 2019-12-01
  * @description 用户角色接口
  */
 public interface IUserRoleService extends IService<UserRole> {
-    /**
-     * @description 通过角色信息获取用户角色关联信息
-     * @date 2019/11/27 10:03 AM
-     * @param roleId
-     * @return
-     */
-    List<UserRole> getByRoleId(Long roleId);
 
     /**
      * @description 通过用户id和公司id获取用户角色关联信息

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

@@ -47,12 +47,8 @@ public class RoleMenuService extends ServiceImpl<RoleMenuMapper, RoleMenu> imple
     }
 
     @Override
-    public boolean deleteRoleMenu(Long roleId) {
-        int deleteCount = roleMenuMapper.deleteByRoleId(roleId);
-        if (deleteCount == 0) {
-            return false;
-        }
-        return true;
+    public void deleteRoleMenu(Long roleId) {
+        roleMenuMapper.deleteByRoleId(roleId);
     }
 
     @Override

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

@@ -51,17 +51,17 @@ public class RoleService extends ServiceImpl<RoleMapper, Role> implements IRoleS
                 .eq("delete_flag", ApiConstants.DELETE_NO)
         );
         List<Role> roleList = rolePage.getRecords();
-        if(roleList != null && roleList.size() > 0){
+        if (roleList != null && roleList.size() > 0) {
             List<RoleResponse> roleResponseList = new ArrayList<>();
             //获取创建者名称
             List<Long> userIdList = ProjectUtils.getAttrList(roleList, "createUserId", null);
             Map<Long, UserInfo> userIdToInfo = userInfoService.userIdToInfo(userIdList);
-            for(Role role : roleList){
+            for (Role role : roleList) {
                 RoleResponse roleResponse = new RoleResponse(role);
                 //设置创建者名称
-                if(userIdToInfo != null){
+                if (userIdToInfo != null) {
                     UserInfo userInfo = userIdToInfo.get(role.getCreateUserId());
-                    if(userInfo != null){
+                    if (userInfo != null) {
                         roleResponse.setCreateUserName(userInfo.getName());
                     }
                 }
@@ -96,14 +96,11 @@ public class RoleService extends ServiceImpl<RoleMapper, Role> implements IRoleS
         role.setName(roleRequest.getName());
         role.setUpdateTime(new Date());
         //更新角色信息
-        int updateCount = roleMapper.updateById(role);
+        roleMapper.updateById(role);
         //删除角色原来关联的菜单信息
-        boolean deleteFlag = roleMenuService.deleteRoleMenu(role.getId());
+        roleMenuService.deleteRoleMenu(role.getId());
         //保存角色关联的新的菜单信息
-        boolean saveBatchFlag = roleMenuService.saveRoleMenu(role.getId(), roleRequest.getMenuIds());
-        if (updateCount == 0 || !deleteFlag || !saveBatchFlag) {
-            return RestResponse.fail(ApiConstants.RESULT_ERROR, "更新角色信息失败");
-        }
+        roleMenuService.saveRoleMenu(role.getId(), roleRequest.getMenuIds());
         return RestResponse.success(role, ApiConstants.RESULT_SUCCESS, "更新角色信息成功");
     }
 
@@ -112,18 +109,17 @@ public class RoleService extends ServiceImpl<RoleMapper, Role> implements IRoleS
     public RestResponse deleteRole(RoleRequest roleRequest) {
         Long roleId = roleRequest.getId();
         //判断角色有没有分配给用户
-        List<UserRole> userRoleList = userRoleService.getByRoleId(roleId);
-        if (userRoleList != null && userRoleList.size() > 0) {
+        int userRoleCount = userRoleService.count(new QueryWrapper<UserRole>()
+                .eq("role_id", roleId)
+        );
+        if (userRoleCount > 0) {
             return RestResponse.fail(ApiConstants.RESULT_ERROR, "角色已关联用户,无法删除");
         }
         Role role = roleMapper.selectById(roleId);
         role.setDeleteFlag(ApiConstants.DELETE_YES);
-        int updateCount = roleMapper.updateById(role);
+        roleMapper.updateById(role);
         //删除角色菜单关联信息
-        boolean deleteFlag = roleMenuService.deleteRoleMenu(roleId);
-        if (updateCount == 0 || !deleteFlag) {
-            return RestResponse.fail(ApiConstants.RESULT_ERROR, "删除失败");
-        }
+        roleMenuService.deleteRoleMenu(roleId);
         return RestResponse.success(null, ApiConstants.RESULT_SUCCESS, "删除成功");
     }
 

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

@@ -66,6 +66,8 @@ public class UserApplicationService extends ServiceImpl<UserApplicationMapper, U
             userApplication.setUserId(userApplyRequest.getUserId());
             userApplication.setMtCompanyId(userApplyRequest.getCompanyId());
             userApplication.setType(applyTypeTeam);
+            //设置审核描述信息
+            userApplication.setDescription(userApplyRequest.getDescription());
             //申请加入项目时需要设置的信息
             userApplication.setProjectId(userApplyRequest.getProjectId());
         }
@@ -191,7 +193,7 @@ public class UserApplicationService extends ServiceImpl<UserApplicationMapper, U
      * @description 封装用户申请信息状态条数
      * @date 2020-01-06 23:12
      */
-    private void packUserApplicationStatusCount(List<UserApplication> userApplicationListResult, ApplyPageResponse applyPageResponse, int CurrentStatus) {
+    private void packUserApplicationStatusCount(List<UserApplication> userApplicationListResult, ApplyPageResponse applyPageResponse, int currentStatus) {
         //获取状态对应的数量
         Map<Integer, Long> statusToApplyCount = this.getApplyStatusToCountMap(userApplicationListResult,
                 CommonConstants.USER_APPLICATION_STATUS, "status");
@@ -202,7 +204,8 @@ public class UserApplicationService extends ServiceImpl<UserApplicationMapper, U
         //审核未通过
         applyPageResponse.setApplyFailCount(statusToApplyCount.get(ApiConstants.ApplicationConstants.APPLY_FAIL));
         //设置未查询的总记录条数
-        applyPageResponse.setCount(statusToApplyCount.get(CurrentStatus));
+        Long count = statusToApplyCount.get(currentStatus) == null ? 0L : statusToApplyCount.get(currentStatus);
+        applyPageResponse.setCount(count);
     }
 
     /**

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

@@ -7,8 +7,6 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.List;
-
 /**
  * @author huangyuan
  * @date 2019-12-01
@@ -20,10 +18,6 @@ public class UserRoleService extends ServiceImpl<UserRoleMapper, UserRole> imple
     @Autowired
     private UserRoleMapper userRoleMapper;
 
-    @Override
-    public List<UserRole> getByRoleId(Long roleId) {
-        return userRoleMapper.getByRoleId(roleId);
-    }
 
     @Override
     public UserRole getByUserRole(UserRole userRole) {

+ 21 - 36
lift-system-service/src/main/resources/mapper/UserAccountMapper.xml

@@ -76,9 +76,9 @@
     <select id="getProjectUserList" parameterType="cn.com.ty.lift.system.user.dao.entity.model.ProjectUser"
             resultType="cn.com.ty.lift.system.user.dao.entity.model.ProjectUser">
         select
-            project_id as projectId,
-            user_id as userId,
-            user_role as userRole
+        project_id as projectId,
+        user_id as userId,
+        user_role as userRole
         <include refid="projectUserQueryCondition"/>
     </select>
 
@@ -91,48 +91,33 @@
     </select>
 
     <!--获取项目信息-->
-    <select id="getProjectInfoList" parameterType="java.util.List"
-            resultType="cn.com.ty.lift.system.user.dao.entity.model.ProjectInfo">
+    <select id="getProjectInfoList" resultType="cn.com.ty.lift.system.user.dao.entity.model.ProjectInfo">
         select
-            id as projectId,
-            project_name as projectName,
-            region_id as regionId
+        id as projectId,
+        project_name as projectName,
+        region_id as regionId
         from
-            project
+        project
         where
-        <choose>
-            <when test="projectIdList != null">
-                id in
-                <foreach item="item" index="index" collection="projectIdList" open="(" separator="," close=")">
-                    #{item}
-                </foreach>
-            </when>
-            <otherwise>
-                1 <![CDATA[ <> ]]>b 1
-            </otherwise>
-        </choose>
+        id in
+        <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
+            #{item}
+        </foreach>
     </select>
 
     <!-- 获取项目区域信息 -->
-    <select id="getRegionInfoList" parameterType="java.util.List"
-            resultType="cn.com.ty.lift.system.user.dao.entity.model.RegionInfo">
+    <select id="getRegionInfoList" resultType="cn.com.ty.lift.system.user.dao.entity.model.RegionInfo">
         select
-            id as regionId,
-            area_name as areaName
+        id as regionId,
+        area_name as areaName
         from
-            region
+        region
         where
-        <choose>
-            <when test="regionIdList != null">
-                id in
-                <foreach item="item" index="index" collection="regionIdList" open="(" separator="," close=")">
-                    #{item}
-                </foreach>
-            </when>
-            <otherwise>
-                1 <![CDATA[ <> ]]>b 1
-            </otherwise>
-        </choose>
+        id in
+        <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+
     </select>
 
     <!-- 删除项目用户,条件:用户id,项目id-->

+ 0 - 8
lift-system-service/src/main/resources/mapper/UserRoleMapper.xml

@@ -12,14 +12,6 @@
 		id, user_id, role_id, company_id
 	</sql>
 
-	<!-- 通过角色id获取角色用户关联信息 -->
-	<select id="getByRoleId" parameterType="java.lang.Long" resultType="java.util.ArrayList">
-		select
-		<include refid="Base_Column_List"></include>
-		from user_role
-		where role_id = #{roleId,jdbcType=BIGINT}
-	</select>
-
 	<!-- 通过用户id和公司id获取角色用户关联关系 -->
 	<select id="getByUserRole" parameterType="cn.com.ty.lift.system.user.dao.entity.UserRole" resultType="cn.com.ty.lift.system.user.dao.entity.UserRole">
 		select