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.util.UserContext;
import com.kcim.dao.mapper.ItemNoValuationDrugMaterialMapMapper;
import com.kcim.dao.model.ItemNoValuationDrugMaterialMap;
import org.springframework.stereotype.Repository;

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

/**
 * @program: CostAccount
 * @description: 医疗服务项目不计价药品材料对照数据互交互
 * @author: Wang.YS
 * @create: 2024-01-11 17:16
 **/
@Repository
public class ItemNoValuationDrugMaterialMapRepository extends ServiceImpl<ItemNoValuationDrugMaterialMapMapper, ItemNoValuationDrugMaterialMap> {
    public void removeByItemCode(List<String> collect) {
        LambdaUpdateWrapper<ItemNoValuationDrugMaterialMap> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(ItemNoValuationDrugMaterialMap::getDelFlag,0)
                .eq(ItemNoValuationDrugMaterialMap::getHospId, UserContext.getHospId())
                .in(ItemNoValuationDrugMaterialMap::getItemCode,collect)
                .set(ItemNoValuationDrugMaterialMap::getDelFlag,1)
                .set(ItemNoValuationDrugMaterialMap::getDeleteUser,String.valueOf(UserContext.getCurrentUser().getId()))
                .set(ItemNoValuationDrugMaterialMap::getDeleteTime,new Date());
        this.update(updateWrapper);
    }

    public List<ItemNoValuationDrugMaterialMap> getList() {
        LambdaQueryWrapper<ItemNoValuationDrugMaterialMap> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ItemNoValuationDrugMaterialMap::getHospId, UserContext.getHospId());
        return this.list(queryWrapper);
    }

    public List<ItemNoValuationDrugMaterialMap> getList(String itemCode) {
        LambdaQueryWrapper<ItemNoValuationDrugMaterialMap> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ItemNoValuationDrugMaterialMap::getHospId, UserContext.getHospId());
        queryWrapper.eq(ItemNoValuationDrugMaterialMap::getItemCode, itemCode);

        return this.list(queryWrapper);
    }

    public List<ItemNoValuationDrugMaterialMap> getByItemCode(String itemCode) {
        LambdaQueryWrapper<ItemNoValuationDrugMaterialMap> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ItemNoValuationDrugMaterialMap::getHospId, UserContext.getHospId());
        queryWrapper.eq(ItemNoValuationDrugMaterialMap::getItemCode, itemCode);
        return this.list(queryWrapper);
    }

    public List<ItemNoValuationDrugMaterialMap> getList(String itemCode, String departmentCode) {
        LambdaQueryWrapper<ItemNoValuationDrugMaterialMap> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ItemNoValuationDrugMaterialMap::getHospId, UserContext.getHospId());
        queryWrapper.eq(ItemNoValuationDrugMaterialMap::getItemCode, itemCode);
        queryWrapper.eq(ItemNoValuationDrugMaterialMap::getDepartmentCode, departmentCode);
        return this.list(queryWrapper);
    }
}
