Browse Source

Merge branch 'develop' of http://132.232.206.88:3000/lift-manager/lift-server into feature-bieao

别傲 5 years ago
parent
commit
15dc6842e0

+ 96 - 0
lift-common/src/main/java/cn.com.ty.lift.common/utils/MybatisSqlUtils.java

@@ -0,0 +1,96 @@
+package cn.com.ty.lift.common.utils;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author huangyuan
+ * @date 2020/4/18
+ * @description mybatis @select 自定义sql 处理工具
+ */
+public class MybatisSqlUtils {
+
+    /**
+     * @param params 查询参数
+     * @return 拼接的sql语句
+     * @description 通过给定参数拼接sql - 获取当前公司指定角色的用户信息
+     * @date 2020/4/18 6:27 下午
+     */
+    @SuppressWarnings("unchecked")
+    public String getPushUserInfoByRoleCodesSql(Map<String, Object> params) {
+
+        List<String> roleCodeList = (List<String>) params.get("roleCodeList");
+        Long companyId = (Long) params.get("companyId");
+        //获取通用语句
+        StringBuilder sql = getPushUserInfoSql();
+        if (roleCodeList != null && roleCodeList.size() > 0) {
+            sql.append("and r.code in (");
+            //拼接list语句
+            spliceList(roleCodeList, sql);
+        }
+        sql.append("and ur.company_id=").append(companyId);
+        System.out.println(sql.toString());
+        return sql.toString();
+    }
+
+    /**
+     * @param params 查询参数
+     * @return 拼接的sql语句
+     * @description 通过给定参数拼接sql - 获取当前公司指定角色的用户信息
+     * @date 2020/4/18 6:27 下午
+     */
+    @SuppressWarnings("unchecked")
+    public String getPushUserInfoByIdsSql(Map<String, Object> params) {
+        List<Long> userIdList = (List<Long>) params.get("userIdList");
+        Long companyId = (Long) params.get("companyId");
+        //获取通用语句
+        StringBuilder sql = getPushUserInfoSql();
+        if (userIdList != null && userIdList.size() > 0) {
+            sql.append("and ua.user_id in (");
+            //拼接list语句
+            spliceList(userIdList, sql);
+        }
+        sql.append("and ur.company_id=").append(companyId);
+        System.out.println(sql);
+        return sql.toString();
+    }
+
+    /**
+     * @param list 要拼接的list
+     * @description 拼接语句
+     * @date 2020/4/18 6:37 下午
+     */
+    private static void spliceList(List<?> list, StringBuilder sql) {
+        for (int i = 0; i < list.size(); i++) {
+            sql.append("'").append(list.get(i));
+            if (i == list.size() - 1) {
+                sql.append("')");
+            } else {
+                sql.append("',");
+            }
+        }
+    }
+
+    /**
+     * @return 通用语句
+     * @description 获取查询通用语句
+     * @date 2020/4/18 6:51 下午
+     */
+    private static StringBuilder getPushUserInfoSql() {
+        StringBuilder sql = new StringBuilder();
+        sql.append("select ui.user_id as userId, ");
+        sql.append("ui.name as userName, ");
+        sql.append("ua.mobile as mobile, ");
+        sql.append("ua.device_model as deviceModel, ");
+        sql.append("ua.device_flag as deviceFlag, ");
+        sql.append("r.name as roleName from ");
+        sql.append("user_account ua ");
+        sql.append("left join user_info ui on ua.user_id = ui.user_id ");
+        sql.append("left join user_role ur on ua.user_id = ur.user_id ");
+        sql.append("left join role r on r.id = ur.role_id ");
+        sql.append("where 1 = 1 ");
+        return sql;
+    }
+
+}
+

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

@@ -123,5 +123,4 @@ public class UserController {
     }
 
 
-
 }

+ 19 - 14
lift-system-service/src/main/java/cn/com/ty/lift/system/user/dao/mapper/IPushUserMapper.java

@@ -1,9 +1,11 @@
 package cn.com.ty.lift.system.user.dao.mapper;
 
 import cn.com.ty.lift.common.model.PushUserInfo;
+import cn.com.ty.lift.common.utils.MybatisSqlUtils;
 import cn.com.xwy.boot.mybatis.MyBatisMapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.SelectProvider;
 
 import java.util.List;
 
@@ -27,17 +29,20 @@ public interface IPushUserMapper extends BaseMapper<PushUserInfo> {
      * @description 获取要推送的用户信息
      * @date 2020/4/17 2:03 下午
      */
-    @Select("select ui.user_id as userId, "
-            + "ui.name as userName, "
-            + "ua.mobile as mobile, "
-            + "ua.device_model as deviceModel, "
-            + "ua.device_flag as deviceFlag, "
-            + "r.name as roleName from "
-            + "user_account ua "
-            + "left join user_info ui on ua.user_id = ui.user_id "
-            + "left join user_role ur on ua.user_id = ur.user_id "
-            + "left join role r on r.id = ur.role_id"
-            + "where r.code in#{roleCodes} "
-            + "and ur.company_id=#{companyId}")
-    List<PushUserInfo> getPushUserInfo(Long companyId, List<String> roleCodes);
+    @SelectProvider(type = MybatisSqlUtils.class, method = "getPushUserInfoByRoleCodesSql")
+    List<PushUserInfo> getPushUserInfoByRoleCodes(@Param("companyId") Long companyId,
+                                                  @Param("roleCodeList") List<String> roleCodes);
+
+    /**
+     * 获取要推送的用户信息
+     *
+     * @param companyId  当前公司id
+     * @param userIdList 用户id集合
+     * @return 用户信息
+     * @description 获取要推送的用户信息
+     * @date 2020/4/18 7:24 下午
+     */
+    @SelectProvider(type = MybatisSqlUtils.class, method = "getPushUserInfoByIdsSql")
+    List<PushUserInfo> getPushUserInfoByUserIds(@Param("companyId") Long companyId,
+                                                @Param("companyId") List<Long> userIdList);
 }

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

@@ -35,9 +35,9 @@ public class PushUserService extends BaseServiceImpl<IPushUserMapper, PushUserIn
      * @date 2020/4/17 11:14 上午
      */
     public List<PushUserInfo> getPushUserInfo(int pushSituation) {
-        String [] roleCodes = PushMessageConstants.PUSH_VALUE_TO_ROLE_CODE.get(pushSituation);
-        if(roleCodes != null && roleCodes.length > 0) {
-            return getPushUserInfo(Arrays.asList(roleCodes));
+        String[] roleCodes = PushMessageConstants.PUSH_VALUE_TO_ROLE_CODE.get(pushSituation);
+        if (roleCodes != null && roleCodes.length > 0) {
+            return getPushUserInfoByRoleCodes(Arrays.asList(roleCodes));
         }
         return null;
     }
@@ -48,10 +48,22 @@ public class PushUserService extends BaseServiceImpl<IPushUserMapper, PushUserIn
      * @description
      * @date 2020/4/17 3:38 下午
      */
-    public List<PushUserInfo> getPushUserInfo(List<String> roleCodes) {
+    public List<PushUserInfo> getPushUserInfoByRoleCodes(List<String> roleCodes) {
         //获取当前公司id
         Long companyId = getCurrentCompanyId();
-        return this.baseMapper.getPushUserInfo(companyId, roleCodes);
+        return this.baseMapper.getPushUserInfoByRoleCodes(companyId, roleCodes);
+    }
+
+    /**
+     * @param userIdList 用户id集合
+     * @return 用户信息
+     * @description
+     * @date 2020/4/18 7:16 下午
+     */
+    public List<PushUserInfo> getPushUserInfoByUserIds(List<Long> userIdList) {
+        //获取当前公司id
+        Long companyId = getCurrentCompanyId();
+        return this.baseMapper.getPushUserInfoByUserIds(companyId, userIdList);
     }
 
     /**