吴羡
7 小时以前 2f07589b54d56085af77b50d580890cd4130b444
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?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.ruoyi.require.mapper.FeStandardSubstanceMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ruoyi.require.pojo.FeStandardSubstance">
        <id column="id" property="id" />
        <result column="name" property="name" />
        <result column="model" property="model" />
        <result column="factory_manufacturer" property="factoryManufacturer" />
        <result column="factory_num" property="factoryNum" />
        <result column="manage_num" property="manageNum" />
        <result column="uncertainty" property="uncertainty" />
        <result column="quantity" property="quantity" />
        <result column="acquisition_date" property="acquisitionDate" />
        <result column="effective_date" property="effectiveDate" />
        <result column="file_num" property="fileNum" />
        <result column="position" property="position" />
        <result column="state" property="state" />
        <result column="remark" property="remark" />
        <result column="create_user" property="createUser" />
        <result column="create_time" property="createTime" />
        <result column="update_user" property="updateUser" />
        <result column="update_time" property="updateTime" />
    </resultMap>
    <select id="getPage" resultType="com.ruoyi.require.pojo.FeStandardSubstance">
        select s.*,
               GREATEST(COALESCE(s.quantity, 0) - COALESCE((
                   SELECT SUM(CASE WHEN r.borrow_quantity IS NULL THEN COALESCE(s.quantity, 0)
                                   ELSE r.borrow_quantity END)
                   FROM cnas_fe_standard_substance_record r
                   WHERE r.substance_id = s.id AND COALESCE(r.status, '0') &lt;&gt; '1'
               ), 0), 0) AS remaining_quantity
        from cnas_fe_standard_substance s
        <where>
            <if test="ew.name != null and ew.name != ''">
                s.name like CONCAT('%', #{ew.name}, '%')
            </if>
            <if test="ew.factoryManufacturer != null and ew.factoryManufacturer != ''">
                and s.factory_manufacturer like CONCAT('%', #{ew.factoryManufacturer}, '%')
            </if>
            <if test="ew.factoryNum != null and ew.factoryNum != ''">
                and s.factory_num like CONCAT('%', #{ew.factoryNum}, '%')
            </if>
            <if test="ew.manageNum != null and ew.manageNum != ''">
                and s.manage_num like CONCAT('%', #{ew.manageNum}, '%')
            </if>
            <if test="ew.model != null and ew.model != ''">
                and s.model like CONCAT('%', #{ew.model}, '%')
            </if>
            <if test="ew.effectiveDate != null and ew.effectiveDate != ''">
                and s.effective_date =  #{ew.effectiveDate}
            </if>
            <if test="ew.fileNum != null and ew.fileNum != ''">
                and s.file_num like CONCAT('%', #{ew.fileNum}, '%')
            </if>
            <if test="ew.position != null and ew.position != ''">
                and s.position like CONCAT('%', #{ew.position}, '%')
            </if>
        </where>
        ORDER BY s.acquisition_date DESC, s.id DESC
    </select>
 
</mapper>