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.ShareParamCostMapper;
import com.kcim.dao.model.ShareParamCost;
import com.kcim.vo.ShareParamCostVo;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @program: CostAccount
 * @description: 成本分摊参数设置数据库交互
 * @author: Wang.YS
 * @create: 2024-01-17 20:31
 **/
@Repository
public class ShareParamCostRepository extends ServiceImpl<ShareParamCostMapper, ShareParamCost> {
    public List<ShareParamCostVo> getParamCost() {
        return this.baseMapper.getParamCost(UserContext.getHospId());
    }

    public List<ShareParamCost> getList(String filter) {
        LambdaQueryWrapper<ShareParamCost> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ShareParamCost::getHospId,UserContext.getHospId());
        if(!StringUtils.isEmpty(filter)){
            queryWrapper.and(q-> q.like(ShareParamCost::getColumnCode,filter).or().like(ShareParamCost::getColumnName,filter));
        }
        return this.list(queryWrapper);

    }

    public ShareParamCost getByParamCode(String columnCode) {
        LambdaQueryWrapper<ShareParamCost> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ShareParamCost::getHospId,UserContext.getHospId());
        queryWrapper.eq(ShareParamCost::getColumnCode,columnCode);

        return this.getOne(queryWrapper);
    }
}
