<?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.system.mapper.WorkOrderInfoMapper">
    
    <resultMap type="WorkOrderInfo" id="WorkOrderInfoResult">
        <result property="orderId"    column="order_id"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="unitName"    column="unit_name"    />
        <result property="provinceId"    column="province_id"    />
        <result property="province"    column="province"    />
        <result property="cityId"    column="city_id"    />
        <result property="city"    column="city"    />
        <result property="regionId"    column="region_id"    />
        <result property="region"    column="region"    />
        <result property="detailedAddress"    column="detailed_address"    />
        <result property="lon"    column="lon"    />
        <result property="lat"    column="lat"    />
        <result property="personName"    column="person_name"    />
        <result property="phonenumber"    column="phonenumber"    />
        <result property="sex"    column="sex"    />
        <result property="type"    column="type"    />
        <result property="demand"    column="demand"    />
        <result property="isSignature"    column="is_signature"    />
        <result property="evaluation"    column="evaluation"    />
        <result property="evaluationContent"    column="evaluation_content"    />
        <result property="serviceProgress"    column="service_progress"    />
        <result property="serviceType"    column="service_type"    />
        <result property="orderPlacement"    column="order_placement"    />
        <result property="agency"    column="agency"    />
        <result property="responsibleId"    column="responsible_id"    />
        <result property="responsibleName"    column="responsible_name"    />
        <result property="responsiblePhone"    column="responsible_phone"    />
        <result property="takeTime"    column="take_time"    />
        <result property="projectName"    column="project_name"    />
        <result property="shelfLife"    column="shelf_life"    />
        <result property="isCharge"    column="is_charge"    />
        <result property="totalCost"    column="total_cost"    />
        <result property="totalCostDx"    column="total_cost_dx"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectWorkOrderInfoVo">
        select order_id,user_id,user_name, unit_name, province_id, province, city_id, city, region_id, region, detailed_address, lon, lat, person_name, phonenumber, sex, type, demand, is_signature, evaluation, evaluation_content, service_progress,service_type, order_placement,agency, responsible_id, responsible_name,responsible_phone,take_time, project_name, shelf_life, is_charge, total_cost, total_cost_dx, del_flag, create_by, create_time, update_by, update_time, remark from work_order_info
    </sql>

    <select id="selectWorkOrderInfoList" parameterType="WorkOrderInfo" resultMap="WorkOrderInfoResult">
        <include refid="selectWorkOrderInfoVo"/>
        <where>
            <if test="userId != null  and userId != ''"> and user_id = #{userId}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="unitName != null  and unitName != ''"> and unit_name like concat('%', #{unitName}, '%')</if>
            <if test="provinceId != null  and provinceId != ''"> and province_id = #{provinceId}</if>
            <if test="province != null  and province != ''"> and province = #{province}</if>
            <if test="cityId != null  and cityId != ''"> and city_id = #{cityId}</if>
            <if test="city != null  and city != ''"> and city = #{city}</if>
            <if test="regionId != null  and regionId != ''"> and region_id = #{regionId}</if>
            <if test="region != null  and region != ''"> and region = #{region}</if>
            <if test="detailedAddress != null  and detailedAddress != ''"> and detailed_address = #{detailedAddress}</if>
            <if test="lon != null  and lon != ''"> and lon = #{lon}</if>
            <if test="lat != null  and lat != ''"> and lat = #{lat}</if>
            <if test="personName != null  and personName != ''"> and person_name like concat('%', #{personName}, '%')</if>
            <if test="phonenumber != null  and phonenumber != ''"> and phonenumber like concat('%', #{phonenumber}, '%')</if>
            <if test="sex != null  and sex != ''"> and sex = #{sex}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="demand != null  and demand != ''"> and demand = #{demand}</if>
            <if test="isSignature != null  and isSignature != ''"> and is_signature = #{isSignature}</if>
            <if test="evaluation != null  and evaluation != ''"> and evaluation = #{evaluation}</if>
            <if test="evaluationContent != null  and evaluationContent != ''"> and evaluation_content = #{evaluationContent}</if>
            <if test="serviceProgress != null  and serviceProgress != ''"> and service_progress = #{serviceProgress}</if>
            <if test="serviceType != null  and serviceType != ''"> and service_type = #{serviceType}</if>
            <if test="orderPlacement != null  and orderPlacement != ''"> and order_placement = #{orderPlacement}</if>
            <if test="agency != null  and agency != ''"> and agency = #{agency}</if>
            <if test="responsibleId != null "> and responsible_id = #{responsibleId}</if>
            <if test="responsibleName != null  and responsibleName != ''"> and responsible_name like concat('%', #{responsibleName}, '%')</if>
            <if test="responsiblePhone != null  and responsiblePhone != ''"> and responsible_phone = #like concat('%', #{responsiblePhone}, '%')</if>
            <if test="projectName != null  and projectName != ''"> and project_name like concat('%', #{projectName}, '%')</if>
            <if test="shelfLife != null  and shelfLife != ''"> and shelf_life = #{shelfLife}</if>
            <if test="isCharge != null  and isCharge != ''"> and is_charge = #{isCharge}</if>
            <if test="totalCost != null  and totalCost != ''"> and total_cost = #{totalCost}</if>
            <if test="totalCostDx != null  and totalCostDx != ''"> and total_cost_dx = #{totalCostDx}</if>
            <if test="delFlag != null  and delFlag != ''"> and del_flag = #{delFlag}</if>
            <if test="createTime != null and createTime != ''"><!-- 开始时间检索 -->
                and date_format(create_time,'%Y%m%d') = date_format(#{createTime},'%Y%m%d')
            </if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectWorkOrderInfoByOrderId" parameterType="String" resultMap="WorkOrderInfoResult">
        <include refid="selectWorkOrderInfoVo"/>
        where order_id = #{orderId}
    </select>

    <select id="selectWorkOrderInfoListBymonth" parameterType="WorkOrderInfo" resultMap="WorkOrderInfoResult">
        <include refid="selectWorkOrderInfoVo"/>
        where date_format(create_time,'%Y%m') = date_format(#{month},'%Y%m') and del_flag = 'N'
    </select>
    <select id="selectWorkOrderInfoListByTime" parameterType="WorkOrderInfo" resultMap="WorkOrderInfoResult">
        <include refid="selectWorkOrderInfoVo"/>
        where take_time &gt;= #{startDate}
        and take_time &lt;= #{endDate}
        and responsible_id = #{userId}
        and order_placement is not null
    </select>
    <select id="selectWorkOrderInfoListBymonthOne" parameterType="WorkOrderInfo" resultMap="WorkOrderInfoResult">
        <include refid="selectWorkOrderInfoVo"/>
        where date_format(create_time,'%Y%m') = date_format(#{month},'%Y%m') and del_flag = 'N' and responsible_id is not null
    </select>
    <select id="selectWorkOrderInfoListByYearOne" parameterType="WorkOrderInfo" resultMap="WorkOrderInfoResult">
        <include refid="selectWorkOrderInfoVo"/>
        where date_format(create_time,'%Y') = date_format(#{year},'%Y') and del_flag = 'N' and responsible_id is not null
    </select>
    <select id="selectWorkOrderInfoListByYear" parameterType="WorkOrderInfo" resultMap="WorkOrderInfoResult">
        <include refid="selectWorkOrderInfoVo"/>
        where date_format(create_time,'%Y') = date_format(#{year},'%Y') and del_flag = 'N'
        <if test="userId != null and userId !=0"> and responsible_id = #{userId}</if>
    </select>

    <select id="selectWorkOrderInfoListByUserList" parameterType="WorkOrderInfo" resultMap="WorkOrderInfoResult">
        <include refid="selectWorkOrderInfoVo"/>
        where date_format(create_time,'%Y') = date_format(#{year},'%Y') and del_flag = 'N'
        and responsible_id in
        <foreach item="userId" index="index" collection="userIds" open="(" separator="," close=")">
            #{userId}
        </foreach>
    </select>

    <insert id="insertWorkOrderInfo" parameterType="WorkOrderInfo">
        insert into work_order_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderId != null">order_id,</if>
            <if test="userId != null  ">user_id,</if>
            <if test="userName != null ">user_name,</if>
            <if test="unitName != null">unit_name,</if>
            <if test="provinceId != null">province_id,</if>
            <if test="province != null">province,</if>
            <if test="cityId != null">city_id,</if>
            <if test="city != null">city,</if>
            <if test="regionId != null">region_id,</if>
            <if test="region != null">region,</if>
            <if test="detailedAddress != null">detailed_address,</if>
            <if test="lon != null">lon,</if>
            <if test="lat != null">lat,</if>
            <if test="personName != null">person_name,</if>
            <if test="phonenumber != null">phonenumber,</if>
            <if test="sex != null">sex,</if>
            <if test="type != null">type,</if>
            <if test="demand != null">demand,</if>
            <if test="isSignature != null">is_signature,</if>
            <if test="evaluation != null">evaluation,</if>
            <if test="evaluationContent != null">evaluation_content,</if>
            <if test="serviceProgress != null">service_progress,</if>
            <if test="serviceType != null "> service_type,</if>
            <if test="orderPlacement != null">order_placement,</if>
            <if test="agency != null  ">agency,</if>
            <if test="responsibleId != null">responsible_id,</if>
            <if test="responsibleName != null">responsible_name,</if>
            <if test="responsiblePhone != null">responsible_phone,</if>
            <if test="takeTime != null">take_time,</if>
            <if test="projectName != null">project_name,</if>
            <if test="shelfLife != null">shelf_life,</if>
            <if test="isCharge != null">is_charge,</if>
            <if test="totalCost != null">total_cost,</if>
            <if test="totalCostDx != null">total_cost_dx,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderId != null">#{orderId},</if>
            <if test="userId != null  ">#{userId},</if>
            <if test="userName != null  ">#{userName},</if>
            <if test="unitName != null">#{unitName},</if>
            <if test="provinceId != null">#{provinceId},</if>
            <if test="province != null">#{province},</if>
            <if test="cityId != null">#{cityId},</if>
            <if test="city != null">#{city},</if>
            <if test="regionId != null">#{regionId},</if>
            <if test="region != null">#{region},</if>
            <if test="detailedAddress != null">#{detailedAddress},</if>
            <if test="lon != null">#{lon},</if>
            <if test="lat != null">#{lat},</if>
            <if test="personName != null">#{personName},</if>
            <if test="phonenumber != null">#{phonenumber},</if>
            <if test="sex != null">#{sex},</if>
            <if test="type != null">#{type},</if>
            <if test="demand != null">#{demand},</if>
            <if test="isSignature != null">#{isSignature},</if>
            <if test="evaluation != null">#{evaluation},</if>
            <if test="evaluationContent != null">#{evaluationContent},</if>
            <if test="serviceProgress != null">#{serviceProgress},</if>
            <if test="serviceType != null "> #{serviceType},</if>
            <if test="orderPlacement != null">#{orderPlacement},</if>
            <if test="agency != null  ">#{agency},</if>
            <if test="responsibleId != null">#{responsibleId},</if>
            <if test="responsibleName != null">#{responsibleName},</if>
            <if test="responsiblePhone != null">#{responsiblePhone},</if>
            <if test="takeTime != null">#{takeTime},</if>
            <if test="projectName != null">#{projectName},</if>
            <if test="shelfLife != null">#{shelfLife},</if>
            <if test="isCharge != null">#{isCharge},</if>
            <if test="totalCost != null">#{totalCost},</if>
            <if test="totalCostDx != null">#{totalCostDx},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateWorkOrderInfo" parameterType="WorkOrderInfo">
        update work_order_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null  "> user_id = #{userId},</if>
            <if test="userName != null  ">user_name = #{userName},</if>
            <if test="unitName != null">unit_name = #{unitName},</if>
            <if test="provinceId != null">province_id = #{provinceId},</if>
            <if test="province != null">province = #{province},</if>
            <if test="cityId != null">city_id = #{cityId},</if>
            <if test="city != null">city = #{city},</if>
            <if test="regionId != null">region_id = #{regionId},</if>
            <if test="region != null">region = #{region},</if>
            <if test="detailedAddress != null">detailed_address = #{detailedAddress},</if>
            <if test="lon != null">lon = #{lon},</if>
            <if test="lat != null">lat = #{lat},</if>
            <if test="personName != null">person_name = #{personName},</if>
            <if test="phonenumber != null">phonenumber = #{phonenumber},</if>
            <if test="sex != null">sex = #{sex},</if>
            <if test="type != null">type = #{type},</if>
            <if test="demand != null">demand = #{demand},</if>
            <if test="isSignature != null">is_signature = #{isSignature},</if>
            <if test="evaluation != null">evaluation = #{evaluation},</if>
            <if test="evaluationContent != null">evaluation_content = #{evaluationContent},</if>
            <if test="serviceProgress != null">service_progress = #{serviceProgress},</if>
            <if test="serviceType != null ">service_type = #{serviceType},</if>
            <if test="orderPlacement != null">order_placement = #{orderPlacement},</if>
            <if test="agency != null  "> agency = #{agency},</if>
            <if test="responsibleId != null">responsible_id = #{responsibleId},</if>
            <if test="responsibleName != null">responsible_name = #{responsibleName},</if>
            <if test="responsiblePhone != null">responsible_phone = #{responsiblePhone},</if>
            <if test="takeTime != null">take_time = #{takeTime},</if>
            <if test="projectName != null">project_name = #{projectName},</if>
            <if test="shelfLife != null">shelf_life = #{shelfLife},</if>
            <if test="isCharge != null">is_charge = #{isCharge},</if>
            <if test="totalCost != null">total_cost = #{totalCost},</if>
            <if test="totalCostDx != null">total_cost_dx = #{totalCostDx},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where order_id = #{orderId}
    </update>

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

    <delete id="deleteWorkOrderInfoByOrderIds" parameterType="String">
        delete from work_order_info where order_id in 
        <foreach item="orderId" collection="array" open="(" separator="," close=")">
            #{orderId}
        </foreach>
    </delete>
</mapper>