问题修改

This commit is contained in:
jiang 2025-10-29 18:14:07 +08:00
parent 199b2ef82d
commit 2b29489f2c
8 changed files with 53 additions and 66 deletions

View File

@ -26,7 +26,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ifnull(sum(mdi.buy_price * mdi.device_count),0) as totalValue,
COUNT(1) as deviceQuantity
from ma_dev_info mdi
left join ma_type_view mtv on mtv.typeId = mdi.type_id
INNER join ma_type_view mtv on mtv.typeId = mdi.type_id
where mdi.is_active = 1 and mtv.MaxTypeId = #{typeId} and mdi.on_company = #{companyId}
<if test="year == 1">
and TIMESTAMPDIFF(YEAR,mdi.production_date, NOW()) <![CDATA[ < ]]> 5
@ -53,7 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
mdi.change_status as status,
mtv.maxTypeId as typeId
from ma_dev_info mdi
left join ma_type_view mtv on mtv.typeId = mdi.type_id
INNER join ma_type_view mtv on mtv.typeId = mdi.type_id
where mdi.is_active = 1 and mdi.on_company = #{companyId}
<if test="typeId != null">
and mtv.MaxTypeId = #{typeId}
@ -80,7 +80,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
when TIMESTAMPDIFF(DAY, NOW(),mdq.next_check_time) <![CDATA[ < ]]> 0 then '已超期'
else '未检' end as situation
from ma_dev_info mdi
left join ma_type_view mtv on mtv.typeId = mdi.type_id
INNER join ma_type_view mtv on mtv.typeId = mdi.type_id
left join ma_dev_qc mdq on mdq.ma_id = mdi.ma_id
where mdi.is_active = 1 and mdi.on_company = #{companyId} and mdi.change_status != 4
order by TIMESTAMPDIFF(YEAR, NOW(),mdq.next_check_time)
@ -89,7 +89,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select
count(DISTINCT mdi.ma_id)
from ma_dev_info mdi
left join ma_type_view mtv on mtv.typeId = mdi.type_id
INNER join ma_type_view mtv on mtv.typeId = mdi.type_id
left join ma_dev_qc mdq on mdq.ma_id = mdi.ma_id
where mdi.is_active = 1 and mdi.on_company = #{companyId} and mdi.change_status != 4
</select>
@ -99,7 +99,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
mtv.devCategory as procedureName,
concat('差',TIMESTAMPDIFF(DAY, NOW(),mdi.expiration_time),'天退役') as situation
from ma_dev_info mdi
left join ma_type_view mtv on mtv.typeId = mdi.type_id
INNER join ma_type_view mtv on mtv.typeId = mdi.type_id
where mdi.is_active = 1 and mdi.on_company = #{companyId} and mdi.change_status != 4
order by TIMESTAMPDIFF(YEAR, NOW(),mdi.expiration_time)
</select>
@ -108,7 +108,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select
count(DISTINCT mdi.ma_id)
from ma_dev_info mdi
left join ma_type_view mtv on mtv.typeId = mdi.type_id
INNER join ma_type_view mtv on mtv.typeId = mdi.type_id
where mdi.is_active = 1 and mdi.on_company = #{companyId} and mdi.change_status != 4
</select>
@ -116,7 +116,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select
count(1)
from ma_dev_info mdi
left join ma_type_view mtv on mtv.typeId = mdi.type_id
INNER join ma_type_view mtv on mtv.typeId = mdi.type_id
where mdi.is_active = 1 and mdi.on_company = #{companyId} and mdi.change_status != 3
</select>
@ -128,7 +128,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
mdi.device_name as deviceName,
CONCAT(ROUND(count(cdcd.dev_id)/mdi.device_count, 2),'次/年') as turnoverRate
from ma_dev_info mdi
left join ma_type_view mtv on mtv.typeId = mdi.type_id
INNER join ma_type_view mtv on mtv.typeId = mdi.type_id
left join cs_device_change_details cdcd on cdcd.dev_id = mdi.ma_id
left join cs_device_change cdc on cdc.id = cdcd.change_id
where mdi.is_active = 1 and mdi.on_company = #{companyId} and mdi.change_status != 4 and cdc.type = 2 and cdc.del_flag = 0
@ -144,7 +144,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
sum(mdi.buy_price * mdi.device_count) as investAmount
from jj_sing_project jsp
left join ma_dev_info mdi on mdi.on_project = jsp.id
left join ma_type_view mtv on mtv.typeId = mdi.type_id
INNER join ma_type_view mtv on mtv.typeId = mdi.type_id
where mdi.is_active = 1 and mdi.on_company = #{companyId} and mdi.change_status in (2,3)
<if test="voltageLevel != null">
and jsp.voltage = #{voltageLevel}
@ -161,7 +161,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select DISTINCT count(1)
from jj_sing_project jsp
left join ma_dev_info mdi on mdi.on_project = jsp.id
left join ma_type_view mtv on mtv.typeId = mdi.type_id
INNER join ma_type_view mtv on mtv.typeId = mdi.type_id
where mdi.is_active = 1
and mdi.on_company = #{companyId}
and mdi.change_status in (2, 3)
@ -182,7 +182,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select DISTINCT ifnull(sum(mdi.device_count),0) as num
from jj_sing_project jsp
left join ma_dev_info mdi on mdi.on_project = jsp.id
left join ma_type_view mtv on mtv.typeId = mdi.type_id
INNER join ma_type_view mtv on mtv.typeId = mdi.type_id
where mdi.is_active = 1
and mdi.on_company = #{companyId}
and mdi.change_status in (2, 3)
@ -206,7 +206,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
sum(mdi.device_count) as useNum
from jj_sing_project jsp
left join ma_dev_info mdi on mdi.on_project = jsp.id
left join ma_type_view mtv on mtv.typeId = mdi.type_id
INNER join ma_type_view mtv on mtv.typeId = mdi.type_id
<!-- left join coordinate_point cp on cp.name = jsp.county-->
where mdi.is_active = 1
<!-- and mdi.change_status in (2,3)-->
@ -221,7 +221,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ifnull(sum(mdi.device_count),0) as useNum
from jj_sing_project jsp
left join ma_dev_info mdi on mdi.on_project = jsp.id
left join ma_type_view mtv on mtv.typeId = mdi.type_id
INNER join ma_type_view mtv on mtv.typeId = mdi.type_id
where mdi.is_active = 1
and mdi.change_status in (1,5)
and jsp.city = #{city}
@ -233,7 +233,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from (select DISTINCT ifnull(sum(mdi.device_count), 0) as useNum
from jj_sing_project jsp
left join ma_dev_info mdi on mdi.on_project = jsp.id
left join ma_type_view mtv on mtv.typeId = mdi.type_id
INNER join ma_type_view mtv on mtv.typeId = mdi.type_id
where mdi.is_active = 1
and (mdi.change_status in (2, 3) or mdi.change_status is null)
and jsp.city != #{city}) r

View File

@ -70,7 +70,7 @@
dev.on_project proId,dev.change_status AS status
FROM ma_dev_info dev
left join bm_company_info bci on bci.company_id=dev.on_company
left join ma_type_view mt on mt.typeId=dev.type_id
INNER join ma_type_view mt on mt.typeId=dev.type_id
LEFT JOIN (SELECT max( next_check_time) next_check_time,ma_id from ma_dev_qc GROUP BY ma_id ) mdq on
dev.ma_id=mdq.ma_id
left join jj_sing_project pro on pro.pro_code=dev.on_project
@ -203,7 +203,7 @@
FROM cs_device_change_details dcd
left join ma_dev_info dev on dcd.dev_id = dev.ma_id
left join bm_company_info bci on bci.company_id = dev.on_company
left join ma_type_view mt on mt.typeId = dev.type_id
INNER join ma_type_view mt on mt.typeId = dev.type_id
LEFT JOIN
(SELECT max(next_check_time) next_check_time, ma_id
from ma_dev_qc

View File

@ -251,20 +251,7 @@
count(distinct if(mdi.change_status = '5', mdi.ma_id, null)) as underRepair
FROM
ma_dev_info mdi
LEFT JOIN ma_dev_qc mdq ON mdq.ma_id = mdi.ma_id
LEFT JOIN sys_dept sd ON sd.dept_id = mdi.on_company
LEFT JOIN bm_company_info c ON sd.dept_id = c.company_id
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
WHERE mdi.is_active = 1
<if test="typeId != null">
and (
mtv.mainGxId = #{typeId}
or mtv.childGxId = #{typeId}
or mtv.devCategoryId = #{typeId}
or mtv.devSubcategoryId = #{typeId}
or mtv.maxTypeId = #{typeId}
)
</if>
</select>
<select id="getProperties" resultType="com.bonus.material.device.domain.vo.DevInfoPropertyVo">
@ -345,7 +332,7 @@
AND `status` IN ( 2, 3 )) AS usageCount,
sc.name AS province
from ma_dev_info mdi
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
LEFT JOIN jj_sing_project jsp ON mdi.on_project = jsp.pro_code
LEFT JOIN sys_dept sd ON sd.dept_id = mdi.on_company
LEFT JOIN (SELECT max( next_check_time) next_check_time,ma_id from ma_dev_qc GROUP BY ma_id ) mdq on
@ -472,7 +459,7 @@
mdq.next_check_time AS nextMaintenanceDate,
mdi.max_working_hours AS maxServiceLifeYears
from ma_dev_info mdi
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
LEFT JOIN jj_sing_project jsp ON mdi.on_project = jsp.pro_code
LEFT JOIN sys_dept sd ON sd.dept_id = mdi.on_company
LEFT JOIN (SELECT max( next_check_time) next_check_time,ma_id from ma_dev_qc GROUP BY ma_id ) mdq on

View File

@ -78,7 +78,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ma_dev_info d
LEFT JOIN sys_dept sd ON d.on_company = sd.dept_id
LEFT JOIN bm_company_info c ON sd.dept_id = c.company_id
LEFT JOIN ma_type_view mtv ON mtv.typeId = d.type_id
INNER JOIN ma_type_view mtv ON mtv.typeId = d.type_id
LEFT JOIN bm_file_info bfi on d.ma_id = bfi.model_id and bfi.file_type = '0' and bfi.task_type = '17'
LEFT JOIN ma_dev_file mdf on d.ma_id = mdf.ma_id and mdf.file_type = '1' and mdf.is_active = '1'
<where>
@ -229,7 +229,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
LEFT JOIN sys_dept sd ON d.on_company = sd.dept_id
LEFT JOIN bm_company_info c ON sd.dept_id = c.company_id
LEFT JOIN ma_hot_search h ON d.ma_id = h.ma_id
LEFT JOIN ma_type_view mtv ON mtv.typeId = d.type_id
INNER JOIN ma_type_view mtv ON mtv.typeId = d.type_id
LEFT JOIN ma_type mt4 ON mt4.type_id = d.type_id and mt4.del_flag = '0'
LEFT JOIN ma_type mt3 ON mt3.type_id = mt4.parent_id and mt3.del_flag = '0'
LEFT JOIN ma_type mt2 ON mt2.type_id = mt3.parent_id and mt2.del_flag = '0'
@ -1369,28 +1369,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="getLineNum" resultType="java.lang.Integer">
select count(1)
from ma_dev_info mdi
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
where mtv.maxTypeId = #{typeId}
and mdi.is_active = '1'
</select>
<select id="getLinePrice" resultType="java.math.BigDecimal">
select sum(mdi.buy_price)
from ma_dev_info mdi
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
where mtv.maxTypeId = #{typeId}
and mdi.is_active = '1'
</select>
<select id="getLineProductionDateList" resultType="java.lang.String">
select production_date
from ma_dev_info mdi
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
where mtv.maxTypeId = #{typeId}
and mdi.is_active = '1'
</select>
<select id="getUnitEquipmentConfiguration" resultType="com.bonus.material.equipment.domain.SysDept">
select production_date
from ma_dev_info mdi
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
where mtv.maxTypeId = #{typeId}
and mdi.is_active = '1'
</select>
@ -1436,7 +1436,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ma_dev_info d
LEFT JOIN sys_dept sd ON d.on_company = sd.dept_id
LEFT JOIN bm_company_info c ON sd.dept_id = c.company_id
LEFT JOIN ma_type_view mtv ON mtv.typeId = d.type_id
INNER JOIN ma_type_view mtv ON mtv.typeId = d.type_id
<where>
<if test="maId != null "> and d.ma_id = #{maId}</if>
<if test="code != null and code != ''"> and d.code = #{code}</if>
@ -1507,7 +1507,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="getTotalEquipmentByLevel" resultType="java.lang.Integer">
select count(1)
from ma_dev_info mdi
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
where mtv.typeId = #{typeId} and mdi.is_active ='1'
<if test="changeStatus != null ">
AND change_status = #{changeStatus}
@ -1517,7 +1517,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select count(1) from cs_device_change_details cdcd
left join cs_device_change cdc on cdcd.change_id = cdc.id
left join ma_dev_info mdi on mdi.ma_id = cdcd.dev_id
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
where cdcd.del_flag = '0'
AND cdc.create_time >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH)
<if test="typeId != null ">

View File

@ -68,7 +68,7 @@
LEFT JOIN cs_device_status cds ON cdrd.cs_id = cds.id
LEFT JOIN sys_dept sd ON d.on_company = sd.dept_id
LEFT JOIN bm_company_info c ON sd.dept_id = c.company_id
LEFT JOIN ma_type_view mtv ON mtv.typeId = d.type_id
INNER JOIN ma_type_view mtv ON mtv.typeId = d.type_id
<where>
<if test="orderId != null and orderId != ''">
and cdrd.cs_id = #{orderId}
@ -248,7 +248,7 @@
type_name AS label,
parent_id AS parentId
FROM ma_type
WHERE parent_id IS NULL
WHERE parent_id = '0'
AND del_flag = '0'; -- 排除已删除的数据
</select>
<select id="findSecondAndThirdLevelTypes" resultType="java.util.Map">
@ -262,7 +262,7 @@
JOIN ma_type t2 ON t1.type_id = t2.parent_id
OR t1.type_id = (SELECT parent_id FROM ma_type WHERE type_id = t2.parent_id)
WHERE t1.type_id = #{firstLevelId} -- 一级类型ID
AND t1.parent_id IS NULL -- 确保t1是一级类型
AND t1.parent_id = '0' -- 确保t1是一级类型
AND t2.del_flag = '0'
</select>
@ -325,7 +325,7 @@
AND t5.del_flag = '0' -- 五级
) AS all_levels ON t.type_id = all_levels.type_id
WHERE t1.type_id = #{firstLevelId}
AND t1.parent_id IS NULL -- 确保是一级类型
AND t1.parent_id = '0' -- 确保是一级类型
AND t.del_flag = '0'
</select>
<select id="selectTodayOrderCount" resultType="java.lang.Integer">
@ -379,7 +379,7 @@
from cs_device_status cds
LEFT JOIN cs_device_real_dev cdrd ON cdrd.cs_id = cds.id
LEFT JOIN ma_dev_info mdi ON cdrd.dev_id = mdi.ma_id
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
LEFT JOIN jj_sing_project jsp ON mdi.on_project = jsp.pro_code
LEFT JOIN sys_dept sd ON sd.dept_id = mdi.on_company
LEFT JOIN (SELECT max( next_check_time) next_check_time,ma_id from ma_dev_qc GROUP BY ma_id ) mdq on
@ -480,7 +480,7 @@
from cs_device_status cds
LEFT JOIN cs_device_real_dev cdrd ON cdrd.cs_id = cds.id
LEFT JOIN ma_dev_info mdi ON cdrd.dev_id = mdi.ma_id
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
LEFT JOIN jj_sing_project jsp ON mdi.on_project = jsp.pro_code
LEFT JOIN sys_dept sd ON sd.dept_id = mdi.on_company
LEFT JOIN (SELECT max( next_check_time) next_check_time,ma_id from ma_dev_qc GROUP BY ma_id ) mdq on

View File

@ -785,7 +785,7 @@
END) AS fiveOrTen
FROM
ma_dev_info mdi
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
WHERE
-- 过滤目标proType只处理需要的三类
mtv.proType IN ('变电施工类', '架空输电线路工程', '电缆(海缆)工程')
@ -827,7 +827,7 @@
ELSE 0
END) AS fiveOrTen
FROM ma_dev_info mdi
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
WHERE mdi.change_status != '4'
and mdi.is_active = '1'
and
@ -841,7 +841,7 @@
sum(mdi.buy_price) AS price,
mtv.devSubcategory AS name
FROM ma_dev_info mdi
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id and mdi.change_status != '4' and mdi.is_active ='1'
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id and mdi.change_status != '4' and mdi.is_active ='1'
WHERE
-- 过滤目标proType只处理需要的三类
mtv.maxTypeId IN (#{type})
@ -850,6 +850,7 @@
ORDER BY
price DESC
Limit 10
</select>
<select id="statByTypeAndAgeByCity" resultType="java.util.Map">
SELECT sd.dept_name AS name,
@ -871,7 +872,7 @@
AND mdi.change_status != '4'
AND mdi.is_active = '1'
-- 左连接类型表不在这里加maxTypeId条件避免过滤主表
LEFT JOIN ma_type_view mtv
INNER JOIN ma_type_view mtv
ON mtv.typeId = mdi.type_id
GROUP BY sd.dept_id, sd.dept_name -- 按部门分组,确保所有部门都被列出
ORDER BY count DESC
@ -885,15 +886,15 @@
ELSE 0
END) AS count,
SUM(CASE
WHEN mtv.maxTypeId = 5080 THEN 1 -- 仅当类型符合时计数
WHEN mtv.maxTypeId = 1 THEN 1 -- 仅当类型符合时计数
ELSE 0
END) AS cableCount,
SUM(CASE
WHEN mtv.maxTypeId = 5010 THEN 1 -- 仅当类型符合时计数
WHEN mtv.maxTypeId = 3 THEN 1 -- 仅当类型符合时计数
ELSE 0
END) AS substationCount,
SUM(CASE
WHEN mtv.maxTypeId = 5474 THEN 1 -- 仅当类型符合时计数
WHEN mtv.maxTypeId = 2 THEN 1 -- 仅当类型符合时计数
ELSE 0
END) AS lineCount
FROM sys_dept sd
@ -903,7 +904,7 @@
AND mdi.change_status != '4'
AND mdi.is_active = '1'
-- 左连接类型表不在这里加maxTypeId条件避免过滤主表
LEFT JOIN ma_type_view mtv
INNER JOIN ma_type_view mtv
ON mtv.typeId = mdi.type_id
GROUP BY sd.dept_id, sd.dept_name -- 按部门分组,确保所有部门都被列出
ORDER BY count DESC
@ -911,14 +912,14 @@
<select id="statByTypeAndAgeByTurnoverRate" resultType="java.util.Map">
SELECT DATE_FORMAT(cdcd.use_time, '%Y/%m') AS month,-- 月份
-- 统计不同类型设备的有效使用次数status为2/3
SUM(CASE WHEN mtv.maxTypeId = 5080 AND cdcd.`status` IN (2, 3) THEN 1 ELSE 0 END) AS cableCount,
SUM(CASE WHEN mtv.maxTypeId = 5010 AND cdcd.`status` IN (2, 3) THEN 1 ELSE 0 END) AS substationCount,
SUM(CASE WHEN mtv.maxTypeId = 5474 AND cdcd.`status` IN (2, 3) THEN 1 ELSE 0 END) AS lineCount
SUM(CASE WHEN mtv.maxTypeId = 1 AND cdcd.`status` IN (2, 3) THEN 1 ELSE 0 END) AS cableCount,
SUM(CASE WHEN mtv.maxTypeId = 3 AND cdcd.`status` IN (2, 3) THEN 1 ELSE 0 END) AS substationCount,
SUM(CASE WHEN mtv.maxTypeId = 2 AND cdcd.`status` IN (2, 3) THEN 1 ELSE 0 END) AS lineCount
FROM cs_device_change_details cdcd -- 左连接设备表(过滤有效设备)
LEFT JOIN ma_dev_info mdi ON cdcd.dev_id = mdi.ma_id -- 关联设备ID
AND mdi.change_status != '4'
AND mdi.is_active = '1' -- 左连接类型表(获取设备类型)
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id -- 过滤无效的使用时间可选避免NULL的月份
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id -- 过滤无效的使用时间可选避免NULL的月份
WHERE cdcd.use_time IS NOT NULL
AND mdi.ma_id IS NOT NULL -- 按「设备ID+月份」分组(核心修正)
@ -957,21 +958,21 @@
COUNT(DISTINCT mddu.ma_id) AS total_devs, -- 当日总设备数(去重)
-- 5080类型当日在用设备数status=1且类型=5080
COUNT(DISTINCT CASE
WHEN mddu.status = 1 AND mtv.maxTypeId = 5080
WHEN mddu.status = 1 AND mtv.maxTypeId = 1
THEN mddu.ma_id END) AS cable_use,
-- 5010类型当日在用设备数
COUNT(DISTINCT CASE
WHEN mddu.status = 1 AND mtv.maxTypeId = 5010
WHEN mddu.status = 1 AND mtv.maxTypeId = 3
THEN mddu.ma_id END) AS substation_use,
-- 5474类型当日在用设备数
COUNT(DISTINCT CASE
WHEN mddu.status = 1 AND mtv.maxTypeId = 5474
WHEN mddu.status = 1 AND mtv.maxTypeId = 2
THEN mddu.ma_id END) AS line_use
FROM ma_dev_daily_use mddu
-- 关联类型表时过滤目标类型,减少关联数据量(核心优化)
LEFT JOIN ma_type_view mtv
INNER JOIN ma_type_view mtv
ON mtv.typeId = mddu.type_id
AND mtv.maxTypeId IN (5080, 5010, 5474) -- 只关联需要的类型
AND mtv.maxTypeId IN (1, 3, 2) -- 只关联需要的类型
GROUP BY DATE(mddu.create_time)) AS dt -- dt = daily_total每日统计基础数据
) AS daily_stats
GROUP BY DATE_FORMAT(stat_date, '%Y-%m')

View File

@ -643,7 +643,7 @@
-- 关联每日使用记录,获取设备状态
LEFT JOIN ma_dev_daily_use mddu ON mddu.ma_id = mdi.ma_id
-- 关联类型视图获取小类devSubcategory和大类maxTypeId=5080
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
WHERE
mdi.is_active = '1'
AND mdi.change_status != '4'
@ -664,7 +664,7 @@
-- 关联设备信息表,筛选有效设备
LEFT JOIN ma_dev_info mdi ON mdi.ma_id = cdcd.dev_id
-- 关联类型视图,限定小类和大类
LEFT JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
WHERE
cdcd.`use_time` is not null -- 出库状态
AND mdi.is_active = '1'

View File

@ -32,7 +32,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
d.order_num,
d.leader,
d.phone,
d.email,
d.status,
d.del_flag,
d.create_by,