MaterialWarningMapper.xml 3.93 KB
<?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.huaheng.pc.config.materialWarnning.mapper.MaterialWarningMapper">

    <resultMap type="com.huaheng.pc.config.materialWarnning.domain.MaterialWarning" id="materialWarningResult">
        <result property="id"    column="id"    />
        <result property="alarmType"    column="alarmType"    />
        <result property="warehouseCode"    column="warehouseCode"    />
        <result property="companyCode"    column="companyCode"    />
        <result property="materialCode"    column="materialCode"    />
        <result property="materialName"    column="materialName"    />
        <result property="materialSpec"    column="materialSpec"    />
        <result property="materialUnit"    column="materialUnit"    />
        <result property="max"    column="max"    />
        <result property="min"    column="min"    />
        <result property="upper"    column="upper"    />
        <result property="lower"    column="lower"    />
        <result property="remark"    column="remark"    />
        <result property="created"    column="created"    />
        <result property="createdBy"    column="createdBy"    />
        <result property="lastUpdated"    column="lastUpdated"    />
        <result property="lastUpdatedBy"    column="lastUpdatedBy"    />
        <result property="userId"    column="userId"    />
        <result property="userName"    column="userName"    />
        <result property="email"    column="email"    />
    </resultMap>
	<sql id="selectmaterialWarningVo">
        select id, alarmType, warehouseCode, companyCode, materialCode, materialName, materialSpec, materialUnit, max, min, upper, lower, remark, created, createdBy, lastUpdated, lastUpdatedBy, userId, userName, email from material_warning
    </sql>

    <select id="selectMaterialWarningList" resultType="com.huaheng.api.tv.domain.MaterialWarningList">
        <![CDATA[select m.qty,m.materialCode,mw.materialName,"预警" as type
                 from
                     (SELECT sum(qty) as qty,materialCode
                      FROM inventory_detail
                      GROUP BY materialCode) m
                         left join material_warning mw
                                   on mw.materialCode=m.materialCode
                 where m.qty>mw.upper or m.qty>mw.max
                 union
                 select m.qty,m.materialCode,mw.materialName,"缺料" as type
                 from
                     (SELECT sum(qty) as qty,materialCode
                      FROM inventory_detail
                      GROUP BY materialCode) m
                         left join material_warning mw
                                   on mw.materialCode=m.materialCode
                 where m.qty<mw.min  or m.qty<mw.lower
                 union
                 (select inventory.qty,m.code as materialCode,m.name as materialName,"正常" as type
                  from
                      (SELECT sum(qty) as qty,materialCode
                       FROM inventory_detail
                       GROUP BY materialCode) inventory
                          left join material m
                                    on m.code=inventory.materialCode
                          left join material_warning mw
                                    on mw.materialCode=m.code
                  where
                      inventory.qty>IFNULL(mw.min,0)  or inventory.qty>IFNULL(mw.lower,0)
                 )
        ]]>
    </select>

    <select id="selectWarningQuantity" resultType="java.lang.Integer">
        select if(sum(m.qty)is null,0,sum(m.qty))
        from
            (SELECT sum(qty) as qty,materialCode
             FROM inventory_detail
             GROUP BY materialCode) m
             left join material_warning mw
             on mw.materialCode=m.materialCode
        where m.qty>mw.upper or m.qty>mw.max
    </select>
</mapper>