package com.yd.csf.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yd.csf.service.model.SalaryRemittance;
import com.yd.csf.service.dao.SalaryRemittanceMapper;
import com.yd.csf.service.service.ISalaryRemittanceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 薪资汇款明细表 服务实现类
 * </p>
 *
 * @author zxm
 * @since 2026-05-08
 */
@Service
public class SalaryRemittanceServiceImpl extends ServiceImpl<SalaryRemittanceMapper, SalaryRemittance> implements ISalaryRemittanceService {

    @Override
    public Boolean delBySalaryBizId(String salaryBizId) {
        return this.remove(new LambdaQueryWrapper<SalaryRemittance>()
                .eq(SalaryRemittance::getSalaryBizId,salaryBizId));
    }

    @Override
    public List<SalaryRemittance> queryList(String salaryBizId) {
        return this.baseMapper.selectList(new LambdaQueryWrapper<SalaryRemittance>()
        .eq(SalaryRemittance::getSalaryBizId,salaryBizId));
    }

    @Override
    public SalaryRemittance queryOne(String salaryRemittanceBizId) {
        return this.baseMapper.selectOne(new LambdaQueryWrapper<SalaryRemittance>()
                .eq(SalaryRemittance::getSalaryRemittanceBizId,salaryRemittanceBizId)
                .last(" limit 1 "));
    }

    @Override
    public Map<String, List<SalaryRemittance>> queryListBySalaryBizIds(List<String> salaryBizIds) {
        if (CollectionUtils.isEmpty(salaryBizIds)) {
            return java.util.Collections.emptyMap();
        }
        // 批量查询
        List<SalaryRemittance> list = this.baseMapper.selectList(
                new LambdaQueryWrapper<SalaryRemittance>()
                        .in(SalaryRemittance::getSalaryBizId, salaryBizIds)
                        .orderByAsc(SalaryRemittance::getCreateTime) // 按需排序
        );
        // 按 salaryBizId 分组
        return list.stream()
                .collect(Collectors.groupingBy(SalaryRemittance::getSalaryBizId));
    }
}
