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.LeaseOutDetailsMapper" >
<resultMap type= "com.bonus.material.lease.domain.LeaseOutDetails" id= "LeaseOutDetailsResult" >
<result property= "id" column= "id" />
<result property= "parentId" column= "parent_id" />
<result property= "typeId" column= "type_id" />
<result property= "maId" column= "ma_id" />
<result property= "outNum" column= "out_num" />
<result property= "outType" column= "out_type" />
<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" />
<result property= "carCode" column= "car_code" />
<result property= "pushNotifications" column= "push_notifications" />
</resultMap>
<sql id= "selectLeaseOutDetailsVo" >
2024-11-13 11:08:34 +08:00
select
lod.id, lod.parent_id, lod.type_id, lod.ma_id, lod.out_num, lod.out_type, lod.create_by, lod.create_time,
lod.update_by, lod.update_time, lod.remark, lod.company_id, lod.car_code, lod.push_notifications
from
lease_out_details lod
2024-09-27 15:26:57 +08:00
</sql>
<select id= "selectLeaseOutDetailsList" parameterType= "com.bonus.material.lease.domain.LeaseOutDetails" resultMap= "LeaseOutDetailsResult" >
<include refid= "selectLeaseOutDetailsVo" />
<where >
2024-11-13 11:08:34 +08:00
<if test= "parentId != null " > and lod.parent_id = #{parentId}</if>
<if test= "typeId != null " > and lod.type_id = #{typeId}</if>
<if test= "maId != null " > and lod.ma_id = #{maId}</if>
<if test= "outNum != null " > and lod.out_num = #{outNum}</if>
<if test= "outType != null and outType != ''" > and lod.out_type = #{outType}</if>
<if test= "companyId != null " > and lod.company_id = #{companyId}</if>
<if test= "carCode != null and carCode != ''" > and lod.car_code = #{carCode}</if>
<if test= "pushNotifications != null " > and lod.push_notifications = #{pushNotifications}</if>
2024-09-27 15:26:57 +08:00
</where>
</select>
<select id= "selectLeaseOutDetailsById" parameterType= "Long" resultMap= "LeaseOutDetailsResult" >
<include refid= "selectLeaseOutDetailsVo" />
2024-11-13 11:08:34 +08:00
where lod.id = #{id}
</select>
<select id= "selectLeaseOutDetailsListByParentId" parameterType= "com.bonus.material.lease.domain.LeaseOutDetails" resultMap= "LeaseOutDetailsResult" >
<include refid= "selectLeaseOutDetailsVo" />
<where >
lod.parent_id = #{parentId}
</where>
2024-09-27 15:26:57 +08:00
</select>
<insert id= "insertLeaseOutDetails" parameterType= "com.bonus.material.lease.domain.LeaseOutDetails" useGeneratedKeys= "true" keyProperty= "id" >
insert into lease_out_details
<trim prefix= "(" suffix= ")" suffixOverrides= "," >
<if test= "parentId != null" > parent_id,</if>
<if test= "typeId != null" > type_id,</if>
<if test= "maId != null" > ma_id,</if>
<if test= "outNum != null" > out_num,</if>
<if test= "outType != null" > out_type,</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>
<if test= "carCode != null" > car_code,</if>
<if test= "pushNotifications != null" > push_notifications,</if>
</trim>
<trim prefix= "values (" suffix= ")" suffixOverrides= "," >
<if test= "parentId != null" > #{parentId},</if>
<if test= "typeId != null" > #{typeId},</if>
<if test= "maId != null" > #{maId},</if>
<if test= "outNum != null" > #{outNum},</if>
<if test= "outType != null" > #{outType},</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>
<if test= "carCode != null" > #{carCode},</if>
<if test= "pushNotifications != null" > #{pushNotifications},</if>
</trim>
</insert>
<update id= "updateLeaseOutDetails" parameterType= "com.bonus.material.lease.domain.LeaseOutDetails" >
update lease_out_details
<trim prefix= "SET" suffixOverrides= "," >
<if test= "parentId != null" > parent_id = #{parentId},</if>
<if test= "typeId != null" > type_id = #{typeId},</if>
<if test= "maId != null" > ma_id = #{maId},</if>
<if test= "outNum != null" > out_num = #{outNum},</if>
<if test= "outType != null" > out_type = #{outType},</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>
<if test= "carCode != null" > car_code = #{carCode},</if>
<if test= "pushNotifications != null" > push_notifications = #{pushNotifications},</if>
</trim>
where id = #{id}
</update>
<delete id= "deleteLeaseOutDetailsById" parameterType= "Long" >
delete from lease_out_details where id = #{id}
</delete>
<delete id= "deleteLeaseOutDetailsByIds" parameterType= "String" >
delete from lease_out_details where id in
<foreach item= "id" collection= "array" open= "(" separator= "," close= ")" >
#{id}
</foreach>
</delete>
2024-11-13 09:30:23 +08:00
<select id= "getMachineStatus" resultType= "java.lang.String" >
select ma_status
from ma_machine
where ma_id = #{maId}
</select>
<select id= "getOutboundNum" resultType= "com.bonus.material.lease.domain.LeaseOutDetails" >
SELECT pre_num AS preNum,
pre_num - IFNULL(al_num, 0) AS nums
FROM lease_apply_details
WHERE id = #{id} AND (pre_num - IFNULL(al_num, 0)) > 0
</select>
<select id= "getTaskId" resultType= "java.lang.String" >
select task_id
from lease_apply_info
where id = #{parentId}
</select>
<select id= "getmaChineByCt" resultType= "java.lang.Integer" >
SELECT
CASE mt.manage_type
WHEN 0 THEN
IFNULL(subquery0.num, 0)
ELSE
IFNULL(mt.num, 0)
END as num
FROM ma_type mt
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 (15)
GROUP BY mt.type_id) AS subquery0 ON subquery0.type_id = mt.type_id
WHERE mt.del_flag = '0' and mt.type_id = #{typeId}
</select>
<select id= "getMaTypeDetails" resultType= "com.bonus.material.task.domain.TmTask" >
SELECT
mws2.type_id AS typeId,
mws2.part_num AS partNum
FROM
ma_type mt1
LEFT JOIN ma_whole_set mws2 ON mt1.type_id = mws2.parent_id
WHERE
mt1.type_id = #{typeId}
</select>
<update id= "updateTaskStatus" >
update tm_task
set task_status = #{status},
update_time = NOW()
where task_id = #{taskId}
</update>
<select id= "selectByTypeId" resultType= "com.bonus.material.ma.domain.Type" >
select * from ma_type WHERE
type_id = #{record.typeId}
</select>
<select id= "getCountOfCodeMachine" resultType= "java.lang.Integer" >
select count(mm.ma_id)
FROM ma_type mt
left join ma_machine mm on mm.type_id=mt.type_id
WHERE
mm.type_id = #{record.typeId}
and mm.ma_code is not null
and mm.ma_status in (15)
and mt.`level` = 4
and mt.del_flag = '0'
</select>
2024-11-13 09:44:07 +08:00
<insert id= "insertSelective" >
insert into lease_out_details
<trim prefix= "(" suffix= ")" suffixOverrides= "," >
<if test= "parentId!= null" >
parent_id,
</if>
<if test= "typeId!= null" >
type_id,
</if>
<if test= "maId!= null" >
ma_id,
</if>
<if test= "outNum!= null" >
out_num,
</if>
<if test= "outType!= null" >
out_type,
</if>
<if test= "createBy!= null" >
create_by,
</if>
<if test= "updateBy!= null" >
update_by,
</if>
<if test= "remark!= null" >
remark,
</if>
<if test= "companyId!= null" >
company_id,
</if>
<if test= "carCode!= null" >
car_code,
</if>
create_time,
update_time
</trim>
<trim prefix= "values (" suffix= ")" suffixOverrides= "," >
<if test= "parentId!= null" >
#{parentId},
</if>
<if test= "typeId!= null" >
#{typeId},
</if>
<if test= "maId!= null" >
#{maId},
</if>
<if test= "outNum!= null" >
#{outNum},
</if>
<if test= "outType!= null" >
#{outType},
</if>
<if test= "createBy!= null" >
#{createBy},
</if>
<if test= "updateBy!= null" >
#{updateBy},
</if>
<if test= "remark!= null" >
#{remark},
</if>
<if test= "companyId!= null" >
#{companyId},
</if>
<if test= "carCode!= null" >
#{carCode},
</if>
NOW(),
NOW()
</trim>
</insert>
<update id= "updateMaTypeStockNum" >
UPDATE
ma_type
SET
num = num - #{record.outNum} ,update_time = NOW()
WHERE
type_id = #{record.typeId}
</update>
<update id= "updateMaMachineStatus" >
UPDATE
ma_machine
SET
ma_status = '16',create_time = NOW()
<where >
type_id = #{record.typeId}
<if test= "record.maId != null and record.maId != ''" >
and ma_id = #{record.maId}
</if>
</where>
</update>
<select id= "getSltAgreementInfo" resultType= "com.bonus.material.settlement.domain.SltAgreementInfo" >
SELECT
id,
agreement_id AS agreementId,
type_id AS typeId,
ma_id AS maId,
num AS num,
start_time AS startTime,
end_time AS endTime,
status AS status,
lease_id AS leaseId,
back_id AS backId,
lease_price AS leasePrice,
buy_price AS buyPrice,
company_id AS companyId
FROM
slt_agreement_info
WHERE
lease_id = #{parentId}
AND
type_id = #{typeId}
AND
ma_id IS NULL
AND
status = '0'
AND
DATE(start_time) = CURDATE();
</select>
<update id= "updSltInfo" >
update slt_agreement_info
set num = #{num},
update_time = now()
where id = #{id}
</update>
<select id= "getAgreementId" resultType= "java.lang.String" >
select agreement_id
from tm_task_agreement
where task_id = #{taskId}
</select>
<select id= "getMaType" resultType= "com.bonus.material.ma.domain.Type" >
select lease_price as leasePrice,
rent_price as rentPrice,
buy_price as buyPrice,
pay_price as payPrice,
company_id as companyId
from ma_type
where type_id = #{typeId} and del_flag = 0
</select>
<select id= "getProtocol" resultType= "java.lang.String" >
select protocol
from bm_agreement_info
where agreement_id = #{agreementId}
</select>
<insert id= "insSltInfo" >
insert into slt_agreement_info (agreement_id,type_id,ma_id,num,start_time,status,lease_id,lease_price,buy_price,is_slt,company_id,lease_type,create_time)
values (#{agreementId},#{record.typeId},#{record.maId},#{record.outNum},now(),0,#{record.parentId},#{ma.finalPrice},#{ma.buyPrice},'0',#{record.companyId},#{record.leaseType},now());
</insert>
<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
2024-11-13 09:47:36 +08:00
parent_id = #{record.parentId} and type_id = #{record.typeId}
2024-11-13 09:44:07 +08:00
</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
2024-11-13 09:47:36 +08:00
parent_id = #{record.parentId}
2024-11-13 09:44:07 +08:00
AND type_id = #{record.typeId}
</select>
<update id= "updateLeaseApplyDetails" >
UPDATE
lease_apply_details
SET
status = '2'
WHERE
2024-11-13 09:47:36 +08:00
parent_id = #{record.parentId} and type_id = #{record.typeId}
2024-11-13 09:44:07 +08:00
</update>
2024-09-27 15:26:57 +08:00
</mapper>