package com.rongwei.bscommon.sys.utils;

import com.rongwei.bscommon.sys.dao.ApsProcessOperationBackupDao;
import com.rongwei.bscommon.sys.dao.ApsProcessOperationProcessEquBackupDao;
import com.rongwei.commonservice.serial.service.SysSerialNumberService;
import com.rongwei.commonservice.service.RedisService;
import com.rongwei.rwadmincommon.system.domain.SysOrganizationDo;
import com.rongwei.rwadmincommon.system.vo.SysOrganizationVo;
import com.rongwei.rwadmincommon.system.vo.SysUserVo;
import com.rongwei.rwcommon.utils.StringUtils;
import com.rongwei.safecommon.fegin.CXAdminFeginClient;
import com.rongwei.safecommon.fegin.CXCommonFeginClient;
import com.rongwei.safecommon.utils.CXCommonUtils;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

import static com.rongwei.safecommon.utils.SaveConstans.MINUS_ONE;

/**
 * ApsUtils class
 *
 * @author XH
 * @date 2024/05/07
 */
@Component
public class ApsUtils {
    private static final Logger log = LoggerFactory.getLogger(ApsUtils.class.getName());
    @Autowired
    private ApsProcessOperationBackupDao autoApsProcessOperationBackupDao;
    @Autowired
    private ApsProcessOperationProcessEquBackupDao autoApsProcessOperationProcessEquBackupDao;


    private static ApsProcessOperationBackupDao apsProcessOperationBackupDao;
    private static ApsProcessOperationProcessEquBackupDao apsProcessOperationProcessEquBackupDao;


    @PostConstruct
    public void info() {
        apsProcessOperationBackupDao = autoApsProcessOperationBackupDao;
        apsProcessOperationProcessEquBackupDao = autoApsProcessOperationProcessEquBackupDao;
    }

    /**
     * 删除当前员工所属工厂的排程备份信息
     * @param currentUser
     */
    public static void clearBackup(SysUserVo currentUser) {
        if(currentUser==null){
            currentUser = CXCommonUtils.getCurrentUser();
        }
        String factoryId = CXCommonUtils.getCurrentUserFactoryId(currentUser);
        log.info("开始删除工厂：{}的排除备份数据",factoryId);
        // 先删除
        apsProcessOperationBackupDao.deletedByBlankId(null, factoryId);
        apsProcessOperationProcessEquBackupDao.deletedByBlankId(null, factoryId);
    }

}
