<?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="cn.iocoder.yudao.module.inspection.mapper.InspectionInfoMapper">

    <resultMap type="cn.iocoder.yudao.module.inspection.entity.InspectionInfo" id="InspectionInfoResult">
        <result property="id"    column="id"    />
        <result property="inspectionOrderId"    column="inspection_order_id"    />
        <result property="workId"    column="work_id"    />
        <result property="workerName"    column="worker_name"    />
        <result property="workerPhone"    column="worker_phone"    />
        <result property="isPass"    column="is_pass"    />
        <result property="status"    column="status"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="year"    column="year"    />
        <result property="month"    column="month"    />
        <result property="day"    column="day"    />
        <result property="createTime"    column="create_time"    />
        <result property="creator"    column="creator"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updater"    column="updater"    />
    </resultMap>

    <sql id="selectInspectionInfoVo">
        select id, inspection_order_id, work_id, worker_name, worker_phone, is_pass, status, start_time, end_time, year, month, day, create_time, creator, update_time, updater from inspection_info
    </sql>

    <select id="selectInspectionInfoList" parameterType="cn.iocoder.yudao.module.inspection.entity.InspectionInfo" resultMap="InspectionInfoResult">
        <include refid="selectInspectionInfoVo"/>
        <where>
            <if test="inspectionOrderId != null "> and inspection_order_id = #{inspectionOrderId}</if>
            <if test="workId != null "> and work_id = #{workId}</if>
            <if test="workerName != null  and workerName != ''"> and worker_name like concat('%', #{workerName}, '%')</if>
            <if test="workerPhone != null  and workerPhone != ''"> and worker_phone = #{workerPhone}</if>
            <if test="isPass != null  and isPass != ''"> and is_pass = #{isPass}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="year != null  and year != ''"> and year = #{year}</if>
            <if test="month != null  and month != ''"> and month = #{month}</if>
            <if test="day != null  and day != ''"> and day = #{day}</if>
        </where>
    </select>

    <select id="selectInspectionInfoById" parameterType="Long" resultMap="InspectionInfoResult">
        <include refid="selectInspectionInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertInspectionInfo" parameterType="cn.iocoder.yudao.module.inspection.entity.InspectionInfo">
        insert into inspection_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="inspectionOrderId != null">inspection_order_id,</if>
            <if test="workId != null">work_id,</if>
            <if test="workerName != null">worker_name,</if>
            <if test="workerPhone != null">worker_phone,</if>
            <if test="isPass != null">is_pass,</if>
            <if test="status != null">status,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="year != null">year,</if>
            <if test="month != null">month,</if>
            <if test="day != null">day,</if>
            <if test="createTime != null">create_time,</if>
            <if test="creator != null">creator,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updater != null">updater,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="inspectionOrderId != null">#{inspectionOrderId},</if>
            <if test="workId != null">#{workId},</if>
            <if test="workerName != null">#{workerName},</if>
            <if test="workerPhone != null">#{workerPhone},</if>
            <if test="isPass != null">#{isPass},</if>
            <if test="status != null">#{status},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="year != null">#{year},</if>
            <if test="month != null">#{month},</if>
            <if test="day != null">#{day},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="creator != null">#{creator},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updater != null">#{updater},</if>
         </trim>
    </insert>

    <update id="updateInspectionInfo" parameterType="cn.iocoder.yudao.module.inspection.entity.InspectionInfo">
        update inspection_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="inspectionOrderId != null">inspection_order_id = #{inspectionOrderId},</if>
            <if test="workId != null">work_id = #{workId},</if>
            <if test="workerName != null">worker_name = #{workerName},</if>
            <if test="workerPhone != null">worker_phone = #{workerPhone},</if>
            <if test="isPass != null">is_pass = #{isPass},</if>
            <if test="status != null">status = #{status},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="year != null">year = #{year},</if>
            <if test="month != null">month = #{month},</if>
            <if test="day != null">day = #{day},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="creator != null">creator = #{creator},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updater != null">updater = #{updater},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteInspectionInfoById" parameterType="Long">
        delete from inspection_info where id = #{id}
    </delete>

    <delete id="deleteInspectionInfoByIds" parameterType="String">
        delete from inspection_info where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <select id="workOrder" resultType="cn.iocoder.yudao.module.inspection.entity.InspectionInfo">
        select ins.*,oi.goods_title,su.nickname as buyName,su.mobile as buyPhone,oi.sku_name,oi.pay_money as realPayMoney
        ,oi.pay_type,oi.order_status as orderStatus,oi.goods_id,oi.sku_id,oi.pay_time,oi.goods_price,ins.create_time
         from inspection_info ins
         left join order_info oi on oi.id = ins.inspection_order_id
         left join system_users su on su.id = ins.user_id
         left join system_user_role sur on sur.user_id = su.id
         where 1=1
        <if test="carNum!=null and carNum!=''">
            and ins.car_num like concat('%',#{carNum},'%')
        </if>
        <if test="goodsTitle!=null and goodsTitle!=''">
            and oi.goods_title like concat('%',#{goodsTitle},'%')
        </if>
        <if test="roleId!=null and roleId!=''">
            and sur.role_id  = #{roleId}
        </if>

        <if test="customerSource!=null and customerSource!=''">
            and ins.customer_source =#{customerSource}
        </if>
        <if test="payType!=null and payType!=''">
            and oi.pay_type  =  #{payType}
        </if>
        <if test="startTime!=null and startTime!=''">
            and ins.start_time between #{startTime} and #{endTime}
        </if>
        order by  ins.start_time desc
    </select>

    <select id="delworkOrder" resultType="cn.iocoder.yudao.module.inspection.entity.InspectionInfo">
        select ins.*,oi.goods_title,su.nickname as buyName,su.mobile as buyPhone,oi.sku_name,oi.pay_money as realPayMoney
        ,oi.pay_type,oi.order_status as orderStatus,oi.goods_id,oi.sku_id,oi.pay_time,oi.goods_price,ins.create_time
        from del_inspection_info ins
        left join del_order_info oi on oi.id = ins.inspection_order_id
        left join system_users su on su.id = ins.user_id
        left join system_user_role sur on sur.user_id = su.id
        where 1=1
        <if test="carNum!=null and carNum!=''">
            and ins.car_num like concat('%',#{carNum},'%')
        </if>
        <if test="goodsTitle!=null and goodsTitle!=''">
            and oi.goods_title like concat('%',#{goodsTitle},'%')
        </if>
        <if test="roleId!=null and roleId!=''">
            and sur.role_id  = #{roleId}
        </if>

        <if test="customerSource!=null and customerSource!=''">
            and ins.customer_source =#{customerSource}
        </if>
        <if test="payType!=null and payType!=''">
            and oi.pay_type  =  #{payType}
        </if>
        <if test="startTime!=null and startTime!=''">
            and ins.start_time between #{startTime} and #{endTime}
        </if>
        order by  ins.start_time desc
    </select>

    <select id="workOrderData" resultType="java.util.Map">
        select ifnull(sum(oi.pay_money),0) as payMoneySum,ifnull(sum(oi.goods_price),0) goodsPriceSum
        from inspection_info ins
        left join order_info oi on oi.id = ins.inspection_order_id
        left join system_users su on su.id = ins.user_id
        left join system_user_role sur on sur.user_id = su.id
        where 1=1
        <if test="carNum!=null and carNum!=''">
            and ins.car_num like concat('%',#{carNum},'%')
        </if>
        <if test="goodsTitle!=null and goodsTitle!=''">
            and oi.goods_title like concat('%',#{goodsTitle},'%')
        </if>
        <if test="roleId!=null and roleId!=''">
            and sur.role_id  = #{roleId}
        </if>

        <if test="customerSource!=null and customerSource!=''">
            and ins.customer_source =#{customerSource}
        </if>
        <if test="payType!=null and payType!=''">
            and oi.pay_type  =  #{payType}
        </if>
        <if test="startTime!=null and startTime!=''">
            and ins.start_time between #{startTime} and #{endTime}
        </if>
    </select>
</mapper>
