<?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.ssm.manage.mapper.BaseStoreMapper">
  <resultMap id="BaseResultMap" type="com.ssm.manage.entity.BaseStore">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="store_num" jdbcType="VARCHAR" property="storeNum" />
    <result column="store_name" jdbcType="VARCHAR" property="storeName" />
    <result column="province_id" jdbcType="INTEGER" property="provinceId" />
    <result column="province" jdbcType="VARCHAR" property="province" />
    <result column="city_id" jdbcType="INTEGER" property="cityId" />
    <result column="city" jdbcType="VARCHAR" property="city" />
    <result column="county_id" jdbcType="INTEGER" property="countyId" />
    <result column="county" jdbcType="VARCHAR" property="county" />
    <result column="street" jdbcType="VARCHAR" property="street" />
    <result column="store_address" jdbcType="VARCHAR" property="storeAddress" />
    <result column="location_longitude" jdbcType="VARCHAR" property="locationLongitude" />
    <result column="location_latitude" jdbcType="VARCHAR" property="locationLatitude" />
    <result column="telephone" jdbcType="CHAR" property="telephone" />
    <result column="registrant" jdbcType="VARCHAR" property="registrant" />
    <result column="registrant_mobile_phone" jdbcType="CHAR" property="registrantMobilePhone" />
    <result column="account_number" jdbcType="VARCHAR" property="accountNumber" />
    <result column="state" jdbcType="INTEGER" property="state" />
    <result column="reviewer" jdbcType="VARCHAR" property="reviewer" />
    <result column="reviewer_datetime" jdbcType="TIMESTAMP" property="reviewerDatetime" />
    <result column="reviewer_file" jdbcType="VARCHAR" property="reviewerFile" />
    <result column="reviewer_file_path" jdbcType="VARCHAR" property="reviewerFilePath" />
    <result column="opening_date" jdbcType="DATE" property="openingDate" />
    <result column="opening_year" jdbcType="INTEGER" property="openingYear" />
    <result column="end_date" jdbcType="DATE" property="endDate" />
    <result column="annual_fee" jdbcType="DECIMAL" property="annualFee" />
    <result column="presuppose_password" jdbcType="VARCHAR" property="presupposePassword" />
    <result column="registrant_identity" jdbcType="VARCHAR" property="registrantIdentity" />
    <result column="registrant_sex" jdbcType="INTEGER" property="registrantSex" />
    <result column="funder_id" jdbcType="BIGINT" property="funderId" />
    <result column="funder_name" jdbcType="VARCHAR" property="funderName" />
    <result column="funder_date" jdbcType="TIMESTAMP" property="funderDate" />
    <result column="updated_id" jdbcType="BIGINT" property="updatedId" />
    <result column="updated_name" jdbcType="VARCHAR" property="updatedName" />
    <result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate" />
    <result column="sms_account" jdbcType="VARCHAR" property="smsAccount" />
    <result column="sms_password" jdbcType="VARCHAR" property="smsPassword" />
    <result column="sms_url" jdbcType="VARCHAR" property="smsUrl" />
    <result column="industry" jdbcType="INTEGER" property="industry" />
    <result column="parent_id" jdbcType="BIGINT" property="parentId" />
    <result column="description" jdbcType="LONGVARCHAR" property="description" />
    <result column="reason" jdbcType="LONGVARCHAR" property="reason" />
    <result column="payment_code" jdbcType="VARCHAR" property="paymentCode" />
    <result column="messaging_platform" jdbcType="INTEGER" property="messagingPlatform" />
    <result column="sign_id" jdbcType="VARCHAR" property="signId" />
  </resultMap>

  <resultMap type="com.ssm.manage.entity.BaseStores" id="menuTree">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="store_num" jdbcType="VARCHAR" property="storeNum" />
    <result column="store_name" jdbcType="VARCHAR" property="storeName" />
    <result column="province_id" jdbcType="INTEGER" property="provinceId" />
    <result column="province" jdbcType="VARCHAR" property="province" />
    <result column="city_id" jdbcType="INTEGER" property="cityId" />
    <result column="city" jdbcType="VARCHAR" property="city" />
    <result column="county_id" jdbcType="INTEGER" property="countyId" />
    <result column="county" jdbcType="VARCHAR" property="county" />
    <result column="street" jdbcType="VARCHAR" property="street" />
    <result column="store_address" jdbcType="VARCHAR" property="storeAddress" />
    <result column="location_longitude" jdbcType="VARCHAR" property="locationLongitude" />
    <result column="location_latitude" jdbcType="VARCHAR" property="locationLatitude" />
    <result column="telephone" jdbcType="CHAR" property="telephone" />
    <result column="registrant" jdbcType="VARCHAR" property="registrant" />
    <result column="registrant_mobile_phone" jdbcType="CHAR" property="registrantMobilePhone" />
    <result column="account_number" jdbcType="VARCHAR" property="accountNumber" />
    <result column="state" jdbcType="INTEGER" property="state" />
    <result column="reviewer" jdbcType="VARCHAR" property="reviewer" />
    <result column="reviewer_datetime" jdbcType="TIMESTAMP" property="reviewerDatetime" />
    <result column="reviewer_file" jdbcType="VARCHAR" property="reviewerFile" />
    <result column="reviewer_file_path" jdbcType="VARCHAR" property="reviewerFilePath" />
    <result column="opening_date" jdbcType="DATE" property="openingDate" />
    <result column="opening_year" jdbcType="INTEGER" property="openingYear" />
    <result column="end_date" jdbcType="DATE" property="endDate" />
    <result column="annual_fee" jdbcType="DECIMAL" property="annualFee" />
    <result column="presuppose_password" jdbcType="VARCHAR" property="presupposePassword" />
    <result column="registrant_identity" jdbcType="VARCHAR" property="registrantIdentity" />
    <result column="registrant_sex" jdbcType="INTEGER" property="registrantSex" />
    <result column="funder_id" jdbcType="BIGINT" property="funderId" />
    <result column="funder_name" jdbcType="VARCHAR" property="funderName" />
    <result column="funder_date" jdbcType="TIMESTAMP" property="funderDate" />
    <result column="updated_id" jdbcType="BIGINT" property="updatedId" />
    <result column="updated_name" jdbcType="VARCHAR" property="updatedName" />
    <result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate" />
    <result column="sms_account" jdbcType="VARCHAR" property="smsAccount" />
    <result column="sms_password" jdbcType="VARCHAR" property="smsPassword" />
    <result column="sms_url" jdbcType="VARCHAR" property="smsUrl" />
    <result column="industry" jdbcType="INTEGER" property="industry" />
    <result column="parent_id" jdbcType="BIGINT" property="parentId" />
    <result column="description" jdbcType="LONGVARCHAR" property="description" />
    <result column="reason" jdbcType="LONGVARCHAR" property="reason" />
    <result column="payment_code" jdbcType="VARCHAR" property="paymentCode" />
    <result column="messaging_platform" jdbcType="INTEGER" property="messagingPlatform" />
    <result column="sign_id" jdbcType="VARCHAR" property="signId" />
    <collection property="children" ofType="com.ssm.manage.entity.BaseStores" column="id" select="getMenuChildren"/>
  </resultMap>

  <resultMap type="com.ssm.manage.entity.BaseStores" id="menuTrees">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="store_num" jdbcType="VARCHAR" property="storeNum" />
    <result column="store_name" jdbcType="VARCHAR" property="storeName" />
    <result column="province_id" jdbcType="INTEGER" property="provinceId" />
    <result column="province" jdbcType="VARCHAR" property="province" />
    <result column="city_id" jdbcType="INTEGER" property="cityId" />
    <result column="city" jdbcType="VARCHAR" property="city" />
    <result column="county_id" jdbcType="INTEGER" property="countyId" />
    <result column="county" jdbcType="VARCHAR" property="county" />
    <result column="street" jdbcType="VARCHAR" property="street" />
    <result column="store_address" jdbcType="VARCHAR" property="storeAddress" />
    <result column="location_longitude" jdbcType="VARCHAR" property="locationLongitude" />
    <result column="location_latitude" jdbcType="VARCHAR" property="locationLatitude" />
    <result column="telephone" jdbcType="CHAR" property="telephone" />
    <result column="registrant" jdbcType="VARCHAR" property="registrant" />
    <result column="registrant_mobile_phone" jdbcType="CHAR" property="registrantMobilePhone" />
    <result column="account_number" jdbcType="VARCHAR" property="accountNumber" />
    <result column="state" jdbcType="INTEGER" property="state" />
    <result column="reviewer" jdbcType="VARCHAR" property="reviewer" />
    <result column="reviewer_datetime" jdbcType="TIMESTAMP" property="reviewerDatetime" />
    <result column="reviewer_file" jdbcType="VARCHAR" property="reviewerFile" />
    <result column="reviewer_file_path" jdbcType="VARCHAR" property="reviewerFilePath" />
    <result column="opening_date" jdbcType="DATE" property="openingDate" />
    <result column="opening_year" jdbcType="INTEGER" property="openingYear" />
    <result column="end_date" jdbcType="DATE" property="endDate" />
    <result column="annual_fee" jdbcType="DECIMAL" property="annualFee" />
    <result column="presuppose_password" jdbcType="VARCHAR" property="presupposePassword" />
    <result column="registrant_identity" jdbcType="VARCHAR" property="registrantIdentity" />
    <result column="registrant_sex" jdbcType="INTEGER" property="registrantSex" />
    <result column="funder_id" jdbcType="BIGINT" property="funderId" />
    <result column="funder_name" jdbcType="VARCHAR" property="funderName" />
    <result column="funder_date" jdbcType="TIMESTAMP" property="funderDate" />
    <result column="updated_id" jdbcType="BIGINT" property="updatedId" />
    <result column="updated_name" jdbcType="VARCHAR" property="updatedName" />
    <result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate" />
    <result column="sms_account" jdbcType="VARCHAR" property="smsAccount" />
    <result column="sms_password" jdbcType="VARCHAR" property="smsPassword" />
    <result column="sms_url" jdbcType="VARCHAR" property="smsUrl" />
    <result column="industry" jdbcType="INTEGER" property="industry" />
    <result column="parent_id" jdbcType="BIGINT" property="parentId" />
    <result column="description" jdbcType="LONGVARCHAR" property="description" />
    <result column="reason" jdbcType="LONGVARCHAR" property="reason" />
    <result column="payment_code" jdbcType="VARCHAR" property="paymentCode" />
    <result column="messaging_platform" jdbcType="INTEGER" property="messagingPlatform" />
    <result column="sign_id" jdbcType="VARCHAR" property="signId" />
    <collection property="parent" ofType="com.ssm.manage.entity.BaseStores" column="parent_id" select="getMenuparent"/>
  </resultMap>

  <!--父查子-->
  <!-- 先查询菜单根级目录 -->
  <!-- 这里的返回结果必须为resultMap，并且值为上面构建的resultMap的id的值 -->
  <select id="findAllRecursion" resultMap="menuTree">
    SELECT
      *
    FROM
      base_store
    WHERE
      parent_id IS NULL and id =#{id}
  </select>

  <!-- 再利用上次查询结果colliection中column的值cid做递归查询，查出所有子菜单 -->
  <!-- 这里的返回结果必须为resultMap，并且值为上面构建的resultMap的id的值 -->
  <select id="getMenuChildren" resultMap="menuTree">
    SELECT
      *
    FROM
      base_store
    WHERE
      parent_id= #{id}
  </select>


  <!--子查父-->
  <!-- 先查询菜单根级目录 -->
  <!-- 这里的返回结果必须为resultMap，并且值为上面构建的resultMap的id的值 -->
  <select id="findAllRecursions" resultMap="menuTrees">
    SELECT
      *
    FROM
      base_store
    WHERE
      id = #{id}
  </select>

  <!-- 再利用上次查询结果colliection中column的值cid做递归查询，查出所有子菜单 -->
  <!-- 这里的返回结果必须为resultMap，并且值为上面构建的resultMap的id的值 -->
  <select id="getMenuparent" resultMap="menuTrees">
    SELECT
      *
    FROM
      base_store
    WHERE
      id = #{parent_id}
  </select>


  <select id="selectTableName1" resultType="java.lang.String">
    SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='dcmy_new' and TABLE_NAME like '%account_trade_record_%' ;
  </select>

  <select id="selectTableName2" resultType="java.lang.String">
    SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='dcmy_new' and TABLE_NAME like '%cash_list_%' ;
  </select>

  <select id="selectTableName3" resultType="java.lang.String">
    SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='dcmy_new' and TABLE_NAME like '%recharge_list_%' ;
  </select>

  <select id="selectTableName4" resultType="java.lang.String">
    SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='dcmy_new' and TABLE_NAME like '%service_orders_%' ;
  </select>
  <select id="selectByStoreName" resultMap="menuTrees">
    select * from base_store where store_name like #{storeName} or store_num like #{storeName}
  </select>
  <select id="selectChildren" resultMap="BaseResultMap" parameterType="long">
    SELECT id,store_num,store_name from base_store where state = '1' and (id = #{storeId} or parent_id = (select id from base_store where state='1' and id = #{storeId} )
      or parent_id in
         (SELECT id from base_store where state = '1' and parent_id = (select id from base_store where state='1' and id = #{storeId} ) )) order by id
  </select>
  <select id="selectStoreS"  resultMap="BaseResultMap">
    select *
    from   base_store
             where id in
             <foreach collection="storeIds" item="item" separator="," open="(" close=")" >
               #{item}
             </foreach>
            and state = '1'

  </select>
  <select id="selectDescription" resultType="java.lang.String">
    select description from base_store where description is not null  group by description;
  </select>
    <select id="selectGroup" resultType="java.lang.String">
      select DISTINCT(ifnull(description,'无')) from base_store
    </select>
  <select id="selectByIds" resultMap="BaseResultMap">
    select *
    from   base_store
    where id in
    <foreach collection="storeIds" item="item" separator="," open="(" close=")" >
      #{item}
    </foreach>
    and state = '1'

  </select>

  <update id="updateName">
    update (account_trade_record_202208 a INNER JOIN account_trade_record_202209 b ON a.member_name=b.member_name)
    set a.member_name='zz',b.member_name='zz'
    where a.member_name='z' and b.member_name='z'
  </update>

</mapper>