package com.sky.ioc.mapper.operation;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sky.ioc.entity.domain.operation.Asset;
import com.sky.ioc.entity.params.IocParam;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AssetMapper extends BaseMapper<Asset> {

    @Select("<script> " +
            "select coalesce(sum(worth),0) from asset where  1=1 " +
            "<if test='iocParam!=null and iocParam.deptId!=null '>" +
            " and dept_id = #{iocParam.deptId} " +
            "</if>" +
            "</script>")
    Double getTotalWorth(@Param("iocParam")IocParam iocParam);

    @Select("<script> " +
            "select coalesce(count(1),0) from asset where  1=1 " +
            "<if test='iocParam!=null and iocParam.deptId!=null '>" +
            " and dept_id = #{iocParam.deptId} " +
            "</if>" +
            "</script>")
    Integer getTotalCount(@Param("iocParam")IocParam iocParam);

    @Select("<script> " +
            "select name,worth from asset where 1=1 " +
            "<if test='iocParam!=null and iocParam.deptId!=null '>" +
            " and dept_id = #{iocParam.deptId} " +
            "</if>" +
            "order by worth desc " +
            "</script>")
    List<Asset> topList(@Param("iocParam")IocParam iocParam);
}
