<?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.cool.store.mapper.DecorationMeasureMapper">
    <resultMap id="BaseResultMap" type="com.cool.store.entity.DecorationMeasureDO">
        <!--
          WARNING - @mbg.generated
        -->
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="shop_id" jdbcType="BIGINT" property="shopId"/>
        <result column="measure_user_id" jdbcType="VARCHAR" property="measureUserId"/>
        <result column="design_user_id" jdbcType="VARCHAR" property="designUserId"/>
        <result column="measure_date" jdbcType="TIMESTAMP" property="measureDate"/>
        <result column="diagram_date" jdbcType="TIMESTAMP" property="diagramDate"/>
        <result column="measure_url" jdbcType="VARCHAR" property="measureUrl"/>
        <result column="remark" jdbcType="VARCHAR" property="remark"/>
        <result column="submit_time" jdbcType="TIMESTAMP" property="submitTime"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="deleted" jdbcType="BIT" property="deleted"/>
        <result column="create_user_id" jdbcType="VARCHAR" property="createUserId"/>
        <result column="update_user_id" jdbcType="VARCHAR" property="updateUserId"/>
        <result column="measurement_sheet_id" jdbcType="VARCHAR" property="measurementSheetId"/>
        <result column="measure_user_name" jdbcType="VARCHAR" property="measureUserName"/>
        <result column="design_leader_name" jdbcType="VARCHAR" property="designLeaderName"/>
    </resultMap>

    <select id="selectByShopId" resultMap="BaseResultMap">
        select *
        from xfsg_decoration_measure where shop_id = #{shopId} and deleted = 0
    </select>
    <select id="selectByMeasureUserIdAndShopStage"
            resultType="com.cool.store.vo.desk.PreparationCommonPendingVO">

        select
        c.shop_name as storeName,
        c.shop_code as ShopCode,
        c.detail_address as shopAddress,
        c.investment_manager as investmentManagerId,
        c.id as shopId,
        c.line_id as lineId,
        c.region_id as regionId,
        c.join_mode as joinMode,
        c.store_type as storeType,
        b.shop_stage as stage,
        b.shop_sub_stage as subStage,
        b.shop_sub_stage_status as subStageStatus,
        b.update_time as updateTime

        from xfsg_decoration_measure a
        left join xfsg_shop_stage_info b on a.shop_id = b.shop_id
        left join xfsg_shop_info c on a.shop_id = c.id
        <if test="request.signTypes !=null and request.signTypes.size()>0">
            left join xfsg_sign_franchise sign on a.shop_id = sign.shop_id
        </if>
        where a.measure_user_id = #{measureUserId}
        and b.shop_sub_stage_status = 892
        and c.deleted = 0
        and c.shop_status !=2
        <if test="request.stageStatus !=null and request.stageStatus.size() >0">
            and b.shop_sub_stage_status in
            <foreach collection="request.stageStatus" item="item" index="index" open="(" separator=","
                     close=")">
                #{item}
            </foreach>
        </if>
        <if test="request.shopKeyword !=null and request.shopKeyword !=''">
            and (c.shop_name like concat('%',#{request.shopKeyword},'%') or c.shop_code like concat('%',#{request.shopKeyword},'%'))
        </if>
        <if test="request.regionIds !=null and request.regionIds.size()>0">
            and c.region_id in
            <foreach collection="request.regionIds" item="regionId" index="index" open="(" separator="," close=")">
                #{regionId}
            </foreach>
        </if>
        <if test="request.storeTypes !=null and request.storeTypes.size()>0">
            and c.store_type in
            <foreach collection="request.storeTypes" item="storeType" index="index" open="(" separator="," close=")">
                #{storeType}
            </foreach>
        </if>
        <if test="request.signTypes !=null and request.signTypes.size()>0">
            and sign.sign_type in
            <foreach collection="request.signTypes" item="signType" index="index" open="(" separator="," close=")">
                #{signType}
            </foreach>
        </if>
        <if test="request.supervisorId != null and request.supervisorId!= ''">
            and c.investment_manager = #{request.supervisorId}
        </if>
        <if test="request.joinModes !=null and request.joinModes.size()>0">
            and c.join_mode in
            <foreach collection="request.joinModes" item="joinMode" index="index" open="(" separator="," close=")">
                #{joinMode}
            </foreach>
        </if>
        order by b.update_time desc
    </select>
    <select id="getShopIdListByDesignUserIdAndShopStage"    resultType="com.cool.store.vo.desk.PreparationCommonPendingVO">
        select
        c.shop_name as storeName,
        c.shop_code as ShopCode,
        c.detail_address as shopAddress,
        c.investment_manager as investmentManagerId,
        c.id as shopId,
        c.line_id as lineId,
        c.region_id as regionId,
        c.store_type as storeType,
        c.join_mode as joinMode,
        b.shop_stage as stage,
        b.shop_sub_stage as subStage,
        b.shop_sub_stage_status as subStageStatus,
        b.update_time as updateTime

        from xfsg_decoration_measure a
        left join xfsg_shop_stage_info b on a.shop_id = b.shop_id
        left join xfsg_shop_info c on a.shop_id = c.id
        <if test="request.signTypes !=null and request.signTypes.size()>0">
            left join xfsg_sign_franchise sign on a.shop_id = sign.shop_id
        </if>
        where a.design_user_id = #{userId}
        and b.shop_sub_stage_status = 900
        and c.deleted = 0
        and c.shop_status !=2
        <if test="request.stageStatus !=null and request.stageStatus.size() >0">
            and b.shop_sub_stage_status in
            <foreach collection="request.stageStatus" item="item" index="index" open="(" separator=","
                     close=")">
                #{item}
            </foreach>
        </if>
        <if test="request.shopKeyword !=null and request.shopKeyword !=''">
            and (c.shop_name like concat('%',#{request.shopKeyword},'%') or c.shop_code like concat('%',#{request.shopKeyword},'%'))
        </if>
        <if test="request.regionIds !=null and request.regionIds.size()>0">
            and c.region_id in
            <foreach collection="request.regionIds" item="regionId" index="index" open="(" separator="," close=")">
                #{regionId}
            </foreach>
        </if>
        <if test="request.storeTypes !=null and request.storeTypes.size()>0">
            and c.store_type in
            <foreach collection="request.storeTypes" item="storeType" index="index" open="(" separator="," close=")">
                #{storeType}
            </foreach>
        </if>
        <if test="request.signTypes !=null and request.signTypes.size()>0">
            and sign.sign_type in
            <foreach collection="request.signTypes" item="signType" index="index" open="(" separator="," close=")">
                #{signType}
            </foreach>
        </if>
        <if test="request.supervisorId != null and request.supervisorId!= ''">
            and c.investment_manager = #{request.supervisorId}
        </if>
        <if test="request.joinModes !=null and request.joinModes.size()>0">
            and c.join_mode in
            <foreach collection="request.joinModes" item="joinMode" index="index" open="(" separator="," close=")">
                #{joinMode}
            </foreach>
        </if>
        order by b.update_time desc
    </select>
    <select id="getShopIdListByDesignUserIdOrQuotationAndShopStage" resultType="com.cool.store.vo.desk.PreparationCommonPendingVO">
        select
        c.shop_name as storeName,
        c.shop_code as ShopCode,
        c.detail_address as shopAddress,
        c.investment_manager as investmentManagerId,
        c.id as shopId,
        c.line_id as lineId,
        c.region_id as regionId,
        c.store_type as storeType,
        c.join_mode as joinMode,
        b.shop_stage as stage,
        b.shop_sub_stage as subStage,
        b.shop_sub_stage_status as subStageStatus,
        b.update_time as updateTime

        from xfsg_decoration_measure a
        left join xfsg_shop_stage_info b on a.shop_id = b.shop_id
        left join xfsg_shop_info c on a.shop_id = c.id
        left join xfsg_decoration_design_info d on a.shop_id = d.shop_id
        <if test="request.signTypes !=null and request.signTypes.size()>0">
            left join xfsg_sign_franchise sign on a.shop_id = sign.shop_id
        </if>
        where
         ((b.shop_sub_stage_status = 900 and a.design_user_id = #{userId}) or (b.shop_sub_stage_status = 901 and d.design_user_id = #{userId}))
        and c.deleted = 0     and c.shop_status !=2
        <if test="request.stageStatus !=null and request.stageStatus.size() >0">
            and b.shop_sub_stage_status in
            <foreach collection="request.stageStatus" item="item" index="index" open="(" separator=","
                     close=")">
                #{item}
            </foreach>
        </if>
        <if test="request.shopKeyword !=null and request.shopKeyword !=''">
            and (c.shop_name like concat('%',#{request.shopKeyword},'%') or c.shop_code like concat('%',#{request.shopKeyword},'%'))
        </if>
        <if test="request.regionIds !=null and request.regionIds.size()>0">
            and c.region_id in
            <foreach collection="request.regionIds" item="regionId" index="index" open="(" separator="," close=")">
                #{regionId}
            </foreach>
        </if>
        <if test="request.storeTypes !=null and request.storeTypes.size()>0">
            and c.store_type in
            <foreach collection="request.storeTypes" item="storeType" index="index" open="(" separator="," close=")">
                #{storeType}
            </foreach>
        </if>
        <if test="request.signTypes !=null and request.signTypes.size()>0">
            and sign.sign_type in
            <foreach collection="request.signTypes" item="signType" index="index" open="(" separator="," close=")">
                #{signType}
            </foreach>
        </if>
        <if test="request.supervisorId != null and request.supervisorId!= ''">
            and c.investment_manager = #{request.supervisorId}
        </if>
        <if test="request.joinModes !=null and request.joinModes.size()>0">
            and c.join_mode in
            <foreach collection="request.joinModes" item="joinMode" index="index" open="(" separator="," close=")">
                #{joinMode}
            </foreach>
        </if>
        order by b.update_time desc

    </select>


</mapper>