shikeyin
2024-01-11 65da8373531677b1c37a98f53eaa30c892f35e5a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.iplatform.chat.config;
 
import com.iplatform.chat.ChatService;
import com.iplatform.chat.support.MongoChatService;
import com.iplatform.core.PlatformConfiguration;
import com.walker.jdbc.mongo.MongoProperty;
import com.walker.jdbc.mongo.MongoService;
import com.walker.jdbc.mongo.MongoTemplateFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.data.mongodb.core.MongoTemplate;
 
/**
 * 注意:这里要禁用Mongo自动配置启动(第四行),因为我们做了自定义配置。
 * @author 时克英
 * @date 2023-07-07
 */
//@Configuration
//@ConditionalOnProperty(prefix = "iplatform.chat", name = "mongo-enabled", havingValue = "true", matchIfMissing = false)
//@ConditionalOnClass({MongoService.class})
//@EnableAutoConfiguration(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
    @Deprecated
public class MongoChatConfig extends PlatformConfiguration {
 
    @Bean
    public ChatService chatService(MongoChatProperties mongoChatProperties, MongoTemplateFactory mongoTemplateFactory){
        logger.info(mongoChatProperties.toString());
        MongoService mongoService = this.acquireMongoService(mongoTemplateFactory, mongoChatProperties);
        MongoChatService chatService = new MongoChatService();
        chatService.setMongoService(mongoService);
        return chatService;
    }
 
    @Bean
    public MongoTemplateFactory mongoTemplateFactory(){
        return new MongoTemplateFactory();
    }
 
    @Bean
    public MongoChatProperties mongoChatProperties(){
        return new MongoChatProperties();
    }
 
    private MongoService acquireMongoService(MongoTemplateFactory mongoTemplateFactory, MongoChatProperties properties){
        MongoProperty property = new MongoProperty();
        property.setIp(properties.getIp());
        property.setPort(properties.getPort());
        property.setDatabase(properties.getDatabase());
        property.setUserName(properties.getUserName());
        property.setPassword(properties.getPassword());
        property.setMaxSize(properties.getMaxSize());
        property.setMinSize(properties.getMinSize());
        property.setMaxIdleTimeSeconds(properties.getMaxIdleTimeSeconds());
        property.setMaxWaitTimeSeconds(properties.getMaxWaitTimeSeconds());
 
        MongoTemplate mongoTemplate = mongoTemplateFactory.createTemplate(property);
        MongoService mongoService = new MongoService();
        mongoService.setMongoTemplate(mongoTemplate);
        return mongoService;
    }
}