<?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="vip.xiaonuo.purchase.mapper.PurchaseOrderMapper">


    <select id="listType" resultType="vip.xiaonuo.purchase.entity.vo.PurchaseOrderTypeVo">
        select material as 'material',
        IFNULL(sum(case when create_time >=#{month} then purchase_money else 0 end),'0') as 'monthMoney',
        IFNULL(sum(case when create_time >=#{year} then purchase_money else 0 end),'0') as 'yearMoney',
        IFNULL(sum(case when create_time between '${lastMonth}-01 00:00:00' and '${lastMonth}-31 23:59:59' then purchase_money else 0 end),'0') as 'lastMonthMoney',
        IFNULL(sum(case when create_time between '${lastYear}-01-01 00:00:00' and '${lastYear}-12-31 23:59:59' then purchase_money else 0 end),'0') as 'lastYearMoney'
        from purchase_order
        <if test="orgId!=null and orgId!=''">
            where org_id=#{orgId}
        </if>
        group by material
    </select>

    <select id="getSupplier" resultType="vip.xiaonuo.purchase.entity.vo.PurchaseMaterialVo">
        select IFNULL(sum(purchase_money),'0') as 'value',supplier as 'name' from purchase_order
        ${ew.customSqlSegment}
        group by supplier
    </select>
</mapper>
