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.material_man, lai.confirm_time, lai.is_confirm, lai.confirm_remark,
bai.unit_id,bai.project_id,bu.unit_name, bp.pro_name, bai.agreement_code, tt.task_status as taskStatus,
sda.dict_label as taskStatusName,
IFNULL(sum(lad.pre_num),0) as preCountNum,
IFNULL(sum(lod.num),0) as alNum,
GROUP_CONCAT(DISTINCT mt1.type_name) as maTypeNames,
bp.contract_part as contractPart,
sd.dept_name as impUnitName,
tt.task_type as taskType,
COALESCE(lai.release_time, lai.create_time) as releaseTime,
GROUP_CONCAT(DISTINCT mt3.type_id) as firstId,
su.sign_type as lease_sign_type,
su.sign_url as lease_sign_url,
lod.lease_sign_id as signId,
lad.lease_sign_url as signUrl
from
lease_apply_info lai
left join tm_task tt on lai.task_id = tt.task_id
left join lease_apply_details lad on lai.id = lad.parent_id
LEFT JOIN (SELECT parent_id,type_id ,IFNULL( sum( out_num ), 0 )as num, lease_sign_id FROM lease_out_details
GROUP BY parent_id,type_id) lod ON lai.id = lod.parent_id and lad.type_id = lod.type_id
left join tm_task_agreement tta on lai.task_id = tta.task_id
left join bm_agreement_info bai on tta.agreement_id = bai.agreement_id
left join bm_unit bu on bu.unit_id = bai.unit_id
left join bm_project bp on bp.pro_id = bai.project_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 sys_user su on lai.publisher = su.user_id
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'
left join ma_type mt2 ON mt1.parent_id = mt2.type_id and mt2.del_flag = '0'
left join ma_type mt3 ON mt2.parent_id = mt3.type_id and mt3.del_flag = '0'
JOIN ma_type_keeper mtk ON mtk.type_id = lad.type_id AND mtk.user_id = #{userId}
select
lai.id, lai.code, lai.task_id, lai.lease_person as leasePerson, 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 as createTime, 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.material_man, lai.confirm_time, lai.is_confirm, lai.confirm_remark,
bai.unit_id,bai.project_id,bai.project_id as projectId,bu.unit_name as unitName, bp.pro_name as projectName,bp.external_id as externalId, bai.agreement_code as agreementCode, tt.task_status as taskStatus,
sda.dict_label as taskStatusName,
IFNULL(sum(lad.pre_num),0) as preCountNum,
IFNULL(lod.num,0) as alNum,
GROUP_CONCAT(DISTINCT mt1.type_name) as maTypeNames,
bp.contract_part as contractPart,
sd.dept_name as impUnitName,
tt.task_type as taskType
from
lease_apply_info lai
left join tm_task tt on lai.task_id = tt.task_id
left join lease_apply_details lad on lai.id = lad.parent_id
LEFT JOIN (SELECT IFNULL( sum(out_num ), 0) AS num, parent_id, publish_task, is_confirm, confirm_remark, confirm_time, lease_sign_id from lease_out_details
GROUP BY parent_id) lod ON lai.id = lod.parent_id
left join tm_task_agreement tta on lai.task_id = tta.task_id
left join bm_agreement_info bai on tta.agreement_id = bai.agreement_id
left join bm_unit bu on bu.unit_id = bai.unit_id
left join bm_project bp on bp.pro_id = bai.project_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'
and lai.code = #{code}
and lai.task_id = #{taskId}
and lai.lease_person = #{leasePerson}
and lai.phone = #{phone}
and lai.type = #{type}
and lai.company_audit_by = #{companyAuditBy}
and lai.company_audit_time = #{companyAuditTime}
and lai.company_audit_remark = #{companyAuditRemark}
and lai.dept_audit_by = #{deptAuditBy}
and lai.dept_audit_time = #{deptAuditTime}
and lai.dept_audit_remark = #{deptAuditRemark}
and lai.direct_audit_by = #{directAuditBy}
and lai.direct_audit_time = #{directAuditTime}
and lai.direct_audit_remark = #{directAuditRemark}
and mt.company_id = #{companyId}
and COALESCE(lai.release_time, lai.create_time) BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime}, ' 23:59:59')
and lai.direct_id = #{directId}
and lai.lease_type = #{leaseType}
and lai.estimate_lease_time = #{estimateLeaseTime}
and lai.cost_bearing_party = #{costBearingParty}
and tt.task_type = '2' and lai.direct_id is null
GROUP BY lai.id
ORDER BY tt.task_status,tt.create_time desc
where lai.id = #{id}
insert into 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,
#{code},
#{taskId},
#{leasePerson},
#{phone},
#{type},
#{companyAuditBy},
#{companyAuditTime},
#{companyAuditRemark},
#{deptAuditBy},
#{deptAuditTime},
#{deptAuditRemark},
#{directAuditBy},
#{directAuditTime},
#{directAuditRemark},
#{createBy},
#{createTime},
#{updateBy},
#{updateTime},
#{remark},
#{companyId},
#{directId},
#{leaseType},
#{estimateLeaseTime},
#{costBearingParty},
insert into lease_sign_info
lease_sign_url,
lease_sign_type,
lease_user,
create_by,
create_time,
#{leaseSignUrl},
#{leaseSignType},
#{signPerson},
#{createBy},
#{createTime},
update 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},
release_time = now(),
cost_bearing_party = #{costBearingParty},
publisher = #{publisher},
where id = #{id}
delete from lease_apply_info where id = #{id}
delete from lease_apply_info where id in
#{id}
delete from lease_publish_details where id = #{id}
select task_id
from lease_apply_info
where id = #{parentId}
LIMIT 1
update lease_apply_info
lease_sign_url = #{leaseSignUrl},
lease_sign_type = #{leaseSignType},
where id = #{id}
select
sc.people_id as peopleId
from sign_config sc
where sc.process_id = 0 and sc.sign_type = 0 and sc.del_flag = 0
select
su.sign_url as directAuditSignUrl
from sys_user su
where su.user_id = #{directAuditBy} and su.del_flag = 0
select
sd.dept_name as sendUnit
from sys_user su
left join sys_dept sd on su.dept_id = sd.dept_id and sd.del_flag = 0
where su.user_id = #{directAuditBy} and su.del_flag = 0
SELECT
lai.id AS id,
lpd.code AS code,
tt.code AS businessCode,
lai.create_by AS createBy,
lai.create_time AS createTime,
sd.dept_name AS impUnitName,
bp.contract_part AS contractPart,
lpd.lease_person AS leasePerson,
lpd.phone AS phone,
lpd.unit_id AS leaseUnitId,
lpd.project_id AS leaseProjectId,
bu.unit_name AS leaseUnit,
bp.pro_name AS leaseProject,
bai.agreement_code AS agreementCode,
IFNULL( sum( lpd.num ), 0 ) AS preCountNum,
IFNULL(lod.num, 0) AS alNum,
GROUP_CONCAT( DISTINCT mt1.type_name ) AS maTypeNames,
lpd.publish_task AS publishTask,
lai.task_id AS taskId,
su.sign_url AS leaseSignUrl,
su.sign_type AS leaseSignType,
tt.task_type AS taskType,
lai.material_man AS materialMan,
lai.confirm_time AS confirmTime,
lai.is_confirm AS isConfirm,
lai.confirm_remark AS confirmRemark,
mt3.type_id AS firstId,
lpd.create_time AS releaseTime,
lpd.parent_id AS parentId,
lpd.lease_sign_url AS signUrl,
lod.lease_sign_id AS signId
FROM
lease_publish_details lpd
LEFT JOIN lease_apply_info lai ON lai.id = lpd.parent_id
LEFT JOIN tm_task tt ON lai.task_id = tt.task_id
LEFT JOIN (SELECT IFNULL( sum(out_num ), 0) AS num, parent_id, publish_task, lease_sign_id from lease_out_details a
JOIN ma_type_keeper mtk ON mtk.type_id = a.type_id AND mtk.user_id = #{userId}
WHERE a.publish_task is not null
GROUP BY parent_id, publish_task) lod ON lpd.parent_id = lod.parent_id
AND lpd.publish_task = lod.publish_task
LEFT JOIN bm_unit bu ON bu.unit_id = lpd.unit_id
LEFT JOIN bm_project bp ON bp.pro_id = lpd.project_id
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
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 ma_type mt2 ON mt1.parent_id = mt2.type_id and mt2.del_flag = '0'
left join ma_type mt3 ON mt2.parent_id = mt3.type_id and mt3.del_flag = '0'
LEFT JOIN bm_agreement_info bai ON lpd.unit_id = bai.unit_id AND lpd.project_id = bai.project_id AND bai.project_unit_id IS NULL
left join sys_user su on lpd.create_by = su.user_id
JOIN ma_type_keeper mtk ON mtk.type_id = lpd.new_type AND mtk.user_id = #{userId}
where 1 = 1
AND lai.id = #{id}
AND lpd.publish_task = #{publishTask}
AND lpd.company_id = #{companyId}
GROUP BY
lpd.publish_task
ORDER BY lpd.code DESC;
SELECT
su.sign_type AS outSignType,
su.sign_url AS outSignUrl
FROM
sys_user su
LEFT JOIN lease_out_details lod ON su.user_id = lod.create_by
WHERE
lod.parent_id = #{id} AND su.sign_url IS NOT NULL
AND lod.publish_task = #{publishTask}
GROUP BY
su.user_id
where
lod.num >0 and lod.lease_sign_id is not null and bp.external_id is not null
and tt.task_type = 2
and lai.code LIKE CONCAT('%', #{code}, '%')
and lai.task_id = #{taskId}
and lai.lease_person LIKE CONCAT('%', #{leasePerson}, '%')
and sd.dept_name LIKE CONCAT('%', #{impUnitName}, '%')
and bu.unit_name LIKE CONCAT('%', #{unitName}, '%')
and bp.pro_name LIKE CONCAT('%', #{projectName}, '%')
and lai.phone = #{phone}
and lai.type = #{type}
and lai.company_audit_by = #{companyAuditBy}
and lai.company_audit_time = #{companyAuditTime}
and lai.company_audit_remark = #{companyAuditRemark}
and lai.dept_audit_by = #{deptAuditBy}
and lai.dept_audit_time = #{deptAuditTime}
and lai.dept_audit_remark = #{deptAuditRemark}
and lai.direct_audit_by = #{directAuditBy}
and lai.direct_audit_time = #{directAuditTime}
and lai.direct_audit_remark = #{directAuditRemark}
and lai.company_id = #{companyId}
and tt.task_status in
#{item}
and lai.direct_id = #{directId}
and lai.lease_type = #{leaseType}
and lai.estimate_lease_time = #{estimateLeaseTime}
and lai.cost_bearing_party = #{costBearingParty}
GROUP BY lai.id
ORDER BY tt.task_status,lai.create_time desc
SELECT COUNT(1)
FROM `sbd_audit`.sg_project_post_personnel sgp
LEFT JOIN `data_center`.dx_fb_son dfs ON sgp.depart_id = dfs.project_dept_id
WHERE sgp.post_id = '3de0eb390f3611efa1940242ac130004'
AND sgp.cno = #{username}
AND dfs.id = #{externalId}
select
lod.id as id,
lod.parent_id as parentId,
sum(lod.out_num) as outNum,
DATE_FORMAT(lod.confirm_time, '%Y-%m-%d') as confirmTime,
lod.is_confirm as isConfirm,
su.nick_name as confirmPerson,
lod.confirm_remark as confirmRemark,
GROUP_CONCAT(DISTINCT mt2.type_name) as maTypeNames,
lod.lease_sign_id as leaseSignId,
lod.publish_task as publishTask
from lease_out_details lod
left join ma_type mt1 on lod.type_id = mt1.type_id
left join ma_type mt2 on mt1.parent_id = mt2.type_id
left join sys_user su on lod.confirm_person = su.user_id
where lod.parent_id = #{id}
and lod.out_num > 0
and lod.lease_sign_id is not null
AND lod.publish_task = #{publishTask}
AND GROUP_CONCAT(DISTINCT mt2.type_name) LIKE CONCAT(CONCAT('%', #{keyWord}), '%')
group by lod.lease_sign_id
order by lod.is_confirm
select
lai.id, lai.code, lai.task_id, lai.lease_person as leasePerson, lai.phone, lai.type, lai.company_audit_by,
lai.company_audit_time, lai.company_audit_remark, lai.dept_audit_by as directAuditBy, lai.dept_audit_time,
lai.dept_audit_remark, lai.direct_audit_by, lai.direct_audit_time, lai.direct_audit_remark,
lai.create_by, DATE_FORMAT(lai.create_time, '%Y-%m-%d') as createTime, 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.material_man, lai.confirm_time, lai.is_confirm, lai.confirm_remark,
bai.unit_id,bai.project_id,bu.unit_name as unitName, bp.pro_name as projectName,bp.external_id as externalId, bai.agreement_code as agreementCode, tt.task_status as taskStatus,
sda.dict_label as taskStatusName,
IFNULL(sum(lad.pre_num),0) as preCountNum,
IFNULL(sum(lod.out_num),0) as alNum,
CASE
WHEN IFNULL(sum(lad.pre_num),0) = SUM(CASE WHEN lod.is_confirm = 2 THEN lod.out_num ELSE 0 END) THEN 2
ELSE 1
END as isConfirm,
GROUP_CONCAT(DISTINCT mt1.type_name) as maTypeNames,
bp.contract_part as contractPart,
sd.dept_name as impUnitName,
tt.task_type as taskType,
su.sign_type as leaseSignType,
su.sign_url as leaseSignUrl
from
lease_apply_info lai
left join tm_task tt on lai.task_id = tt.task_id
left join lease_apply_details lad on lai.id = lad.parent_id
left join lease_out_details lod on lai.id = lod.parent_id
left join tm_task_agreement tta on lai.task_id = tta.task_id
left join bm_agreement_info bai on tta.agreement_id = bai.agreement_id
left join bm_unit bu on bu.unit_id = bai.unit_id
left join bm_project bp on bp.pro_id = bai.project_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'
left join sys_user su on lai.publisher = su.user_id
where lai.id = #{id}
select
lod.id as id,
lod.type_id as typeId,
lod.parent_id as parentId,
IFNULL( SUM( lod.out_num ), 0 ) as outNum,
DATE_FORMAT(lod.confirm_time, '%Y-%m-%d') as confirmTime,
mt2.type_name as maTypeName,
mt1.type_name as typeName,
lod.remark as remark,
mt1.manage_type as manageType,
lod.confirm_person as confirmPerson,
mt1.unit_name as unitName,
su.sign_url as signUrl,
su.sign_type as signType
from lease_out_details lod
left join ma_type mt1 on lod.type_id = mt1.type_id
left join ma_type mt2 on mt1.parent_id = mt2.type_id
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
where lod.parent_id = #{id}
and lod.out_num > 0
and lod.lease_sign_id = #{leaseSignId}
GROUP BY lod.type_id
ORDER BY lod.create_time DESC
select
su.sign_url as confirmSignUrl,
su.sign_type as confirmSignType
from sys_user su
where su.user_id = #{confirmPerson} and su.del_flag = 0
SELECT
GROUP_CONCAT( DISTINCT lad.id ) AS ids,
lai.id AS id,
lai.CODE AS CODE,
lai.create_by AS createBy,
lai.create_time AS createTime,
lai.lease_person AS leasePerson,
lai.phone AS phone,
bai.unit_id AS leaseUnitId,
bai.project_id AS leaseProjectId,
bu.unit_name AS leaseUnit,
bp.pro_name AS leaseProject,
bai.agreement_code AS agreementCode,
IFNULL( sum( lad.pre_num ), 0 ) AS alNum,
GROUP_CONCAT( DISTINCT mt1.type_name ) AS maTypeNames,
lai.task_id AS taskId,
tt.task_type AS taskType,
bp.external_id AS externalId,
bu.bzz_idcard AS idCard,
mt4.type_id AS firstId,
COALESCE(lai.release_time, lai.create_time) as releaseTime
FROM
lease_apply_details lad
LEFT JOIN lease_apply_info lai ON lai.id = lad.parent_id
LEFT JOIN (SELECT parent_id, lease_sign_id FROM lease_out_details GROUP BY
parent_id) lod ON lad.parent_id = lod.parent_id
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 bm_agreement_info bai ON tta.agreement_id = bai.agreement_id
LEFT JOIN bm_unit bu ON bu.unit_id = bai.unit_id
LEFT JOIN bm_project bp ON bp.pro_id = bai.project_id
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'
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'
WHERE
lad.lease_sign_url is null and lai.direct_id is null
and tt.task_type = '2' and lod.lease_sign_id is null
and tt.task_status in (3, 4)
AND mt.company_id = #{companyId}
GROUP BY
lad.parent_id
ORDER BY
lai.release_time DESC
select
DISTINCT
type_id
from
ma_type_manage
where
user_id = #{userId}
SELECT
lsi.lease_sign_type as outSignType,
lsi.lease_sign_url as outSignUrl
FROM
lease_out_details lod
LEFT JOIN lease_sign_info lsi ON lod.lease_sign_id = lsi.id
WHERE
lsi.lease_sign_url IS NOT NULL
and lod.parent_id = #{id}
and lsi.id = #{leaseSignId}
and lod.publish_task = #{publishTask}
GROUP BY
lod.lease_sign_id
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.material_man, lai.confirm_time, lai.is_confirm, lai.confirm_remark,
bu.unit_name, bp.pro_name, tt.task_status as taskStatus,
sda.dict_label as taskStatusName,
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,
tt.task_type as taskType
from
lease_apply_info lai
left join tm_task tt on lai.task_id = tt.task_id
left join lease_apply_details lad on lai.id = lad.parent_id
left join bm_unit bu on bu.unit_id = lai.unit_id
left join bm_project bp on bp.pro_id = lai.project_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'
left join ma_type mt2 ON mt1.parent_id = mt2.type_id and mt2.del_flag = '0'
left join ma_type mt3 ON mt2.parent_id = mt3.type_id and mt3.del_flag = '0'
where lai.id = #{id}
SELECT
GROUP_CONCAT( DISTINCT lpd.id ) AS ids,
lai.id AS id,
lpd.`code` AS CODE,
lai.create_by AS createBy,
lai.create_time AS createTime,
lpd.lease_person AS leasePerson,
lai.phone AS phone,
lpd.unit_id AS leaseUnitId,
lpd.project_id AS leaseProjectId,
bu.unit_name AS leaseUnit,
bp.pro_name AS leaseProject,
bai.agreement_code AS agreementCode,
IFNULL( sum( lpd.num ), 0 ) AS alNum,
GROUP_CONCAT( DISTINCT mt1.type_name ) AS maTypeNames,
lai.task_id AS taskId,
tt.task_type AS taskType,
bp.external_id AS externalId,
bu.bzz_idcard AS idCard,
mt4.type_id AS firstId,
lpd.create_time AS releaseTime,
lpd.publish_task AS publishTask
FROM
lease_publish_details lpd
LEFT JOIN lease_apply_info lai ON lai.id = lpd.parent_id
LEFT JOIN (SELECT parent_id, publish_task, lease_sign_id FROM lease_out_details GROUP BY
parent_id,publish_task) lod ON lpd.parent_id = lod.parent_id
and lod.publish_task = lpd.publish_task
LEFT JOIN tm_task tt ON lai.task_id = tt.task_id
LEFT JOIN bm_unit bu ON bu.unit_id = lpd.unit_id
LEFT JOIN bm_project bp ON bp.pro_id = lpd.project_id
LEFT JOIN bm_agreement_info bai ON lpd.unit_id = bai.unit_id
AND lpd.project_id = bai.project_id
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 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'
WHERE
lpd.lease_sign_url is null and lai.direct_id is null
and tt.task_type = '19' and lod.lease_sign_id is null
AND lpd.company_id = #{companyId}
GROUP BY
lpd.parent_id,
lpd.publish_task
ORDER BY
lpd.create_time DESC
SELECT
lai.id AS id,
lpd.code AS code,
lai.code AS businessCode,
lai.create_by AS createBy,
lai.create_time AS createTime,
sd.dept_name AS impUnitName,
bp.contract_part AS contractPart,
lpd.lease_person AS leasePerson,
lpd.phone AS phone,
lpd.unit_id AS leaseUnitId,
lpd.project_id AS leaseProjectId,
lpd.project_id AS projectId,
bu.unit_name AS unitName,
bp.pro_name AS projectName,
bai.agreement_code AS agreementCode,
IFNULL(SUM(lpd.num), 0) AS preCountNum,
IFNULL(lod.num, 0) AS alNum,
GROUP_CONCAT( DISTINCT mt1.type_name ) AS maTypeNames,
lpd.publish_task AS publishTask,
lai.task_id AS taskId,
su.sign_url AS leaseSignUrl,
su.sign_type AS leaseSignType,
tt.task_type AS taskType,
mt3.type_id AS firstId,
lpd.create_time AS releaseTime,
bp.external_id as externalId
FROM
lease_publish_details lpd
LEFT JOIN lease_apply_info lai ON lai.id = lpd.parent_id
LEFT JOIN tm_task tt ON lai.task_id = tt.task_id
LEFT JOIN (SELECT IFNULL( sum(out_num ), 0) AS num, parent_id, publish_task, is_confirm, confirm_remark, confirm_time, lease_sign_id from lease_out_details
where publish_task is not null
GROUP BY parent_id, publish_task) lod ON lpd.parent_id = lod.parent_id and lod.publish_task = lpd.publish_task
LEFT JOIN bm_unit bu ON bu.unit_id = lpd.unit_id
LEFT JOIN bm_project bp ON bp.pro_id = lpd.project_id
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
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 ma_type mt2 ON mt1.parent_id = mt2.type_id and mt2.del_flag = '0'
left join ma_type mt3 ON mt2.parent_id = mt3.type_id and mt3.del_flag = '0'
LEFT JOIN bm_agreement_info bai ON lpd.unit_id = bai.unit_id
AND lpd.project_id = bai.project_id
left join sys_user su on lpd.create_by = su.user_id
where
lod.lease_sign_id is not null and bp.external_id is not null and tt.task_type = '19'
and lpd.lease_person LIKE CONCAT('%', #{leasePerson}, '%')
and sd.dept_name LIKE CONCAT('%', #{impUnitName}, '%')
and bu.unit_name LIKE CONCAT('%', #{unitName}, '%')
and bp.pro_name LIKE CONCAT('%', #{projectName}, '%')
AND lai.id = #{id}
AND lpd.publish_task = #{publishTask}
GROUP BY
lpd.publish_task
ORDER BY lpd.create_time DESC
SELECT
parent_id as id,
SUM(out_num) as alNum
FROM
lease_out_details
WHERE
parent_id = #{id}
AND publish_task = #{publishTask}
HAVING
SUM( out_num ) > 0
update
lease_out_details
set
is_confirm = #{isConfirm}, confirm_time = #{confirmTime}, confirm_person = #{confirmPerson},
confirm_remark = #{confirmRemark}
where
parent_id = #{id} and lease_sign_id = #{leaseSignId}
update lease_publish_details
lease_sign_url = #{leaseSignUrl},
lease_sign_type = #{leaseSignType},
where parent_id = #{id}
and publish_task = #{publishTask}
update lease_apply_info
is_confirm = 2
where id = #{id}
update lease_apply_details
set publish_num = IFNULL(publish_num, 0) + #{pendingNum}
where id = #{id}
update lease_apply_details
set pre_num = #{preNum}
where parent_id = #{parentId}
AND type_id = #{typeId}
update lease_publish_details
set num = num + #{pendingNum}
where id = #{id}
update lease_publish_details
set num = num - #{publishNum}
where id = #{id}
update lease_apply_details
set publish_num = IFNULL(publish_num, 0) - #{publishNum}
where parent_id = #{parentId}
and type_id = #{typeId}
SELECT
sgp.cno
FROM
bm_project bp
LEFT JOIN `data_center`.dx_fb_son dfs on bp.external_id = dfs.id
LEFT JOIN `sbd_audit`.sg_project_post_personnel sgp on sgp.depart_id = dfs.project_dept_id
WHERE sgp.post_id = '3de0eb390f3611efa1940242ac130004'
AND bp.pro_id = #{leaseProjectId}
select
user_id,
phonenumber AS phone
from
sys_user
where user_name = #{cno}
select
bu.type_id as typeId
from
lease_apply_info lai
left join bm_unit bu on lai.unit_id = bu.unit_id
where
lai.id = #{leaseId}
SELECT
project_unit_id AS unitId
FROM
bm_agreement_info
WHERE
unit_id = #{leaseUnitId}
LIMIT 1
select type_id as typeId
from bm_unit
where unit_id = #{unitId}
LIMIT 1
SELECT
baii.agreement_id AS projectUnitAgreementId, bai.project_unit_id AS projectUnitId
FROM
bm_agreement_info bai
LEFT JOIN bm_agreement_info baii ON baii.unit_id = bai.project_unit_id AND baii.project_id = #{projectId}
WHERE
bai.unit_id = #{teamId} AND bai.project_id = #{projectId}
LIMIT 1
SELECT
IFNULL(SUM(lod.out_num), 0) as alNum
FROM
lease_out_details lod
LEFT JOIN lease_apply_info lai on lod.parent_id = lai.id
LEFT JOIN tm_task_agreement tta on lai.task_id = tta.task_id
LEFT JOIN bm_agreement_info bai on tta.agreement_id = bai.agreement_id
LEFT JOIN bm_unit bu2 on bai.unit_id = bu2.unit_id
LEFT JOIN bm_project bp2 on bai.project_id = bp2.pro_id
LEFT JOIN sys_dept sd on bp2.imp_unit = sd.dept_id
LEFT JOIN bm_unit bu on lai.unit_id = bu.unit_id
LEFT JOIN bm_project bp on lai.project_id = bp.pro_id
LEFT JOIN sys_dept sd2 on bp.imp_unit = sd2.dept_id
LEFT JOIN ma_type mt on lod.type_id = mt.type_id
LEFT JOIN ma_type mt2 on mt.parent_id = mt2.type_id
where lai.direct_id is null
and lod.create_time BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime}, ' 23:59:59')
and (bp2.pro_id = #{leaseProjectId} OR bp.pro_id = #{leaseProjectId})
and (bu2.unit_id = #{leaseUnitId} OR bu.unit_id = #{leaseUnitId})
and (sd2.dept_name = #{impUnitName} OR sd.dept_name = #{impUnitName})
AND lod.company_id = #{companyId}
SELECT
parent_id AS id,
SUM( out_num ) AS alNum
FROM
lease_out_details
WHERE
is_confirm = 2
AND parent_id = #{id}
AND publish_task = #{publishTask}
HAVING
SUM( out_num ) > 0
SELECT
parent_id AS parentId,
type_id AS typeId,
pre_num AS preNum,
al_num AS alNum,
pre_num - IFNULL( al_num, 0 ) AS outNum
FROM
lease_apply_details
WHERE
parent_id = #{id} and al_num > 0
SELECT
id AS id,
parent_id AS parentId,
type_id AS typeId,
pre_num AS preNum,
publish_num AS publishNum,
pre_num - IFNULL( publish_num, 0 ) AS pendingNum
FROM
lease_apply_details
WHERE
parent_id = #{parentId}
AND type_id IN
#{item}
GROUP BY
parent_id,
type_id
SELECT
lai.id AS id,
lpd.code AS code,
tt.code AS businessCode,
lai.create_by AS createBy,
lai.create_time AS createTime,
sd.dept_name AS impUnitName,
bp.contract_part AS contractPart,
lpd.lease_person AS leasePerson,
lpd.phone AS phone,
lpd.unit_id AS leaseUnitId,
lpd.project_id AS leaseProjectId,
bu.unit_name AS leaseUnit,
bp.pro_name AS leaseProject,
bai.agreement_code AS agreementCode,
IFNULL( sum( lpd.num ), 0 ) AS preCountNum,
IFNULL(lod.num, 0) AS alNum,
GROUP_CONCAT( DISTINCT mt1.type_name ) AS maTypeNames,
lpd.publish_task AS publishTask,
lai.task_id AS taskId,
su.sign_url AS leaseSignUrl,
su.sign_type AS leaseSignType,
tt.task_type AS taskType,
tt.task_status AS taskStatus,
lai.material_man AS materialMan,
lai.confirm_time AS confirmTime,
lai.is_confirm AS isConfirm,
lai.confirm_remark AS confirmRemark,
mt3.type_id AS firstId,
lpd.create_time AS releaseTime,
lpd.parent_id AS parentId
FROM
lease_publish_details lpd
LEFT JOIN lease_apply_info lai ON lai.id = lpd.parent_id
LEFT JOIN tm_task tt ON lai.task_id = tt.task_id
LEFT JOIN (SELECT IFNULL( sum(out_num ), 0) AS num, parent_id, publish_task,lease_sign_id from lease_out_details a
JOIN ma_type_keeper mtk ON mtk.type_id = a.type_id AND mtk.user_id = #{userId}
WHERE a.publish_task is not null
GROUP BY parent_id, publish_task) lod ON lpd.parent_id = lod.parent_id
AND lpd.publish_task = lod.publish_task
LEFT JOIN bm_unit bu ON bu.unit_id = lpd.unit_id
LEFT JOIN bm_project bp ON bp.pro_id = lpd.project_id
LEFT JOIN sys_dept sd ON sd.dept_id = bp.imp_unit
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 ma_type mt2 ON mt1.parent_id = mt2.type_id and mt2.del_flag = '0'
left join ma_type mt3 ON mt2.parent_id = mt3.type_id and mt3.del_flag = '0'
LEFT JOIN bm_agreement_info bai ON lpd.unit_id = bai.unit_id AND lpd.project_id = bai.project_id AND bai.project_unit_id IS NULL
left join sys_user su on lpd.create_by = su.user_id
JOIN ma_type_keeper mtk ON mtk.type_id = lpd.new_type AND mtk.user_id = #{userId}
where
(lpd.lease_sign_url is not null or lod.lease_sign_id is not null)
AND lai.id = #{id}
AND lpd.publish_task = #{publishTask}
GROUP BY
lpd.publish_task
ORDER BY lpd.code DESC;
SELECT
lease_sign_type as outSignType,
lease_sign_url as outSignUrl
FROM
lease_publish_details
WHERE
lease_sign_url IS NOT NULL
and parent_id = #{id}
and publish_task = #{publishTask}
GROUP BY
publish_task
SELECT
lease_sign_type as outSignType,
lease_sign_url as outSignUrl
FROM
lease_apply_details
WHERE
lease_sign_url IS NOT NULL
and parent_id = #{id}
GROUP BY
parent_id
SELECT
project_dept
FROM
`data_center`.dx_fb_son
WHERE
id = #{externalId}
LIMIT 1
SELECT
GROUP_CONCAT(mt.type_id)
FROM
ma_type mt
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
AND mt1.del_flag = 0
LEFT JOIN ma_type mt2 ON mt1.parent_id = mt2.type_id
AND mt2.del_flag = 0
LEFT JOIN ma_type mt3 ON mt2.parent_id = mt3.type_id
AND mt3.del_flag = 0
WHERE
mt.del_flag = '0'
AND mt3.type_id = 1169
SELECT
IFNULL(SUM(lod.out_num), 0) as alNum
FROM
lease_out_details lod
LEFT JOIN lease_apply_info lai on lod.parent_id = lai.id
LEFT JOIN tm_task_agreement tta on lai.task_id = tta.task_id
LEFT JOIN bm_agreement_info bai on tta.agreement_id = bai.agreement_id
LEFT JOIN bm_unit bu2 on bai.unit_id = bu2.unit_id
LEFT JOIN bm_project bp2 on bai.project_id = bp2.pro_id
LEFT JOIN sys_dept sd on bp2.imp_unit = sd.dept_id
LEFT JOIN bm_unit bu on lai.unit_id = bu.unit_id
LEFT JOIN bm_project bp on lai.project_id = bp.pro_id
LEFT JOIN sys_dept sd2 on bp.imp_unit = sd2.dept_id
LEFT JOIN ma_type mt on lod.type_id = mt.type_id
LEFT JOIN ma_type mt2 on mt.parent_id = mt2.type_id
where lai.direct_id is null
and lod.create_time BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime}, ' 23:59:59')
and lod.type_id in
#{item}
and (bp2.pro_id = #{leaseProjectId} OR bp.pro_id = #{leaseProjectId})
and (bu2.unit_id = #{leaseUnitId} OR bu.unit_id = #{leaseUnitId})
and (sd2.dept_name = #{impUnitName} OR sd.dept_name = #{impUnitName})
AND lod.company_id = #{companyId}
SELECT
IFNULL(SUM(lod.out_num), 0) as alNum
FROM
lease_out_details lod
LEFT JOIN lease_apply_info lai on lod.parent_id = lai.id
LEFT JOIN tm_task_agreement tta on lai.task_id = tta.task_id
LEFT JOIN bm_agreement_info bai on tta.agreement_id = bai.agreement_id
LEFT JOIN bm_unit bu2 on bai.unit_id = bu2.unit_id
LEFT JOIN bm_project bp2 on bai.project_id = bp2.pro_id
LEFT JOIN sys_dept sd on bp2.imp_unit = sd.dept_id
LEFT JOIN bm_unit bu on lai.unit_id = bu.unit_id
LEFT JOIN bm_project bp on lai.project_id = bp.pro_id
LEFT JOIN sys_dept sd2 on bp.imp_unit = sd2.dept_id
LEFT JOIN ma_type mt on lod.type_id = mt.type_id
LEFT JOIN ma_type mt2 on mt.parent_id = mt2.type_id
where
mt.unit_value = '1' and lai.direct_id is null
and lod.create_time BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime}, ' 23:59:59')
and lod.type_id not in
#{item}
and (bp2.pro_id = #{leaseProjectId} OR bp.pro_id = #{leaseProjectId})
and (bu2.unit_id = #{leaseUnitId} OR bu.unit_id = #{leaseUnitId})
and (sd2.dept_name = #{impUnitName} OR sd.dept_name = #{impUnitName})
AND lod.company_id = #{companyId}
SELECT
IFNULL(SUM(lod.out_num), 0) as alNum
FROM
lease_out_details lod
LEFT JOIN lease_apply_info lai on lod.parent_id = lai.id
LEFT JOIN tm_task_agreement tta on lai.task_id = tta.task_id
LEFT JOIN bm_agreement_info bai on tta.agreement_id = bai.agreement_id
LEFT JOIN bm_unit bu2 on bai.unit_id = bu2.unit_id
LEFT JOIN bm_project bp2 on bai.project_id = bp2.pro_id
LEFT JOIN sys_dept sd on bp2.imp_unit = sd.dept_id
LEFT JOIN bm_unit bu on lai.unit_id = bu.unit_id
LEFT JOIN bm_project bp on lai.project_id = bp.pro_id
LEFT JOIN sys_dept sd2 on bp.imp_unit = sd2.dept_id
LEFT JOIN ma_type mt on lod.type_id = mt.type_id
LEFT JOIN ma_type mt2 on mt.parent_id = mt2.type_id
where
mt.unit_value = '0' and lai.direct_id is null
and lod.create_time BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime}, ' 23:59:59')
and lod.type_id not in
#{item}
and (bp2.pro_id = #{leaseProjectId} OR bp.pro_id = #{leaseProjectId})
and (bu2.unit_id = #{leaseUnitId} OR bu.unit_id = #{leaseUnitId})
and (sd2.dept_name = #{impUnitName} OR sd.dept_name = #{impUnitName})
AND lod.company_id = #{companyId}
SELECT DISTINCT
lease_sign_id
FROM
lease_out_details
and publish_task = #{publishTask}
and parent_id = #{id}
SELECT
lpd.id as id,
lpd.parent_id as parentId,
lpd.type_id as typeId,
lpd.new_type as newTypeId,
lad.pre_num - IFNULL( lad.publish_num, 0 ) as pendingNum,
lpd.num as publishNum
FROM
lease_publish_details lpd
LEFT JOIN lease_apply_details lad ON lpd.parent_id = lad.parent_id
AND lpd.type_id = lad.type_id
WHERE
lpd.new_type = #{newTypeId}
AND lpd.parent_id = #{parentId}
AND lpd.publish_task = #{publishTask}
GROUP BY
lpd.parent_id,
lpd.type_id
SELECT
lad.id AS id,
lad.parent_id AS parentId,
lad.type_id AS typeId,
IFNULL( lad.pre_num, 0 ) AS preNum,
mt1.type_name AS maTypeName,
mt.type_name AS typeName,
mt.unit_name AS unitName,
mt.manage_type AS manageType
FROM
lease_apply_details lad
LEFT JOIN ma_type mt ON lad.type_id = mt.type_id
AND mt.`level` = 4
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
WHERE
mt.is_rs = 1
AND lad.parent_id = #{id}
SELECT
bai.agreement_code AS agreementcode,
lod.parent_id as parentid,
sd2.dept_name as deptname,
bu2.unit_name as unitname,
bp2.pro_name as proname,
mt2.type_name as typename,
mt.type_name as modeltype,
lod.out_num as outnum,
mm.ma_code as macode,
lod.create_time as outTime,
case when mt.jiju_type='1' then '机具' else '安全工器具' end as jijutype,
lai.`code` as code,
lai.lease_person as leaseperson,
lod.publish_task as publishtask,
lai.direct_id as directid,
lod.publish_task as publishtaskt
FROM
lease_out_details lod
LEFT JOIN lease_apply_info lai on lod.parent_id = lai.id
LEFT JOIN tm_task_agreement tta on lai.task_id = tta.task_id
LEFT JOIN bm_agreement_info bai on tta.agreement_id = bai.agreement_id
LEFT JOIN bm_unit bu2 on bai.unit_id = bu2.unit_id
LEFT JOIN bm_project bp2 on bai.project_id = bp2.pro_id
LEFT JOIN sys_dept sd2 on bp2.imp_unit = sd2.dept_id
LEFT JOIN ma_type mt on lod.type_id = mt.type_id
LEFT JOIN ma_type mt2 on mt.parent_id = mt2.type_id
LEFT JOIN ma_machine mm on mm.ma_id = lod.ma_id
WHERE lod.publish_task is null
and SUBSTR(lod.create_time,1,10)>=#{startTime}
and #{endTime}>=SUBSTR(lod.create_time,1,10)
and sd2.dept_name like concat('%', #{deptName} ,'%')
and bp2.pro_name like concat('%', #{proName} ,'%')
and lai.lease_person like concat('%', #{leasePerson} ,'%')
and mt.type_name like concat('%', #{modelType} ,'%')
and mt2.type_name like concat('%', #{typeName} ,'%')
and mt.jiju_type= #{jijuType}
and ( bp2.pro_name like concat('%', #{keyWord} ,'%')
or sd2.dept_name like concat('%', #{keyWord} ,'%')
or bai.agreement_code like concat('%', #{keyWord} ,'%')
or lai.`code` like concat('%', #{keyWord} ,'%')
or mm.ma_code like concat('%', #{keyWord} ,'%')
or mt2.type_name like concat('%', #{keyWord} ,'%')
or mt.type_name like concat('%', #{keyWord} ,'%'))
GROUP BY lod.ID
UNION
SELECT
bai.agreement_code as agreementcode,
lod.parent_id as parentid,
sd2.dept_name as deptname,
bu2.unit_name as unitname,
bp2.pro_name as proname,
mt2.type_name as typename,
mt.type_name as modelname,
lod.out_num as outnum,
mm.ma_code as macode,
lod.create_time as outTime,
case when mt.jiju_type='1' then '机具' else '安全工器具' end as jijutype,
lpd.`code` as code,
lpd.lease_person as leaseperson,
lod.publish_task as publishtask,
null as directid,
lpd.publish_task as publishtaskt
FROM
lease_out_details lod
LEFT JOIN lease_publish_details lpd on lod.publish_task = lpd.publish_task
LEFT JOIN bm_unit bu2 on lpd.unit_id = bu2.unit_id
LEFT JOIN bm_project bp2 on lpd.project_id = bp2.pro_id
LEFT JOIN bm_agreement_info bai on lpd.unit_id = bai.unit_id and lpd.project_id = bai.project_id
LEFT JOIN sys_dept sd2 on bp2.imp_unit = sd2.dept_id
LEFT JOIN ma_type mt on lod.type_id = mt.type_id
LEFT JOIN ma_type mt2 on mt.parent_id = mt2.type_id
LEFT JOIN ma_machine mm on mm.ma_id = lod.ma_id
WHERE mt.jiju_type =1 and lod.publish_task is not null
and SUBSTR(lod.create_time,1,10)>=#{startTime}
and #{endTime}>=SUBSTR(lod.create_time,1,10)
and sd2.dept_name like concat('%', #{deptName} ,'%')
and bp2.pro_name like concat('%', #{proName} ,'%')
and lpd.lease_person like concat('%', #{leasePerson} ,'%')
and mt.type_name like concat('%', #{modelType} ,'%')
and mt2.type_name like concat('%', #{typeName} ,'%')
and mt.jiju_type= #{jijuType}
and ( bp2.pro_name like concat('%', #{keyWord} ,'%')
or sd2.dept_name like concat('%', #{keyWord} ,'%')
or bai.agreement_code like concat('%', #{keyWord} ,'%')
or lai.`code` like concat('%', #{keyWord} ,'%')
or mm.ma_code like concat('%', #{keyWord} ,'%')
or mt2.type_name like concat('%', #{keyWord} ,'%')
or mt.type_name like concat('%', #{keyWord} ,'%'))
GROUP BY lod.ID