package com.fs.task;

import com.fs.hisStore.domain.FsStoreScrm;
import com.fs.hisStore.service.IFsStoreScrmService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
import com.fs.common.utils.PubFun;

import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;

@AllArgsConstructor
@Component("storeTaskScrm")
public class FsStoreTask {

    private final IFsStoreScrmService fsStoreScrmService;


    public void store(){
        LocalDate now = LocalDate.now();
        List<FsStoreScrm> storeList = fsStoreScrmService.selectOverList();
        List<FsStoreScrm> collect = storeList.stream().filter(e -> {
            // 过期判定：任一证件到期日为 null 或 早于今天
            return e.getBusinessLicenseExpireEnd() == null
                    || e.getDrugLicenseExpiryEnd() == null
                    || e.getMedicalLicenseExpiryEnd() == null
                    || e.getBusinessLicenseExpireEnd().isBefore(now)
                    || e.getDrugLicenseExpiryEnd().isBefore(now)
                    || e.getMedicalLicenseExpiryEnd().isBefore(now);
        }).collect(Collectors.toList());

        if (!collect.isEmpty()) {
            List<Long> ids = PubFun.listToNewList(collect, FsStoreScrm::getStoreId);
            fsStoreScrmService.batchUpdateStatusByIds(ids, 0);
        }
    }

}