insert into book_car_detail(ma_id, order_status, order_company, order_user, address, creater, create_time,
devType)
values (#{maId}, 0, #{orderCompany}, #{orderUser}, #{address}, #{creater}, now(), #{devType})
delete from book_car_detail where id = #{id}
delete from book_car_detail where id in
#{id}
(SELECT
bcd.id as id,
d.ma_id as maId,
d.code as code,
d.device_name as deviceName,
d.device_count as deviceCount,
d.type_id as typeId,
d.ma_status as maStatus,
d.brand as brand,
'0' AS devType,
mt.type_name as typeName,
d.manage_type as manageType,
d.production_date as productionDate,
d.working_hours as workingHours,
sd.leader as person,
sd.phone as personPhone,
c.company_name as companyName,
c.company_id as companyId,
c.operate_address as operateAddress,
d.create_time as createTime,
d.up_down_status as upDownStatus,
bcd.order_user as orderUser,
bcd.address as address
FROM ma_dev_info d
LEFT JOIN sys_dept sd ON sd.dept_id = d.on_company
LEFT JOIN bm_company_info c ON d.on_company = c.company_id
LEFT JOIN book_car_detail bcd ON d.ma_id = bcd.ma_id
LEFT JOIN ma_type mt ON d.type_id = mt.type_id and mt.del_flag = '0'
where d.is_active = '1' and bcd.order_status = '0' and bcd.devType ='0'
and bcd.ma_id = #{maId}
and bcd.order_user = #{orderUser}
)
UNION ALL
(
SELECT
bcd.id as id,
tl.id as maId,
tl.tool_code as code,
tt1.type_name as deviceName,
tl.available_num as deviceCount,
tl.type_id as typeId,
if(tl.available_num = 0,2,1) as maStatus,
ms.supplier_name as brand,
'1' AS devType,
tt.type_name as typeName,
tl.manage_mode as manageType,
tl.production_date as productionDate,
'' as workingHours,
sd.leader as person,
sd.phone as personPhone,
c.company_name as companyName,
c.company_id as companyId,
c.operate_address as operateAddress,
tt.create_time as createTime,
tl.up_down_status AS upDownStatus,
bcd.order_user as orderUser,
bcd.address as address
FROM
tool_ledger tl
LEFT JOIN sys_dept sd ON sd.dept_id = tl.company_id
LEFT JOIN tool_type tt ON tt.type_id = tl.type_id
LEFT JOIN tool_type tt1 ON tt.parent_id = tt1.type_id
LEFT JOIN bm_company_info c ON tl.company_id = c.company_id
LEFT JOIN book_car_detail bcd ON tl.id = bcd.ma_id
LEFT JOIN ma_supplier ms ON ms.supplier_id = tl.supplier_id
WHERE
tl.up_down_status = '1' and bcd.order_status = '0' and bcd.devType ='1'
-- 工具表也可添加动态筛选条件(如需),示例:
and bcd.ma_id = #{maId}
and bcd.order_user = #{orderUser}
-- 子查询加 limit 避免 order by 问题(如果工具表也需要排序,可在这里加)
LIMIT 1000000
)
SELECT ma_id as maId,
order_user as orderUser
from book_car_detail
where ma_id = #{maId}
and order_user = #{userId}
and order_status = '0'
and devType = #{devType}
SELECT tl.fileList AS picUrl, -- 1. 对应第一部分 picUrl
'' AS proType, -- 2. 对应 proType
'' AS mainGx, -- 3. 对应 mainGx
'' AS childGx, -- 4. 对应 childGx
'' AS devCategory, -- 5. 对应 devCategory
'' AS devSubcategory, -- 6. 对应 devSubcategory
tt.type_name AS typeName, -- 7. 对应 devName
'1' AS devType, -- 8. 对应 devType
tl.manage_mode AS manageMode, -- 9. 对应 manageMode(与第一部分位置一致!)
bcd.id AS id, -- 10. 对应 maId
tl.id AS maId, -- 10. 对应 maId
tl.tool_code AS `code`, -- 11. 对应 code
tl.identify_code AS identifyCode, -- 12. 对应 identifyCode
tt1.type_name AS deviceName, -- 13. 对应 deviceName
tl.available_num AS deviceCount, -- 14. 对应 deviceCount
tl.type_id AS typeId, -- 15. 对应 typeId
tl.STATUS AS maStatus, -- 16. 对应 maStatus
'' AS brand, -- 17. 对应 brand
tl.production_date AS productionDate, -- 18. 对应 productionDate
0 AS workingHours, -- 19. 对应 workingHours
sd.leader AS person, -- 20. 对应 person
sd.phone AS personPhone, -- 21. 对应 personPhone
tl.create_time AS createTime, -- 22. 对应 createTime
tl.update_time AS updateTime, -- 23. 对应 updateTime
tl.company_id AS companyId, -- 24. 对应 companyId
sd.dept_name AS companyName, -- 25. 对应 companyName
c.operate_address AS operateAddress, -- 26. 对应 operateAddress(列数对齐!)
tt.create_time AS companyCreateTime
FROM tool_ledger tl
LEFT JOIN sys_dept sd ON tl.company_id = sd.dept_id
INNER JOIN tool_type tt ON tt.type_id = tl.type_id
INNER JOIN tool_type tt1 ON tt.parent_id = tt1.type_id -- 确保 tt 有 parent_id,否则可能查不到数据
LEFT JOIN bm_company_info c ON sd.dept_id = c.company_id
LEFT JOIN book_car_detail bcd ON tl.id = bcd.ma_id
where bcd.order_status = '0' and bcd.devType ='0'
and bcd.ma_id = #{maId}
and bcd.order_user = #{orderUser}