<?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.mmc.csf.release.dao.TaskDao">
    <insert id="insertOrderTask"  useGeneratedKeys="true"
            keyProperty="id" parameterType="com.mmc.csf.release.entity.TaskOrderDO">
        insert into task_order
        (user_account_id, inspection_id, order_no, order_name, task_address,
         start_time, end_time, order_status, lon, lat,image_url)
        values (#{userAccountId}, #{inspectionId}, #{orderNo}, #{orderName}, #{taskAddress},
                #{startTime}, #{endTime}, #{orderStatus}, #{lon}, #{lat},#{imageUrl})
    </insert>

    <select id="countTaskServiceList" resultType="java.lang.Integer">
        SELECT
        count(*)
        FROM
        industry ind
        INNER JOIN industry_inspection ii ON ind.id = ii.industry_id
        INNER JOIN inspection ins ON ii.inspection_id = ins.id
        <where>
            and ins.is_del = 0
            <if test="inspectionName != null">
                and ins.name like concat('%',#{inspectionName},'%')
            </if>
            <if test="industryId != null">
                and ii.industry_id = #{industryId}
            </if>
            <if test="appTypeId != null">
                and ins.app_type_id = #{appTypeId}
            </if>
        </where>
    </select>
    <select id="listPageTaskService" resultType="com.mmc.csf.release.entity.InspectionDO">
        SELECT
        ins.`name`,
        ins.id,
        ins.price
        FROM
        industry ind
        INNER JOIN industry_inspection ii ON ind.id = ii.industry_id
        INNER JOIN inspection ins ON ii.inspection_id = ins.id
        <where>
            and ins.is_del = 0
            <if test="inspectionName != null">
                and ins.name like concat('%',#{inspectionName},'%')
            </if>
            <if test="industryId != null">
                and ii.industry_id = #{industryId}
            </if>
            <if test="appTypeId != null">
                and ins.app_type_id = #{appTypeId}
            </if>
        </where>
        ORDER BY ins.add_time desc
        LIMIT #{pageNo},#{pageSize}
    </select>
    <select id="selectInspectionById" resultType="com.mmc.csf.release.entity.InspectionDO">
        select `name`,
               id,
               video,
               image
        from inspection
        where id = #{id}
    </select>
    <select id="getIndustryAndInspect" resultType="java.lang.Integer">
        select count(*)
        from industry_inspection
        where industry_id = #{industryId}
          and inspection_id = #{inspectionId}
    </select>
    <select id="getInspectionById" resultType="com.mmc.csf.release.entity.InspectionDO">
        select i.id,
               i.name,
               i.service_type,
               i.limit_active,
               i.work_type_id,
               i.light_spot,
               i.number,
               i.video,
               i.image,
               i.sort,
               i.is_shelf,
               i.content,
               i.order_num,
               i.is_del,
               i.fake_num,
               i.card_img,
               i.is_show_code
        from inspection i
        where i.is_del = 0
          and i.id = #{id}
        order by i.sort
                ASC
    </select>
    <select id="getEvaluateInfoList" resultType="com.mmc.csf.release.entity.InspComtDO">
        SELECT id,
               content,
               content_imgs,
               content_video,
               star,
               `type`,
               create_time
        FROM insp_comt
        ORDER BY RAND() LIMIT #{size}
    </select>

    <select id="listAllIndustry" resultType="com.mmc.csf.release.entity.IndustryDO">
        select
        i.id,i.name,i.short_name,i.industry_type,i.number,i.propagate1,i.propagate2,i.image,i.video,i.sort,i.is_shelf,i.industry_icon
        from industry i
        <where>
            i.is_del = 0 and is_shelf = 1
        </where>
        order by i.sort ASC
    </select>
    <select id="listAllAppType" resultType="com.mmc.csf.release.entity.AppTypeDO">
        select id,
               app_name,
               create_time
        from app_type
    </select>
    <select id="listAllTaskService" resultType="com.mmc.csf.release.entity.InspectionDO">
        select i.id,
               i.name,
               i.service_type,
               i.limit_active,
               i.work_type_id,
               i.light_spot,
               i.number,
               i.video,
               i.image,
               i.sort,
               i.is_shelf,
               i.content,
               i.order_num,
               i.is_del,
               i.fake_num,
               i.card_img,
               i.is_show_code
        from inspection i
        where i.is_del = 0 and i.is_shelf = 1
    </select>
</mapper>