devicesmgt/sgzb-modules/sgzb-base/src/main/resources/mapper/app/BackApplyAppMapper.xml

540 lines
17 KiB
XML
Raw Normal View History

<?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">
2024-01-24 09:59:58 +08:00
<mapper namespace="com.bonus.sgzb.app.mapper.BackApplyAppMapper">
<resultMap id="BaseResultMap" type="com.bonus.sgzb.app.domain.BmAgreementInfo">
<!--@mbg.generated-->
<!--@Table bm_agreement_info-->
<id column="agreement_id" jdbcType="INTEGER" property="agreementId" />
<result column="agreement_code" jdbcType="VARCHAR" property="agreementCode" />
<result column="sign_time" jdbcType="VARCHAR" property="signTime" />
<result column="unit_id" jdbcType="INTEGER" property="unitId" />
<result column="project_id" jdbcType="INTEGER" property="projectId" />
<result column="create_by" jdbcType="VARCHAR" property="createBy" />
<result column="lease_day" jdbcType="INTEGER" property="leaseDay" />
<result column="plan_start_time" jdbcType="TIMESTAMP" property="planStartTime" />
<result column="contract_code" jdbcType="VARCHAR" property="contractCode" />
<result column="auth_person" jdbcType="VARCHAR" property="authPerson" />
<result column="phone" jdbcType="VARCHAR" property="phone" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_by" jdbcType="VARCHAR" property="updateBy" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="remark" jdbcType="VARCHAR" property="remark" />
<result column="company_id" jdbcType="INTEGER" property="companyId" />
<result column="unit_id" jdbcType="INTEGER" property="unitId" />
<result column="unit_name" jdbcType="VARCHAR" property="unitName" />
<result column="lot_id" jdbcType="INTEGER" property="lotId" />
<result column="lot_name" jdbcType="VARCHAR" property="lotName" />
</resultMap>
2024-01-16 20:06:21 +08:00
<insert id="insertTask" keyColumn="task_id" keyProperty="taskId" parameterType="com.bonus.sgzb.app.domain.TmTask" useGeneratedKeys="true">
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>
create_time
) values (
<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>
NOW()
)
</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">
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>
2023-12-21 14:14:05 +08:00
<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>
2023-12-21 14:14:05 +08:00
<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>
<insert id="upload">
insert into back_apply_details
(
2024-01-08 14:17:38 +08:00
<if test="parentId != null">
parent_id,
</if>
<if test="typeId != null">
type_id,
</if>
2024-01-08 14:17:38 +08:00
<if test="preNum != 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 (
2024-01-08 14:17:38 +08:00
<if test="parentId != null">
#{parentId},
</if>
<if test="typeId != null">
#{typeId},
</if>
2024-01-08 14:17:38 +08:00
<if test="preNum != null">
#{preNum},
</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="audit">
2023-12-21 13:31:29 +08:00
UPDATE tm_task tt
2024-01-22 17:42:47 +08:00
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
2024-02-21 20:22:34 +08:00
SET bai.status = #{status},bad.audit_num=bad.pre_num,bai.direct_audit_by=#{createBy},bai.direct_audit_time=NOW()
2023-12-21 13:31:29 +08:00
WHERE
2024-02-21 20:22:34 +08:00
bai.id = #{id} and bai.company_id = #{companyId}
</update>
2024-01-18 17:00:26 +08:00
<update id="refuse">
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
SET bai.status = #{status},bad.audit_num=bad.pre_num,bai.direct_audit_by=#{createBy},bai.direct_audit_time=NOW()
2024-01-18 17:00:26 +08:00
WHERE
bai.id = #{id} and bai.company_id = #{companyId}
</update>
<update id="examineListByUser">
SELECT
bai.id,
bai.back_person as backPerson,
bai.phone,
bpl.lot_name as lotName,
bui.unit_name as unitName,
bai.back_time as backTime,
bagi.plan_start_time as planStartTime,
tt.task_status as taskStatus,
GROUP_CONCAT(DISTINCT bad.type_id) as typeId,
GROUP_CONCAT(CONCAT_WS('/', IFNULL(mt2.type_name, ''))) AS typeName,
SUM(DISTINCT bad.pre_num) AS num,
bai.direct_audit_remark as directAuditRemark
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
bad.type_id is not null and tt.create_by = #{createBy}
GROUP BY bai.id, us.user_name, bai.phone, bpl.lot_name, bui.unit_name, bagi.plan_start_time
ORDER BY bai.create_time desc
2024-01-18 17:00:26 +08:00
</update>
2024-02-21 20:22:34 +08:00
<update id="updateBackApply">
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
SET tt.task_status = 38
WHERE
bai.id = #{id}
</update>
<update id="updateTmTask">
2024-02-21 20:22:34 +08:00
UPDATE tm_task tt
INNER JOIN back_apply_info bai ON bai.task_id = tt.task_id
SET tt.task_status = #{taskStatus}
2024-02-21 20:22:34 +08:00
WHERE
bai.id = #{id}
</update>
2024-01-18 17:00:26 +08:00
2024-02-21 20:22:34 +08:00
<delete id="del">
2024-01-09 15:33:50 +08:00
DELETE
FROM tm_task_agreement
WHERE task_id IN (SELECT task_id FROM back_apply_info WHERE id = #{id});
DELETE
FROM tm_task
WHERE task_id IN (SELECT task_id FROM back_apply_info WHERE id = #{id});
DELETE
FROM back_apply_details
WHERE parent_id IN (SELECT id FROM back_apply_info WHERE id = #{id});
DELETE
FROM back_apply_info
WHERE id = #{id};
</delete>
<select id="getbackUnit" resultType="com.bonus.sgzb.app.domain.BmAgreementInfo">
SELECT bui.unit_id,
bui.unit_name,
bai.agreement_id,
bai.agreement_code,
bpl.lot_id,
bpl.lot_name
FROM bm_unit_info bui
LEFT JOIN bm_unit_person bup on bup.unit_id = bui.unit_id
LEFT JOIN bm_agreement_info bai on bai.unit_id=bui.unit_id
LEFT JOIN bm_project_lot bpl on bpl.lot_id=bai.project_id
WHERE bup.user_id = #{userId}
and bui.del_flag = '0'
</select>
<select id="getbackPro" resultType="com.bonus.sgzb.app.domain.BmAgreementInfo">
SELECT
bpl.lot_id,
bpl.lot_name
FROM
bm_unit_info bui
LEFT JOIN bm_agreement_info bai ON bai.unit_id = bui.unit_id
LEFT JOIN bm_project_lot bpl on bai.project_id=bpl.lot_id
WHERE
bui.unit_id=#{unitId}
and bui.del_flag='0'
</select>
<select id="getbackList" resultType="com.bonus.sgzb.app.domain.BackApplyInfo">
SELECT
bai.id,
2023-12-20 19:47:26 +08:00
bai.`code`,
bai.back_person as backPerson,
bai.phone,
2023-12-20 19:47:26 +08:00
bpl.lot_id,
bpl.lot_name as lotName,
2023-12-20 19:47:26 +08:00
bui.unit_id as unitId,
bui.unit_name as unitName,
2023-12-20 19:47:26 +08:00
bai.back_time as backTime,
tt.task_status as taskStatus,
2023-12-20 19:47:26 +08:00
tta.agreement_id as agreementId,
GROUP_CONCAT(DISTINCT bad.type_id) as typeId,
2024-01-09 15:33:50 +08:00
GROUP_CONCAT(CONCAT_WS('/', IFNULL(mt2.type_name, ''))) AS typeName
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
GROUP BY bai.id, us.user_name, bai.phone, bpl.lot_name, bui.unit_name, bagi.plan_start_time
2023-12-25 11:54:12 +08:00
ORDER BY bai.create_time desc
</select>
<select id="materialList" resultType="com.bonus.sgzb.app.domain.BackApplyInfo">
2024-01-08 14:17:38 +08:00
SELECT subquery1.type_id as typeId,subquery1.company_id as companyId,
2023-12-22 14:13:53 +08:00
subquery1.typeName typeCode,
subquery1.typeNames as typeName,
subquery1.out_num - COALESCE(subquery2.audit_num, 0) AS num
2023-12-21 10:39:12 +08:00
FROM (
2023-12-22 14:13:53 +08:00
-- 第一个查询作为子查询
2024-01-08 14:17:38 +08:00
SELECT mt.type_id,mt.company_id,
2023-12-22 14:13:53 +08:00
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
WHERE tta.agreement_id = #{agreementId}
and tt.task_type = '29'
and mt.`level`='4'
<if test="keyWord != null and keyWord != ''">
2024-01-19 14:55:21 +08:00
and (mt.type_name like concat('%', #{keyWord}, '%') or
mt2.type_name like concat('%', #{keyWord}, '%'))
2023-12-22 14:13:53 +08:00
</if>
GROUP BY mt.type_id
) AS subquery1
LEFT JOIN
(
-- 第二个查询作为子查询
2024-01-08 14:17:38 +08:00
SELECT mt.type_id,mt.company_id,
2023-12-22 14:13:53 +08:00
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
WHERE tta.agreement_id = #{agreementId}
and tt.task_type = '36'
and mt.`level`='4'
<if test="keyWord != null and keyWord != ''">
2024-01-19 14:55:21 +08:00
and (mt.type_name like concat('%', #{keyWord}, '%') or
mt2.type_name like concat('%', #{keyWord}, '%'))
2023-12-22 14:13:53 +08:00
</if>
GROUP BY mt.type_id
) AS subquery2
ON subquery1.type_id = subquery2.type_id
</select>
<select id="view" resultType="com.bonus.sgzb.app.domain.BackApplyInfo">
SELECT
mt.type_name typeCode,
2024-01-19 14:55:21 +08:00
CONCAT_WS('/', IFNULL(mt2.type_name, '')) AS typeName,
bad.pre_num as num
FROM
back_apply_details bad
LEFT JOIN back_apply_info bai on bai.id=bad.parent_id
LEFT JOIN ma_type mt on mt.type_id=bad.type_id
2024-01-19 14:55:21 +08:00
LEFT JOIN ma_type mt2 ON mt2.type_id=mt.parent_id
WHERE
bai.id=#{id}
</select>
2023-12-17 20:04:38 +08:00
<select id="examineList" resultType="com.bonus.sgzb.app.domain.BackApplyInfo">
SELECT
bai.id,
2024-01-09 15:33:50 +08:00
bai.back_person as backPerson,
2023-12-17 20:04:38 +08:00
bai.phone,
bpl.lot_name as lotName,
bui.unit_name as unitName,
2024-01-19 11:30:59 +08:00
bai.back_time as backTime,
2023-12-17 20:04:38 +08:00
bagi.plan_start_time as planStartTime,
tt.task_status as taskStatus,
GROUP_CONCAT(DISTINCT bad.type_id) as typeId,
2024-01-09 15:33:50 +08:00
GROUP_CONCAT(CONCAT_WS('/', IFNULL(mt2.type_name, ''))) AS typeName,
2023-12-17 20:04:38 +08:00
SUM(DISTINCT bad.pre_num) AS num,
bai.direct_audit_remark as directAuditRemark
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
bad.type_id is not null
2023-12-17 20:04:38 +08:00
GROUP BY bai.id, us.user_name, bai.phone, bpl.lot_name, bui.unit_name, bagi.plan_start_time
2024-01-19 14:55:21 +08:00
ORDER BY bai.create_time desc
2023-12-17 20:04:38 +08:00
</select>
<select id="examineView" resultType="com.bonus.sgzb.app.domain.BackApplyInfo">
SELECT
mt.type_name typeCode,
2024-01-09 15:33:50 +08:00
CONCAT_WS('/', IFNULL(mt2.type_name, '')) AS typeName,
2024-01-19 13:29:02 +08:00
bad.pre_num as num
2023-12-17 20:04:38 +08:00
FROM
back_apply_details bad
LEFT JOIN back_apply_info bai on bai.id=bad.parent_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
WHERE
bai.id=#{id}
</select>
2024-02-21 20:22:34 +08:00
<select id="selectBackApplyInfo" resultType="com.bonus.sgzb.app.domain.BackApplyInfo">
SELECT * FROM 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
WHERE
bai.id = #{id}
</select>
<select id="getTaskIdById" resultType="java.lang.Integer">
SELECT bai1.status FROM back_apply_info bai1
INNER JOIN
(SELECT * FROM back_apply_info bai2 WHERE bai2.id = #{id}) dd
on bai1.task_id = dd.task_id
</select>
</mapper>