Переглянути джерело

fix: 修复渠道分享用户数据查询问题

hidewnd 3 днів тому
батько
коміт
fe531295df

+ 18 - 168
yt-agent/agent-service/src/main/java/com/ytpm/service/impl/RiskServiceImpl.java

@@ -24,7 +24,10 @@ import com.ytpm.app.model.YtDyzUser;
 import com.ytpm.app.param.AppUserParam;
 import com.ytpm.config.mq.ReliableMessageSender;
 import com.ytpm.custom.CustomField;
-import com.ytpm.dao.*;
+import com.ytpm.dao.AgentAppMapper;
+import com.ytpm.dao.AgentDictMapper;
+import com.ytpm.dao.AppMapper;
+import com.ytpm.dao.RiskMapper;
 import com.ytpm.general.RepMessage;
 import com.ytpm.general.Result;
 import com.ytpm.general.ResultTable;
@@ -71,8 +74,6 @@ public class RiskServiceImpl implements RiskService {
     private FeignClientInvoker feignInvoker;
     @Resource
     private ReliableMessageSender reliableMessageSender;
-    @Resource
-    private DitchShareMapper ditchShareMapper;
 
     /**
      * 风控锁定用户
@@ -304,12 +305,16 @@ public class RiskServiceImpl implements RiskService {
         List<YtDyzUser> data = new ArrayList<>();
         List<String> collect = issuedAppList.stream().map(YtPlatformUserApp::getServiceName).distinct().collect(Collectors.toList());
         for (String serviceName : collect) {
-            Object o = feignInvoker.invoke(serviceName, "getUserList", appUserParam);
-            String jsonString = JSON.toJSONString(o);
-            JSONObject object = JSONObject.parseObject(jsonString);
-            List<YtDyzUser> dyzUsers = JSONArray.parseArray(object.getString("data"), YtDyzUser.class);
-            if (CollUtil.isNotEmpty(dyzUsers)) {
-                data.addAll(dyzUsers.stream().distinct().collect(Collectors.toList()));
+            try {
+                Object o = feignInvoker.invoke(serviceName, "getUserList", appUserParam);
+                String jsonString = JSON.toJSONString(o);
+                JSONObject object = JSONObject.parseObject(jsonString);
+                List<YtDyzUser> dyzUsers = JSONArray.parseArray(object.getString("data"), YtDyzUser.class);
+                if (CollUtil.isNotEmpty(dyzUsers)) {
+                    data.addAll(dyzUsers.stream().distinct().collect(Collectors.toList()));
+                }
+            } catch (Exception e) {
+                log.warn("调用服务[{}]查询信息失败", serviceName);
             }
         }
         return data;
@@ -461,9 +466,9 @@ public class RiskServiceImpl implements RiskService {
     /**
      * 新增模版和关联配置
      */
-    private void addTemplateAndRelative(RiskConfigParam param,String content,List<YtRiskConfig> configs) {
+    private void addTemplateAndRelative(RiskConfigParam param, String content, List<YtRiskConfig> configs) {
         YtRiskTemplate template = new YtRiskTemplate();
-        BeanUtil.copyProperties(param,template);
+        BeanUtil.copyProperties(param, template);
         template.setTemplateId(IdUtil.fastSimpleUUID());
         template.setTemplateContent(content);
         template.setEnabled(0);
@@ -472,7 +477,7 @@ public class RiskServiceImpl implements RiskService {
         riskMapper.saveTemplate(template);
         riskMapper.addRelease(template.getTemplateId(),
                 configs.stream().map(YtRiskConfig::getConfigId).collect(Collectors.toList()),
-                param.getOperator(),param.getOperatorName()
+                param.getOperator(), param.getOperatorName()
         );
         //传入消息队列通知子服务更新
         reliableMessageSender.sendRiskChangeToMq(template.getTemplateId());
@@ -573,27 +578,6 @@ public class RiskServiceImpl implements RiskService {
         return ResultTable.resultTableOk(new PageInfo<>(configList));
     }
 
-    /**
-     * 添加配置项
-     */
-    private void addConfigItem(Field[] fields, List<RiskConfigView> configList, Integer effectNode) {
-        RiskConfigView view;
-        for (Field field : fields) {
-            field.setAccessible(true);
-            if ((Objects.nonNull(effectNode) && field.getAnnotation(CustomField.class).node() != 99 &&
-                    field.getAnnotation(CustomField.class).node() != effectNode) ||
-                    !field.isAnnotationPresent(CustomField.class)
-            ) continue;
-            view = new RiskConfigView();
-            view.setFieldName(field.getName());
-            if (CharSequenceUtil.isNotBlank(field.getAnnotation(CustomField.class).value())) {
-                view.setDictList(dictMapper.getByTypeCode(field.getAnnotation(CustomField.class).value()));
-            }
-            view.setFieldDesc(field.getAnnotation(ApiModelProperty.class).value());
-            configList.add(view);
-        }
-    }
-
 
     /**
      * 风控配置启用关闭
@@ -639,24 +623,6 @@ public class RiskServiceImpl implements RiskService {
         return Result.resultObjOk(riskMapper.getTemplateView(templateId, channelId));
     }
 
-    /**
-     * 根据业务节点查询配置项
-     */
-    @Override
-    public ResultTable<RiskConfigView> getFieldConfigByNode(Integer effectNode) {
-        List<AgentAppClassView> viewList = riskMapper.getAppClazz("");
-        List<RiskConfigView> configList = new ArrayList<>();
-        Set<String> clazzSet = viewList.stream().map(AgentAppClassView::getFullName).collect(Collectors.toSet());
-        try{
-            for (String fullName : clazzSet) {
-                addConfigItem(Class.forName(fullName).getDeclaredFields(),configList,effectNode);
-            }
-        }catch (Exception e){
-            log.error(e.getMessage());
-            throw new CustomerException(e.getMessage());
-        }
-        return ResultTable.resultTableOk(new PageInfo<RiskConfigView>(configList));
-    }
 
     /**
      * 添加配置项
@@ -672,7 +638,7 @@ public class RiskServiceImpl implements RiskService {
             }
             view = new RiskConfigView();
             view.setFieldName(field.getName());
-            if(CharSequenceUtil.isNotBlank(field.getAnnotation(CustomField.class).value())){
+            if (CharSequenceUtil.isNotBlank(field.getAnnotation(CustomField.class).value())) {
                 view.setDictList(dictMapper.getByTypeCode(field.getAnnotation(CustomField.class).value()));
             }
             view.setFieldDesc(field.getAnnotation(ApiModelProperty.class).value());
@@ -680,122 +646,6 @@ public class RiskServiceImpl implements RiskService {
         }
     }
 
-    /**
-     * 修改用户信息
-     */
-    private void modifyAppUserInfo(String userId, RiskUserStatusParam param, AgentUserInfo curUser) {
-        YtDyzUser appUser = new YtDyzUser();
-        appUser.setUserId(param.getUserId());
-        appUser.setUserStatus(param.getUserStatus());
-        switch (param.getUserStatus()){
-            case 2:
-                appUser.setRiskReason(param.getReason());
-                //1s锁定用户,并设置 24小时后进行解锁
-                redisService.setTimeOutStr("lock_"+userId,param.getAppId(),1000);
-                redisService.setTimeOutHoursStr("unlock_"+userId,param.getAppId(),24);
-                break;
-            case 3: //增加封禁记录
-                appUser.setRiskReason(param.getReason());
-                addBannedRecord(userId,curUser,param.getAppId(),param.getBannedLimit()*24, param.getReason());
-                //1s锁定用户,并设置 24小时后进行解锁
-                redisService.setTimeOutStr("lock_"+userId,param.getAppId(),1000);
-                redisService.setTimeOutHoursStr("unlock_"+userId,param.getAppId(),param.getBannedLimit()*24L);
-                break;
-            default: //解禁
-                YtPlatformBanned banned = riskMapper.getLastBanned(userId);
-                if(Objects.nonNull(banned)){
-                    addDeblockingRecord(banned,param);
-                }
-                redisService.setTimeOutStr("unlock_"+userId,param.getAppId(),1000);
-        }
-    }
-    /**
-     * 根据应用远程调用获取数据
-     */
-    private List<YtDyzUser> dealWithFeignData(List<YtPlatformUserApp> issuedAppList, AppUserParam appUserParam) {
-        List<YtDyzUser> data = new ArrayList<>();
-        List<String> collect = issuedAppList.stream().map(YtPlatformUserApp::getServiceName).distinct().collect(Collectors.toList());
-        for (String serviceName : collect) {
-            Object o;
-            try {
-                o = feignInvoker.invoke(serviceName, "getUserList", appUserParam);
-            }catch (Exception e){
-                log.error("{}服务调用失败: {}", serviceName, e.getMessage());
-                continue;
-            }
-            String jsonString = JSON.toJSONString(o);
-            JSONObject object = JSONObject.parseObject(jsonString);
-            List<YtDyzUser> dyzUsers = JSONArray.parseArray(object.getString("data"), YtDyzUser.class);
-            if(CollUtil.isNotEmpty(dyzUsers)){
-                data.addAll(dyzUsers.stream().distinct().collect(Collectors.toList()));
-            }
-        }
-        return data;
-    }
-
-    /**
-     * 增加解禁记录
-     */
-    private void addDeblockingRecord(YtPlatformBanned banned, RiskUserStatusParam param) {
-        YtPlatformDeblocking deblocking = new YtPlatformDeblocking();
-        deblocking.setDeblockingId(IdUtil.fastSimpleUUID());
-        deblocking.setUserId(banned.getUserId());
-        deblocking.setAppId(banned.getAppId());
-        deblocking.setAgentId(param.getAgentId());
-        deblocking.setOperator(param.getOperator());
-        deblocking.setOperatorName(param.getOperatorName());
-        deblocking.setBannedId(banned.getBannedId());
-        deblocking.setDeblockingReason(param.getReason());
-        deblocking.setDeblockingTime(new Date());
-        riskMapper.addDeblockingRecord(deblocking);
-    }
-
-    /**
-     * 设置解封用户信息
-     */
-    private void setDeblockLoginInfo(List<RiskDeblockingListView> deblockingList,List<YtDyzUser> data) {
-        Map<String, YtDyzUser> collect = data.stream().collect(Collectors.toMap(YtDyzUser::getUserId, o->o));
-        for (RiskDeblockingListView view : deblockingList) {
-            if(!collect.containsKey(view.getUserId())) {
-                continue;
-            }
-            YtDyzUser dyzUser = collect.get(view.getUserId());
-            view.setPlatformId(dyzUser.getPlatformId());
-            view.setChannelId(dyzUser.getUserId());
-            view.setUserId(dyzUser.getUserId());
-            view.setNickName(dyzUser.getNickName());
-            view.setRegistryTime(dyzUser.getRegistryTime());
-            view.setLastLoginTime(dyzUser.getLastLoginTime());
-            view.setUserStatus(dyzUser.getUserStatus());
-        }
-    }
-    /**
-     * 设置封禁用户信息
-     */
-    private void setBannedLoginInfo(List<RiskBannedListView> bannedList, List<YtDyzUser> data) {
-        Map<String, YtDyzUser> collectMap = data.stream().collect(Collectors.toMap(
-                item-> StrUtil.format("{}_{}", item.getAppId(), item.getUserId()), o -> o));
-        for (RiskBannedListView view : bannedList) {
-            String key = StrUtil.format("{}_{}", view.getAppId(), view.getUserId());
-            if(!collectMap.containsKey(key))continue;
-            YtDyzUser dyzUser = collectMap.get(key);
-            List<YtDyzLoginRecord> recordList = dyzUser.getLoginRecordList();
-            if(CollUtil.isNotEmpty(recordList)){
-                view.setPhoneModel(recordList.get(0).getDeviceModel());
-                view.setPhoneBrand(recordList.get(0).getDeviceBrand());
-                view.setIpAddr(recordList.get(0).getIpAddr());
-                view.setCommunicationOperator(recordList.get(0).getOperator());
-            }
-            view.setPlatformId(dyzUser.getPlatformId());
-            view.setChannelId(dyzUser.getUserId());
-            view.setUserId(dyzUser.getUserId());
-            view.setNickName(dyzUser.getNickName());
-            view.setRegistryTime(dyzUser.getRegistryTime());
-            view.setLastLoginIp(dyzUser.getLastLoginIp());
-            view.setLastLoginTime(dyzUser.getLastLoginTime());
-            view.setUserStatus(dyzUser.getUserStatus());
-        }
-    }
 
     /**
      * 增加封禁记录

+ 5 - 6
yt-agent/agent-service/src/main/resources/mapper/AgentAppMapper.xml

@@ -212,7 +212,7 @@
                ypua.feign_class_path,
                ypua.service_name
         from yt_platform_user_app ypua
-        where ypua.user_id = #{userId}
+        where ypua.available = 1 and ypua.user_id = #{userId}
         union
         select
             ypua.app_id,
@@ -228,10 +228,7 @@
             ypua.service_name
         from yt_ditch_share yds
         left join yt_platform_user_app ypua on ypua.app_id = yds.superior_id
-        where yds.is_deleted = 0 and shared_user_id = #{userId}
-           app_id, app_name, user_id, app_type, detail_url, package_name, domain, issued_time, wx_app_id, feign_class_path, service_name
-        from yt_platform_user_app
-        where available = 1 and user_id = #{userId}
+        where yds.is_deleted = 0 and ypua.available = 1 and shared_user_id = #{userId}
     </select>
     <select id="getApkIdList" resultType="java.lang.String">
         select
@@ -241,7 +238,9 @@
     </select>
     <select id="selectByPrimaryKey" resultType="com.ytpm.agent.model.YtPlatformUserApp">
         select
-            app_id, app_name, user_id, app_type, detail_url, package_name, domain, issued_time, wx_app_id, wx_secret, sale_price, grant_type, charge_status, feign_class_path, service_name, create_time, create_user_id, update_time, update_user_id, available
+            app_id, app_name, user_id, app_type, detail_url, package_name, domain, issued_time, wx_app_id, wx_secret,
+            sale_price, grant_type, charge_status, feign_class_path, service_name,
+            create_time, create_user_id, update_time, update_user_id, available
         from yt_platform_user_app
         where available = 1 and app_id = #{appId}
     </select>

+ 3 - 2
yt-agent/agent-service/src/main/resources/mapper/AgentDitchMapper.xml

@@ -47,7 +47,8 @@
         t.app_type,
         t.app_id,
         t.service_name,
-        t.create_time
+        t.create_time,
+        t.user_id
         FROM (
             select
                 yd.ditch_id,
@@ -80,7 +81,7 @@
         ) t
         <where>
             <if test="ditchName != null and ditchName != ''">
-                AND yd.ditch_name LIKE CONCAT('%', #{ditchName}, '%')
+                AND t.ditch_name LIKE CONCAT('%', #{ditchName}, '%')
             </if>
         </where>
         order by t.create_time

+ 92 - 52
yt-agent/agent-service/src/main/resources/mapper/RiskMapper.xml

@@ -126,84 +126,124 @@
         group by t.template_id
     </select>
     <select id="getBannedList" resultType="com.ytpm.risk.view.RiskBannedListView">
-        SELECT
-        pb.banned_id,
-        pb.banned_time,
-        pb.banned_reason,
-        pb.banned_type,
-        pb.banned_limit,
-        pb.operator,
-        pb.operator_name,
-        pb.user_id,
-        pb.agent_id,
-        a.app_id,
-        a.app_name,
-        a.ditch_id,
-        a.ditch_name
-        FROM
-        yt_platform_banned pb
-        JOIN yt_app a ON pb.app_id = a.app_id
-        WHERE
-        pb.agent_id = #{agentId}
+        SELECT t.*
+        FROM (
+            SELECT
+            pb.banned_id,
+            pb.banned_time,
+            pb.banned_reason,
+            pb.banned_type,
+            pb.banned_limit,
+            pb.operator,
+            pb.operator_name,
+            pb.user_id,
+            pb.agent_id,
+            a.app_id,
+            a.app_name,
+            a.ditch_id,
+            a.ditch_name
+            FROM yt_platform_banned pb
+            LEFT JOIN yt_app a ON pb.app_id = a.app_id
+            WHERE pb.agent_id = #{agentId}
+            UNION
+            SELECT
+            pb.banned_id,
+            pb.banned_time,
+            pb.banned_reason,
+            pb.banned_type,
+            pb.banned_limit,
+            pb.operator,
+            pb.operator_name,
+            pb.user_id,
+            pb.agent_id,
+            a.app_id,
+            a.app_name,
+            a.ditch_id,
+            a.ditch_name
+            FROM yt_platform_banned pb
+            LEFT JOIN yt_app a ON pb.app_id = a.app_id
+            LEFT JOIN yt_ditch_share yds ON yds.app_id = a.app_id AND pb.agent_id = yds.user_id
+            WHERE yds.is_deleted = 0 AND yds.shared_user_id = #{agentId}
+        ) t
         <if test="appId != null and appId != ''">
-            and a.app_id = #{appId}
+            and t.app_id = #{appId}
         </if>
         <if test="userId != null and userId != ''">
-            and pb.user_id = #{userId}
+            and t.user_id = #{userId}
         </if>
         <if test="channelOrigin != null and channelOrigin != ''">
-            and a.ditch_id = #{channelOrigin}
+            and t.ditch_id = #{channelOrigin}
         </if>
         <if test="bannedReason != null and bannedReason != ''">
-            and pb.banned_reason like concat('%',#{bannedReason},'%')
+            and t.banned_reason like concat('%',#{bannedReason},'%')
         </if>
         <if test="bannedTimeBegin != null">
-            and DATE_FORMAT(pb.banned_time,'%Y-%m-%d') <![CDATA[>=]]> DATE_FORMAT(#{bannedTimeBegin}, '%Y-%m-%d')
+            and DATE_FORMAT(t.banned_time,'%Y-%m-%d') <![CDATA[>=]]> DATE_FORMAT(#{bannedTimeBegin}, '%Y-%m-%d')
         </if>
         <if test="bannedTimeEnd != null">
-            and DATE_FORMAT(pb.banned_time,'%Y-%m-%d') <![CDATA[<=]]> DATE_FORMAT(#{bannedTimeEnd}, '%Y-%m-%d')
+            and DATE_FORMAT(t.banned_time,'%Y-%m-%d') <![CDATA[<=]]> DATE_FORMAT(#{bannedTimeEnd}, '%Y-%m-%d')
         </if>
-        ORDER BY pb.banned_time DESC
+        ORDER BY t.banned_time DESC
     </select>
     <select id="getDeblockingList" resultType="com.ytpm.risk.view.RiskDeblockingListView">
-        SELECT
-        pd.deblocking_id,
-        pd.banned_id,
-        pd.user_id,
-        pd.agent_id,
-        pd.channel_id,
-        pd.deblocking_time,
-        pd.deblocking_reason,
-        pd.operator,
-        pd.operator_name,
-        a.app_id,
-        a.app_name,
-        a.ditch_id,
-        a.ditch_name
-        FROM
-        yt_platform_deblocking pd
-        JOIN yt_app a ON pd.app_id = a.app_id
-        WHERE
-        pd.agent_id = #{agentId}
+        SELECT t.*
+        FROM (
+            SELECT
+            pd.deblocking_id,
+            pd.banned_id,
+            pd.user_id,
+            pd.agent_id,
+            pd.channel_id,
+            pd.deblocking_time,
+            pd.deblocking_reason,
+            pd.operator,
+            pd.operator_name,
+            a.app_id,
+            a.app_name,
+            a.ditch_id,
+            a.ditch_name
+            FROM yt_platform_deblocking pd
+            LEFT JOIN yt_app a ON pd.app_id = a.app_id
+            WHERE pd.agent_id = #{agentId}
+            UNION
+            SELECT
+            pd.deblocking_id,
+            pd.banned_id,
+            pd.user_id,
+            pd.agent_id,
+            pd.channel_id,
+            pd.deblocking_time,
+            pd.deblocking_reason,
+            pd.operator,
+            pd.operator_name,
+            a.app_id,
+            a.app_name,
+            a.ditch_id,
+            a.ditch_name
+            FROM yt_platform_deblocking pd
+            LEFT JOIN yt_app a ON pd.app_id = a.app_id
+            LEFT JOIN yt_ditch_share yds ON yds.app_id = a.app_id AND pd.agent_id = yds.user_id
+            WHERE yds.is_deleted = 0 AND yds.shared_user_id = #{agentId}
+        ) t
         <if test="appId != null and appId != ''">
-            and a.app_id = #{appId}
+            and t.app_id = #{appId}
         </if>
         <if test="userId != null and userId != ''">
-            and pd.user_id = #{userId}
+            and t.user_id = #{userId}
         </if>
         <if test="channelOrigin != null and channelOrigin != ''">
-            and a.ditch_id = #{channelOrigin}
+            and t.ditch_id = #{channelOrigin}
         </if>
         <if test="deblockingReason != null and deblockingReason != ''">
-            and pd.deblocking_reason like concat('%',#{deblockingReason},'%')
+            and t.deblocking_reason like concat('%',#{deblockingReason},'%')
         </if>
         <if test="deblockingTimeBegin != null">
-            and DATE_FORMAT(pd.deblocking_time,'%Y-%m-%d') <![CDATA[>=]]> DATE_FORMAT(#{deblockingTimeBegin}, '%Y-%m-%d')
+            and DATE_FORMAT(t.deblocking_time,'%Y-%m-%d') <![CDATA[>=]]> DATE_FORMAT(#{deblockingTimeBegin}, '%Y-%m-%d')
         </if>
         <if test="deblockingTimeEnd != null">
-            and DATE_FORMAT(pd.deblocking_time,'%Y-%m-%d') <![CDATA[<=]]> DATE_FORMAT(#{deblockingTimeEnd}, '%Y-%m-%d')
+            and DATE_FORMAT(t.deblocking_time,'%Y-%m-%d') <![CDATA[<=]]> DATE_FORMAT(#{deblockingTimeEnd}, '%Y-%m-%d')
         </if>
-        ORDER BY pd.deblocking_time DESC
+        ORDER BY t.deblocking_time DESC
     </select>
     <select id="getLastBanned" resultType="com.ytpm.agent.model.YtPlatformBanned">
         select

+ 2 - 0
yt-common/src/main/java/com/ytpm/agent/view/AgentDitchView.java

@@ -22,5 +22,7 @@ public class AgentDitchView implements Serializable {
     private String serviceName;
     @ApiModelProperty("创建时间")
     private Date createTime;
+    @ApiModelProperty("归属用户ID")
+    private String userId;
 
 }