Ver código fonte

修改sql查询逻辑bug--(group by 字段问题|数据跨库查询问题)

songyh 3 anos atrás
pai
commit
e3266dbb6c

+ 6 - 0
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java

@@ -114,6 +114,12 @@ public class ShiroConfig {
         filterChainDefinitionMap.put("/ctop/material/top/cost", "anon");
         filterChainDefinitionMap.put("/dimension/report/*", "anon");
         filterChainDefinitionMap.put("/userAllocation/updateAuthName", "anon");
+        filterChainDefinitionMap.put("/account/report/getProjectAccountByUserId", "anon");
+        filterChainDefinitionMap.put("/account/report/kuaishou/list", "anon");
+        filterChainDefinitionMap.put("/account/report/kuaishou/chart", "anon");
+        filterChainDefinitionMap.put("/material/report/getProjectAccountByUserId", "anon");
+        filterChainDefinitionMap.put("/material/report/kuaishou/list", "anon");
+        filterChainDefinitionMap.put("/material/report/kuaishou/detail", "anon");
 
         filterChainDefinitionMap.put("/v1/**", "anon");
 

+ 1 - 1
jeecg-boot-report/src/main/java/cn/com/ctop/common/constant/AccountReportConstants.java

@@ -174,7 +174,7 @@ public class AccountReportConstants {
             "    \"comment\": \"行为数\"\n" +
             "  },\n" +
             "  \"clickRate\": {\n" +
-            "    \"filed\": \"CASE WHEN sum(show) != 0    THEN CONCAT( CAST(ROUND((sum(photo_click) / sum(show)) * 100,2) AS CHAR) ,'%') else '0%' END AS clickRate \",\n" +
+            "    \"filed\": \"CASE WHEN sum(show) != 0    THEN CONCAT( CAST(ROUND((sum(photo_click) / sum(show)) * 100,2) AS CHAR) ,'%') else 0 END AS clickRate \",\n" +
             "    \"comment\": \"封面点击率\"\n" +
             "  },\n" +
             "  \"bClickRate\": {\n" +

+ 1 - 1
jeecg-boot-report/src/main/java/cn/com/ctop/common/mapper/xml/ProjectMapper.xml

@@ -3,7 +3,7 @@
 <mapper namespace="cn.com.ctop.common.mapper.ProjectMapper">
 
     <select id="getListByParams" resultType="cn.com.ctop.common.entity.Project">
-        select * from ctop_project where 1=1
+        select * from hcst_system.ctop_project where 1=1
         and media_id in
         <foreach collection="mediaIds" item="item" separator=","
                  open="(" close=")">

+ 31 - 26
jeecg-boot-report/src/main/java/cn/com/ctop/common/mapper/xml/ProjectMemberMapper.xml

@@ -116,8 +116,8 @@
         b.product_id as productId,
         b.media_id as mediaId
         from
-        ctop_user_allocation a
-        left join ctop_project b on a.project_id = b.id
+        hcst_system.ctop_user_allocation a
+        left join hcst_system.ctop_project b on a.project_id = b.id
         where a.user_id = #{userId}
         and b.media_id in
         <foreach collection="mediaIds" item="item" separator=","
@@ -130,7 +130,7 @@
         select
         role_code
         from
-        sys_user_role a
+            hcst_system.sys_user_role a
         left join sys_role b on a.role_id = b.id
         where a.user_id = #{userId}
     </select>
@@ -139,7 +139,7 @@
             select
             company_id
         from
-        user_company
+            hcst_system.user_company
         where user_id = #{userId}
     </select>
 
@@ -164,7 +164,7 @@
         SELECT
         project_id
         FROM
-        ctop_project_member
+        hcst_system.ctop_project_member
         where user_id = #{userId}
         GROUP BY
         project_id
@@ -187,7 +187,7 @@
         a.sale_id as saleId,
         b.realname as saleName
         from
-        ctop_project a
+        hcst_system.ctop_project a
         left join sys_user b on a.sale_id = b.id
         where a.sale_id = #{userId}
         and a.media_id in
@@ -199,7 +199,7 @@
 
     <select id="getProjectByMap" resultType="java.lang.Long">
         select project_id
-        from ctop_project_member
+        from hcst_system.ctop_project_member
         where user_id = #{userId}
         group by project_id
     </select>
@@ -207,7 +207,7 @@
         select
             project.*
         from
-            ctop_project_member member left join ctop_project project on project.id = member.project_id
+            hcst_system.ctop_project_member member left join hcst_system.ctop_project project on project.id = member.project_id
         where
             member.user_id = #{userId}
     </select>
@@ -216,7 +216,7 @@
         SELECT
         project_id
         FROM
-        ctop_user_allocation
+        hcst_system.ctop_user_allocation
         WHERE
         account_id IN
         <foreach collection="accountIds" item="item" separator=","
@@ -230,7 +230,7 @@
         (SELECT
         project_id
         FROM
-        ctop_user_allocation
+        hcst_system.ctop_user_allocation
         WHERE
         account_id IN
         <foreach collection="accountIds" item="item" separator=","
@@ -241,16 +241,16 @@
 
 
     <select id="getProjectByUserIdAndMediaIds" resultType="com.alibaba.fastjson.JSONObject">
-        select
-        t2.id as 'projectId',
-        t2.project_name as 'projectName',
-        t2.product_id as 'productId',
-        t2.product_name as 'productName',
+        select t2.id            as 'projectId',
+        t2.project_name  as 'projectName',
+        t2.product_id    as 'productId',
+        t3.product_name  as 'productName',
         t2.advertiser_id as 'advertiserId',
-        (select name from ctop_advertiser where id = t2.advertiser_id) as 'advertiserName'
-        from ctop_project_member t1
-        left join ctop_project t2
-        on t1.project_id = t2.id
+        t4.`name`        as 'advertiserName'
+        from hcst_system.ctop_project_member t1
+        left join hcst_system.ctop_project t2 on t1.project_id = t2.id
+        left join hcst_system.ctop_product t3 on t3.id = t2.product_id
+        left join hcst_system.ctop_advertiser t4 on t2.advertiser_id = t4.id
         where 1 = 1
         <if test="userId !=null and userId!=''">
             and t1.user_id = #{userId}
@@ -262,15 +262,20 @@
                 #{item}
             </foreach>
         </if>
-        group by t2.id
-        order by t2.create_time desc
+        group by t2.id,
+        t2.project_name,
+        t2.product_id,
+        t3.product_name,
+        t2.advertiser_id,
+        t4.`name`
+        order by t2.id desc
     </select>
     <select id="getProjectIdsByProductId" resultType="java.lang.Long">
         SELECT
         t1.id
         FROM
-        ctop_project t1
-        LEFT JOIN ctop_project_member t2 ON t1.id = t2.project_id
+        hcst_system.ctop_project t1
+        LEFT JOIN hcst_system.ctop_project_member t2 ON t1.id = t2.project_id
         WHERE
         t2.user_id = #{userId}
         <if test="productId != null and productId != ''">
@@ -281,9 +286,9 @@
     </select>
     <select id="getlistByUserId" resultType="cn.com.ctop.common.entity.ProjectMember">
         select cp.id as id, cp.project_name as project_name, cp.media_id as media_id, ca.name as advertiser_name
-        from ctop_project_member cpm
-                 left join ctop_project cp on cpm.project_id = cp.id
-                 left join ctop_advertiser ca on ca.id = cp.advertiser_id
+        from hcst_system.ctop_project_member cpm
+                 left join hcst_system.ctop_project cp on cpm.project_id = cp.id
+                 left join hcst_system.ctop_advertiser ca on ca.id = cp.advertiser_id
         where 1=1
         <if test="userId!=null">
             and cpm.user_id = #{userId}

+ 1 - 1
jeecg-boot-report/src/main/java/cn/com/ctop/common/mapper/xml/SysDepartMapper.xml

@@ -6,7 +6,7 @@
         select
                *
         from
-             sys_depart
+        hcst_system.sys_depart
         where
               1=1
               <if test="orgType!=null">

+ 5 - 5
jeecg-boot-report/src/main/java/cn/com/ctop/common/mapper/xml/SysRoleMapper.xml

@@ -5,23 +5,23 @@
     <!-- 根据roleCode获取roleId -->
     <select id="getRoleIdByRoleCode" resultType="java.lang.String">
         select id
-        from sys_role
+        from hcst_system.sys_role
         where role_code = #{roleCode}
     </select>
 
     <!-- 根据userId获取角色code -->
     <select id="getRoleCodeByUserId" resultType="java.lang.String">
         select c.role_code
-        from sys_user a
-                 left join sys_user_role b on a.id = b.user_id
-                 left join sys_role c on b.role_id = c.id
+        from hcst_system.sys_user a
+                 left join hcst_system.sys_user_role b on a.id = b.user_id
+                 left join hcst_system.sys_role c on b.role_id = c.id
         where a.id = #{userId}
     </select>
 
 
     <select id="queryRoleByUserId" resultType="cn.com.ctop.common.entity.SysRole">
         SELECT t2.role_name,t2.role_code
-        FROM sys_user_role t1
+        FROM hcst_system.sys_user_role t1
                  LEFT JOIN sys_role t2 ON t1.role_id = t2.id
         WHERE t1.user_id = #{userId} LIMIT 1
     </select>

+ 1 - 1
jeecg-boot-report/src/main/java/cn/com/ctop/common/mapper/xml/SysUserMapper.xml

@@ -3,6 +3,6 @@
 <mapper namespace="cn.com.ctop.common.mapper.SysUserMapper">
 
     <select id="selectAllUser" resultType="org.jeecg.common.system.entity.SysUser">
-        select * from sys_user where del_flag = 0 and status = 1
+        select * from hcst_system.sys_user where del_flag = 0 and status = 1
     </select>
 </mapper>

+ 3 - 5
jeecg-boot-report/src/main/java/cn/com/ctop/common/mapper/xml/UserAllocationMapper.xml

@@ -3,23 +3,21 @@
 <mapper namespace="cn.com.ctop.common.mapper.UserAllocationMapper">
 
     <select id="queryListWithPermission" resultType="cn.com.ctop.common.entity.UserAllocation">
-        select * from user_allocation where 1=1 ${permissionSql}
+        select * from hcst_system.user_allocation where 1=1 ${permissionSql}
     </select>
     <select id="getAccountListByProjectList" resultType="com.alibaba.fastjson.JSONObject">
         select
         t1.project_id as 'projectId',
         t1.account_id as 'accountId',
-        (select realname from sys_user where id = t1.user_id ) as 'userName',
+        (select realname from hcst_system.sys_user where id = t1.user_id ) as 'userName',
         t1.auth_name as 'authName',
         t1.account_status as 'accountStatus'
-        from ctop_user_allocation t1
+        from hcst_system.ctop_user_allocation t1
         where t1.project_id in
         <foreach collection="list" item="item" separator=","
                  open="(" close=")">
             #{item}
         </foreach>
-
-
         order by t1.create_time desc
     </select>
 </mapper>

+ 1 - 6
jeecg-boot-report/src/main/java/cn/com/ctop/report/controller/KuaishouMaterialReportDailyDwController.java

@@ -8,16 +8,12 @@ import cn.com.ctop.common.utils.Check;
 import cn.com.ctop.common.utils.JsonResourceUtil;
 import cn.com.ctop.common.utils.ResultMapUtils;
 import cn.com.ctop.common.utils.StatusCode;
-import cn.com.ctop.report.entity.AccountAttributionInfo;
-import cn.com.ctop.report.service.AccountAttributionInfoService;
-import cn.com.ctop.report.service.IKuaishouAccountReportDailyDwService;
 import cn.com.ctop.report.service.IKuaishouMaterialVideoReportDailyDwService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
-import org.jeecg.common.system.entity.SysUser;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -25,7 +21,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
-import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -178,7 +173,7 @@ public class KuaishouMaterialReportDailyDwController {
 
 
 
-    @PostMapping("/detail")
+    @PostMapping("/kuaishou/detail")
     public Result<List<JSONObject>> getReportDetail(@RequestBody JSONObject requestBody) {
         Result<List<JSONObject>> result = new Result<>();
         if (requestBody.isEmpty()) {

+ 12 - 12
jeecg-boot-report/src/main/java/cn/com/ctop/report/mapper/xml/AccountAttributionInfoMapper.xml

@@ -3,7 +3,7 @@
 <mapper namespace="cn.com.ctop.report.mapper.AccountAttributionInfoMapper">
 
     <insert id="reloadData">
-        replace into ctop_account_attribution_info(id, account_id, project_id, product_id, advertiser_id, company_id,
+        replace into hcst_system.ctop_account_attribution_info(id, account_id, project_id, product_id, advertiser_id, company_id,
                                           account_name, project_name, advertiser_name, company_name, sale_id, user_id,
                                           org_code)
         select cua.account_id,
@@ -19,20 +19,20 @@
                cp.sale_id,
                su.id,
                su.org_code
-        from ctop_user_allocation cua
-                 left join ctop_project cp on cua.project_id = cp.id
-                 left join ctop_advertiser ca on ca.id = cua.advertiser_id
-                 left join sys_user su on su.id = cua.user_id
-                 left join user_company uc on uc.user_id = cua.user_id
-                 left join ctop_product product on product.id = cp.product_id where cua.account_id is not null;
+        from hcst_system.ctop_user_allocation cua
+                 left join hcst_system.ctop_project cp on cua.project_id = cp.id
+                 left join hcst_system.ctop_advertiser ca on ca.id = cua.advertiser_id
+                 left join hcst_system.sys_user su on su.id = cua.user_id
+                 left join hcst_system.user_company uc on uc.user_id = cua.user_id
+                 left join hcst_system.ctop_product product on product.id = cp.product_id where cua.account_id is not null;
     </insert>
     <select id="selectByParams" resultType="cn.com.ctop.report.entity.AccountAttributionInfo">
         select
                caai.*
-        from ctop_user_allocation cua
-        left join ctop_account_attribution_info caai on caai.account_id = cua.account_id
+        from hcst_system.ctop_user_allocation cua
+        left join hcst_system.ctop_account_attribution_info caai on caai.account_id = cua.account_id
         where cua.media_id in
-        <foreach collection="mediaIds" item="item" separator=","
+        <foreach collection="mediaList" item="item" separator=","
                  open="(" close=")">
             #{item}
         </foreach>
@@ -57,8 +57,8 @@
     </select>
     <select id="selectDesignAccuntsByParams" resultType="cn.com.ctop.report.entity.AccountAttributionInfo">
         select caai.*
-        from ctop_user_allocation cua
-                 left join ctop_account_attribution_info caai on cua.account_id = caai.account_id
+        from hcst_system.ctop_user_allocation cua
+                 left join hcst_system.ctop_account_attribution_info caai on cua.account_id = caai.account_id
         where cua.account_status = 0
         <if test="mediaList != null">
             and cua.media_id in

+ 23 - 9
jeecg-boot-report/src/main/java/cn/com/ctop/report/service/impl/AccountAttributionInfoServiceImpl.java

@@ -94,25 +94,39 @@ public class AccountAttributionInfoServiceImpl extends ServiceImpl<AccountAttrib
         List<AccountAttributionInfo>accountAttributionInfos = getAccountInfoList(userId,mediaType);
         Map<Long,Long> projectIdMaps = new HashMap<>();
         for(AccountAttributionInfo attributionInfo:accountAttributionInfos){
-            projectIdMaps.putIfAbsent(attributionInfo.getProjectId(),attributionInfo.getProjectId());
+            if(null!=attributionInfo.getProjectId()&&attributionInfo.getProjectId()!=0){
+                projectIdMaps.putIfAbsent(attributionInfo.getProjectId(),attributionInfo.getProjectId());
+            }
         }
         JSONArray projectInfos = new JSONArray();
         if(projectIdMaps.isEmpty()){
             return projectInfos;
         }
         for (Long key : projectIdMaps.keySet()) {
-            List<AccountAttributionInfo>accountInfos = accountAttributionInfos.stream().filter(a->a.getProjectId().equals(key)).collect(Collectors.toList());
+            List<AccountAttributionInfo>accountInfos = getAccountInfoListByProjectId(key,accountAttributionInfos);
             JSONObject projectInfo = new JSONObject();
-            projectInfo.put("projectId",accountInfos.get(0).getProjectId());
-            projectInfo.put("projectName",accountInfos.get(0).getProjectName());
-            projectInfo.put("advertiserName",accountInfos.get(0).getAdvertiserName());
-            projectInfo.put("advertiserId",accountInfos.get(0).getAdvertiserId());
-            projectInfo.put("accountList",accountInfos);
-            projectInfos.add(projectInfo);
+            if(!accountInfos.isEmpty()){
+                projectInfo.put("projectId",accountInfos.get(0).getProjectId());
+                projectInfo.put("projectName",accountInfos.get(0).getProjectName());
+                projectInfo.put("advertiserName",accountInfos.get(0).getAdvertiserName());
+                projectInfo.put("advertiserId",accountInfos.get(0).getAdvertiserId());
+                projectInfo.put("accountList",accountInfos);
+                projectInfos.add(projectInfo);
+            }
         }
         return projectInfos;
     }
 
+    private List<AccountAttributionInfo> getAccountInfoListByProjectId(Long projectId, List<AccountAttributionInfo> accountAttributionInfos) {
+        List<AccountAttributionInfo>result = new ArrayList<>();
+        for(AccountAttributionInfo attributionInfo:accountAttributionInfos){
+            if(null!=attributionInfo.getProjectId()&&attributionInfo.getProjectId().equals(projectId)){
+                result.add(attributionInfo);
+            }
+        }
+        return result;
+    }
+
     @Override
     public JSONArray getMaterialProjectAccountByUserId(String userId, String mediaType) {
         List<AccountAttributionInfo>accountAttributionInfos = getAccountInfoList(userId,mediaType);
@@ -254,7 +268,7 @@ public class AccountAttributionInfoServiceImpl extends ServiceImpl<AccountAttrib
         JSONObject aClickLink = new JSONObject();
 
         costLink.put("cost", after.getBigDecimal("cost"));
-        costLink.put("CostSumLink", LinkUtils.countLink(after.getBigDecimal("cost"), before.getBigDecimal("cost")));
+        costLink.put("costSumLink", LinkUtils.countLink(after.getBigDecimal("cost"), before.getBigDecimal("cost")));
         if (mediaId.equals(CtopAdConstant.PLATFORM_TYPE_KUAISHOU)) {
             discountCostLink.put("discountCost", after.getBigDecimal("cost").divide(discount, 4, RoundingMode.HALF_UP));
             discountCostLink.put("discountCostLink", LinkUtils.countLink(after.getBigDecimal("cost").divide(discount, 4, RoundingMode.HALF_UP), before.getBigDecimal("cost").divide(discount, 4, RoundingMode.HALF_UP)));

+ 1 - 1
jeecg-boot-report/src/main/resources/application-dev.yml

@@ -107,7 +107,7 @@ spring:
         master:
           url: jdbc:mysql://192.168.1.187:4000/application?characterEncoding=UTF-8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
           username: root
-          password: hcst@2021
+          password: hcst2021
           driver-class-name: com.mysql.jdbc.Driver
   #redis 配置
   redis:

+ 0 - 1
jeecg-boot-report/src/main/resources/application-prod.yml

@@ -5,7 +5,6 @@ server:
     include-exception: true
     include-stacktrace: ALWAYS
     include-message: ALWAYS
-
   compression:
     enabled: true
     min-response-size: 1024

+ 2 - 2
jeecg-boot-report/src/main/resources/application-test.yml

@@ -15,8 +15,8 @@ spring:
   cloud:
     nacos:
       discovery:
-        server-addr: 139.186.134.115:8848
-        service: jeecg-cloud-finance
+        server-addr: 172.30.0.14:8848
+        service: jeecg-cloud-report
   servlet:
     multipart:
       max-file-size: -1

+ 6 - 0
jeecg-cloud-module/jeecg-cloud-gateway/src/main/resources/application-dev.yml

@@ -38,6 +38,12 @@ spring:
           - Path=/bytedance/ad/**
         filters:
           - DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin
+      - id: jeecg-bytedance-ad
+        uri: lb://jeecg-cloud-report
+        predicates:
+          - Path=/reportModule/**
+        filters:
+          - DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin
 # hystrix 信号量隔离,3秒后自动超时
 hystrix:
   enabled: true