package com.skr.mdm.manager;/**
 * @Author: nfq
 * @Date: 2022/06/20/16:39
 */

import com.skr.mdm.bean.so.app.AppStrategySO;
import com.skr.mdm.bean.so.app.AppStrategyUsePermissionSO;
import com.skr.mdm.dao.*;
import com.skr.mdm.entity.AppStrategyDO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author nfq
 * @date 2022-06-20 16:39
 */
@Component
public class AppStrategyManager {

    @Autowired
    private AppStrategyDao appStrategyDao;
    @Autowired
    private AppStrategyInstallDao appStrategyInstallDao;
    @Autowired
    private AppStrategyInstallSourceDao appStrategyInstallSourceDao;
    @Autowired
    private AppStrategyNotUninstallDao appStrategyNotUninstallDao;
    @Autowired
    private AppStrategyRunDao appStrategyRunDao;
    @Autowired
    private AppStrategyShortcutsDao appStrategyShortcutsDao;
    @Autowired
    private AppStrategyUsePermissionDao appStrategyUsePermissionDao;
    @Autowired
    private AppStrategyUsePermissionAppDao appStrategyUsePermissionAppDao;

    public List<AppStrategySO> getAppStrategySOList(List<Integer> strategyIdList) {
        return strategyIdList.stream().map(this::getAppStrategySO).collect(Collectors.toList());
    }

    private AppStrategySO getAppStrategySO(Integer strategyId) {
        AppStrategyDO appStrategyDO = appStrategyDao.selectById(strategyId);
        AppStrategySO appStrategySO = new AppStrategySO();
        appStrategySO.setSendTime(new Date());
        BeanUtils.copyProperties(appStrategyDO, appStrategySO);
        // 安装黑白名单
        appStrategySO.setAppStrategyInstallSO(appStrategyInstallDao.getAppStrategyInfoSO(strategyId));
        // 安装来源
        appStrategySO.setAppStrategyInstallSourceSO(appStrategyInstallSourceDao.getAppStrategyInfoSO(strategyId));
        // 运行黑白名单
        appStrategySO.setAppStrategyRunSO(appStrategyRunDao.getAppStrategyInfoSO(strategyId));
        // 防卸载
        appStrategySO.setNotUninstallAppConfigList(appStrategyNotUninstallDao.listAppConfigSO(strategyId));
        // 快捷应用
        appStrategySO.setShortcutsAppConfigList(appStrategyShortcutsDao.listAppConfigSO(strategyId));
        // 应用使用权限
        AppStrategyUsePermissionSO appStrategyUsePermissionSO = appStrategyUsePermissionDao.getAppStrategyUsePermissionSO(strategyId);
        if (appStrategyUsePermissionSO != null) {
            appStrategyUsePermissionSO.setAppConfigSOList(appStrategyUsePermissionAppDao.listAppConfigSO(strategyId));
        }
        appStrategySO.setAppStrategyUsePermissionSO(appStrategyUsePermissionSO);
        return appStrategySO;
    }

}