xyc
2024-11-05 af97e376db85a53b41c9fe069bd2948b59387e49
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.zt.life;
 
import cn.hutool.core.io.FileUtil;
import com.zt.modules.workflow.service.WorkflowService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
 
import java.io.File;
 
/**
 * @author hehz
 */
@MapperScan("com.zt.**.dao")
@ComponentScan(basePackages = {"com.zt.**"})
@SpringBootApplication(exclude = {
// org.activiti.spring.boot.SecurityAutoConfiguration.class,
        org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class})
@EnableCaching
@EnableAsync
@EnableScheduling
public class AdminApplication extends SpringBootServletInitializer {
 
    @Value("${zt.oss.local-path}")
    private String localPath;
 
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(AdminApplication.class);
    }
 
 
    @Autowired
    private WorkflowService workflowService;
 
    public static void main(String[] args) {
        SpringApplication.run(AdminApplication.class, args);
    }
 
    @Bean
    public ConfigurableServletWebServerFactory webServerFactory() {
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
        factory.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> connector.setProperty("relaxedQueryChars", "|{}[]\\"));
        return factory;
    }
 
//    @Scheduled(cron = "0 0 3 * * ?") //每天3点执行
//    public void timerListener() throws ParseException {
///*        projectService.dropTemporaryTable();
//        projectService.updateHasLifeData();
//        this.deleteTempFile();*/
//    }
 
    private void deleteTempFile() {
        String tempUploadDir = localPath + File.separator + "TEMP_UPLOAD";
        FileUtil.del(tempUploadDir);
        tempUploadDir = localPath + File.separator + "svg";
        FileUtil.del(tempUploadDir);
    }
 
    @Autowired
    private RedisConnectionFactory redisConnectionFactory;
 
    @Bean
    public RedisTemplate<String, Object> redisTemplate() {
        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
        // 暂时先设置key和value的序列化都是字符串
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setValueSerializer(new StringRedisSerializer());
        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
        redisTemplate.setHashValueSerializer(new StringRedisSerializer());
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        return redisTemplate;
    }
 
}