Skip to content

Commit 57b6c4a

Browse files
hello-haohello-hao
authored andcommitted
Merge remote-tracking branch 'origin/hellohao-dev'
# Conflicts: # src/main/java/cn/hellohao/service/impl/InitializationStorage.java
2 parents 538482a + 733ec3e commit 57b6c4a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+896
-940
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ Core版:`本地`,`阿里OSS`,`又拍USS`,`七牛KODO`,`腾讯COS`,`网易NOS`,
188188
### 反馈交流
189189

190190
**如果你遇到BUG欢迎反馈**
191-
192-
欢迎加入Hellohao开发者交流群,群聊号码:**864800972**
191+
- 前往论坛发帖反馈、求助:[Hellohao开发者交流论坛](http://bbs.hellohao.cn)
192+
- 也可加QQ群探讨(目前已满):864800972
193193

194194
### 捐赠开发者
195195

docker/Dockerfile-tbed

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM openjdk:8
2+
3+
4+
5+
ADD hellohaotbed/ /hellohaotbed
6+
7+
COPY appstart.sh /appstart.sh
8+
9+
COPY application.properties /application.properties
10+
11+
COPY Tbed.jar /Tbed.jar
12+
13+
EXPOSE 10088
14+
15+
EXPOSE 10089
16+
17+
CMD ["/bin/bash","/appstart.sh"]

pom.xml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@
9090
<artifactId>spring-boot-starter-validation</artifactId>
9191
</dependency>
9292

93-
<dependency>
94-
<groupId>commons-logging</groupId>
95-
<artifactId>commons-logging</artifactId>
96-
<version>1.2</version>
97-
</dependency>
93+
<!-- <dependency>-->
94+
<!-- <groupId>commons-logging</groupId>-->
95+
<!-- <artifactId>commons-logging</artifactId>-->
96+
<!-- <version>1.2</version>-->
97+
<!-- </dependency>-->
9898
<dependency>
9999
<groupId>com.github.pagehelper</groupId>
100100
<artifactId>pagehelper-spring-boot-starter</artifactId>
@@ -120,7 +120,11 @@
120120
<artifactId>pebble</artifactId>
121121
<version>3.1.5</version>
122122
</dependency>
123-
123+
<dependency>
124+
<groupId>com.amazonaws</groupId>
125+
<artifactId>aws-java-sdk-s3</artifactId>
126+
<version>1.12.334</version>
127+
</dependency>
124128
<dependency>
125129
<groupId>org.springframework.boot</groupId>
126130
<artifactId>spring-boot-starter-mail</artifactId>
@@ -130,7 +134,7 @@
130134
<dependency>
131135
<groupId>com.baidu.aip</groupId>
132136
<artifactId>java-sdk</artifactId>
133-
<version>4.11.0</version>
137+
<version>4.16.14</version>
134138
</dependency>
135139
<dependency>
136140
<groupId>net.coobird</groupId>

src/main/java/cn/hellohao/TbedApplication.java

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
package cn.hellohao;
22

3-
import javax.servlet.MultipartConfigElement;
4-
import javax.servlet.http.HttpServletRequest;
5-
6-
import cn.hellohao.utils.Print;
3+
import cn.hellohao.dao.KeysMapper;
4+
import cn.hellohao.utils.FirstRun;
5+
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
76
import org.springframework.boot.SpringApplication;
87
import org.springframework.boot.autoconfigure.SpringBootApplication;
8+
import org.springframework.boot.jdbc.DatabaseDriver;
99
import org.springframework.boot.web.servlet.MultipartConfigFactory;
1010
import org.springframework.boot.web.servlet.ServletComponentScan;
1111
import org.springframework.context.annotation.Bean;
1212
import org.springframework.context.annotation.Configuration;
13-
import org.springframework.context.annotation.PropertySource;
13+
import org.springframework.jdbc.support.DatabaseStartupValidator;
1414
import org.springframework.scheduling.annotation.EnableScheduling;
1515
import org.springframework.transaction.annotation.EnableTransactionManagement;
1616
import org.springframework.util.unit.DataSize;
17-
import org.springframework.web.context.request.RequestContextHolder;
18-
import org.springframework.web.context.request.ServletRequestAttributes;
1917

20-
import java.net.InetAddress;
21-
import java.util.Scanner;
18+
import javax.servlet.MultipartConfigElement;
19+
import javax.sql.DataSource;
20+
import java.util.stream.Stream;
2221

2322
@SpringBootApplication
2423
@Configuration
@@ -30,6 +29,32 @@ public class TbedApplication {
3029
public static void main(String[] args) {
3130
SpringApplication.run(TbedApplication.class, args);
3231
}
32+
33+
//延缓Spring Boot启动时间直到数据库启动的方法
34+
@Bean
35+
public DatabaseStartupValidator databaseStartupValidator(DataSource dataSource) {
36+
DatabaseStartupValidator databaseStartupValidator = new DatabaseStartupValidator();
37+
databaseStartupValidator.setDataSource(dataSource);
38+
databaseStartupValidator.setValidationQuery(DatabaseDriver.POSTGRESQL.getValidationQuery());
39+
return databaseStartupValidator;
40+
}
41+
@Bean
42+
public static BeanFactoryPostProcessor dependsOnPostProcessor() {
43+
return bf -> {
44+
// Let beans that need the database depend on the DatabaseStartupValidator
45+
// like the JPA EntityManagerFactory or Flyway
46+
String[] flyway = bf.getBeanNamesForType(FirstRun.class);
47+
Stream.of(flyway)
48+
.map(bf::getBeanDefinition)
49+
.forEach(it -> it.setDependsOn("databaseStartupValidator"));
50+
51+
String[] jpa = bf.getBeanNamesForType(KeysMapper.class);
52+
Stream.of(jpa)
53+
.map(bf::getBeanDefinition)
54+
.forEach(it -> it.setDependsOn("databaseStartupValidator"));
55+
56+
};
57+
}
3358
/**
3459
* 文件上传配置
3560
* @return
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package cn.hellohao.config;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.context.annotation.Configuration;
6+
import javax.annotation.PostConstruct;
7+
import java.io.PrintStream;
8+
import java.util.function.Consumer;
9+
10+
@Configuration
11+
public class LogSystemProxy {
12+
13+
private final static Logger log = LoggerFactory.getLogger("proxy.system.log");
14+
15+
@PostConstruct
16+
public void initProxy(){
17+
log.debug("LogSystemProxy init .....");
18+
System.setOut(getLoggerProxy(StdType.OUT));
19+
System.setErr(getLoggerProxy(StdType.ERR));
20+
}
21+
22+
23+
private enum StdType{
24+
OUT(System.out, log::info),
25+
ERR(System.err, log::error),
26+
;
27+
PrintStream stream;
28+
Consumer<String> consumer;
29+
StdType(PrintStream stream,Consumer<String> consumer){
30+
this.stream = stream;
31+
this.consumer = consumer;
32+
}
33+
}
34+
35+
private PrintStream getLoggerProxy(StdType stdType){
36+
return new PrintStream(stdType.stream){
37+
@Override
38+
public void print(String s) {
39+
stdType.stream.print(s);
40+
stdType.consumer.accept(s);
41+
}
42+
};
43+
}
44+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package cn.hellohao.config;
2+
3+
import lombok.Data;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.scheduling.annotation.EnableAsync;
7+
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
8+
9+
import java.util.concurrent.ThreadPoolExecutor;
10+
11+
//线程池
12+
@Configuration
13+
@EnableAsync
14+
public class PoolConfig {
15+
ThreadPoolProperties properties = new ThreadPoolProperties();
16+
@Bean(name = "taskExecutor")
17+
public ThreadPoolTaskExecutor taskExecutor() {
18+
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
19+
executor.setCorePoolSize(properties.getCorePoolSize());
20+
executor.setMaxPoolSize(properties.getMaxPoolSize());
21+
executor.setQueueCapacity(properties.getQueueCapacity());
22+
executor.setThreadNamePrefix(properties.getThreadNamePrefix());
23+
executor.setKeepAliveSeconds(properties.getKeepAliveTime());
24+
executor.setWaitForTasksToCompleteOnShutdown(properties.isWaitForTasksToCompleteOnShutdown());
25+
executor.setAwaitTerminationSeconds(properties.getAwaitTerminationSeconds());
26+
// 设置任务拒绝策略
27+
/**
28+
* 4种
29+
* ThreadPoolExecutor类有几个内部实现类来处理这类情况:
30+
- AbortPolicy 丢弃任务,抛RejectedExecutionException
31+
- CallerRunsPolicy 由该线程调用线程运行。直接调用Runnable的run方法运行。
32+
- DiscardPolicy 抛弃策略,直接丢弃这个新提交的任务
33+
- DiscardOldestPolicy 抛弃旧任务策略,从队列中踢出最先进入队列(最后一个执行)的任务
34+
* 实现RejectedExecutionHandler接口,可自定义处理器
35+
*/
36+
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
37+
return executor;
38+
}
39+
40+
@Data
41+
class ThreadPoolProperties {
42+
private int corePoolSize = 5;
43+
private int maxPoolSize = 50;
44+
private int keepAliveTime = 15;
45+
private int queueCapacity = 6;
46+
private String threadNamePrefix = "Tbed-Thread";
47+
private boolean allowCoreThreadTimeout = false;
48+
private boolean waitForTasksToCompleteOnShutdown = false;
49+
private int awaitTerminationSeconds;
50+
51+
}
52+
}

src/main/java/cn/hellohao/controller/AdminController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,9 @@ public Msg deleImages(@RequestParam(value = "data", defaultValue = "") String da
472472
msg.setInfo("为获取到图像信息");
473473
return msg;
474474
}
475-
List<Integer> imgIds = new ArrayList<Integer>();
475+
List<Long> imgIds = new ArrayList<Long>();
476476
for (int i = 0; i < split.length; i++) {
477-
Integer imgid = Integer.valueOf(split[i]);
477+
Long imgid = Long.valueOf(split[i]);
478478
Images image = imgService.selectByPrimaryKey(imgid);
479479
if (!subject.hasRole("admin")) {
480480
if (!image.getUserid().equals(user.getId())) {
@@ -486,7 +486,7 @@ public Msg deleImages(@RequestParam(value = "data", defaultValue = "") String da
486486
if (imgIds.size() == 0) {
487487
msg.setCode("110404");
488488
} else {
489-
deleimages.dele(uuid, imgIds.stream().toArray(Integer[]::new));
489+
deleimages.dele(uuid, imgIds.stream().toArray(Long[]::new));
490490
msg.setCode("200");
491491
}
492492
return msg;

src/main/java/cn/hellohao/controller/AdminRootController.java

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
@RequestMapping("/admin/root")
2626
public class AdminRootController {
2727
@Autowired
28-
private ConfigService configService;
28+
private ConfdataService confdataService;
2929
@Autowired
3030
private KeysService keysService;
3131
@Autowired
@@ -196,7 +196,7 @@ public Msg LoadInfo(@RequestParam(value = "data", defaultValue = "") String data
196196
} else if (key.getStorageType() == 7) {
197197
ret = FtpServiceImpl.Initialize(key);
198198
} else if (key.getStorageType() == 8) {
199-
ret = UFileImageupload.Initialize(key);
199+
ret = S3Imageupload.Initialize(key);
200200
}
201201
Long l = imgService.getsourcememory(keyId);
202202
jsonObject.put("isok", ret);
@@ -219,23 +219,24 @@ public Msg LoadInfo(@RequestParam(value = "data", defaultValue = "") String data
219219
@ResponseBody
220220
public Msg updateStorage(@RequestParam(value = "data", defaultValue = "") String data) {
221221
JSONObject jsonObj = JSONObject.parseObject(data);
222-
Integer id = jsonObj.getInteger("id");
223-
String AccessKey = jsonObj.getString("AccessKey");
224-
String AccessSecret = jsonObj.getString("AccessSecret");
225-
String Endpoint = jsonObj.getString("Endpoint");
226-
String Bucketname = jsonObj.getString("Bucketname");
227-
String RequestAddress = jsonObj.getString("RequestAddress");
228-
Integer storageType = jsonObj.getInteger("storageType");
229-
String keyname = jsonObj.getString("keyname");
230-
Keys keys = new Keys();
231-
keys.setId(id);
232-
keys.setAccessKey(AccessKey);
233-
keys.setAccessSecret(AccessSecret);
234-
keys.setEndpoint(Endpoint);
235-
keys.setBucketname(Bucketname);
236-
keys.setRequestAddress(RequestAddress);
237-
keys.setStorageType(storageType);
238-
keys.setKeyname(keyname);
222+
// Integer id = jsonObj.getInteger("id");
223+
// String AccessKey = jsonObj.getString("AccessKey");
224+
// String AccessSecret = jsonObj.getString("AccessSecret");
225+
// String Endpoint = jsonObj.getString("Endpoint");
226+
// String Bucketname = jsonObj.getString("Bucketname");
227+
// String RequestAddress = jsonObj.getString("RequestAddress");
228+
// Integer storageType = jsonObj.getInteger("storageType");
229+
// String keyname = jsonObj.getString("keyname");
230+
// Keys keys = new Keys();
231+
// keys.setId(id);
232+
// keys.setAccessKey(AccessKey);
233+
// keys.setAccessSecret(AccessSecret);
234+
// keys.setEndpoint(Endpoint);
235+
// keys.setBucketname(Bucketname);
236+
// keys.setRequestAddress(RequestAddress);
237+
// keys.setStorageType(storageType);
238+
// keys.setKeyname(keyname);
239+
Keys keys = JSON.toJavaObject(jsonObj,Keys.class);
239240
Msg msg = keysService.updateKey(keys);
240241
return msg;
241242
}
@@ -260,15 +261,15 @@ public Msg getSettingConfig(@RequestParam(value = "data", defaultValue = "") Str
260261
User u = (User) subject.getPrincipal();
261262
try {
262263
UploadConfig uploadConfig = uploadConfigService.getUpdateConfig();
263-
Config config = configService.getSourceype();
264+
final Confdata confdata = confdataService.selectConfdata("config");
264265
SysConfig sysConfig = sysConfigService.getstate();
265266
AppClient appClientData = appClientService.getAppClientData("app");
266267
uploadConfig.setUsermemory(Long.toString(Long.valueOf(uploadConfig.getUsermemory()) / 1024 / 1024));
267268
uploadConfig.setVisitormemory(Long.toString(Long.valueOf(uploadConfig.getVisitormemory()) / 1024 / 1024));
268269
uploadConfig.setFilesizetourists(Long.toString(Long.valueOf(uploadConfig.getFilesizetourists()) / 1024 / 1024));
269270
uploadConfig.setFilesizeuser(Long.toString(Long.valueOf(uploadConfig.getFilesizeuser()) / 1024 / 1024));
270271
jsonObject.put("uploadConfig", uploadConfig);
271-
jsonObject.put("config", config);
272+
jsonObject.put("config", JSONObject.parseObject(confdata.getJsondata()));
272273
jsonObject.put("sysConfig", sysConfig);
273274
jsonObject.put("appClient", appClientData);
274275
msg.setData(jsonObject);
@@ -296,7 +297,7 @@ public Msg updateConfig(@RequestParam(value = "data", defaultValue = "") String
296297
msg.setCode("500");
297298
return msg;
298299
}
299-
Config config = JSON.toJavaObject((JSON) jsonObject.get("config"), Config.class);
300+
// Config config = JSON.toJavaObject((JSON) jsonObject.get("config"), Config.class);
300301
SysConfig sysConfig = JSON.toJavaObject((JSON) jsonObject.get("sysConfig"), SysConfig.class);
301302
AppClient appClient = JSON.toJavaObject((JSON) jsonObject.get("appClient"), AppClient.class);
302303
if (Integer.valueOf(vm) == -1) {
@@ -308,7 +309,10 @@ public Msg updateConfig(@RequestParam(value = "data", defaultValue = "") String
308309
uploadConfig.setUsermemory(Long.toString(Long.valueOf(uploadConfig.getUsermemory()) * 1024 * 1024));
309310
uploadConfig.setFilesizeuser(Long.toString(Long.valueOf(uploadConfig.getFilesizeuser()) * 1024 * 1024));
310311
uploadConfigService.setUpdateConfig(uploadConfig);
311-
configService.setSourceype(config);
312+
Confdata confdata = new Confdata();
313+
confdata.setKey("config");
314+
confdata.setJsondata(jsonObject.getJSONObject("config").toJSONString());
315+
confdataService.updateConfdata(confdata);
312316
sysConfigService.setstate(sysConfig);
313317
if (!appClient.getIsuse().equals("on")) {
314318
appClient.setIsuse("off");

0 commit comments

Comments
 (0)