<?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.DecorationDesignInfoMapper">
  <resultMap id="BaseResultMap" type="com.cool.store.entity.DecorationDesignInfoDO">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="shop_id" jdbcType="BIGINT" property="shopId" />
    <result column="quotation_url" jdbcType="VARCHAR" property="quotationUrl" />
    <result column="design_url" jdbcType="VARCHAR" property="designUrl" />
    <result column="remark" jdbcType="VARCHAR" property="remark" />
    <result column="partner_acceptance_signatures" jdbcType="VARCHAR" property="partnerAcceptanceSignatures" />
    <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="construction_plan_start_time" jdbcType="TIMESTAMP" property="constructionPlanStartTime" />
    <result column="construction_plan_end_time" jdbcType="TIMESTAMP" property="constructionPlanEndTime" />
    <result column="construction_annex" jdbcType="VARCHAR" property="constructionAnnex" />
    <result column="construction_remark" jdbcType="VARCHAR" property="constructionRemark" />
    <result column="construction_create_time" jdbcType="TIMESTAMP" property="constructionCreateTime" />
    <result column="construction_create_user" jdbcType="VARCHAR" property="constructionCreateUser" />
    <result column="design_leader_id" jdbcType="VARCHAR" property="designLeaderId" />
    <result column="design_user_id" jdbcType="VARCHAR" property="designUserId" />
    <result column="quotation_user_id" jdbcType="VARCHAR" property="quotationUserId" />
    <result column="quotation_remark" jdbcType="VARCHAR" property="quotationRemark" />
    <result column="design_submit_time" jdbcType="TIMESTAMP" property="designSubmitTime" />
    <result column="quotation_submit_time" jdbcType="TIMESTAMP" property="quotationSubmitTime" />
    <result column="design_sheet_id" jdbcType="VARCHAR" property="designSheetId" />
    <result column="design_name" jdbcType="VARCHAR" property="designName" />
    <result column="design_leader_name" jdbcType="VARCHAR" property="designLeaderName" />
    <result column="original_photo_url" jdbcType="VARCHAR" property="originalPhotoUrl" />
    <result column="rendering_url" jdbcType="VARCHAR" property="renderingUrl" />
    <result column="floor_plan_url" jdbcType="VARCHAR" property="floorPlanUrl" />
    <result column="quotation_sheet_id" jdbcType="VARCHAR" property="quotationSheetId" />
    <result column="quoter" jdbcType="VARCHAR" property="quoter" />
    <result column="construction_order_id" jdbcType="VARCHAR" property="constructionOrderId" />
    <result column="actual_entry_time" jdbcType="TIMESTAMP" property="actualEntryTime" />
  </resultMap>
    <update id="updateDesignLeaderIdAndDesignUserIdInteger">
      update xfsg_decoration_design_info
      set design_leader_id = #{designLeaderId},
      design_user_id = null
      where shop_id = #{shopId}
    </update>
  <update id="updateDesignUserId">
    update xfsg_decoration_design_info
    set design_user_id = #{designUserId}
    where shop_id = #{shopId}
  </update>

  <select id="selectByShopId" resultMap="BaseResultMap">
    select
    *
    from xfsg_decoration_design_info where shop_id = #{shopId} and deleted = 0
  </select>
  <select id="getByDesignUserIdAndShopStage" 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_design_info 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 = 901
    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>