Bonus-Cloud-Material/bonus-modules/bonus-material/src/main/resources/mapper/material/lossAssessment/LossAssignMapper.xml

631 lines
25 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.material.lossAssessment.mapper.LossAssignMapper">
<resultMap type="com.bonus.material.ma.domain.Type" id="TypeResult">
<result property="typeId" column="type_id" />
<result property="typeName" column="type_name" />
<result property="parentId" column="parent_id" />
<result property="keeperNickName" column="keeper_nick_name" />
<result property="repairNickName" column="repair_nick_name" />
<result property="houseId" column="house_id" />
<result property="houseName" column="house_name" />
<result property="storageNum" column="storage_num" />
<result property="typeCode" column="type_code" />
<result property="modelCode" column="model_code" />
<result property="unitId" column="unit_id" />
<result property="unitName" column="unit_name" />
<result property="unitValue" column="unit_value" />
<result property="sortNum" column="sort_num" />
<result property="manageType" column="manage_type" />
<result property="leasePrice" column="lease_price" />
<result property="effTime" column="eff_time" />
<result property="rentPrice" column="rent_price" />
<result property="buyPrice" column="buy_price" />
<result property="payRatio" column="pay_ratio" />
<result property="payPrice" column="pay_price" />
<result property="taxRatio" column="tax_ratio" />
<result property="level" column="level" />
<result property="ratedLoad" column="rated_load" />
<result property="testLoad" column="test_load" />
<result property="holdingTime" column="holding_time" />
<result property="warnNum" column="warn_num" />
<result property="delFlag" column="del_flag" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="isPlan" column="is_plan" />
<result property="isAncuo" column="is_ancuo" />
<result property="remark" column="remark" />
<result property="facModel" column="fac_model" />
<result property="intelligentCode" column="intelligent_code" />
<result property="isTest" column="is_test" />
<result property="companyId" column="company_id" />
<result property="samplingRatio" column="sampling_ratio" />
<result property="isEnter" column="is_enter" />
<result property="keeperUserId" column="keep_user_id" />
<result property="isCheck" column="is_check" />
<result property="jiJuType" column="jiju_type" />
</resultMap>
<insert id="saveDirectApplyInfo" keyProperty="id" useGeneratedKeys="true">
insert into bm_loss_assign
(
<if test="code != null and code != ''">
code,
</if>
<if test="agreementId != null ">
agreement_id,
</if>
<if test="lossMan != null and lossMan != ''">
loss_man,
</if>
<if test="lossPhone != null and lossPhone != ''">
phone,
</if>
<if test="lossUrl != null and lossUrl != ''">
loss_url,
</if>
<if test="status != null">
status,
</if>
<if test="createBy != null">
create_by,
</if>
create_time,
del_flag
) values (
<if test="code != null and code != ''">
#{code},
</if>
<if test="agreementId != null">
#{agreementId},
</if>
<if test="lossMan != null and lossMan != ''">
#{lossMan},
</if>
<if test="lossPhone != null and lossPhone != ''">
#{lossPhone},
</if>
<if test="lossUrl != null and lossUrl != ''">
#{lossUrl},
</if>
<if test="status != null">
#{status},
</if>
<if test="createBy != null">
#{createBy},
</if>
NOW(),
'1'
)
</insert>
<insert id="saveDirectApplyDetails">
insert into bm_loss_assign_details(loss_assign_id, type_id, ma_id, num, create_by,create_time, del_flag)
values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.lossId}, #{item.typeId}, #{item.maId}, #{item.lossNum}, #{item.createBy}, NOW() , '1')
</foreach>
</insert>
<insert id="insertWorkOrder" useGeneratedKeys="true" keyProperty="id">
insert into uni_org.sys_information
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="createTime != null">create_time,</if>
<if test="createUserName != null">create_user_name,</if>
<if test="title != null">title,</if>
<if test="content != null">content,</if>
<if test="webAppId != null">web_app_id,</if>
<if test="type != null">type,</if>
<if test="extend != null">extend,</if>
<if test="sendUserName != null">send_user_name,</if>
<if test="webUrl != null">web_url,</if>
<if test="typeId != null">type_id,</if>
<if test="businessId != null">business_id,</if>
<if test="flowState != null">flow_state,</if>
<if test="rout != null">rout,</if>
<if test="nextStatus != null">next_status,</if>
<if test="extendName != null">extend_name,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="createTime != null">now(),</if>
<if test="createUserName != null">#{createUserName},</if>
<if test="title != null">#{title},</if>
<if test="content != null">#{content},</if>
<if test="webAppId != null">#{webAppId},</if>
<if test="type != null">#{type},</if>
<if test="extend != null">#{extend},</if>
<if test="sendUserName != null">#{sendUserName},</if>
<if test="webUrl != null">#{webUrl},</if>
<if test="typeId != null">#{typeId},</if>
<if test="businessId != null">#{businessId},</if>
<if test="flowState != null">#{flowState},</if>
<if test="rout != null">#{rout},</if>
<if test="nextStatus != null">#{nextStatus},</if>
<if test="extendName != null">#{extendName},</if>
</trim>
</insert>
<insert id="insertWorkPeople">
insert into uni_org.sys_information_people
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="createTime != null">create_time,</if>
<if test="updateTime != null">update_time,</if>
<if test="informationId != null">information_id,</if>
<if test="readState != null">read_state,</if>
<if test="handleState != null">handle_state,</if>
<if test="receiverUsername != null">receiver_username,</if>
<if test="updateUser != null">update_user,</if>
<if test="isExamine != null">is_examine,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="createTime != null">now(),</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="informationId != null">#{informationId},</if>
<if test="readState != null">#{readState},</if>
<if test="handleState != null">#{handleState},</if>
<if test="receiverUsername != null">#{receiverUsername},</if>
<if test="updateUser != null">#{updateUser},</if>
<if test="isExamine != null">#{isExamine},</if>
</trim>
</insert>
<update id="updateDirectApplyInfo">
update bm_loss_assign
set
<if test="agreementId != null">
agreement_id = #{agreementId},
</if>
<if test="lossMan != null">
loss_man = #{lossMan},
</if>
<if test="lossPhone != null">
phone = #{lossPhone},
</if>
<if test="lossUrl != null">
loss_url = #{lossUrl},
</if>
<if test="status != null">
status = #{status},
</if>
update_time= NOW()
where id = #{id}
</update>
<update id="updateStatus">
update ma_machine
set
ma_status = #{maStatus}
where ma_id = #{maId}
</update>
<update id="updateLossDate">
update slt_agreement_info set end_time = now() where ma_id = #{maId} and agreement_id = #{agreementId} and status = 0
</update>
<delete id="deleteDirectApplyDetails">
update bm_loss_assign_details
set del_flag = '0'
where loss_assign_id = #{id}
</delete>
<delete id="deleteWorkflowRecord">
delete from sys_workflow_record where id = #{newId}
</delete>
<delete id="deleteDirectApplyInfo">
update bm_loss_assign
set del_flag = '0'
where id = #{id}
</delete>
<delete id="deleteApplyDetails">
delete from bm_loss_assign_details where loss_assign_id = #{id}
</delete>
<select id="getUseData" resultType="com.bonus.material.settlement.domain.SltAgreementInfo">
SELECT
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
mt.unit_name AS unitName,
sum( sai.num ) AS useNum ,
mm.ma_code AS maCode,
lai.lease_person AS leasePerson,
DATE(sai.start_time) AS startTime,
mm.next_check_time AS nextCheckTime,
sai.ma_id AS maId,
sai.type_id AS typeId,
sai.agreement_id AS agreementId,
lai.create_time AS createTime,
mt.unit_value AS unitValue,
mt.jiju_type AS jiJuType
FROM
slt_agreement_info sai
LEFT JOIN ma_type mt ON sai.type_id = mt.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
LEFT JOIN ma_machine mm ON sai.ma_id = mm.ma_id
LEFT JOIN lease_apply_info lai ON lai.id = sai.lease_id
WHERE
sai.agreement_id = #{agreementId} AND sai.status = '0'
AND mt.manage_type = 0 AND sai.ma_id is not null
AND mm.ma_status = '2'
<if test="typeId != null">
AND sai.type_id = #{typeId}
</if>
<if test="maId != null">
AND mt.parent_id = #{maId}
</if>
<if test="startDate != null and endDate != ''">
AND DATE_FORMAT(lai.create_time, '%Y-%m-%d' ) BETWEEN #{startDate} AND #{endDate}
</if>
<if test="keyWord != null and keyWord != ''">
AND (mt2.type_name like concat('%', #{keyWord}, '%') or
mt.type_name like concat('%', #{keyWord}, '%') or
mm.ma_code like concat('%', #{keyWord}, '%')
)
</if>
GROUP BY
sai.type_id,
sai.ma_id
</select>
<select id="getBatchInfo" resultType="com.bonus.material.settlement.domain.SltAgreementInfo">
SELECT
bl.agreement_id AS agreementId,
blad.type_id AS typeId,
blad.ma_id AS maId,
bl.id AS id,
SUM(IFNULL(blad.num, 0)) AS waitTransNum -- 待转数量
FROM
bm_loss_assign bl
INNER JOIN bm_loss_assign_details blad ON bl.id = blad.loss_assign_id
WHERE
bl.`status` IN (0, 1)
and bl.del_flag = '1'
and blad.del_flag = '1'
AND bl.agreement_id = #{agreementId}
AND (
<foreach collection="pairs" item="pair" separator="OR">
(blad.type_id = #{pair.typeId}
<if test="pair.maId != null">AND blad.ma_id = #{pair.maId}</if>
<if test="pair.maId == null">AND blad.ma_id IS NULL</if>)
</foreach>
)
AND IFNULL(blad.num, 0) > 0 -- 提前过滤0值减少计算
GROUP BY
bl.agreement_id, blad.type_id, blad.ma_id, bl.id;
</select>
<select id="getListAll" resultType="java.lang.Integer">
SELECT
COUNT(*)
FROM
bm_loss_assign
</select>
<select id="getDeptId" resultType="java.lang.String">
select
project_leader_id as leaderId
from
data_center.dx_fb_son
where
id = #{externalId}
</select>
<select id="getUserNameById" resultType="java.lang.String">
select
account as userName
from
data_center.dc_user
where
id = #{leaderId}
</select>
<select id="getUserIdByUserName" resultType="com.bonus.common.biz.domain.lease.WorkPeopleInfo">
select
user_id as userId,
user_name as userName
from
sys_user
where user_name = #{userName}
</select>
<select id="getInfoById" resultType="com.bonus.material.lossAssessment.domain.LossAssignInfo">
SELECT DISTINCT
bla.id AS id,
bla.code AS code,
bla.create_time AS createTime,
bui.unit_id AS lossUnitId,
bui.unit_name AS lossUnitName,
bpl.pro_id AS lossProId,
bpl.pro_name AS lossProName,
bla.status as status,
bla.loss_url as lossUrl,
bla.loss_man as lossMan,
bla.phone as lossPhone,
bpl.external_id as lossExternalId
FROM
bm_loss_assign bla
LEFT JOIN bm_agreement_info bai ON bla.agreement_id = bai.agreement_id
LEFT JOIN bm_project bpl ON bpl.pro_id = bai.project_id
LEFT JOIN bm_unit bui ON bui.unit_id = bai.unit_id
WHERE
bla.del_flag = '1' and bla.id = #{id}
</select>
<select id="getDetailsById" resultType="com.bonus.material.lossAssessment.domain.LossAssignDetails">
SELECT blad.id AS id,
blad.loss_assign_id AS lossId,
blad.type_id AS typeId,
blad.ma_id AS maId,
blad.num AS lossNum,
mt1.type_name AS typeModelName,
mt2.type_name AS typeName,
mm.ma_code AS maCode,
mt1.unit_name AS unitName,
cla.lease_person AS leasePerson,
csi.start_time AS startTime,
bla.agreement_id AS agreementId,
SUM(CASE WHEN csi.status = '0' and mm.ma_status = '2' THEN IFNULL(csi.num, 0) ELSE 0 END) AS useNum
FROM bm_loss_assign_details blad
LEFT JOIN ma_type mt1 on mt1.type_id = blad.type_id
LEFT JOIN ma_type mt2 on mt2.type_id = mt1.parent_id
LEFT JOIN ma_machine mm on mm.ma_id = blad.ma_id
LEFT JOIN bm_loss_assign bla ON blad.loss_assign_id = bla.id
LEFT JOIN slt_agreement_info csi ON bla.agreement_id = csi.agreement_id
and csi.ma_id = mm.ma_id and csi.type_id = blad.type_id
LEFT JOIN lease_apply_info cla ON csi.lease_id = cla.id
WHERE blad.del_flag = '1' and blad.loss_assign_id = #{id}
GROUP BY
blad.type_id,
blad.ma_id
</select>
<select id="getDeptInfo" resultType="com.bonus.material.lossAssessment.domain.LossAssignInfo">
SELECT DISTINCT
df.project_dept AS lossDepartName,
sd.dept_name AS lossImpUnitName
FROM
bm_project bp
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
LEFT JOIN data_center.dx_fb_son df ON bp.external_id = df.id
WHERE
bp.pro_center IS NOT NULL
AND bp.external_id IS NOT NULL
AND bp.pro_id NOT IN ( 3414, 1192, 3321, 3595 )
AND bp.external_id = #{lossExternalId}
AND bp.del_flag = '0'
GROUP BY
bp.pro_name
LIMIT 1
</select>
<select id="getInfoDetails" resultType="com.bonus.material.lossAssessment.domain.LossAssignInfo">
SELECT DISTINCT
bla.id AS id,
bla.code AS code,
bla.create_time AS createTime,
su.nick_name AS createBy,
bui.unit_id AS lossUnitId,
bui.unit_name AS lossUnitName,
bpl.pro_id AS lossProId,
bpl.pro_name AS lossProName,
GROUP_CONCAT(DISTINCT mt2.type_name) as typeName,
bla.status as status,
swrs.direct_user as directUserIds,
swrs.node_id AS nodeId,
swrs.next_node_id AS nextNodeId,
swr.id AS recordId
FROM
bm_loss_assign bla
LEFT JOIN bm_agreement_info bai ON bla.agreement_id = bai.agreement_id
LEFT JOIN bm_project bpl ON bpl.pro_id = bai.project_id
LEFT JOIN bm_unit bui ON bui.unit_id = bai.unit_id
LEFT JOIN bm_loss_assign_details blad on blad.loss_assign_id = bla.id
LEFT JOIN ma_type mt1 on mt1.type_id = blad.type_id
LEFT JOIN ma_type mt2 on mt2.type_id = mt1.parent_id
left join sys_user su on bla.create_by = su.user_id
left join sys_workflow_record swr on bla.id = swr.task_id and swr.task_type = '26'
left join sys_workflow_type swt on swr.workflow_id = swt.id
left join sys_workflow_node swn on swt.id = swn.type_id
left join sys_workflow_config swc on swn.id = swc.node_id
left join (
select swrs.*
from sys_workflow_record_history swrs
inner join (
-- 第一步:按 record_id 分组,获取每组最新的 create_time
select record_id, max(create_time) as max_create_time
from sys_workflow_record_history
group by record_id
) t on swrs.record_id = t.record_id
and swrs.create_time = t.max_create_time
) swrs on swr.id = swrs.record_id
where
bla.del_flag = '1' and bla.id = #{id}
GROUP BY bla.id
ORDER BY bla.create_time desc
</select>
<select id="getUseList" resultType="com.bonus.common.biz.domain.lease.WorkPeopleInfo">
select
user_id as userId,
user_name as userName
from sys_user
where user_id in(1549,57)
</select>
<select id="getList" resultType="com.bonus.material.lossAssessment.domain.LossAssignInfo">
SELECT * FROM (
SELECT DISTINCT
bla.id AS id,
bla.code AS code,
bla.create_time AS createTime,
su.nick_name AS createBy,
bui.unit_id AS lossUnitId,
bui.unit_name AS lossUnitName,
bpl.pro_id AS lossProId,
bpl.pro_name AS lossProName,
GROUP_CONCAT(DISTINCT mt2.type_name) as typeName,
bla.status as status,
swrs.direct_user as directUserIds,
swrs.node_id AS nodeId,
swrs.next_node_id AS nextNodeId,
swr.id AS recordId,
bla.create_by AS userId,
bui.bzz_idcard AS bzIdCard
FROM
bm_loss_assign bla
LEFT JOIN bm_agreement_info bai ON bla.agreement_id = bai.agreement_id
LEFT JOIN bm_project bpl ON bpl.pro_id = bai.project_id
LEFT JOIN bm_unit bui ON bui.unit_id = bai.unit_id
LEFT JOIN bm_loss_assign_details blad on blad.loss_assign_id = bla.id
LEFT JOIN ma_type mt1 on mt1.type_id = blad.type_id
LEFT JOIN ma_type mt2 on mt2.type_id = mt1.parent_id
left join sys_user su on bla.create_by = su.user_id
left join sys_workflow_record swr on bla.id = swr.task_id and swr.task_type = '26'
left join sys_workflow_type swt on swr.workflow_id = swt.id
left join sys_workflow_node swn on swt.id = swn.type_id
left join sys_workflow_config swc on swn.id = swc.node_id
left join (
select swrs.*
from sys_workflow_record_history swrs
inner join (
-- 第一步:按 record_id 分组,获取每组最新的 create_time
select record_id, max(create_time) as max_create_time
from sys_workflow_record_history
group by record_id
) t on swrs.record_id = t.record_id
and swrs.create_time = t.max_create_time -- 第二步:关联原表,获取最新时间对应的完整记录
) swrs on swr.id = swrs.record_id
<where>
bla.del_flag = '1'
<if test="status != null">
AND bla.status = #{status}
</if>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
AND DATE_FORMAT( bla.create_time, '%Y-%m-%d' ) BETWEEN #{startTime} AND #{endTime}
</if>
<if test="projectIdList != null and projectIdList.size() > 0">
AND bpl.external_id in
<foreach item="item" collection="projectIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="impUnit != null and impUnit != ''">
AND bpl.imp_unit = #{impUnit}
</if>
<if test="statusList != null and statusList.size() > 0">
AND bla.status in
<foreach item="item" collection="statusList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</where>
GROUP BY bla.id
ORDER BY bla.create_time desc
) a
<where>
<if test="keyWord!=null and keyWord!=''">
AND (
INSTR(a.typeName, #{keyWord}) > 0 OR
INSTR(a.lossUnitName, #{keyWord}) > 0 OR
INSTR(a.lossProName, #{keyWord}) > 0 OR
INSTR(a.code, #{keyWord}) > 0 OR
INSTR(a.createBy, #{keyWord}) > 0
)
</if>
</where>
</select>
<select id="selectMaTypeThreeLists" resultMap="TypeResult">
SELECT
m.type_id,
m.type_name,
m.parent_id,
m.manage_type,
m.`LEVEL`,
m.type_id AS id,
m.type_name AS label
FROM ma_type m
WHERE m.type_id IN (
-- 对三级节点去重
SELECT DISTINCT node_id
FROM (
-- 三级父节点
SELECT
mt.parent_id AS node_id
FROM (
SELECT DISTINCT sai.type_id
FROM slt_agreement_info sai
WHERE sai.agreement_id = #{agreementId} AND sai.STATUS = '0'
) AS sai_filtered
INNER JOIN ma_type mt ON mt.type_id = sai_filtered.type_id
WHERE mt.parent_id IS NOT NULL and mt.manage_type = 0
UNION ALL -- 二级父节点
SELECT
mt2.parent_id AS node_id
FROM (
SELECT DISTINCT sai.type_id
FROM slt_agreement_info sai
WHERE sai.agreement_id = #{agreementId} AND sai.STATUS = '0'
) AS sai_filtered
INNER JOIN ma_type mt ON mt.type_id = sai_filtered.type_id
INNER JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
WHERE mt2.parent_id IS NOT NULL and mt.manage_type = 0
UNION ALL -- 一级父节点
SELECT
mt3.parent_id AS node_id
FROM (
SELECT DISTINCT sai.type_id
FROM slt_agreement_info sai
WHERE sai.agreement_id = #{agreementId} AND sai.STATUS = '0'
) AS sai_filtered
INNER JOIN ma_type mt ON mt.type_id = sai_filtered.type_id
INNER JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
INNER JOIN ma_type mt3 ON mt3.type_id = mt2.parent_id
WHERE mt3.parent_id IS NOT NULL and mt.manage_type = 0
) AS all_nodes
);
</select>
<select id="getExternalId" resultType="com.bonus.material.lossAssessment.domain.LossAssignInfo">
select
external_id as lossExternalId,
pro_name as lossProName
from
bm_project
where
pro_id = #{projectId}
</select>
<select id="getNumList" resultType="com.bonus.material.lossAssessment.domain.LossAssignDetails">
SELECT
bl.id AS lossId,
bl.agreement_id AS agreementId,
blad.type_id AS typeId,
blad.ma_id AS maId,
SUM(IFNULL(blad.num, 0)) AS waitTransNum
FROM
bm_loss_assign bl
INNER JOIN bm_loss_assign_details blad ON bl.id = blad.loss_assign_id
WHERE
bl.`status` IN (0, 1)
AND bl.agreement_id = #{agreementId}
AND blad.type_id = #{typeId}
AND blad.ma_id = #{maId}
GROUP BY
bl.agreement_id, blad.type_id, blad.ma_id, bl.id
LIMIT 1
</select>
</mapper>