<?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="org.springblade.modules.investment.mapper.IbaProjectVolumeMapper">

    <resultMap id="BaseResultMap" type="org.springblade.modules.investment.pojo.entity.IbaProjectVolume">
            <id property="id" column="id" />
            <result property="projectId" column="project_id" />
            <result property="year" column="year" />
            <result property="month" column="month" />
            <result property="number" column="number" />
            <result property="isDeleted" column="is_deleted" />
            <result property="createTime" column="create_time" />
            <result property="createUser" column="create_user" />
            <result property="updateTime" column="update_time" />
            <result property="updateUser" column="update_user" />
    </resultMap>
    <resultMap id="groupYear" type="org.springblade.modules.investment.pojo.dto.IbaProjectVolumeDTO">
        <result column="project_id" property="projectId"/>
        <result column="year" property="year"/>
        <collection property="numbers" ofType="java.lang.Integer"
                    javaType="java.util.List"
                    select="selectMonthByYearList" column="{id=project_id,year=year}">
            <result column="number"/>
        </collection>
    </resultMap>


    <sql id="Base_Column_List">
        id,project_id,year,month,number,is_deleted,
        create_time,create_user,update_time,update_user
    </sql>
    <update id="updateIsDeleted">
        UPDATE iba_project SET is_deleted = #{isDeleted} WHERE id IN
        <foreach item="id" collection="ids" separator="," open="(" close=")" index="">
            #{id}
        </foreach>
    </update>
    <select id="selectGroupYearList"
            resultMap="groupYear">
        select project_id,`year`,`number` from iba_project_volume where project_id = #{id} and is_deleted = 0
        group by year
        order by year, month
    </select>
    <select id="selectMonthByYearList"
            resultType="java.lang.Integer">
        select `number` from iba_project_volume
        where project_id = #{id}
        and year = #{year}
        and is_deleted = 0
        order by month
    </select>
</mapper>
