package com.yuchen.saas.park.service.mapper.property;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuchen.saas.park.api.entity.property.PropertyShareFeeDetail;
import com.yuchen.saas.park.api.vo.property.PropertyShareFeeDetailListVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

public interface PropertyShareFeeDetailMapper extends BaseMapper<PropertyShareFeeDetail> {


    @Select("SELECT d.id,b.building_name,d.house_id,h.house_name,h.construction_area,d.share_amt_fen" +
            " from property_share_fee_detail d" +
            " LEFT JOIN property_houses h on d.house_id = h.id" +
            " LEFT JOIN property_buildings b on h.building_id = b.id" +
            " where d.share_fee_id = #{shareFeeId}" +
            " ORDER BY b.building_name,h.house_name")
    Page<PropertyShareFeeDetailListVo> selectDetailPage(Page<PropertyShareFeeDetailListVo> page, @Param("shareFeeId") String shareFeeId);


    @Select("select h.construction_area,d.* from property_share_fee_detail d" +
            " LEFT JOIN property_houses h on d.house_id = h.id" +
            " where d.share_fee_id = #{shareFeeId}")
    List<PropertyShareFeeDetail> listAreaDetail(@Param("shareFeeId") Long shareFeeId);


    @Select("SELECT sum(h.construction_area) as total_area from property_share_fee_detail d" +
            " LEFT JOIN property_houses h on d.house_id = h.id" +
            " where share_fee_id = #{shareFeeId}")
    BigDecimal getTotalArea(@Param("shareFeeId") Long shareFeeId);

}
