<?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.yami.shop.dao.ShopAuditingMapper">

  <resultMap id="shopAuditingMap" type="com.yami.shop.bean.model.ShopAuditing">
    <id column="shop_auditing_id" property="shopAuditingId" />
    <result column="user_id" property="userId"/>
    <result column="auditor_id" property="auditorId"/>
    <result column="create_time" property="createTime"/>
    <result column="update_time" property="updateTime"/>
    <result column="status" property="status"/>
    <result column="remarks" property="remarks"/>
    <result column="shop_id" property="shopId"/>
  </resultMap>

  <resultMap id="shopAuditingInfoDtoMap" type="com.yami.shop.bean.dto.ShopAuditingInfoDto">
    <id column="shop_auditing_id" property="shopAuditingId" />
    <result column="shop_id" property="shopId"/>
    <result column="create_time" property="createTime"/>
    <result column="status" property="status"/>
    <result column="shop_name" property="shopName"/>
    <result column="shop_address" property="shopAddress"/>
    <result column="province" property="province"/>
    <result column="city" property="city"/>
    <result column="area" property="area"/>
    <result column="shop_logo" property="shopLogo"/>
    <result column="intro" property="intro"/>
    <result column="shop_status" property="shopStatus"/>
    <result column="mobile" property="mobile"/>
  </resultMap>

  <select id="getShopAuditingByUserId" resultMap="shopAuditingMap">
    select * from tz_shop_auditing where user_id = #{userId}
  </select>

  <select id="auditingInfoList" resultMap="shopAuditingInfoDtoMap">
    SELECT  sa.shop_auditing_id,sa.user_id,sa.`status`,
    sd.shop_id,sd.shop_name,sd.intro,sd.shop_logo,sd.intro,sd.shop_status,sd.mobile,IF(sa.create_time IS NULL,sd.create_time,sa.create_time) AS create_time
    FROM tz_shop_detail sd
    LEFT JOIN tz_shop_auditing sa ON sa.user_id = sd.user_id
        <trim prefix="where" prefixOverrides="and | or" >
          <if test="map.shopAuditingId!=null">
            and sa.shop_auditing_id = #{map.shopAuditingId}
          </if>
          <if test="map.status!=null">
            and sa.status = #{map.status}
          </if>
          <if test="map.intro!=null">
            and sd.intro like CONCAT('%',#{map.intro},'%')
          </if>
          <if test="map.beginTime!=null and map.endTime!=null">
            and date(sa.create_time) between #{map.beginTime} and #{map.endTime}
          </if>
          <if test="map.shopStatus!=null">
            and sd.shop_status = #{map.shopStatus}
          </if>
          <if test="map.shopName!=null and map.shopName!=''">
            and sd.shop_name like CONCAT('%',#{map.shopName},'%')
          </if>
        </trim>
    ORDER BY sd.create_time DESC, sd.shop_id desc
  </select>

</mapper>
