package com.kcim.dao.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kcim.common.constants.NumberConstant;
import com.kcim.common.util.UserContext;
import com.kcim.dao.mapper.ShareParamCostDetailMapper;
import com.kcim.dao.model.ShareParamCostDetail;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * @program: CostAccount
 * @description:
 * @author: Wang.YS
 * @create: 2024-01-19 15:15
 **/
@Repository
public class ShareParamCostDetailRepository extends ServiceImpl<ShareParamCostDetailMapper, ShareParamCostDetail> {
    public List<ShareParamCostDetail> getByShareColumnCode(List<String> collect) {
        LambdaQueryWrapper<ShareParamCostDetail> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ShareParamCostDetail::getHospId, UserContext.getHospId());
        queryWrapper.in(ShareParamCostDetail::getShareParamColumnCode, collect);
        return this.list(queryWrapper);
    }

    public void removeByShareParamColumnCode(String shareParamColumnCode) {
        LambdaUpdateWrapper<ShareParamCostDetail> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(ShareParamCostDetail::getHospId, UserContext.getHospId())
                .eq(ShareParamCostDetail::getShareParamColumnCode, shareParamColumnCode)
                .set(ShareParamCostDetail::getDelFlag, NumberConstant.ONE)
                .set(ShareParamCostDetail::getDeleteUser,String.valueOf(UserContext.getCurrentUser().getId()))
                .set(ShareParamCostDetail::getDeleteTime,new Date());
        this.update(updateWrapper);

    }
}
