<?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.th.demo.mapping.home.HomeMapper" >
    <resultMap id="BaseResultMap" type="com.th.demo.model.home.HomeValue" >
        <result column="value1" property="value1" jdbcType="VARCHAR" />
        <result column="value2" property="value2" jdbcType="VARCHAR" />
        <result column="value3" property="value3" jdbcType="VARCHAR" />
    </resultMap>

    <select id="selectdrawLine1" resultMap="BaseResultMap" >
        SELECT CC.MONTH_NUM AS value1 , (CC.inweight + CC.outweight) AS value2
        FROM (select SUBSTR(A.date_note,6) AS MONTH_NUM , A.weight as inweight , IFNULL(B.weight,0) as outweight,A.date_note
              from (select sum(twir.weight) weight ,DATE_FORMAT(twir.add_time,'%Y-%m') as date_note
                    from t_ware_in_record twir where twir.cancel_flag ='0' group by date_note) A
                       LEFT JOIN (select sum(twor.weight) weight,DATE_FORMAT(twor.add_time,'%Y-%m') as date_note
                                  from t_ware_out_record twor where twor.cancel_flag ='0' group by date_note) B
                                 ON A.date_note = B.date_note ORDER BY A.date_note DESC LIMIT 12) CC ORDER BY date_note;
    </select>

    <select id="selectdrawLine2" resultMap="BaseResultMap" parameterType="java.lang.String" >
        SELECT tmm.name AS value1,sum(tws.weight) as value2 FROM t_ware_store tws, t_maint_material tmm
        where 1=1 AND tws.material_id = tmm.id
          AND tws.cancel_flag ='0' and tws.out_flag ='0' and tws.lock_flag ='0' group by tmm.name order by value2 desc
    </select>

    <select id="selectdrawLine3" resultMap="BaseResultMap" parameterType="java.lang.String" >
        SELECT CC.MONTH_NUM AS value1 , CC.inweight AS value2, CC.outweight AS value3
        FROM (select SUBSTR(A.date_note,6) AS MONTH_NUM , A.weight as inweight , IFNULL(B.weight,0) as outweight,A.date_note
              from (select sum(twir.weight) weight ,DATE_FORMAT(twir.add_time,'%Y-%m') as date_note
                    from t_ware_in_record twir where twir.cancel_flag ='0' group by date_note) A
                       LEFT JOIN (select sum(twor.weight) weight,DATE_FORMAT(twor.add_time,'%Y-%m') as date_note
                                  from t_ware_out_record twor where twor.cancel_flag ='0' group by date_note) B
                                 ON A.date_note = B.date_note ORDER BY A.date_note DESC LIMIT 12) CC ORDER BY date_note;
    </select>

    <select id="selectdrawLine4" resultMap="BaseResultMap" parameterType="java.lang.String" >
        select (select count(A.stack_id) from
            (select DISTINCT tws.stack_id from t_ware_store tws
             where tws.cancel_flag ='0' and tws.out_flag ='0' and tws.lock_flag ='0') A)/count(*)*100 AS value1
        from t_maint_stack tms where tms.cancel_flag ='0'
    </select>

</mapper>