select
ma_id as maId,
ma_code as maCode
from
ma_machine
where ma_status in (15,16)
and type_id = #{typeId}
select
red.id as id,
red.type_id as typeId,
red.ma_id as maId,
mt2.type_name as typeName,
mt.type_name as typeModelName,
mm.ma_code as maCode,
red.repair_num as repairNum,
red.status as repairStatus,
su.nick_name as repairer,
DATE_FORMAT(red.repair_time,'%Y-%m-%d') as repairTime
from repair_equipment_record red
left join ma_type mt on red.type_id = mt.type_id
left join ma_machine mm on mm.ma_id = red.ma_id
left join sys_user su on red.repairer = su.user_id
LEFT JOIN ma_type mt2 on mt.parent_id = mt2.type_id
LEFT JOIN ma_type_repair mtr on mtr.type_id = red.type_id
where 1=1
and mtr.user_id = #{userId}
AND (locate(#{keyword}, mm.ma_code) > 0
or locate(#{keyword}, su.nick_name) > 0
or locate(#{keyword}, mt2.type_name) > 0
or locate(#{keyword}, mt.type_name) > 0)
AND mt.type_name like concat('%',#{typeModelName},'%')
AND mt2.type_name like concat('%',#{typeName},'%')
AND red.status = #{repairStatus}
order by red.create_time desc
insert into repair_equipment_record (ma_id,type_id,repair_num,status,create_by,create_time,repairer,repair_time)
values (#{maId},#{typeId},#{repairNum},#{repairStatus},#{createBy},now(),#{repairer},#{repairTime});
insert into repair_equipment_details (parent_id,type_id,ma_id,part_id,part_num,part_price,repair_remark,repair_content,repair_content_before,part_change,part_change_num,create_by,create_time)
values (#{parentId},#{typeId},#{maId},#{partId},#{partNum},#{partPrice},#{repairRemark},#{repairContent},#{repairContentBefore},#{partChange},#{partChangeNum},#{createBy},now());
select
id,
ma_id as maId,
type_id as typeId,
repairer as repairer,
repair_num AS repairNum,
DATE_FORMAT(repair_time, '%Y-%m-%d') as repairTime
from repair_equipment_record rer
where rer.id = #{id}
select
red.id as id,
red.parent_id as parentId,
red.ma_id as maId,
red.part_id as partId,
part_num as partNum,
part_price as partCost,
repair_content as repairContent,
repair_content_before as repairContentBefore,
repair_remark as repairRemark,
part_change as partChange,
part_change_num as partChangeNum
from repair_equipment_details red
left join ma_part_type mpt on red.part_id = mpt.pa_id
where red.parent_id = #{id}
order by red.create_time desc
select
id,
model_id as modelId,
file_name as fileName,
file_url as fileUrl
from
sys_file_info sfi
where model_id = #{id} and repair_status = 2
delete from repair_equipment_details where parent_id = #{id}
delete from sys_file_info
where type_id = #{typeId} and repair_status = 2
and ma_id = #{maId}
update repair_equipment_record
ma_id = #{maId},
type_id = #{typeId},
repair_num = #{repairNum},
repairer = #{repairer},
repair_time = #{repairTime},
update_by = #{updateBy},
update_time = now()
where id = #{id}
update repair_equipment_record
status = 1
where id = #{id}
select
red.parent_id as parentId,
red.create_time,
red.type_id,
mm.ma_id as maId,
mm.ma_code as maCode,
rer.repair_num as repairNum,
rer.status as repairStatus,
DATE_FORMAT(rer.repair_time, '%Y-%m-%d') as repairTime,
mt2.type_name as typeName,
mt.type_name as typeModelName,
su.nick_name as repairerName,
(
SELECT GROUP_CONCAT(DISTINCT red2.repair_remark SEPARATOR ';')
FROM repair_equipment_details red2
WHERE red2.parent_id = rer.id
) as repairRemark,
-- 使用子查询获取 repairRemarkBefore
(
SELECT GROUP_CONCAT(DISTINCT red3.repair_content_before SEPARATOR ';')
FROM repair_equipment_details red3
WHERE red3.parent_id = rer.id
) as repairContentBefore,
(
SELECT GROUP_CONCAT(
CASE
-- 当 part_id 存在时,关联表获取 pa_name
WHEN red4.part_id IS NOT NULL THEN CONCAT(mpt.pa_name, ':','数量为',red4.part_num,' ', red4.repair_content)
WHEN red4.part_id IS NULL THEN CONCAT( red4.repair_content)
ELSE NULL
END
SEPARATOR '; '
)
FROM repair_equipment_details red4
LEFT JOIN ma_part_type mpt ON red4.part_id = mpt.pa_id
WHERE red4.parent_id = rer.id
) as repairContent
from
repair_equipment_details red
left join repair_equipment_record rer on red.parent_id = rer.id
left join ma_machine mm on mm.ma_id = rer.ma_id
left join ma_type mt on rer.type_id = mt.type_id
left join sys_user su on rer.repairer = su.user_id
LEFT JOIN ma_type mt2 on mt.parent_id = mt2.type_id
where
red.parent_id = #{id}
group by red.parent_id,red.type_id
delete from repair_equipment_record where id = #{id}