package com.fs.company.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fs.company.domain.CompanyTrafficRecord;
import com.fs.company.param.CompanyTrafficRecordQueryParam;
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 CompanyTrafficRecordMapper extends BaseMapper<CompanyTrafficRecord> {

    @Select("SELECT SUM(ctr.balance) FROM company_traffic_record ctr inner join company c on ctr.company_id = c.company_id and c.dept_id = #{deptId}")
    Long calculateTotalTrafficByDeptId(@Param("deptId") Long deptId);

    @Select({"<script>"+
                "SELECT ctr.id,c.company_id,c.company_name,ctr.balance from company c " +
                "LEFT JOIN company_traffic_record ctr on ctr.company_id = c.company_id " +
                "WHERE c.is_del = 0 "+
                "<if test = 'maps.companyIds != null'> " +
                "and c.company_id IN " +
                "<foreach collection='maps.companyIds'  item='item' index='index'  open='(' separator=',' close=')'> #{item} </foreach> "+
                "</if> " +
            "</script>"})
    List<CompanyTrafficRecord> selectListWithUncharged(@Param("maps") CompanyTrafficRecordQueryParam record);
}
