地质所 沉降监测网建设项目
zmk
2024-10-23 3f47c88e7cb4e53b3637620794420181f47b5a5e
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?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.javaweb.geo.mapper.TubLogMapper">
    
    <resultMap type="TubLog" id="TubLogResult">
        <result property="id"    column="id"    />
        <result property="code"    column="code"    />
        <result property="projectId"    column="project_id"    />
        <result property="tubName"    column="tub_name"    />
        <result property="type"    column="type"    />
        <result property="outboundDate"    column="outbound_date"    />
        <result property="inboundDate"    column="inbound_date"    />
        <result property="optUser"    column="opt_user"    />
        <result property="applyUser"    column="apply_user"    />
        <result property="number"    column="number"    />
        <result property="unit"    column="unit"    />
        <result property="createDate"    column="create_date"    />
        <result property="fileUrl"    column="file_url"    />
        <result property="remark"    column="remark"    />
        <result property="outboundNumber"    column="outbound_number"    />
        <result property="inboundNumber"    column="inbound_number"    />
    </resultMap>
 
    <sql id="selectTubLogVo">
        select id, code, project_id, tub_name, type, outbound_date, inbound_date, opt_user, apply_user, number, unit, create_date, file_url, remark from js_tub_log
    </sql>
 
    <select id="selectTubLogList" parameterType="TubLog" resultMap="TubLogResult">
        <include refid="selectTubLogVo"/>
        <where>  
            <if test="code != null  and code != ''"> and code = #{code}</if>
            <if test="projectId != null  and projectId != ''"> and project_id = #{projectId}</if>
            <if test="tubName != null  and tubName != ''"> and tub_name like concat('%', #{tubName}, '%')</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="outboundDate != null "> and outbound_date = #{outboundDate}</if>
            <if test="inboundDate != null "> and inbound_date = #{inboundDate}</if>
            <if test="optUser != null  and optUser != ''"> and opt_user = #{optUser}</if>
            <if test="applyUser != null  and applyUser != ''"> and apply_user = #{applyUser}</if>
            <if test="number != null "> and number = #{number}</if>
            <if test="unit != null  and unit != ''"> and unit = #{unit}</if>
            <if test="createDate != null "> and create_date = #{createDate}</if>
        </where>
    </select>
    
    <select id="selectTubLogById" parameterType="Integer" resultMap="TubLogResult">
        <include refid="selectTubLogVo"/>
        where id = #{id}
    </select>
 
    <select id="selectMaxTubLogId" resultType="java.lang.Integer">
        SELECT MAX(id) FROM js_tub_log where project_id = #{projectId}
    </select>
 
    <select id="countTubLogDate2" resultMap="TubLogResult">
        SELECT
            a.tub_name,
            b.inbound_number,
            a.outbound_number,
            a.unit
        FROM
            ( SELECT tub_name, SUM( number ) AS outbound_number, unit FROM js_tub_log WHERE outbound_date IS NOT NULL GROUP BY tub_name ) a
            LEFT JOIN ( SELECT tub_name, SUM( number ) AS inbound_number, unit FROM js_tub_log WHERE inbound_date IS NOT NULL GROUP BY tub_name ) b ON a.tub_name = b.tub_name
    </select>
 
    <select id="countTubLogDate" resultMap="TubLogResult">
        SELECT
        a.project_id,
        a.tub_name,
        a.inbound_number,
        b.outbound_number,
        a.unit
        FROM
        ( SELECT project_id, tub_name, SUM( number ) AS inbound_number, unit FROM js_tub_log WHERE inbound_date IS NOT NULL and project_id = #{projectId} GROUP BY tub_name ) a
        LEFT JOIN ( SELECT project_id, tub_name, SUM( number ) AS outbound_number, unit FROM js_tub_log WHERE outbound_date IS NOT NULL and project_id = #{projectId} GROUP BY tub_name ) b ON a.tub_name = b.tub_name
        AND a.project_id = b.project_id
    </select>
 
    <insert id="insertTubLog" parameterType="TubLog" useGeneratedKeys="true" keyProperty="id">
        insert into js_tub_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="code != null  and code != ''">code,</if>
            <if test="projectId != null  and projectId != ''">project_id,</if>
            <if test="tubName != null  and tubName != ''">tub_name,</if>
            <if test="type != null  and type != ''">type,</if>
            <if test="outboundDate != null ">outbound_date,</if>
            <if test="inboundDate != null ">inbound_date,</if>
            <if test="optUser != null  and optUser != ''">opt_user,</if>
            <if test="applyUser != null  and applyUser != ''">apply_user,</if>
            <if test="number != null ">number,</if>
            <if test="unit != null  and unit != ''">unit,</if>
            <if test="createDate != null ">create_date,</if>
            <if test="fileUrl != null  and fileUrl != ''">file_url,</if>
            <if test="remark != null  and remark != ''">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="code != null  and code != ''">#{code},</if>
            <if test="projectId != null  and projectId != ''">#{projectId},</if>
            <if test="tubName != null  and tubName != ''">#{tubName},</if>
            <if test="type != null  and type != ''">#{type},</if>
            <if test="outboundDate != null ">#{outboundDate},</if>
            <if test="inboundDate != null ">#{inboundDate},</if>
            <if test="optUser != null  and optUser != ''">#{optUser},</if>
            <if test="applyUser != null  and applyUser != ''">#{applyUser},</if>
            <if test="number != null ">#{number},</if>
            <if test="unit != null  and unit != ''">#{unit},</if>
            <if test="createDate != null ">#{createDate},</if>
            <if test="fileUrl != null  and fileUrl != ''">#{fileUrl},</if>
            <if test="remark != null  and remark != ''">#{remark},</if>
         </trim>
    </insert>
 
    <update id="updateTubLog" parameterType="TubLog">
        update js_tub_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="code != null  and code != ''">code = #{code},</if>
            <if test="projectId != null  and projectId != ''">project_id = #{projectId},</if>
            <if test="tubName != null  and tubName != ''">tub_name = #{tubName},</if>
            <if test="type != null  and type != ''">type = #{type},</if>
            <if test="outboundDate != null ">outbound_date = #{outboundDate},</if>
            <if test="inboundDate != null ">inbound_date = #{inboundDate},</if>
            <if test="optUser != null  and optUser != ''">opt_user = #{optUser},</if>
            <if test="applyUser != null  and applyUser != ''">apply_user = #{applyUser},</if>
            <if test="number != null ">number = #{number},</if>
            <if test="unit != null  and unit != ''">unit = #{unit},</if>
            <if test="createDate != null ">create_date = #{createDate},</if>
            <if test="fileUrl != null  and fileUrl != ''">file_url = #{fileUrl},</if>
            <if test="remark != null  and remark != ''">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>
 
    <delete id="deleteTubLogById" parameterType="Integer">
        delete from js_tub_log where id = #{id}
    </delete>
 
    <delete id="deleteTubLogByIds" parameterType="String">
        delete from js_tub_log where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    
</mapper>