package com.zhongshu.card.server.core.service.fix;

import com.github.microservice.auth.security.type.AuthType;
import com.github.microservice.net.ResultContent;
import com.zhongshu.card.server.core.dao.org.OrganizationDao;
import com.zhongshu.card.server.core.domain.org.Organization;
import com.zhongshu.card.server.core.service.devices.ProjectSyncIotCenterService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author TRX
 * @date 2024/6/28
 */
@Slf4j
@Service
public class FixDataService {

    @Autowired
    OrganizationDao organizationDao;

    @Autowired
    ProjectSyncIotCenterService projectSyncIotCenterService;

    /**
     * 同步项目信息到物联网平台
     *
     * @return
     */
    public ResultContent fixSyncProjectToIot() {
        int count = 0;
        List<Organization> list = organizationDao.findByAuthType(AuthType.Project);
        if (ObjectUtils.isNotEmpty(list)) {
            count = list.size();
            projectSyncIotCenterService.noticeSyncProjects(list);
        }
        return ResultContent.buildSuccess(String.format("同步项目：%d", count));
    }

}
