Newer
Older
newfiber-termite / newfiber-termites-business / newfiber-termites-biz / src / main / java / com / newfiber / termite / schedule / MongoIndexSchedule.java
@xiongkai xiongkai 2 days ago 796 bytes 包结构调整
package com.newfiber.termite.schedule;

import com.mongodb.BasicDBObject;
import java.util.Set;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MongoIndexSchedule {

    @Resource
    private MongoTemplate mongoTemplate;

//    @Scheduled(cron = "0 0 0 * * ? ")
    public void createIndex() {

        Set<String> setList = mongoTemplate.getCollectionNames();
        for(String stCode : setList){
            BasicDBObject defaultIndex = new BasicDBObject();
            defaultIndex.put("sn", 1);
            defaultIndex.put("date", 1);
            mongoTemplate.getCollection(stCode).createIndex(defaultIndex);
        }
    }

}