select
lai.id, lai.code, lai.task_id, lai.lease_person, lai.phone, lai.type, lai.company_audit_by,
lai.company_audit_time, lai.company_audit_remark, lai.dept_audit_by, lai.dept_audit_time,
lai.dept_audit_remark, lai.direct_audit_by, lai.direct_audit_time, lai.direct_audit_remark,
lai.create_by, lai.create_time, lai.update_by, lai.update_time, lai.remark, lai.company_id,
lai.direct_id, lai.lease_type, lai.estimate_lease_time, lai.cost_bearing_party, lai.lease_sign_url, lai.lease_sign_type,
lai.project_id as projectId, bp.pro_name as projectName, tt.task_status as taskStatus,
sda.dict_label as taskStatusName,
lai.team_id as teamId,
bt.unit_name as teamName,
IFNULL(sum(lad.pre_num),0) as preCountNum,
IFNULL(sum(lad.al_num),0) as alNum,
GROUP_CONCAT(DISTINCT mt1.type_name) as maTypeNames,
bp.contract_part as contractPart,
sd.dept_name as impUnitName,
tta.agreement_id
from
clz_lease_apply_info lai
left join tm_task tt on lai.task_id = tt.task_id
left join tm_task_agreement tta ON tt.task_id = tta.task_id
left join clz_lease_apply_details lad on lai.id = lad.parent_id
left join bm_project bp on bp.pro_id = lai.project_id
left join bm_unit bt on bt.unit_id = lai.team_id
left join sys_dept sd on sd.dept_id = bp.imp_unit
left join sys_dict_data sda on tt.task_status = sda.dict_value
and sda.dict_type = 'lease_task_status'
left join ma_type mt on lad.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'
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,
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 as remark, lad.company_id
from
clz_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
JOIN ma_type_keeper mtk ON mtk.type_id = lad.type_id AND mtk.user_id = #{userId}
insert into clz_lease_apply_info
code,task_id,lease_person,phone,type,company_audit_by,company_audit_time,company_audit_remark,dept_audit_by,dept_audit_time,dept_audit_remark,direct_audit_by,direct_audit_time,direct_audit_remark,create_by,create_time,update_by,update_time,remark,company_id,direct_id,lease_type,estimate_lease_time,cost_bearing_party,team_id,project_id,lease_style,#{code},#{taskId},#{leasePerson},#{phone},#{type},#{companyAuditBy},#{companyAuditTime},#{companyAuditRemark},#{deptAuditBy},#{deptAuditTime},#{deptAuditRemark},#{directAuditBy},#{directAuditTime},#{directAuditRemark},#{createBy},#{createTime},#{updateBy},#{updateTime},#{remark},#{companyId},#{directId},#{leaseType},#{estimateLeaseTime},#{costBearingParty},#{teamId},#{projectId},#{leaseStyle},
insert into clz_lease_out_details
parent_id,
type_id,
ma_id,
out_num,
out_type,
create_by,
update_by,
remark,
company_id,
car_code,
publish_task,
is_finished,
create_time,
update_time
#{parentId},
#{typeId},
#{maId},
#{outNum},
#{outType},
#{createBy},
#{updateBy},
#{remark},
#{companyId},
#{carCode},
#{publishTask},
#{isFinished},
NOW(),
NOW()
insert into clz_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})
insert into clz_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,publish_task)
values (#{agreementId},#{record.typeId},#{record.maId},#{record.outNum},now(),0,#{record.parentId},#{ma.finalPrice},#{ma.buyPrice},'0',#{record.companyId},#{record.leaseType},now(),#{record.publishTask});
update clz_lease_apply_info
code = #{code},task_id = #{taskId},lease_person = #{leasePerson},phone = #{phone},`type` = #{type},company_audit_by = #{companyAuditBy},company_audit_time = #{companyAuditTime},company_audit_remark = #{companyAuditRemark},dept_audit_by = #{deptAuditBy},dept_audit_time = #{deptAuditTime},dept_audit_remark = #{deptAuditRemark},direct_audit_by = #{directAuditBy},direct_audit_time = #{directAuditTime},direct_audit_remark = #{directAuditRemark},update_by = #{updateBy},
update_time = now(),
remark = #{remark},company_id = #{companyId},direct_id = #{directId},lease_type = #{leaseType},estimate_lease_time = #{estimateLeaseTime},cost_bearing_party = #{costBearingParty},team_id = #{teamId},project_id = #{projectId},
where id = #{id}
update clz_lease_apply_info
lease_sign_url = #{leaseSignUrl},lease_sign_type = #{leaseSignType},update_by = #{updateBy},update_time = #{updateTime},
where id = #{id}
update clz_slt_agreement_info
set num = #{num},
update_time = now()
where id = #{id}
delete from clz_lease_apply_details where parent_id in
#{id}
delete from clz_lease_out_details where parent_id in
#{id}
delete from clz_lease_apply_info where id in
#{id}