Bonus-Cloud-Material/bonus-modules/bonus-material/src/main/resources/mapper/material/lease/LeaseApplyDetailsMapper.xml

674 lines
29 KiB
XML
Raw Normal View History

2024-09-27 15:26:57 +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.material.lease.mapper.LeaseApplyDetailsMapper">
<resultMap type="com.bonus.material.lease.domain.LeaseApplyDetails" id="LeaseApplyDetailsResult">
<result property="id" column="id" />
2024-11-11 10:18:32 +08:00
<result property="parentId" column="parent_id" />
2024-09-27 15:26:57 +08:00
<result property="typeId" column="type_id" />
2024-11-13 13:57:05 +08:00
<result property="typeName" column="type_name" />
<result property="maTypeName" column="ma_type_name" />
<result property="unitName" column="unit_name" />
2024-12-06 18:02:55 +08:00
<result property="unitValue" column="unit_value" />
2024-11-13 13:57:05 +08:00
<result property="storageNum" column="storage_num" />
2024-09-27 15:26:57 +08:00
<result property="preNum" column="pre_num" />
<result property="auditNum" column="audit_num" />
<result property="alNum" column="al_num" />
<result property="status" column="status" />
<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="remark" column="remark" />
<result property="companyId" column="company_id" />
</resultMap>
2024-11-13 09:30:23 +08:00
<sql id="Base_Column_List">
<!--@mbg.generated-->
id, parent_id, type_id, pre_num, al_num, `status`, create_by, create_time, update_by, update_time, remark, company_id
</sql>
2024-09-27 15:26:57 +08:00
<sql id="selectLeaseApplyDetailsVo">
2024-11-13 11:08:34 +08:00
select
lad.id, lad.parent_id, mt.type_id, mt.type_name, mt2.type_name as ma_type_name,
CASE mt.manage_type
WHEN 0 THEN
IFNULL(subquery0.num, 0)
ELSE
IFNULL(mt.storage_num, 0)
END as storage_num,
2024-11-13 15:41:40 +08:00
mt.manage_type as manageType,
(lad.pre_num - IF(lad.al_num IS NULL,'0',lad.al_num)) AS outNum,
2024-11-14 16:38:12 +08:00
IFNULL(lad.pre_num,0) as pre_num,
IFNULL(lad.audit_num,0) as audit_num,
IFNULL(lad.al_num,0) as al_num,
2024-12-06 18:02:55 +08:00
IFNULL(lad.status,0) as status, mt.unit_name,mt.unit_value,
2025-07-16 18:49:44 +08:00
lad.create_by, lad.create_time, lad.update_by, lad.update_time, lad.remark, lad.company_id,
2025-07-25 14:14:19 +08:00
mt4.type_id as firstId,
su.sign_url as signUrl,
su.sign_type as signType
2024-11-13 11:08:34 +08:00
from
lease_apply_details lad
2024-11-13 13:57:05 +08:00
left join
ma_type mt on lad.type_id = mt.type_id and mt.`level` = '4' and mt.del_flag = '0'
left join
ma_type mt2 on mt2.type_id = mt.parent_id and mt2.`level` = '3' and mt2.del_flag = '0'
2025-07-16 18:49:44 +08:00
left join ma_type mt3 ON mt2.parent_id = mt3.type_id and mt3.del_flag = '0'
left join ma_type mt4 ON mt3.parent_id = mt4.type_id and mt4.del_flag = '0'
2025-07-25 14:14:19 +08:00
left join sys_user su on su.user_id = mt3.keep_user_id
left join (SELECT mt.type_id,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
count(mm.ma_id) num
FROM ma_machine mm
LEFT JOIN ma_type mt ON mt.type_id = mm.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
WHERE mm.ma_code is not null and mm.ma_status in (1)
GROUP BY mt.type_id) AS subquery0 ON subquery0.type_id = mt.type_id
2024-12-27 18:35:02 +08:00
<if test="userId != null">
JOIN ma_type_keeper mtk ON mtk.type_id = lad.type_id AND mtk.user_id = #{userId}
</if>
2024-09-27 15:26:57 +08:00
</sql>
<select id="selectLeaseApplyDetailsList" parameterType="com.bonus.material.lease.domain.LeaseApplyDetails" resultMap="LeaseApplyDetailsResult">
select
lad.id, lad.parent_id, mt.type_id, mt.type_name, mt2.type_name as ma_type_name,
CASE mt.manage_type
WHEN 0 THEN
IFNULL(subquery0.num, 0)
ELSE
IFNULL(mt.storage_num, 0)
END as storage_num,
mt.manage_type as manageType,
(lad.pre_num - IF(lad.al_num IS NULL,'0',lad.al_num)) AS outNum,
IFNULL(lad.pre_num,0) as pre_num,
IFNULL(lad.audit_num,0) as audit_num,
IFNULL(lad.al_num,0) as al_num,
IFNULL(lad.status,0) as status, mt.unit_name,mt.unit_value,
lad.create_by, lad.create_time, lad.update_by, lad.update_time, lad.remark, lad.company_id,
mt4.type_id as firstId,
su.sign_url as signUrl,
su.sign_type as signType
from
lease_apply_details lad
left join
ma_type mt on lad.type_id = mt.type_id and mt.`level` = '4' and mt.del_flag = '0'
left join
ma_type mt2 on mt2.type_id = mt.parent_id and mt2.`level` = '3' and mt2.del_flag = '0'
left join ma_type mt3 ON mt2.parent_id = mt3.type_id and mt3.del_flag = '0'
left join ma_type mt4 ON mt3.parent_id = mt4.type_id and mt4.del_flag = '0'
left join sys_user su on su.user_id = mt3.keep_user_id
left join (SELECT mt.type_id,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
count(mm.ma_id) num
FROM ma_machine mm
LEFT JOIN ma_type mt ON mt.type_id = mm.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
WHERE mm.ma_code is not null and mm.ma_status in (1)
GROUP BY mt.type_id) AS subquery0 ON subquery0.type_id = mt.type_id
<if test="userId != null">
JOIN ma_type_keeper mtk ON mtk.type_id = lad.type_id AND mtk.user_id = #{userId}
</if>
2024-12-06 18:02:55 +08:00
<where>
2024-11-13 11:08:34 +08:00
<if test="parentId != null "> and lad.parent_id = #{parentId}</if>
2024-11-21 17:43:05 +08:00
<if test="keyword != null and keyword != ''">
AND (mt.type_name LIKE CONCAT('%', #{keyword}, '%')
OR mt2.type_name LIKE CONCAT('%', #{keyword}, '%'))
</if>
2024-11-13 11:08:34 +08:00
<if test="typeId != null "> and lad.type_id = #{typeId}</if>
<if test="preNum != null "> and lad.pre_num = #{preNum}</if>
<if test="auditNum != null "> and lad.audit_num = #{auditNum}</if>
<if test="alNum != null "> and lad.al_num = #{alNum}</if>
<if test="status != null and status != ''"> and lad.status = #{status}</if>
<if test="companyId != null "> and lad.company_id = #{companyId}</if>
2025-07-16 18:49:44 +08:00
<if test="typeIdList != null and typeIdList.size() > 0">
and mt4.type_id in
<foreach item="item" collection="typeIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
2024-09-27 15:26:57 +08:00
</where>
</select>
2024-12-06 18:02:55 +08:00
2024-09-27 15:26:57 +08:00
<select id="selectLeaseApplyDetailsById" parameterType="Long" resultMap="LeaseApplyDetailsResult">
<include refid="selectLeaseApplyDetailsVo"/>
2024-11-13 11:08:34 +08:00
where lad.id = #{id}
2024-09-27 15:26:57 +08:00
</select>
2024-12-06 18:02:55 +08:00
2024-09-27 15:26:57 +08:00
<insert id="insertLeaseApplyDetails" parameterType="com.bonus.material.lease.domain.LeaseApplyDetails" useGeneratedKeys="true" keyProperty="id">
insert into lease_apply_details
<trim prefix="(" suffix=")" suffixOverrides=",">
2024-11-11 10:18:32 +08:00
<if test="parentId != null">parent_id,</if>
2024-09-27 15:26:57 +08:00
<if test="typeId != null">type_id,</if>
<if test="preNum != null">pre_num,</if>
<if test="auditNum != null">audit_num,</if>
<if test="alNum != null">al_num,</if>
<if test="status != null">status,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="remark != null">remark,</if>
<if test="companyId != null">company_id,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
2024-11-11 10:18:32 +08:00
<if test="parentId != null">#{parentId},</if>
2024-09-27 15:26:57 +08:00
<if test="typeId != null">#{typeId},</if>
<if test="preNum != null">#{preNum},</if>
<if test="auditNum != null">#{auditNum},</if>
<if test="alNum != null">#{alNum},</if>
<if test="status != null">#{status},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="remark != null">#{remark},</if>
<if test="companyId != null">#{companyId},</if>
</trim>
</insert>
2024-11-11 10:08:01 +08:00
<insert id="insertLeaseApplyDetailsList" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
insert into lease_apply_details
2024-11-11 10:18:32 +08:00
(parent_id, type_id, pre_num, al_num, `status`, create_by, create_time, update_by,
2024-11-11 10:08:01 +08:00
update_time, remark, company_id)
values
<foreach collection="list" item="item" separator=",">
2024-11-11 10:18:32 +08:00
(#{item.parentId,jdbcType=INTEGER}, #{item.typeId,jdbcType=INTEGER}, #{item.preNum,jdbcType=INTEGER},
2024-11-11 10:08:01 +08:00
#{item.alNum,jdbcType=INTEGER}, #{item.status,jdbcType=VARCHAR}, #{item.createBy,jdbcType=VARCHAR},
NOW(), #{item.updateBy,jdbcType=VARCHAR}, NOW(),
#{item.remark,jdbcType=VARCHAR}, #{item.companyId,jdbcType=INTEGER})
</foreach>
</insert>
2024-09-27 15:26:57 +08:00
<update id="updateLeaseApplyDetails" parameterType="com.bonus.material.lease.domain.LeaseApplyDetails">
update lease_apply_details
<trim prefix="SET" suffixOverrides=",">
2024-11-11 10:18:32 +08:00
<if test="parentId != null">parent_id = #{parentId},</if>
2024-09-27 15:26:57 +08:00
<if test="typeId != null">type_id = #{typeId},</if>
<if test="preNum != null">pre_num = #{preNum},</if>
<if test="auditNum != null">audit_num = #{auditNum},</if>
<if test="alNum != null">al_num = #{alNum},</if>
<if test="status != null">status = #{status},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="companyId != null">company_id = #{companyId},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteLeaseApplyDetailsById" parameterType="Long">
delete from lease_apply_details where id = #{id}
</delete>
<delete id="deleteLeaseApplyDetailsByIds" parameterType="String">
2024-12-06 18:02:55 +08:00
delete from lease_apply_details where id in
2024-09-27 15:26:57 +08:00
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
2024-11-11 10:18:32 +08:00
<delete id="deleteLeaseApplyDetailsByParentIds" parameterType="Long">
2024-11-16 14:43:35 +08:00
delete from lease_apply_details where parent_id in
2024-11-11 10:18:32 +08:00
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
2024-11-13 09:30:23 +08:00
2025-03-10 16:39:12 +08:00
<delete id="deletePublishTask">
delete from lease_out_details where parent_id = #{parentId} and type_id = #{typeId}
and publish_task = #{publishTask}
<if test="maId != null">
and ma_id = #{maId}
</if>
</delete>
2024-11-13 09:30:23 +08:00
<select id="getByParentId" resultType="com.bonus.material.lease.domain.LeaseApplyDetails">
<!--@mbg.generated-->
select
2024-11-16 15:02:12 +08:00
id, parent_id as parentId, type_id as typeId, pre_num as preNum, al_num as alNum, `status`
2024-11-13 09:30:23 +08:00
from lease_apply_details
2024-11-13 09:47:36 +08:00
where parent_id = #{parentId}
2024-11-13 09:30:23 +08:00
</select>
2024-11-14 16:02:40 +08:00
<update id="updateLeaseApplyDetailsOutNum">
UPDATE
lease_apply_details
SET
al_num = IF(al_num IS NULL, #{record.outNum}, al_num + #{record.outNum}),
<if test="record.updateBy != null and record.updateBy!= '' ">
update_by = #{record.updateBy},
</if>
update_time = now(),
status = '1'
WHERE
parent_id = #{record.parentId} and type_id = #{record.typeId}
</update>
<select id="getLeaseApplyDetails" resultType="com.bonus.material.lease.domain.LeaseApplyDetails">
SELECT
ifnull( pre_num, 0 ) AS preNum,
ifnull( audit_num, 0 ) AS auditNum,
ifnull( al_num, 0 ) AS alNum
FROM
lease_apply_details
WHERE
parent_id = #{record.parentId}
AND type_id = #{record.typeId}
</select>
<update id="updateLeaseApplyDetailsByLeaseOutRecord">
UPDATE
lease_apply_details
SET
status = '2'
WHERE
parent_id = #{record.parentId} and type_id = #{record.typeId}
</update>
2024-11-19 10:33:56 +08:00
2025-01-13 18:03:20 +08:00
<update id="updateBackDetailsOutNum">
UPDATE
lease_apply_details
SET
al_num = al_num - #{outNum},
2025-01-14 16:57:44 +08:00
<if test="updateBy != null and updateBy!= '' ">
2025-01-13 18:03:20 +08:00
update_by = #{updateBy},
</if>
update_time = now(),
status = '1'
WHERE
parent_id = #{parentId} and type_id = #{typeId}
</update>
2025-07-23 18:56:14 +08:00
<update id="updateLeaseApplyPublishDetailsOutNum">
UPDATE
lease_apply_details
SET
al_num = IF(al_num IS NULL, #{record.outNum}, al_num + #{record.outNum}),
<if test="record.updateBy != null and record.updateBy!= '' ">
update_by = #{record.updateBy},
</if>
update_time = now(),
status = '1'
WHERE
parent_id = #{record.parentId} and new_type = #{record.typeId}
</update>
2024-11-19 10:33:56 +08:00
<select id="getOutboundNum" resultType="com.bonus.material.lease.domain.LeaseApplyDetails">
SELECT id, parent_id as parentId, type_id as typeId, pre_num as preNum, al_num as alNum, `status`, remark
FROM lease_apply_details
WHERE id = #{id} AND (pre_num - IFNULL(al_num, 0)) > 0
</select>
2024-11-19 13:50:48 +08:00
<select id="selectMaTypeNameByParentId" resultType="java.lang.String">
select
GROUP_CONCAT(type_name) typeName
from
(
select
distinct lad.parent_id, mt1.type_name
from
lease_apply_details lad
left join ma_type mt on lad.type_id = mt.type_id
left join ma_type mt1 on mt.parent_id = mt1.type_id
where
1=1
<if test="parentId != null">
and lad.parent_id = #{parentId}
</if>
) t
GROUP BY parent_id
</select>
2024-12-24 18:32:18 +08:00
<select id="getInfoByQrcode" resultType="com.bonus.common.biz.domain.lease.LeaseOutDetails">
SELECT
mt1.type_name as typeName,
mt.type_name as typeModelName,
mm.ma_id as maId,
mm.ma_code as maCode,
mm.type_id as typeId,
mm.ma_status as maStatus,
2024-12-26 14:38:33 +08:00
mm.qr_code as qrCode,
case when mm.ma_status = '1' then '在库'
else ''
2024-12-26 15:17:59 +08:00
end as statusName,
mt.manage_type as manageType
2024-12-24 18:32:18 +08:00
FROM ma_machine mm
LEFT JOIN ma_type mt ON mm.type_id = mt.type_id AND mt.del_flag = '0'
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id AND mt1.del_flag = '0'
where
mm.qr_code = #{qrCode}
</select>
<select id="getCodeList" resultType="com.bonus.material.back.domain.vo.MaCodeVo">
SELECT
mt.type_id as typeId,
mt1.type_name as materialName,
mt.type_name as typeName,
mm.ma_id as maId,
mm.ma_code as maCode
FROM
lease_out_details lod
LEFT JOIN ma_machine mm ON lod.ma_id = mm.ma_id
LEFT JOIN ma_type mt ON mm.type_id = mt.type_id
AND mt.del_flag = '0'
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
AND mt1.del_flag = '0'
WHERE
lod.parent_id = #{id}
2024-12-24 18:50:06 +08:00
and mt.type_id = #{typeId}
2024-12-24 18:32:18 +08:00
</select>
2024-12-25 14:32:34 +08:00
<!-- 批量获取编码详情优化N+1查询问题 -->
<select id="getCodeListBatch" resultType="com.bonus.material.back.domain.vo.MaCodeVo">
SELECT
mt.type_id as typeId,
mt1.type_name as materialName,
mt.type_name as typeName,
mm.ma_id as maId,
mm.ma_code as maCode
FROM
lease_out_details lod
LEFT JOIN ma_machine mm ON lod.ma_id = mm.ma_id
LEFT JOIN ma_type mt ON mm.type_id = mt.type_id
AND mt.del_flag = '0'
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
AND mt1.del_flag = '0'
WHERE
lod.parent_id = #{id}
<if test="typeIds != null and typeIds.size() > 0">
AND mt.type_id IN
<foreach collection="typeIds" item="typeId" open="(" separator="," close=")">
#{typeId}
</foreach>
</if>
ORDER BY mt.type_id, mm.ma_code
</select>
2024-12-25 14:32:34 +08:00
<select id="selectLeaseOutDetailsList" resultType="com.bonus.material.lease.domain.vo.LeaseOutVo">
SELECT
mt1.type_name AS typeName,
mt.type_name AS typeModelName,
mt.unit_name AS unit,
2025-03-18 17:14:22 +08:00
SUM(lod.out_num) AS num,
2025-03-06 17:21:53 +08:00
lod.ma_id AS maId,
2024-12-25 14:32:34 +08:00
mm.ma_code AS maCode,
mt.rated_load AS ratedLoad,
mt.test_load AS testLoad,
mt.holding_time AS holdingTime,
2024-12-25 18:33:19 +08:00
DATE(lod.create_time) AS testTime,
2025-01-08 13:33:45 +08:00
'合格' AS checkResult,
2024-12-25 14:32:34 +08:00
lad.remark AS remark,
2024-12-25 18:33:19 +08:00
DATE(DATE_SUB(DATE_ADD(lod.create_time, INTERVAL 1 YEAR), INTERVAL 1 DAY)) AS nextTestTime -- 计算 nextTestTime
2024-12-25 14:32:34 +08:00
FROM
lease_out_details lod
LEFT JOIN ma_type mt ON lod.type_id = mt.type_id AND mt.del_flag = '0'
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id AND mt1.del_flag = '0'
2025-07-23 09:04:57 +08:00
LEFT JOIN ma_type mt3 ON mt1.parent_id = mt3.type_id and mt3.del_flag = '0'
LEFT JOIN ma_type mt4 ON mt3.parent_id = mt4.type_id and mt4.del_flag = '0'
2024-12-25 14:32:34 +08:00
LEFT JOIN ma_machine mm ON lod.ma_id = mm.ma_id
2025-03-18 17:14:22 +08:00
LEFT JOIN lease_apply_details lad ON lod.type_id = lad.type_id AND lad.parent_id = #{id}
2024-12-27 18:35:02 +08:00
<if test="userId != null">
JOIN ma_type_keeper mtk ON mtk.type_id = lod.type_id AND mtk.user_id = #{userId}
</if>
2024-12-25 14:32:34 +08:00
WHERE lod.parent_id = #{id}
2025-07-23 09:04:57 +08:00
<if test="typeIdList != null and typeIdList.size() > 0">
and mt4.type_id in
<foreach item="item" collection="typeIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
GROUP BY lod.type_id, mm.ma_id
2024-12-25 14:32:34 +08:00
</select>
2025-01-13 18:03:20 +08:00
<select id="getInnerById" resultType="com.bonus.material.lease.domain.LeaseApplyDetails">
select lad.id as id,
lad.parent_id as parentId,
mt.type_id as typeId,
mt.type_name as typeName,
mt2.type_name as maTypeName,
CASE mt.manage_type
WHEN 0 THEN
IFNULL(subquery0.num, 0)
ELSE
IFNULL(mt.storage_num, 0)
END as storageNum,
mt.manage_type as manageType,
(lad.pre_num - IF(lad.al_num IS NULL, '0', lad.al_num)) AS outNum,
IFNULL(lad.pre_num, 0) as preNum,
IFNULL(lad.audit_num, 0) as auditNum,
IFNULL(lad.al_num, 0) as alNum,
IFNULL(lad.status, 0) as status,
mt.unit_name as unitName,
mt.unit_value as unitValue,
lad.create_by as createBy,
lad.create_time as createTime,
lad.update_by as updateBy,
lad.update_time as updateTime,
lad.remark as remark,
lad.company_id as companyId
from lease_apply_details lad
left join
ma_type mt on lad.type_id = mt.type_id and mt.`level` = '4' and mt.del_flag = '0'
left join
ma_type mt2 on mt2.type_id = mt.parent_id and mt2.`level` = '3' and mt2.del_flag = '0'
left join (SELECT mt.type_id,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
count(mm.ma_id) num
FROM ma_machine mm
LEFT JOIN ma_type mt ON mt.type_id = mm.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
WHERE mm.ma_code is not null
and mm.ma_status in (1)
GROUP BY mt.type_id) AS subquery0 ON subquery0.type_id = mt.type_id
where lad.id = #{id}
</select>
<select id="getDetailsById" resultType="com.bonus.material.lease.domain.LeaseApplyDetails">
SELECT
mt1.type_name as maTypeName,
mt.type_name as typeName,
mm.ma_code as maCode,
2025-07-04 18:07:30 +08:00
su.nick_name as createBy,
2025-01-14 16:57:44 +08:00
lod.create_time as createTime,
lod.ma_id as maId
2025-01-13 18:03:20 +08:00
FROM
lease_out_details lod
LEFT JOIN ma_type mt ON lod.type_id = mt.type_id
AND mt.del_flag = '0'
LEFT JOIN ma_type mt1 ON mt1.type_id = mt.parent_id
AND mt1.del_flag = '0'
LEFT JOIN lease_apply_info lai ON lod.parent_id = lai.id
LEFT JOIN ma_machine mm ON lod.ma_id = mm.ma_id
2025-07-04 18:07:30 +08:00
LEFT JOIN sys_user su ON lod.create_by = su.user_id
where lai.task_id = #{taskId} and lod.type_id = #{typeId}
2025-01-13 18:03:20 +08:00
ORDER BY
lod.create_time DESC
</select>
2025-03-05 13:27:10 +08:00
<select id="selectByMaId" resultType="com.bonus.material.lease.domain.vo.LeaseOutVo">
SELECT
lod.parent_id AS id,
mt1.type_name AS typeName,
mt.type_name AS typeModelName,
mt.unit_name AS unit,
lod.out_num AS num,
mm.ma_code AS maCode,
mt.rated_load AS ratedLoad,
mt.test_load AS testLoad,
mt.holding_time AS holdingTime,
DATE(lod.create_time) AS testTime,
'合格' AS checkResult,
lad.remark AS remark,
DATE(DATE_SUB(DATE_ADD(lod.create_time, INTERVAL 1 YEAR), INTERVAL 1 DAY)) AS nextTestTime -- 计算 nextTestTime
FROM
lease_out_details lod
LEFT JOIN ma_type mt ON lod.type_id = mt.type_id AND mt.del_flag = '0'
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id AND mt1.del_flag = '0'
LEFT JOIN ma_machine mm ON lod.ma_id = mm.ma_id
LEFT JOIN lease_apply_details lad ON lod.type_id = lad.type_id
LEFT JOIN purchase_check_details pcd ON lod.type_id = pcd.type_id
WHERE lod.ma_id = #{maId}
2025-07-23 09:04:57 +08:00
GROUP BY lod.type_id, mm.ma_id
2025-03-05 13:27:10 +08:00
ORDER BY lod.create_time DESC
</select>
2025-03-06 10:26:16 +08:00
<select id="getDetailsPublish" resultType="com.bonus.material.lease.domain.LeaseApplyDetails">
SELECT
2025-03-08 15:59:33 +08:00
a.id AS id,
lpd.parent_id AS parentId,
mt1.type_name AS maTypeName,
mt.type_name AS typeName,
mt.unit_name AS unitName,
lpd.new_type AS newTypeId,
2025-07-26 14:03:59 +08:00
COALESCE(lpd.new_type, lpd.type_id) AS typeId,
2025-03-08 15:59:33 +08:00
IFNULL( lpd.num, 0 ) AS preNum,
IFNULL( lpd.num, 0 ) - IFNULL( SUM( lod.out_num ), 0 ) AS outNum,
IFNULL( SUM( lod.out_num ), 0 ) AS alNum,
lpd.publish_task AS publishTask,
mt.manage_type AS manageType,
CASE mt.manage_type
WHEN 0 THEN
IFNULL(subquery0.num, 0)
ELSE
IFNULL(mt.storage_num, 0)
2025-07-16 18:49:44 +08:00
END as storageNum,
2025-07-25 14:14:19 +08:00
mt4.type_id as firstId,
su.sign_url as signUrl,
su.sign_type as signType
2025-03-06 10:26:16 +08:00
FROM
2025-03-08 15:59:33 +08:00
lease_publish_details lpd
LEFT JOIN ma_type mt ON lpd.new_type = mt.type_id
AND mt.del_flag = '0'
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
AND mt1.del_flag = '0'
2025-07-16 18:49:44 +08:00
left join ma_type mt3 ON mt1.parent_id = mt3.type_id and mt3.del_flag = '0'
left join ma_type mt4 ON mt3.parent_id = mt4.type_id and mt4.del_flag = '0'
2025-07-25 14:14:19 +08:00
left join sys_user su on su.user_id = mt3.keep_user_id
2025-03-08 15:59:33 +08:00
left join (SELECT mt.type_id,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
count(mm.ma_id) num
FROM ma_machine mm
LEFT JOIN ma_type mt ON mt.type_id = mm.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
WHERE mm.ma_code is not null
and mm.ma_status in (1)
GROUP BY mt.type_id) AS subquery0 ON subquery0.type_id = mt.type_id
2025-07-23 18:56:14 +08:00
LEFT JOIN lease_out_details lod ON lpd.new_type = lod.type_id
2025-03-08 15:59:33 +08:00
AND lpd.publish_task = lod.publish_task
LEFT JOIN (SELECT id, parent_id, type_id from lease_apply_details GROUP BY parent_id, type_id) a
on lpd.parent_id = a.parent_id and a.type_id = lpd.type_id
2025-07-16 18:49:44 +08:00
<if test="userId != null">
JOIN ma_type_keeper mtk ON mtk.type_id = lpd.new_type AND mtk.user_id = #{userId}
</if>
2025-03-06 10:26:16 +08:00
WHERE
2025-03-08 15:59:33 +08:00
lpd.publish_task = #{publishTask}
2025-03-06 15:23:58 +08:00
<if test="keyWord != null and keyWord != ''">
AND (mt1.type_name LIKE CONCAT(CONCAT('%', #{keyWord}), '%')
OR mt.type_name LIKE CONCAT(CONCAT('%', #{keyWord}), '%'))
</if>
2025-07-16 18:49:44 +08:00
<if test="typeIdList != null and typeIdList.size() > 0">
and mt4.type_id in
<foreach item="item" collection="typeIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
2025-03-06 10:26:16 +08:00
GROUP BY
2025-03-08 15:59:33 +08:00
lpd.new_type
</select>
<select id="selectInfo" resultType="com.bonus.material.lease.domain.LeaseApplyDetails">
SELECT
lpd.id AS id,
lpd.parent_id AS parentId,
mt1.type_name AS maTypeName,
mt.type_name AS typeName,
mt.unit_name AS unitName,
lpd.new_type AS typeId,
IFNULL( lpd.num, 0 ) AS preNum,
IFNULL( lpd.num, 0 ) - IFNULL( SUM( lod.out_num ), 0 ) AS outNum,
IFNULL( SUM( lod.out_num ), 0 ) AS alNum,
lpd.publish_task AS publishTask,
lpd.unit_id AS unitId,
lpd.project_id AS projectId,
bu.unit_name AS leaseUnit,
bp.pro_name AS leaseProject,
CASE mt.manage_type
WHEN 0 THEN
IFNULL(subquery0.num, 0)
ELSE
IFNULL(mt.storage_num, 0)
END as storageNum
FROM
lease_publish_details lpd
LEFT JOIN ma_type mt ON lpd.new_type = mt.type_id
AND mt.del_flag = '0'
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
AND mt1.del_flag = '0'
left join (SELECT mt.type_id,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
count(mm.ma_id) num
FROM ma_machine mm
LEFT JOIN ma_type mt ON mt.type_id = mm.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
WHERE mm.ma_code is not null
and mm.ma_status in (1)
GROUP BY mt.type_id) AS subquery0 ON subquery0.type_id = mt.type_id
LEFT JOIN lease_out_details lod ON lpd.parent_id = lod.parent_id
2025-06-21 21:04:32 +08:00
AND lpd.publish_task = lod.publish_task AND lod.type_id = lpd.new_type
2025-03-08 15:59:33 +08:00
LEFT JOIN bm_unit bu ON bu.unit_id = lpd.unit_id
LEFT JOIN bm_project bp ON bp.pro_id = lpd.project_id
WHERE
lpd.publish_task = #{publishTask}
<if test="typeId != null ">
AND lpd.new_type = #{typeId}
</if>
GROUP BY
lpd.new_type
</select>
<select id="selectPublishDetails" resultType="com.bonus.material.lease.domain.LeaseApplyDetails">
SELECT
mt1.type_name as maTypeName,
mt.type_name as typeName,
mm.ma_code as maCode,
2025-06-21 21:04:32 +08:00
su.nick_name as createBy,
2025-03-08 15:59:33 +08:00
lod.create_time as createTime,
lod.ma_id as maId
FROM
lease_out_details lod
LEFT JOIN ma_type mt ON lod.type_id = mt.type_id
AND mt.del_flag = '0'
LEFT JOIN ma_type mt1 ON mt1.type_id = mt.parent_id
AND mt1.del_flag = '0'
LEFT JOIN lease_publish_details lpd on lod.publish_task = lpd.publish_task
and lod.type_id = lpd.type_id
LEFT JOIN ma_machine mm ON lod.ma_id = mm.ma_id
2025-06-21 21:04:32 +08:00
LEFT JOIN sys_user su ON lod.create_by = su.user_id
2025-03-08 15:59:33 +08:00
where lod.publish_task = #{publishTask} and lod.type_id = #{typeId}
ORDER BY
lod.create_time DESC
2025-03-06 10:26:16 +08:00
</select>
2025-07-23 18:56:14 +08:00
<select id="getLeasePublishApplyDetails" resultType="com.bonus.material.lease.domain.LeaseApplyDetails">
SELECT
ifnull( pre_num, 0 ) AS preNum,
ifnull( audit_num, 0 ) AS auditNum,
ifnull( al_num, 0 ) AS alNum
FROM
lease_apply_details
WHERE
parent_id = #{record.parentId}
AND new_type = #{record.typeId}
</select>
2024-12-06 18:02:55 +08:00
</mapper>