|
|
@@ -9,35 +9,112 @@
|
|
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
|
|
-->
|
|
|
|
|
|
+ <!-- 与 MaterialsCabinetServiceImpl 原 Java 逻辑一致:物资异常状态(按 status 倒序取一条) -->
|
|
|
+ <sql id="exMaterialStatusSubquery">
|
|
|
+ (SELECT m1.status
|
|
|
+ FROM isc_materials m1
|
|
|
+ WHERE m1.deleted = 0
|
|
|
+ AND m1.materials_cabinet_id = c.id
|
|
|
+ AND (m1.loan_state = '0' OR m1.status != '0')
|
|
|
+ AND m1.status NOT IN ('0', '3')
|
|
|
+ ORDER BY m1.status DESC
|
|
|
+ LIMIT 1)
|
|
|
+ </sql>
|
|
|
+
|
|
|
<select id="getIsMaterialsCabinetPage"
|
|
|
resultType="cn.iocoder.yudao.module.iscs.controller.admin.materialscabinet.vo.MaterialsCabinetRespVO">
|
|
|
- SELECT
|
|
|
- c.*,
|
|
|
- h.hardware_name,
|
|
|
- w.workstation_name
|
|
|
- FROM
|
|
|
- isc_materials_cabinet c
|
|
|
- LEFT JOIN isc_hardware h ON c.hardware_id = h.id
|
|
|
- LEFT JOIN isc_workstation w ON c.workstation_id = w.id
|
|
|
+ SELECT *
|
|
|
+ FROM (
|
|
|
+ SELECT
|
|
|
+ c.id,
|
|
|
+ c.cabinet_code,
|
|
|
+ c.cabinet_name,
|
|
|
+ c.hardware_id,
|
|
|
+ c.workarea_id,
|
|
|
+ c.workstation_id,
|
|
|
+ c.cabinet_icon,
|
|
|
+ c.cabinet_picture,
|
|
|
+ c.remark,
|
|
|
+ c.creator,
|
|
|
+ c.create_time,
|
|
|
+ c.updater,
|
|
|
+ c.update_time,
|
|
|
+ c.deleted,
|
|
|
+ CASE
|
|
|
+ WHEN <include refid="exMaterialStatusSubquery"/> IS NOT NULL THEN '2'
|
|
|
+ WHEN EXISTS (
|
|
|
+ SELECT 1 FROM sys_exception_misplace e1
|
|
|
+ WHERE e1.deleted = 0
|
|
|
+ AND e1.restitution_to_id = c.id
|
|
|
+ AND e1.status = '0'
|
|
|
+ AND e1.exception_type = '0'
|
|
|
+ ) THEN '2'
|
|
|
+ WHEN EXISTS (
|
|
|
+ SELECT 1 FROM sys_exception_misplace e2
|
|
|
+ WHERE e2.deleted = 0
|
|
|
+ AND e2.loan_from_id = c.id
|
|
|
+ AND e2.status = '0'
|
|
|
+ AND e2.exception_type = '1'
|
|
|
+ ) THEN '2'
|
|
|
+ WHEN EXISTS (
|
|
|
+ SELECT 1 FROM isc_materials m2
|
|
|
+ WHERE m2.deleted = 0
|
|
|
+ AND m2.materials_cabinet_id = c.id
|
|
|
+ AND m2.loan_state = '0'
|
|
|
+ ) THEN '1'
|
|
|
+ ELSE '0'
|
|
|
+ END AS status,
|
|
|
+ CASE
|
|
|
+ WHEN <include refid="exMaterialStatusSubquery"/> IS NOT NULL THEN <include refid="exMaterialStatusSubquery"/>
|
|
|
+ WHEN EXISTS (
|
|
|
+ SELECT 1 FROM sys_exception_misplace e1
|
|
|
+ WHERE e1.deleted = 0
|
|
|
+ AND e1.restitution_to_id = c.id
|
|
|
+ AND e1.status = '0'
|
|
|
+ AND e1.exception_type = '0'
|
|
|
+ ) THEN '3'
|
|
|
+ WHEN EXISTS (
|
|
|
+ SELECT 1 FROM sys_exception_misplace e2
|
|
|
+ WHERE e2.deleted = 0
|
|
|
+ AND e2.loan_from_id = c.id
|
|
|
+ AND e2.status = '0'
|
|
|
+ AND e2.exception_type = '1'
|
|
|
+ ) THEN '5'
|
|
|
+ WHEN EXISTS (
|
|
|
+ SELECT 1 FROM isc_materials m2
|
|
|
+ WHERE m2.deleted = 0
|
|
|
+ AND m2.materials_cabinet_id = c.id
|
|
|
+ AND m2.loan_state = '0'
|
|
|
+ ) THEN '4'
|
|
|
+ ELSE '0'
|
|
|
+ END AS ex_reason,
|
|
|
+ h.hardware_name,
|
|
|
+ w.workstation_name
|
|
|
+ FROM
|
|
|
+ isc_materials_cabinet c
|
|
|
+ LEFT JOIN isc_hardware h ON c.hardware_id = h.id
|
|
|
+ LEFT JOIN isc_workstation w ON c.workstation_id = w.id
|
|
|
+ <where>
|
|
|
+ c.deleted = 0
|
|
|
+ <if test="vo.cabinetId != null">
|
|
|
+ and c.id = #{vo.cabinetId}
|
|
|
+ </if>
|
|
|
+ <if test="vo.cabinetCode != null and vo.cabinetCode.trim() != ''">
|
|
|
+ and c.cabinet_code like concat('%',#{vo.cabinetCode},'%')
|
|
|
+ </if>
|
|
|
+ <if test="vo.workstationId != null">
|
|
|
+ and c.workstation_id = #{vo.workstationId}
|
|
|
+ </if>
|
|
|
+ <if test="vo.cabinetName != null and vo.cabinetName.trim() != ''">
|
|
|
+ and c.cabinet_name like concat('%',#{vo.cabinetName},'%')
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
+ ) cabinet_row
|
|
|
<where>
|
|
|
- c.deleted = 0
|
|
|
- <if test="vo.cabinetId != null">
|
|
|
- and c.id = #{vo.cabinetId}
|
|
|
- </if>
|
|
|
- <if test="vo.cabinetCode != null and vo.cabinetCode.trim != ''">
|
|
|
- and c.cabinet_code like concat('%',#{vo.cabinetCode},'%')
|
|
|
- </if>
|
|
|
- <if test="vo.workstationId != null">
|
|
|
- and c.workstation_id = #{vo.workstationId}
|
|
|
- </if>
|
|
|
- <if test="vo.cabinetName != null and vo.cabinetName.trim != ''">
|
|
|
- and c.cabinet_name like concat('%',#{vo.cabinetName},'%')
|
|
|
- </if>
|
|
|
- <if test="vo.status != null and vo.status.trim != ''">
|
|
|
- and c.status = #{vo.status}
|
|
|
+ <if test="vo.status != null and vo.status.trim() != ''">
|
|
|
+ cabinet_row.status = #{vo.status}
|
|
|
</if>
|
|
|
</where>
|
|
|
- ORDER BY
|
|
|
- c.id asc
|
|
|
+ ORDER BY cabinet_row.id ASC
|
|
|
</select>
|
|
|
</mapper>
|