<?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.ruoyi.syzy.mapper.BCustomerMarjorsMapper">

  <resultMap type="BCustomerMarjors" id="BCustomerMarjorsResult">
    <result property="id" column="id" />
    <result property="customerCode" column="customerCode" />
    <result property="marjorId" column="marjorId" />
    <result property="createTime" column="createTime" />
    <result property="status" column="status" />
  </resultMap>

  <sql id="selectBCustomerMarjorsVo">
    select id, customerCode, marjorId, createTime, status from b_customer_marjors
  </sql>

  <select id="selectBCustomerMarjorsList" parameterType="BCustomerMarjors" resultMap="BCustomerMarjorsResult">
    <include refid="selectBCustomerMarjorsVo" />
    <where>
      <if test="customerCode != null  and customerCode != ''"> and customerCode = #{customerCode}</if>
      <if test="marjorId != null  and marjorId != ''"> and marjorId = #{marjorId}</if>
      <if test="createTime != null "> and createTime = #{createTime}</if>
      <if test="status != null "> and status = #{status}</if>
      <if test="status == null "> and status >0 </if>
    </where>
  </select>

  <select id="selectBCustomerMarjorsById" parameterType="Long" resultMap="BCustomerMarjorsResult">
    <include refid="selectBCustomerMarjorsVo" />
    where id = #{id}
  </select>

  <select id="listMyByPage" parameterType="String" resultType="com.alibaba.fastjson.JSONObject">
    select b.code, b.parent_code, b.name, b.type, b.level, b.ancestors, b.child_count, b.grandchild_count, b.learn_year_arab,
    a.id,a.customerCode,a.marjorId,a.status,a.createTime
    from b_customer_marjors a, sy_major b
    where a.status > 0 and a.marjorId=b.id
    <if test="customerCode != null and customerCode!=''"> and a.customerCode = #{customerCode} </if>
    order by a.id desc
  </select>

  <insert id="insertBCustomerMarjors" parameterType="BCustomerMarjors" useGeneratedKeys="true" keyProperty="id">
    insert into b_customer_marjors
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="customerCode != null">customerCode,</if>
      <if test="marjorId != null">marjorId,</if>
      <if test="createTime != null">createTime,</if>
      <if test="status != null">status,</if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="customerCode != null">#{customerCode},</if>
      <if test="marjorId != null">#{marjorId},</if>
      <if test="createTime != null">#{createTime},</if>
      <if test="status != null">#{status},</if>
    </trim>
  </insert>

  <update id="updateBCustomerMarjors" parameterType="BCustomerMarjors">
    update b_customer_marjors
    <trim prefix="SET" suffixOverrides=",">
      <if test="customerCode != null">customerCode = #{customerCode},</if>
      <if test="marjorId != null">marjorId = #{marjorId},</if>
      <if test="createTime != null">createTime = #{createTime},</if>
      <if test="status != null">status = #{status},</if>
    </trim>
    where id = #{id}
  </update>

  <delete id="deleteBCustomerMarjorsById" parameterType="Long">
    delete from b_customer_marjors where id = #{id}
  </delete>

  <delete id="deleteBCustomerMarjorsByIds" parameterType="String">
    delete from b_customer_marjors where id in
    <foreach item="id" collection="array" open="(" separator="," close=")">
      #{id}
    </foreach>
  </delete>
</mapper>