<?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.OpenAcceptanceInfoMapper">
  <resultMap id="BaseResultMap" type="com.cool.store.entity.OpenAcceptanceInfoDO">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="shop_id" jdbcType="BIGINT" property="shopId" />
    <result column="plan_open_time" jdbcType="TIMESTAMP" property="planOpenTime" />
    <result column="acceptance_status" jdbcType="TINYINT" property="acceptanceStatus" />
    <result column="acceptance_time" jdbcType="TIMESTAMP" property="acceptanceTime" />
    <result column="acceptance_user_id" jdbcType="TIMESTAMP" property="acceptanceUserId" />
    <result column="system_setup" jdbcType="TINYINT" property="systemSetup" />
    <result column="license_processing" jdbcType="TINYINT" property="licenseProcessing" />
    <result column="franchise_fee_deposit" jdbcType="TINYINT" property="franchiseFeeDeposit" />
    <result column="contract_signing" jdbcType="TINYINT" property="contractSigning" />
    <result column="training_registration" jdbcType="TINYINT" property="trainingRegistration" />
    <result column="training_for_franchisee" jdbcType="TINYINT" property="trainingForFranchisee" />
    <result column="store_design" jdbcType="TINYINT" property="storeDesign" />
    <result column="construction" jdbcType="TINYINT" property="construction" />
    <result column="triple_acceptance" jdbcType="TINYINT" property="tripleAcceptance" />
    <result column="visual_acceptance" jdbcType="TINYINT" property="visualAcceptance" />
    <result column="market_planning" jdbcType="TINYINT" property="marketPlanning" />
    <result column="initial_delivery_list" jdbcType="TINYINT" property="initialDeliveryList" />
    <result column="deleted" jdbcType="BIT" property="deleted" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <update id="shopOpenAcceptanceStatusUpdate">
    UPDATE xfsg_shop_stage_info s
    SET shop_sub_stage_status = 1710
    WHERE
      shop_sub_stage_status = 1700
      AND shop_id IN (
      SELECT
        shop_id
      FROM
        xfsg_open_acceptance_info
      WHERE
        acceptance_status = 1
        AND plan_open_time BETWEEN DATE_SUB( NOW( ), INTERVAL 7 DAY )
        AND DATE_SUB( NOW( ), INTERVAL 3 DAY )
    )
  </update>

  <select id="openAcceptanceList" resultType="com.cool.store.vo.OpenAcceptanceInfoListVO">
    SELECT
      o.id AS openAcceptanceInfoId,
      s.id AS shopId,
      s.shop_name AS shopName,
      s.store_num AS storeNum,
      s.shop_manager_user_id AS shopManagerUserId,
      s.supervisor_user_id AS supervisorUserId,
      l.username AS partnerName,
      l.mobile AS partnerMobile,
      l.region_id AS regionId,
      o.plan_open_time AS planOpenTime,
      o.acceptance_status AS acceptanceStatus,
      l.investment_manager AS investmentManager,
      l.acceptance_time AS acceptanceTime,
      o.acceptance_user_id AS acceptanceUserId
    FROM
      xfsg_open_acceptance_info o
        LEFT JOIN xfsg_shop_info s ON o.shop_id = s.id
        LEFT JOIN xfsg_line_info l ON l.id = s.line_id
        <where>
          <if test="openAcceptance.storeName != null and openAcceptance.storeName != ''">
            s.shop_name LIKE CONCAT('%',#{openAcceptance.storeName},'%')
          </if>
          <if test="openAcceptance.supervisorUserId != null and openAcceptance.supervisorUserId != ''">
            s.supervisor_user_id = #{openAcceptance.supervisorUserId}
          </if>
          <if test="openAcceptance.investmentManager != null and openAcceptance.investmentManager != ''">
            l.investment_manager =#{openAcceptance.investmentManager}
          </if>
          <if test="openAcceptance.acceptanceStatus != null">
            o.acceptance_status = #{openAcceptance.acceptanceStatus}
          </if>
          <if test="openAcceptance.planOpenTimeBegin != null">
            AND o.plan_open_time &gt;= #{openAcceptance.planOpenTimeBegin}
          </if>
          <if test="openAcceptance.planOpenTimeEnd != null">
            AND o.plan_open_time &lt;= #{openAcceptance.planOpenTimeEnd}
          </if>
        </where>
  </select>
</mapper>