<?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.huimv.admin.mapper.ProdStockMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.huimv.admin.entity.ProdStock">
        <id column="id" property="id" />
        <result column="MZCL" property="mzcl" />
        <result column="GZCL" property="gzcl" />
        <result column="BRZCL" property="brzcl" />
        <result column="BYZCL" property="byzcl" />
        <result column="YFZCL" property="yfzcl" />
        <result column="HBZCL" property="hbzcl" />
        <result column="RSZCL" property="rszcl" />
        <result column="BRMZCL" property="brmzcl" />
        <result column="KHZCL" property="khzcl" />
        <result column="SPZCL" property="spzcl" />
        <result column="creat_time" property="creatTime" />
        <result column="farm_id" property="farmId" />
        <result column="other2" property="other2" />
        <result column="other3" property="other3" />
    </resultMap>
<select id="listDay" resultType="com.huimv.admin.entity.ProdStock">
    SELECT t.*
        FROM `prod_stock` t
        JOIN (
          SELECT DATE_FORMAT(creat_time, '%Y-%m') AS `month`, MAX(id) AS max_id
          FROM `prod_stock`
          GROUP BY DATE_FORMAT(creat_time, '%Y-%m') ,farm_id
        ) m ON DATE_FORMAT(t.creat_time, '%Y-%m') = m.month AND t.id = m.max_id
    ${ew.customSqlSegment}
    </select>
        <select id="sumInPig" resultType="java.lang.Integer">

           SELECT  IFNULL(SUM(in_pig) ,0)FROM `prod_stock` ${ew.customSqlSegment}
        </select>
    <select id="sumOutPig" resultType="java.lang.Integer">
           SELECT IFNULL(SUM(out_pig),0) FROM `prod_stock`${ew.customSqlSegment}
    </select>
</mapper>
