浏览代码

[chg] 推送消息设备列表非空,去重

wcz 5 年之前
父节点
当前提交
c98f3b183a

+ 12 - 8
lift-business-service/src/main/java/cn/com/ty/lift/business/project/dao/entity/Region.java

@@ -72,22 +72,26 @@ public class Region implements Serializable {
     /**
      * 拆分解析文员的id
      */
-    public List<Long> splitClerk(){
+    public Set<Long> splitClerk(){
         if(StrUtil.isBlank(clerk)){
-            return Collections.emptyList();
+            return Collections.emptySet();
         }
-        if(clerk.contains(",")){
-            return Arrays.stream(clerk.split(",")).map(c -> Long.parseLong(c.trim())).collect(Collectors.toList());
-        }else{
-            return Arrays.asList(Long.parseLong(clerk.trim()));
+        try {
+            if(clerk.contains(",")){
+                return Arrays.stream(clerk.split(",")).map(c -> Long.parseLong(c.trim())).collect(Collectors.toSet());
+            }else{
+                return new HashSet<>(Arrays.asList(Long.parseLong(clerk.trim())));
+            }
+        }catch (Exception e){
+            return Collections.emptySet();
         }
     }
 
     /**
      * 返回区域主管和文员的id列表
      */
-    public List<Long> members(){
-        List<Long> members = new ArrayList<>();
+    public Set<Long> members(){
+        Set<Long> members = new HashSet<>();
         members.add(userId);
         members.addAll(splitClerk());
         return members;

+ 9 - 13
lift-business-service/src/main/java/cn/com/ty/lift/business/push/PushUserService.java

@@ -84,35 +84,31 @@ public class PushUserService extends BaseServiceImpl<PushUserMapper, PushUserInf
     }
     /**
      * 查询公司下总经理
-     * @param mtCompanyId
-     * @return
      */
     public List<PushUserInfo> listHighDirector(Long mtCompanyId){
         return baseMapper.listByRoleCode(mtCompanyId, CommonEnum.DefaultRole.HIGH_DIRECTOR.getCode());
     }
     /**
      * 查询公司下管理员
-     * @param mtCompanyId
-     * @return
      */
     public List<PushUserInfo> listEnterpriseAdmin(Long mtCompanyId){
         return baseMapper.listByRoleCode(mtCompanyId, CommonEnum.DefaultRole.ENTERPRISE_ADMIN.getCode());
     }
-
-    public List<PushUserInfo> listByEmergencyRepair(Long repairId, Long mtCompanyId, List<String> roleCodes){
-        return baseMapper.listByEmergencyRepair(repairId, mtCompanyId, roleCodes);
-    }
+    /**
+     * 根据急修id和维保公司id查询region
+     */
     public Region findRegionByEmergencyRepair(Long repairId, Long mtCompanyId){
         return baseMapper.findRegionByEmergencyRepair(repairId, mtCompanyId);
     }
-
-    public List<PushUserInfo> listByAnnualInspection(Long inspectionId, Long mtCompanyId, List<String> roleCodes){
-        return baseMapper.listByAnnualInspection(inspectionId, mtCompanyId, roleCodes);
-    }
+    /**
+     * 根据年检id和维保公司id查询region
+     */
     public Region findRegionByAnnualInspection(Long inspectionId, Long mtCompanyId){
         return baseMapper.findRegionByAnnualInspection(inspectionId, mtCompanyId);
     }
-
+    /**
+     * 根据项目id和维保公司id查询region
+     */
     public Region findRegionByProject(Long projectId, Long mtCompanyId){
         return baseMapper.findRegionByProject(projectId, mtCompanyId);
     }

+ 11 - 75
lift-business-service/src/main/resources/mapper/push/PushUserMapper.xml

@@ -89,17 +89,17 @@
 
     <select id="listByRoleCode" resultMap="BaseResultMap">
         SELECT
-        ui.user_id,
-        ui.NAME AS username,
-        ua.mobile,
-        ua.device_model,
-        ua.device_flag,
-        ro.NAME AS role_name
+            ui.user_id,
+            ui.NAME AS username,
+            ua.mobile,
+            ua.device_model,
+            ua.device_flag,
+            ro.NAME AS role_name
         FROM
-        user_info ui
-        LEFT JOIN user_account ua ON ui.user_id = ua.user_id
-        LEFT JOIN user_role ur ON ui.user_id = ur.user_id
-        LEFT JOIN role ro ON ro.id = ur.role_id
+            user_info ui
+            LEFT JOIN user_account ua ON ui.user_id = ua.user_id
+            LEFT JOIN user_role ur ON ui.user_id = ur.user_id
+            LEFT JOIN role ro ON ro.id = ur.role_id
         <where>
             <if test="mtCompanyId != null and mtCompanyId > 0">
                 AND ur.company_id = #{mtCompanyId}
@@ -127,71 +127,6 @@
         </where>
     </select>
 
-    <select id="listByEmergencyRepair" resultMap="BaseResultMap">
-        SELECT
-            ui.user_id,
-            ui.NAME AS username,
-            ua.mobile,
-            ua.device_model,
-            ua.device_flag,
-            ro.NAME AS role_name
-        FROM
-            emergency_repair er
-            LEFT JOIN project pr ON pr.id = er.project_id
-            LEFT JOIN region re ON re.id = pr.region_id
-            LEFT JOIN user_info ui ON ui.user_id = re.user_id
-            LEFT JOIN user_account ua ON ui.user_id = ua.user_id
-            LEFT JOIN user_role ur ON ui.user_id = ur.user_id
-            LEFT JOIN role ro ON ro.id = ur.role_id
-        <where>
-            <if test="id != null and id > 0">
-                AND er.id = #{id}
-            </if>
-            <if test="mtCompanyId != null and mtCompanyId > 0">
-                AND er.mt_company_id = #{mtCompanyId}
-            </if>
-            <if test="roleCodes != null">
-                AND ro.`code` IN
-                <foreach collection="roleCodes" item="roleCode" open="(" separator="," close=")">
-                    #{roleCode, jdbcType=VARCHAR}
-                </foreach>
-            </if>
-        </where>
-    </select>
-
-    <select id="listByAnnualInspection" resultMap="BaseResultMap">
-        SELECT
-            ui.user_id,
-            ui.NAME AS username,
-            ua.mobile,
-            ua.device_model,
-            ua.device_flag,
-            ro.NAME AS role_name
-        FROM
-            annual_inspection ai
-            LEFT JOIN project_lift_relevance plr ON plr.mt_company_id = ai.mt_company_id AND ai.lift_id = plr.lift_id
-            LEFT JOIN project pr ON pr.id = plr.project_id
-            LEFT JOIN region re ON re.id = pr.region_id
-            LEFT JOIN user_info ui ON ui.user_id = re.user_id
-            LEFT JOIN user_account ua ON ui.user_id = ua.user_id
-            LEFT JOIN user_role ur ON ua.user_id = ur.user_id
-            LEFT JOIN role ro ON ro.id = ur.role_id
-        <where>
-            <if test="id != null and id > 0">
-                AND ai.id = #{id}
-            </if>
-            <if test="mtCompanyId != null and mtCompanyId > 0">
-                AND ai.mt_company_id = #{mtCompanyId}
-            </if>
-            <if test="roleCodes != null">
-                AND ro.`code` IN
-                <foreach collection="roleCodes" item="roleCode" open="(" separator="," close=")">
-                    #{roleCode, jdbcType=VARCHAR}
-                </foreach>
-            </if>
-        </where>
-    </select>
-
     <select id="findRegionByAnnualInspection" resultType="cn.com.ty.lift.business.project.dao.entity.Region">
         SELECT
             re.user_id,
@@ -209,6 +144,7 @@
             </if>
         </where>
     </select>
+
     <select id="findRegionByProject" resultType="cn.com.ty.lift.business.project.dao.entity.Region">
         SELECT
             re.user_id,

+ 20 - 59
lift-common/src/main/java/cn.com.ty.lift.common/model/PushMessage.java

@@ -2,6 +2,7 @@ package cn.com.ty.lift.common.model;
 
 import cn.com.ty.lift.common.utils.ValuePool;
 import cn.hutool.core.collection.IterUtil;
+import cn.hutool.core.util.StrUtil;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.jms.core.JmsMessagingTemplate;
@@ -10,11 +11,7 @@ import org.springframework.messaging.support.GenericMessage;
 import java.io.Serializable;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.stream.Collectors;
+import java.util.*;
 
 /**
  * 推送消息
@@ -537,21 +534,25 @@ public class PushMessage implements Serializable {
             if(IterUtil.isEmpty(pushUserInfos)){
                 return false;
             }
-            Map<Integer, List<PushUserInfo>> collect = pushUserInfos.stream().collect(Collectors.groupingBy(PushUserInfo::getDeviceModel));
-            List<PushUserInfo> pushAndroids = collect.get(1);
-            List<PushUserInfo> pushIos = collect.get(2);
-            if(IterUtil.isNotEmpty(pushAndroids)){
-                List<String> toAndroid = pushAndroids.stream().map(PushUserInfo::getDeviceFlag).filter(Objects::nonNull).distinct().collect(Collectors.toList());
-                if (IterUtil.isNotEmpty(toAndroid)) {
-                    this.setToList(toAndroid);
-                    jmsMessagingTemplate.send(ValuePool.QUEUE_ANDROID_TOKEN, new GenericMessage<>(this));
-                }
-            }else if (IterUtil.isNotEmpty(pushIos)) {
-                List<String> toIos = pushIos.stream().map(PushUserInfo::getDeviceFlag).filter(Objects::nonNull).distinct().collect(Collectors.toList());
-                if(IterUtil.isNotEmpty(toIos)){
-                    this.setToList(toIos);
-                    jmsMessagingTemplate.send(ValuePool.QUEUE_IOS_TOKEN, new GenericMessage<>(this));
+            Set<String> toAndroid = new HashSet<>();
+            Set<String> toIos = new HashSet<>();
+            for (PushUserInfo pushUserInfo : pushUserInfos) {
+                Integer deviceModel = pushUserInfo.getDeviceModel();
+                String deviceFlag = pushUserInfo.getDeviceFlag();
+                if (Objects.nonNull(deviceModel) && StrUtil.isNotBlank(deviceFlag)) {
+                    if (1 == deviceModel) {
+                        toAndroid.add(deviceFlag);
+                    } else if (2 == deviceModel) {
+                        toIos.add(deviceFlag);
+                    }
                 }
+            }
+            if (IterUtil.isNotEmpty(toAndroid)) {
+                this.setToList(new ArrayList<>(toAndroid));
+                jmsMessagingTemplate.send(ValuePool.QUEUE_ANDROID_TOKEN, new GenericMessage<>(this));
+            } else if (IterUtil.isNotEmpty(toIos)) {
+                this.setToList(new ArrayList<>(toIos));
+                jmsMessagingTemplate.send(ValuePool.QUEUE_IOS_TOKEN, new GenericMessage<>(this));
             } else {
                 return false;
             }
@@ -577,44 +578,4 @@ public class PushMessage implements Serializable {
             return false;
         }
     }
-
-    /**
-     * 只推送到android平台的指定设备token
-     *
-     * @param jmsMessagingTemplate jms
-     * @param toList               推到安卓平台的设备token
-     */
-    public boolean sendTokenOnAndroid(JmsMessagingTemplate jmsMessagingTemplate, List<String> toList) {
-        try {
-            if (IterUtil.isEmpty(toList)) {
-                return false;
-            }
-            this.setToList(toList.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList()));
-            jmsMessagingTemplate.send(ValuePool.QUEUE_ANDROID_TOKEN, new GenericMessage<>(this));
-            return true;
-        } catch (Exception e) {
-            log.error("Failed to Send pushMessage to ANDROID_TOKEN Message Queue: ", e);
-            return false;
-        }
-    }
-
-    /**
-     * 只推送到ios的指定设备token
-     * @param jmsMessagingTemplate
-     * @param toList ios设备token
-     * @return
-     */
-    public boolean sendTokenOnIos(JmsMessagingTemplate jmsMessagingTemplate, List<String> toList) {
-        try {
-            if (IterUtil.isEmpty(toList)) {
-                return false;
-            }
-            this.setToList(toList.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList()));
-            jmsMessagingTemplate.send(ValuePool.QUEUE_IOS_TOKEN, new GenericMessage<>(this));
-            return true;
-        } catch (Exception e) {
-            log.error("Failed to Send pushMessage to IOS_TOKEN Message Queue: ", e);
-            return false;
-        }
-    }
 }

+ 1 - 1
lift-common/src/main/java/cn.com.ty.lift.common/verify/VerifyProcessor.java

@@ -941,7 +941,7 @@ public class VerifyProcessor {
                 setIllegalArgMessage("The @NotBlank only supports CharSequence.");
                 return false;
             }
-            return !((CharSequence) value).toString().trim().isEmpty();
+            return ((CharSequence) value).toString().trim().length() > 0;
         }
 
         /**