InventoryChangesMapper.xml 1.39 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.inventory.report.mapper.InventoryChangesMapper">

    <select id="select" resultType="com.huaheng.pc.inventory.report.domain.InventoryChanges">
        select a.created,IFNULL(count,0)  count,materialCode from (
        select DATE_FORMAT(d.m, '%Y-%m') created
        from(
        select
        ( #{startTime} -  INTERVAL DAYOFMONTH(#{endTime})-1 DAY)
        +INTERVAL m MONTH as m
        from(
        select @rownum:=@rownum+1 as m from
        (select 1 union select 2 union select 3 union select 4) t1,
        (select 1 union select 2 union select 3 union select 4) t2,
        (select 1 union select 2 union select 3 union select 4) t3,
        (select 1 union select 2 union select 3 union select 4) t4,
        (select @rownum:=-1) t
        ) d1
        ) d
        where m &lt;= #{endTime}
        order by created ) a left join
        (SELECT
        DATE_FORMAT( created, '%Y-%m' ) created,
        sum( qty ) count,
        materialCode
        FROM
        snapshot_inventory_detail  where 1 = 1
        <if test="materialCode != null">
            and materialCode = #{materialCode}
        </if>
        GROUP BY DATE_FORMAT( created, '%Y-%m' )
        ) t on t.created = a.created
    </select>
</mapper>