jsk 数据概览 修改

This commit is contained in:
jiask 2026-02-05 17:01:09 +08:00
parent 3f42f95b41
commit 3c046f5ee6
2 changed files with 1203 additions and 1068 deletions

View File

@ -10,7 +10,7 @@
<select id="getMaTypeDetails" parameterType="com.bonus.index.beans.IndexHomeDetailsBean" resultMap="index"> <select id="getMaTypeDetails" parameterType="com.bonus.index.beans.IndexHomeDetailsBean" resultMap="index">
select * from (
SELECT SELECT
rs.typeId, rs.typeId,
mat2.`NAME` maType, mat2.`NAME` maType,
@ -274,6 +274,16 @@
</if> </if>
</where> </where>
GROUP BY rs.typeId GROUP BY rs.typeId
) a WHERE
typeId IN (
SELECT DISTINCT
mt.ID
FROM
mm_type mt
WHERE
mt.`LEVEL` = 4
AND mt.IS_ACTIVE = 1
)
</select> </select>
@ -597,7 +607,7 @@
mt.`NAME` as maName, mt.`NAME` as maName,
mt.UNIT as maUnit, mt.UNIT as maUnit,
mt.is_COUNT AS isCount, mt.is_COUNT AS isCount,
mt.NUM as storageNum CAST(mt.NUM AS SIGNED) AS storageNum
FROM FROM
mm_type mt mm_type mt
LEFT JOIN mm_type mt2 on mt.PARENT_ID = mt2.ID LEFT JOIN mm_type mt2 on mt.PARENT_ID = mt2.ID
@ -635,57 +645,81 @@
LEFT JOIN v_mtp_status vs on mm.ID = vs.maId LEFT JOIN v_mtp_status vs on mm.ID = vs.maId
WHERE 30> to_days(ifnull(mm.NEXT_CHECK_TIME,now())) - to_days(now()) WHERE 30> to_days(ifnull(mm.NEXT_CHECK_TIME,now())) - to_days(now())
group by mm.ID
</select> </select>
<select id="getInUseWarn" parameterType="com.bonus.index.beans.IndexInuseWarnBean" resultType="com.bonus.index.beans.IndexInuseWarnBean"> <select id="getInUseWarn" parameterType="com.bonus.index.beans.IndexInuseWarnBean" resultType="com.bonus.index.beans.IndexInuseWarnBean">
SELECT SELECT
mt2.`NAME` as maType, mt2.`NAME` AS maType,
mt.`NAME` as maName, mt.`NAME` AS maName,
mt.UNIT as maUnit, mt.UNIT AS maUnit,
COUNT( DISTINCT mm.ID) as inuseNum, COUNT( DISTINCT mm.ID ) AS inuseNum,
MIN(mtp.start_date) as outTime, MIN( filtered_mtp.start_date ) AS outTime,
mt.IS_COUNT as isCount, mt.IS_COUNT AS isCount,
to_days(now()) -to_days(mtp.start_date) as days , DATEDIFF(
wla.`CODE` as agreementCode, NOW(),
bc.`NAME` as projectName, MIN( filtered_mtp.start_date )) AS days,
bp.`NAME` as companyName wla.`CODE` AS agreementCode,
bp.`NAME` AS projectName,
bc.`NAME` AS companyName
FROM FROM
ma_type_project_storage mtp (
LEFT JOIN mm_machines mm on mtp.machine = mm.ID SELECT
LEFT JOIN mm_type mt on mm.TYPE = mt.ID ps.machine,
LEFT JOIN mm_type mt2 on mt.PARENT_ID = mt2.ID ps.agreement_id,
LEFT JOIN wf_lease_agreement wla on mtp.agreement_id = wla.ID ps.start_date
LEFT JOIN bm_project bp on wla.PROJECT = bp.ID FROM
LEFT JOIN bm_company bc on bp.COMPANY_ID = bc.ID ma_type_project_storage ps
WHERE mm.BATCH_STATUS=6 and mtp.`status` =1 INNER JOIN mm_machines mm ON ps.machine = mm.ID
WHERE
ps.`status` = 1
AND ps.`end_date` is null
AND mm.BATCH_STATUS = 6
AND DATEDIFF( NOW(), ps.start_date ) > 180
) AS filtered_mtp
INNER JOIN mm_machines mm ON filtered_mtp.machine = mm.ID
INNER JOIN mm_type mt ON mm.TYPE = mt.ID
LEFT JOIN mm_type mt2 ON mt.PARENT_ID = mt2.ID
LEFT JOIN wf_lease_agreement wla ON filtered_mtp.agreement_id = wla.ID
LEFT JOIN bm_project bp ON wla.PROJECT = bp.ID
LEFT JOIN bm_company bc ON bp.COMPANY_ID = bc.ID
where 1=1
<if test="maType != null and maType != ''"> <if test="maType != null and maType != ''">
and mt2.`NAME` like concat('%', #{maType}, '%') and mt2.`NAME` like concat('%', #{maType}, '%')
</if> </if>
<if test="maName != null and maName != ''"> <if test="maName != null and maName != ''">
and mt.`NAME` like concat('%', #{maName}, '%') and mt.`NAME` like concat('%', #{maName}, '%')
</if> </if>
GROUP BY mm.TYPE GROUP BY
HAVING days > 180 mt.ID,
mt2.ID,
wla.ID,
bp.ID,
bc.ID
</select> </select>
<select id="getTotalChangeWarn" parameterType="com.bonus.index.beans.IndexTotalWarnBean" resultType="com.bonus.index.beans.IndexTotalWarnBean"> <select id="getTotalChangeWarn" parameterType="com.bonus.index.beans.IndexTotalWarnBean" resultType="com.bonus.index.beans.IndexTotalWarnBean">
SELECT SELECT
mt.ID, mt.ID,
mt2.`NAME` as maType, mt2.`NAME` AS maType,
mt.`NAME` as maName, mt.`NAME` AS maName,
mt.UNIT as maUnit, mt.UNIT AS maUnit,
mt.is_count as isCount, mt.is_count AS isCount,
t1.TIME as time, t1.TIME AS time,
t1.content t1.content
FROM ma_total_change t1 FROM ma_total_change t1
LEFT JOIN mm_type mt on mt.ID = t1.type_id LEFT JOIN mm_type mt ON mt.ID = t1.type_id
LEFT JOIN mm_type mt2 on mt.PARENT_ID = mt2.ID LEFT JOIN mm_type mt2 ON mt.PARENT_ID = mt2.ID
WHERE NOT EXISTS ( WHERE
DATEDIFF(NOW(), t1.time) &lt; 30
AND NOT EXISTS (
SELECT 1 SELECT 1
FROM ma_total_change t2 FROM ma_total_change t2
WHERE t2.type_id = t1.type_id AND t2.time > t1.time WHERE
t2.type_id = t1.type_id
AND t2.time > t1.time
) )
<if test="maType != null and maType != ''"> <if test="maType != null and maType != ''">
and mt2.`NAME` like concat('%', #{maType}, '%') and mt2.`NAME` like concat('%', #{maType}, '%')
@ -693,6 +727,7 @@
<if test="maName != null and maName != ''"> <if test="maName != null and maName != ''">
and mt.`NAME` like concat('%', #{maName}, '%') and mt.`NAME` like concat('%', #{maName}, '%')
</if> </if>
order by t1.TIME desc
</select> </select>
<select id="getTotalInfo" parameterType="com.bonus.index.beans.IndexTotalWarnBean" resultType="com.bonus.index.beans.IndexTotalWarnBean"> <select id="getTotalInfo" parameterType="com.bonus.index.beans.IndexTotalWarnBean" resultType="com.bonus.index.beans.IndexTotalWarnBean">
@ -887,7 +922,7 @@
SUM( leaseNum ) - SUM( backNum ) diffCount , SUM( leaseNum ) - SUM( backNum ) diffCount ,
firstTime, firstTime,
lastTime, lastTime,
max(backTime) as backTime max(backTime) as backTime,subName
FROM FROM
( (
SELECT SELECT
@ -901,11 +936,20 @@
wla.ID AS agreementId , wla.ID AS agreementId ,
min(wir.time) as firstTime, min(wir.time) as firstTime,
max(wir.time) as lastTime, max(wir.time) as lastTime,
wir.time as backTime wir.time as backTime,real_sub.subName
FROM FROM
wf_task_record wtr wf_task_record wtr
LEFT JOIN wf_agreement_task wat ON wtr.ID = wat.TASK_ID LEFT JOIN wf_agreement_task wat ON wtr.ID = wat.TASK_ID
LEFT JOIN wf_lease_agreement wla ON wat.AGREEMENT_ID = wla.ID LEFT JOIN wf_lease_agreement wla ON wat.AGREEMENT_ID = wla.ID
left join(
SELECT wla.PROJECT proId ,GROUP_CONCAT( distinct bu.`NAME`) subName
FROM wf_task_record wtr
LEFT JOIN wf_agreement_task wat ON wtr.ID = wat.TASK_ID
LEFT JOIN wf_lease_agreement wla ON wat.AGREEMENT_ID = wla.ID
left join bm_unit bu on bu.id =wla.LEASE_COMPANY
where bu.`NAME` is not null AND wtr.IS_ACTIVE = 1
GROUP BY wla.PROJECT
) real_sub on real_sub.proId=wla.PROJECT
LEFT JOIN bm_project bp ON wla.PROJECT = bp.ID LEFT JOIN bm_project bp ON wla.PROJECT = bp.ID
LEFT JOIN bm_company bc on bp.COMPANY_ID = bc.ID LEFT JOIN bm_company bc on bp.COMPANY_ID = bc.ID
LEFT JOIN wf_task_record wte ON wtr.ID = wte.SUP_ID LEFT JOIN wf_task_record wte ON wtr.ID = wte.SUP_ID
@ -929,28 +973,143 @@
wla.ID AS agreementId , wla.ID AS agreementId ,
"" as firstTime, "" as firstTime,
"" as lastTime, "" as lastTime,
max(wir.time) as backTime max(wir.time) as backTime,real_sub.subName
FROM FROM
wf_task_record wtr wf_task_record wtr
LEFT JOIN wf_agreement_task wat ON wtr.ID = wat.TASK_ID LEFT JOIN wf_agreement_task wat ON wtr.ID = wat.TASK_ID
LEFT JOIN wf_lease_agreement wla ON wat.AGREEMENT_ID = wla.ID LEFT JOIN wf_lease_agreement wla ON wat.AGREEMENT_ID = wla.ID
left join(
SELECT wla.PROJECT proId ,GROUP_CONCAT( distinct bu.`NAME`) subName
FROM wf_task_record wtr
LEFT JOIN wf_agreement_task wat ON wtr.ID = wat.TASK_ID
LEFT JOIN wf_lease_agreement wla ON wat.AGREEMENT_ID = wla.ID
left join bm_unit bu on bu.id =wla.LEASE_COMPANY
where bu.`NAME` is not null AND wtr.IS_ACTIVE = 1
GROUP BY wla.PROJECT
) real_sub on real_sub.proId= wla.PROJECT
LEFT JOIN bm_project bp ON wla.PROJECT = bp.ID LEFT JOIN bm_project bp ON wla.PROJECT = bp.ID
LEFT JOIN bm_company bc on bp.COMPANY_ID = bc.ID LEFT JOIN bm_company bc on bp.COMPANY_ID = bc.ID
LEFT JOIN wf_return_material_details wrd ON wtr.ID = wrd.TASK_ID LEFT JOIN wf_return_material_details wrd ON wtr.ID = wrd.TASK_ID
LEFT JOIN wf_info_record wir ON wrd.ID = wir.SUP_ID LEFT JOIN wf_info_record wir ON wrd.ID = wir.SUP_ID
WHERE WHERE wtr.IS_ACTIVE = 1 AND wir.TYPE = 4
wir.TYPE = 4
AND wtr.IS_ACTIVE = 1
<if test="projectId != null and projectId != ''"> <if test="projectId != null and projectId != ''">
and wla.PROJECT = #{projectId} and wla.PROJECT = #{projectId}
</if> </if>
GROUP BY GROUP BY
wla.ID wla.ID
union
SELECT
bp.id AS id,
bp.`NAME` AS projectName,
bc.ID AS companyId,
bc.`NAME` AS companyName,
"" AS agreementCode,
"0" AS leaseNum,
"0" AS backNum,
"0" AS agreementId,
"" AS firstTime,
"" AS lastTime,
"" AS backTime,
"" AS subName
FROM
bm_project bp
LEFT JOIN bm_company bc ON bp.COMPANY_ID = bc.ID
WHERE
bp.IS_ACTIVE = 1
AND bp.id NOT IN (
SELECT
id
FROM
(
SELECT
wla.PROJECT AS id,
bp.`NAME` AS projectName,
bc.ID AS companyId,
bc.`NAME` AS companyName,
wla.`CODE` AS agreementCode,
SUM( wir.NUM ) AS leaseNum,
"0" AS backNum,
wla.ID AS agreementId,
min( wir.time ) AS firstTime,
max( wir.time ) AS lastTime,
wir.time AS backTime,
real_sub.subName
FROM
wf_task_record wtr
LEFT JOIN wf_agreement_task wat ON wtr.ID = wat.TASK_ID
LEFT JOIN wf_lease_agreement wla ON wat.AGREEMENT_ID = wla.ID
LEFT JOIN (
SELECT
wla.PROJECT proId,
GROUP_CONCAT( DISTINCT bu.`NAME` ) subName
FROM
wf_task_record wtr
LEFT JOIN wf_agreement_task wat ON wtr.ID = wat.TASK_ID
LEFT JOIN wf_lease_agreement wla ON wat.AGREEMENT_ID = wla.ID
LEFT JOIN bm_unit bu ON bu.id = wla.LEASE_COMPANY
WHERE
bu.`NAME` IS NOT NULL
AND wtr.IS_ACTIVE = 1
GROUP BY
wla.PROJECT
) real_sub ON real_sub.proId = wla.PROJECT
LEFT JOIN bm_project bp ON wla.PROJECT = bp.ID
LEFT JOIN bm_company bc ON bp.COMPANY_ID = bc.ID
LEFT JOIN wf_task_record wte ON wtr.ID = wte.SUP_ID
LEFT JOIN wf_info_record wir ON wte.ID = wir.SUP_ID
WHERE
wir.TYPE = 2
AND wtr.IS_ACTIVE = 1
GROUP BY
wla.ID UNION
SELECT
wla.PROJECT AS id,
bp.`NAME` AS projectName,
bc.ID AS companyId,
bc.`NAME` AS companyName,
wla.`CODE` AS agreementCode,
"0" AS leaseNum,
SUM( wir.NUM ) AS backNum,
wla.ID AS agreementId,
"" AS firstTime,
"" AS lastTime,
max( wir.time ) AS backTime,
real_sub.subName
FROM
wf_task_record wtr
LEFT JOIN wf_agreement_task wat ON wtr.ID = wat.TASK_ID
LEFT JOIN wf_lease_agreement wla ON wat.AGREEMENT_ID = wla.ID
LEFT JOIN (
SELECT
wla.PROJECT proId,
GROUP_CONCAT( DISTINCT bu.`NAME` ) subName
FROM
wf_task_record wtr
LEFT JOIN wf_agreement_task wat ON wtr.ID = wat.TASK_ID
LEFT JOIN wf_lease_agreement wla ON wat.AGREEMENT_ID = wla.ID
LEFT JOIN bm_unit bu ON bu.id = wla.LEASE_COMPANY
WHERE
bu.`NAME` IS NOT NULL
AND wtr.IS_ACTIVE = 1
GROUP BY
wla.PROJECT
) real_sub ON real_sub.proId = wla.PROJECT
LEFT JOIN bm_project bp ON wla.PROJECT = bp.ID
LEFT JOIN bm_company bc ON bp.COMPANY_ID = bc.ID
LEFT JOIN wf_return_material_details wrd ON wtr.ID = wrd.TASK_ID
LEFT JOIN wf_info_record wir ON wrd.ID = wir.SUP_ID
WHERE
wtr.IS_ACTIVE = 1
AND wir.TYPE = 4
GROUP BY
wla.ID
) a
)
) a ) a
<where> <where>
<if test="companyId != null and companyId != ''"> <if test="subName != null and subName != ''">
and companyId = #{companyId} AND FIND_IN_SET(subName, #{subName}) > 0
</if> </if>
<if test="projectName != null and projectName != ''"> <if test="projectName != null and projectName != ''">
and projectName like concat('%',#{projectName},'%') and projectName like concat('%',#{projectName},'%')
@ -958,7 +1117,7 @@
</where> </where>
GROUP BY GROUP BY
a.projectName a.projectName
order by diffCount desc order by diffCount,subName desc
</select> </select>
<select id="getProjectMaDiff" parameterType="com.bonus.index.beans.IndexProjectBean" resultType="com.bonus.index.beans.IndexProjectBean"> <select id="getProjectMaDiff" parameterType="com.bonus.index.beans.IndexProjectBean" resultType="com.bonus.index.beans.IndexProjectBean">
@ -1065,19 +1224,22 @@
<select id="getProjectCompany" parameterType="com.bonus.index.beans.IndexProjectBean" resultType="com.bonus.index.beans.IndexProjectBean"> <select id="getProjectCompany" parameterType="com.bonus.index.beans.IndexProjectBean" resultType="com.bonus.index.beans.IndexProjectBean">
SELECT SELECT
bc.ID as companyId, bc.ID as companyId,
bc.`NAME` as companyName bc.`NAME` as companyName
FROM FROM
bm_company bc bm_company bc
WHERE bc.IS_ACTIVE =1 WHERE bc.IS_ACTIVE =1
</select> </select>
<!-- 查询 -->
<select id="getProjectSub" parameterType="com.bonus.index.beans.IndexProjectBean" resultType="com.bonus.index.beans.IndexProjectBean">
SELECT
bs.ID as companyId,
bs.`NAME` as companyName
FROM
bm_unit bs
WHERE bs.IS_ACTIVE =1
</select>
<select id="getToOutList" parameterType="com.bonus.index.beans.IndexTodoWarnBean" resultType="com.bonus.index.beans.IndexTodoWarnBean"> <select id="getToOutList" parameterType="com.bonus.index.beans.IndexTodoWarnBean" resultType="com.bonus.index.beans.IndexTodoWarnBean">
@ -1336,7 +1498,7 @@
cpd.model_id modelId, cpd.model_id modelId,
cpd.need_num needNum, cpd.need_num needNum,
cpd.need_day needDay, cpd.need_day needDay,
cpd.back_date backDate, cpa.need_time backDate,
cpd.remark, cpd.remark,
cmti.type maType, cmti.type maType,
cmti.`NAME` maName, cmti.`NAME` maName,
@ -1348,6 +1510,9 @@
LEFT JOIN bm_project bp ON cpa.pro_id = bp.ID LEFT JOIN bm_project bp ON cpa.pro_id = bp.ID
LEFT JOIN car_ma_type_info cmti ON cpd.model_id = cmti.id LEFT JOIN car_ma_type_info cmti ON cpd.model_id = cmti.id
WHERE bp.`NAME` IS NOT NULL WHERE bp.`NAME` IS NOT NULL
and cpa.status = 2
and cpa.dispatch_num = 0
and cpa.status_type = 1
<if test="projectName != null and projectName != ''"> <if test="projectName != null and projectName != ''">
and bp.`NAME` like concat('%', #{projectName}, '%') and bp.`NAME` like concat('%', #{projectName}, '%')
</if> </if>
@ -1364,7 +1529,7 @@
spd.model_id AS modelId, spd.model_id AS modelId,
spd.need_num AS needNum, spd.need_num AS needNum,
spd.need_day AS needDay, spd.need_day AS needDay,
spd.back_date AS backDate, spa.need_time AS backDate,
spd.remark, spd.remark,
spd.type maType, spd.type maType,
spd.`name` maName, spd.`name` maName,
@ -1374,6 +1539,9 @@
LEFT JOIN st_plan_apply spa ON spd.apply_id = spa.id LEFT JOIN st_plan_apply spa ON spd.apply_id = spa.id
LEFT JOIN bm_project bp ON spa.project_id = bp.ID LEFT JOIN bm_project bp ON spa.project_id = bp.ID
WHERE bp.`NAME` IS NOT NULL WHERE bp.`NAME` IS NOT NULL
and spa.status = 2
and spa.ck_num = 0
and spa.status_type = 1
<if test="projectName != null and projectName != ''"> <if test="projectName != null and projectName != ''">
and bp.`NAME` like concat('%', #{projectName}, '%') and bp.`NAME` like concat('%', #{projectName}, '%')
</if> </if>
@ -1390,7 +1558,7 @@
tpd.model_id moduleId, tpd.model_id moduleId,
tpd.need_num needNum, tpd.need_num needNum,
tpd.need_day needDay, tpd.need_day needDay,
tpd.back_date backDate, tpa.need_time backDate,
tpd.remark, tpd.remark,
tpd.type maType, tpd.type maType,
tpd.`NAME` maName, tpd.`NAME` maName,
@ -1401,6 +1569,8 @@
LEFT JOIN t_plan_apply tpa on tpa.id=tpd.apply_id LEFT JOIN t_plan_apply tpa on tpa.id=tpd.apply_id
LEFT JOIN bm_project pro on tpa.project_id=pro.ID LEFT JOIN bm_project pro on tpa.project_id=pro.ID
WHERE pro.`NAME` is not null WHERE pro.`NAME` is not null
and tpa.status = 2
and tpa.status_type = 1
<if test="maName != null and maName != ''"> <if test="maName != null and maName != ''">
and tpd.`NAME` like concat('%', #{maName}, '%') and tpd.`NAME` like concat('%', #{maName}, '%')
</if> </if>

View File

@ -198,21 +198,30 @@
SELECT SELECT
0 AS storageNum, 0 AS storageNum,
0 AS checkNum, 0 AS checkNum,
COUNT(DISTINCT maId) as useNum, COUNT(*) AS useNum,
0 as changeNum 0 AS changeNum
FROM FROM (
( SELECT 1
SELECT
DISTINCT ps.machine as maId,
to_days(now()) -to_days(ps.start_date) as days
FROM FROM
ma_type_project_storage ps ma_type_project_storage ps
LEFT JOIN mm_machines mm on ps.machine = mm.ID INNER JOIN mm_machines mm ON ps.machine = mm.ID
WHERE ps.`status` =1 and ps.is_count = 0 INNER JOIN mm_type mt ON mm.TYPE = mt.ID
and mm.BATCH_STATUS = 6 LEFT JOIN mm_type mt2 ON mt.PARENT_ID = mt2.ID
GROUP BY ps.machine LEFT JOIN wf_lease_agreement wla ON ps.agreement_id = wla.ID
) rs LEFT JOIN bm_project bp ON wla.PROJECT = bp.ID
WHERE rs.days> 180 LEFT JOIN bm_company bc ON bp.COMPANY_ID = bc.ID
WHERE
ps.status = 1
AND ps.end_date IS NULL
AND mm.BATCH_STATUS = 6
AND DATEDIFF(NOW(), ps.start_date) > 180
GROUP BY
mt.ID,
mt2.ID,
wla.ID,
bp.ID,
bc.ID
) AS t
UNION UNION
SELECT SELECT
@ -316,17 +325,15 @@
<select id="getOverview" parameterType="com.bonus.index.beans.IndexHomeBean" resultType="com.bonus.index.beans.PartOneBean"> <select id="getOverview" parameterType="com.bonus.index.beans.IndexHomeBean" resultType="com.bonus.index.beans.PartOneBean">
SELECT SELECT
SUM(projectCount) projectCount, SUM( projectCount ) projectCount,
SUM(equipmentTypes) equipmentTypes, SUM( equipmentTypes ) equipmentTypes,
SUM(totalCount) totalCount, SUM( totalCount ) totalCount,
SUM(stockCount) stockCount, SUM( stockCount ) stockCount,
SUM(inUseCount) inUseCount, SUM( inUseCount ) inUseCount,
SUM(repairCount) repairCount, SUM( repairCount ) repairCount,
SUM(scrappedCount) scrappedCount SUM( scrappedCount ) scrappedCount
FROM FROM
( (
SELECT SELECT
COUNT( DISTINCT bp.ID ) AS projectCount, COUNT( DISTINCT bp.ID ) AS projectCount,
0 AS equipmentTypes, 0 AS equipmentTypes,
@ -355,31 +362,43 @@
SELECT SELECT
0 AS projectCount, 0 AS projectCount,
0 AS equipmentTypes, 0 AS equipmentTypes,
ROUND( sum( maTotal ) AS totalCount,
IF sum( storageNum ) AS stockCount,
SUM( inuseNum ) AS inUseCount,
SUM( repairNum ) AS repairCount,
SUM( scrapNum ) AS scrappedCount
FROM
( (
SUM( storageNum ) IS NULL, SELECT
0, rs.typeId,
SUM( storageNum )))+ ROUND( mat2.`NAME` maType,
sum( leaseNum ))+ ROUND( mat1.`NAME` maName,
SUM( repairNum )) + ROUND( mat1.UNIT AS maUnit,
SUM( checkNum )) + ROUND( SUM( waitInputNum ) ) AS totalCount, SUM( rs.storageNum )+ SUM( rs.inuseNum ) + SUM( rs.repairNum ) AS maTotal,
0 AS stockCount, SUM( rs.storageNum ) storageNum,
0 AS inUseCount, SUM( rs.inuseNum ) inuseNum,
0 AS repairCount, SUM( rs.repairNum ) repairNum,
0 AS scrappedCount SUM( rs.scrapNum ) scrapNum,
SUM( rs.projectNum ) projectNum,
SUM( rs.inuseCount ) inuseCount,
SUM( rs.backCount ) backCount,
SUM( rs.pyNum ) AS pyNum,
SUM( rs.pkNum ) AS pkNum,
rs.isCount
FROM FROM
( (
SELECT SELECT
mat1.ID AS typeId, mat1.ID AS typeId,
mat1.NUM storageNum, mat1.NUM storageNum,
0 leaseNum, 0 inuseNum,
0 repairNum, 0 repairNum,
0 checkNum,
0 scrapNum, 0 scrapNum,
0 loseNum, 0 projectNum,
0 waitInputNum, 0 inuseCount,
1 AS isCount 0 backCount,
0 AS pyNum,
0 AS pkNum,
mat1.IS_COUNT AS isCount
FROM FROM
mm_type mat1 mm_type mat1
LEFT JOIN mm_type mat2 ON mat2.ID = mat1.PARENT_ID LEFT JOIN mm_type mat2 ON mat2.ID = mat1.PARENT_ID
@ -392,13 +411,15 @@
SELECT SELECT
typeId, typeId,
0 storageNum, 0 storageNum,
sum( leaseNum ) - SUM( backNum ) leaseNum, sum( leaseNum ) - SUM( backNum ) inuseNum,
0 repairNum, 0 repairNum,
0 checkNum,
0 scrapNum, 0 scrapNum,
0 loseNum, 0 projectNum,
0 waitInputNum, sum( leaseNum ) inuseCount,
1 AS isCount SUM( backNum ) backCount,
0 AS pyNum,
0 AS pkNum,
isCount AS isCount
FROM FROM
( (
SELECT SELECT
@ -451,6 +472,20 @@
) a ) a
GROUP BY GROUP BY
typeId UNION typeId UNION
SELECT
typeId,
0 storageNum,
0 inuseNum,
SUM( repairNum ) + SUM( checkNum ) + SUM( waitInputNum ) AS repairNum,
0 scrapNum,
0 projectNum,
0 inuseCount,
0 backCount,
0 AS pyNum,
0 AS pkNum,
isCount
FROM
(
SELECT SELECT
mat1.ID AS typeId, mat1.ID AS typeId,
0 storageNum, 0 storageNum,
@ -460,7 +495,7 @@
0 scrapNum, 0 scrapNum,
0 loseNum, 0 loseNum,
0 waitInputNum, 0 waitInputNum,
1 AS isCount mat1.IS_COUNT AS isCount
FROM FROM
wf_repair_details wrd wf_repair_details wrd
LEFT JOIN mm_type mat1 ON wrd.MODEL_ID = mat1.ID LEFT JOIN mm_type mat1 ON wrd.MODEL_ID = mat1.ID
@ -477,7 +512,7 @@
0 scrapNum, 0 scrapNum,
0 loseNum, 0 loseNum,
0 waitInputNum, 0 waitInputNum,
1 AS isCount mat1.IS_COUNT AS isCount
FROM FROM
wf_repair_check wrc wf_repair_check wrc
LEFT JOIN mm_type mat1 ON wrc.MODEL_ID = mat1.ID LEFT JOIN mm_type mat1 ON wrc.MODEL_ID = mat1.ID
@ -496,7 +531,7 @@
SUM( SUM(
IFNULL( PRE_PUT_NUM, 0 )) - sum( IFNULL( PRE_PUT_NUM, 0 )) - sum(
IFNULL( AL_PUT_NUM, 0 )) AS waitInputNum, IFNULL( AL_PUT_NUM, 0 )) AS waitInputNum,
1 AS isCount mat1.IS_COUNT AS isCount
FROM FROM
wf_put_storage_details wpd wf_put_storage_details wpd
LEFT JOIN mm_type mat1 ON wpd.MODEL_ID = mat1.ID LEFT JOIN mm_type mat1 ON wpd.MODEL_ID = mat1.ID
@ -506,152 +541,21 @@
wpd.IS_SURE = 0 wpd.IS_SURE = 0
GROUP BY GROUP BY
wpd.MODEL_ID wpd.MODEL_ID
) res UNION ) res
SELECT
0 AS projectCount,
0 AS equipmentTypes,
0 AS totalCount,
SUM( mat1.NUM ) AS stockCount,
0 AS inUseCount,
0 AS repairCount,
0 AS scrappedCount
FROM
mm_type mat1
WHERE
mat1.`LEVEL` = 4
AND mat1.IS_ACTIVE = '1' UNION
SELECT
0 AS projectCount,
0 AS equipmentTypes,
0 AS totalCount,
0 AS stockCount,
sum( leaseNum ) - SUM( backNum ) inUseCount,
0 AS repairCount,
0 AS scrappedCount
FROM
(
SELECT
mmt1.`NAME` AS pMachineName,
mmt.`NAME` AS machineName,
mt.`NAME` AS machineModel,
mt.ID AS typeId,
mt.BUY_PRICE AS buyPrice,
mt.UNIT,
SUM( wir.NUM ) AS leaseNum,
0 AS backNum,
mt.IS_COUNT AS isCount
FROM
wf_info_record wir
LEFT JOIN wf_task_record wtr ON wir.SUP_ID = wtr.ID
LEFT JOIN wf_task_record wtr2 ON wtr.SUP_ID = wtr2.ID
LEFT JOIN mm_type mt ON wir.MODEL_ID = mt.ID
LEFT JOIN mm_type mmt ON mt.PARENT_ID = mmt.ID
LEFT JOIN mm_type mmt1 ON mmt.PARENT_ID = mmt1.ID
LEFT JOIN wf_collar_details wcd ON wcd.TASK_ID = wtr.SUP_ID
AND wcd.MODEL_ID = wir.MODEL_ID
WHERE
wir.TYPE = 2
AND wtr2.IS_ACTIVE = 1
AND wcd.IS_APPROVAL = 1
GROUP BY GROUP BY
mt.ID UNION typeId UNION
SELECT
mmt1.`NAME` AS pMachineName,
mmt.`NAME` AS machineName,
mt.`NAME` AS machineModel,
mt.ID AS typeId,
mt.BUY_PRICE AS buyPrice,
mt.UNIT,
0 AS leaseNum,
SUM( wir.NUM ) AS backNum,
mt.IS_COUNT AS isCount
FROM
wf_info_record wir
LEFT JOIN wf_return_material_details wrd ON wir.SUP_ID = wrd.ID
LEFT JOIN wf_task_record wtr ON wrd.TASK_ID = wtr.ID
LEFT JOIN mm_type mt ON wir.MODEL_ID = mt.ID
LEFT JOIN mm_type mmt ON mt.PARENT_ID = mmt.ID
LEFT JOIN mm_type mmt1 ON mmt.PARENT_ID = mmt1.ID
WHERE
wir.TYPE = 4
AND wtr.IS_ACTIVE = 1
GROUP BY
mt.ID
) a UNION
SELECT
0 AS projectCount,
0 AS equipmentTypes,
0 AS totalCount,
0 AS stockCount,
0 inUseCount,
SUM( repairNum )+ SUM( checkNum )+ SUM( waitInputNum ) AS repairCount,
0 AS scrappedCount
FROM
(
SELECT SELECT
mat1.ID AS typeId, mat1.ID AS typeId,
0 storageNum, 0 storageNum,
0 leaseNum, 0 inuseNum,
SUM( wrd.REPAIR_NUM ) - SUM( wrd.ALREPAIR_NUM ) - SUM( SCRAP_NUM ) AS repairNum, 0 AS repairNum,
0 checkNum, SUM( wsd.ALSCRAP_NUM ) AS scrapNum,
0 scrapNum, 0 projectNum,
0 loseNum, 0 inuseCount,
0 waitInputNum, 0 backCount,
1 AS isCount 0 AS pyNum,
FROM 0 AS pkNum,
wf_repair_details wrd mat1.IS_COUNT AS isCount
LEFT JOIN mm_type mat1 ON wrd.MODEL_ID = mat1.ID
LEFT JOIN mm_type mat2 ON mat2.ID = mat1.PARENT_ID
LEFT JOIN mm_type mat3 ON mat3.ID = mat2.PARENT_ID
GROUP BY
wrd.MODEL_ID UNION
SELECT
mat1.ID AS typeId,
0 storageNum,
0 leaseNum,
0 repairNum,
SUM( wrc.CHECK_NUM ) - SUM( wrc.ALCHECK_NUM ) AS checkNum,
0 scrapNum,
0 loseNum,
0 waitInputNum,
1 AS isCount
FROM
wf_repair_check wrc
LEFT JOIN mm_type mat1 ON wrc.MODEL_ID = mat1.ID
LEFT JOIN mm_type mat2 ON mat2.ID = mat1.PARENT_ID
LEFT JOIN mm_type mat3 ON mat3.ID = mat2.PARENT_ID
GROUP BY
wrc.MODEL_ID UNION
SELECT DISTINCT
mat1.ID AS typeId,
0 storageNum,
0 leaseNum,
0 repairNum,
0 checkNum,
0 AS scrapNum,
0 loseNum,
SUM(
IFNULL( PRE_PUT_NUM, 0 )) - sum(
IFNULL( AL_PUT_NUM, 0 )) AS waitInputNum,
1 AS isCount
FROM
wf_put_storage_details wpd
LEFT JOIN mm_type mat1 ON wpd.MODEL_ID = mat1.ID
LEFT JOIN mm_type mat2 ON mat2.ID = mat1.PARENT_ID
LEFT JOIN mm_type mat3 ON mat3.ID = mat2.PARENT_ID
WHERE
wpd.IS_SURE = 0
GROUP BY
wpd.MODEL_ID
) res UNION
SELECT
0 AS projectCount,
0 AS equipmentTypes,
0 AS totalCount,
0 AS stockCount,
0 inUseCount,
0 AS repairCount,
SUM( wsd.ALSCRAP_NUM ) AS scrappedCount
FROM FROM
wf_scrap_details wsd wf_scrap_details wsd
LEFT JOIN mm_type mat1 ON wsd.MODEL_ID = mat1.ID LEFT JOIN mm_type mat1 ON wsd.MODEL_ID = mat1.ID
@ -659,6 +563,67 @@
LEFT JOIN mm_type mat3 ON mat3.ID = mat2.PARENT_ID LEFT JOIN mm_type mat3 ON mat3.ID = mat2.PARENT_ID
WHERE WHERE
wsd.IS_SURE = 1 wsd.IS_SURE = 1
GROUP BY
wsd.MODEL_ID UNION
SELECT
mps.type AS typeId,
0 storageNum,
0 inuseNum,
0 AS repairNum,
0 AS scrapNum,
COUNT( DISTINCT wla.PROJECT ) AS projectNum,
0 inuseCount,
0 backCount,
0 AS pyNum,
0 AS pkNum,
mat1.IS_COUNT AS isCount
FROM
ma_type_project_storage mps
LEFT JOIN wf_lease_agreement wla ON mps.agreement_id = wla.ID
LEFT JOIN mm_type mat1 ON mps.type = mat1.ID
WHERE
mps.`status` = 1
GROUP BY
mps.type UNION
SELECT
typeId,
0 storageNum,
0 inuseNum,
0 AS repairNum,
0 AS scrapNum,
0 AS projectNum,
0 inuseCount,
0 backCount,
SUM( pyNum ) AS pyNum,
SUM( pkNum ) AS pkNum,
isCount
FROM
(
SELECT
mli.TYPE_ID AS typeId,
mli.IS_PROFIT AS type,
IF
( mli.IS_PROFIT = 1, SUM( mli.IN_NUMS ), 0 ) AS pyNum,
IF
( mli.IS_PROFIT = 0, SUM( mli.IN_NUMS ), 0 ) AS pkNum,
mat1.IS_COUNT AS isCount
FROM
ma_lib_inventroy mli
LEFT JOIN mm_type mat1 ON mli.TYPE_ID = mat1.ID
GROUP BY
mli.TYPE_ID,
mli.IS_PROFIT
) res
GROUP BY
typeId
) rs
LEFT JOIN mm_type mat1 ON rs.typeId = mat1.ID
LEFT JOIN mm_type mat2 ON mat2.ID = mat1.PARENT_ID
GROUP BY
rs.typeId
) a
WHERE
typeId IN ( SELECT DISTINCT mt.ID FROM mm_type mt WHERE mt.`LEVEL` = 4 AND mt.IS_ACTIVE = 1 )
) rs ) rs
</select> </select>