package com.kcim.dao.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kcim.common.util.UserContext;
import com.kcim.dao.mapper.HistoryMatchMapper;
import com.kcim.dao.model.HistoryMatch;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

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

/**
 * @program: CostAccount
 * @description:
 * @author: Wang.YS
 * @create: 2024-03-12 16:51
 **/
@Repository
public class HistoryMatchRepository extends ServiceImpl<HistoryMatchMapper, HistoryMatch> {
    public List<HistoryMatch> getList() {
        return this.list();

    }

    public List<HistoryMatch> getByFilter(String name, String code, String name1) {
        LambdaQueryWrapper<HistoryMatch> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HistoryMatch::getName,name);
        queryWrapper.eq(HistoryMatch::getStandItemCode,code);
        queryWrapper.eq(HistoryMatch::getStandItemName,name1);
       return this.list(queryWrapper);
    }


    public void removeByItemCode(String itemCode) {
        LambdaQueryWrapper<HistoryMatch> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HistoryMatch::getHospId, UserContext.getHospId());
        queryWrapper.eq(HistoryMatch::getCode,itemCode);
        List<HistoryMatch> list = this.list(queryWrapper);
        if(!CollectionUtils.isEmpty(list)){
            List<Integer> collect = list.stream().map(HistoryMatch::getId).collect(Collectors.toList());
            this.removeByIds(collect);
        }
    }
}
