<?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.BaseStaffMapper">
  <resultMap id="BaseResultMap" type="com.ssm.manage.entity.BaseStaff">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="staff_num" jdbcType="VARCHAR" property="staffNum" />
    <result column="staff_name" jdbcType="VARCHAR" property="staffName" />
    <result column="sex" jdbcType="INTEGER" property="sex" />
    <result column="mobile_phone" jdbcType="VARCHAR" property="mobilePhone" />
    <result column="QQ" jdbcType="VARCHAR" property="qq" />
    <result column="wechat" jdbcType="VARCHAR" property="wechat" />
    <result column="joined_date" jdbcType="DATE" property="joinedDate" />
    <result column="leave_date" jdbcType="DATE" property="leaveDate" />
    <result column="reinstate_date" jdbcType="DATE" property="reinstateDate" />
    <result column="password" jdbcType="VARCHAR" property="password" />
    <result column="identity_card" jdbcType="VARCHAR" property="identityCard" />
    <result column="state" jdbcType="INTEGER" property="state" />
    <result column="job" jdbcType="INTEGER" property="job" />
    <result column="grade" jdbcType="INTEGER" property="grade" />
    <result column="brand_number" jdbcType="VARCHAR" property="brandNumber" />
    <result column="brief_introduction" jdbcType="VARCHAR" property="briefIntroduction" />
    <result column="good_at" jdbcType="VARCHAR" property="goodAt" />
    <result column="popularity" jdbcType="INTEGER" property="popularity" />
    <result column="user_state" jdbcType="INTEGER" property="userState" />
    <result column="role_num" jdbcType="VARCHAR" property="roleNum" />
    <result column="role_name" jdbcType="VARCHAR" property="roleName" />
    <result column="store_id" jdbcType="BIGINT" property="storeId" />
    <result column="store_name" jdbcType="VARCHAR" property="storeName" />
    <result column="row" jdbcType="INTEGER" property="row" />
    <result column="month_task" jdbcType="VARCHAR" property="monthTask" />
    <result column="base_salary" jdbcType="DECIMAL" property="baseSalary" />
    <result column="month_ratio" jdbcType="DECIMAL" property="monthRatio" />
    <result column="month_higher_one" jdbcType="DECIMAL" property="monthHigherOne" />
    <result column="month_higher_one_ratio" jdbcType="DECIMAL" property="monthHigherOneRatio" />
    <result column="month_higher_two" jdbcType="DECIMAL" property="monthHigherTwo" />
    <result column="month_higher_two_ratio" jdbcType="DECIMAL" property="monthHigherTwoRatio" />
    <result column="month_higher_three" jdbcType="DECIMAL" property="monthHigherThree" />
    <result column="month_higher_three_ratio" jdbcType="DECIMAL" property="monthHigherThreeRatio" />
    <result column="month_higher_four" jdbcType="DECIMAL" property="monthHigherFour" />
    <result column="month_higher_four_ratio" jdbcType="DECIMAL" property="monthHigherFourRatio" />
    <result column="month_lower_one" jdbcType="DECIMAL" property="monthLowerOne" />
    <result column="month_lower_one_ratio" jdbcType="DECIMAL" property="monthLowerOneRatio" />
    <result column="month_lower_two" jdbcType="DECIMAL" property="monthLowerTwo" />
    <result column="month_lower_two_ratio" jdbcType="DECIMAL" property="monthLowerTwoRatio" />
    <result column="month_lower_three" jdbcType="DECIMAL" property="monthLowerThree" />
    <result column="month_lower_three_ratio" jdbcType="DECIMAL" property="monthLowerThreeRatio" />
    <result column="month_lower_four" jdbcType="DECIMAL" property="monthLowerFour" />
    <result column="month_lower_four_ratio" jdbcType="DECIMAL" property="monthLowerFourRatio" />
    <result column="recharge_achi" jdbcType="DECIMAL" property="rechargeAchi" />
    <result column="course_achi" jdbcType="DECIMAL" property="courseAchi" />
    <result column="cash_achi" jdbcType="DECIMAL" property="cashAchi" />
    <result column="source" jdbcType="INTEGER" property="source" />
    <result column="post_id" jdbcType="INTEGER" property="postId" />
    <result column="post_num" jdbcType="VARCHAR" property="postNum" />
    <result column="post_name" jdbcType="VARCHAR" property="postName" />
    <result column="word_type_id" jdbcType="BIGINT" property="wordTypeId" />
    <result property="wordTypeNum" column="word_type_num" jdbcType="VARCHAR"/>
    <result property="wordTypeName" column="word_type_name" jdbcType="VARCHAR"/>
  </resultMap>

  <resultMap id="BaseResultloginMap" type="com.ssm.manage.query.StaffRequest">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="staff_num" jdbcType="VARCHAR" property="staffNum" />
    <result column="staff_name" jdbcType="VARCHAR" property="staffName" />
    <result column="sex" jdbcType="INTEGER" property="sex" />
    <result column="mobile_phone" jdbcType="VARCHAR" property="mobilePhone" />
    <result column="QQ" jdbcType="VARCHAR" property="qq" />
    <result column="wechat" jdbcType="VARCHAR" property="wechat" />
    <result column="joined_date" jdbcType="DATE" property="joinedDate" />
    <result column="leave_date" jdbcType="DATE" property="leaveDate" />
    <result column="reinstate_date" jdbcType="DATE" property="reinstateDate" />
    <result column="password" jdbcType="VARCHAR" property="password" />
    <result column="identity_card" jdbcType="VARCHAR" property="identityCard" />
    <result column="state" jdbcType="INTEGER" property="state" />
    <result column="job" jdbcType="INTEGER" property="job" />
    <result column="grade" jdbcType="INTEGER" property="grade" />
    <result column="brand_number" jdbcType="VARCHAR" property="brandNumber" />
    <result column="brief_introduction" jdbcType="VARCHAR" property="briefIntroduction" />
    <result column="good_at" jdbcType="VARCHAR" property="goodAt" />
    <result column="popularity" jdbcType="INTEGER" property="popularity" />
    <result column="user_state" jdbcType="INTEGER" property="userState" />
    <result column="role_num" jdbcType="VARCHAR" property="roleNum" />
    <result column="role_name" jdbcType="VARCHAR" property="roleName" />
    <result column="role_id" jdbcType="BIGINT" property="roleId" />
    <result column="store_id" jdbcType="BIGINT" property="storeId" />
    <result column="store_name" jdbcType="VARCHAR" property="storeName" />
    <result column="row" jdbcType="INTEGER" property="row" />
    <result column="month_task" jdbcType="VARCHAR" property="monthTask" />
    <result column="base_salary" jdbcType="DECIMAL" property="baseSalary" />
    <result column="month_ratio" jdbcType="DECIMAL" property="monthRatio" />
    <result column="month_higher_one" jdbcType="DECIMAL" property="monthHigherOne" />
    <result column="month_higher_one_ratio" jdbcType="DECIMAL" property="monthHigherOneRatio" />
    <result column="month_higher_two" jdbcType="DECIMAL" property="monthHigherTwo" />
    <result column="month_higher_two_ratio" jdbcType="DECIMAL" property="monthHigherTwoRatio" />
    <result column="month_higher_three" jdbcType="DECIMAL" property="monthHigherThree" />
    <result column="month_higher_three_ratio" jdbcType="DECIMAL" property="monthHigherThreeRatio" />
    <result column="month_higher_four" jdbcType="DECIMAL" property="monthHigherFour" />
    <result column="month_higher_four_ratio" jdbcType="DECIMAL" property="monthHigherFourRatio" />
    <result column="month_lower_one" jdbcType="DECIMAL" property="monthLowerOne" />
    <result column="month_lower_one_ratio" jdbcType="DECIMAL" property="monthLowerOneRatio" />
    <result column="month_lower_two" jdbcType="DECIMAL" property="monthLowerTwo" />
    <result column="month_lower_two_ratio" jdbcType="DECIMAL" property="monthLowerTwoRatio" />
    <result column="month_lower_three" jdbcType="DECIMAL" property="monthLowerThree" />
    <result column="month_lower_three_ratio" jdbcType="DECIMAL" property="monthLowerThreeRatio" />
    <result column="month_lower_four" jdbcType="DECIMAL" property="monthLowerFour" />
    <result column="month_lower_four_ratio" jdbcType="DECIMAL" property="monthLowerFourRatio" />
    <result column="recharge_achi" jdbcType="DECIMAL" property="rechargeAchi" />
    <result column="course_achi" jdbcType="DECIMAL" property="courseAchi" />
    <result column="cash_achi" jdbcType="DECIMAL" property="cashAchi" />
    <result column="source" jdbcType="INTEGER" property="source" />
    <result column="store_num" jdbcType="VARCHAR" property="storeNum" />
    <result column="parent_id" jdbcType="VARCHAR" property="parentId" />
    <result column="dept_name" jdbcType="INTEGER" property="deptName" />
    <result column="post_id" jdbcType="INTEGER" property="postId" />
    <result column="post_num" jdbcType="VARCHAR" property="postNum" />
    <result column="post_name" jdbcType="VARCHAR" property="postName" />
    <result column="word_type_id" jdbcType="BIGINT" property="wordTypeId" />
    <result property="wordTypeNum" column="word_type_num" jdbcType="VARCHAR"/>
    <result property="wordTypeName" column="word_type_name" jdbcType="VARCHAR"/>
  </resultMap>
<sql id="baseColumnList">
  id,
  staff_num,
  staff_name,
  sex,
  mobile_phone,
  QQ,
  wechat,
  joined_date,
  leave_date,
  reinstate_date,
  password,
  identity_card,
  state,
  job,
  grade,
  brand_number,
  brief_introduction,
  good_at,
  popularity,
  user_state,
  role_num,
  role_name,
  store_id,
  store_name,
  row,
  month_task,
  base_salary,
  month_ratio,
  month_higher_one,
  month_higher_one_ratio,
  month_higher_two,
  month_higher_two_ratio,
  month_higher_three,
  month_higher_three_ratio,
  month_higher_four,
  month_higher_four_ratio,
  month_lower_one,
  month_lower_one_ratio,
  month_lower_two,
  month_lower_two_ratio,
  month_lower_three,
  month_lower_three_ratio,
  month_lower_four,
  month_lower_four_ratio,
  recharge_achi,
  course_achi,
  cash_achi,
  source,
  dept_name,
    post_id,
    post_num,
    post_name,word_type_id,word_type_num,word_type_name,role_id
</sql>
  <insert id="insertBatch" parameterType="java.util.ArrayList">
    insert into base_staff (<include refid="baseColumnList"/>) values
    <foreach collection="list" index="index" item="staff" separator=",">
      (#{staff.id},
      #{staff.staffNum},
      #{staff.staffName},
      #{staff.sex},
      #{staff.mobilePhone},
      #{staff.qq},
      #{staff.wechat},
      #{staff.joinedDate},
      #{staff.leaveDate},
      #{staff.reinstateDate},
      #{staff.password},
      #{staff.identityCard},
      #{staff.state},
      #{staff.job},
      #{staff.grade},
      #{staff.brandNumber},
      #{staff.briefIntroduction},
      #{staff.goodAt},
      #{staff.popularity},
      #{staff.userState},
      #{staff.roleNum},
      #{staff.roleName},
      #{staff.storeId},
      #{staff.storeName},
      #{staff.row},
      #{staff.baseSalary},
      #{staff.monthTask},
      #{staff.monthRatio},
      #{staff.monthHigherOne},
      #{staff.monthHigherOneRatio},
      #{staff.monthHigherTwo},
      #{staff.monthHigherTwoRatio},
      #{staff.monthHigherThree},
      #{staff.monthHigherThreeRatio},
      #{staff.monthHigherFour},
      #{staff.monthHigherFourRatio},
      #{staff.monthLowerOne},
      #{staff.monthLowerOneRatio},
      #{staff.monthLowerTwo},
      #{staff.monthLowerTwoRatio},
      #{staff.monthLowerThree},
      #{staff.monthLowerThreeRatio},
      #{staff.monthLowerFour},
      #{staff.monthLowerFourRatio},
      #{staff.rechargeAchi},
      #{staff.courseAchi},
      #{staff.cashAchi},
      #{staff.source},
      #{staff.deptName},
      #{staff.postId},
      #{staff.postNum},
      #{staff.postName},#{staff.wordTypeId},#{staff.wordTypeNum},#{staff.wordTypeName},#{staff.roleId}
      )
    </foreach>
  </insert>
    <update id="updateStaffState">
      update base_staff set state = #{state} where identity_card = #{identityCard} and mobile_phone = #{mobilePhone} and store_id = #{storeId}
    </update>


    <select id="liststarfall" resultMap="BaseResultloginMap">
    select a.*,b.store_num,b.parent_id from base_staff a left join base_store b on a.store_id = b.id
    <where>
      <if test="state != null">
        and a.state = #{state}
      </if>
      <if test="mobilePhone != null">
        and a.mobile_phone = #{mobilePhone}
      </if>
      <if test="storeName != null">
        and a.store_name Like concat('%','${storeName}','%')
      </if>
      <if test="storeId != null">
        and a.store_id = #{storeId}
      </if>
      <if test="storeNum != null">
        and b.store_num Like concat('%','${storeNum}','%')
      </if>
    </where>
  </select>

  <select id="liststarfallRoot" resultMap="BaseResultloginMap">
    select * from base_store
  </select>

  <select id="selectCheck" resultMap="BaseResultloginMap">
    select * from base_staff where mobile_phone = #{mobilePhone} and store_id=#{storeId}
    <if test="roleId != null">
      and role_id=#{roleId}
    </if>
  </select>

  <select id="CheckPhone" resultMap="BaseResultloginMap">
    select * from base_staff where mobile_phone = #{mobilePhone} and store_id=#{storeId} and state=1
  </select>
    <select id="selectByAllSalemans" resultMap="BaseResultMap">
      select * from base_staff where type in(1,2)
    </select>


</mapper>