<?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.PreFryQualificationApplyMapper">
  <resultMap id="BaseResultMap" type="com.cool.store.entity.PreFryQualificationApplyDO">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="apply_code" jdbcType="VARCHAR" property="applyCode" />
    <result column="store_code" jdbcType="VARCHAR" property="storeCode" />
    <result column="apply_type" jdbcType="TINYINT" property="applyType" />
    <result column="refrigerator_photo" jdbcType="VARCHAR" property="refrigeratorPhoto" />
    <result column="refrigerator_plate_photo" jdbcType="VARCHAR" property="refrigeratorPlatePhoto" />
    <result column="protective_cover_photo" jdbcType="VARCHAR" property="protectiveCoverPhoto" />
    <result column="cold_storage_box_photo" jdbcType="VARCHAR" property="coldStorageBoxPhoto" />
    <result column="audit_status" jdbcType="TINYINT" property="auditStatus" />
    <result column="created_time" jdbcType="TIMESTAMP" property="createdTime" />
    <result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime" />
    <result column="created_user_id" jdbcType="VARCHAR" property="createdUserId" />
  </resultMap>


  <update id="updateForce" parameterType="com.cool.store.entity.PreFryQualificationApplyDO">
    UPDATE xfsg_pre_fry_qualification_apply
    SET store_code = #{storeCode},
    apply_type = #{applyType},
    refrigerator_photo = #{refrigeratorPhoto},
    refrigerator_plate_photo = #{refrigeratorPlatePhoto},
    protective_cover_photo = #{protectiveCoverPhoto},
    cold_storage_box_photo = #{coldStorageBoxPhoto},
    audit_status = #{auditStatus},
    updated_time = NOW()
    WHERE id = #{id}
  </update>

  <select id="listByStoreCode" resultMap="BaseResultMap">
    SELECT *
    FROM xfsg_pre_fry_qualification_apply
    WHERE store_code = #{storeCode}
  </select>

  <select id="selectByStoreCodeAndType" resultMap="BaseResultMap">
    SELECT *
    FROM xfsg_pre_fry_qualification_apply
    WHERE store_code = #{storeCode} and apply_type = #{applyType}
  </select>


  <select id="selectMinApplyTypeByStoreCode" resultMap="BaseResultMap">
    SELECT *
    FROM xfsg_pre_fry_qualification_apply
    WHERE store_code = #{storeCode} and audit_status = 1
    ORDER BY apply_type ASC
    LIMIT 1
  </select>


  <select id="selectApplyManagementList" resultType="com.cool.store.dto.pre.fry.ApplyManagementDTO">
    SELECT
      a.id AS id,
      a.store_code AS storeCode,
      b.store_name AS storeName,
      a.apply_code AS applyCode,
      a.apply_type AS applyType,
      a.created_user_id AS createUserId,
      c.username AS createUserName,
      c.mobile AS createUserMobile,
      a.created_time AS createTime,
      a.audit_status AS auditStatus
    FROM
    xfsg_pre_fry_qualification_apply a
    LEFT JOIN store_${enterpriseId} b ON a.store_code = b.store_num
    LEFT JOIN xfsg_line_info c ON c.partner_id = a.created_user_id
    <where>
      <if test="applyCode !=null and applyCode != ''">
        and a.apply_code LIKE CONCAT('%', #{applyCode}, '%')
      </if>
      <if test="storeCode != null and storeCode != ''">
        AND a.store_code LIKE CONCAT('%', #{storeCode}, '%')
      </if>
      <if test="storeName != null and storeName != ''">
        AND b.store_name LIKE CONCAT('%', #{storeName}, '%')
      </if>
      <if test="createUserName != null and createUserName != ''">
        AND c.username LIKE CONCAT('%', #{createUserName}, '%')
      </if>
      <if test="createUserMobile != null and createUserMobile != ''">
        AND c.mobile LIKE CONCAT('%', #{createUserMobile}, '%')
      </if>
      <if test="auditStatus != null">
        AND a.audit_status = #{auditStatus}
      </if>
      <if test="applyType != null">
        AND a.apply_type = #{applyType}
      </if>
      <if test="createTimeStart != null">
        AND a.created_time >= #{createTimeStart}
      </if>
      <if test="createTimeEnd != null">
        AND a.created_time <![CDATA[<=]]> #{createTimeEnd}
      </if>
    </where>
    ORDER BY a.created_time DESC
  </select>

  <select id="getDetail" resultType="com.cool.store.dto.pre.fry.ApplyDetailDTO">
  SELECT
  a.id AS id,
  a.store_code AS storeCode,
  a.refrigerator_photo   as refrigeratorPhoto,
  a.refrigerator_plate_photo AS refrigeratorPlatePhoto,
  a.protective_cover_photo AS protectiveCoverPhoto,
  a.cold_storage_box_photo AS coldStorageBoxPhoto,
  b.store_name AS storeName,
  a.apply_code AS applyCode,
  a.apply_type AS applyType,
  a.created_user_id AS createUserId,
  c.username AS createUserName,
  c.mobile AS createUserMobile,
  a.created_time AS createTime,
  a.audit_status AS auditStatus
  FROM
  xfsg_pre_fry_qualification_apply a
  LEFT JOIN store_${enterpriseId} b ON a.store_code = b.store_num
  LEFT JOIN xfsg_line_info c ON c.partner_id = a.created_user_id
  where a.id= #{id}
  </select>
</mapper>