<?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.boco.nbd.wios.manage.mapper.def.ScoreSupplierDetailMapper">

    <resultMap id="BaseResultMap" type="com.boco.nbd.wios.manage.entity.bo.ScoreSupplierDetail">
        <id column="id" jdbcType="INTEGER" property="id" />
        <result column="score_supplier_id" jdbcType="INTEGER" property="scoreSupplierId" />
        <result column="code" jdbcType="VARCHAR" property="code" />
        <result column="name" jdbcType="VARCHAR" property="name" />
        <result column="status" jdbcType="INTEGER" property="status" />
        <result column="type" jdbcType="VARCHAR" property="type" />
        <result column="parent_code" jdbcType="VARCHAR" property="parentCode" />
        <result column="parent_name" jdbcType="VARCHAR" property="parentName" />
        <result column="parent_weight" jdbcType="VARCHAR" property="parentWeight" />
        <result column="weight" jdbcType="INTEGER" property="weight" />
        <result column="score" jdbcType="DECIMAL" property="score" />
        <result column="result_calc" jdbcType="DECIMAL" property="resultCalc" />
        <result column="source" jdbcType="VARCHAR" property="source" />
        <result column="description" jdbcType="VARCHAR" property="description" />
        <result column="create_account" jdbcType="VARCHAR" property="createAccount" />
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
        <result column="modify_account" jdbcType="VARCHAR" property="modifyAccount" />
        <result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime" />
    </resultMap>


    <sql id="Base_Column_List">
      tss.id, tss.score_supplier_id, tss.code, tss.name, tss.status, tss.type, tss.parent_code,tss.score, tss.result_calc, tss.weight, tss.source, tss.description, tss.create_account,
      tss.create_time, tss.modify_account, tss.modify_time
    </sql>

    <insert id="insert" parameterType="com.boco.nbd.wios.manage.entity.bo.ScoreSupplierDetail">
      insert into t_score_supplier_detail (id, score_supplier_id, code, name,
        status, type, parent_code,
        weight,score, source, description,
        create_account, create_time, modify_account,
        modify_time)
      values (#{id,jdbcType=INTEGER}, #{iscore_supplier_id,jdbcType=INTEGER}, #{code,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
        #{status,jdbcType=INTEGER}, #{type,jdbcType=VARCHAR}, #{parentCode,jdbcType=VARCHAR},
        #{weight,jdbcType=INTEGER}, #{score,jdbcType=INTEGER}, #{source,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR},
        #{createAccount,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{modifyAccount,jdbcType=VARCHAR},
        #{modifyTime,jdbcType=TIMESTAMP})
    </insert>


    <update id="update" parameterType="com.boco.nbd.wios.manage.entity.bo.ScoreSupplierDetail">
        update t_score_supplier_detail
        <set>
            <if test="score != null">
                score = #{score,jdbcType=DECIMAL},
            </if>
            <if test="resultCalc != null">
                result_calc = #{resultCalc,jdbcType=DECIMAL},
            </if>
            <if test="status != null">
                status = #{status,jdbcType=INTEGER},
            </if>
            <if test="description != null">
                description = #{description,jdbcType=VARCHAR},
            </if>
            <if test="modifyAccount != null">
                modify_account = #{modifyAccount,jdbcType=VARCHAR},
            </if>
            <if test="modifyTime != null">
                modify_time = #{modifyTime,jdbcType=TIMESTAMP},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>

    <update id="updateByCode" parameterType="com.boco.nbd.wios.manage.entity.bo.ScoreSupplierDetail">
        update t_score_supplier_detail
        <set>
            <if test="score != null">
                score = #{score,jdbcType=DECIMAL},
            </if>
            <if test="resultCalc != null">
                result_calc = #{resultCalc,jdbcType=INTEGER},
            </if>
            <if test="description != null">
                description = #{description,jdbcType=VARCHAR},
            </if>
            <if test="modifyAccount != null">
                modify_account = #{modifyAccount,jdbcType=VARCHAR},
            </if>
            <if test="modifyTime != null">
                modify_time = #{modifyTime,jdbcType=TIMESTAMP},
            </if>
        </set>
        where score_supplier_id = #{scoreSupplierId,jdbcType=INTEGER}
            and code = #{code,jdbcType=VARCHAR}
    </update>


    <select id="selectById" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from  t_score_supplier_detail tss
        where tss.id = #{id,jdbcType=INTEGER}
    </select>

    <select id="selectByExample" parameterType="com.boco.nbd.wios.manage.entity.bo.ScoreSupplierDetail" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />,
        ts.name as parent_name,
        ts.weight as parent_weight
        from  t_score_supplier_detail tss
        join t_score_config ts on tss.parent_code=ts.code and ts.status=1
        where tss.score_supplier_id = #{scoreSupplierId,jdbcType=INTEGER}
        <if test="code != null">
            and tss.code = #{code,jdbcType=VARCHAR}
        </if>
        <if test="parentCode != null">
            and tss.parent_code = #{parentCode,jdbcType=VARCHAR}
        </if>
    </select>


    <select id="getListByScoreSupplierId" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />,
        ts.name as parent_name
        from  t_score_supplier_detail tss
        left join t_score_config ts on tss.parent_code=ts.code and ts.status=1
        where tss.score_supplier_id = #{scoreSupplierId,jdbcType=VARCHAR} and tss.status =1
    </select>

	<select id="getListByScoreSupplierIdAndParentCode" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from  t_score_supplier_detail tss
        where tss.score_supplier_id = #{scoreSupplierId} and tss.status =1 and parent_code=#{parentCode}
    </select>



</mapper>