select
r.id,
r.review_status,
r.reporting_work_id,
r.patch_id,
r.process_id,
r.order_id,
r.order_sort,
o.project,
o.batch,
od.building_number,
od.product_name,
r.technology_number,
ogd.glass_address,
ogd.glass_child,
r.patch_num,
ogd.child_width as width,
ogd.child_height as height,
od.shape,
r.patch_type,
r.patch_reason,
r.responsible_team,
r.responsible_personnel,
r.responsible_equipment,
r.patch_area,
r.quality_inspector,
r.patch_processes,
r.reviewer,
r.create_time as create_time,
date(r.update_time) as update_time,
JSON_UNQUOTE( JSON_EXTRACT( od.other_columns, '$.S01' )) AS glassNumber
from pp.patch_log r left join sd.order_detail od on r.order_id=od.order_id and r.order_sort=od.order_number
left join sd.`order` o on r.order_id = o.order_id
left join (select * from sd.order_glass_detail group by order_id,order_number,technology_number) as ogd
on r.order_id = ogd.order_id and r.order_sort = ogd.order_number and r.technology_number=ogd.technology_number
date(r.create_time)>=#{startDate} and date(r.create_time) <= #{endDate}
and o.create_order>0
and r.patch_id regexp #{patchLog.patchId}
and r.order_id regexp #{patchLog.orderId}
and r.reporting_work_id regexp #{patchLog.reportingWorkId}
and r.process_id regexp #{patchLog.processId}
and o.project regexp #{patchLog.project}
and o.batch regexp #{patchLog.batch}
and r.order_sort regexp #{patchLog.orderSort}
and od.building_number regexp #{patchLog.buildingNumber}
and od.product_name regexp #{patchLog.productName}
and r.technology_number regexp #{patchLog.technologyNumber}
and r.quality_inspector regexp #{patchLog.qualityInspector}
and ogd.child_width regexp REGEXP_REPLACE(#{patchLog.width},'\\.0+$','')
and ogd.child_height regexp REGEXP_REPLACE(#{patchLog.height},'\\.0+$','')
and od.shape regexp #{patchLog.shape}
and r.patch_num regexp #{patchLog.patchNum}
and ogd.glass_address regexp #{patchLog.glassAddress}
and ogd.glass_child regexp #{patchLog.glassChild}
and r.responsible_team like concat('%', #{patchLog.responsibleTeam}, '%')
and r.responsible_equipment regexp #{patchLog.responsibleEquipment}
and r.responsible_personnel regexp #{patchLog.responsiblePersonnel}
and r.patch_type regexp #{patchLog.patchType}
and r.patch_reason regexp #{patchLog.patchReason}
and r.patch_area regexp #{patchLog.patchArea}
and r.quality_inspector regexp #{patchLog.qualityInspector}
and r.patch_processes regexp #{patchLog.patchProcesses}
and r.reviewer like concat('%', #{patchLog.reviewer}, '%')
order by r.review_status,r.id desc
limit #{offset},#{pageSize};
select CEILING(count(zu.id)/#{pageSize}) as 'pageTotal',
count(zu.id) as 'total'
from (select r.id as id
from pp.patch_log r left join sd.order_detail od on r.order_id=od.order_id and r.order_sort=od.order_number
left join sd.`order` o on r.order_id = o.order_id
left join (select * from sd.order_glass_detail group by order_id,order_number,technology_number) as ogd
on r.order_id = ogd.order_id and r.order_sort = ogd.order_number and r.technology_number=ogd.technology_number
date(r.create_time)>=#{startDate} and date(r.create_time) <= #{endDate}
and r.patch_id regexp #{patchLog.patchId}
and r.order_id regexp #{patchLog.orderId}
and r.reporting_work_id regexp #{patchLog.reportingWorkId}
and r.process_id regexp #{patchLog.processId}
and o.project regexp #{patchLog.project}
and o.batch regexp #{patchLog.batch}
and r.order_sort regexp #{patchLog.orderSort}
and od.building_number regexp #{patchLog.buildingNumber}
and od.product_name regexp #{patchLog.productName}
and r.technology_number regexp #{patchLog.technologyNumber}
and r.quality_inspector regexp #{patchLog.qualityInspector}
and ogd.child_width regexp REGEXP_REPLACE(#{patchLog.width},'\\.0+$','')
and ogd.child_height regexp REGEXP_REPLACE(#{patchLog.height},'\\.0+$','')
and od.shape regexp #{patchLog.shape}
and r.patch_num regexp #{patchLog.patchNum}
and ogd.glass_address regexp #{patchLog.glassAddress}
and ogd.glass_child regexp #{patchLog.glassChild}
and r.responsible_team like concat('%', #{patchLog.responsibleTeam}, '%')
and r.responsible_equipment regexp #{patchLog.responsibleEquipment}
and r.responsible_personnel regexp #{patchLog.responsiblePersonnel}
and r.patch_type regexp #{patchLog.patchType}
and r.patch_reason regexp #{patchLog.patchReason}
and r.patch_area regexp #{patchLog.patchArea}
and r.quality_inspector regexp #{patchLog.qualityInspector}
and r.patch_processes regexp #{patchLog.patchProcesses}
and r.reviewer like concat('%', #{patchLog.reviewer}, '%')
) as zu
SELECT IFNULL(patch_id,'00')
FROM patch_log
WHERE DATE(create_time) = CURDATE()
ORDER BY create_time DESC
LIMIT 1;
insert into pp.patch_log(patch_id,reporting_work_id,process_id,order_id, order_sort, technology_number, responsible_team,
responsible_personnel, patch_type, patch_reason, patch_processes, patch_num,
patch_area,responsible_equipment,quality_inspector, reviewer, review_status, create_time)
values (
#{oddNumber}, #{patchLog.reportingWorkId},#{patchLog.processId},#{patchLog.orderId},#{patchLog.orderSort},#{patchLog.technologyNumber},
#{patchLog.responsibleTeam},#{patchLog.responsiblePersonnel},#{patchLog.patchType},#{patchLog.patchReason},
#{patchLog.patchProcesses},#{patchLog.patchNum},#{patchLog.patchArea},#{patchLog.responsibleEquipment},#{patchLog.qualityInspector},"",0,now()
)
update pp.patch_log set reviewer=#{userName},review_status=1,update_time=now() where id=#{patchLog.id}
update sd.order_process_detail
set reporting_work_num=reporting_work_num - #{patchLog.patchNum}
where order_id = #{patchLog.orderId}
and process_id = #{patchLog.processId}
and order_number = #{patchLog.orderSort}
and technology_number = #{patchLog.technologyNumber}
and id (select a.opdid
from (select id as opdid
from sd.order_process_detail opd
where opd.order_id = #{patchLog.orderId}
and opd.process_id = #{patchLog.processId}
and opd.order_number = #{patchLog.orderSort}
and opd.technology_number = #{patchLog.technologyNumber}
and process = #{reportingWork.thisProcess}) as a)
update pp.damage_details set quantity=quantity+#{patchLog.patchNum},patch_status=1 where id=#{patchLog.reviewer}
update pp.reporting_work_detail set patch_status=1 where reporting_work_id=#{reportingWorkId}
and order_number=#{orderSort} and technology_number=#{technologyNumber}
select date(rw.reporting_work_time) as reportingWorkTime,
o.order_id as orderId,
dd.reporting_work_id as reportingWorkId,
rw.production_id as productionId,
rw.process_id as processId,
o.project,
o.batch,
dd.id as reviewer,
od.building_number as buildingNumber,
dd.order_number as orderSort,
od.product_name as productName,
dd.technology_number as technologyNumber,
ogd.glass_address as glassAddress,
dd.breakage_quantity-dd.quantity as patchNum,
ogd.child_width as width,
ogd.child_height as height,
od.shape,
dd.responsible_process as responsibleProcess,
rw.this_process as patchProcesses,
dd.breakage_quantity-dd.quantity as breakageQuantity,
dd.return_process as patchProcesses,
dd.breakage_reason as patchReason,
dd.breakage_type as patchType,
dd.responsible_personnel as responsiblePersonnel,
dd.responsible_equipment as responsibleEquipment,
dd.responsible_team as responsibleTeam,
ROUND((dd.breakage_quantity-dd.quantity) * od.width * od.height / 1000000, 2) as patchArea,
rw.quality_inspector as qualityInspector,
ogd.glass_child as glassChild,
if(dd.responsible_process=rw.this_process,2,dd.quality_ins_status) as qualityInsStatus,
if(dd.quality_ins_status=1,1,2) as orderBy,
dd.responsible_personnel as responsiblePersonnel
from pp.damage_details dd
left join pp.reporting_work_detail rwd on dd.reporting_work_id = rwd.reporting_work_id and dd.order_number=rwd.order_number and dd.technology_number=rwd.technology_number
left join pp.reporting_work rw on dd.reporting_work_id = rw.reporting_work_id
left join sd.`order` o on rw.order_id = o.order_id
left join sd.order_detail od on rw.order_id = od.order_id and dd.order_number = od.order_number
left join (select * from sd.order_glass_detail group by order_id,order_number,technology_number) as ogd
on rw.order_id = ogd.order_id and dd.order_number = ogd.order_number and rwd.technology_number=ogd.technology_number
dd.breakage_quantity-dd.quantity>0 and dd.available=0 and rw.reviewed_state!=-1 /*(dd.responsible_process=rw.this_process or (dd.quality_ins_status!=1)) and */
and o.create_order>0 and dd.patch_status=0
and o.order_id regexp #{patchLogAddDTO.orderId}
and dd.reporting_work_id regexp #{patchLogAddDTO.reportingWorkId}
and rw.production_id regexp #{patchLogAddDTO.productionId}
and rw.process_id regexp #{patchLogAddDTO.processId}
and o.project regexp #{patchLogAddDTO.project}
and o.batch regexp #{patchLogAddDTO.batch}
and dd.order_number regexp #{patchLogAddDTO.orderSort}
and od.product_name regexp #{patchLogAddDTO.productName}
and dd.technology_number regexp #{patchLogAddDTO.technologyNumber}
and rw.quality_inspector regexp #{patchLogAddDTO.qualityInspector}
and ogd.child_width regexp REGEXP_REPLACE(#{patchLogAddDTO.width},'\\.0+$','')
and ogd.child_height regexp REGEXP_REPLACE(#{patchLogAddDTO.height},'\\.0+$','')
and od.shape regexp #{patchLogAddDTO.shape}
and ogd.glass_address regexp #{patchLogAddDTO.glassAddress}
and ogd.glass_child regexp #{patchLogAddDTO.glassChild}
and dd.responsible_team like concat('%', #{patchLogAddDTO.responsibleTeam}, '%')
and dd.responsible_equipment regexp #{patchLogAddDTO.responsibleEquipment}
and dd.responsible_process regexp #{patchLogAddDTO.responsibleProcess}
and rw.this_process regexp #{patchLogAddDTO.patchProcesses}
and dd.breakage_type regexp #{patchLogAddDTO.patchType}
and dd.breakage_reason regexp #{patchLogAddDTO.patchReason}
order by orderBy desc,dd.id desc
delete from pp.patch_log where id=#{id}
delete from pp.damage_details
where reporting_work_id=#{reportingWorkId} and order_number=#{orderSort} and technology_number=#{technologyNumber}
and breakage_reason=#{patchReason}
update pp.reporting_work_detail set patch_status=0
where reporting_work_id=#{reportingWorkId} and order_number=#{orderSort} and technology_number=#{technologyNumber}
update sd.order_process_detail
set reporting_work_num=reporting_work_num + #{patchLog.patchNum}
where order_id = #{patchLog.orderId}
and process_id = #{patchLog.processId}
and order_number = #{patchLog.orderSort}
and technology_number = #{patchLog.technologyNumber}
and id (select a.opdid
from (select id as opdid
from sd.order_process_detail opd
where opd.order_id = #{patchLog.orderId}
and opd.process_id = #{patchLog.processId}
and opd.order_number = #{patchLog.orderSort}
and opd.technology_number = #{patchLog.technologyNumber}
and process = #{reportingWork.thisProcess}) as a)
update pp.patch_log set reviewer=null,review_status=0,update_time=now() where id=#{patchLog.id}
SELECT COUNT(*)
FROM patch_log
WHERE process_id= #{processId} and patch_id=#{patchId} and technology_number = #{technologyNumber}
and project_no IS not NULL;
select
r.id,
r.review_status,
r.reporting_work_id,
r.patch_id,
r.process_id,
r.order_id,
r.order_sort,
o.project,
o.batch,
od.building_number,
od.product_name,
r.technology_number,
ogd.glass_address,
ogd.glass_child,
r.patch_num,
ogd.child_width as width,
ogd.child_height as height,
od.shape,
r.patch_type,
r.patch_reason,
r.responsible_team,
r.responsible_personnel,
r.responsible_equipment,
r.patch_area,
r.quality_inspector,
r.patch_processes,
r.reviewer,
r.create_time as create_time,
date(r.update_time) as update_time,
JSON_UNQUOTE( JSON_EXTRACT( od.other_columns, '$.S01' )) AS glassNumber
from pp.patch_log r left join sd.order_detail od on r.order_id=od.order_id and r.order_sort=od.order_number
left join sd.`order` o on r.order_id = o.order_id
left join (select * from sd.order_glass_detail group by order_id,order_number,technology_number) as ogd
on r.order_id = ogd.order_id and r.order_sort = ogd.order_number and r.technology_number=ogd.technology_number
date(r.create_time)>=#{dates[0]} and date(r.create_time) <= #{dates[1]}
and o.create_order>0
order by r.review_status,r.id desc