统计错误修复

用户表增加索引
This commit is contained in:
dinggang 2022-11-28 19:10:38 +08:00
parent 85e3c58cf8
commit 624140d67a
2 changed files with 228 additions and 87 deletions

View File

@ -0,0 +1,2 @@
ALTER TABLE `sys_user`
ADD INDEX `idx_dept_id`(`dept_id`);

View File

@ -699,46 +699,74 @@
</select>
<select id="getDistrictFundStatement" resultType="java.util.Map">
( SELECT
srg.id AS "districtId ",
SELECT
districtId,
districtName,
SUM(applyPrice) AS "applyPrice"
FROM
(
SELECT
srg.id AS "districtId",
srg.NAME AS "districtName",
convert(IFNULL(SUM( taa.apply_price ), 0) / 10000, decimal(15, 1)) AS "applyPrice",
CONVERT (
IFNULL( SUM( taa.apply_price ), 0 ) / 10000,
DECIMAL ( 15, 1 )) AS "applyPrice",
srg.sort
FROM
( SELECT id, NAME, sort FROM sys_region WHERE tree_level = 3 AND 9 >= sort ) srg
LEFT JOIN sys_dept sd ON sd.district = srg.id
LEFT JOIN sys_user su ON su.dept_id = sd.id
LEFT JOIN t_ability_application taa ON taa.user_id = su.id
LEFT JOIN tb_data_resource tdr ON tdr.dept_id = sd.id
LEFT JOIN (
SELECT
resource_id,
SUM( apply_price ) AS "apply_price"
FROM
t_ability_application taa
WHERE
taa.del_flag = 0
AND taa.approve_status IN ( '通过', '审核中' )
GROUP BY
srg.id
) UNION ALL
SELECT
id AS "districtId",
NAME AS "districtName",
0 AS "applyPrice",
sort
FROM
sys_region
WHERE
tree_level = 3
AND 9 >= sort
AND id NOT IN (
SELECT
srg.id
FROM
( SELECT id, NAME, sort FROM sys_region WHERE tree_level = 3 AND 9 >= sort ) srg
LEFT JOIN sys_dept sd ON sd.district = srg.id
LEFT JOIN sys_user su ON su.dept_id = sd.id
LEFT JOIN t_ability_application taa ON taa.user_id = su.id
WHERE
taa.del_flag = 0
AND taa.approve_status IN ( '通过', '审核中' )
resource_id
) taa ON taa.resource_id = tdr.id
GROUP BY
srg.id
) ORDER BY sort
srg.id UNION ALL
SELECT
tmb.district AS "districtId",
srg.NAME AS "districtName",
SUM( tmb.applyPrice ) AS "applyPrice",
srg.sort
FROM
(
SELECT
sd.id AS "deptId",
tmb.dept AS "deptName",
CONVERT (
IFNULL( SUM( tmb.apply_price ), 0 ) / 10000,
DECIMAL ( 15, 1 )) AS "applyPrice",
sd.district
FROM
t_meetingroom_book tmb
LEFT JOIN ( SELECT id, NAME, district FROM sys_dept ) sd ON tmb.dept = sd.NAME
WHERE
tmb.state IN ( 0, 2 )
GROUP BY
sd.id,
tmb.dept
) tmb
LEFT JOIN ( SELECT id, NAME, tree_level, sort FROM sys_region ) srg ON tmb.district = srg.id
WHERE
srg.tree_level = 3
GROUP BY
tmb.district
) temp
WHERE
temp.districtId IS NOT NULL
GROUP BY
temp.districtId,
temp.districtName,
temp.sort
ORDER BY
temp.sort
</select>
<select id="getComponentFundStatement" resultType="java.util.Map">
@ -797,6 +825,7 @@
WHERE
tdr.del_flag = 0
ORDER BY taa.price DESC
LIMIT 30
</select>
@ -813,11 +842,20 @@
</select>
<select id="getProvideDeptFundStatement" resultType="java.util.Map">
SELECT
deptId,
deptName,
SUM( resourceCount ) AS "resourceCount",
SUM( applyPrice ) AS "applyPrice"
FROM
(
SELECT
sd.id AS "deptId",
sd.NAME AS "deptName",
COUNT( tdr.id ) AS "resourceCount",
convert(IFNULL( SUM( taa.price ), 0 ) / 10000, decimal(15,1)) AS "applyPrice"
CONVERT (
IFNULL( SUM( taa.price ), 0 ) / 10000,
DECIMAL ( 15, 1 )) AS "applyPrice"
FROM
sys_dept sd
LEFT JOIN tb_data_resource tdr ON tdr.dept_id = sd.id
@ -838,18 +876,44 @@
tdr.del_flag = 0
AND sd.type = 2
GROUP BY
sd.id
sd.id UNION ALL
SELECT
1067246875800000066 AS "deptId",
'青岛市大数据发展管理局' AS "deptName",
( SELECT COUNT( id ) FROM t_meetingroom ) AS "resourceCount",
CONVERT (
IFNULL( SUM( tmb.apply_price ), 0 ) / 10000,
DECIMAL ( 15, 1 )) AS "applyPrice"
FROM
t_meetingroom tm
LEFT JOIN t_meetingroom_book tmb ON tmb.room_id = tm.id
WHERE
tm.del_flag = 0
AND tmb.state IN ( 0, 2 )
) temp
GROUP BY
deptId,
deptName
ORDER BY
applyPrice DESC
SUM( applyPrice ) DESC
LIMIT 10
</select>
<select id="getApplyDeptFundStatement" resultType="java.util.Map">
SELECT
deptId,
deptName,
SUM( applyCount ) AS "applyCount",
SUM( applyPrice ) AS "applyPrice"
FROM
(
SELECT
sd.id AS "deptId",
sd.NAME AS "deptName",
SUM( taa.applyCount ) AS "applyCount",
convert(IFNULL( SUM( taa.price ), 0 ) / 10000, decimal(15,1)) AS "applyPrice"
CONVERT (
IFNULL( SUM( taa.price ), 0 ) / 10000,
DECIMAL ( 15, 1 )) AS "applyPrice"
FROM
(
SELECT
@ -869,9 +933,27 @@
WHERE
sd.type = 2
GROUP BY
sd.id
sd.id UNION ALL
SELECT
sd.id AS "deptId",
tmb.dept AS "deptName",
COUNT( tmb.id ) AS "applyCount",
CONVERT (
IFNULL( SUM( tmb.apply_price ), 0 ) / 10000,
DECIMAL ( 15, 1 )) AS "applyPrice"
FROM
t_meetingroom_book tmb
LEFT JOIN ( SELECT id, NAME FROM sys_dept ) sd ON tmb.dept = sd.NAME
WHERE
tmb.state IN ( 0, 2 )
GROUP BY
sd.id,
tmb.dept
) temp
GROUP BY
deptName, deptId
ORDER BY
applyPrice DESC
SUM( applyPrice ) DESC
LIMIT 10
</select>
@ -896,21 +978,78 @@
<select id="getApplyDistrictFundStatement" resultType="java.util.Map">
SELECT
srg.id AS "districtId ",
districtId,
districtName,
SUM( applyCount ),
SUM( applyPrice )
FROM
(
SELECT
srg.id AS "districtId",
srg.NAME AS "districtName",
IFNULL(SUM(taa.applyCount), 0) AS "applyCount",
convert(IFNULL( SUM( taa.apply_price ), 0 ) / 10000, decimal(15,1)) AS "applyPrice",
IFNULL( SUM( taa.applyCount ), 0 ) AS "applyCount",
CONVERT (
IFNULL( SUM( taa.apply_price ), 0 ) / 10000,
DECIMAL ( 15, 1 )) AS "applyPrice",
srg.sort
FROM
( SELECT id, NAME, sort FROM sys_region WHERE tree_level = 3 AND 9 >= sort ) srg
LEFT JOIN sys_dept sd ON sd.district = srg.id
LEFT JOIN tb_data_resource tdr ON tdr.dept_id = sd.id
LEFT JOIN (SELECT resource_id, SUM(apply_price) AS "apply_price", COUNT(id) AS "applyCount" FROM t_ability_application taa WHERE
LEFT JOIN (
SELECT
resource_id,
SUM( apply_price ) AS "apply_price",
COUNT( id ) AS "applyCount"
FROM
t_ability_application taa
WHERE
taa.del_flag = 0
AND taa.approve_status IN ( '通过', '审核中' ) GROUP BY resource_id ) taa ON taa.resource_id = tdr.id
AND taa.approve_status IN ( '通过', '审核中' )
GROUP BY
srg.id
ORDER BY srg.sort
resource_id
) taa ON taa.resource_id = tdr.id
GROUP BY
srg.id UNION ALL
SELECT
tmb.district AS "districtId",
srg.NAME AS "districtName",
SUM( tmb.applyCount ) AS "applyCount",
SUM( tmb.applyPrice ) AS "applyPrice",
srg.sort
FROM
(
SELECT
sd.id AS "deptId",
tmb.dept AS "deptName",
COUNT( tmb.id ) AS "applyCount",
CONVERT (
IFNULL( SUM( tmb.apply_price ), 0 ) / 10000,
DECIMAL ( 15, 1 )) AS "applyPrice",
sd.district
FROM
t_meetingroom_book tmb
LEFT JOIN ( SELECT id, NAME, district FROM sys_dept ) sd ON tmb.dept = sd.NAME
WHERE
tmb.state IN ( 0, 2 )
GROUP BY
sd.id,
tmb.dept
) tmb
LEFT JOIN ( SELECT id, NAME, tree_level, sort FROM sys_region ) srg ON tmb.district = srg.id
WHERE
srg.tree_level = 3
GROUP BY
tmb.district
) temp
WHERE
temp.districtId IS NOT NULL
GROUP BY
temp.districtId,
temp.districtName,
temp.sort
ORDER BY
temp.sort
</select>