<?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.shinsoft.sto.mapper.main.MaterialMapper">

    <resultMap id="BaseResultMap" type="com.shinsoft.sto.model.main.Material">
        <id column="id" property="id" jdbcType="VARCHAR"/>
        <result column="process_instance_id" property="processInstanceId" jdbcType="VARCHAR"/>
        <result column="process_instance_status" property="processInstanceStatus" jdbcType="VARCHAR"/>
        <result column="add_id" property="addId" jdbcType="VARCHAR"/>
        <result column="add_code" property="addCode" jdbcType="VARCHAR"/>
        <result column="add_name" property="addName" jdbcType="VARCHAR"/>
        <result column="add_dept_id" property="addDeptId" jdbcType="VARCHAR"/>
        <result column="add_dept_code" property="addDeptCode" jdbcType="VARCHAR"/>
        <result column="add_dept_name" property="addDeptName" jdbcType="VARCHAR"/>
        <result column="add_time" property="addTime" jdbcType="TIMESTAMP"/>
        <result column="modify_id" property="modifyId" jdbcType="VARCHAR"/>
        <result column="modify_code" property="modifyCode" jdbcType="VARCHAR"/>
        <result column="modify_name" property="modifyName" jdbcType="VARCHAR"/>
        <result column="modify_time" property="modifyTime" jdbcType="TIMESTAMP"/>
        <result column="cancel_id" property="cancelId" jdbcType="VARCHAR"/>
        <result column="cancel_code" property="cancelCode" jdbcType="VARCHAR"/>
        <result column="cancel_name" property="cancelName" jdbcType="VARCHAR"/>
        <result column="cancel_time" property="cancelTime" jdbcType="TIMESTAMP"/>
        <result column="cancel_flag" property="cancelFlag" jdbcType="VARCHAR"/>
        <result column="belong_id" property="belongId" jdbcType="VARCHAR"/>
        <result column="material_name" property="materialName" jdbcType="VARCHAR"/>
        <result column="material_code" property="materialCode" jdbcType="VARCHAR"/>
        <result column="material_standard" property="materialStandard" jdbcType="VARCHAR"/>
        <result column="material_model" property="materialModel" jdbcType="VARCHAR"/>
        <result column="material_attr1" property="materialAttr1" jdbcType="VARCHAR"/>
        <result column="material_attr2" property="materialAttr2" jdbcType="VARCHAR"/>
        <result column="material_attr3" property="materialAttr3" jdbcType="VARCHAR"/>
        <result column="material_attr4" property="materialAttr4" jdbcType="VARCHAR"/>
        <result column="material_attr5" property="materialAttr5" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, process_instance_id, process_instance_status, add_id, add_code, add_name, add_dept_id,
        add_dept_code, add_dept_name, add_time, modify_id, modify_code, modify_name, modify_time, cancel_id,
        cancel_code, cancel_name, cancel_time, cancel_flag, belong_id, material_name, material_code,
        material_standard, material_model, material_attr1, material_attr2, material_attr3, material_attr4, material_attr5
    </sql>

    <select id="selectMaterialPage" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from T_MAIN_MATERIAL
        where nvl(cancel_flag,'0') = '0'
        and belong_id = #{belongId}
        <if test="material != null and material != ''">
            and (material_name like '%' || #{material} || '%'
            or material_code like '%' || #{material} || '%')
        </if>
        <if test="standard != null and standard != ''">
            and material_standard like '%' || #{standard} || '%'
        </if>
        order by add_time desc
    </select>

    <select id="selectByMaterialName" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from T_MAIN_MATERIAL
        where nvl(cancel_flag,'0') = '0'
        and belong_id = #{belongId}
        and material_name = #{materialName}
    </select>

</mapper>