TWorkOrderMapper.xml 8.66 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
<?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.zehong.system.mapper.TWorkOrderMapper">
    
    <resultMap type="TWorkOrder" id="TWorkOrderResult">
        <result property="orderId"    column="order_id"    />
        <result property="orderType"    column="order_type"    />
        <result property="resourceId"    column="resource_id"    />
        <result property="orderName"    column="order_name"    />
        <result property="orderStatus"    column="order_status"    />
王晓倩's avatar
王晓倩 committed
13
        <result property="archiving"    column="archiving"    />
王晓倩's avatar
王晓倩 committed
14
        <result property="updateTime"    column="update_time"    />
15 16 17 18 19
        <result property="appointInspector"    column="appoint_inspector"    />
        <result property="allotTime"    column="allot_time"    />
        <result property="actualInspector"    column="actual_inspector"    />
        <result property="actualTime"    column="actual_time"    />
        <result property="remarks"    column="remarks"    />
jianqian's avatar
jianqian committed
20
        <result property="address"    column="address"    />
21 22 23 24 25 26 27
    </resultMap>

    <select id="getWorkOrderId" resultType="String">
        select nextval('seq_work_order_id') as id
    </select>

    <sql id="selectTWorkOrderVo">
王晓倩's avatar
王晓倩 committed
28
        select t.order_id, t.order_type, t.resource_id, t.order_name, t.order_status, t.archiving, t.update_time, t.appoint_inspector, t.allot_time, t.actual_inspector, t.actual_time, t.remarks
29 30
        from t_work_order t
        left join sys_user s on t.appoint_inspector = s.user_id
31 32
    </sql>

33
    <select id="selectTWorkOrderList" parameterType="TWorkOrderForm" resultMap="TWorkOrderResult">
34
        <include refid="selectTWorkOrderVo"/>
35 36 37 38 39 40 41 42 43
        <where>
            <if test="orderId != null  and orderId != ''"> and t.order_id like concat('%',#{orderId},'%')</if>
            <if test="orderType != null  and orderType != ''"> and t.order_type = #{orderType}</if>
            <if test="orderName != null  and orderName != ''"> and t.order_name like concat('%', #{orderName}, '%')</if>
            <if test="orderStatus != null  and orderStatus != ''"> and t.order_status = #{orderStatus}</if>
            <if test="appointInspector != null "> and t.appoint_inspector = #{appointInspector}</if>
            <if test="startAllotTime != null "> and t.allot_time &gt;= #{startAllotTime}</if>
            <if test="endAllotTime != null "> and t.allot_time &lt;= #{endAllotTime}</if>
            <if test="userName != null  and userName != ''"> and s.user_name = #{userName}</if>
44
        </where>
45
        order by t.allot_time desc
46
    </select>
jianqian's avatar
jianqian committed
47 48 49 50 51 52 53
    <select id="selectWaitingWorkOrder" resultMap="TWorkOrderResult">
        SELECT o.*,IF(o.`order_type`=1,IFNULL(p.`address`,""),IFNULL(t.`address`,"")) AS address FROM t_work_order o
        LEFT JOIN t_hidden_trouble t ON t.trouble_id = o.resource_id
        LEFT JOIN t_inspection_plan p ON p.plan_id = o.resource_id
        WHERE
        <choose>
            <when test="type==1">
jianqian's avatar
jianqian committed
54 55 56 57 58 59 60 61 62 63 64
                <choose>
                    <when test="waitingtype==0">
                        o.order_status &lt; 2
                    </when>
                    <when test="waitingtype==1">
                        o.order_status = 0
                    </when>
                    <otherwise>
                        o.order_status = 1
                    </otherwise>
                </choose>
jianqian's avatar
jianqian committed
65 66
            </when>
            <otherwise>
jianqian's avatar
jianqian committed
67
                 o.order_status = #{waitingtype}
jianqian's avatar
jianqian committed
68 69
            </otherwise>
        </choose>
jianqian's avatar
jianqian committed
70 71 72
        <if test="searchStr!=null and searchStr!=''">
            AND o.order_name LIKE concat('%',#{searchStr},'%')
        </if>
jianqian's avatar
jianqian committed
73 74 75
        and (o.appoint_inspector is null  OR o.appoint_inspector = #{userId})
        order by o.allot_time desc
    </select>
76 77
    <select id="selectTWorkOrderById" parameterType="String" resultMap="TWorkOrderResult">
        <include refid="selectTWorkOrderVo"/>
78
        where t.order_id = #{orderId}
79 80 81 82 83 84 85 86 87 88
    </select>
        
    <insert id="insertTWorkOrder" parameterType="TWorkOrder">
        insert into t_work_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderId != null">order_id,</if>
            <if test="orderType != null">order_type,</if>
            <if test="resourceId != null">resource_id,</if>
            <if test="orderName != null">order_name,</if>
            <if test="orderStatus != null">order_status,</if>
王晓倩's avatar
王晓倩 committed
89
            <if test="archiving != null">archiving,</if>
王晓倩's avatar
王晓倩 committed
90
            <if test="updateTime != null">update_time,</if>
91 92 93 94 95 96 97 98 99 100 101 102
            <if test="appointInspector != null">appoint_inspector,</if>
            <if test="allotTime != null">allot_time,</if>
            <if test="actualInspector != null">actual_inspector,</if>
            <if test="actualTime != null">actual_time,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderId != null">#{orderId},</if>
            <if test="orderType != null">#{orderType},</if>
            <if test="resourceId != null">#{resourceId},</if>
            <if test="orderName != null">#{orderName},</if>
            <if test="orderStatus != null">#{orderStatus},</if>
王晓倩's avatar
王晓倩 committed
103
            <if test="archiving != null">#{archiving},</if>
王晓倩's avatar
王晓倩 committed
104
            <if test="updateTime != null">#{updateTime},</if>
105 106 107 108 109 110 111 112 113 114 115 116 117 118
            <if test="appointInspector != null">#{appointInspector},</if>
            <if test="allotTime != null">#{allotTime},</if>
            <if test="actualInspector != null">#{actualInspector},</if>
            <if test="actualTime != null">#{actualTime},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTWorkOrder" parameterType="TWorkOrder">
        update t_work_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderType != null">order_type = #{orderType},</if>
            <if test="orderName != null">order_name = #{orderName},</if>
            <if test="orderStatus != null">order_status = #{orderStatus},</if>
王晓倩's avatar
王晓倩 committed
119
            <if test="archiving != null">archiving = #{archiving},</if>
王晓倩's avatar
王晓倩 committed
120
            <if test="updateTime != null">update_time = #{updateTime},</if>
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
            <if test="appointInspector != null">appoint_inspector = #{appointInspector},</if>
            <if test="allotTime != null">allot_time = #{allotTime},</if>
            <if test="actualInspector != null">actual_inspector = #{actualInspector},</if>
            <if test="actualTime != null">actual_time = #{actualTime},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where order_id = #{orderId}
    </update>

    <delete id="deleteTWorkOrderById" parameterType="String">
        delete from t_work_order where order_id = #{orderId}
    </delete>

    <delete id="deleteTWorkOrderByIds" parameterType="String">
        delete from t_work_order where order_id in 
        <foreach item="orderId" collection="array" open="(" separator="," close=")">
            #{orderId}
        </foreach>
    </delete>
jianqian's avatar
jianqian committed
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
    <select id="orderdtail" resultType="com.zehong.system.domain.TWorkOrder">
        SELECT t.*,
        <choose>
            <when test='type=="3"'>
                p.device_addr as address,
            </when>
            <otherwise>
                p.address AS address,
            </otherwise>
        </choose>
        <choose>
            <when test='type=="1"'>
                "" as longitude,
            </when>
            <otherwise>
                p.longitude as longitude,
            </otherwise>
        </choose>
        <choose>
            <when test='type=="1"'>
jianqian's avatar
jianqian committed
160
                "" as latitude,
jianqian's avatar
jianqian committed
161 162
            </when>
            <otherwise>
jianqian's avatar
jianqian committed
163 164 165 166 167 168 169 170 171
                p.latitude as latitude,
            </otherwise>
        </choose>
        <choose>
            <when test='type!="2"'>
                "" as pictureUrl
            </when>
            <otherwise>
                p.picture_url as pictureUrl
jianqian's avatar
jianqian committed
172 173 174
            </otherwise>
        </choose>
        FROM (SELECT order_id as orderId,order_name as orderName,order_type as orderType,
jianqian's avatar
jianqian committed
175
        order_status as orderStatus,allot_time as allotTime,remarks,resource_id as resourceId
jianqian's avatar
jianqian committed
176 177 178
        FROM t_work_order WHERE order_id=#{orderId})t
        <choose>
            <when test='type=="1"'>
jianqian's avatar
jianqian committed
179
                LEFT JOIN t_inspection_plan p ON p.plan_id = t.resourceId
jianqian's avatar
jianqian committed
180 181
            </when>
            <when test='type=="2"'>
jianqian's avatar
jianqian committed
182
                LEFT JOIN t_hidden_trouble p ON p.trouble_id = t.resourceId
jianqian's avatar
jianqian committed
183 184
            </when>
            <otherwise>
jianqian's avatar
jianqian committed
185
                LEFT JOIN t_device_alarm  a ON a.alarm_id = t.resourceId
jianqian's avatar
jianqian committed
186 187 188 189 190
                LEFT JOIN t_device_info p ON p.device_id = a.`device_id`
            </otherwise>
        </choose>

    </select>
191
</mapper>