2023-12-21 20:17:36 +08:00
|
|
|
<?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.sgzb.material.mapper.BackApplyMapper">
|
|
|
|
|
|
|
|
|
|
<resultMap type="com.bonus.sgzb.material.domain.AgreementInfo" id="BmAgreementInfoResult">
|
|
|
|
|
<result property="agreementId" column="agreement_id"/>
|
|
|
|
|
<result property="agreementCode" column="agreement_code"/>
|
|
|
|
|
<result property="signTime" column="sign_time"/>
|
|
|
|
|
<result property="unitId" column="unit_id"/>
|
|
|
|
|
<result property="unitName" column="unit_name"/>
|
|
|
|
|
<result property="projectId" column="project_id"/>
|
|
|
|
|
<result property="createBy" column="create_by"/>
|
|
|
|
|
<result property="leaseDay" column="lease_day"/>
|
|
|
|
|
<result property="planStartTime" column="plan_start_time"/>
|
|
|
|
|
<result property="contractCode" column="contract_code"/>
|
|
|
|
|
<result property="authPerson" column="auth_person"/>
|
|
|
|
|
<result property="phone" column="phone"/>
|
|
|
|
|
<result property="createTime" column="create_time"/>
|
|
|
|
|
<result property="updateBy" column="update_by"/>
|
|
|
|
|
<result property="updateTime" column="update_time"/>
|
|
|
|
|
<result property="remark" column="remark"/>
|
|
|
|
|
<result property="companyId" column="company_id"/>
|
|
|
|
|
<result property="fileName" column="file_name"/>
|
|
|
|
|
<result property="fileUrl" column="file_url"/>
|
|
|
|
|
</resultMap>
|
|
|
|
|
<insert id="insertTask" keyColumn="task_id" keyProperty="taskId" parameterType="com.bonus.sgzb.material.domain.BackApplyInfo" useGeneratedKeys="true">
|
2023-12-22 00:13:15 +08:00
|
|
|
insert into tm_task (
|
|
|
|
|
<if test="taskType != null">task_type, </if>
|
|
|
|
|
<if test="taskStatus != null">task_status, </if>
|
|
|
|
|
<if test="code != null and code != ''">code, </if>
|
|
|
|
|
<if test="createBy != null and createBy != ''">create_by, </if>
|
|
|
|
|
<if test="updateBy != null and updateBy != ''">update_by, </if>
|
|
|
|
|
<if test="updateTime != null">update_time, </if>
|
|
|
|
|
<if test="remark != null and remark != ''">remark, </if>
|
|
|
|
|
<if test="companyId != null">company_id, </if>
|
2023-12-21 20:17:36 +08:00
|
|
|
create_time
|
|
|
|
|
) values (
|
2023-12-22 00:13:15 +08:00
|
|
|
<if test="taskType != null">#{taskType}, </if>
|
|
|
|
|
<if test="taskStatus != null">#{taskStatus}, </if>
|
|
|
|
|
<if test="code != null and code != ''">#{code}, </if>
|
|
|
|
|
<if test="createBy != null and createBy != ''">#{createBy}, </if>
|
|
|
|
|
<if test="updateBy != null and updateBy != ''">#{updateBy}, </if>
|
|
|
|
|
<if test="updateTime != null">#{updateTime}, </if>
|
|
|
|
|
<if test="remark != null and remark != ''">#{remark}, </if>
|
|
|
|
|
<if test="companyId != null">#{companyId}, </if>
|
2023-12-21 20:17:36 +08:00
|
|
|
NOW()
|
2023-12-22 00:13:15 +08:00
|
|
|
)
|
2023-12-21 20:17:36 +08:00
|
|
|
</insert>
|
|
|
|
|
|
|
|
|
|
<insert id="insertTaskAgreement">
|
|
|
|
|
insert into tm_task_agreement
|
|
|
|
|
(
|
|
|
|
|
<if test="taskId != null">
|
|
|
|
|
task_id,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="agreementId != null">
|
|
|
|
|
agreement_id,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="createBy != null and createBy != ''">
|
|
|
|
|
create_by,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="updateBy != null and updateBy != ''">
|
|
|
|
|
update_by,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="updateTime != null">
|
|
|
|
|
update_time,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="remark != null and remark != ''">
|
|
|
|
|
remark,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="companyId != null">
|
|
|
|
|
company_id,
|
|
|
|
|
</if>
|
|
|
|
|
create_time
|
|
|
|
|
) values (
|
|
|
|
|
<if test="taskId != null">
|
|
|
|
|
#{taskId},
|
|
|
|
|
</if>
|
|
|
|
|
<if test="agreementId != null">
|
|
|
|
|
#{agreementId},
|
|
|
|
|
</if>
|
|
|
|
|
<if test="createBy != null and createBy != ''">
|
|
|
|
|
#{createBy},
|
|
|
|
|
</if>
|
|
|
|
|
<if test="updateBy != null and updateBy != ''">
|
|
|
|
|
#{updateBy},
|
|
|
|
|
</if>
|
|
|
|
|
<if test="updateTime != null">
|
|
|
|
|
#{updateTime},
|
|
|
|
|
</if>
|
|
|
|
|
<if test="remark != null and remark != ''">
|
|
|
|
|
#{remark},
|
|
|
|
|
</if>
|
|
|
|
|
<if test="companyId != null">
|
|
|
|
|
#{companyId},
|
|
|
|
|
</if>
|
|
|
|
|
NOW()
|
|
|
|
|
)
|
|
|
|
|
</insert>
|
|
|
|
|
|
|
|
|
|
<insert id="insertBackApply" keyColumn="id" keyProperty="id" parameterType="com.bonus.sgzb.material.domain.BackApplyInfo" useGeneratedKeys="true">
|
|
|
|
|
insert into back_apply_info
|
|
|
|
|
(
|
|
|
|
|
<if test="code != null">
|
|
|
|
|
code,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="taskId != null">
|
|
|
|
|
task_id,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="backPerson != null and backPerson != ''">
|
|
|
|
|
back_person,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="backTime != null and backTime != ''">
|
|
|
|
|
back_time,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="phone != null and phone != ''">
|
|
|
|
|
phone,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="directAuditBy != null">
|
|
|
|
|
direct_audit_by,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="directAuditTime != null and directAuditTime != ''">
|
|
|
|
|
direct_audit_time,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="directAuditRemark != null">
|
|
|
|
|
direct_audit_remark,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="createBy != null and createBy != ''">
|
|
|
|
|
create_by,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="updateBy != null and updateBy != ''">
|
|
|
|
|
update_by,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="updateTime != null">
|
|
|
|
|
update_time,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="remark != null and remark != ''">
|
|
|
|
|
remark,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="companyId != null">
|
|
|
|
|
company_id,
|
|
|
|
|
</if>
|
|
|
|
|
create_time
|
|
|
|
|
) values (
|
|
|
|
|
<if test="code != null">
|
|
|
|
|
#{code},
|
|
|
|
|
</if>
|
|
|
|
|
<if test="taskId != null">
|
|
|
|
|
#{taskId},
|
|
|
|
|
</if>
|
|
|
|
|
<if test="backPerson != null and backPerson != ''">
|
|
|
|
|
#{backPerson},
|
|
|
|
|
</if>
|
|
|
|
|
<if test="backTime != null and backTime != ''">
|
|
|
|
|
#{backTime},
|
|
|
|
|
</if>
|
|
|
|
|
<if test="phone != null and phone != ''">
|
|
|
|
|
#{phone},
|
|
|
|
|
</if>
|
|
|
|
|
<if test="directAuditBy != null">
|
|
|
|
|
#{directAuditBy},
|
|
|
|
|
</if>
|
|
|
|
|
<if test="directAuditTime != null and directAuditTime != ''">
|
|
|
|
|
#{directAuditTime},
|
|
|
|
|
</if>
|
|
|
|
|
<if test="directAuditRemark != null">
|
|
|
|
|
#{directAuditRemark},
|
|
|
|
|
</if>
|
|
|
|
|
<if test="createBy != null and createBy != ''">
|
|
|
|
|
#{createBy},
|
|
|
|
|
</if>
|
|
|
|
|
<if test="updateBy != null and updateBy != ''">
|
|
|
|
|
#{updateBy},
|
|
|
|
|
</if>
|
|
|
|
|
<if test="updateTime != null">
|
|
|
|
|
#{updateTime},
|
|
|
|
|
</if>
|
|
|
|
|
<if test="remark != null and remark != ''">
|
|
|
|
|
#{remark},
|
|
|
|
|
</if>
|
|
|
|
|
<if test="companyId != null">
|
|
|
|
|
#{companyId},
|
|
|
|
|
</if>
|
|
|
|
|
NOW()
|
|
|
|
|
)
|
|
|
|
|
</insert>
|
|
|
|
|
|
2023-12-23 10:24:00 +08:00
|
|
|
<insert id="upload" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
|
2023-12-21 20:17:36 +08:00
|
|
|
insert into back_apply_details
|
|
|
|
|
(
|
|
|
|
|
<if test="id != null">
|
|
|
|
|
parent_id,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="typeId != null">
|
|
|
|
|
type_id,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="num != null">
|
|
|
|
|
pre_num,
|
|
|
|
|
</if>
|
|
|
|
|
status,
|
|
|
|
|
<if test="createBy != null and createBy != ''">
|
|
|
|
|
create_by,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="createBy != null and createBy != ''">
|
|
|
|
|
update_by,
|
|
|
|
|
</if>
|
|
|
|
|
update_time,
|
|
|
|
|
<if test="remark != null and remark != ''">
|
|
|
|
|
remark,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="companyId != null">
|
|
|
|
|
company_id,
|
|
|
|
|
</if>
|
|
|
|
|
create_time
|
|
|
|
|
)
|
|
|
|
|
values (
|
|
|
|
|
<if test="id != null">
|
|
|
|
|
#{id},
|
|
|
|
|
</if>
|
|
|
|
|
<if test="typeId != null">
|
|
|
|
|
#{typeId},
|
|
|
|
|
</if>
|
|
|
|
|
<if test="num != null">
|
|
|
|
|
#{num},
|
|
|
|
|
</if>
|
|
|
|
|
'0',
|
|
|
|
|
<if test="createBy != null and createBy != ''">
|
|
|
|
|
#{createBy},
|
|
|
|
|
</if>
|
|
|
|
|
<if test="createBy != null and createBy != ''">
|
|
|
|
|
#{createBy},
|
|
|
|
|
</if>
|
|
|
|
|
NOW(),
|
|
|
|
|
<if test="remark != null and remark != ''">
|
|
|
|
|
#{remark},
|
|
|
|
|
</if>
|
|
|
|
|
<if test="companyId != null">
|
|
|
|
|
#{companyId},
|
|
|
|
|
</if>
|
|
|
|
|
NOW()
|
|
|
|
|
)
|
|
|
|
|
</insert>
|
|
|
|
|
|
|
|
|
|
<update id="setModify">
|
|
|
|
|
update back_apply_details
|
|
|
|
|
set pre_num =#{num}
|
|
|
|
|
where id = #{detailsId}
|
|
|
|
|
</update>
|
2023-12-22 00:13:15 +08:00
|
|
|
|
|
|
|
|
<update id="audit">
|
|
|
|
|
UPDATE tm_task tt
|
|
|
|
|
LEFT JOIN back_apply_info bai ON bai.task_id = tt.task_id
|
|
|
|
|
LEFT JOIN back_apply_details bad on bad.parent_id=bai.id
|
2023-12-23 22:32:38 +08:00
|
|
|
SET tt.task_status = '38',bad.audit_num=bad.pre_num,bai.direct_audit_by=#{createBy},bad.status='1',bai.direct_audit_time=NOW()
|
2023-12-22 00:13:15 +08:00
|
|
|
WHERE
|
|
|
|
|
bai.id = #{id}
|
|
|
|
|
</update>
|
2023-12-21 20:17:36 +08:00
|
|
|
<delete id="del">
|
|
|
|
|
DELETE
|
2023-12-22 00:13:15 +08:00
|
|
|
FROM tm_task_agreement
|
|
|
|
|
WHERE task_id IN (SELECT task_id FROM back_apply_info WHERE id = #{id});
|
2023-12-21 20:17:36 +08:00
|
|
|
|
|
|
|
|
DELETE
|
2023-12-22 00:13:15 +08:00
|
|
|
FROM tm_task
|
|
|
|
|
WHERE task_id IN (SELECT task_id FROM back_apply_info WHERE id = #{id});
|
|
|
|
|
|
2023-12-21 20:17:36 +08:00
|
|
|
|
|
|
|
|
DELETE
|
2023-12-22 00:13:15 +08:00
|
|
|
FROM back_apply_details
|
|
|
|
|
WHERE parent_id IN (SELECT id FROM back_apply_info WHERE id = #{id});
|
2023-12-21 20:17:36 +08:00
|
|
|
|
|
|
|
|
DELETE
|
|
|
|
|
FROM back_apply_info
|
|
|
|
|
WHERE id = #{id};
|
|
|
|
|
</delete>
|
|
|
|
|
|
|
|
|
|
<select id="getBackApplyList" resultType="com.bonus.sgzb.material.domain.BackApplyInfo">
|
|
|
|
|
SELECT
|
|
|
|
|
bai.id,
|
|
|
|
|
bai.`code`,
|
|
|
|
|
bai.back_person as backPerson,
|
|
|
|
|
bai.phone,
|
|
|
|
|
bpl.lot_id as lotId,
|
|
|
|
|
bpl.lot_name as lotName,
|
|
|
|
|
bui.unit_id as unitId,
|
|
|
|
|
bui.unit_name as unitName,
|
|
|
|
|
bai.back_time as backTime,
|
|
|
|
|
bagi.agreement_code as agreementCode,
|
|
|
|
|
tt.task_status as taskStatus,
|
|
|
|
|
tta.agreement_id as agreementId,
|
|
|
|
|
GROUP_CONCAT(DISTINCT bad.type_id) as typeId,
|
2023-12-25 09:59:55 +08:00
|
|
|
GROUP_CONCAT(mt2.type_name) AS typeName
|
2023-12-21 20:17:36 +08:00
|
|
|
FROM
|
|
|
|
|
back_apply_info bai
|
|
|
|
|
LEFT JOIN back_apply_details bad on bad.parent_id=bai.id
|
|
|
|
|
LEFT JOIN tm_task tt on tt.task_id=bai.task_id
|
|
|
|
|
LEFT JOIN tm_task_agreement tta on tta.task_id=tt.task_id
|
|
|
|
|
LEFT JOIN bm_agreement_info bagi on bagi.agreement_id=tta.agreement_id
|
|
|
|
|
LEFT JOIN bm_project_lot bpl on bpl.lot_id=bagi.project_id
|
|
|
|
|
LEFT JOIN bm_unit_info bui on bui.unit_id=bagi.unit_id
|
|
|
|
|
LEFT JOIN sys_user us on us.user_id=bai.create_by
|
|
|
|
|
LEFT JOIN ma_type mt1 ON mt1.type_id=bad.type_id
|
|
|
|
|
LEFT JOIN ma_type mt2 ON mt2.type_id=mt1.parent_id
|
|
|
|
|
WHERE
|
2023-12-24 01:53:20 +08:00
|
|
|
1=1
|
2023-12-21 20:17:36 +08:00
|
|
|
<if test="keyWord != null and keyWord != ''">
|
|
|
|
|
and bai.`code` like concat('%', #{keyWord}, '%') or
|
2023-12-22 14:13:53 +08:00
|
|
|
bai.back_person like concat('%', #{keyWord}, '%') or
|
|
|
|
|
bai.phone like concat('%', #{keyWord}, '%')
|
2023-12-21 20:17:36 +08:00
|
|
|
</if>
|
2023-12-22 00:13:15 +08:00
|
|
|
<if test="unitId != null and unitId != ''">
|
|
|
|
|
and bui.unit_id = #{unitId}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="lotId != null and lotId != ''">
|
|
|
|
|
and bpl.lot_id = #{lotId}
|
|
|
|
|
</if>
|
2024-01-12 16:05:33 +08:00
|
|
|
<if test="proId != null and proId != ''">
|
|
|
|
|
and bpl.lot_id = #{proId}
|
|
|
|
|
</if>
|
2023-12-22 00:13:15 +08:00
|
|
|
<if test="taskStatus != null and taskStatus != ''">
|
|
|
|
|
and tt.task_status = #{taskStatus}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="agreementCode != null and agreementCode != ''">
|
|
|
|
|
and bagi.agreement_code like concat('%', #{agreementCode}, '%')
|
|
|
|
|
</if>
|
2024-01-12 16:05:33 +08:00
|
|
|
<if test="time != null and time != ''">
|
|
|
|
|
and bai.back_time =#{time}
|
2023-12-22 11:05:45 +08:00
|
|
|
</if>
|
2023-12-21 20:17:36 +08:00
|
|
|
GROUP BY bai.id, us.user_name, bai.phone, bpl.lot_name, bui.unit_name, bagi.plan_start_time
|
2023-12-25 10:48:28 +08:00
|
|
|
ORDER BY bai.create_time desc
|
2023-12-21 20:17:36 +08:00
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<select id="getMaterialList" resultType="com.bonus.sgzb.material.domain.BackApplyInfo">
|
2023-12-22 14:13:53 +08:00
|
|
|
SELECT subquery1.type_id as typeId,
|
|
|
|
|
subquery1.typeName typeCode,
|
|
|
|
|
subquery1.typeNames as typeName,
|
|
|
|
|
subquery1.out_num - COALESCE(subquery2.audit_num, 0) AS num
|
2023-12-21 20:17:36 +08:00
|
|
|
FROM (
|
2023-12-22 14:13:53 +08:00
|
|
|
-- 第一个查询作为子查询
|
|
|
|
|
SELECT mt.type_id,
|
|
|
|
|
mt.type_name as typeName,
|
|
|
|
|
mt2.type_name AS typeNames,
|
|
|
|
|
SUM(lod.out_num) as out_num
|
|
|
|
|
FROM lease_apply_info lai
|
|
|
|
|
LEFT JOIN tm_task_agreement tta on lai.task_id = tta.task_id
|
|
|
|
|
LEFT JOIN lease_out_details lod on lod.parent_id = lai.id
|
|
|
|
|
LEFT JOIN tm_task tt on tt.task_id = tta.task_id
|
|
|
|
|
LEFT JOIN ma_type mt on lod.type_id=mt.type_id
|
|
|
|
|
LEFT JOIN ma_type mt1 ON mt1.type_id = lod.type_id
|
|
|
|
|
LEFT JOIN ma_type mt2 ON mt2.type_id = mt1.parent_id
|
|
|
|
|
LEFT JOIN ma_type mt3 ON mt3.type_id = mt2.parent_id
|
|
|
|
|
LEFT JOIN ma_type mt4 ON mt4.type_id = mt3.parent_id
|
|
|
|
|
WHERE tta.agreement_id = #{agreementId}
|
|
|
|
|
and tt.task_type = '29'
|
|
|
|
|
and mt.`level`='4'
|
|
|
|
|
|
2023-12-22 00:13:15 +08:00
|
|
|
<if test="keyWord != null and keyWord != ''">
|
|
|
|
|
and mt.type_name like concat('%', #{keyWord}, '%') or
|
2023-12-22 14:13:53 +08:00
|
|
|
mt2.type_name like concat('%', #{keyWord}, '%')
|
|
|
|
|
</if>
|
|
|
|
|
GROUP BY mt.type_id
|
|
|
|
|
) AS subquery1
|
|
|
|
|
LEFT JOIN
|
|
|
|
|
(
|
|
|
|
|
-- 第二个查询作为子查询
|
|
|
|
|
SELECT mt.type_id,
|
|
|
|
|
mt.type_name,
|
|
|
|
|
mt2.type_name AS typeNames,
|
|
|
|
|
SUM(bad.audit_num) as audit_num
|
|
|
|
|
FROM back_apply_info bai
|
|
|
|
|
LEFT JOIN tm_task tt on tt.task_id=bai.task_id
|
|
|
|
|
LEFT JOIN back_apply_details bad on bad.parent_id = bai.id
|
|
|
|
|
LEFT JOIN tm_task_agreement tta on tta.task_id = tt.task_id
|
|
|
|
|
LEFT JOIN ma_type mt on mt.type_id = bad.type_id
|
|
|
|
|
LEFT JOIN ma_type mt1 ON mt1.type_id = bad.type_id
|
|
|
|
|
LEFT JOIN ma_type mt2 ON mt2.type_id = mt1.parent_id
|
|
|
|
|
LEFT JOIN ma_type mt3 ON mt3.type_id = mt2.parent_id
|
|
|
|
|
LEFT JOIN ma_type mt4 ON mt4.type_id = mt3.parent_id
|
|
|
|
|
WHERE tta.agreement_id = #{agreementId}
|
|
|
|
|
and tt.task_type = '36'
|
|
|
|
|
and mt.`level`='4'
|
|
|
|
|
<if test="keyWord != null and keyWord != ''">
|
|
|
|
|
and mt.type_name like concat('%', #{keyWord}, '%') or
|
|
|
|
|
mt2.type_name like concat('%', #{keyWord}, '%')
|
|
|
|
|
</if>
|
|
|
|
|
GROUP BY mt.type_id
|
|
|
|
|
) AS subquery2
|
|
|
|
|
ON subquery1.type_id = subquery2.type_id
|
|
|
|
|
WHERE
|
|
|
|
|
subquery1.out_num - COALESCE(subquery2.audit_num, 0)>0
|
2023-12-21 20:17:36 +08:00
|
|
|
</select>
|
|
|
|
|
<select id="selectTaskNumByMonth" resultType="java.lang.Integer">
|
|
|
|
|
select count(*) from tm_task where DATE_FORMAT(create_time,'%y%m') = DATE_FORMAT(#{date},'%y%m') and task_type = #{taskType}
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<select id="getView" resultType="com.bonus.sgzb.material.domain.BackApplyInfo">
|
|
|
|
|
SELECT
|
2023-12-23 22:30:03 +08:00
|
|
|
bai.back_person AS backPerson,
|
|
|
|
|
bai.phone AS phone,
|
|
|
|
|
bai.back_time as backTime,
|
|
|
|
|
lot.lot_name AS lotName,
|
|
|
|
|
unit.unit_name AS unitName,
|
|
|
|
|
mt.type_name typeCode,
|
|
|
|
|
mt2.type_name AS typeName,
|
|
|
|
|
bagi.agreement_code as agreementCode,
|
|
|
|
|
bad.pre_num AS num
|
2023-12-21 20:17:36 +08:00
|
|
|
FROM
|
2023-12-23 22:30:03 +08:00
|
|
|
back_apply_details bad
|
|
|
|
|
LEFT JOIN back_apply_info bai ON bai.id = bad.parent_id
|
|
|
|
|
LEFT JOIN tm_task_agreement tta ON tta.task_id = bai.task_id
|
|
|
|
|
LEFT JOIN bm_agreement_info bagi ON bagi.agreement_id = tta.agreement_id
|
|
|
|
|
LEFT JOIN bm_project_lot lot ON lot.lot_id = bagi.project_id
|
|
|
|
|
LEFT JOIN bm_unit_info unit ON unit.unit_id = bagi.unit_id
|
|
|
|
|
LEFT JOIN ma_type mt ON mt.type_id = bad.type_id
|
|
|
|
|
LEFT JOIN ma_type mt1 ON mt1.type_id = bad.type_id
|
|
|
|
|
LEFT JOIN ma_type mt2 ON mt2.type_id = mt1.parent_id
|
|
|
|
|
LEFT JOIN ma_type mt3 ON mt3.type_id = mt2.parent_id
|
|
|
|
|
LEFT JOIN ma_type mt4 ON mt4.type_id = mt3.parent_id
|
|
|
|
|
WHERE
|
|
|
|
|
bai.id = #{id}
|
2023-12-21 20:17:36 +08:00
|
|
|
</select>
|
2023-12-22 15:57:10 +08:00
|
|
|
<select id="getUseTypeTree" resultType="com.bonus.sgzb.material.domain.TypeTreeNode">
|
|
|
|
|
WITH RECURSIVE cte AS (
|
2023-12-25 09:59:55 +08:00
|
|
|
SELECT
|
|
|
|
|
mt.type_id,
|
|
|
|
|
mt.parent_id,
|
|
|
|
|
mt.type_name,
|
|
|
|
|
mt.`level`,
|
|
|
|
|
mt.unit_name,
|
|
|
|
|
mt4.num
|
|
|
|
|
FROM
|
|
|
|
|
ma_type mt
|
|
|
|
|
LEFT JOIN (
|
|
|
|
|
SELECT
|
|
|
|
|
subquery1.type_id AS typeId,
|
|
|
|
|
subquery1.parent_id ,
|
|
|
|
|
subquery1.typeName typeCode,
|
|
|
|
|
subquery1.out_num - COALESCE ( subquery2.audit_num, 0 ) AS num
|
|
|
|
|
FROM
|
|
|
|
|
(-- 第一个查询作为子查询
|
|
|
|
|
SELECT
|
|
|
|
|
mt.type_id,
|
|
|
|
|
mt.parent_id,
|
|
|
|
|
mt.type_name AS typeName,
|
|
|
|
|
SUM( lod.out_num ) AS out_num
|
|
|
|
|
FROM
|
|
|
|
|
lease_apply_info lai
|
|
|
|
|
LEFT JOIN tm_task_agreement tta ON lai.task_id = tta.task_id
|
|
|
|
|
LEFT JOIN lease_out_details lod ON lod.parent_id = lai.id
|
|
|
|
|
LEFT JOIN tm_task tt ON tt.task_id = tta.task_id
|
|
|
|
|
LEFT JOIN ma_type mt ON lod.type_id = mt.type_id
|
|
|
|
|
WHERE
|
|
|
|
|
tta.agreement_id = #{agreementId}
|
|
|
|
|
AND tt.task_type = '29'
|
|
|
|
|
AND mt.`level` = '4'
|
|
|
|
|
GROUP BY
|
|
|
|
|
mt.type_id
|
|
|
|
|
) AS subquery1
|
|
|
|
|
LEFT JOIN (-- 第二个查询作为子查询
|
|
|
|
|
SELECT
|
|
|
|
|
mt.type_id,
|
|
|
|
|
mt.parent_id,
|
|
|
|
|
mt.type_name,
|
|
|
|
|
SUM( bad.audit_num ) AS audit_num
|
|
|
|
|
FROM
|
|
|
|
|
back_apply_info bai
|
|
|
|
|
LEFT JOIN tm_task tt ON tt.task_id = bai.task_id
|
|
|
|
|
LEFT JOIN back_apply_details bad ON bad.parent_id = bai.id
|
|
|
|
|
LEFT JOIN tm_task_agreement tta ON tta.task_id = tt.task_id
|
|
|
|
|
LEFT JOIN ma_type mt ON mt.type_id = bad.type_id
|
|
|
|
|
WHERE
|
|
|
|
|
tta.agreement_id = #{agreementId}
|
|
|
|
|
AND tt.task_type = '36'
|
|
|
|
|
AND mt.`level` = '4'
|
|
|
|
|
GROUP BY
|
|
|
|
|
mt.type_id
|
|
|
|
|
) AS subquery2 ON subquery1.type_id = subquery2.type_id
|
|
|
|
|
WHERE
|
|
|
|
|
subquery1.out_num - COALESCE ( subquery2.audit_num, 0 )> 0) mt4 on mt4.typeId = mt.type_id
|
|
|
|
|
HAVING num> 0
|
|
|
|
|
UNION ALL
|
|
|
|
|
SELECT ma_type.type_id, ma_type.parent_id,ma_type.type_name as typeCode, ma_type.`level`,ma_type.unit_name,0 as
|
|
|
|
|
num
|
|
|
|
|
FROM ma_type
|
|
|
|
|
JOIN cte ON ma_type.type_id = cte.parent_id
|
2023-12-22 15:57:10 +08:00
|
|
|
)
|
2023-12-25 10:21:58 +08:00
|
|
|
SELECT type_id as typeId, parent_id as parentId,type_name as typeName,num,`level`,unit_name as unitNames
|
2023-12-22 15:57:10 +08:00
|
|
|
FROM cte
|
|
|
|
|
WHERE
|
2023-12-25 09:59:55 +08:00
|
|
|
1=1
|
2023-12-22 15:57:10 +08:00
|
|
|
<if test="level!=null and level!=''">
|
|
|
|
|
<if test="level == 2">
|
|
|
|
|
AND level IN ('1','2')
|
|
|
|
|
</if>
|
|
|
|
|
<if test="level == 3">
|
|
|
|
|
AND level IN ('1','2','3')
|
|
|
|
|
</if>
|
|
|
|
|
<if test="level == 4">
|
|
|
|
|
AND level IN ('1','2','3','4')
|
|
|
|
|
</if>
|
|
|
|
|
</if>
|
|
|
|
|
GROUP BY type_id
|
|
|
|
|
ORDER BY type_id;
|
|
|
|
|
</select>
|
2023-12-21 20:17:36 +08:00
|
|
|
|
2024-01-08 14:17:38 +08:00
|
|
|
<select id="exportList" resultType="com.bonus.sgzb.material.domain.BackApplyInfo">
|
|
|
|
|
SELECT
|
|
|
|
|
bai.`code`,
|
|
|
|
|
bai.back_person as backPerson,
|
|
|
|
|
bai.phone,
|
|
|
|
|
bpl.lot_name as lotName,
|
|
|
|
|
bui.unit_name as unitName,
|
|
|
|
|
bai.back_time as backTime,
|
|
|
|
|
bagi.agreement_code as agreementCode,
|
|
|
|
|
tt.task_status as taskStatus,
|
|
|
|
|
mt2.type_name AS typeName,
|
|
|
|
|
mt1.type_name as typeCode
|
|
|
|
|
FROM
|
|
|
|
|
back_apply_details bad
|
|
|
|
|
LEFT JOIN back_apply_info bai on bad.parent_id=bai.id
|
|
|
|
|
LEFT JOIN tm_task tt on tt.task_id=bai.task_id
|
|
|
|
|
LEFT JOIN tm_task_agreement tta on tta.task_id=tt.task_id
|
|
|
|
|
LEFT JOIN bm_agreement_info bagi on bagi.agreement_id=tta.agreement_id
|
|
|
|
|
LEFT JOIN bm_project_lot bpl on bpl.lot_id=bagi.project_id
|
|
|
|
|
LEFT JOIN bm_unit_info bui on bui.unit_id=bagi.unit_id
|
|
|
|
|
LEFT JOIN sys_user us on us.user_id=bai.create_by
|
|
|
|
|
LEFT JOIN ma_type mt1 ON mt1.type_id=bad.type_id
|
|
|
|
|
LEFT JOIN ma_type mt2 ON mt2.type_id=mt1.parent_id
|
|
|
|
|
where
|
|
|
|
|
1=1
|
|
|
|
|
<if test="keyWord != null and keyWord != ''">
|
|
|
|
|
and bai.`code` like concat('%', #{keyWord}, '%') or
|
|
|
|
|
bai.back_person like concat('%', #{keyWord}, '%') or
|
|
|
|
|
bai.phone like concat('%', #{keyWord}, '%')
|
|
|
|
|
</if>
|
|
|
|
|
<if test="unitId != null and unitId != ''">
|
|
|
|
|
and bui.unit_id = #{unitId}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="lotId != null and lotId != ''">
|
|
|
|
|
and bpl.lot_id = #{lotId}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="taskStatus != null and taskStatus != ''">
|
|
|
|
|
and tt.task_status = #{taskStatus}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="agreementCode != null and agreementCode != ''">
|
|
|
|
|
and bagi.agreement_code like concat('%', #{agreementCode}, '%')
|
|
|
|
|
</if>
|
|
|
|
|
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
|
|
|
|
|
and bai.back_time >=#{startTime}
|
|
|
|
|
and #{endTime} >=bai.back_time
|
|
|
|
|
</if>
|
|
|
|
|
ORDER BY bai.task_id desc
|
|
|
|
|
</select>
|
|
|
|
|
|
2023-12-21 20:17:36 +08:00
|
|
|
</mapper>
|