package com.skr.mdm.service.impl.reload.handler;

import com.skr.mdm.annotation.MdmReloadHandler;
import com.skr.mdm.bean.so.ReloadSO;
import com.skr.mdm.bean.so.app.AppPushSO;
import com.skr.mdm.dao.MdmAppPushDao;
import com.skr.mdm.service.impl.reload.ReloadHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author nfq
 * @date 2023-01-11 10:09
 */
@MdmReloadHandler
@Slf4j
public class AppPushReloadHandler implements ReloadHandler {

    @Autowired
    private MdmAppPushDao appPushDao;

    @Override
    public void doHandler(ReloadSO reloadSO, Integer equipmentId) {
        try {
            List<AppPushSO> appPushSOList = appPushDao.listAppPushSO(equipmentId, 0);
            if (CollectionUtils.isNotEmpty(appPushSOList)) {
                appPushSOList.forEach(appPushSO -> {
                    BeanUtils.copyProperties(appPushDao.getMdmAppVersionBO(appPushSO.getId()), appPushSO);
                });
                reloadSO.setAppPushSOList(appPushSOList);
            }
        } catch (Exception e) {
            log.error("卸载重装应用推送异常：" + equipmentId, e);
        }
    }
}
