id, parent_id, type_id, pre_num, al_num, `status`, create_by, create_time, update_by, update_time, remark, company_id
select
lad.id, lad.parent_id, mt.type_id, mt.type_name, mt2.type_name as ma_type_name, mt.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,
lad.create_by, lad.create_time, lad.update_by, lad.update_time, lad.remark, lad.company_id
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'
insert into lease_apply_details
parent_id,
type_id,
pre_num,
audit_num,
al_num,
status,
create_by,
create_time,
update_by,
update_time,
remark,
company_id,
#{parentId},
#{typeId},
#{preNum},
#{auditNum},
#{alNum},
#{status},
#{createBy},
#{createTime},
#{updateBy},
#{updateTime},
#{remark},
#{companyId},
insert into lease_apply_details
(parent_id, type_id, pre_num, al_num, `status`, create_by, create_time, update_by,
update_time, remark, company_id)
values
(#{item.parentId,jdbcType=INTEGER}, #{item.typeId,jdbcType=INTEGER}, #{item.preNum,jdbcType=INTEGER},
#{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})
update lease_apply_details
parent_id = #{parentId},
type_id = #{typeId},
pre_num = #{preNum},
audit_num = #{auditNum},
al_num = #{alNum},
status = #{status},
create_by = #{createBy},
create_time = #{createTime},
update_by = #{updateBy},
update_time = #{updateTime},
remark = #{remark},
company_id = #{companyId},
where id = #{id}
delete from lease_apply_details where id = #{id}
delete from lease_apply_details where id in
#{id}
delete from lease_apply_details where parent_id in
#{id}
UPDATE
lease_apply_details
SET
al_num = IF(al_num IS NULL, #{record.outNum}, al_num + #{record.outNum}),
update_by = #{record.updateBy},
update_time = now(),
status = '1'
WHERE
parent_id = #{record.parentId} and type_id = #{record.typeId}
UPDATE
lease_apply_details
SET
status = '2'
WHERE
parent_id = #{record.parentId} and type_id = #{record.typeId}