<?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.zt.plat.module.base.dal.mysql.masterdata.MdmMaterialViewMapper">

    <sql id="baseColumns">
        a.codeid            AS code_id,
        a.desc86             AS material_code,
        a.categorycode       AS category_code,
        a.categoryname       AS category_name,
        a.desc1              AS material_name,
        a.desc6              AS base_unit_code,
        a.desc19             AS base_unit_name,
        a.descshort          AS short_description,
        a.desclong           AS long_description,
        a.desc86             AS chalco_code,
        a.code               AS zhongtong_code,
        b.pur_class          AS major_class_code,
        c.desc1              AS major_class_name,
        a.desc9              AS specification,
        a.desc10             AS model,
        a.desc11             AS texture,
        a.desc12             AS drawing_number,
        a.desc13             AS order_number,
        a.desc14             AS other_parameters,
        a.desc15             AS equipment_category,
        a.desc16             AS manufacturer,
        a.desc17             AS source,
        a.recordtime         AS record_time
    </sql>

    <sql id="fromClause">
        mdm_wlzsj_code a
        INNER JOIN z_pur_class b ON a.codeid = b.codeid
        INNER JOIN mdm_wlfl_code c ON b.pur_class = c.code
    </sql>

    <select id="selectSlice" resultType="com.zt.plat.module.base.dal.dataobject.masterdata.MdmMaterialViewDO">
        SELECT
        <include refid="baseColumns"/>
        FROM
        <include refid="fromClause"/>
        WHERE a.auditflag = 2
        <if test="since != null">
            AND a.recordtime &gt;= #{since}
        </if>
        <if test="codes != null and codes.size > 0">
            AND a.code IN
            <foreach collection="codes" item="code" open="(" separator="," close=")">
                #{code}
            </foreach>
        </if>
        ORDER BY a.CODEID
        LIMIT #{limit} OFFSET #{offset}
    </select>

    <select id="countEligible" resultType="long">
        SELECT COUNT(1)
        FROM
        <include refid="fromClause"/>
        WHERE a.auditflag = 2
        <if test="since != null">
            AND a.recordtime &gt;= #{since}
        </if>
        <if test="codes != null and codes.size > 0">
            AND a.code IN
            <foreach collection="codes" item="code" open="(" separator="," close=")">
                #{code}
            </foreach>
        </if>
    </select>
</mapper>
