package com.kcim.dao.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.kcim.common.constants.NumberConstant;
import com.kcim.common.util.UserContext;
import com.kcim.dao.mapper.CostDepartmentProfitAccountMapper;
import com.kcim.dao.model.CostDepartmentProfitAccount;
import com.kcim.service.impl.BaseBatchServiceImpl;
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 CostDepartmentProfitAccountRepository extends BaseBatchServiceImpl<CostDepartmentProfitAccountMapper, CostDepartmentProfitAccount> {
    public List<CostDepartmentProfitAccount> getList(String computeDate) {
        LambdaQueryWrapper<CostDepartmentProfitAccount> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CostDepartmentProfitAccount::getHospId, UserContext.getHospId());
        queryWrapper.eq(CostDepartmentProfitAccount::getComputeDate, computeDate);
        return this.list(queryWrapper);
    }


    /**
     * 删除科室损益的会计科目金额表
     * @param computeDate
     * @return
     */
    public boolean deleteDeptProfitAccount(String computeDate) {
        return deleteDeptProfitAccountWithUser(UserContext.getHospId(),computeDate,UserContext.getCurrentUser().getId());
    }

    public boolean deleteDeptProfitAccountWithUser(Long hospId,String computeDate,Long userId) {
        LambdaUpdateWrapper<CostDepartmentProfitAccount> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(CostDepartmentProfitAccount::getHospId, hospId);
        updateWrapper.eq(CostDepartmentProfitAccount::getComputeDate, computeDate);
        updateWrapper.eq(CostDepartmentProfitAccount::getDelFlag, NumberConstant.ZERO);
        updateWrapper.set(CostDepartmentProfitAccount::getDelFlag, NumberConstant.ONE);
        updateWrapper.set(CostDepartmentProfitAccount::getDeleteTime,new Date());
        updateWrapper.set(CostDepartmentProfitAccount::getDeleteUser, userId);
        return this.update(updateWrapper);
    }
}
