Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
szj committed Sep 1, 2018
1 parent 234c5b7 commit 0c0ae5a
Show file tree
Hide file tree
Showing 22 changed files with 76 additions and 26 deletions.
31 changes: 30 additions & 1 deletion server/web/src/main/java/esform/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@

import esform.filter.LoggerFilter;
import esform.filter.OauthFilter;
import esform.listener.InitListener;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

import javax.annotation.Resource;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
* Created by
Expand All @@ -23,10 +33,15 @@
@SpringBootApplication
@EnableAutoConfiguration
@EnableTransactionManagement
@PropertySource(value = {"classpath:esform.properties"})
@PropertySource(value = {"classpath:application.properties"})
@MapperScan(basePackages = "esform.dao")
public class Application {

@Value("${redis-master1.ip}")
private String redisMaster1Ip;
@Value("${redis-master1.port}")
private int redisMaster1Port;

@Autowired
private LoggerFilter loggerFilter;
@Autowired
Expand All @@ -53,4 +68,18 @@ public FilterRegistrationBean<OauthFilter> authFilter() {
registrationBean.setOrder(2);
return registrationBean;
}

@Bean
public JedisCluster jedisClusterFactory(){
Set<HostAndPort> hostAndPortSet = new HashSet<>();
hostAndPortSet.add(new HostAndPort(redisMaster1Ip, redisMaster1Port));
return new JedisCluster(hostAndPortSet);
}

@Bean
public ServletListenerRegistrationBean XervletListenerRegistration(){
ServletListenerRegistrationBean servletListenerRegistrationBean = new ServletListenerRegistrationBean();
servletListenerRegistrationBean.setListener(new InitListener());
return servletListenerRegistrationBean;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Response register(@RequestBody AuthRequest request, HttpServletResponse r

userDao.add(user);

addAccessToken(response,user);
addAccessToken(response, user);

return Response.ok();
}
Expand All @@ -60,7 +60,7 @@ public Response login(@RequestBody AuthRequest request, HttpServletResponse resp
return Response.unAuthenticated("username or password wrong");
}

addAccessToken(response,user);
addAccessToken(response, user);

return Response.ok();
}
Expand Down Expand Up @@ -135,7 +135,7 @@ public Response menu() {
return Response.ok(menuJson);
}

private void addAccessToken(HttpServletResponse response,User user){
private void addAccessToken(HttpServletResponse response, User user) {
Cookie cookie = new Cookie("access_token", user.getUserName() + "@" + user.getPassword());
cookie.setMaxAge(7 * 24 * 60 * 60);
cookie.setPath("/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Control getDomain() {
control.setName(name);
control.setNickname(nickname);
control.setCode(code);
control.setClazzId(clazzId != null ? clazzId : 6 );
control.setClazzId(clazzId != null ? clazzId : 6);
control.setSort(sort != null ? sort : -100);
return control;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @name:孙证杰
* @email:[email protected] on 2017/10/20.
*/
public class QueryControlRequest extends BaseRequest{
public class QueryControlRequest extends BaseRequest {
private String controlName;
private String controlClass;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ControlResource {
@ResponseBody
public Response add(@RequestBody OperateControlRequest request) {
Control domain = request.getDomain();
Util.trace(domain,true);
Util.trace(domain, true);
controlDao.add(domain);
return Response.ok();
}
Expand All @@ -44,7 +44,7 @@ public Response del(@PathVariable("id") Long id) {
Control domain = new Control(id);
User user = OauthFilter.getUser();
domain.setCreateBy(user.getUserName());
Util.trace(domain,false);
Util.trace(domain, false);
controlDao.del(domain);
return Response.ok();
}
Expand All @@ -55,7 +55,7 @@ public Response update(@RequestBody OperateControlRequest request) {
Control domain = request.getDomain();
User user = OauthFilter.getUser();
domain.setCreateBy(user.getUserName());
Util.trace(domain,false);
Util.trace(domain, false);
controlDao.update(domain);
return Response.ok();
}
Expand Down
10 changes: 5 additions & 5 deletions server/web/src/main/java/esform/controller/TestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public class TestController {
@PostMapping("refreshTable")
@ResponseBody
public Response submit_form(@RequestBody Map map) {
List<Map> list= new ArrayList<>();
for(int i =0;i<10;i++){
List<Map> list = new ArrayList<>();
for (int i = 0; i < 10; i++) {
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("name","xm");
hashMap.put("age","18");
hashMap.put("gender","male");
hashMap.put("name", "xm");
hashMap.put("age", "18");
hashMap.put("gender", "male");
list.add(hashMap);
}
return Response.ok(list);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@ControllerAdvice(basePackages = {"esform"})
public class WebExceptionHandler {
private static Logger LOGGER = LoggerFactory.getLogger(WebExceptionHandler.class);

@ExceptionHandler(Exception.class)
@ResponseBody
Response handleControllerException(HttpServletRequest request, Throwable ex) {
Expand Down
6 changes: 3 additions & 3 deletions server/web/src/main/java/esform/filter/OauthFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ private static void setVar(String key, Object obj) {
stringObjectMap.put(key, obj);
}

public static User getUser(){
public static User getUser() {
Map<String, Object> stringObjectMap = LOCAL_VARS.get();
User user = (User)stringObjectMap.get("user");
if(user == null){
User user = (User) stringObjectMap.get("user");
if (user == null) {
throw new RuntimeException("unauthorized");
}
return user;
Expand Down
19 changes: 19 additions & 0 deletions server/web/src/main/java/esform/listener/InitListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package esform.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
* Created by admin on 2018/9/1.
*/
public class InitListener implements ServletContextListener{
@Override
public void contextInitialized(ServletContextEvent sce) {
System.out.println("1");
}

@Override
public void contextDestroyed(ServletContextEvent sce) {
System.out.println("2");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Response pageList(@RequestBody QueryPageRequest request) {
page.setName(request.getName());
List<Page> pages = pageDao.selectByExample(page);

pages.forEach(page1->{
pages.forEach(page1 -> {
page1.setPageSoul("");
});

Expand Down
6 changes: 3 additions & 3 deletions server/web/src/main/java/esform/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
*/
public class Util {

public static void trace(BaseDomain domain, boolean isCreate){
public static void trace(BaseDomain domain, boolean isCreate) {
User user = OauthFilter.getUser();
if(null == user){
if (null == user) {
throw new RuntimeException("not authorized");
}
Date now = new Date();
if(isCreate){
if (isCreate) {
domain.setCreateBy(user.getUserName());
domain.setCreateDt(now);
}
Expand Down
2 changes: 2 additions & 0 deletions server/web/src/main/resources/dev/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
redis-master1.ip = 47.97.220.227
redis-master1.port = 6379
2 changes: 1 addition & 1 deletion server/web/src/main/resources/dev/application.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
spring:
datasource:
url: jdbc:mysql://172.16.75.62:33639/soul-esview?useUnicode=true&characterEncoding=utf8
url: jdbc:mysql://47.97.220.227:33639/soul-esview?useUnicode=true&characterEncoding=utf8
password: mysql1992
driver-class-name: com.mysql.jdbc.Driver
username: root
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion server/web/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration>
<configuration>
<property name="APP_Name" value="es-view" />
<property name="APP_Name" value="es-view"/>
<property name="LOG_HOME" value="/var/logs/es-form"/>
<contextName>${APP_Name}</contextName>
<timestamp key="dateFormat" datePattern="yyyy-MM-dd HH:mm:ss"/>
Expand Down
Binary file removed server/web/src/main/resources/module/saved_model.pb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions server/web/src/main/resources/prod/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
redis-master1.ip = 172.16.75.62
redis-master1.port = 6379
3 changes: 0 additions & 3 deletions server/web/src/test/java/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;

import static org.assertj.core.api.Java6Assertions.assertThat;

/**
* Created by
*
Expand Down

0 comments on commit 0c0ae5a

Please sign in to comment.