package com.kcim.dao.repository;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kcim.common.enums.DateStyleEnum;
import com.kcim.common.util.DateUtils;
import com.kcim.common.util.UserContext;
import com.kcim.dao.mapper.CostCostingGroupMapper;
import com.kcim.dao.model.CostCostingGroup;
import org.springframework.stereotype.Repository;

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

/**
 * @program: CostAccount
 * @description:
 * @author: Wang.YS
 * @create: 2024-04-07 10:34
 **/
@Repository
public class CostCostingGroupRepository extends ServiceImpl<CostCostingGroupMapper, CostCostingGroup> {
    public List<CostCostingGroup> getList(String computeDate) {
        int year = 0;
        int month = 0;
        if (StrUtil.isNotBlank(computeDate)) {
            Date dateTime = DateUtils.StringToDate(computeDate, DateStyleEnum.YYYY_MM);
            year = DateUtil.year(dateTime);
            month = DateUtil.month(dateTime) + 1;
        }
        LambdaQueryWrapper<CostCostingGroup> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CostCostingGroup::getHospId, UserContext.getHospId());
        queryWrapper.eq(CostCostingGroup::getDateYear,year);
        queryWrapper.eq(CostCostingGroup::getDateMonth,month);
        return this.list(queryWrapper);


    }
}
