package com.ruoyi.os.service.impl;

import com.ruoyi.os.domain.DrugArchive;
import com.ruoyi.os.domain.DrugFiling;
import com.ruoyi.os.mapper.DrugArchiveMapper;
import com.ruoyi.os.service.IDrugArchiveService;
import com.ruoyi.os.service.IDrugFilingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
/**
 *
 *  @author 何顺
 *  @date 2024-09-17
 */
@Service
public class DrugArchiveServiceImpl implements IDrugArchiveService {

    @Autowired
    private DrugArchiveMapper drugArchiveMapper;
    @Autowired
    private IDrugFilingService drugFilingService;

    @Override
    public List<DrugArchive> selectDrugArchiveList(DrugArchive drugArchive) {
        List<DrugArchive> list = drugArchiveMapper.selectDrugArchiveList(drugArchive);
        list.forEach(item -> {
            DrugFiling filing = new DrugFiling();
            filing.setArchiveId(item.getId());
            item.setDrugFilings(drugFilingService.selectDrugFilingList(filing));
        });
        return list;
    }

    @Override
    public DrugArchive selectDrugArchiveById(Long id) {
        DrugArchive archive = drugArchiveMapper.selectDrugArchiveById(id);
        if (archive != null) {
            DrugFiling filing = new DrugFiling();
            filing.setArchiveId(id);
            archive.setDrugFilings(drugFilingService.selectDrugFilingList(filing));
        }
        return archive;
    }

    @Override
    public int insertDrugArchive(DrugArchive drugArchive) {
        drugArchive.setCreateTime(new Date());
        return drugArchiveMapper.insertDrugArchive(drugArchive);
    }

    @Override
    public int updateDrugArchive(DrugArchive drugArchive) {
        drugArchive.setUpdateTime(new Date());
        return drugArchiveMapper.updateDrugArchive(drugArchive);
    }

    @Override
    public int deleteDrugArchiveById(Long id) {
        return drugArchiveMapper.deleteDrugArchiveById(id);
    }

    @Override
    public int deleteDrugArchiveByIds(Long[] ids) {
        return drugArchiveMapper.deleteDrugArchiveByIds(ids);
    }
}