<?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.bonus.zlpt.company.mapper.MaUserCollectMapper">
  <resultMap id="BaseResultMap" type="com.bonus.zlpt.company.domain.MaUserCollect">
    <!--@mbg.generated-->
    <!--@Table ma_user_collect-->
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="user_id" jdbcType="INTEGER" property="userId" />
    <result column="ma_id" jdbcType="INTEGER" property="maId" />
    <result column="time" jdbcType="VARCHAR" property="time" />
  </resultMap>

  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, user_id, ma_id, `time`
  </sql>

  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    <!--@mbg.generated-->
    select 
    <include refid="Base_Column_List" />
    from ma_user_collect
    where id = #{id,jdbcType=INTEGER}
  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from ma_user_collect
    where user_id = #{userId,jdbcType=INTEGER} and ma_id = #{maId,jdbcType=INTEGER}
  </delete>

  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.bonus.zlpt.company.domain.MaUserCollect" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into ma_user_collect (user_id, ma_id, `time`)
    values (#{userId,jdbcType=INTEGER}, #{maId,jdbcType=INTEGER}, #{time,jdbcType=VARCHAR})
  </insert>

  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.bonus.zlpt.company.domain.MaUserCollect" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into ma_user_collect
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="userId != null">
        user_id,
      </if>
      <if test="maId != null">
        ma_id,
      </if>
      <if test="time != null and time != ''">
        `time`,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="userId != null">
        #{userId,jdbcType=INTEGER},
      </if>
      <if test="maId != null">
        #{maId,jdbcType=INTEGER},
      </if>
      <if test="time != null and time != ''">
        #{time,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>

  <update id="updateByPrimaryKeySelective" parameterType="com.bonus.zlpt.company.domain.MaUserCollect">
    <!--@mbg.generated-->
    update ma_user_collect
    <set>
      <if test="userId != null">
        user_id = #{userId,jdbcType=INTEGER},
      </if>
      <if test="maId != null">
        ma_id = #{maId,jdbcType=INTEGER},
      </if>
      <if test="time != null and time != ''">
        `time` = #{time,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>

  <update id="updateByPrimaryKey" parameterType="com.bonus.zlpt.company.domain.MaUserCollect">
    <!--@mbg.generated-->
    update ma_user_collect
    set user_id = #{userId,jdbcType=INTEGER},
      ma_id = #{maId,jdbcType=INTEGER},
      `time` = #{time,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <select id="selectByMaId" resultType="com.bonus.zlpt.company.domain.MaUserCollect">
      select
        ma_user_collect.id, ma_user_collect.user_id, ma_user_collect.ma_id, ma_user_collect.`time`,mdi.model_name as maName,
        su.user_name as userName
      from ma_user_collect
      left join ma_zlpt.ma_dev_info mdi on ma_user_collect.ma_id = mdi.ma_id
      left join sys_user su on ma_user_collect.user_id = su.user_id
      where ma_user_collect.ma_id = #{maId,jdbcType=INTEGER}
  </select>

  <select id="selectAll" resultType="com.bonus.zlpt.company.domain.MaUserCollect">
    select
    ma_user_collect.id, ma_user_collect.user_id, ma_user_collect.ma_id, ma_user_collect.`time`,mdi.model_name as maName,
    su.user_name as userName
    from ma_user_collect
    left join ma_zlpt.ma_dev_info mdi on ma_user_collect.ma_id = mdi.ma_id
    left join sys_user su on ma_user_collect.user_id = su.user_id
    <where>
      <if test="userId != null and userId != ''">
        and ma_user_collect.user_id = #{userId,jdbcType=INTEGER}
      </if>
      <if test="maId != null and maId != ''">
        and ma_user_collect.ma_id = #{maId,jdbcType=INTEGER}
      </if>
    </where>
  </select>

</mapper>