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.ItemValuationDrugMaterialMapMapper;
import com.kcim.dao.model.ItemEquipmentMap;
import com.kcim.dao.model.ItemNoValuationDrugMaterialMap;
import com.kcim.dao.model.ItemValuationDrugMaterialMap;
import com.kcim.dao.model.OrderItemMap;
import org.springframework.stereotype.Repository;

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

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

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

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

        return this.list(queryWrapper);
    }

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

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

        return this.list(queryWrapper);
    }
}
