package com.hzs.system.sys.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.domain.system.sys.SysApprovalBusinessDetail;
import com.hzs.system.sys.mapper.SysApprovalBusinessDetailMapper;
import com.hzs.system.sys.service.ISysApprovalBusinessDetailService;
import org.springframework.stereotype.Service;

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

/**
 * 审批业务明细表 服务实现类
 *
 * @author hzs
 * @since 2022-09-21
 */
@Service
public class SysApprovalBusinessDetailServiceImpl extends ServiceImpl<SysApprovalBusinessDetailMapper, SysApprovalBusinessDetail> implements ISysApprovalBusinessDetailService {

    @Override
    public int insertBatch(List<SysApprovalBusinessDetail> list) {
        return baseMapper.insertBatch(list);
    }

    @Override
    public Integer detailExistByUserAndDept(Long userId, Long deptId) {
        return baseMapper.detailExistByUserAndDept(userId, deptId);
    }

    @Override
    public List<SysApprovalBusinessDetail> approvalBusinessList(List<Long> pkIdList) {
        return baseMapper.approvalDetailList(pkIdList);
    }

    @Override
    public Map<Long, List<SysApprovalBusinessDetail>> approvalBusinessMap(List<Long> pkIdList) {
        Map<Long, List<SysApprovalBusinessDetail>> resultMap = new HashMap<>();

        List<SysApprovalBusinessDetail> list = baseMapper.approvalDetailList(pkIdList);
        if (CollectionUtil.isNotEmpty(list)) {
            // 明细列表转map
            resultMap = list.stream().collect(Collectors.groupingBy(SysApprovalBusinessDetail::getPkApprovalBusiness));
        }

        return resultMap;
    }

    /**
     * 查询终审信息
     *
     * @param pkApprovalBusiness
     * @return
     */
    @Override
    public SysApprovalBusinessDetail selectByMaxApprovalBusinessDetailInfo(Long pkApprovalBusiness) {
        return baseMapper.selectByMaxApprovalBusinessDetailInfo(pkApprovalBusiness);
    }

}
