package com.kcim.dao.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.kcim.common.util.UserContext;
import com.kcim.dao.mapper.ComputeProjectCostAccountMapper;
import com.kcim.dao.model.ComputeProjectCostAccount;
import com.kcim.service.impl.BaseBatchServiceImpl;
import com.kcim.vo.HospitalServiceProjectCostVO;
import com.kcim.vo.SessionUserVO;
import org.springframework.stereotype.Repository;

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

/**
 * @program: CostAccount
 * @description:
 * @author: Wang.YS
 * @create: 2023-11-27 17:52
 **/
@Repository
public class ComputeProjectCostAccountRepository extends BaseBatchServiceImpl<ComputeProjectCostAccountMapper, ComputeProjectCostAccount> {
    public List<ComputeProjectCostAccount> getList(String computeDate) {
        LambdaQueryWrapper<ComputeProjectCostAccount> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ComputeProjectCostAccount::getHospId, UserContext.getHospId());
        queryWrapper.eq(ComputeProjectCostAccount::getComputeDate, computeDate);
        return this.list(queryWrapper);
    }

    public List<HospitalServiceProjectCostVO> getMedicalServiceCostDetailList(String computeDate) {
        return this.baseMapper.getMedicalServiceCostDetailList(computeDate, UserContext.getHospId());
    }

    public void removeByComputeDate(String computeDate, SessionUserVO currentUser) {
        UpdateWrapper<ComputeProjectCostAccount> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().eq(ComputeProjectCostAccount::getDelFlag, 0)
                .eq(ComputeProjectCostAccount::getHospId, currentUser.getHospId())
                .eq(ComputeProjectCostAccount::getComputeDate, computeDate)
                .set(ComputeProjectCostAccount::getDeleteTime,new Date())
                .set(ComputeProjectCostAccount::getDeleteUser,String.valueOf(currentUser.getId()))
                .set(ComputeProjectCostAccount::getDelFlag, 1);
        this.update(updateWrapper);
    }
}
