Bonus-Cloud-Material/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/DirectRotationMapper.xml

524 lines
19 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.ma.mapper.DirectRotationMapper">
<update id="updateDirectApplyInfo">
update direct_apply_info
set
<if test="backAgreementId != null">
back_agreement_id = #{backAgreementId},
</if>
<if test="backMan != null">
back_man = #{backMan},
</if>
<if test="backPhone != null">
back_phone = #{backPhone},
</if>
<if test="leaseAgreementId != null">
lease_agreement_id = #{leaseAgreementId},
</if>
<if test="leaseMan != null">
lease_man = #{leaseMan},
</if>
<if test="leasePhone != null">
lease_phone = #{leasePhone},
</if>
<if test="dirUrl != null">
dir_url = #{dirUrl},
</if>
<if test="status != null">
status = #{status},
</if>
<if test="auditor != null">
auditor = #{auditor},
</if>
<if test="auditTime != null">
audit_time = #{auditTime},
</if>
update_time= NOW()
where id = #{id}
</update>
<delete id="deleteDirectApplyDetails">
delete
from direct_apply_details
where direct_id = #{id}
</delete>
<delete id="deleteDirectApply">
delete
from direct_apply_info
where id = #{id};
delete
from direct_apply_details
where direct_id = #{id}
</delete>
<select id="getUseringData" 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,
sai.*
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'
<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.ma_id,sai.type_id
</select>
<select id="getList" resultType="com.bonus.material.ma.domain.DirectApplyExportInfo">
SELECT * FROM (
SELECT DISTINCT
dai.id AS id,
dai.create_time AS createTime,
su.nick_name AS createName,
bui.unit_id AS backUnitId,
bui.unit_name AS backUnitName,
bpl.pro_id AS backProId,
bpl.pro_name AS backProName,
bui1.unit_id AS leaseUnitId,
bui1.unit_name AS leaseUnitName,
bpl1.pro_id AS leaseProId,
bpl1.pro_name AS leaseProName,
GROUP_CONCAT(DISTINCT mt2.type_name) as typeName,
IFNULL(swr.workflow_status,2) as status,
dai.business_code as businessCode
FROM
direct_apply_info dai
LEFT JOIN bm_agreement_info bai ON dai.back_agreement_id = bai.agreement_id
LEFT JOIN bm_agreement_info bai1 ON dai.lease_agreement_id = bai1.agreement_id
LEFT JOIN bm_project bpl ON bpl.pro_id = bai.project_id
LEFT JOIN bm_project bpl1 ON bpl1.pro_id = bai1.project_id
LEFT JOIN bm_unit bui ON bui.unit_id = bai.unit_id
LEFT JOIN bm_unit bui1 ON bui1.unit_id = bai1.unit_id
LEFT JOIN direct_apply_details dad on dad.direct_id=dai.id
LEFT JOIN ma_type mt1 on mt1.type_id=dad.type_id
LEFT JOIN ma_type mt2 on mt2.type_id=mt1.parent_id
left join sys_user su on dai.create_by = su.user_id
left join sys_workflow_record swr on swr.task_id = dai.id
<where>
<if test="lotId != null and lotId != ''">
and bpl.pro_id = #{lotId}
</if>
<if test="unitId != null and unitId != ''">
and bui.unit_id = #{unitId}
</if>
<if test="auditProId != null and auditProId != ''">
and (bpl.pro_id = #{auditProId} OR bpl1.pro_id = #{auditProId})
</if>
<if test="auditUnitId != null and auditUnitId != ''">
and (bui.unit_id = #{auditUnitId} OR bui1.unit_id = #{auditUnitId})
</if>
<if test="status != null and status != ''">
and swr.workflow_status = #{status}
</if>
<if test="isApp != null and taskStatus==0">and dai.status = 0 </if>
<if test="isApp != null and taskStatus==1">and (dai.status = 1 or dai.status = 2)</if>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
AND DATE_FORMAT( dai.create_time, '%Y-%m-%d' ) BETWEEN #{startTime} AND #{endTime}
</if>
</where>
GROUP BY dai.id
order by dai.create_time desc
) a
<where>
<if test="keyWord!=null and keyWord!=''">
AND (
INSTR(a.typeName,#{keyWord}) > 0 OR
INSTR(a.backUnitName,#{keyWord}) > 0 OR
INSTR(a.backProName,#{keyWord}) > 0 OR
INSTR(a.leaseUnitName,#{keyWord}) > 0 OR
INSTR(a.leaseProName,#{keyWord}) > 0 OR
INSTR(a.businessCode,#{keyWord}) > 0
)
</if>
</where>
</select>
<select id="getInfoById" resultType="com.bonus.material.ma.domain.DirectApplyInfo">
SELECT
dai.id,
dai.`code`,
bui.unit_id AS backUnitId,
bui.unit_name AS backUnitName,
bpl.pro_id AS backProId,
bpl.pro_name AS backProName,
dai.back_agreement_id AS backAgreementId,
bai.agreement_code AS backAgreementCode,
dai.back_man AS backMan,
dai.back_phone AS backPhone,
bui1.unit_id AS leaseUnitId,
bui1.unit_name AS leaseUnitName,
bpl1.pro_id AS leaseProId,
bpl1.pro_name AS leaseProName,
dai.lease_agreement_id AS leaseAgreementId,
bai1.agreement_code AS leaseAgreementCode,
dai.lease_man AS leaseMan,
dai.lease_phone AS leasePhone,
dai.dir_url AS dirUrl,
dai.`status`,
bpl.external_id AS backExternalId,
bpl1.external_id AS leaseExternalId,
dai.business_code AS businessCode
FROM
direct_apply_info dai
LEFT JOIN direct_apply_details dad ON dai.id = dad.direct_id
LEFT JOIN bm_agreement_info bai ON dai.back_agreement_id = bai.agreement_id
LEFT JOIN bm_agreement_info bai1 ON dai.lease_agreement_id = bai1.agreement_id
LEFT JOIN bm_project bpl ON bpl.pro_id = bai.project_id
LEFT JOIN bm_project bpl1 ON bpl1.pro_id = bai1.project_id
LEFT JOIN bm_unit bui ON bui.unit_id = bai.unit_id
LEFT JOIN bm_unit bui1 ON bui1.unit_id = bai1.unit_id
WHERE
dai.id = #{id}
GROUP BY
dai.id
</select>
<select id="getDetailById" resultType="com.bonus.material.ma.domain.DirectApplyDetails">
SELECT
dad.direct_num AS directNum,
dad.type_id AS typeId,
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,
mm.ma_id AS maId,
lai.lease_person as leasePerson,
DATE(sai.start_time) as startTime,
mt.manage_type as manageType,
dai.back_agreement_id as backAgreementId,
dai.lease_agreement_id as leaseAgreementId
FROM
direct_apply_info dai
LEFT JOIN direct_apply_details dad ON dai.id = dad.direct_id
LEFT JOIN slt_agreement_info sai ON dai.back_agreement_id = sai.agreement_id and sai.status =0
AND sai.type_id = dad.type_id and IFNULL(dad.ma_id,0)=IFNULL(sai.ma_id,0)
LEFT JOIN lease_apply_info lai on lai.id=sai.lease_id
LEFT JOIN ma_type mt ON mt.type_id = dad.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
LEFT JOIN ma_machine mm ON dad.ma_id = mm.ma_id
WHERE
dai.id = #{id}
<if test="typeId != null">
and sai.type_id = #{typeId}
</if>
<if test="maId != null">
and mt.parent_id = #{maId}
</if>
<if test="keyWord != null and keyWord != ''">
and (mt2.type_name like concat('%', #{keyWord}, '%') or
mt.type_name like concat('%', #{keyWord}, '%'))
</if>
GROUP BY
dad.id,
sai.type_id
</select>
<select id="getTypeNameList" 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, sai.ma_id as maId, sai.type_id as typeId, mt.parent_id as parentId, sai.*
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'
<if test="parentId != null">
and mt.parent_id=#{parentId}
</if>
<if test="typeId != null">
and sai.type_id=#{typeId}
</if>
<if test="type != null and type==1">
GROUP BY
mt.parent_id
</if>
<if test="type != null and type==2">
GROUP BY
sai.ma_id,sai.type_id
</if>
</select>
<select id="selectDetails" resultType="com.bonus.material.ma.domain.DirectApplyDetails">
SELECT
dad.type_id AS typeId,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
mt.unit_name AS unitName,
mt.manage_type AS manageType,
SUM( dad.direct_num ) AS directNum
FROM
direct_apply_info dai
LEFT JOIN direct_apply_details dad ON dai.id = dad.direct_id
LEFT JOIN ma_type mt ON mt.type_id = dad.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
WHERE
dai.id = #{id}
GROUP BY
dad.type_id
</select>
<select id="getprojectId" resultType="java.lang.Integer">
SELECT
project_id
FROM
bm_agreement_info
WHERE
agreement_id = #{agreementId}
</select>
<select id="getUseringDataByClz" resultType="com.bonus.material.settlement.domain.SltAgreementInfo">
SELECT
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
mt.unit_name as unitName,
ifnull(sum( sai.num ) ,0 ) AS useNum,
mm.ma_code AS maCode,
lai.lease_person as leasePerson,
DATE(sai.start_time) as startTime,
sai.ma_id as maId,
sai.type_id as typeId,
lai.create_time as createTime,
mt.unit_value as unitValue,
sai.*
FROM
clz_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 clz_lease_apply_info lai on lai.id=sai.lease_id
left join clz_bm_agreement_info col on col.agreement_id=sai.agreement_id
left join bm_project pro on pro.pro_id=col.project_id
where pro.pro_id = #{projectId} and sai.status = '0'
GROUP BY
sai.ma_id,sai.type_id
</select>
<select id="getApproveList" resultType="com.bonus.common.biz.domain.lease.LeaseOutSign">
SELECT
su.sign_type as outSignType,
su.sign_url as outSignUrl
FROM
sys_workflow_record_history swh
LEFT JOIN sys_workflow_record swr ON swh.record_id = swr.id
LEFT JOIN sys_user su ON swh.create_by = su.user_id
WHERE
swr.task_id = #{id}
</select>
<select id="getSignatureList" resultType="com.bonus.material.clz.domain.direct.ClzDirectApplyInfo">
SELECT
swh.node_id AS nodeId,
su.sign_type AS outSignType,
su.sign_url AS outSignUrl,
swn.type_id as typeId,
swn.node_sort as nodeSort
FROM
sys_workflow_record_history swh
LEFT JOIN sys_workflow_record swr ON swh.record_id = swr.id
LEFT JOIN sys_user su ON swh.create_by = su.user_id
LEFT JOIN sys_workflow_node swn on swn.id=swh.node_id
WHERE
swr.task_id = #{id}
ORDER BY swh.create_time ASC
</select>
<select id="getSignById" resultType="com.bonus.material.clz.domain.direct.ClzDirectApplyInfo">
SELECT
swr.id,
su.sign_type AS outSignType,
su.sign_url AS outSignUrl
FROM
direct_apply_info dai
LEFT JOIN sys_workflow_record swr on swr.task_id=dai.id
LEFT JOIN sys_user su on su.user_id=dai.create_by
WHERE
dai.id=#{id}
</select>
<select id="getInfo" resultType="com.bonus.material.settlement.domain.SltAgreementInfo">
SELECT
da.id AS id,
SUM(IFNULL(dad.direct_num, 0)) AS waitTransNum
FROM
direct_apply_info da
LEFT JOIN direct_apply_details dad ON da.id = dad.direct_id
WHERE
da.`status` = '0'
AND da.id IN (SELECT task_id FROM sys_workflow_record)
AND da.back_agreement_id = #{agreementId}
AND dad.type_id = #{typeId}
<if test="maId != null">
AND dad.ma_id = #{maId}
</if>
GROUP BY
da.id
HAVING
waitTransNum > 0
</select>
<select id="getBatchInfo" resultType="com.bonus.material.settlement.domain.SltAgreementInfo">
SELECT
da.back_agreement_id AS agreementId,
dad.type_id AS typeId,
dad.ma_id AS maId,
da.id AS id,
SUM(IFNULL(dad.direct_num, 0)) AS waitTransNum -- 待转数量
FROM
direct_apply_info da
INNER JOIN direct_apply_details dad ON da.id = dad.direct_id
WHERE
da.`status` = '0'
AND EXISTS (
SELECT 1 FROM sys_workflow_record swr
WHERE swr.task_id = da.id
)
AND da.back_agreement_id = #{agreementId}
AND (
<foreach collection="pairs" item="pair" separator="OR">
(dad.type_id = #{pair.typeId}
<if test="pair.maId != null">AND dad.ma_id = #{pair.maId}</if>
<if test="pair.maId == null">AND dad.ma_id IS NULL</if>)
</foreach>
)
AND IFNULL(dad.direct_num, 0) > 0 -- 提前过滤0值减少计算
GROUP BY
da.back_agreement_id, dad.type_id, dad.ma_id, da.id;
</select>
<select id="getDeptInfo" resultType="com.bonus.material.ma.domain.DirectApplyInfo">
SELECT DISTINCT
df.project_dept AS leaseDepartName,
sd.dept_name AS leaseImpUnitName
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 = #{leaseExternalId}
AND bp.del_flag = '0'
GROUP BY
bp.pro_name
LIMIT 1
</select>
<select id="getTeam" resultType="com.bonus.material.basic.domain.BmUnit">
SELECT
bai.unit_id as unitId,
bu.type_id as typeId
FROM
bm_agreement_info bai
LEFT JOIN bm_unit bu ON bai.unit_id = bu.unit_id
WHERE
agreement_id = #{agreementId}
</select>
<select id="getCodeList" resultType="com.bonus.material.ma.domain.DirectApplyInfo">
SELECT
lai.`code` as businessCode
FROM
lease_apply_info lai
LEFT JOIN tm_task tt ON lai.task_id = tt.task_id
WHERE
tt.task_type = 19
GROUP BY
lai.`code`
ORDER BY
lai.create_time DESC
</select>
<select id="getXmList" resultType="com.bonus.material.settlement.domain.SltAgreementInfo">
SELECT
id AS id,
agreement_id AS agreementId,
type_id AS typeId,
ma_id AS maId,
num AS backNum,
start_time AS startTime,
end_time AS endTime,
status AS status,
lease_id AS leaseId,
lease_type AS leaseType,
back_id AS backId,
lease_price AS leasePrice,
buy_price AS buyPrice,
company_id AS companyId
FROM
slt_agreement_info
WHERE
status = 0
AND source = '1'
AND type_id = #{typeId}
AND agreement_id = #{agreementId}
<if test="maId != null">
AND ma_id = #{maId}
</if>
order by start_time asc
</select>
<select id="getClzList" resultType="com.bonus.material.settlement.domain.SltAgreementInfo">
SELECT
id AS id,
agreement_id AS agreementId,
type_id AS typeId,
ma_id AS maId,
num AS backNum,
start_time AS startTime,
end_time AS endTime,
status AS status,
lease_id AS leaseId,
lease_type AS leaseType,
back_id AS backId,
lease_price AS leasePrice,
buy_price AS buyPrice,
company_id AS companyId
FROM
clz_slt_agreement_info
WHERE
status = 0
AND source = '2'
AND type_id = #{typeId}
AND agreement_id = #{agreementId}
<if test="maId != null">
AND ma_id = #{maId}
</if>
order by start_time asc
</select>
</mapper>