<?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.ltgk.catches.mapper.TpFishCatchMapper">
    <resultMap type="com.ltgk.catches.domain.entity.TpFishCatch" id="TpFishCatchResult">
        <result property="id" column="id"/>
        <result property="portId" column="port_id"/>
        <result property="portName" column="port_name"/>
        <result property="landPort" column="land_port"/>
        <result property="boatName" column="boat_name"/>
        <result property="fishWeight" column="fish_weight"/>
        <result property="landTime" column="land_time"/>
        <result property="batchCode" column="batch_code"/>
        <result property="infoCodeUrl" column="info_code_url"/>
        <result property="infoSource" column="info_source"/>
        <result property="scaleNo" column="scale_no"/>
        <result property="operator" column="operator"/>
        <result property="operatorPhone" column="operator_phone"/>
        <result property="delFlag" column="del_flag"/>
        <result property="areaCode" column="area_code"/>
        <result property="areaName" column="area_name"/>
        <result property="createBy" column="create_by"/>
        <result property="createAt" column="create_at"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateAt" column="update_at"/>
        <result property="remark" column="remark"/>
    </resultMap>
    <select id="getRangeTotalNum" resultType="java.math.BigDecimal">
        select sum(fish_weight)
        from tp_fish_catch
        where land_time &gt;= STR_TO_DATE(#{startTime}, '%Y-%m-%d %H:%i:%s')
        AND land_time &lt;= STR_TO_DATE(#{endTime}, '%Y-%m-%d %H:%i:%s')
    </select>

    <select id="getTodayTotalWeight" resultType="java.math.BigDecimal">
        select sum(fish_weight)
        from tp_fish_catch
        where land_time &gt;= #{startTime}
        <if test="infoSource != null">
            and info_source = #{infoSource}
        </if>
        and del_flag = 0
    </select>

    <select id="getCatchesTrain" resultType="com.ltgk.catches.domain.vo.CatchesTrainVo">
        select date_format(land_time, '%Y-%m') as date, sum(fish_weight) as weight, count(id) as boatNum
        from tp_fish_catch
        where land_time &gt;= STR_TO_DATE(#{startTime}, '%Y-%m-%d %H:%i:%s')
        AND land_time &lt;= STR_TO_DATE(#{endTime}, '%Y-%m-%d %H:%i:%s')
        AND del_flag = 0
        group by date
        order by date
    </select>

    <select id="getCatchesProportion" resultType="com.ltgk.catches.domain.vo.CatchesProportionVo">
        select tcr.fish_name as fishName, sum(tcr.weight) as weight
        from tp_fish_catch_record as tcr
        left join tp_fish_catch as tfc on tcr.catch_id = tfc.id
        where tfc.land_time &gt;= STR_TO_DATE(#{startTime}, '%Y-%m-%d %H:%i:%s')
        AND tfc.land_time &lt;= STR_TO_DATE(#{endTime}, '%Y-%m-%d %H:%i:%s')
        AND tcr.del_flag = 0
        group by fishName
        order by weight desc
    </select>

    <select id="getCatchesPriceList" resultType="com.ltgk.catches.domain.vo.CatchesPriceVo">
        select p1.product_name as productName, p1.trading_time as tradingTime, p1.avg_price as avgPrice
        from tp_aquatic_product_price as p1
                 join (select product_name, max(trading_time) as trading_time
                       from tp_aquatic_product_price
                       group by product_name) as p2
                      on p1.product_name = p2.product_name and p1.trading_time = p2.trading_time
        order by p1.avg_price desc
    </select>
</mapper>