<?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.erp.dal.mysql.erp.ErpMaterialMapper">

    <!--
        一般情况下，尽可能使用 Mapper 进行 CRUD 增删改查即可。
        无法满足的场景，例如说多表关联查询，才使用 XML 编写 SQL。
        代码生成器暂时只生成 Mapper XML 文件本身，更多推荐 MybatisX 快速开发插件来生成查询。
        文档可见：https://www.iocoder.cn/MyBatis/x-plugins/
     -->


    <update id="updateBatchByNumber">
        <foreach collection="toUpdate" item="item" separator=";" open="BEGIN" close=";END;">
            UPDATE SPLY_ERP_MTRL
            <set>
                <if test="item.downCenterNumber != null">DOWN_CTR_NUM = #{item.downCenterNumber},</if>
                <if test="item.centerNumber != null">CTR_NUM = #{item.centerNumber},</if>
                <if test="item.createDate != null">CRT_DT = #{item.createDate},</if>
                <if test="item.materialType != null">MTRL_TP = #{item.materialType},</if>
                <if test="item.materialGroupDate != null">MTRL_GRP_DT = #{item.materialGroupDate},</if>
                <if test="item.externalMaterialGroupDate != null">EXT_MTRL_GRP_DT = #{item.externalMaterialGroupDate},</if>
                <if test="item.unit != null">UNT = #{item.unit},</if>
                <if test="item.unitDescription != null">UNT_DSP = #{item.unitDescription},</if>
                <if test="item.materialTypeDescription != null">MTRL_TP_DSP = #{item.materialTypeDescription},</if>
                <if test="item.materialGroupDescription != null">MTRL_GRP_DSP = #{item.materialGroupDescription},</if>
                <if test="item.externalMaterialGroupDescription != null">EXT_MTRL_GRP_DSP =#{item.externalMaterialGroupDescription},</if>
                <if test="item.materialName != null">MTRL_NAME = #{item.materialName},</if>
                <if test="item.materialLengthDescription != null">MTRL_LEN_DSP = #{item.materialLengthDescription},</if>
                <if test="item.type != null">TP = #{item.type},</if>
                <if test="item.tenantId != null">TENANT_ID = #{item.tenantId},</if>
            </set>
            WHERE DOWN_CTR_NUM = #{item.downCenterNumber}
        </foreach>
    </update>

    <select id="selectMaxCode" resultType="java.lang.String">
        SELECT MAX(MTRL_CODE) FROM SPLY_ERP_MTRL
    </select>

    <select id="selectByErpMId">
        SELECT * FROM SPLY_ERP_MTRL WHERE MTRL_ID = #{erpMId}
    </select>

    <select id="countByErpMNumbers" resultType="java.lang.Integer">
        SELECT COUNT(*)
        FROM sply_mtrl_oth
        WHERE ERP_MTRL_NUM IN
        <foreach item="erpMNumber" collection="erpMNumbers" open="(" separator="," close=")">
            #{erpMNumber}
        </foreach>
    </select>

</mapper>
