<?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.TpFishCatchRecordMapper">
    <resultMap type="com.ltgk.catches.domain.entity.TpFishCatchRecord" id="TpFishCatchRecordResult">
        <result property="id" column="id"/>
        <result property="catchId" column="catch_id"/>
        <result property="portId" column="port_id"/>
        <result property="portName" column="port_name"/>
        <result property="fishName" column="fish_name"/>
        <result property="fishType" column="fish_type"/>
        <result property="weight" column="weight"/>
        <result property="weighTime" column="weigh_time"/>
        <result property="photo" column="photo"/>
        <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="findFishCatchStatsList" resultType="com.ltgk.catches.domain.vo.TpFishCatchStatsVO">
        SELECT a.fish_name AS fishName,
        SUM(a.weight) AS weight
        FROM tp_fish_catch_record a
        LEFT JOIN tp_fish_catch b ON b.id = a.catch_id
        <where>
            <if test="params.portId != null">
                AND b.port_id = #{params.portId}
            </if>
            <if test="params.scaleNo != null and params.scaleNo != ''">
                AND b.scale_no = #{params.scaleNo}
            </if>
            <if test="params.beginTime != null and params.beginTime != ''">
                AND b.land_time &gt;= #{params.beginTime}
            </if>
            <if test="params.endTime != null and params.endTime != ''">
                AND b.land_time &lt;= #{params.endTime}
            </if>
        </where>
        GROUP BY a.fish_name
    </select>
</mapper>