package com.ann.demo.service;

import com.ann.demo.entity.interfaceEntity.ArchiveMaster;
import com.ann.demo.interfaces.impl.HomepageDictionaryImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: LeiJiaXin
 * @Date: 2019/9/26 9:52
 */
@Service
public class TimerService {

    private static final Logger logger = LoggerFactory.getLogger(TimerService.class);

    @Autowired
    private MedicalRecordHomepageCacheService medicalRecordHomepageCacheService;

    @Autowired
    private ArchiveMasterService archiveMasterService;

    public void doSomethingByMedicalRecordHomepageCache() {
        try {
            List<ArchiveMaster> allArchiveMaster = archiveMasterService.findAllArchiveMaster();
            if (allArchiveMaster.size() > 0) {
                for (ArchiveMaster archiveMaster : allArchiveMaster) {
                    // 新增病案首页
                    if (medicalRecordHomepageCacheService.save(archiveMaster.getId())) {
                        // 清空master 当前已归档信息
                        if (archiveMasterService.updateCheckedDatetime(archiveMaster.getId())) {
                            //删除病案首页缓存信息
                            medicalRecordHomepageCacheService.delete(archiveMaster.getId());
                        }
                    }
                }
            }
        }catch (Exception e){
            logger.error("出错咯！错误信息为{}，以及错误行数为:{}" ,e,e.getStackTrace()[0]);
        }

    }
}
