<?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.fjs.scenic.mapper.user.StatisticalPermissionsMapper">
  <resultMap id="BaseResultMap" type="com.fjs.scenic.entity.user.StatisticalPermissions">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="code" jdbcType="VARCHAR" property="code" />
    <result column="name" jdbcType="VARCHAR" property="name" />
  </resultMap>
  <sql id="Base_Column_List">
    id, code, name
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from statistical_permissions
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from statistical_permissions
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.fjs.scenic.entity.user.StatisticalPermissions">
    insert into statistical_permissions (id, code, name
      )
    values (#{id,jdbcType=INTEGER}, #{code,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.fjs.scenic.entity.user.StatisticalPermissions">
    insert into statistical_permissions
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="code != null">
        code,
      </if>
      <if test="name != null">
        name,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="code != null">
        #{code,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.fjs.scenic.entity.user.StatisticalPermissions">
    update statistical_permissions
    <set>
      <if test="code != null">
        code = #{code,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.fjs.scenic.entity.user.StatisticalPermissions">
    update statistical_permissions
    set code = #{code,jdbcType=VARCHAR},
      name = #{name,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <!--自定义-->
  <select id="selectAll" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from statistical_permissions
  </select>

  <select id="selectByUserID" parameterType="java.lang.Integer" resultType="java.util.HashMap">
    SELECT sp.*, us.user_id FROM statistical_permissions sp
    INNER JOIN (
        SELECT * FROM user_statistical WHERE user_id = #{id,jdbcType=INTEGER}
    ) us ON sp.id = us.statiscal_permissions_id
  </select>

  <select id="getByUserID" parameterType="java.lang.Integer" resultType="java.lang.Integer">
    SELECT statiscal_permissions_id FROM user_statistical WHERE user_id = #{id,jdbcType=INTEGER}
  </select>

  <select id="getByOpenID" parameterType="java.lang.String" resultType="map">
    SELECT * FROM user_statistical
    LEFT JOIN `user` ON user_statistical.user_id = `user`.id
    WHERE `user`.openid = #{openID,jdbcType=VARCHAR}
  </select>
</mapper>