package com.kcim.dao.repository;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
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.ComputeShareParamDetailMapper;
import com.kcim.dao.model.ComputeShareParamDetail;
import com.kcim.vo.ComputeDateShareParamVo;
import com.kcim.vo.SessionUserVO;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * @program: CostAccount
 * @description:
 * @author: Wang.YS
 * @create: 2024-01-15 20:34
 **/
@Repository
public class ComputeShareParamDetailRepository extends ServiceImpl<ComputeShareParamDetailMapper, ComputeShareParamDetail> {
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    public void removeByComputeDate(String computeDate, SessionUserVO currentUser) {
        UpdateWrapper<ComputeShareParamDetail> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().eq(ComputeShareParamDetail::getDelFlag, NumberConstant.ZERO)
                .eq(ComputeShareParamDetail::getHospId, currentUser.getHospId())
                .eq(ComputeShareParamDetail::getComputeDate, computeDate)
                .set(ComputeShareParamDetail::getDeleteTime,new Date())
                .set(ComputeShareParamDetail::getDeleteUser,String.valueOf(currentUser.getId()))
                .set(ComputeShareParamDetail::getDelFlag, NumberConstant.ONE);
        this.update(updateWrapper);
    }

    public List<ComputeDateShareParamVo> getByShareParamId(String computeDate, List<Integer> collect1) {
        return this.baseMapper.getByShareParamId( computeDate, UserContext.getHospId(),collect1);

    }
}
