Bonus-Cloud-Material-Mall/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/bookcar/BookCarMapper.xml

160 lines
6.6 KiB
XML
Raw Normal View History

2024-11-22 17:41:27 +08:00
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.material.book.mapper.BookCarMapper">
<insert id="addBookCarDetail">
2025-11-20 18:01:26 +08:00
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})
2024-11-22 17:41:27 +08:00
</insert>
2024-11-23 17:15:01 +08:00
2024-11-26 10:59:41 +08:00
<delete id="deleteById">
delete from book_car_detail where id = #{id}
</delete>
2024-12-26 18:09:09 +08:00
<delete id="deleteByIds">
delete from book_car_detail where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
2024-11-23 17:15:01 +08:00
<select id="getBookCarDetails" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
2025-11-20 18:01:26 +08:00
(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,
2025-12-01 17:23:50 +08:00
d.manage_type as manageType,
2025-11-20 18:01:26 +08:00
d.production_date as productionDate,
d.working_hours as workingHours,
2025-12-01 17:23:50 +08:00
sd.leader as person,
sd.phone as personPhone,
2025-11-20 18:01:26 +08:00
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
2024-11-23 17:15:01 +08:00
FROM ma_dev_info d
2025-12-01 17:23:50 +08:00
LEFT JOIN sys_dept sd ON sd.dept_id = d.on_company
2025-11-20 18:01:26 +08:00
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
2024-11-23 17:15:01 +08:00
LEFT JOIN ma_type mt ON d.type_id = mt.type_id and mt.del_flag = '0'
2025-11-20 18:01:26 +08:00
where d.is_active = '1' and bcd.order_status = '0' and bcd.devType ='0'
<if test="maId != null and maId != ''">
2024-11-26 11:15:54 +08:00
and bcd.ma_id = #{maId}
2025-11-20 18:01:26 +08:00
</if>
<if test="orderUser != null and orderUser != ''">
and bcd.order_user = #{orderUser}
</if>)
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,
2025-12-01 17:23:50 +08:00
if(tl.available_num = 0,2,1) as maStatus,
2025-11-20 18:01:26 +08:00
ms.supplier_name as brand,
'1' AS devType,
2025-12-01 17:23:50 +08:00
tt.type_name as typeName,
2025-11-20 18:01:26 +08:00
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'
-- 工具表也可添加动态筛选条件(如需),示例:
<if test="maId != null and maId != ''">
and bcd.ma_id = #{maId}
</if>
2024-11-26 11:15:54 +08:00
<if test="orderUser != null and orderUser != ''">
and bcd.order_user = #{orderUser}
</if>
2025-11-20 18:01:26 +08:00
-- 子查询加 limit 避免 order by 问题(如果工具表也需要排序,可在这里加)
LIMIT 1000000
)
2024-11-22 17:41:27 +08:00
</select>
2024-11-26 10:25:17 +08:00
<select id="selectDevInfoByMaId" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
2025-11-20 18:01:26 +08:00
SELECT ma_id as maId,
order_user as orderUser
2024-11-26 10:25:17 +08:00
from book_car_detail
2025-11-20 18:01:26 +08:00
where ma_id = #{maId}
and order_user = #{userId}
and order_status = '0'
and devType = #{devType}
</select>
<select id="getBookCarDetailsTool" resultType="com.bonus.material.device.domain.vo.DevInfoVo">
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'
<if test="maId != null and maId != ''">
and bcd.ma_id = #{maId}
</if>
<if test="orderUser != null and orderUser != ''">
and bcd.order_user = #{orderUser}
</if>
2024-11-26 10:25:17 +08:00
</select>
2024-11-22 17:41:27 +08:00
</mapper>