Эх сурвалжийг харах

fix: SQL修复——站点统计stationIds条件错位/子查询裁剪列/时间条件下推防全表聚合,管理员列表status条件笔误且不再返回密码hash,充值流水三个并列where合并防语法错误,getMe改预编译占位符

skyline 3 долоо хоног өмнө
parent
commit
3528cf978e

+ 1 - 1
mapper/src/main/java/com/kym/mapper/miniapp/UserMapper.java

@@ -38,7 +38,7 @@ public interface UserMapper extends MPJBaseMapper<User> {
             "  t_user u \n" +
             "  LEFT JOIN t_account acc \n" +
             "    ON u.id = acc.user_id \n" +
-            "WHERE u.id = ${userId} ")
+            "WHERE u.id = #{userId} ")
     UserVo getMe(Long userId);
 
     List<CustomUserVo> listUser(@Param("list") List<Long> userId);

+ 11 - 2
mapper/src/main/resources/mappers/admin/AdminUserMapper.xml

@@ -62,7 +62,16 @@
 
     <select id="listAdminUser" resultMap="AdminUserVoMap" parameterType="com.kym.entity.admin.queryParams.CommonQueryParam">
         SELECT
-        t1.*,
+        t1.id,
+        t1.company_id,
+        t1.username,
+        t1.nickname,
+        t1.mobile_phone,
+        t1.avatar,
+        t1.status,
+        t1.create_time,
+        t1.update_time,
+        t1.last_login_time,
         t4.role_name,
         t4.permissions
         FROM
@@ -85,7 +94,7 @@
                 and t1.mobile_phone = #{params.mobilePhone}
             </if>
             <if test="params.status != null">
-                and t1.status = #{params.mobilePhone}
+                and t1.status = #{params.status}
             </if>
         </where>
     </select>

+ 18 - 9
mapper/src/main/resources/mappers/miniapp/ChargeOrderMapper.xml

@@ -189,7 +189,7 @@
 
     <select id="stationStat" resultMap="StationStatMap" parameterType="com.kym.entity.admin.queryParams.StatQueryParam">
         SELECT
-        <if test="params.stationIds != null and params.stationId != ''">
+        <if test="params.stationIds != null and params.stationIds.size() > 0">
             t1.station_id,
         </if>
         <if test="params.type == null or params.type == 'day'">
@@ -207,24 +207,33 @@
         (SUM(t1.service_money) - SUM(t1.service_money_discount)) pay_service_amount
         FROM
         (SELECT
-        *
+        id, station_id, start_time, total_power, total_money, elec_money, service_money, service_money_discount
         FROM
         t_charge_order
         <where>
             <if test="params.stationId != null and params.stationId != ''">
                 and station_id = #{params.stationId}
             </if>
-        </where>
-        ) t1
-        GROUP BY stat_time
-        <trim prefix="having" suffixOverrides="and">
+            <if test="params.stationIds != null and params.stationIds.size() > 0">
+                and station_id IN
+                <foreach collection="params.stationIds" item="stationId" index="index" open="(" close=")" separator=",">
+                    #{stationId}
+                </foreach>
+            </if>
+            <!-- 时间条件下推子查询,避免全表聚合 -->
             <if test="params.startTime != null">
-                stat_time &gt;= #{params.startTime} and
+                and start_time &gt;= #{params.startTime}
             </if>
             <if test="params.endTime != null">
-                stat_time &lt;= #{params.endTime} and
+                and start_time &lt; DATE_ADD(#{params.endTime}, INTERVAL 1 DAY)
             </if>
-        </trim>
+        </where>
+        ) t1
+        GROUP BY
+        <if test="params.stationIds != null and params.stationIds.size() > 0">
+            t1.station_id,
+        </if>
+        stat_time
         order by stat_time desc
     </select>
 

+ 11 - 9
mapper/src/main/resources/mappers/miniapp/PayLogMapper.xml

@@ -55,15 +55,17 @@
         t_pay_log t1
         LEFT JOIN t_user t2
         ON t1.`user_id` = t2.`id`
-        <if test="params.mobilePhone != null and params.mobilePhone!=''">
-            where t2.mobile_phone = #{params.mobilePhone}
-        </if>
-        <if test="params.transactionId != null and params.transactionId!=''">
-            where t1.transaction_id = #{params.transactionId}
-        </if>
-        <if test="params.outTradeNo != null and params.outTradeNo!=''">
-            where t1.out_trade_no = #{params.outTradeNo}
-        </if>
+        <where>
+            <if test="params.mobilePhone != null and params.mobilePhone!=''">
+                t2.mobile_phone = #{params.mobilePhone}
+            </if>
+            <if test="params.transactionId != null and params.transactionId!=''">
+                and t1.transaction_id = #{params.transactionId}
+            </if>
+            <if test="params.outTradeNo != null and params.outTradeNo!=''">
+                and t1.out_trade_no = #{params.outTradeNo}
+            </if>
+        </where>
         order by t1.create_time desc
     </select>