Commit 83cb5889459bdb318a19787fa91118165a996a0c
1 parent
5bb75329
master update
Showing
58 changed files
with
2405 additions
and
2364 deletions
Too many changes to show.
To preserve performance only 58 of 438 files are displayed.
src/main/java/com/bsth/Application.java
| 1 | -package com.bsth; | ||
| 2 | - | ||
| 3 | -import org.springframework.boot.SpringApplication; | ||
| 4 | -import org.springframework.boot.autoconfigure.*; | ||
| 5 | - | ||
| 6 | -@SpringBootApplication | ||
| 7 | -public class Application{ | ||
| 8 | - | ||
| 9 | - public static void main(String[] args) throws Exception { | ||
| 10 | - SpringApplication.run(Application.class, args); | ||
| 11 | - } | 1 | +package com.bsth; |
| 2 | + | ||
| 3 | +import org.springframework.boot.SpringApplication; | ||
| 4 | +import org.springframework.boot.autoconfigure.*; | ||
| 5 | + | ||
| 6 | +@SpringBootApplication | ||
| 7 | +public class Application{ | ||
| 8 | + | ||
| 9 | + public static void main(String[] args) throws Exception { | ||
| 10 | + SpringApplication.run(Application.class, args); | ||
| 11 | + } | ||
| 12 | } | 12 | } |
| 13 | \ No newline at end of file | 13 | \ No newline at end of file |
src/main/java/com/bsth/WebAppConfiguration.java
| 1 | -package com.bsth; | ||
| 2 | - | ||
| 3 | -import javax.servlet.Filter; | ||
| 4 | - | ||
| 5 | -import org.springframework.boot.context.embedded.FilterRegistrationBean; | ||
| 6 | -import org.springframework.context.annotation.Bean; | ||
| 7 | -import org.springframework.context.annotation.ComponentScan; | ||
| 8 | -import org.springframework.context.annotation.Configuration; | ||
| 9 | -import org.springframework.web.filter.CharacterEncodingFilter; | ||
| 10 | -import org.springframework.web.filter.HttpPutFormContentFilter; | ||
| 11 | -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | ||
| 12 | -import org.springframework.web.socket.config.annotation.EnableWebSocket; | ||
| 13 | -import org.springframework.web.socket.config.annotation.WebSocketConfigurer; | ||
| 14 | -import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; | ||
| 15 | - | ||
| 16 | -import com.bsth.filter.ResourceFilter; | ||
| 17 | - | ||
| 18 | -@Configuration | ||
| 19 | -@EnableWebSocket | ||
| 20 | -@ComponentScan | ||
| 21 | -public class WebAppConfiguration extends WebMvcConfigurerAdapter implements WebSocketConfigurer{ | ||
| 22 | - | ||
| 23 | - /** | ||
| 24 | - * | ||
| 25 | - * @Title: httpPutFormContentFilter | ||
| 26 | - * @Description: TODO(弥补浏览器不支持PUT/DELETE,对携带 _method 参数的请求进行转换) | ||
| 27 | - * @return Filter 返回类型 | ||
| 28 | - * @throws | ||
| 29 | - */ | ||
| 30 | - @Bean | ||
| 31 | - public Filter httpPutFormContentFilter() { | ||
| 32 | - return new HttpPutFormContentFilter(); | ||
| 33 | - } | ||
| 34 | - | ||
| 35 | - /** | ||
| 36 | - * | ||
| 37 | - * @Title: characterEncodingFilter | ||
| 38 | - * @Description: TODO(编码过滤器) | ||
| 39 | - * @return Filter 返回类型 | ||
| 40 | - * @throws | ||
| 41 | - */ | ||
| 42 | - @Bean | ||
| 43 | - public Filter characterEncodingFilter(){ | ||
| 44 | - return new CharacterEncodingFilter("UTF-8"); | ||
| 45 | - } | ||
| 46 | - | ||
| 47 | - /** | ||
| 48 | - * | ||
| 49 | - * @Title: resourceFilterRegistration | ||
| 50 | - * @Description: TODO(静态资源过滤器, 只处理 /pages 目录下的片段请求 ) | ||
| 51 | - * @return FilterRegistrationBean 返回类型 | ||
| 52 | - * @throws | ||
| 53 | - */ | ||
| 54 | - @Bean | ||
| 55 | - public FilterRegistrationBean resourceFilterRegistration(){ | ||
| 56 | - FilterRegistrationBean registration = new FilterRegistrationBean(); | ||
| 57 | - registration.setFilter(new ResourceFilter()); | ||
| 58 | - registration.addUrlPatterns("/pages/*"); | ||
| 59 | - return registration; | ||
| 60 | - } | ||
| 61 | - | ||
| 62 | - @Override | ||
| 63 | - public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { | ||
| 64 | - | ||
| 65 | - } | ||
| 66 | -} | 1 | +package com.bsth; |
| 2 | + | ||
| 3 | +import javax.servlet.Filter; | ||
| 4 | + | ||
| 5 | +import org.springframework.boot.context.embedded.FilterRegistrationBean; | ||
| 6 | +import org.springframework.context.annotation.Bean; | ||
| 7 | +import org.springframework.context.annotation.ComponentScan; | ||
| 8 | +import org.springframework.context.annotation.Configuration; | ||
| 9 | +import org.springframework.web.filter.CharacterEncodingFilter; | ||
| 10 | +import org.springframework.web.filter.HttpPutFormContentFilter; | ||
| 11 | +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | ||
| 12 | +import org.springframework.web.socket.config.annotation.EnableWebSocket; | ||
| 13 | +import org.springframework.web.socket.config.annotation.WebSocketConfigurer; | ||
| 14 | +import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; | ||
| 15 | + | ||
| 16 | +import com.bsth.filter.ResourceFilter; | ||
| 17 | + | ||
| 18 | +@Configuration | ||
| 19 | +@EnableWebSocket | ||
| 20 | +@ComponentScan | ||
| 21 | +public class WebAppConfiguration extends WebMvcConfigurerAdapter implements WebSocketConfigurer{ | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * | ||
| 25 | + * @Title: httpPutFormContentFilter | ||
| 26 | + * @Description: TODO(弥补浏览器不支持PUT/DELETE,对携带 _method 参数的请求进行转换) | ||
| 27 | + * @return Filter 返回类型 | ||
| 28 | + * @throws | ||
| 29 | + */ | ||
| 30 | + @Bean | ||
| 31 | + public Filter httpPutFormContentFilter() { | ||
| 32 | + return new HttpPutFormContentFilter(); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * | ||
| 37 | + * @Title: characterEncodingFilter | ||
| 38 | + * @Description: TODO(编码过滤器) | ||
| 39 | + * @return Filter 返回类型 | ||
| 40 | + * @throws | ||
| 41 | + */ | ||
| 42 | + @Bean | ||
| 43 | + public Filter characterEncodingFilter(){ | ||
| 44 | + return new CharacterEncodingFilter("UTF-8"); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * | ||
| 49 | + * @Title: resourceFilterRegistration | ||
| 50 | + * @Description: TODO(静态资源过滤器, 只处理 /pages 目录下的片段请求 ) | ||
| 51 | + * @return FilterRegistrationBean 返回类型 | ||
| 52 | + * @throws | ||
| 53 | + */ | ||
| 54 | + @Bean | ||
| 55 | + public FilterRegistrationBean resourceFilterRegistration(){ | ||
| 56 | + FilterRegistrationBean registration = new FilterRegistrationBean(); | ||
| 57 | + registration.setFilter(new ResourceFilter()); | ||
| 58 | + registration.addUrlPatterns("/pages/*"); | ||
| 59 | + return registration; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + @Override | ||
| 63 | + public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { | ||
| 64 | + | ||
| 65 | + } | ||
| 66 | +} |
src/main/java/com/bsth/common/Constants.java
| 1 | -package com.bsth.common; | ||
| 2 | - | ||
| 3 | -/** | ||
| 4 | - * | ||
| 5 | - * @ClassName: Constants | ||
| 6 | - * @Description: TODO(常量类) | ||
| 7 | - * @author PanZhao | ||
| 8 | - * @date 2016年3月18日 下午11:06:53 | ||
| 9 | - * | ||
| 10 | - */ | ||
| 11 | -public class Constants { | ||
| 12 | - | ||
| 13 | - | ||
| 14 | - /** | ||
| 15 | - * 不需要拦截的资源 | ||
| 16 | - */ | ||
| 17 | - public static final String LOGIN = "/login"; | ||
| 18 | - public static final String LOGIN_PAGE = "/login.html"; | ||
| 19 | - public static final String ASSETS_URL = "/assets/**"; | ||
| 20 | - public static final String FAVICON_URL = "/favicon.ico"; | ||
| 21 | - public static final String METRONIC_URL = "/metronic_v4.5.4/**"; | ||
| 22 | - public static final String LOGIN_FAILURE = "/user/loginFailure"; | ||
| 23 | -} | 1 | +package com.bsth.common; |
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * | ||
| 5 | + * @ClassName: Constants | ||
| 6 | + * @Description: TODO(常量类) | ||
| 7 | + * @author PanZhao | ||
| 8 | + * @date 2016年3月18日 下午11:06:53 | ||
| 9 | + * | ||
| 10 | + */ | ||
| 11 | +public class Constants { | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * 不需要拦截的资源 | ||
| 16 | + */ | ||
| 17 | + public static final String LOGIN = "/login"; | ||
| 18 | + public static final String LOGIN_PAGE = "/login.html"; | ||
| 19 | + public static final String ASSETS_URL = "/assets/**"; | ||
| 20 | + public static final String FAVICON_URL = "/favicon.ico"; | ||
| 21 | + public static final String METRONIC_URL = "/metronic_v4.5.4/**"; | ||
| 22 | + public static final String LOGIN_FAILURE = "/user/loginFailure"; | ||
| 23 | +} |
src/main/java/com/bsth/common/ResponseCode.java
| 1 | -package com.bsth.common; | ||
| 2 | - | ||
| 3 | -/** | ||
| 4 | - * | ||
| 5 | - * @ClassName: ResponseCode | ||
| 6 | - * @Description: TODO(响应状态码) | ||
| 7 | - * @author PanZhao | ||
| 8 | - * @date 2016年3月18日 下午11:12:08 | ||
| 9 | - * | ||
| 10 | - */ | ||
| 11 | -public enum ResponseCode { | ||
| 12 | - | ||
| 13 | - SUCCESS("操作成功", 200), | ||
| 14 | - NO_PERMISSION("无资源访问权限", 403), | ||
| 15 | - NO_AUTHENTICATION("客户端未授权", 407), | ||
| 16 | - ERROR("服务器异常", 500); | ||
| 17 | - | ||
| 18 | - private String text; | ||
| 19 | - private int code; | ||
| 20 | - | ||
| 21 | - ResponseCode(String text, int code) { | ||
| 22 | - this.text = text; | ||
| 23 | - this.code = code; | ||
| 24 | - } | ||
| 25 | - | ||
| 26 | - @Override | ||
| 27 | - public String toString() { | ||
| 28 | - return this.code + ""; | ||
| 29 | - } | ||
| 30 | - | ||
| 31 | - public String getText() { | ||
| 32 | - return this.text; | ||
| 33 | - } | ||
| 34 | -} | 1 | +package com.bsth.common; |
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * | ||
| 5 | + * @ClassName: ResponseCode | ||
| 6 | + * @Description: TODO(响应状态码) | ||
| 7 | + * @author PanZhao | ||
| 8 | + * @date 2016年3月18日 下午11:12:08 | ||
| 9 | + * | ||
| 10 | + */ | ||
| 11 | +public enum ResponseCode { | ||
| 12 | + | ||
| 13 | + SUCCESS("操作成功", 200), | ||
| 14 | + NO_PERMISSION("无资源访问权限", 403), | ||
| 15 | + NO_AUTHENTICATION("客户端未授权", 407), | ||
| 16 | + ERROR("服务器异常", 500); | ||
| 17 | + | ||
| 18 | + private String text; | ||
| 19 | + private int code; | ||
| 20 | + | ||
| 21 | + ResponseCode(String text, int code) { | ||
| 22 | + this.text = text; | ||
| 23 | + this.code = code; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + @Override | ||
| 27 | + public String toString() { | ||
| 28 | + return this.code + ""; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public String getText() { | ||
| 32 | + return this.text; | ||
| 33 | + } | ||
| 34 | +} |
src/main/java/com/bsth/controller/BaseController.java
| 1 | -package com.bsth.controller; | ||
| 2 | - | ||
| 3 | -import java.io.Serializable; | ||
| 4 | -import java.util.Map; | ||
| 5 | - | ||
| 6 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 7 | -import org.springframework.data.domain.Page; | ||
| 8 | -import org.springframework.data.domain.PageRequest; | ||
| 9 | -import org.springframework.data.domain.Sort; | ||
| 10 | -import org.springframework.data.domain.Sort.Direction; | ||
| 11 | -import org.springframework.web.bind.annotation.PathVariable; | ||
| 12 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 13 | -import org.springframework.web.bind.annotation.RequestMethod; | ||
| 14 | -import org.springframework.web.bind.annotation.RequestParam; | ||
| 15 | - | ||
| 16 | -import com.bsth.service.BaseService; | ||
| 17 | - | ||
| 18 | -/** | ||
| 19 | - * | ||
| 20 | - * @ClassName: BaseController | ||
| 21 | - * @Description: TODO(基础的Controller实现) | ||
| 22 | - * @author PanZhao | ||
| 23 | - * @date 2016年3月17日 下午12:44:06 | ||
| 24 | - * | ||
| 25 | - * @param <T> | ||
| 26 | - * @param <ID> 主键类型 | ||
| 27 | - */ | ||
| 28 | -public class BaseController<T, ID extends Serializable> { | ||
| 29 | - | ||
| 30 | - @Autowired | ||
| 31 | - BaseService<T, ID> baseService; | ||
| 32 | - | ||
| 33 | - /** | ||
| 34 | - * | ||
| 35 | - * @Title: list | ||
| 36 | - * @Description: TODO(多条件分页查询) | ||
| 37 | - * @param @param map 查询条件 | ||
| 38 | - * @param @param page 页码 | ||
| 39 | - * @param @param size 每页显示数量 | ||
| 40 | - * @throws | ||
| 41 | - */ | ||
| 42 | - @RequestMapping(method = RequestMethod.GET) | ||
| 43 | - public Page<T> list(@RequestParam Map<String, Object> map, | ||
| 44 | - @RequestParam(defaultValue = "0") int page, | ||
| 45 | - @RequestParam(defaultValue = "10") int size, | ||
| 46 | - @RequestParam(defaultValue = "id") String order, | ||
| 47 | - @RequestParam(defaultValue = "DESC") String direction){ | ||
| 48 | - | ||
| 49 | - Direction d; | ||
| 50 | - | ||
| 51 | - if(null != direction && direction.equals("ASC")) | ||
| 52 | - d = Direction.ASC; | ||
| 53 | - else | ||
| 54 | - d = Direction.DESC; | ||
| 55 | - | ||
| 56 | - return baseService.list(map, new PageRequest(page, size, new Sort(d, order))); | ||
| 57 | - } | ||
| 58 | - | ||
| 59 | - /** | ||
| 60 | - * | ||
| 61 | - * @Title: list | ||
| 62 | - * @Description: TODO(多条件查询) | ||
| 63 | - * @param @param map | ||
| 64 | - * @throws | ||
| 65 | - */ | ||
| 66 | - @RequestMapping(value = "/all", method = RequestMethod.GET) | ||
| 67 | - public Iterable<T> list(@RequestParam Map<String, Object> map){ | ||
| 68 | - return baseService.list(map); | ||
| 69 | - } | ||
| 70 | - | ||
| 71 | - /** | ||
| 72 | - * | ||
| 73 | - * @Title: save | ||
| 74 | - * @Description: TODO(持久化对象) | ||
| 75 | - * @param @param t | ||
| 76 | - * @param @return 设定文件 | ||
| 77 | - * @return Map<String,Object> {status: 1(成功),-1(失败)} | ||
| 78 | - * @throws | ||
| 79 | - */ | ||
| 80 | - @RequestMapping(method = RequestMethod.POST) | ||
| 81 | - public Map<String, Object> save(T t){ | ||
| 82 | - return baseService.save(t); | ||
| 83 | - } | ||
| 84 | - | ||
| 85 | - /** | ||
| 86 | - * | ||
| 87 | - * @Title: findById | ||
| 88 | - * @Description: TODO(根据主键获取单个对象) | ||
| 89 | - * @param @param id | ||
| 90 | - * @throws | ||
| 91 | - */ | ||
| 92 | - @RequestMapping(value="/{id}",method = RequestMethod.GET) | ||
| 93 | - public T findById(@PathVariable("id") ID id){ | ||
| 94 | - return baseService.findById(id); | ||
| 95 | - } | ||
| 96 | - | ||
| 97 | - /** | ||
| 98 | - * | ||
| 99 | - * @Title: delete | ||
| 100 | - * @Description: TODO(根据主键删除对象) | ||
| 101 | - * @param @param id | ||
| 102 | - * @throws | ||
| 103 | - */ | ||
| 104 | - @RequestMapping(value="/{id}",method = RequestMethod.DELETE) | ||
| 105 | - public Map<String, Object> delete(@PathVariable("id") ID id){ | ||
| 106 | - return baseService.delete(id); | ||
| 107 | - } | ||
| 108 | - | ||
| 109 | -} | 1 | +package com.bsth.controller; |
| 2 | + | ||
| 3 | +import java.io.Serializable; | ||
| 4 | +import java.util.Map; | ||
| 5 | + | ||
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 7 | +import org.springframework.data.domain.Page; | ||
| 8 | +import org.springframework.data.domain.PageRequest; | ||
| 9 | +import org.springframework.data.domain.Sort; | ||
| 10 | +import org.springframework.data.domain.Sort.Direction; | ||
| 11 | +import org.springframework.web.bind.annotation.PathVariable; | ||
| 12 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 13 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
| 14 | +import org.springframework.web.bind.annotation.RequestParam; | ||
| 15 | + | ||
| 16 | +import com.bsth.service.BaseService; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * | ||
| 20 | + * @ClassName: BaseController | ||
| 21 | + * @Description: TODO(基础的Controller实现) | ||
| 22 | + * @author PanZhao | ||
| 23 | + * @date 2016年3月17日 下午12:44:06 | ||
| 24 | + * | ||
| 25 | + * @param <T> | ||
| 26 | + * @param <ID> 主键类型 | ||
| 27 | + */ | ||
| 28 | +public class BaseController<T, ID extends Serializable> { | ||
| 29 | + | ||
| 30 | + @Autowired | ||
| 31 | + BaseService<T, ID> baseService; | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * | ||
| 35 | + * @Title: list | ||
| 36 | + * @Description: TODO(多条件分页查询) | ||
| 37 | + * @param @param map 查询条件 | ||
| 38 | + * @param @param page 页码 | ||
| 39 | + * @param @param size 每页显示数量 | ||
| 40 | + * @throws | ||
| 41 | + */ | ||
| 42 | + @RequestMapping(method = RequestMethod.GET) | ||
| 43 | + public Page<T> list(@RequestParam Map<String, Object> map, | ||
| 44 | + @RequestParam(defaultValue = "0") int page, | ||
| 45 | + @RequestParam(defaultValue = "10") int size, | ||
| 46 | + @RequestParam(defaultValue = "id") String order, | ||
| 47 | + @RequestParam(defaultValue = "DESC") String direction){ | ||
| 48 | + | ||
| 49 | + Direction d; | ||
| 50 | + | ||
| 51 | + if(null != direction && direction.equals("ASC")) | ||
| 52 | + d = Direction.ASC; | ||
| 53 | + else | ||
| 54 | + d = Direction.DESC; | ||
| 55 | + | ||
| 56 | + return baseService.list(map, new PageRequest(page, size, new Sort(d, order))); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * | ||
| 61 | + * @Title: list | ||
| 62 | + * @Description: TODO(多条件查询) | ||
| 63 | + * @param @param map | ||
| 64 | + * @throws | ||
| 65 | + */ | ||
| 66 | + @RequestMapping(value = "/all", method = RequestMethod.GET) | ||
| 67 | + public Iterable<T> list(@RequestParam Map<String, Object> map){ | ||
| 68 | + return baseService.list(map); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + /** | ||
| 72 | + * | ||
| 73 | + * @Title: save | ||
| 74 | + * @Description: TODO(持久化对象) | ||
| 75 | + * @param @param t | ||
| 76 | + * @param @return 设定文件 | ||
| 77 | + * @return Map<String,Object> {status: 1(成功),-1(失败)} | ||
| 78 | + * @throws | ||
| 79 | + */ | ||
| 80 | + @RequestMapping(method = RequestMethod.POST) | ||
| 81 | + public Map<String, Object> save(T t){ | ||
| 82 | + return baseService.save(t); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + /** | ||
| 86 | + * | ||
| 87 | + * @Title: findById | ||
| 88 | + * @Description: TODO(根据主键获取单个对象) | ||
| 89 | + * @param @param id | ||
| 90 | + * @throws | ||
| 91 | + */ | ||
| 92 | + @RequestMapping(value="/{id}",method = RequestMethod.GET) | ||
| 93 | + public T findById(@PathVariable("id") ID id){ | ||
| 94 | + return baseService.findById(id); | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + /** | ||
| 98 | + * | ||
| 99 | + * @Title: delete | ||
| 100 | + * @Description: TODO(根据主键删除对象) | ||
| 101 | + * @param @param id | ||
| 102 | + * @throws | ||
| 103 | + */ | ||
| 104 | + @RequestMapping(value="/{id}",method = RequestMethod.DELETE) | ||
| 105 | + public Map<String, Object> delete(@PathVariable("id") ID id){ | ||
| 106 | + return baseService.delete(id); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | +} |
src/main/java/com/bsth/controller/DictionaryController.java
| 1 | -package com.bsth.controller; | ||
| 2 | - | ||
| 3 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 4 | -import org.springframework.web.bind.annotation.RestController; | ||
| 5 | - | ||
| 6 | -import com.bsth.entity.sys.Dictionary; | ||
| 7 | - | ||
| 8 | -@RestController | ||
| 9 | -@RequestMapping("dictionary") | ||
| 10 | -public class DictionaryController extends BaseController<Dictionary, Integer>{ | ||
| 11 | - | ||
| 12 | -} | 1 | +package com.bsth.controller; |
| 2 | + | ||
| 3 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 4 | +import org.springframework.web.bind.annotation.RestController; | ||
| 5 | + | ||
| 6 | +import com.bsth.entity.sys.Dictionary; | ||
| 7 | + | ||
| 8 | +@RestController | ||
| 9 | +@RequestMapping("dictionary") | ||
| 10 | +public class DictionaryController extends BaseController<Dictionary, Integer>{ | ||
| 11 | + | ||
| 12 | +} |
src/main/java/com/bsth/controller/ModuleController.java
| 1 | -package com.bsth.controller; | ||
| 2 | - | ||
| 3 | -import java.util.List; | ||
| 4 | - | ||
| 5 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 6 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 7 | -import org.springframework.web.bind.annotation.RequestParam; | ||
| 8 | -import org.springframework.web.bind.annotation.RestController; | ||
| 9 | - | ||
| 10 | -import com.bsth.entity.sys.Module; | ||
| 11 | -import com.bsth.service.ModuleService; | ||
| 12 | - | ||
| 13 | -@RestController | ||
| 14 | -@RequestMapping("module") | ||
| 15 | -public class ModuleController extends BaseController<Module, Integer>{ | ||
| 16 | - | ||
| 17 | - @Autowired | ||
| 18 | - ModuleService moduleService; | ||
| 19 | - | ||
| 20 | - @RequestMapping(value = "/findByGroupType") | ||
| 21 | - public List<Module> findByGroupType(@RequestParam String group){ | ||
| 22 | - return moduleService.findByGroupType(group); | ||
| 23 | - } | ||
| 24 | - | ||
| 25 | - /** | ||
| 26 | - * | ||
| 27 | - * @Title: findByRoleId | ||
| 28 | - * @Description: TODO(根据角色获取功能模块) | ||
| 29 | - * @param @param roleId | ||
| 30 | - * @throws | ||
| 31 | - */ | ||
| 32 | - @RequestMapping(value = "/findByCurrentUser") | ||
| 33 | - public List<Module> findByCurrentUser(){ | ||
| 34 | - return moduleService.findByCurrentUser(); | ||
| 35 | - } | ||
| 36 | -} | 1 | +package com.bsth.controller; |
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | + | ||
| 5 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 6 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 7 | +import org.springframework.web.bind.annotation.RequestParam; | ||
| 8 | +import org.springframework.web.bind.annotation.RestController; | ||
| 9 | + | ||
| 10 | +import com.bsth.entity.sys.Module; | ||
| 11 | +import com.bsth.service.ModuleService; | ||
| 12 | + | ||
| 13 | +@RestController | ||
| 14 | +@RequestMapping("module") | ||
| 15 | +public class ModuleController extends BaseController<Module, Integer>{ | ||
| 16 | + | ||
| 17 | + @Autowired | ||
| 18 | + ModuleService moduleService; | ||
| 19 | + | ||
| 20 | + @RequestMapping(value = "/findByGroupType") | ||
| 21 | + public List<Module> findByGroupType(@RequestParam String group){ | ||
| 22 | + return moduleService.findByGroupType(group); | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * | ||
| 27 | + * @Title: findByRoleId | ||
| 28 | + * @Description: TODO(根据角色获取功能模块) | ||
| 29 | + * @param @param roleId | ||
| 30 | + * @throws | ||
| 31 | + */ | ||
| 32 | + @RequestMapping(value = "/findByCurrentUser") | ||
| 33 | + public List<Module> findByCurrentUser(){ | ||
| 34 | + return moduleService.findByCurrentUser(); | ||
| 35 | + } | ||
| 36 | +} |
src/main/java/com/bsth/controller/ResourceController.java
| 1 | -package com.bsth.controller; | ||
| 2 | - | ||
| 3 | -import java.util.Map; | ||
| 4 | - | ||
| 5 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 6 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 7 | -import org.springframework.web.bind.annotation.RequestMethod; | ||
| 8 | -import org.springframework.web.bind.annotation.RequestParam; | ||
| 9 | -import org.springframework.web.bind.annotation.RestController; | ||
| 10 | - | ||
| 11 | -import com.alibaba.fastjson.JSON; | ||
| 12 | -import com.bsth.entity.sys.Resource; | ||
| 13 | -import com.bsth.service.ResourceService; | ||
| 14 | - | ||
| 15 | -@RestController | ||
| 16 | -@RequestMapping("resource") | ||
| 17 | -public class ResourceController extends BaseController<Resource, Integer>{ | ||
| 18 | - | ||
| 19 | - @Autowired | ||
| 20 | - ResourceService resourceService; | ||
| 21 | - | ||
| 22 | - @RequestMapping(value = "/batch", method = RequestMethod.POST) | ||
| 23 | - public Map<String, Object> save(@RequestParam String array){ | ||
| 24 | - return resourceService.saveList(JSON.parseArray(array, Resource.class)); | ||
| 25 | - } | ||
| 26 | -} | 1 | +package com.bsth.controller; |
| 2 | + | ||
| 3 | +import java.util.Map; | ||
| 4 | + | ||
| 5 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 6 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 7 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
| 8 | +import org.springframework.web.bind.annotation.RequestParam; | ||
| 9 | +import org.springframework.web.bind.annotation.RestController; | ||
| 10 | + | ||
| 11 | +import com.alibaba.fastjson.JSON; | ||
| 12 | +import com.bsth.entity.sys.Resource; | ||
| 13 | +import com.bsth.service.ResourceService; | ||
| 14 | + | ||
| 15 | +@RestController | ||
| 16 | +@RequestMapping("resource") | ||
| 17 | +public class ResourceController extends BaseController<Resource, Integer>{ | ||
| 18 | + | ||
| 19 | + @Autowired | ||
| 20 | + ResourceService resourceService; | ||
| 21 | + | ||
| 22 | + @RequestMapping(value = "/batch", method = RequestMethod.POST) | ||
| 23 | + public Map<String, Object> save(@RequestParam String array){ | ||
| 24 | + return resourceService.saveList(JSON.parseArray(array, Resource.class)); | ||
| 25 | + } | ||
| 26 | +} |
src/main/java/com/bsth/controller/RoleController.java
| 1 | -package com.bsth.controller; | ||
| 2 | - | ||
| 3 | -import java.util.Map; | ||
| 4 | - | ||
| 5 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 6 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 7 | -import org.springframework.web.bind.annotation.RequestMethod; | ||
| 8 | -import org.springframework.web.bind.annotation.RequestParam; | ||
| 9 | -import org.springframework.web.bind.annotation.RestController; | ||
| 10 | - | ||
| 11 | -import com.bsth.entity.sys.Role; | ||
| 12 | -import com.bsth.service.RoleService; | ||
| 13 | - | ||
| 14 | -@RestController | ||
| 15 | -@RequestMapping("role") | ||
| 16 | -public class RoleController extends BaseController<Role, Integer>{ | ||
| 17 | - | ||
| 18 | - | ||
| 19 | - @Autowired | ||
| 20 | - RoleService roleService; | ||
| 21 | - | ||
| 22 | - /** | ||
| 23 | - * | ||
| 24 | - * @Title: settRoleModules | ||
| 25 | - * @Description: TODO(为角色设置模块,全量覆盖) | ||
| 26 | - * @param @param roleId 角色ID | ||
| 27 | - * @param @param mIds 模块ID字符串(1,2,3,4) | ||
| 28 | - * @throws | ||
| 29 | - */ | ||
| 30 | - @RequestMapping(value = "/settModules", method = RequestMethod.POST) | ||
| 31 | - public Map<String, Object> settRoleModules(@RequestParam Integer roleId,@RequestParam String mIds){ | ||
| 32 | - return roleService.settRoleModules(roleId, mIds); | ||
| 33 | - } | ||
| 34 | -} | 1 | +package com.bsth.controller; |
| 2 | + | ||
| 3 | +import java.util.Map; | ||
| 4 | + | ||
| 5 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 6 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 7 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
| 8 | +import org.springframework.web.bind.annotation.RequestParam; | ||
| 9 | +import org.springframework.web.bind.annotation.RestController; | ||
| 10 | + | ||
| 11 | +import com.bsth.entity.sys.Role; | ||
| 12 | +import com.bsth.service.RoleService; | ||
| 13 | + | ||
| 14 | +@RestController | ||
| 15 | +@RequestMapping("role") | ||
| 16 | +public class RoleController extends BaseController<Role, Integer>{ | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + @Autowired | ||
| 20 | + RoleService roleService; | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * | ||
| 24 | + * @Title: settRoleModules | ||
| 25 | + * @Description: TODO(为角色设置模块,全量覆盖) | ||
| 26 | + * @param @param roleId 角色ID | ||
| 27 | + * @param @param mIds 模块ID字符串(1,2,3,4) | ||
| 28 | + * @throws | ||
| 29 | + */ | ||
| 30 | + @RequestMapping(value = "/settModules", method = RequestMethod.POST) | ||
| 31 | + public Map<String, Object> settRoleModules(@RequestParam Integer roleId,@RequestParam String mIds){ | ||
| 32 | + return roleService.settRoleModules(roleId, mIds); | ||
| 33 | + } | ||
| 34 | +} |
src/main/java/com/bsth/controller/StationController.java
| 1 | package com.bsth.controller; | 1 | package com.bsth.controller; |
| 2 | 2 | ||
| 3 | +import java.util.Map; | ||
| 4 | + | ||
| 5 | +import org.hibernate.annotations.Parameter; | ||
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 3 | import org.springframework.web.bind.annotation.RequestMapping; | 7 | import org.springframework.web.bind.annotation.RequestMapping; |
| 8 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
| 9 | +import org.springframework.web.bind.annotation.RequestParam; | ||
| 4 | import org.springframework.web.bind.annotation.RestController; | 10 | import org.springframework.web.bind.annotation.RestController; |
| 5 | 11 | ||
| 12 | +import com.alibaba.fastjson.JSONArray; | ||
| 6 | import com.bsth.entity.Station; | 13 | import com.bsth.entity.Station; |
| 14 | +import com.bsth.service.StationService; | ||
| 7 | 15 | ||
| 8 | /** | 16 | /** |
| 9 | * | 17 | * |
| @@ -24,5 +32,23 @@ import com.bsth.entity.Station; | @@ -24,5 +32,23 @@ import com.bsth.entity.Station; | ||
| 24 | @RestController | 32 | @RestController |
| 25 | @RequestMapping("station") | 33 | @RequestMapping("station") |
| 26 | public class StationController extends BaseController<Station, Integer> { | 34 | public class StationController extends BaseController<Station, Integer> { |
| 27 | - | 35 | + |
| 36 | + @Autowired | ||
| 37 | + private StationService service; | ||
| 38 | + | ||
| 39 | + @RequestMapping(value="collection" , method = RequestMethod.POST) | ||
| 40 | + public Map<String, Object> collection(@RequestParam Map<String, Object> map) { | ||
| 41 | + | ||
| 42 | + String strJSON = map.get("json").toString().equals("") ? "" : map.get("json").toString(); | ||
| 43 | + | ||
| 44 | + if(!strJSON.equals("")) { | ||
| 45 | + | ||
| 46 | + JSONArray stationsArray = JSONArray.parseArray(strJSON); | ||
| 47 | + | ||
| 48 | + | ||
| 49 | + | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + return null; | ||
| 53 | + } | ||
| 28 | } | 54 | } |
src/main/java/com/bsth/controller/UserController.java
| 1 | -package com.bsth.controller; | ||
| 2 | - | ||
| 3 | -import javax.servlet.http.HttpServletRequest; | ||
| 4 | -import javax.servlet.http.HttpServletResponse; | ||
| 5 | -import javax.servlet.http.HttpSession; | ||
| 6 | - | ||
| 7 | -import org.springframework.security.authentication.BadCredentialsException; | ||
| 8 | -import org.springframework.security.core.Authentication; | ||
| 9 | -import org.springframework.security.core.context.SecurityContextHolder; | ||
| 10 | -import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler; | ||
| 11 | -import org.springframework.security.web.authentication.session.SessionAuthenticationException; | ||
| 12 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 13 | -import org.springframework.web.bind.annotation.RestController; | ||
| 14 | -import org.springframework.web.servlet.ModelAndView; | ||
| 15 | - | ||
| 16 | -import com.bsth.entity.sys.SysUser; | ||
| 17 | - | ||
| 18 | -@RestController | ||
| 19 | -@RequestMapping("user") | ||
| 20 | -public class UserController extends BaseController<SysUser, Integer>{ | ||
| 21 | - | ||
| 22 | - /** | ||
| 23 | - * | ||
| 24 | - * @Title: loginFailure | ||
| 25 | - * @Description: TODO(查询登录失败的详细信息) | ||
| 26 | - * @param @param request | ||
| 27 | - * @return String 返回类型 | ||
| 28 | - * @throws | ||
| 29 | - */ | ||
| 30 | - @RequestMapping("/loginFailure") | ||
| 31 | - public String loginFailure(HttpServletRequest request){ | ||
| 32 | - String msg = ""; | ||
| 33 | - HttpSession session = request.getSession(); | ||
| 34 | - | ||
| 35 | - Object obj = session.getAttribute("SPRING_SECURITY_LAST_EXCEPTION"); | ||
| 36 | - | ||
| 37 | - if(obj instanceof BadCredentialsException) | ||
| 38 | - msg = "登录失败,用户名或密码错误."; | ||
| 39 | - else if(obj instanceof SessionAuthenticationException) | ||
| 40 | - msg = "登录失败,当前策略不允许重复登录."; | ||
| 41 | - session.removeAttribute("SPRING_SECURITY_LAST_EXCEPTION"); | ||
| 42 | - return msg; | ||
| 43 | - } | ||
| 44 | - | ||
| 45 | - /** | ||
| 46 | - * | ||
| 47 | - * @Title: logout | ||
| 48 | - * @Description: TODO(注销吧皮卡丘) | ||
| 49 | - * @param @param request | ||
| 50 | - * @return ModelAndView 返回类型 | ||
| 51 | - * @throws | ||
| 52 | - */ | ||
| 53 | - @RequestMapping("/logout") | ||
| 54 | - public ModelAndView logout(HttpServletRequest request, HttpServletResponse response){ | ||
| 55 | - Authentication auth = SecurityContextHolder.getContext().getAuthentication(); | ||
| 56 | - if (auth != null){ | ||
| 57 | - new SecurityContextLogoutHandler().logout(request, response, auth); | ||
| 58 | - } | ||
| 59 | - return new ModelAndView("/"); | ||
| 60 | - } | ||
| 61 | -} | 1 | +package com.bsth.controller; |
| 2 | + | ||
| 3 | +import javax.servlet.http.HttpServletRequest; | ||
| 4 | +import javax.servlet.http.HttpServletResponse; | ||
| 5 | +import javax.servlet.http.HttpSession; | ||
| 6 | + | ||
| 7 | +import org.springframework.security.authentication.BadCredentialsException; | ||
| 8 | +import org.springframework.security.core.Authentication; | ||
| 9 | +import org.springframework.security.core.context.SecurityContextHolder; | ||
| 10 | +import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler; | ||
| 11 | +import org.springframework.security.web.authentication.session.SessionAuthenticationException; | ||
| 12 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 13 | +import org.springframework.web.bind.annotation.RestController; | ||
| 14 | +import org.springframework.web.servlet.ModelAndView; | ||
| 15 | + | ||
| 16 | +import com.bsth.entity.sys.SysUser; | ||
| 17 | + | ||
| 18 | +@RestController | ||
| 19 | +@RequestMapping("user") | ||
| 20 | +public class UserController extends BaseController<SysUser, Integer>{ | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * | ||
| 24 | + * @Title: loginFailure | ||
| 25 | + * @Description: TODO(查询登录失败的详细信息) | ||
| 26 | + * @param @param request | ||
| 27 | + * @return String 返回类型 | ||
| 28 | + * @throws | ||
| 29 | + */ | ||
| 30 | + @RequestMapping("/loginFailure") | ||
| 31 | + public String loginFailure(HttpServletRequest request){ | ||
| 32 | + String msg = ""; | ||
| 33 | + HttpSession session = request.getSession(); | ||
| 34 | + | ||
| 35 | + Object obj = session.getAttribute("SPRING_SECURITY_LAST_EXCEPTION"); | ||
| 36 | + | ||
| 37 | + if(obj instanceof BadCredentialsException) | ||
| 38 | + msg = "登录失败,用户名或密码错误."; | ||
| 39 | + else if(obj instanceof SessionAuthenticationException) | ||
| 40 | + msg = "登录失败,当前策略不允许重复登录."; | ||
| 41 | + session.removeAttribute("SPRING_SECURITY_LAST_EXCEPTION"); | ||
| 42 | + return msg; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * | ||
| 47 | + * @Title: logout | ||
| 48 | + * @Description: TODO(注销吧皮卡丘) | ||
| 49 | + * @param @param request | ||
| 50 | + * @return ModelAndView 返回类型 | ||
| 51 | + * @throws | ||
| 52 | + */ | ||
| 53 | + @RequestMapping("/logout") | ||
| 54 | + public ModelAndView logout(HttpServletRequest request, HttpServletResponse response){ | ||
| 55 | + Authentication auth = SecurityContextHolder.getContext().getAuthentication(); | ||
| 56 | + if (auth != null){ | ||
| 57 | + new SecurityContextLogoutHandler().logout(request, response, auth); | ||
| 58 | + } | ||
| 59 | + return new ModelAndView("/"); | ||
| 60 | + } | ||
| 61 | +} |
src/main/java/com/bsth/controller/schedule/BusinessInfoController.java
| 1 | -package com.bsth.controller.schedule; | ||
| 2 | - | ||
| 3 | -import com.bsth.controller.BaseController; | ||
| 4 | -import com.bsth.entity.schedule.BusinessInfo; | ||
| 5 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 6 | -import org.springframework.web.bind.annotation.RestController; | ||
| 7 | - | ||
| 8 | -/** | ||
| 9 | - * Created by xu on 16/5/11. | ||
| 10 | - */ | ||
| 11 | -@RestController | ||
| 12 | -@RequestMapping("bic") | ||
| 13 | -public class BusinessInfoController extends BaseController<BusinessInfo, Long> { | ||
| 14 | -} | 1 | +package com.bsth.controller.schedule; |
| 2 | + | ||
| 3 | +import com.bsth.controller.BaseController; | ||
| 4 | +import com.bsth.entity.schedule.BusinessInfo; | ||
| 5 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 6 | +import org.springframework.web.bind.annotation.RestController; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * Created by xu on 16/5/11. | ||
| 10 | + */ | ||
| 11 | +@RestController | ||
| 12 | +@RequestMapping("bic") | ||
| 13 | +public class BusinessInfoController extends BaseController<BusinessInfo, Long> { | ||
| 14 | +} |
src/main/java/com/bsth/controller/schedule/CarConfigInfoController.java
| 1 | -package com.bsth.controller.schedule; | ||
| 2 | - | ||
| 3 | -import com.bsth.controller.BaseController; | ||
| 4 | -import com.bsth.entity.schedule.CarConfigInfo; | ||
| 5 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 6 | -import org.springframework.web.bind.annotation.RestController; | ||
| 7 | - | ||
| 8 | -/** | ||
| 9 | - * Created by xu on 16/5/9. | ||
| 10 | - */ | ||
| 11 | -@RestController | ||
| 12 | -@RequestMapping("cci") | ||
| 13 | -public class CarConfigInfoController extends BaseController<CarConfigInfo, Long> { | ||
| 14 | -} | 1 | +package com.bsth.controller.schedule; |
| 2 | + | ||
| 3 | +import com.bsth.controller.BaseController; | ||
| 4 | +import com.bsth.entity.schedule.CarConfigInfo; | ||
| 5 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 6 | +import org.springframework.web.bind.annotation.RestController; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * Created by xu on 16/5/9. | ||
| 10 | + */ | ||
| 11 | +@RestController | ||
| 12 | +@RequestMapping("cci") | ||
| 13 | +public class CarConfigInfoController extends BaseController<CarConfigInfo, Long> { | ||
| 14 | +} |
src/main/java/com/bsth/controller/schedule/EmployeeConfigInfoController.java
| 1 | -package com.bsth.controller.schedule; | ||
| 2 | - | ||
| 3 | -import com.bsth.controller.BaseController; | ||
| 4 | -import com.bsth.entity.schedule.EmployeeConfigInfo; | ||
| 5 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 6 | -import org.springframework.web.bind.annotation.RestController; | ||
| 7 | - | ||
| 8 | -/** | ||
| 9 | - * Created by xu on 16/5/10. | ||
| 10 | - */ | ||
| 11 | -@RestController | ||
| 12 | -@RequestMapping("eci") | ||
| 13 | -public class EmployeeConfigInfoController extends BaseController<EmployeeConfigInfo, Long> { | ||
| 14 | -} | 1 | +package com.bsth.controller.schedule; |
| 2 | + | ||
| 3 | +import com.bsth.controller.BaseController; | ||
| 4 | +import com.bsth.entity.schedule.EmployeeConfigInfo; | ||
| 5 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 6 | +import org.springframework.web.bind.annotation.RestController; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * Created by xu on 16/5/10. | ||
| 10 | + */ | ||
| 11 | +@RestController | ||
| 12 | +@RequestMapping("eci") | ||
| 13 | +public class EmployeeConfigInfoController extends BaseController<EmployeeConfigInfo, Long> { | ||
| 14 | +} |
src/main/java/com/bsth/controller/schedule/GuideboardInfoController.java
| 1 | -package com.bsth.controller.schedule; | ||
| 2 | - | ||
| 3 | -import com.bsth.controller.BaseController; | ||
| 4 | -import com.bsth.entity.schedule.GuideboardInfo; | ||
| 5 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 6 | -import org.springframework.web.bind.annotation.RestController; | ||
| 7 | - | ||
| 8 | -/** | ||
| 9 | - * Created by xu on 16/5/11. | ||
| 10 | - */ | ||
| 11 | -@RestController | ||
| 12 | -@RequestMapping("gic") | ||
| 13 | -public class GuideboardInfoController extends BaseController<GuideboardInfo, Long> { | ||
| 14 | -} | 1 | +package com.bsth.controller.schedule; |
| 2 | + | ||
| 3 | +import com.bsth.controller.BaseController; | ||
| 4 | +import com.bsth.entity.schedule.GuideboardInfo; | ||
| 5 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 6 | +import org.springframework.web.bind.annotation.RestController; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * Created by xu on 16/5/11. | ||
| 10 | + */ | ||
| 11 | +@RestController | ||
| 12 | +@RequestMapping("gic") | ||
| 13 | +public class GuideboardInfoController extends BaseController<GuideboardInfo, Long> { | ||
| 14 | +} |
src/main/java/com/bsth/controller/schedule/TTInfoController.java
| 1 | -package com.bsth.controller.schedule; | ||
| 2 | - | ||
| 3 | -import com.bsth.controller.BaseController; | ||
| 4 | -import com.bsth.entity.schedule.TTInfo; | ||
| 5 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 6 | -import org.springframework.web.bind.annotation.RestController; | ||
| 7 | - | ||
| 8 | -/** | ||
| 9 | - * Created by xu on 16/5/12. | ||
| 10 | - */ | ||
| 11 | -@RestController | ||
| 12 | -@RequestMapping("tic") | ||
| 13 | -public class TTInfoController extends BaseController<TTInfo, Long> { | ||
| 14 | -} | 1 | +package com.bsth.controller.schedule; |
| 2 | + | ||
| 3 | +import com.bsth.controller.BaseController; | ||
| 4 | +import com.bsth.entity.schedule.TTInfo; | ||
| 5 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 6 | +import org.springframework.web.bind.annotation.RestController; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * Created by xu on 16/5/12. | ||
| 10 | + */ | ||
| 11 | +@RestController | ||
| 12 | +@RequestMapping("tic") | ||
| 13 | +public class TTInfoController extends BaseController<TTInfo, Long> { | ||
| 14 | +} |
src/main/java/com/bsth/entity/CarDevice.java
| 1 | -package com.bsth.entity; | ||
| 2 | - | ||
| 3 | -import javax.persistence.*; | ||
| 4 | -import java.util.Date; | ||
| 5 | - | ||
| 6 | -/** | ||
| 7 | - * 车辆设备信息(记录车辆设备变更情况,因为是历史表,字段不做关联) | ||
| 8 | - */ | ||
| 9 | -@Entity | ||
| 10 | -@Table(name = "bsth_c_car_device") | ||
| 11 | -public class CarDevice { | ||
| 12 | - | ||
| 13 | - /** 主键 */ | ||
| 14 | - @Id | ||
| 15 | - @GeneratedValue | ||
| 16 | - private Long id; | ||
| 17 | - | ||
| 18 | - /** 公司名称 */ | ||
| 19 | - @Column(nullable = false) | ||
| 20 | - private String gsName; | ||
| 21 | - /** 内部编号(自编号) */ | ||
| 22 | - private String clZbh; | ||
| 23 | - /** 线路名称 */ | ||
| 24 | - private String xlName; | ||
| 25 | - | ||
| 26 | - /** 旧终端号 */ | ||
| 27 | - private String oldDeviceNo; | ||
| 28 | - /** 新终端号 */ | ||
| 29 | - private String newDeviceNo; | ||
| 30 | - /** 旧SIM卡号 */ | ||
| 31 | - private String oldSimNo; | ||
| 32 | - /** 新SIM卡号 */ | ||
| 33 | - private String newSimNo; | ||
| 34 | - | ||
| 35 | - /** 故障描述 */ | ||
| 36 | - private String troubleDesc; | ||
| 37 | - /** 保修描述 */ | ||
| 38 | - private String guaranteeDesc; | ||
| 39 | - | ||
| 40 | - // 创建日期 | ||
| 41 | - @Column(updatable = false, name = "create_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") | ||
| 42 | - private Date createDate; | ||
| 43 | - | ||
| 44 | - // 修改日期 | ||
| 45 | - @Column(name = "update_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP") | ||
| 46 | - private Date updateDate; | ||
| 47 | - | ||
| 48 | - public Long getId() { | ||
| 49 | - return id; | ||
| 50 | - } | ||
| 51 | - | ||
| 52 | - public void setId(Long id) { | ||
| 53 | - this.id = id; | ||
| 54 | - } | ||
| 55 | - | ||
| 56 | - public String getGsName() { | ||
| 57 | - return gsName; | ||
| 58 | - } | ||
| 59 | - | ||
| 60 | - public void setGsName(String gsName) { | ||
| 61 | - this.gsName = gsName; | ||
| 62 | - } | ||
| 63 | - | ||
| 64 | - public String getClZbh() { | ||
| 65 | - return clZbh; | ||
| 66 | - } | ||
| 67 | - | ||
| 68 | - public void setClZbh(String clZbh) { | ||
| 69 | - this.clZbh = clZbh; | ||
| 70 | - } | ||
| 71 | - | ||
| 72 | - public String getXlName() { | ||
| 73 | - return xlName; | ||
| 74 | - } | ||
| 75 | - | ||
| 76 | - public void setXlName(String xlName) { | ||
| 77 | - this.xlName = xlName; | ||
| 78 | - } | ||
| 79 | - | ||
| 80 | - public String getOldDeviceNo() { | ||
| 81 | - return oldDeviceNo; | ||
| 82 | - } | ||
| 83 | - | ||
| 84 | - public void setOldDeviceNo(String oldDeviceNo) { | ||
| 85 | - this.oldDeviceNo = oldDeviceNo; | ||
| 86 | - } | ||
| 87 | - | ||
| 88 | - public String getNewDeviceNo() { | ||
| 89 | - return newDeviceNo; | ||
| 90 | - } | ||
| 91 | - | ||
| 92 | - public void setNewDeviceNo(String newDeviceNo) { | ||
| 93 | - this.newDeviceNo = newDeviceNo; | ||
| 94 | - } | ||
| 95 | - | ||
| 96 | - public String getOldSimNo() { | ||
| 97 | - return oldSimNo; | ||
| 98 | - } | ||
| 99 | - | ||
| 100 | - public void setOldSimNo(String oldSimNo) { | ||
| 101 | - this.oldSimNo = oldSimNo; | ||
| 102 | - } | ||
| 103 | - | ||
| 104 | - public String getNewSimNo() { | ||
| 105 | - return newSimNo; | ||
| 106 | - } | ||
| 107 | - | ||
| 108 | - public void setNewSimNo(String newSimNo) { | ||
| 109 | - this.newSimNo = newSimNo; | ||
| 110 | - } | ||
| 111 | - | ||
| 112 | - public String getTroubleDesc() { | ||
| 113 | - return troubleDesc; | ||
| 114 | - } | ||
| 115 | - | ||
| 116 | - public void setTroubleDesc(String troubleDesc) { | ||
| 117 | - this.troubleDesc = troubleDesc; | ||
| 118 | - } | ||
| 119 | - | ||
| 120 | - public String getGuaranteeDesc() { | ||
| 121 | - return guaranteeDesc; | ||
| 122 | - } | ||
| 123 | - | ||
| 124 | - public void setGuaranteeDesc(String guaranteeDesc) { | ||
| 125 | - this.guaranteeDesc = guaranteeDesc; | ||
| 126 | - } | ||
| 127 | - | ||
| 128 | - public Date getCreateDate() { | ||
| 129 | - return createDate; | ||
| 130 | - } | ||
| 131 | - | ||
| 132 | - public void setCreateDate(Date createDate) { | ||
| 133 | - this.createDate = createDate; | ||
| 134 | - } | ||
| 135 | - | ||
| 136 | - public Date getUpdateDate() { | ||
| 137 | - return updateDate; | ||
| 138 | - } | ||
| 139 | - | ||
| 140 | - public void setUpdateDate(Date updateDate) { | ||
| 141 | - this.updateDate = updateDate; | ||
| 142 | - } | ||
| 143 | -} | 1 | +package com.bsth.entity; |
| 2 | + | ||
| 3 | +import javax.persistence.*; | ||
| 4 | +import java.util.Date; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 车辆设备信息(记录车辆设备变更情况,因为是历史表,字段不做关联) | ||
| 8 | + */ | ||
| 9 | +@Entity | ||
| 10 | +@Table(name = "bsth_c_car_device") | ||
| 11 | +public class CarDevice { | ||
| 12 | + | ||
| 13 | + /** 主键 */ | ||
| 14 | + @Id | ||
| 15 | + @GeneratedValue | ||
| 16 | + private Long id; | ||
| 17 | + | ||
| 18 | + /** 公司名称 */ | ||
| 19 | + @Column(nullable = false) | ||
| 20 | + private String gsName; | ||
| 21 | + /** 内部编号(自编号) */ | ||
| 22 | + private String clZbh; | ||
| 23 | + /** 线路名称 */ | ||
| 24 | + private String xlName; | ||
| 25 | + | ||
| 26 | + /** 旧终端号 */ | ||
| 27 | + private String oldDeviceNo; | ||
| 28 | + /** 新终端号 */ | ||
| 29 | + private String newDeviceNo; | ||
| 30 | + /** 旧SIM卡号 */ | ||
| 31 | + private String oldSimNo; | ||
| 32 | + /** 新SIM卡号 */ | ||
| 33 | + private String newSimNo; | ||
| 34 | + | ||
| 35 | + /** 故障描述 */ | ||
| 36 | + private String troubleDesc; | ||
| 37 | + /** 保修描述 */ | ||
| 38 | + private String guaranteeDesc; | ||
| 39 | + | ||
| 40 | + // 创建日期 | ||
| 41 | + @Column(updatable = false, name = "create_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") | ||
| 42 | + private Date createDate; | ||
| 43 | + | ||
| 44 | + // 修改日期 | ||
| 45 | + @Column(name = "update_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP") | ||
| 46 | + private Date updateDate; | ||
| 47 | + | ||
| 48 | + public Long getId() { | ||
| 49 | + return id; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public void setId(Long id) { | ||
| 53 | + this.id = id; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public String getGsName() { | ||
| 57 | + return gsName; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + public void setGsName(String gsName) { | ||
| 61 | + this.gsName = gsName; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + public String getClZbh() { | ||
| 65 | + return clZbh; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + public void setClZbh(String clZbh) { | ||
| 69 | + this.clZbh = clZbh; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + public String getXlName() { | ||
| 73 | + return xlName; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public void setXlName(String xlName) { | ||
| 77 | + this.xlName = xlName; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + public String getOldDeviceNo() { | ||
| 81 | + return oldDeviceNo; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + public void setOldDeviceNo(String oldDeviceNo) { | ||
| 85 | + this.oldDeviceNo = oldDeviceNo; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + public String getNewDeviceNo() { | ||
| 89 | + return newDeviceNo; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + public void setNewDeviceNo(String newDeviceNo) { | ||
| 93 | + this.newDeviceNo = newDeviceNo; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + public String getOldSimNo() { | ||
| 97 | + return oldSimNo; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + public void setOldSimNo(String oldSimNo) { | ||
| 101 | + this.oldSimNo = oldSimNo; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + public String getNewSimNo() { | ||
| 105 | + return newSimNo; | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + public void setNewSimNo(String newSimNo) { | ||
| 109 | + this.newSimNo = newSimNo; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + public String getTroubleDesc() { | ||
| 113 | + return troubleDesc; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + public void setTroubleDesc(String troubleDesc) { | ||
| 117 | + this.troubleDesc = troubleDesc; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + public String getGuaranteeDesc() { | ||
| 121 | + return guaranteeDesc; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + public void setGuaranteeDesc(String guaranteeDesc) { | ||
| 125 | + this.guaranteeDesc = guaranteeDesc; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + public Date getCreateDate() { | ||
| 129 | + return createDate; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + public void setCreateDate(Date createDate) { | ||
| 133 | + this.createDate = createDate; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + public Date getUpdateDate() { | ||
| 137 | + return updateDate; | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + public void setUpdateDate(Date updateDate) { | ||
| 141 | + this.updateDate = updateDate; | ||
| 142 | + } | ||
| 143 | +} |
src/main/java/com/bsth/entity/schedule/BusinessInfo.java
| 1 | -package com.bsth.entity.schedule; | ||
| 2 | - | ||
| 3 | -import javax.persistence.*; | ||
| 4 | -import java.util.Date; | ||
| 5 | - | ||
| 6 | -/** | ||
| 7 | - * 线路运营信息汇总。 | ||
| 8 | - * TODO:暂时这样写,演示后重新修正 | ||
| 9 | - */ | ||
| 10 | -@Entity | ||
| 11 | -@Table(name = "bsth_c_s_bi") | ||
| 12 | -public class BusinessInfo { | ||
| 13 | - | ||
| 14 | - /** 主键Id */ | ||
| 15 | - @Id | ||
| 16 | - @GeneratedValue | ||
| 17 | - private Long id; | ||
| 18 | - | ||
| 19 | - /** TODO:之后修正 */ | ||
| 20 | - /** 线路名称 */ | ||
| 21 | - private String xlName; | ||
| 22 | - /** 线路编码 */ | ||
| 23 | - private String xlBm; | ||
| 24 | - /** 公司名称 */ | ||
| 25 | - private String gsName; | ||
| 26 | - /** 分公司名称 */ | ||
| 27 | - private String fgsName; | ||
| 28 | - | ||
| 29 | - /** 配车数 */ | ||
| 30 | - private int pcCount; | ||
| 31 | - /** 人员数 */ | ||
| 32 | - private int ryCount; | ||
| 33 | - /** 路牌数 */ | ||
| 34 | - private int lpCount; | ||
| 35 | - /** 套跑数 */ | ||
| 36 | - private int tpCount; | ||
| 37 | - /** 时刻表数 */ | ||
| 38 | - private int ttCount; | ||
| 39 | - /** 调度规则数 */ | ||
| 40 | - private int srCount; | ||
| 41 | - /** 调度计划数 */ | ||
| 42 | - private int spCount; | ||
| 43 | - | ||
| 44 | - // 创建日期 | ||
| 45 | - @Column(updatable = false, name = "create_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") | ||
| 46 | - private Date createDate; | ||
| 47 | - // 修改日期 | ||
| 48 | - @Column(name = "update_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP") | ||
| 49 | - private Date updateDate; | ||
| 50 | - | ||
| 51 | - public Long getId() { | ||
| 52 | - return id; | ||
| 53 | - } | ||
| 54 | - | ||
| 55 | - public void setId(Long id) { | ||
| 56 | - this.id = id; | ||
| 57 | - } | ||
| 58 | - | ||
| 59 | - public String getXlName() { | ||
| 60 | - return xlName; | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | - public void setXlName(String xlName) { | ||
| 64 | - this.xlName = xlName; | ||
| 65 | - } | ||
| 66 | - | ||
| 67 | - public String getXlBm() { | ||
| 68 | - return xlBm; | ||
| 69 | - } | ||
| 70 | - | ||
| 71 | - public void setXlBm(String xlBm) { | ||
| 72 | - this.xlBm = xlBm; | ||
| 73 | - } | ||
| 74 | - | ||
| 75 | - public String getGsName() { | ||
| 76 | - return gsName; | ||
| 77 | - } | ||
| 78 | - | ||
| 79 | - public void setGsName(String gsName) { | ||
| 80 | - this.gsName = gsName; | ||
| 81 | - } | ||
| 82 | - | ||
| 83 | - public String getFgsName() { | ||
| 84 | - return fgsName; | ||
| 85 | - } | ||
| 86 | - | ||
| 87 | - public void setFgsName(String fgsName) { | ||
| 88 | - this.fgsName = fgsName; | ||
| 89 | - } | ||
| 90 | - | ||
| 91 | - public int getPcCount() { | ||
| 92 | - return pcCount; | ||
| 93 | - } | ||
| 94 | - | ||
| 95 | - public void setPcCount(int pcCount) { | ||
| 96 | - this.pcCount = pcCount; | ||
| 97 | - } | ||
| 98 | - | ||
| 99 | - public int getRyCount() { | ||
| 100 | - return ryCount; | ||
| 101 | - } | ||
| 102 | - | ||
| 103 | - public void setRyCount(int ryCount) { | ||
| 104 | - this.ryCount = ryCount; | ||
| 105 | - } | ||
| 106 | - | ||
| 107 | - public int getLpCount() { | ||
| 108 | - return lpCount; | ||
| 109 | - } | ||
| 110 | - | ||
| 111 | - public void setLpCount(int lpCount) { | ||
| 112 | - this.lpCount = lpCount; | ||
| 113 | - } | ||
| 114 | - | ||
| 115 | - public int getTpCount() { | ||
| 116 | - return tpCount; | ||
| 117 | - } | ||
| 118 | - | ||
| 119 | - public void setTpCount(int tpCount) { | ||
| 120 | - this.tpCount = tpCount; | ||
| 121 | - } | ||
| 122 | - | ||
| 123 | - public int getTtCount() { | ||
| 124 | - return ttCount; | ||
| 125 | - } | ||
| 126 | - | ||
| 127 | - public void setTtCount(int ttCount) { | ||
| 128 | - this.ttCount = ttCount; | ||
| 129 | - } | ||
| 130 | - | ||
| 131 | - public int getSrCount() { | ||
| 132 | - return srCount; | ||
| 133 | - } | ||
| 134 | - | ||
| 135 | - public void setSrCount(int srCount) { | ||
| 136 | - this.srCount = srCount; | ||
| 137 | - } | ||
| 138 | - | ||
| 139 | - public int getSpCount() { | ||
| 140 | - return spCount; | ||
| 141 | - } | ||
| 142 | - | ||
| 143 | - public void setSpCount(int spCount) { | ||
| 144 | - this.spCount = spCount; | ||
| 145 | - } | ||
| 146 | - | ||
| 147 | - public Date getCreateDate() { | ||
| 148 | - return createDate; | ||
| 149 | - } | ||
| 150 | - | ||
| 151 | - public void setCreateDate(Date createDate) { | ||
| 152 | - this.createDate = createDate; | ||
| 153 | - } | ||
| 154 | - | ||
| 155 | - public Date getUpdateDate() { | ||
| 156 | - return updateDate; | ||
| 157 | - } | ||
| 158 | - | ||
| 159 | - public void setUpdateDate(Date updateDate) { | ||
| 160 | - this.updateDate = updateDate; | ||
| 161 | - } | ||
| 162 | -} | 1 | +package com.bsth.entity.schedule; |
| 2 | + | ||
| 3 | +import javax.persistence.*; | ||
| 4 | +import java.util.Date; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 线路运营信息汇总。 | ||
| 8 | + * TODO:暂时这样写,演示后重新修正 | ||
| 9 | + */ | ||
| 10 | +@Entity | ||
| 11 | +@Table(name = "bsth_c_s_bi") | ||
| 12 | +public class BusinessInfo { | ||
| 13 | + | ||
| 14 | + /** 主键Id */ | ||
| 15 | + @Id | ||
| 16 | + @GeneratedValue | ||
| 17 | + private Long id; | ||
| 18 | + | ||
| 19 | + /** TODO:之后修正 */ | ||
| 20 | + /** 线路名称 */ | ||
| 21 | + private String xlName; | ||
| 22 | + /** 线路编码 */ | ||
| 23 | + private String xlBm; | ||
| 24 | + /** 公司名称 */ | ||
| 25 | + private String gsName; | ||
| 26 | + /** 分公司名称 */ | ||
| 27 | + private String fgsName; | ||
| 28 | + | ||
| 29 | + /** 配车数 */ | ||
| 30 | + private int pcCount; | ||
| 31 | + /** 人员数 */ | ||
| 32 | + private int ryCount; | ||
| 33 | + /** 路牌数 */ | ||
| 34 | + private int lpCount; | ||
| 35 | + /** 套跑数 */ | ||
| 36 | + private int tpCount; | ||
| 37 | + /** 时刻表数 */ | ||
| 38 | + private int ttCount; | ||
| 39 | + /** 调度规则数 */ | ||
| 40 | + private int srCount; | ||
| 41 | + /** 调度计划数 */ | ||
| 42 | + private int spCount; | ||
| 43 | + | ||
| 44 | + // 创建日期 | ||
| 45 | + @Column(updatable = false, name = "create_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") | ||
| 46 | + private Date createDate; | ||
| 47 | + // 修改日期 | ||
| 48 | + @Column(name = "update_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP") | ||
| 49 | + private Date updateDate; | ||
| 50 | + | ||
| 51 | + public Long getId() { | ||
| 52 | + return id; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public void setId(Long id) { | ||
| 56 | + this.id = id; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public String getXlName() { | ||
| 60 | + return xlName; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public void setXlName(String xlName) { | ||
| 64 | + this.xlName = xlName; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public String getXlBm() { | ||
| 68 | + return xlBm; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public void setXlBm(String xlBm) { | ||
| 72 | + this.xlBm = xlBm; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public String getGsName() { | ||
| 76 | + return gsName; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public void setGsName(String gsName) { | ||
| 80 | + this.gsName = gsName; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + public String getFgsName() { | ||
| 84 | + return fgsName; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + public void setFgsName(String fgsName) { | ||
| 88 | + this.fgsName = fgsName; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + public int getPcCount() { | ||
| 92 | + return pcCount; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + public void setPcCount(int pcCount) { | ||
| 96 | + this.pcCount = pcCount; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + public int getRyCount() { | ||
| 100 | + return ryCount; | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + public void setRyCount(int ryCount) { | ||
| 104 | + this.ryCount = ryCount; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + public int getLpCount() { | ||
| 108 | + return lpCount; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + public void setLpCount(int lpCount) { | ||
| 112 | + this.lpCount = lpCount; | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + public int getTpCount() { | ||
| 116 | + return tpCount; | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + public void setTpCount(int tpCount) { | ||
| 120 | + this.tpCount = tpCount; | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + public int getTtCount() { | ||
| 124 | + return ttCount; | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + public void setTtCount(int ttCount) { | ||
| 128 | + this.ttCount = ttCount; | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + public int getSrCount() { | ||
| 132 | + return srCount; | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + public void setSrCount(int srCount) { | ||
| 136 | + this.srCount = srCount; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + public int getSpCount() { | ||
| 140 | + return spCount; | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + public void setSpCount(int spCount) { | ||
| 144 | + this.spCount = spCount; | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + public Date getCreateDate() { | ||
| 148 | + return createDate; | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + public void setCreateDate(Date createDate) { | ||
| 152 | + this.createDate = createDate; | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + public Date getUpdateDate() { | ||
| 156 | + return updateDate; | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + public void setUpdateDate(Date updateDate) { | ||
| 160 | + this.updateDate = updateDate; | ||
| 161 | + } | ||
| 162 | +} |
src/main/java/com/bsth/entity/search/CustomerSpecs.java
| 1 | -package com.bsth.entity.search; | ||
| 2 | - | ||
| 3 | -import java.lang.reflect.Method; | ||
| 4 | -import java.util.ArrayList; | ||
| 5 | -import java.util.List; | ||
| 6 | -import java.util.Map; | ||
| 7 | -import java.util.Set; | ||
| 8 | -import java.util.TreeSet; | ||
| 9 | - | ||
| 10 | -import javax.persistence.criteria.CriteriaBuilder; | ||
| 11 | -import javax.persistence.criteria.CriteriaQuery; | ||
| 12 | -import javax.persistence.criteria.Path; | ||
| 13 | -import javax.persistence.criteria.Predicate; | ||
| 14 | -import javax.persistence.criteria.Root; | ||
| 15 | - | ||
| 16 | -import org.apache.commons.lang3.StringUtils; | ||
| 17 | -import org.slf4j.Logger; | ||
| 18 | -import org.slf4j.LoggerFactory; | ||
| 19 | -import org.springframework.data.jpa.domain.Specification; | ||
| 20 | - | ||
| 21 | -import com.bsth.entity.search.exception.UnrecognizableSearchSymbolException; | ||
| 22 | - | ||
| 23 | -/** | ||
| 24 | - * | ||
| 25 | - * @ClassName: CustomerSpecs | ||
| 26 | - * @Description: 用于动态条件查询的Specification | ||
| 27 | - * @author PanZhao | ||
| 28 | - * @date 2016年3月16日 下午4:05:22 | ||
| 29 | - * | ||
| 30 | - * @param <T> | ||
| 31 | - */ | ||
| 32 | -public class CustomerSpecs<T> implements Specification<T> { | ||
| 33 | - | ||
| 34 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 35 | - | ||
| 36 | - private Map<String, Object> map; | ||
| 37 | - | ||
| 38 | - // 查询操作符 | ||
| 39 | - private static Set<String> eSet; | ||
| 40 | - | ||
| 41 | - static { | ||
| 42 | - eSet = new TreeSet<String>(); | ||
| 43 | - for (SearchOperator s : SearchOperator.values()) { | ||
| 44 | - eSet.add(s.toString()); | ||
| 45 | - } | ||
| 46 | - } | ||
| 47 | - | ||
| 48 | - private static Class<PredicatesBuilder> preBuilderClazz = PredicatesBuilder.class; | ||
| 49 | - private static Class<CriteriaBuilder> cBuilderClazz = CriteriaBuilder.class; | ||
| 50 | - private static Class<Object> objClazz = Object.class; | ||
| 51 | - | ||
| 52 | - // 查询参数分隔符 | ||
| 53 | - public static final String separator = "_"; | ||
| 54 | - | ||
| 55 | - /** | ||
| 56 | - * 构造函数 | ||
| 57 | - * | ||
| 58 | - * @param map | ||
| 59 | - */ | ||
| 60 | - public CustomerSpecs(Map<String, Object> map) { | ||
| 61 | - this.map = map; | ||
| 62 | - } | ||
| 63 | - | ||
| 64 | - @Override | ||
| 65 | - public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, | ||
| 66 | - CriteriaBuilder cb) { | ||
| 67 | - List<Predicate> predicates = new ArrayList<>(); | ||
| 68 | - | ||
| 69 | - for (Map.Entry<String, Object> entry : map.entrySet()) { | ||
| 70 | - Object value = entry.getValue(); | ||
| 71 | - String[] searchs = StringUtils.split(entry.getKey(), separator); | ||
| 72 | - if (null == searchs || searchs.length < 2) | ||
| 73 | - continue; | ||
| 74 | - // 值为空的不参与查询 | ||
| 75 | - if (value == null || (value instanceof String && value.equals(""))) | ||
| 76 | - continue; | ||
| 77 | - | ||
| 78 | - try { | ||
| 79 | - if(!eSet.contains(searchs[1])) | ||
| 80 | - throw new UnrecognizableSearchSymbolException(searchs[1]); | ||
| 81 | - | ||
| 82 | - // 根据操作符调用对应静态函数 | ||
| 83 | - Method method = preBuilderClazz.getMethod(searchs[1], | ||
| 84 | - cBuilderClazz, Path.class, objClazz); | ||
| 85 | - | ||
| 86 | - Predicate predicate = (Predicate) method.invoke(null, cb, | ||
| 87 | - createPath(root, searchs[0]), value); | ||
| 88 | - | ||
| 89 | - predicates.add(predicate); | ||
| 90 | - } catch (Exception e) { | ||
| 91 | - logger.error("Specification search error.", e); | ||
| 92 | - } | ||
| 93 | - } | ||
| 94 | - Predicate[] pre = new Predicate[predicates.size()]; | ||
| 95 | - return query.where(predicates.toArray(pre)).getRestriction(); | ||
| 96 | - } | ||
| 97 | - | ||
| 98 | - /** | ||
| 99 | - * 生成Path | ||
| 100 | - * @param root | ||
| 101 | - * @param field | ||
| 102 | - * @return | ||
| 103 | - */ | ||
| 104 | - public Path<T> createPath(Root<T> root, String field){ | ||
| 105 | - Path<T> p = null; | ||
| 106 | - | ||
| 107 | - if(field.indexOf(".") == -1) | ||
| 108 | - p = root.get(field); | ||
| 109 | - else{ | ||
| 110 | - String[] fs = field.split("\\."); | ||
| 111 | - | ||
| 112 | - p = root.get(fs[0]); | ||
| 113 | - for(int i = 1; i < fs.length; i ++){ | ||
| 114 | - p = p.get(fs[i]); | ||
| 115 | - } | ||
| 116 | - } | ||
| 117 | - return p; | ||
| 118 | - } | ||
| 119 | -} | 1 | +package com.bsth.entity.search; |
| 2 | + | ||
| 3 | +import java.lang.reflect.Method; | ||
| 4 | +import java.util.ArrayList; | ||
| 5 | +import java.util.List; | ||
| 6 | +import java.util.Map; | ||
| 7 | +import java.util.Set; | ||
| 8 | +import java.util.TreeSet; | ||
| 9 | + | ||
| 10 | +import javax.persistence.criteria.CriteriaBuilder; | ||
| 11 | +import javax.persistence.criteria.CriteriaQuery; | ||
| 12 | +import javax.persistence.criteria.Path; | ||
| 13 | +import javax.persistence.criteria.Predicate; | ||
| 14 | +import javax.persistence.criteria.Root; | ||
| 15 | + | ||
| 16 | +import org.apache.commons.lang3.StringUtils; | ||
| 17 | +import org.slf4j.Logger; | ||
| 18 | +import org.slf4j.LoggerFactory; | ||
| 19 | +import org.springframework.data.jpa.domain.Specification; | ||
| 20 | + | ||
| 21 | +import com.bsth.entity.search.exception.UnrecognizableSearchSymbolException; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * | ||
| 25 | + * @ClassName: CustomerSpecs | ||
| 26 | + * @Description: 用于动态条件查询的Specification | ||
| 27 | + * @author PanZhao | ||
| 28 | + * @date 2016年3月16日 下午4:05:22 | ||
| 29 | + * | ||
| 30 | + * @param <T> | ||
| 31 | + */ | ||
| 32 | +public class CustomerSpecs<T> implements Specification<T> { | ||
| 33 | + | ||
| 34 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 35 | + | ||
| 36 | + private Map<String, Object> map; | ||
| 37 | + | ||
| 38 | + // 查询操作符 | ||
| 39 | + private static Set<String> eSet; | ||
| 40 | + | ||
| 41 | + static { | ||
| 42 | + eSet = new TreeSet<String>(); | ||
| 43 | + for (SearchOperator s : SearchOperator.values()) { | ||
| 44 | + eSet.add(s.toString()); | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + private static Class<PredicatesBuilder> preBuilderClazz = PredicatesBuilder.class; | ||
| 49 | + private static Class<CriteriaBuilder> cBuilderClazz = CriteriaBuilder.class; | ||
| 50 | + private static Class<Object> objClazz = Object.class; | ||
| 51 | + | ||
| 52 | + // 查询参数分隔符 | ||
| 53 | + public static final String separator = "_"; | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * 构造函数 | ||
| 57 | + * | ||
| 58 | + * @param map | ||
| 59 | + */ | ||
| 60 | + public CustomerSpecs(Map<String, Object> map) { | ||
| 61 | + this.map = map; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + @Override | ||
| 65 | + public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, | ||
| 66 | + CriteriaBuilder cb) { | ||
| 67 | + List<Predicate> predicates = new ArrayList<>(); | ||
| 68 | + | ||
| 69 | + for (Map.Entry<String, Object> entry : map.entrySet()) { | ||
| 70 | + Object value = entry.getValue(); | ||
| 71 | + String[] searchs = StringUtils.split(entry.getKey(), separator); | ||
| 72 | + if (null == searchs || searchs.length < 2) | ||
| 73 | + continue; | ||
| 74 | + // 值为空的不参与查询 | ||
| 75 | + if (value == null || (value instanceof String && value.equals(""))) | ||
| 76 | + continue; | ||
| 77 | + | ||
| 78 | + try { | ||
| 79 | + if(!eSet.contains(searchs[1])) | ||
| 80 | + throw new UnrecognizableSearchSymbolException(searchs[1]); | ||
| 81 | + | ||
| 82 | + // 根据操作符调用对应静态函数 | ||
| 83 | + Method method = preBuilderClazz.getMethod(searchs[1], | ||
| 84 | + cBuilderClazz, Path.class, objClazz); | ||
| 85 | + | ||
| 86 | + Predicate predicate = (Predicate) method.invoke(null, cb, | ||
| 87 | + createPath(root, searchs[0]), value); | ||
| 88 | + | ||
| 89 | + predicates.add(predicate); | ||
| 90 | + } catch (Exception e) { | ||
| 91 | + logger.error("Specification search error.", e); | ||
| 92 | + } | ||
| 93 | + } | ||
| 94 | + Predicate[] pre = new Predicate[predicates.size()]; | ||
| 95 | + return query.where(predicates.toArray(pre)).getRestriction(); | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + /** | ||
| 99 | + * 生成Path | ||
| 100 | + * @param root | ||
| 101 | + * @param field | ||
| 102 | + * @return | ||
| 103 | + */ | ||
| 104 | + public Path<T> createPath(Root<T> root, String field){ | ||
| 105 | + Path<T> p = null; | ||
| 106 | + | ||
| 107 | + if(field.indexOf(".") == -1) | ||
| 108 | + p = root.get(field); | ||
| 109 | + else{ | ||
| 110 | + String[] fs = field.split("\\."); | ||
| 111 | + | ||
| 112 | + p = root.get(fs[0]); | ||
| 113 | + for(int i = 1; i < fs.length; i ++){ | ||
| 114 | + p = p.get(fs[i]); | ||
| 115 | + } | ||
| 116 | + } | ||
| 117 | + return p; | ||
| 118 | + } | ||
| 119 | +} |
src/main/java/com/bsth/entity/search/PredicatesBuilder.java
| 1 | -package com.bsth.entity.search; | ||
| 2 | - | ||
| 3 | -import java.text.NumberFormat; | ||
| 4 | -import java.text.ParseException; | ||
| 5 | -import javax.persistence.criteria.CriteriaBuilder; | ||
| 6 | -import javax.persistence.criteria.Path; | ||
| 7 | -import javax.persistence.criteria.Predicate; | ||
| 8 | - | ||
| 9 | -/** | ||
| 10 | - * | ||
| 11 | - * @ClassName: PredicatesBuilder | ||
| 12 | - * @author PanZhao | ||
| 13 | - * @date 2016年3月16日 下午4:05:07 | ||
| 14 | - * | ||
| 15 | - */ | ||
| 16 | -public class PredicatesBuilder { | ||
| 17 | - | ||
| 18 | - /** | ||
| 19 | - * Number转换器 | ||
| 20 | - */ | ||
| 21 | - private static NumberFormat nf; | ||
| 22 | - | ||
| 23 | - static{ | ||
| 24 | - nf = NumberFormat.getInstance(); | ||
| 25 | - } | ||
| 26 | - | ||
| 27 | - public static Predicate eq(CriteriaBuilder cb,Path<?> expression, Object object){ | ||
| 28 | - return cb.equal(expression, object); | ||
| 29 | - } | ||
| 30 | - | ||
| 31 | - public static Predicate ne(CriteriaBuilder cb,Path<?> expression, Object object){ | ||
| 32 | - return cb.notEqual(expression, object); | ||
| 33 | - } | ||
| 34 | - | ||
| 35 | - public static Predicate gt(CriteriaBuilder cb,Path<Number> expression, Object object){ | ||
| 36 | - try { | ||
| 37 | - return cb.gt(expression, nf.parse(object.toString())); | ||
| 38 | - } catch (ParseException e) { | ||
| 39 | - e.printStackTrace(); | ||
| 40 | - return null; | ||
| 41 | - } | ||
| 42 | - } | ||
| 43 | - | ||
| 44 | - public static Predicate ge(CriteriaBuilder cb,Path<Number> expression, Object object){ | ||
| 45 | - try { | ||
| 46 | - return cb.ge(expression, nf.parse(object.toString())); | ||
| 47 | - } catch (ParseException e) { | ||
| 48 | - e.printStackTrace(); | ||
| 49 | - return null; | ||
| 50 | - } | ||
| 51 | - } | ||
| 52 | - | ||
| 53 | - public static Predicate lt(CriteriaBuilder cb,Path<Number> expression, Object object){ | ||
| 54 | - try { | ||
| 55 | - return cb.lt(expression, nf.parse(object.toString())); | ||
| 56 | - } catch (ParseException e) { | ||
| 57 | - e.printStackTrace(); | ||
| 58 | - return null; | ||
| 59 | - } | ||
| 60 | - } | ||
| 61 | - | ||
| 62 | - public static Predicate le(CriteriaBuilder cb,Path<Number> expression, Object object){ | ||
| 63 | - try { | ||
| 64 | - return cb.le(expression, nf.parse(object.toString())); | ||
| 65 | - } catch (ParseException e) { | ||
| 66 | - e.printStackTrace(); | ||
| 67 | - return null; | ||
| 68 | - } | ||
| 69 | - } | ||
| 70 | - | ||
| 71 | - public static Predicate prefixLike(CriteriaBuilder cb,Path<String> expression, Object object){ | ||
| 72 | - return cb.like(expression, object.toString() + "%"); | ||
| 73 | - } | ||
| 74 | - | ||
| 75 | - public static Predicate prefixNotLike(CriteriaBuilder cb,Path<String> expression, Object object){ | ||
| 76 | - return cb.notLike(expression, object.toString() + "%"); | ||
| 77 | - } | ||
| 78 | - | ||
| 79 | - public static Predicate suffixLike(CriteriaBuilder cb,Path<String> expression, Object object){ | ||
| 80 | - return cb.like(expression, "%" + object.toString()); | ||
| 81 | - } | ||
| 82 | - | ||
| 83 | - public static Predicate suffixNotLike(CriteriaBuilder cb,Path<String> expression, Object object){ | ||
| 84 | - return cb.notLike(expression, "%" + object.toString()); | ||
| 85 | - } | ||
| 86 | - | ||
| 87 | - public static Predicate like(CriteriaBuilder cb,Path<String> expression, Object object){ | ||
| 88 | - return cb.like(expression, "%" + object.toString() + "%"); | ||
| 89 | - } | ||
| 90 | - | ||
| 91 | - public static Predicate notLike(CriteriaBuilder cb,Path<String> expression, Object object){ | ||
| 92 | - return cb.notLike(expression, "%" + object.toString() + "%"); | ||
| 93 | - } | ||
| 94 | - | ||
| 95 | - public static Predicate isNull(CriteriaBuilder cb,Path<String> expression, Object object){ | ||
| 96 | - return cb.isNull(expression); | ||
| 97 | - } | ||
| 98 | - | ||
| 99 | - public static Predicate isNotNull(CriteriaBuilder cb,Path<String> expression, Object object){ | ||
| 100 | - return cb.isNotNull(expression); | ||
| 101 | - } | ||
| 102 | -} | 1 | +package com.bsth.entity.search; |
| 2 | + | ||
| 3 | +import java.text.NumberFormat; | ||
| 4 | +import java.text.ParseException; | ||
| 5 | +import javax.persistence.criteria.CriteriaBuilder; | ||
| 6 | +import javax.persistence.criteria.Path; | ||
| 7 | +import javax.persistence.criteria.Predicate; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * | ||
| 11 | + * @ClassName: PredicatesBuilder | ||
| 12 | + * @author PanZhao | ||
| 13 | + * @date 2016年3月16日 下午4:05:07 | ||
| 14 | + * | ||
| 15 | + */ | ||
| 16 | +public class PredicatesBuilder { | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * Number转换器 | ||
| 20 | + */ | ||
| 21 | + private static NumberFormat nf; | ||
| 22 | + | ||
| 23 | + static{ | ||
| 24 | + nf = NumberFormat.getInstance(); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public static Predicate eq(CriteriaBuilder cb,Path<?> expression, Object object){ | ||
| 28 | + return cb.equal(expression, object); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public static Predicate ne(CriteriaBuilder cb,Path<?> expression, Object object){ | ||
| 32 | + return cb.notEqual(expression, object); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public static Predicate gt(CriteriaBuilder cb,Path<Number> expression, Object object){ | ||
| 36 | + try { | ||
| 37 | + return cb.gt(expression, nf.parse(object.toString())); | ||
| 38 | + } catch (ParseException e) { | ||
| 39 | + e.printStackTrace(); | ||
| 40 | + return null; | ||
| 41 | + } | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public static Predicate ge(CriteriaBuilder cb,Path<Number> expression, Object object){ | ||
| 45 | + try { | ||
| 46 | + return cb.ge(expression, nf.parse(object.toString())); | ||
| 47 | + } catch (ParseException e) { | ||
| 48 | + e.printStackTrace(); | ||
| 49 | + return null; | ||
| 50 | + } | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public static Predicate lt(CriteriaBuilder cb,Path<Number> expression, Object object){ | ||
| 54 | + try { | ||
| 55 | + return cb.lt(expression, nf.parse(object.toString())); | ||
| 56 | + } catch (ParseException e) { | ||
| 57 | + e.printStackTrace(); | ||
| 58 | + return null; | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + public static Predicate le(CriteriaBuilder cb,Path<Number> expression, Object object){ | ||
| 63 | + try { | ||
| 64 | + return cb.le(expression, nf.parse(object.toString())); | ||
| 65 | + } catch (ParseException e) { | ||
| 66 | + e.printStackTrace(); | ||
| 67 | + return null; | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public static Predicate prefixLike(CriteriaBuilder cb,Path<String> expression, Object object){ | ||
| 72 | + return cb.like(expression, object.toString() + "%"); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public static Predicate prefixNotLike(CriteriaBuilder cb,Path<String> expression, Object object){ | ||
| 76 | + return cb.notLike(expression, object.toString() + "%"); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public static Predicate suffixLike(CriteriaBuilder cb,Path<String> expression, Object object){ | ||
| 80 | + return cb.like(expression, "%" + object.toString()); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + public static Predicate suffixNotLike(CriteriaBuilder cb,Path<String> expression, Object object){ | ||
| 84 | + return cb.notLike(expression, "%" + object.toString()); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + public static Predicate like(CriteriaBuilder cb,Path<String> expression, Object object){ | ||
| 88 | + return cb.like(expression, "%" + object.toString() + "%"); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + public static Predicate notLike(CriteriaBuilder cb,Path<String> expression, Object object){ | ||
| 92 | + return cb.notLike(expression, "%" + object.toString() + "%"); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + public static Predicate isNull(CriteriaBuilder cb,Path<String> expression, Object object){ | ||
| 96 | + return cb.isNull(expression); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + public static Predicate isNotNull(CriteriaBuilder cb,Path<String> expression, Object object){ | ||
| 100 | + return cb.isNotNull(expression); | ||
| 101 | + } | ||
| 102 | +} |
src/main/java/com/bsth/entity/search/SearchOperator.java
| 1 | -package com.bsth.entity.search; | ||
| 2 | - | ||
| 3 | -/** | ||
| 4 | - * | ||
| 5 | - * @ClassName: SearchOperator | ||
| 6 | - * @Description: 查询操作符 | ||
| 7 | - * @author PanZhao | ||
| 8 | - * @date 2016年3月16日 下午4:08:22 | ||
| 9 | - * | ||
| 10 | - */ | ||
| 11 | -public enum SearchOperator { | ||
| 12 | - | ||
| 13 | - eq, // 等于 | ||
| 14 | - ne, // 不等于 | ||
| 15 | - gt, // 大于 | ||
| 16 | - ge, // 大于等于 | ||
| 17 | - lt, // 小于 | ||
| 18 | - le, // 小于等于 | ||
| 19 | - prefixLike, // 前缀模糊匹配 | ||
| 20 | - prefixNotLike, // 前缀模糊不匹配 | ||
| 21 | - suffixLike, // 后缀模糊匹配 | ||
| 22 | - suffixNotLike, // 后缀模糊不匹配 | ||
| 23 | - like, // 模糊匹配 | ||
| 24 | - notLike, // 不匹配 | ||
| 25 | - isNull, // 空 | ||
| 26 | - isNotNull, // 非空 | ||
| 27 | -} | 1 | +package com.bsth.entity.search; |
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * | ||
| 5 | + * @ClassName: SearchOperator | ||
| 6 | + * @Description: 查询操作符 | ||
| 7 | + * @author PanZhao | ||
| 8 | + * @date 2016年3月16日 下午4:08:22 | ||
| 9 | + * | ||
| 10 | + */ | ||
| 11 | +public enum SearchOperator { | ||
| 12 | + | ||
| 13 | + eq, // 等于 | ||
| 14 | + ne, // 不等于 | ||
| 15 | + gt, // 大于 | ||
| 16 | + ge, // 大于等于 | ||
| 17 | + lt, // 小于 | ||
| 18 | + le, // 小于等于 | ||
| 19 | + prefixLike, // 前缀模糊匹配 | ||
| 20 | + prefixNotLike, // 前缀模糊不匹配 | ||
| 21 | + suffixLike, // 后缀模糊匹配 | ||
| 22 | + suffixNotLike, // 后缀模糊不匹配 | ||
| 23 | + like, // 模糊匹配 | ||
| 24 | + notLike, // 不匹配 | ||
| 25 | + isNull, // 空 | ||
| 26 | + isNotNull, // 非空 | ||
| 27 | +} |
src/main/java/com/bsth/entity/search/exception/UnrecognizableSearchSymbolException.java
| 1 | -package com.bsth.entity.search.exception; | ||
| 2 | - | ||
| 3 | -/** | ||
| 4 | - * | ||
| 5 | - * @ClassName: UnrecognizableSearchSymbolException | ||
| 6 | - * @Description: TODO(查询操作符无法识别时抛出此异常) | ||
| 7 | - * @author PanZhao | ||
| 8 | - * @date 2016年3月17日 下午3:11:02 | ||
| 9 | - * | ||
| 10 | - */ | ||
| 11 | -public class UnrecognizableSearchSymbolException extends Exception{ | ||
| 12 | - | ||
| 13 | - private static final long serialVersionUID = 1L; | ||
| 14 | - | ||
| 15 | - public UnrecognizableSearchSymbolException(String symbol) { | ||
| 16 | - super("无法识别的查询操作符:" + symbol + " 请参考 com.bsth.entity.search.SearchOperator.java"); | ||
| 17 | - } | ||
| 18 | -} | 1 | +package com.bsth.entity.search.exception; |
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * | ||
| 5 | + * @ClassName: UnrecognizableSearchSymbolException | ||
| 6 | + * @Description: TODO(查询操作符无法识别时抛出此异常) | ||
| 7 | + * @author PanZhao | ||
| 8 | + * @date 2016年3月17日 下午3:11:02 | ||
| 9 | + * | ||
| 10 | + */ | ||
| 11 | +public class UnrecognizableSearchSymbolException extends Exception{ | ||
| 12 | + | ||
| 13 | + private static final long serialVersionUID = 1L; | ||
| 14 | + | ||
| 15 | + public UnrecognizableSearchSymbolException(String symbol) { | ||
| 16 | + super("无法识别的查询操作符:" + symbol + " 请参考 com.bsth.entity.search.SearchOperator.java"); | ||
| 17 | + } | ||
| 18 | +} |
src/main/java/com/bsth/entity/sys/SecurityUser.java
| 1 | -package com.bsth.entity.sys; | ||
| 2 | - | ||
| 3 | -import java.util.ArrayList; | ||
| 4 | -import java.util.Collection; | ||
| 5 | -import java.util.Set; | ||
| 6 | - | ||
| 7 | -import org.springframework.security.core.GrantedAuthority; | ||
| 8 | -import org.springframework.security.core.authority.SimpleGrantedAuthority; | ||
| 9 | -import org.springframework.security.core.userdetails.UserDetails; | ||
| 10 | - | ||
| 11 | -public class SecurityUser extends SysUser implements UserDetails { | ||
| 12 | - | ||
| 13 | - private static final long serialVersionUID = 1L; | ||
| 14 | - | ||
| 15 | - public SecurityUser(SysUser user) { | ||
| 16 | - if (null != user) { | ||
| 17 | - this.setId(user.getId()); | ||
| 18 | - this.setUserName(user.getUserName()); | ||
| 19 | - this.setName(user.getName()); | ||
| 20 | - this.setPassword(user.getPassword()); | ||
| 21 | - this.setAgencies(user.getAgencies()); | ||
| 22 | - this.setRoles(user.getRoles()); | ||
| 23 | - this.setEnabled(user.isEnabled()); | ||
| 24 | - } | ||
| 25 | - } | ||
| 26 | - | ||
| 27 | - @Override | ||
| 28 | - public Collection<? extends GrantedAuthority> getAuthorities() { | ||
| 29 | - Collection<GrantedAuthority> authorities = new ArrayList<>(); | ||
| 30 | - Set<Role> userRoles = this.getRoles(); | ||
| 31 | - | ||
| 32 | - if (userRoles != null) { | ||
| 33 | - for (Role role : userRoles) { | ||
| 34 | - SimpleGrantedAuthority authority = new SimpleGrantedAuthority( | ||
| 35 | - role.getCodeName()); | ||
| 36 | - authorities.add(authority); | ||
| 37 | - } | ||
| 38 | - } | ||
| 39 | - return authorities; | ||
| 40 | - } | ||
| 41 | - | ||
| 42 | - @Override | ||
| 43 | - public String getPassword() { | ||
| 44 | - return super.getPassword(); | ||
| 45 | - } | ||
| 46 | - | ||
| 47 | - @Override | ||
| 48 | - public boolean isAccountNonExpired() { | ||
| 49 | - return true; | ||
| 50 | - } | ||
| 51 | - | ||
| 52 | - @Override | ||
| 53 | - public boolean isAccountNonLocked() { | ||
| 54 | - return true; | ||
| 55 | - } | ||
| 56 | - | ||
| 57 | - @Override | ||
| 58 | - public boolean isCredentialsNonExpired() { | ||
| 59 | - return true; | ||
| 60 | - } | ||
| 61 | - | ||
| 62 | - @Override | ||
| 63 | - public String getUsername() { | ||
| 64 | - return super.getUserName(); | ||
| 65 | - } | ||
| 66 | - | ||
| 67 | - @Override | ||
| 68 | - public boolean equals(Object obj) { | ||
| 69 | - return this.getUserName().equals(((SysUser)obj).getUserName()); | ||
| 70 | - } | ||
| 71 | - | ||
| 72 | - @Override | ||
| 73 | - public int hashCode() { | ||
| 74 | - return this.getId() + this.getUserName().hashCode(); | ||
| 75 | - } | ||
| 76 | -} | 1 | +package com.bsth.entity.sys; |
| 2 | + | ||
| 3 | +import java.util.ArrayList; | ||
| 4 | +import java.util.Collection; | ||
| 5 | +import java.util.Set; | ||
| 6 | + | ||
| 7 | +import org.springframework.security.core.GrantedAuthority; | ||
| 8 | +import org.springframework.security.core.authority.SimpleGrantedAuthority; | ||
| 9 | +import org.springframework.security.core.userdetails.UserDetails; | ||
| 10 | + | ||
| 11 | +public class SecurityUser extends SysUser implements UserDetails { | ||
| 12 | + | ||
| 13 | + private static final long serialVersionUID = 1L; | ||
| 14 | + | ||
| 15 | + public SecurityUser(SysUser user) { | ||
| 16 | + if (null != user) { | ||
| 17 | + this.setId(user.getId()); | ||
| 18 | + this.setUserName(user.getUserName()); | ||
| 19 | + this.setName(user.getName()); | ||
| 20 | + this.setPassword(user.getPassword()); | ||
| 21 | + this.setAgencies(user.getAgencies()); | ||
| 22 | + this.setRoles(user.getRoles()); | ||
| 23 | + this.setEnabled(user.isEnabled()); | ||
| 24 | + } | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + @Override | ||
| 28 | + public Collection<? extends GrantedAuthority> getAuthorities() { | ||
| 29 | + Collection<GrantedAuthority> authorities = new ArrayList<>(); | ||
| 30 | + Set<Role> userRoles = this.getRoles(); | ||
| 31 | + | ||
| 32 | + if (userRoles != null) { | ||
| 33 | + for (Role role : userRoles) { | ||
| 34 | + SimpleGrantedAuthority authority = new SimpleGrantedAuthority( | ||
| 35 | + role.getCodeName()); | ||
| 36 | + authorities.add(authority); | ||
| 37 | + } | ||
| 38 | + } | ||
| 39 | + return authorities; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + @Override | ||
| 43 | + public String getPassword() { | ||
| 44 | + return super.getPassword(); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Override | ||
| 48 | + public boolean isAccountNonExpired() { | ||
| 49 | + return true; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + @Override | ||
| 53 | + public boolean isAccountNonLocked() { | ||
| 54 | + return true; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + @Override | ||
| 58 | + public boolean isCredentialsNonExpired() { | ||
| 59 | + return true; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + @Override | ||
| 63 | + public String getUsername() { | ||
| 64 | + return super.getUserName(); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + @Override | ||
| 68 | + public boolean equals(Object obj) { | ||
| 69 | + return this.getUserName().equals(((SysUser)obj).getUserName()); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + @Override | ||
| 73 | + public int hashCode() { | ||
| 74 | + return this.getId() + this.getUserName().hashCode(); | ||
| 75 | + } | ||
| 76 | +} |
src/main/java/com/bsth/filter/AccessLogFilter.java
| 1 | -package com.bsth.filter; | ||
| 2 | - | ||
| 3 | -import javax.servlet.FilterChain; | ||
| 4 | -import javax.servlet.ServletException; | ||
| 5 | -import javax.servlet.http.HttpServletRequest; | ||
| 6 | -import javax.servlet.http.HttpServletResponse; | ||
| 7 | - | ||
| 8 | -import org.slf4j.Logger; | ||
| 9 | -import org.slf4j.LoggerFactory; | ||
| 10 | -import org.springframework.stereotype.Component; | ||
| 11 | - | ||
| 12 | -import com.alibaba.fastjson.JSON; | ||
| 13 | -import com.bsth.security.util.SecurityUtils; | ||
| 14 | -import com.bsth.util.IpUtils; | ||
| 15 | -import com.google.common.collect.Lists; | ||
| 16 | -import com.google.common.collect.Maps; | ||
| 17 | - | ||
| 18 | -import java.io.IOException; | ||
| 19 | -import java.util.Enumeration; | ||
| 20 | -import java.util.List; | ||
| 21 | -import java.util.Map; | ||
| 22 | - | ||
| 23 | -/** | ||
| 24 | - * | ||
| 25 | - * @ClassName: AccessLogFilter | ||
| 26 | - * @Description: TODO(记录访问日志) | ||
| 27 | - * @author PanZhao | ||
| 28 | - * @date 2016年3月17日 下午4:28:31 | ||
| 29 | - * | ||
| 30 | - */ | ||
| 31 | -@Component | ||
| 32 | -public class AccessLogFilter extends BaseFilter { | ||
| 33 | - | ||
| 34 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 35 | - | ||
| 36 | - @Override | ||
| 37 | - public void doFilter(HttpServletRequest request, | ||
| 38 | - HttpServletResponse response, FilterChain chain) | ||
| 39 | - throws IOException, ServletException { | ||
| 40 | - | ||
| 41 | - String username = SecurityUtils.getCurrentUser().getName(); //等集成shiro之后再取 | ||
| 42 | - String jsessionId = request.getRequestedSessionId(); | ||
| 43 | - String ip = IpUtils.getIpAddr(request); | ||
| 44 | - String userAgent = request.getHeader("User-Agent"); | ||
| 45 | - String url = request.getRequestURI(); | ||
| 46 | - String params = getParams(request); | ||
| 47 | - String headers = getHeaders(request); | ||
| 48 | - | ||
| 49 | - StringBuilder s = new StringBuilder(); | ||
| 50 | - s.append(getBlock(username)); | ||
| 51 | - s.append(getBlock(jsessionId)); | ||
| 52 | - s.append(getBlock(ip)); | ||
| 53 | - s.append(getBlock(userAgent)); | ||
| 54 | - s.append(getBlock(url)); | ||
| 55 | - s.append(getBlock(params)); | ||
| 56 | - s.append(getBlock(headers)); | ||
| 57 | - s.append(getBlock(request.getHeader("Referer"))); | ||
| 58 | - | ||
| 59 | - logger.info(s.toString()); | ||
| 60 | - chain.doFilter(request, response); | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | - private static String getParams(HttpServletRequest request) { | ||
| 64 | - Map<String, String[]> params = request.getParameterMap(); | ||
| 65 | - return JSON.toJSONString(params); | ||
| 66 | - } | ||
| 67 | - | ||
| 68 | - private static String getHeaders(HttpServletRequest request) { | ||
| 69 | - Map<String, List<String>> headers = Maps.newHashMap(); | ||
| 70 | - Enumeration<String> namesEnumeration = request.getHeaderNames(); | ||
| 71 | - while (namesEnumeration.hasMoreElements()) { | ||
| 72 | - String name = namesEnumeration.nextElement(); | ||
| 73 | - Enumeration<String> valueEnumeration = request.getHeaders(name); | ||
| 74 | - List<String> values = Lists.newArrayList(); | ||
| 75 | - while (valueEnumeration.hasMoreElements()) { | ||
| 76 | - values.add(valueEnumeration.nextElement()); | ||
| 77 | - } | ||
| 78 | - headers.put(name, values); | ||
| 79 | - } | ||
| 80 | - return JSON.toJSONString(headers); | ||
| 81 | - } | ||
| 82 | - | ||
| 83 | - public static String getBlock(Object msg) { | ||
| 84 | - if (msg == null) { | ||
| 85 | - msg = ""; | ||
| 86 | - } | ||
| 87 | - return "[" + msg.toString() + "]"; | ||
| 88 | - } | ||
| 89 | -} | 1 | +package com.bsth.filter; |
| 2 | + | ||
| 3 | +import javax.servlet.FilterChain; | ||
| 4 | +import javax.servlet.ServletException; | ||
| 5 | +import javax.servlet.http.HttpServletRequest; | ||
| 6 | +import javax.servlet.http.HttpServletResponse; | ||
| 7 | + | ||
| 8 | +import org.slf4j.Logger; | ||
| 9 | +import org.slf4j.LoggerFactory; | ||
| 10 | +import org.springframework.stereotype.Component; | ||
| 11 | + | ||
| 12 | +import com.alibaba.fastjson.JSON; | ||
| 13 | +import com.bsth.security.util.SecurityUtils; | ||
| 14 | +import com.bsth.util.IpUtils; | ||
| 15 | +import com.google.common.collect.Lists; | ||
| 16 | +import com.google.common.collect.Maps; | ||
| 17 | + | ||
| 18 | +import java.io.IOException; | ||
| 19 | +import java.util.Enumeration; | ||
| 20 | +import java.util.List; | ||
| 21 | +import java.util.Map; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * | ||
| 25 | + * @ClassName: AccessLogFilter | ||
| 26 | + * @Description: TODO(记录访问日志) | ||
| 27 | + * @author PanZhao | ||
| 28 | + * @date 2016年3月17日 下午4:28:31 | ||
| 29 | + * | ||
| 30 | + */ | ||
| 31 | +@Component | ||
| 32 | +public class AccessLogFilter extends BaseFilter { | ||
| 33 | + | ||
| 34 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 35 | + | ||
| 36 | + @Override | ||
| 37 | + public void doFilter(HttpServletRequest request, | ||
| 38 | + HttpServletResponse response, FilterChain chain) | ||
| 39 | + throws IOException, ServletException { | ||
| 40 | + | ||
| 41 | + String username = SecurityUtils.getCurrentUser().getName(); //等集成shiro之后再取 | ||
| 42 | + String jsessionId = request.getRequestedSessionId(); | ||
| 43 | + String ip = IpUtils.getIpAddr(request); | ||
| 44 | + String userAgent = request.getHeader("User-Agent"); | ||
| 45 | + String url = request.getRequestURI(); | ||
| 46 | + String params = getParams(request); | ||
| 47 | + String headers = getHeaders(request); | ||
| 48 | + | ||
| 49 | + StringBuilder s = new StringBuilder(); | ||
| 50 | + s.append(getBlock(username)); | ||
| 51 | + s.append(getBlock(jsessionId)); | ||
| 52 | + s.append(getBlock(ip)); | ||
| 53 | + s.append(getBlock(userAgent)); | ||
| 54 | + s.append(getBlock(url)); | ||
| 55 | + s.append(getBlock(params)); | ||
| 56 | + s.append(getBlock(headers)); | ||
| 57 | + s.append(getBlock(request.getHeader("Referer"))); | ||
| 58 | + | ||
| 59 | + logger.info(s.toString()); | ||
| 60 | + chain.doFilter(request, response); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + private static String getParams(HttpServletRequest request) { | ||
| 64 | + Map<String, String[]> params = request.getParameterMap(); | ||
| 65 | + return JSON.toJSONString(params); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + private static String getHeaders(HttpServletRequest request) { | ||
| 69 | + Map<String, List<String>> headers = Maps.newHashMap(); | ||
| 70 | + Enumeration<String> namesEnumeration = request.getHeaderNames(); | ||
| 71 | + while (namesEnumeration.hasMoreElements()) { | ||
| 72 | + String name = namesEnumeration.nextElement(); | ||
| 73 | + Enumeration<String> valueEnumeration = request.getHeaders(name); | ||
| 74 | + List<String> values = Lists.newArrayList(); | ||
| 75 | + while (valueEnumeration.hasMoreElements()) { | ||
| 76 | + values.add(valueEnumeration.nextElement()); | ||
| 77 | + } | ||
| 78 | + headers.put(name, values); | ||
| 79 | + } | ||
| 80 | + return JSON.toJSONString(headers); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + public static String getBlock(Object msg) { | ||
| 84 | + if (msg == null) { | ||
| 85 | + msg = ""; | ||
| 86 | + } | ||
| 87 | + return "[" + msg.toString() + "]"; | ||
| 88 | + } | ||
| 89 | +} |
src/main/java/com/bsth/filter/BaseFilter.java
| 1 | -package com.bsth.filter; | ||
| 2 | - | ||
| 3 | -import java.io.IOException; | ||
| 4 | - | ||
| 5 | -import javax.servlet.Filter; | ||
| 6 | -import javax.servlet.FilterChain; | ||
| 7 | -import javax.servlet.FilterConfig; | ||
| 8 | -import javax.servlet.ServletException; | ||
| 9 | -import javax.servlet.ServletRequest; | ||
| 10 | -import javax.servlet.ServletResponse; | ||
| 11 | -import javax.servlet.http.HttpServletRequest; | ||
| 12 | -import javax.servlet.http.HttpServletResponse; | ||
| 13 | - | ||
| 14 | -import org.springframework.util.AntPathMatcher; | ||
| 15 | -import org.springframework.util.PathMatcher; | ||
| 16 | - | ||
| 17 | -import com.bsth.common.Constants; | ||
| 18 | - | ||
| 19 | -public abstract class BaseFilter implements Filter { | ||
| 20 | - | ||
| 21 | - private final PathMatcher pathMatcher = new AntPathMatcher(); | ||
| 22 | - | ||
| 23 | - /** | ||
| 24 | - * 白名单 | ||
| 25 | - */ | ||
| 26 | - private String[] whiteListURLs = { Constants.LOGIN_PAGE, | ||
| 27 | - Constants.ASSETS_URL, Constants.FAVICON_URL, Constants.METRONIC_URL, Constants.LOGIN, Constants.LOGIN_FAILURE }; | ||
| 28 | - | ||
| 29 | - @Override | ||
| 30 | - public void destroy() { | ||
| 31 | - | ||
| 32 | - } | ||
| 33 | - | ||
| 34 | - @Override | ||
| 35 | - public void doFilter(ServletRequest request, ServletResponse response, | ||
| 36 | - FilterChain chain) throws IOException, ServletException { | ||
| 37 | - | ||
| 38 | - HttpServletRequest httpRequest = (HttpServletRequest) request; | ||
| 39 | - HttpServletResponse httpResponse = (HttpServletResponse) response; | ||
| 40 | - | ||
| 41 | - String currentURL = httpRequest.getServletPath(); | ||
| 42 | - | ||
| 43 | - if (isWhiteURL(currentURL)) { | ||
| 44 | - chain.doFilter(request, response); | ||
| 45 | - return; | ||
| 46 | - } | ||
| 47 | - | ||
| 48 | - doFilter(httpRequest, httpResponse, chain); | ||
| 49 | - return; | ||
| 50 | - } | ||
| 51 | - | ||
| 52 | - public void doFilter(HttpServletRequest request, | ||
| 53 | - HttpServletResponse response, FilterChain chain) | ||
| 54 | - throws IOException, ServletException { | ||
| 55 | - chain.doFilter(request, response); | ||
| 56 | - } | ||
| 57 | - | ||
| 58 | - @Override | ||
| 59 | - public void init(FilterConfig arg0) throws ServletException { | ||
| 60 | - | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | - private boolean isWhiteURL(String currentURL) { | ||
| 64 | - for (String whiteURL : whiteListURLs) { | ||
| 65 | - if (pathMatcher.match(whiteURL, currentURL)) { | ||
| 66 | - return true; | ||
| 67 | - } | ||
| 68 | - } | ||
| 69 | - return false; | ||
| 70 | - } | ||
| 71 | -} | 1 | +package com.bsth.filter; |
| 2 | + | ||
| 3 | +import java.io.IOException; | ||
| 4 | + | ||
| 5 | +import javax.servlet.Filter; | ||
| 6 | +import javax.servlet.FilterChain; | ||
| 7 | +import javax.servlet.FilterConfig; | ||
| 8 | +import javax.servlet.ServletException; | ||
| 9 | +import javax.servlet.ServletRequest; | ||
| 10 | +import javax.servlet.ServletResponse; | ||
| 11 | +import javax.servlet.http.HttpServletRequest; | ||
| 12 | +import javax.servlet.http.HttpServletResponse; | ||
| 13 | + | ||
| 14 | +import org.springframework.util.AntPathMatcher; | ||
| 15 | +import org.springframework.util.PathMatcher; | ||
| 16 | + | ||
| 17 | +import com.bsth.common.Constants; | ||
| 18 | + | ||
| 19 | +public abstract class BaseFilter implements Filter { | ||
| 20 | + | ||
| 21 | + private final PathMatcher pathMatcher = new AntPathMatcher(); | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 白名单 | ||
| 25 | + */ | ||
| 26 | + private String[] whiteListURLs = { Constants.LOGIN_PAGE, | ||
| 27 | + Constants.ASSETS_URL, Constants.FAVICON_URL, Constants.METRONIC_URL, Constants.LOGIN, Constants.LOGIN_FAILURE }; | ||
| 28 | + | ||
| 29 | + @Override | ||
| 30 | + public void destroy() { | ||
| 31 | + | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + @Override | ||
| 35 | + public void doFilter(ServletRequest request, ServletResponse response, | ||
| 36 | + FilterChain chain) throws IOException, ServletException { | ||
| 37 | + | ||
| 38 | + HttpServletRequest httpRequest = (HttpServletRequest) request; | ||
| 39 | + HttpServletResponse httpResponse = (HttpServletResponse) response; | ||
| 40 | + | ||
| 41 | + String currentURL = httpRequest.getServletPath(); | ||
| 42 | + | ||
| 43 | + if (isWhiteURL(currentURL)) { | ||
| 44 | + chain.doFilter(request, response); | ||
| 45 | + return; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + doFilter(httpRequest, httpResponse, chain); | ||
| 49 | + return; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public void doFilter(HttpServletRequest request, | ||
| 53 | + HttpServletResponse response, FilterChain chain) | ||
| 54 | + throws IOException, ServletException { | ||
| 55 | + chain.doFilter(request, response); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + @Override | ||
| 59 | + public void init(FilterConfig arg0) throws ServletException { | ||
| 60 | + | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + private boolean isWhiteURL(String currentURL) { | ||
| 64 | + for (String whiteURL : whiteListURLs) { | ||
| 65 | + if (pathMatcher.match(whiteURL, currentURL)) { | ||
| 66 | + return true; | ||
| 67 | + } | ||
| 68 | + } | ||
| 69 | + return false; | ||
| 70 | + } | ||
| 71 | +} |
src/main/java/com/bsth/filter/CORSFilter.java
| 1 | -package com.bsth.filter; | ||
| 2 | - | ||
| 3 | -import java.io.IOException; | ||
| 4 | - | ||
| 5 | -import javax.servlet.FilterChain; | ||
| 6 | -import javax.servlet.FilterConfig; | ||
| 7 | -import javax.servlet.ServletException; | ||
| 8 | -import javax.servlet.http.HttpServletRequest; | ||
| 9 | -import javax.servlet.http.HttpServletResponse; | ||
| 10 | - | ||
| 11 | -import org.springframework.stereotype.Component; | ||
| 12 | - | ||
| 13 | -@Component | ||
| 14 | -public class CORSFilter extends BaseFilter { | ||
| 15 | - | ||
| 16 | - public void init(FilterConfig filterConfig) { | ||
| 17 | - } | ||
| 18 | - | ||
| 19 | - @Override | ||
| 20 | - public void doFilter(HttpServletRequest request, | ||
| 21 | - HttpServletResponse response, FilterChain chain) | ||
| 22 | - throws IOException, ServletException { | ||
| 23 | - | ||
| 24 | - response.setHeader("Access-Control-Allow-Origin", "*"); | ||
| 25 | - response.setHeader("Access-Control-Allow-Methods", | ||
| 26 | - "POST, GET, OPTIONS, DELETE"); | ||
| 27 | - response.setHeader("Access-Control-Max-Age", "3600"); | ||
| 28 | - response.setHeader("Access-Control-Allow-Headers", "x-requested-with"); | ||
| 29 | - chain.doFilter(request, response); | ||
| 30 | - } | ||
| 31 | - | ||
| 32 | - public void destroy() { | ||
| 33 | - } | ||
| 34 | - | ||
| 35 | -} | 1 | +package com.bsth.filter; |
| 2 | + | ||
| 3 | +import java.io.IOException; | ||
| 4 | + | ||
| 5 | +import javax.servlet.FilterChain; | ||
| 6 | +import javax.servlet.FilterConfig; | ||
| 7 | +import javax.servlet.ServletException; | ||
| 8 | +import javax.servlet.http.HttpServletRequest; | ||
| 9 | +import javax.servlet.http.HttpServletResponse; | ||
| 10 | + | ||
| 11 | +import org.springframework.stereotype.Component; | ||
| 12 | + | ||
| 13 | +@Component | ||
| 14 | +public class CORSFilter extends BaseFilter { | ||
| 15 | + | ||
| 16 | + public void init(FilterConfig filterConfig) { | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + @Override | ||
| 20 | + public void doFilter(HttpServletRequest request, | ||
| 21 | + HttpServletResponse response, FilterChain chain) | ||
| 22 | + throws IOException, ServletException { | ||
| 23 | + | ||
| 24 | + response.setHeader("Access-Control-Allow-Origin", "*"); | ||
| 25 | + response.setHeader("Access-Control-Allow-Methods", | ||
| 26 | + "POST, GET, OPTIONS, DELETE"); | ||
| 27 | + response.setHeader("Access-Control-Max-Age", "3600"); | ||
| 28 | + response.setHeader("Access-Control-Allow-Headers", "x-requested-with"); | ||
| 29 | + chain.doFilter(request, response); | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + public void destroy() { | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | +} |
src/main/java/com/bsth/repository/BaseRepository.java
| 1 | -package com.bsth.repository; | ||
| 2 | - | ||
| 3 | -import java.io.Serializable; | ||
| 4 | - | ||
| 5 | -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
| 6 | -import org.springframework.data.repository.NoRepositoryBean; | ||
| 7 | -import org.springframework.data.repository.PagingAndSortingRepository; | ||
| 8 | - | ||
| 9 | -@NoRepositoryBean | ||
| 10 | -public interface BaseRepository<T, ID extends Serializable> extends PagingAndSortingRepository<T, ID>,JpaSpecificationExecutor<T>{ | ||
| 11 | - | ||
| 12 | -} | 1 | +package com.bsth.repository; |
| 2 | + | ||
| 3 | +import java.io.Serializable; | ||
| 4 | + | ||
| 5 | +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
| 6 | +import org.springframework.data.repository.NoRepositoryBean; | ||
| 7 | +import org.springframework.data.repository.PagingAndSortingRepository; | ||
| 8 | + | ||
| 9 | +@NoRepositoryBean | ||
| 10 | +public interface BaseRepository<T, ID extends Serializable> extends PagingAndSortingRepository<T, ID>,JpaSpecificationExecutor<T>{ | ||
| 11 | + | ||
| 12 | +} |
src/main/java/com/bsth/repository/DictionaryRepository.java
| 1 | -package com.bsth.repository; | ||
| 2 | - | ||
| 3 | -import org.springframework.stereotype.Repository; | ||
| 4 | - | ||
| 5 | -import com.bsth.entity.sys.Dictionary; | ||
| 6 | - | ||
| 7 | -@Repository | ||
| 8 | -public interface DictionaryRepository extends BaseRepository<Dictionary, Integer>{ | ||
| 9 | - | ||
| 10 | -} | 1 | +package com.bsth.repository; |
| 2 | + | ||
| 3 | +import org.springframework.stereotype.Repository; | ||
| 4 | + | ||
| 5 | +import com.bsth.entity.sys.Dictionary; | ||
| 6 | + | ||
| 7 | +@Repository | ||
| 8 | +public interface DictionaryRepository extends BaseRepository<Dictionary, Integer>{ | ||
| 9 | + | ||
| 10 | +} |
src/main/java/com/bsth/repository/ModuleRepository.java
| 1 | -package com.bsth.repository; | ||
| 2 | - | ||
| 3 | -import java.util.List; | ||
| 4 | -import java.util.Set; | ||
| 5 | - | ||
| 6 | -import org.springframework.data.jpa.repository.Query; | ||
| 7 | -import org.springframework.stereotype.Repository; | ||
| 8 | - | ||
| 9 | -import com.bsth.entity.sys.Module; | ||
| 10 | - | ||
| 11 | -@Repository | ||
| 12 | -public interface ModuleRepository extends BaseRepository<Module, Integer>{ | ||
| 13 | - | ||
| 14 | - @Query("select m from Module m where m.groupType in ?1") | ||
| 15 | - List<Module> findByGroupType(String[] groupType); | ||
| 16 | - | ||
| 17 | - List<Module> findByPId(Integer pId); | ||
| 18 | - | ||
| 19 | - @Query("select m from Module m where m.id in ?1") | ||
| 20 | - Set<Module> findByIds(List<Integer> ids); | ||
| 21 | -} | 1 | +package com.bsth.repository; |
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | +import java.util.Set; | ||
| 5 | + | ||
| 6 | +import org.springframework.data.jpa.repository.Query; | ||
| 7 | +import org.springframework.stereotype.Repository; | ||
| 8 | + | ||
| 9 | +import com.bsth.entity.sys.Module; | ||
| 10 | + | ||
| 11 | +@Repository | ||
| 12 | +public interface ModuleRepository extends BaseRepository<Module, Integer>{ | ||
| 13 | + | ||
| 14 | + @Query("select m from Module m where m.groupType in ?1") | ||
| 15 | + List<Module> findByGroupType(String[] groupType); | ||
| 16 | + | ||
| 17 | + List<Module> findByPId(Integer pId); | ||
| 18 | + | ||
| 19 | + @Query("select m from Module m where m.id in ?1") | ||
| 20 | + Set<Module> findByIds(List<Integer> ids); | ||
| 21 | +} |
src/main/java/com/bsth/repository/ResourceRepository.java
| 1 | -package com.bsth.repository; | ||
| 2 | - | ||
| 3 | -import java.util.List; | ||
| 4 | - | ||
| 5 | -import org.springframework.stereotype.Repository; | ||
| 6 | - | ||
| 7 | -import com.bsth.entity.sys.Resource; | ||
| 8 | - | ||
| 9 | -@Repository | ||
| 10 | -public interface ResourceRepository extends BaseRepository<Resource, Integer> { | ||
| 11 | - | ||
| 12 | - List<Resource> findByRolesId(Integer roleId); | ||
| 13 | -} | 1 | +package com.bsth.repository; |
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | + | ||
| 5 | +import org.springframework.stereotype.Repository; | ||
| 6 | + | ||
| 7 | +import com.bsth.entity.sys.Resource; | ||
| 8 | + | ||
| 9 | +@Repository | ||
| 10 | +public interface ResourceRepository extends BaseRepository<Resource, Integer> { | ||
| 11 | + | ||
| 12 | + List<Resource> findByRolesId(Integer roleId); | ||
| 13 | +} |
src/main/java/com/bsth/repository/RoleRepository.java
| 1 | -package com.bsth.repository; | ||
| 2 | - | ||
| 3 | - | ||
| 4 | -import javax.transaction.Transactional; | ||
| 5 | - | ||
| 6 | -import org.springframework.data.jpa.repository.Modifying; | ||
| 7 | -import org.springframework.data.jpa.repository.Query; | ||
| 8 | -import org.springframework.stereotype.Repository; | ||
| 9 | - | ||
| 10 | -import com.bsth.entity.sys.Role; | ||
| 11 | - | ||
| 12 | -@Repository | ||
| 13 | -public interface RoleRepository extends BaseRepository<Role, Integer>{ | ||
| 14 | - | ||
| 15 | - /** | ||
| 16 | - * @Title: update | ||
| 17 | - * @Description: TODO(简洁版更新(不需要级联的)) | ||
| 18 | - */ | ||
| 19 | - @Modifying | ||
| 20 | - @Transactional | ||
| 21 | - @Query("update Role r set r.codeName=?1, r.roleName=?2, r.enable=?3, r.descriptions=?4 where r.id=?5") | ||
| 22 | - void update(String codeName, String roleName, boolean enable, String descriptions, Integer id); | ||
| 23 | -} | 1 | +package com.bsth.repository; |
| 2 | + | ||
| 3 | + | ||
| 4 | +import javax.transaction.Transactional; | ||
| 5 | + | ||
| 6 | +import org.springframework.data.jpa.repository.Modifying; | ||
| 7 | +import org.springframework.data.jpa.repository.Query; | ||
| 8 | +import org.springframework.stereotype.Repository; | ||
| 9 | + | ||
| 10 | +import com.bsth.entity.sys.Role; | ||
| 11 | + | ||
| 12 | +@Repository | ||
| 13 | +public interface RoleRepository extends BaseRepository<Role, Integer>{ | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * @Title: update | ||
| 17 | + * @Description: TODO(简洁版更新(不需要级联的)) | ||
| 18 | + */ | ||
| 19 | + @Modifying | ||
| 20 | + @Transactional | ||
| 21 | + @Query("update Role r set r.codeName=?1, r.roleName=?2, r.enable=?3, r.descriptions=?4 where r.id=?5") | ||
| 22 | + void update(String codeName, String roleName, boolean enable, String descriptions, Integer id); | ||
| 23 | +} |
src/main/java/com/bsth/repository/SysUserRepository.java
| 1 | -package com.bsth.repository; | ||
| 2 | - | ||
| 3 | -import org.springframework.stereotype.Repository; | ||
| 4 | - | ||
| 5 | -import com.bsth.entity.sys.SysUser; | ||
| 6 | - | ||
| 7 | -@Repository | ||
| 8 | -public interface SysUserRepository extends BaseRepository<SysUser, Integer>{ | ||
| 9 | - | ||
| 10 | - SysUser findByUserName(String userName); | ||
| 11 | - | ||
| 12 | -} | 1 | +package com.bsth.repository; |
| 2 | + | ||
| 3 | +import org.springframework.stereotype.Repository; | ||
| 4 | + | ||
| 5 | +import com.bsth.entity.sys.SysUser; | ||
| 6 | + | ||
| 7 | +@Repository | ||
| 8 | +public interface SysUserRepository extends BaseRepository<SysUser, Integer>{ | ||
| 9 | + | ||
| 10 | + SysUser findByUserName(String userName); | ||
| 11 | + | ||
| 12 | +} |
src/main/java/com/bsth/repository/schedule/BusinessInfoRepository.java
| 1 | -package com.bsth.repository.schedule; | ||
| 2 | - | ||
| 3 | -import com.bsth.entity.schedule.BusinessInfo; | ||
| 4 | -import com.bsth.repository.BaseRepository; | ||
| 5 | -import org.springframework.stereotype.Repository; | ||
| 6 | - | ||
| 7 | -/** | ||
| 8 | - * Created by xu on 16/5/11. | ||
| 9 | - */ | ||
| 10 | -@Repository | ||
| 11 | -public interface BusinessInfoRepository extends BaseRepository<BusinessInfo, Long> { | ||
| 12 | -} | 1 | +package com.bsth.repository.schedule; |
| 2 | + | ||
| 3 | +import com.bsth.entity.schedule.BusinessInfo; | ||
| 4 | +import com.bsth.repository.BaseRepository; | ||
| 5 | +import org.springframework.stereotype.Repository; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * Created by xu on 16/5/11. | ||
| 9 | + */ | ||
| 10 | +@Repository | ||
| 11 | +public interface BusinessInfoRepository extends BaseRepository<BusinessInfo, Long> { | ||
| 12 | +} |
src/main/java/com/bsth/repository/schedule/CarConfigInfoRepository.java
| 1 | -package com.bsth.repository.schedule; | ||
| 2 | - | ||
| 3 | -import com.bsth.entity.schedule.CarConfigInfo; | ||
| 4 | -import com.bsth.repository.BaseRepository; | ||
| 5 | -import org.springframework.stereotype.Repository; | ||
| 6 | - | ||
| 7 | -/** | ||
| 8 | - * Created by xu on 16/5/9. | ||
| 9 | - */ | ||
| 10 | -@Repository | ||
| 11 | -public interface CarConfigInfoRepository extends BaseRepository<CarConfigInfo, Long> { | ||
| 12 | -} | 1 | +package com.bsth.repository.schedule; |
| 2 | + | ||
| 3 | +import com.bsth.entity.schedule.CarConfigInfo; | ||
| 4 | +import com.bsth.repository.BaseRepository; | ||
| 5 | +import org.springframework.stereotype.Repository; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * Created by xu on 16/5/9. | ||
| 9 | + */ | ||
| 10 | +@Repository | ||
| 11 | +public interface CarConfigInfoRepository extends BaseRepository<CarConfigInfo, Long> { | ||
| 12 | +} |
src/main/java/com/bsth/repository/schedule/EmployeeConfigInfoRepository.java
| 1 | -package com.bsth.repository.schedule; | ||
| 2 | - | ||
| 3 | -import com.bsth.entity.schedule.EmployeeConfigInfo; | ||
| 4 | -import com.bsth.repository.BaseRepository; | ||
| 5 | -import org.springframework.stereotype.Repository; | ||
| 6 | - | ||
| 7 | -/** | ||
| 8 | - * Created by xu on 16/5/10. | ||
| 9 | - */ | ||
| 10 | -@Repository | ||
| 11 | -public interface EmployeeConfigInfoRepository extends BaseRepository<EmployeeConfigInfo, Long> { | ||
| 12 | -} | 1 | +package com.bsth.repository.schedule; |
| 2 | + | ||
| 3 | +import com.bsth.entity.schedule.EmployeeConfigInfo; | ||
| 4 | +import com.bsth.repository.BaseRepository; | ||
| 5 | +import org.springframework.stereotype.Repository; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * Created by xu on 16/5/10. | ||
| 9 | + */ | ||
| 10 | +@Repository | ||
| 11 | +public interface EmployeeConfigInfoRepository extends BaseRepository<EmployeeConfigInfo, Long> { | ||
| 12 | +} |
src/main/java/com/bsth/repository/schedule/GuideboardInfoRepository.java
| 1 | -package com.bsth.repository.schedule; | ||
| 2 | - | ||
| 3 | -import com.bsth.entity.schedule.GuideboardInfo; | ||
| 4 | -import com.bsth.repository.BaseRepository; | ||
| 5 | -import org.springframework.stereotype.Repository; | ||
| 6 | - | ||
| 7 | -/** | ||
| 8 | - * Created by xu on 16/5/11. | ||
| 9 | - */ | ||
| 10 | -@Repository | ||
| 11 | -public interface GuideboardInfoRepository extends BaseRepository<GuideboardInfo, Long> { | ||
| 12 | -} | 1 | +package com.bsth.repository.schedule; |
| 2 | + | ||
| 3 | +import com.bsth.entity.schedule.GuideboardInfo; | ||
| 4 | +import com.bsth.repository.BaseRepository; | ||
| 5 | +import org.springframework.stereotype.Repository; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * Created by xu on 16/5/11. | ||
| 9 | + */ | ||
| 10 | +@Repository | ||
| 11 | +public interface GuideboardInfoRepository extends BaseRepository<GuideboardInfo, Long> { | ||
| 12 | +} |
src/main/java/com/bsth/repository/schedule/TTInfoRepository.java
| 1 | -package com.bsth.repository.schedule; | ||
| 2 | - | ||
| 3 | -import com.bsth.entity.schedule.TTInfo; | ||
| 4 | -import com.bsth.repository.BaseRepository; | ||
| 5 | -import org.springframework.stereotype.Repository; | ||
| 6 | - | ||
| 7 | -/** | ||
| 8 | - * Created by xu on 16/5/12. | ||
| 9 | - */ | ||
| 10 | -@Repository | ||
| 11 | -public interface TTInfoRepository extends BaseRepository<TTInfo, Long> { | ||
| 12 | -} | 1 | +package com.bsth.repository.schedule; |
| 2 | + | ||
| 3 | +import com.bsth.entity.schedule.TTInfo; | ||
| 4 | +import com.bsth.repository.BaseRepository; | ||
| 5 | +import org.springframework.stereotype.Repository; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * Created by xu on 16/5/12. | ||
| 9 | + */ | ||
| 10 | +@Repository | ||
| 11 | +public interface TTInfoRepository extends BaseRepository<TTInfo, Long> { | ||
| 12 | +} |
src/main/java/com/bsth/security/CustomAccessDecisionManager.java
| 1 | -package com.bsth.security; | ||
| 2 | - | ||
| 3 | -import java.util.Collection; | ||
| 4 | -import java.util.Iterator; | ||
| 5 | - | ||
| 6 | -import org.springframework.security.access.AccessDecisionManager; | ||
| 7 | -import org.springframework.security.access.AccessDeniedException; | ||
| 8 | -import org.springframework.security.access.ConfigAttribute; | ||
| 9 | -import org.springframework.security.access.SecurityConfig; | ||
| 10 | -import org.springframework.security.authentication.InsufficientAuthenticationException; | ||
| 11 | -import org.springframework.security.core.Authentication; | ||
| 12 | -import org.springframework.security.core.GrantedAuthority; | ||
| 13 | -import org.springframework.stereotype.Component; | ||
| 14 | - | ||
| 15 | -@Component | ||
| 16 | -public class CustomAccessDecisionManager implements AccessDecisionManager{ | ||
| 17 | - | ||
| 18 | - @Override | ||
| 19 | - public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) | ||
| 20 | - throws AccessDeniedException, InsufficientAuthenticationException { | ||
| 21 | - | ||
| 22 | - Iterator<ConfigAttribute> iter = configAttributes.iterator(); | ||
| 23 | - Object obj; | ||
| 24 | - while (iter.hasNext()) | ||
| 25 | - { | ||
| 26 | - obj = iter.next(); | ||
| 27 | - if(null == obj) | ||
| 28 | - continue; | ||
| 29 | - | ||
| 30 | - String accessResourceNeedRole = ((SecurityConfig) obj) | ||
| 31 | - .getAttribute(); | ||
| 32 | - for (GrantedAuthority grantedAuthority : authentication.getAuthorities()) | ||
| 33 | - { | ||
| 34 | - String userOwnRole = grantedAuthority.getAuthority(); | ||
| 35 | - if (accessResourceNeedRole.equals(userOwnRole)) | ||
| 36 | - { | ||
| 37 | - return; | ||
| 38 | - } | ||
| 39 | - } | ||
| 40 | - } | ||
| 41 | - throw new AccessDeniedException("访问被拒绝!"); | ||
| 42 | - } | ||
| 43 | - | ||
| 44 | - @Override | ||
| 45 | - public boolean supports(ConfigAttribute arg0) { | ||
| 46 | - return false; | ||
| 47 | - } | ||
| 48 | - | ||
| 49 | - @Override | ||
| 50 | - public boolean supports(Class<?> arg0) { | ||
| 51 | - return false; | ||
| 52 | - } | ||
| 53 | - | ||
| 54 | -} | 1 | +package com.bsth.security; |
| 2 | + | ||
| 3 | +import java.util.Collection; | ||
| 4 | +import java.util.Iterator; | ||
| 5 | + | ||
| 6 | +import org.springframework.security.access.AccessDecisionManager; | ||
| 7 | +import org.springframework.security.access.AccessDeniedException; | ||
| 8 | +import org.springframework.security.access.ConfigAttribute; | ||
| 9 | +import org.springframework.security.access.SecurityConfig; | ||
| 10 | +import org.springframework.security.authentication.InsufficientAuthenticationException; | ||
| 11 | +import org.springframework.security.core.Authentication; | ||
| 12 | +import org.springframework.security.core.GrantedAuthority; | ||
| 13 | +import org.springframework.stereotype.Component; | ||
| 14 | + | ||
| 15 | +@Component | ||
| 16 | +public class CustomAccessDecisionManager implements AccessDecisionManager{ | ||
| 17 | + | ||
| 18 | + @Override | ||
| 19 | + public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) | ||
| 20 | + throws AccessDeniedException, InsufficientAuthenticationException { | ||
| 21 | + | ||
| 22 | + Iterator<ConfigAttribute> iter = configAttributes.iterator(); | ||
| 23 | + Object obj; | ||
| 24 | + while (iter.hasNext()) | ||
| 25 | + { | ||
| 26 | + obj = iter.next(); | ||
| 27 | + if(null == obj) | ||
| 28 | + continue; | ||
| 29 | + | ||
| 30 | + String accessResourceNeedRole = ((SecurityConfig) obj) | ||
| 31 | + .getAttribute(); | ||
| 32 | + for (GrantedAuthority grantedAuthority : authentication.getAuthorities()) | ||
| 33 | + { | ||
| 34 | + String userOwnRole = grantedAuthority.getAuthority(); | ||
| 35 | + if (accessResourceNeedRole.equals(userOwnRole)) | ||
| 36 | + { | ||
| 37 | + return; | ||
| 38 | + } | ||
| 39 | + } | ||
| 40 | + } | ||
| 41 | + throw new AccessDeniedException("访问被拒绝!"); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + @Override | ||
| 45 | + public boolean supports(ConfigAttribute arg0) { | ||
| 46 | + return false; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + @Override | ||
| 50 | + public boolean supports(Class<?> arg0) { | ||
| 51 | + return false; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | +} |
src/main/java/com/bsth/security/LoginSuccessHandler.java
| 1 | -package com.bsth.security; | ||
| 2 | - | ||
| 3 | -import java.io.IOException; | ||
| 4 | -import javax.servlet.ServletException; | ||
| 5 | -import javax.servlet.http.HttpServletRequest; | ||
| 6 | -import javax.servlet.http.HttpServletResponse; | ||
| 7 | - | ||
| 8 | -import org.springframework.security.core.Authentication; | ||
| 9 | -import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; | ||
| 10 | - | ||
| 11 | -import com.bsth.entity.sys.SysUser; | ||
| 12 | -import com.bsth.util.IpUtils; | ||
| 13 | - | ||
| 14 | -public class LoginSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler{ | ||
| 15 | - | ||
| 16 | - @Override | ||
| 17 | - public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, | ||
| 18 | - Authentication authentication) throws ServletException, IOException { | ||
| 19 | - | ||
| 20 | - SysUser user = (SysUser) authentication.getPrincipal(); | ||
| 21 | - | ||
| 22 | - System.out.println("管理员 " + user.getUserName() + " 登录"); | ||
| 23 | - System.out.println("IP :"+IpUtils.getIpAddr(request)); | ||
| 24 | - | ||
| 25 | - super.onAuthenticationSuccess(request, response, authentication); | ||
| 26 | - } | ||
| 27 | - | ||
| 28 | -} | 1 | +package com.bsth.security; |
| 2 | + | ||
| 3 | +import java.io.IOException; | ||
| 4 | +import javax.servlet.ServletException; | ||
| 5 | +import javax.servlet.http.HttpServletRequest; | ||
| 6 | +import javax.servlet.http.HttpServletResponse; | ||
| 7 | + | ||
| 8 | +import org.springframework.security.core.Authentication; | ||
| 9 | +import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; | ||
| 10 | + | ||
| 11 | +import com.bsth.entity.sys.SysUser; | ||
| 12 | +import com.bsth.util.IpUtils; | ||
| 13 | + | ||
| 14 | +public class LoginSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler{ | ||
| 15 | + | ||
| 16 | + @Override | ||
| 17 | + public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, | ||
| 18 | + Authentication authentication) throws ServletException, IOException { | ||
| 19 | + | ||
| 20 | + SysUser user = (SysUser) authentication.getPrincipal(); | ||
| 21 | + | ||
| 22 | + System.out.println("管理员 " + user.getUserName() + " 登录"); | ||
| 23 | + System.out.println("IP :"+IpUtils.getIpAddr(request)); | ||
| 24 | + | ||
| 25 | + super.onAuthenticationSuccess(request, response, authentication); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | +} |
src/main/java/com/bsth/security/SecurityMetadataSourceService.java
| 1 | -package com.bsth.security; | ||
| 2 | - | ||
| 3 | -import java.util.Collection; | ||
| 4 | -import java.util.Iterator; | ||
| 5 | -import java.util.List; | ||
| 6 | -import java.util.Set; | ||
| 7 | - | ||
| 8 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 9 | -import org.springframework.security.access.ConfigAttribute; | ||
| 10 | -import org.springframework.security.access.SecurityConfig; | ||
| 11 | -import org.springframework.security.web.FilterInvocation; | ||
| 12 | -import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource; | ||
| 13 | -import org.springframework.stereotype.Component; | ||
| 14 | -import org.springframework.util.AntPathMatcher; | ||
| 15 | -import org.springframework.util.PathMatcher; | ||
| 16 | - | ||
| 17 | -import com.bsth.entity.sys.Resource; | ||
| 18 | -import com.bsth.entity.sys.Role; | ||
| 19 | -import com.bsth.service.ResourceService; | ||
| 20 | -import com.bsth.service.RoleService; | ||
| 21 | -import com.google.common.collect.ArrayListMultimap; | ||
| 22 | -import com.google.common.collect.Multimap; | ||
| 23 | - | ||
| 24 | -@Component | ||
| 25 | -public class SecurityMetadataSourceService implements | ||
| 26 | - FilterInvocationSecurityMetadataSource { | ||
| 27 | - | ||
| 28 | - @Autowired | ||
| 29 | - RoleService roleService; | ||
| 30 | - | ||
| 31 | - @Autowired | ||
| 32 | - ResourceService resourceService; | ||
| 33 | - | ||
| 34 | - private PathMatcher matcher = new AntPathMatcher(); | ||
| 35 | - | ||
| 36 | - private Multimap<String, ConfigAttribute> multimap; | ||
| 37 | - | ||
| 38 | - | ||
| 39 | - public void loadResourceDefine() throws Exception { | ||
| 40 | - | ||
| 41 | - | ||
| 42 | - multimap = ArrayListMultimap.create(); | ||
| 43 | - //获取所有资源 | ||
| 44 | - List<Resource> resList = (List<Resource>) resourceService.findAll(); | ||
| 45 | - | ||
| 46 | - Set<Role> roles; | ||
| 47 | - String url; | ||
| 48 | - for(Resource res : resList){ | ||
| 49 | - url = res.getMethod() + "#" + replacePlaceholders(res.getUrl()); | ||
| 50 | - roles = res.getRoles(); | ||
| 51 | - | ||
| 52 | - if(null == roles || roles.size() == 0) | ||
| 53 | - multimap.put(url, null); | ||
| 54 | - else{ | ||
| 55 | - for(Role role : roles) | ||
| 56 | - multimap.put(url , new SecurityConfig(role.getCodeName())); | ||
| 57 | - } | ||
| 58 | - } | ||
| 59 | - System.out.println(multimap); | ||
| 60 | - } | ||
| 61 | - | ||
| 62 | - public Collection<ConfigAttribute> getAttributes(Object object) | ||
| 63 | - throws IllegalArgumentException { | ||
| 64 | - | ||
| 65 | - FilterInvocation invocation = ((FilterInvocation) object); | ||
| 66 | - String method = invocation.getRequest().getMethod(); | ||
| 67 | - String url = method.toLowerCase() + "#" + invocation.getRequestUrl(); | ||
| 68 | - | ||
| 69 | - System.out.println(url); | ||
| 70 | - | ||
| 71 | - int symIndex = url.indexOf("?"); | ||
| 72 | - if(symIndex != -1){ | ||
| 73 | - url = url.substring(0, symIndex); | ||
| 74 | - } | ||
| 75 | - | ||
| 76 | - Iterator<String> iter = multimap.keySet().iterator(); | ||
| 77 | - | ||
| 78 | - while(iter.hasNext()){ | ||
| 79 | - String temp = iter.next(); | ||
| 80 | - | ||
| 81 | - if(matcher.match(temp, url)){ | ||
| 82 | - return multimap.get(url); | ||
| 83 | - } | ||
| 84 | - } | ||
| 85 | - | ||
| 86 | - return null; | ||
| 87 | - } | ||
| 88 | - | ||
| 89 | - /** | ||
| 90 | - * | ||
| 91 | - * @Title: replacePlaceholders | ||
| 92 | - * @Description: TODO(把/{xx}占位符替换成*) | ||
| 93 | - * @param @param url | ||
| 94 | - * @throws | ||
| 95 | - */ | ||
| 96 | - public String replacePlaceholders(String url){ | ||
| 97 | - int s = url.indexOf("/{"); | ||
| 98 | - int e = url.indexOf("}"); | ||
| 99 | - if(s != -1 && e != -1){ | ||
| 100 | - String newUrl = url.substring(0, s) + "/*" + url.substring(e + 1, url.length()); | ||
| 101 | - return replacePlaceholders(newUrl); | ||
| 102 | - } | ||
| 103 | - else | ||
| 104 | - return url; | ||
| 105 | - } | ||
| 106 | - | ||
| 107 | - public boolean supports(Class<?> clazz) { | ||
| 108 | - return true; | ||
| 109 | - } | ||
| 110 | - | ||
| 111 | - public Collection<ConfigAttribute> getAllConfigAttributes() { | ||
| 112 | - return null; | ||
| 113 | - } | ||
| 114 | -} | 1 | +package com.bsth.security; |
| 2 | + | ||
| 3 | +import java.util.Collection; | ||
| 4 | +import java.util.Iterator; | ||
| 5 | +import java.util.List; | ||
| 6 | +import java.util.Set; | ||
| 7 | + | ||
| 8 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 9 | +import org.springframework.security.access.ConfigAttribute; | ||
| 10 | +import org.springframework.security.access.SecurityConfig; | ||
| 11 | +import org.springframework.security.web.FilterInvocation; | ||
| 12 | +import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource; | ||
| 13 | +import org.springframework.stereotype.Component; | ||
| 14 | +import org.springframework.util.AntPathMatcher; | ||
| 15 | +import org.springframework.util.PathMatcher; | ||
| 16 | + | ||
| 17 | +import com.bsth.entity.sys.Resource; | ||
| 18 | +import com.bsth.entity.sys.Role; | ||
| 19 | +import com.bsth.service.ResourceService; | ||
| 20 | +import com.bsth.service.RoleService; | ||
| 21 | +import com.google.common.collect.ArrayListMultimap; | ||
| 22 | +import com.google.common.collect.Multimap; | ||
| 23 | + | ||
| 24 | +@Component | ||
| 25 | +public class SecurityMetadataSourceService implements | ||
| 26 | + FilterInvocationSecurityMetadataSource { | ||
| 27 | + | ||
| 28 | + @Autowired | ||
| 29 | + RoleService roleService; | ||
| 30 | + | ||
| 31 | + @Autowired | ||
| 32 | + ResourceService resourceService; | ||
| 33 | + | ||
| 34 | + private PathMatcher matcher = new AntPathMatcher(); | ||
| 35 | + | ||
| 36 | + private Multimap<String, ConfigAttribute> multimap; | ||
| 37 | + | ||
| 38 | + | ||
| 39 | + public void loadResourceDefine() throws Exception { | ||
| 40 | + | ||
| 41 | + | ||
| 42 | + multimap = ArrayListMultimap.create(); | ||
| 43 | + //获取所有资源 | ||
| 44 | + List<Resource> resList = (List<Resource>) resourceService.findAll(); | ||
| 45 | + | ||
| 46 | + Set<Role> roles; | ||
| 47 | + String url; | ||
| 48 | + for(Resource res : resList){ | ||
| 49 | + url = res.getMethod() + "#" + replacePlaceholders(res.getUrl()); | ||
| 50 | + roles = res.getRoles(); | ||
| 51 | + | ||
| 52 | + if(null == roles || roles.size() == 0) | ||
| 53 | + multimap.put(url, null); | ||
| 54 | + else{ | ||
| 55 | + for(Role role : roles) | ||
| 56 | + multimap.put(url , new SecurityConfig(role.getCodeName())); | ||
| 57 | + } | ||
| 58 | + } | ||
| 59 | + System.out.println(multimap); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + public Collection<ConfigAttribute> getAttributes(Object object) | ||
| 63 | + throws IllegalArgumentException { | ||
| 64 | + | ||
| 65 | + FilterInvocation invocation = ((FilterInvocation) object); | ||
| 66 | + String method = invocation.getRequest().getMethod(); | ||
| 67 | + String url = method.toLowerCase() + "#" + invocation.getRequestUrl(); | ||
| 68 | + | ||
| 69 | + System.out.println(url); | ||
| 70 | + | ||
| 71 | + int symIndex = url.indexOf("?"); | ||
| 72 | + if(symIndex != -1){ | ||
| 73 | + url = url.substring(0, symIndex); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + Iterator<String> iter = multimap.keySet().iterator(); | ||
| 77 | + | ||
| 78 | + while(iter.hasNext()){ | ||
| 79 | + String temp = iter.next(); | ||
| 80 | + | ||
| 81 | + if(matcher.match(temp, url)){ | ||
| 82 | + return multimap.get(url); | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + return null; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + /** | ||
| 90 | + * | ||
| 91 | + * @Title: replacePlaceholders | ||
| 92 | + * @Description: TODO(把/{xx}占位符替换成*) | ||
| 93 | + * @param @param url | ||
| 94 | + * @throws | ||
| 95 | + */ | ||
| 96 | + public String replacePlaceholders(String url){ | ||
| 97 | + int s = url.indexOf("/{"); | ||
| 98 | + int e = url.indexOf("}"); | ||
| 99 | + if(s != -1 && e != -1){ | ||
| 100 | + String newUrl = url.substring(0, s) + "/*" + url.substring(e + 1, url.length()); | ||
| 101 | + return replacePlaceholders(newUrl); | ||
| 102 | + } | ||
| 103 | + else | ||
| 104 | + return url; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + public boolean supports(Class<?> clazz) { | ||
| 108 | + return true; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + public Collection<ConfigAttribute> getAllConfigAttributes() { | ||
| 112 | + return null; | ||
| 113 | + } | ||
| 114 | +} |
src/main/java/com/bsth/security/UserDetailServiceImpl.java
| 1 | -package com.bsth.security; | ||
| 2 | - | ||
| 3 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 4 | -import org.springframework.dao.DataAccessException; | ||
| 5 | -import org.springframework.security.core.userdetails.UserDetails; | ||
| 6 | -import org.springframework.security.core.userdetails.UserDetailsService; | ||
| 7 | -import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
| 8 | -import org.springframework.stereotype.Component; | ||
| 9 | - | ||
| 10 | -import com.bsth.entity.sys.SecurityUser; | ||
| 11 | -import com.bsth.entity.sys.SysUser; | ||
| 12 | -import com.bsth.service.SysUserService; | ||
| 13 | - | ||
| 14 | -@Component | ||
| 15 | -public class UserDetailServiceImpl implements UserDetailsService{ | ||
| 16 | - | ||
| 17 | - @Autowired | ||
| 18 | - SysUserService sysUserService; | ||
| 19 | - | ||
| 20 | - public UserDetails loadUserByUsername(String username)throws UsernameNotFoundException, DataAccessException { | ||
| 21 | - | ||
| 22 | - SysUser user = sysUserService.findByUserName(username); | ||
| 23 | - if(null == user){ | ||
| 24 | - throw new UsernameNotFoundException("UserName " + username + " not found"); | ||
| 25 | - } | ||
| 26 | - return new SecurityUser(user); | ||
| 27 | - } | ||
| 28 | -} | 1 | +package com.bsth.security; |
| 2 | + | ||
| 3 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 4 | +import org.springframework.dao.DataAccessException; | ||
| 5 | +import org.springframework.security.core.userdetails.UserDetails; | ||
| 6 | +import org.springframework.security.core.userdetails.UserDetailsService; | ||
| 7 | +import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
| 8 | +import org.springframework.stereotype.Component; | ||
| 9 | + | ||
| 10 | +import com.bsth.entity.sys.SecurityUser; | ||
| 11 | +import com.bsth.entity.sys.SysUser; | ||
| 12 | +import com.bsth.service.SysUserService; | ||
| 13 | + | ||
| 14 | +@Component | ||
| 15 | +public class UserDetailServiceImpl implements UserDetailsService{ | ||
| 16 | + | ||
| 17 | + @Autowired | ||
| 18 | + SysUserService sysUserService; | ||
| 19 | + | ||
| 20 | + public UserDetails loadUserByUsername(String username)throws UsernameNotFoundException, DataAccessException { | ||
| 21 | + | ||
| 22 | + SysUser user = sysUserService.findByUserName(username); | ||
| 23 | + if(null == user){ | ||
| 24 | + throw new UsernameNotFoundException("UserName " + username + " not found"); | ||
| 25 | + } | ||
| 26 | + return new SecurityUser(user); | ||
| 27 | + } | ||
| 28 | +} |
src/main/java/com/bsth/security/WebSecurityConfig.java
| 1 | -package com.bsth.security; | ||
| 2 | - | ||
| 3 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 4 | -import org.springframework.boot.context.embedded.ServletListenerRegistrationBean; | ||
| 5 | -import org.springframework.context.annotation.Bean; | ||
| 6 | -import org.springframework.context.annotation.Configuration; | ||
| 7 | -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; | ||
| 8 | -import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
| 9 | -import org.springframework.security.config.annotation.web.builders.WebSecurity; | ||
| 10 | -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
| 11 | -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
| 12 | -import org.springframework.security.core.session.SessionRegistry; | ||
| 13 | -import org.springframework.security.core.session.SessionRegistryImpl; | ||
| 14 | -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
| 15 | -import org.springframework.security.web.access.intercept.FilterSecurityInterceptor; | ||
| 16 | -import org.springframework.security.web.session.HttpSessionEventPublisher; | ||
| 17 | - | ||
| 18 | -import com.bsth.common.Constants; | ||
| 19 | -import com.bsth.security.filter.LoginInterceptor; | ||
| 20 | - | ||
| 21 | -@Configuration | ||
| 22 | -@EnableWebSecurity | ||
| 23 | -public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | ||
| 24 | - | ||
| 25 | - @Autowired | ||
| 26 | - UserDetailServiceImpl customUserDetailService; | ||
| 27 | - | ||
| 28 | - @Autowired | ||
| 29 | - CustomAccessDecisionManager customAccessDecisionManager; | ||
| 30 | - | ||
| 31 | - @Autowired | ||
| 32 | - SecurityMetadataSourceService securityMetadataSourceService; | ||
| 33 | - | ||
| 34 | - @Override | ||
| 35 | - public void configure(WebSecurity web) throws Exception { | ||
| 36 | - // 白名单 | ||
| 37 | - web.ignoring().antMatchers(Constants.ASSETS_URL, Constants.FAVICON_URL, | ||
| 38 | - Constants.METRONIC_URL, Constants.LOGIN_PAGE, | ||
| 39 | - Constants.LOGIN_FAILURE); | ||
| 40 | - } | ||
| 41 | - | ||
| 42 | - @Override | ||
| 43 | - protected void configure(AuthenticationManagerBuilder auth) | ||
| 44 | - throws Exception { | ||
| 45 | - auth.userDetailsService(customUserDetailService).passwordEncoder( | ||
| 46 | - new BCryptPasswordEncoder(4)); | ||
| 47 | - } | ||
| 48 | - | ||
| 49 | - @Override | ||
| 50 | - protected void configure(HttpSecurity http) throws Exception { | ||
| 51 | - http.authorizeRequests().antMatchers("/").permitAll().anyRequest() | ||
| 52 | - .authenticated().and() | ||
| 53 | - .formLogin() | ||
| 54 | - //指定登录页 | ||
| 55 | - .loginPage(Constants.LOGIN_PAGE) | ||
| 56 | - .loginProcessingUrl(Constants.LOGIN).permitAll() | ||
| 57 | - //登录失败跳转的链接 | ||
| 58 | - .failureUrl(Constants.LOGIN_PAGE + "?error=true") | ||
| 59 | - //登录成功后处理 | ||
| 60 | - .successHandler(loginSuccessHandler()) | ||
| 61 | - //禁用CXRF | ||
| 62 | - .and().csrf().disable() | ||
| 63 | - //禁用匿名用户功能 | ||
| 64 | - .anonymous().disable(); | ||
| 65 | - | ||
| 66 | - // 同时只保持一个回话 | ||
| 67 | - http.sessionManagement().maximumSessions(1) | ||
| 68 | - .expiredUrl(Constants.LOGIN_PAGE + "?error=true") | ||
| 69 | - .maxSessionsPreventsLogin(false)//让之前的登录过期 | ||
| 70 | - .sessionRegistry(sessionRegistry()); | ||
| 71 | - | ||
| 72 | - http.addFilterBefore(new LoginInterceptor(), FilterSecurityInterceptor.class); | ||
| 73 | - http.addFilter(filterSecurityInterceptor()); | ||
| 74 | - } | ||
| 75 | - | ||
| 76 | - private FilterSecurityInterceptor filterSecurityInterceptor() | ||
| 77 | - throws Exception { | ||
| 78 | - FilterSecurityInterceptor filterSecurityInterceptor = new FilterSecurityInterceptor(); | ||
| 79 | - filterSecurityInterceptor | ||
| 80 | - .setAccessDecisionManager(customAccessDecisionManager); | ||
| 81 | - filterSecurityInterceptor | ||
| 82 | - .setSecurityMetadataSource(securityMetadataSourceService); | ||
| 83 | - filterSecurityInterceptor | ||
| 84 | - .setAuthenticationManager(authenticationManager()); | ||
| 85 | - return filterSecurityInterceptor; | ||
| 86 | - } | ||
| 87 | - | ||
| 88 | - @Bean | ||
| 89 | - public LoginSuccessHandler loginSuccessHandler(){ | ||
| 90 | - return new LoginSuccessHandler(); | ||
| 91 | - } | ||
| 92 | - | ||
| 93 | - @Bean | ||
| 94 | - public SessionRegistry sessionRegistry() { | ||
| 95 | - SessionRegistry sessionRegistry = new SessionRegistryImpl(); | ||
| 96 | - return sessionRegistry; | ||
| 97 | - } | ||
| 98 | - | ||
| 99 | - @Bean | ||
| 100 | - public static ServletListenerRegistrationBean<HttpSessionEventPublisher> httpSessionEventPublisher() { | ||
| 101 | - return new ServletListenerRegistrationBean<HttpSessionEventPublisher>( | ||
| 102 | - new HttpSessionEventPublisher()); | ||
| 103 | - } | ||
| 104 | -} | 1 | +package com.bsth.security; |
| 2 | + | ||
| 3 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 4 | +import org.springframework.boot.context.embedded.ServletListenerRegistrationBean; | ||
| 5 | +import org.springframework.context.annotation.Bean; | ||
| 6 | +import org.springframework.context.annotation.Configuration; | ||
| 7 | +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; | ||
| 8 | +import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
| 9 | +import org.springframework.security.config.annotation.web.builders.WebSecurity; | ||
| 10 | +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
| 11 | +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
| 12 | +import org.springframework.security.core.session.SessionRegistry; | ||
| 13 | +import org.springframework.security.core.session.SessionRegistryImpl; | ||
| 14 | +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
| 15 | +import org.springframework.security.web.access.intercept.FilterSecurityInterceptor; | ||
| 16 | +import org.springframework.security.web.session.HttpSessionEventPublisher; | ||
| 17 | + | ||
| 18 | +import com.bsth.common.Constants; | ||
| 19 | +import com.bsth.security.filter.LoginInterceptor; | ||
| 20 | + | ||
| 21 | +@Configuration | ||
| 22 | +@EnableWebSecurity | ||
| 23 | +public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | ||
| 24 | + | ||
| 25 | + @Autowired | ||
| 26 | + UserDetailServiceImpl customUserDetailService; | ||
| 27 | + | ||
| 28 | + @Autowired | ||
| 29 | + CustomAccessDecisionManager customAccessDecisionManager; | ||
| 30 | + | ||
| 31 | + @Autowired | ||
| 32 | + SecurityMetadataSourceService securityMetadataSourceService; | ||
| 33 | + | ||
| 34 | + @Override | ||
| 35 | + public void configure(WebSecurity web) throws Exception { | ||
| 36 | + // 白名单 | ||
| 37 | + web.ignoring().antMatchers(Constants.ASSETS_URL, Constants.FAVICON_URL, | ||
| 38 | + Constants.METRONIC_URL, Constants.LOGIN_PAGE, | ||
| 39 | + Constants.LOGIN_FAILURE); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + @Override | ||
| 43 | + protected void configure(AuthenticationManagerBuilder auth) | ||
| 44 | + throws Exception { | ||
| 45 | + auth.userDetailsService(customUserDetailService).passwordEncoder( | ||
| 46 | + new BCryptPasswordEncoder(4)); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + @Override | ||
| 50 | + protected void configure(HttpSecurity http) throws Exception { | ||
| 51 | + http.authorizeRequests().antMatchers("/").permitAll().anyRequest() | ||
| 52 | + .authenticated().and() | ||
| 53 | + .formLogin() | ||
| 54 | + //指定登录页 | ||
| 55 | + .loginPage(Constants.LOGIN_PAGE) | ||
| 56 | + .loginProcessingUrl(Constants.LOGIN).permitAll() | ||
| 57 | + //登录失败跳转的链接 | ||
| 58 | + .failureUrl(Constants.LOGIN_PAGE + "?error=true") | ||
| 59 | + //登录成功后处理 | ||
| 60 | + .successHandler(loginSuccessHandler()) | ||
| 61 | + //禁用CXRF | ||
| 62 | + .and().csrf().disable() | ||
| 63 | + //禁用匿名用户功能 | ||
| 64 | + .anonymous().disable(); | ||
| 65 | + | ||
| 66 | + // 同时只保持一个回话 | ||
| 67 | + http.sessionManagement().maximumSessions(1) | ||
| 68 | + .expiredUrl(Constants.LOGIN_PAGE + "?error=true") | ||
| 69 | + .maxSessionsPreventsLogin(false)//让之前的登录过期 | ||
| 70 | + .sessionRegistry(sessionRegistry()); | ||
| 71 | + | ||
| 72 | + http.addFilterBefore(new LoginInterceptor(), FilterSecurityInterceptor.class); | ||
| 73 | + http.addFilter(filterSecurityInterceptor()); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + private FilterSecurityInterceptor filterSecurityInterceptor() | ||
| 77 | + throws Exception { | ||
| 78 | + FilterSecurityInterceptor filterSecurityInterceptor = new FilterSecurityInterceptor(); | ||
| 79 | + filterSecurityInterceptor | ||
| 80 | + .setAccessDecisionManager(customAccessDecisionManager); | ||
| 81 | + filterSecurityInterceptor | ||
| 82 | + .setSecurityMetadataSource(securityMetadataSourceService); | ||
| 83 | + filterSecurityInterceptor | ||
| 84 | + .setAuthenticationManager(authenticationManager()); | ||
| 85 | + return filterSecurityInterceptor; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + @Bean | ||
| 89 | + public LoginSuccessHandler loginSuccessHandler(){ | ||
| 90 | + return new LoginSuccessHandler(); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + @Bean | ||
| 94 | + public SessionRegistry sessionRegistry() { | ||
| 95 | + SessionRegistry sessionRegistry = new SessionRegistryImpl(); | ||
| 96 | + return sessionRegistry; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + @Bean | ||
| 100 | + public static ServletListenerRegistrationBean<HttpSessionEventPublisher> httpSessionEventPublisher() { | ||
| 101 | + return new ServletListenerRegistrationBean<HttpSessionEventPublisher>( | ||
| 102 | + new HttpSessionEventPublisher()); | ||
| 103 | + } | ||
| 104 | +} |
src/main/java/com/bsth/security/filter/LoginInterceptor.java
| 1 | -package com.bsth.security.filter; | ||
| 2 | - | ||
| 3 | -import java.io.IOException; | ||
| 4 | -import java.util.HashMap; | ||
| 5 | -import java.util.Map; | ||
| 6 | - | ||
| 7 | -import javax.servlet.Filter; | ||
| 8 | -import javax.servlet.FilterChain; | ||
| 9 | -import javax.servlet.FilterConfig; | ||
| 10 | -import javax.servlet.ServletException; | ||
| 11 | -import javax.servlet.ServletRequest; | ||
| 12 | -import javax.servlet.ServletResponse; | ||
| 13 | -import javax.servlet.http.HttpServletRequest; | ||
| 14 | -import javax.servlet.http.HttpServletResponse; | ||
| 15 | - | ||
| 16 | -import org.springframework.security.access.SecurityMetadataSource; | ||
| 17 | -import org.springframework.security.access.intercept.AbstractSecurityInterceptor; | ||
| 18 | -import org.springframework.security.core.Authentication; | ||
| 19 | -import org.springframework.security.core.context.SecurityContextHolder; | ||
| 20 | - | ||
| 21 | -import com.bsth.common.Constants; | ||
| 22 | -import com.bsth.common.ResponseCode; | ||
| 23 | -import com.bsth.util.RequestUtils; | ||
| 24 | - | ||
| 25 | -/** | ||
| 26 | - * | ||
| 27 | - * @ClassName: LoginInterceptor | ||
| 28 | - * @Description: TODO(登录校验) | ||
| 29 | - * @author PanZhao | ||
| 30 | - * @date 2016年3月24日 上午11:49:20 | ||
| 31 | - * | ||
| 32 | - */ | ||
| 33 | -public class LoginInterceptor extends AbstractSecurityInterceptor implements Filter{ | ||
| 34 | - | ||
| 35 | - @Override | ||
| 36 | - public void destroy() { | ||
| 37 | - | ||
| 38 | - } | ||
| 39 | - | ||
| 40 | - @Override | ||
| 41 | - public void doFilter(ServletRequest arg0, ServletResponse arg1, | ||
| 42 | - FilterChain arg2) throws IOException, ServletException { | ||
| 43 | - | ||
| 44 | - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
| 45 | - | ||
| 46 | - if(null == authentication){ | ||
| 47 | - //没有登录 | ||
| 48 | - HttpServletRequest request = (HttpServletRequest)arg0; | ||
| 49 | - HttpServletResponse response = ((HttpServletResponse)arg1); | ||
| 50 | - | ||
| 51 | - if(RequestUtils.isAjaxRequest(request)){ | ||
| 52 | - Map<String, Object> map = new HashMap<>(); | ||
| 53 | - map.put("status", | ||
| 54 | - ResponseCode.NO_AUTHENTICATION); | ||
| 55 | - response.getWriter().print(map); | ||
| 56 | - } | ||
| 57 | - else | ||
| 58 | - response.sendRedirect(Constants.LOGIN_PAGE); | ||
| 59 | - | ||
| 60 | - return; | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | - arg2.doFilter(arg0, arg1); | ||
| 64 | - } | ||
| 65 | - | ||
| 66 | - @Override | ||
| 67 | - public void init(FilterConfig arg0) throws ServletException { | ||
| 68 | - | ||
| 69 | - } | ||
| 70 | - | ||
| 71 | - @Override | ||
| 72 | - public Class<?> getSecureObjectClass() { | ||
| 73 | - // TODO Auto-generated method stub | ||
| 74 | - return null; | ||
| 75 | - } | ||
| 76 | - | ||
| 77 | - @Override | ||
| 78 | - public SecurityMetadataSource obtainSecurityMetadataSource() { | ||
| 79 | - // TODO Auto-generated method stub | ||
| 80 | - return null; | ||
| 81 | - } | ||
| 82 | - | ||
| 83 | -} | 1 | +package com.bsth.security.filter; |
| 2 | + | ||
| 3 | +import java.io.IOException; | ||
| 4 | +import java.util.HashMap; | ||
| 5 | +import java.util.Map; | ||
| 6 | + | ||
| 7 | +import javax.servlet.Filter; | ||
| 8 | +import javax.servlet.FilterChain; | ||
| 9 | +import javax.servlet.FilterConfig; | ||
| 10 | +import javax.servlet.ServletException; | ||
| 11 | +import javax.servlet.ServletRequest; | ||
| 12 | +import javax.servlet.ServletResponse; | ||
| 13 | +import javax.servlet.http.HttpServletRequest; | ||
| 14 | +import javax.servlet.http.HttpServletResponse; | ||
| 15 | + | ||
| 16 | +import org.springframework.security.access.SecurityMetadataSource; | ||
| 17 | +import org.springframework.security.access.intercept.AbstractSecurityInterceptor; | ||
| 18 | +import org.springframework.security.core.Authentication; | ||
| 19 | +import org.springframework.security.core.context.SecurityContextHolder; | ||
| 20 | + | ||
| 21 | +import com.bsth.common.Constants; | ||
| 22 | +import com.bsth.common.ResponseCode; | ||
| 23 | +import com.bsth.util.RequestUtils; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * | ||
| 27 | + * @ClassName: LoginInterceptor | ||
| 28 | + * @Description: TODO(登录校验) | ||
| 29 | + * @author PanZhao | ||
| 30 | + * @date 2016年3月24日 上午11:49:20 | ||
| 31 | + * | ||
| 32 | + */ | ||
| 33 | +public class LoginInterceptor extends AbstractSecurityInterceptor implements Filter{ | ||
| 34 | + | ||
| 35 | + @Override | ||
| 36 | + public void destroy() { | ||
| 37 | + | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + @Override | ||
| 41 | + public void doFilter(ServletRequest arg0, ServletResponse arg1, | ||
| 42 | + FilterChain arg2) throws IOException, ServletException { | ||
| 43 | + | ||
| 44 | + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
| 45 | + | ||
| 46 | + if(null == authentication){ | ||
| 47 | + //没有登录 | ||
| 48 | + HttpServletRequest request = (HttpServletRequest)arg0; | ||
| 49 | + HttpServletResponse response = ((HttpServletResponse)arg1); | ||
| 50 | + | ||
| 51 | + if(RequestUtils.isAjaxRequest(request)){ | ||
| 52 | + Map<String, Object> map = new HashMap<>(); | ||
| 53 | + map.put("status", | ||
| 54 | + ResponseCode.NO_AUTHENTICATION); | ||
| 55 | + response.getWriter().print(map); | ||
| 56 | + } | ||
| 57 | + else | ||
| 58 | + response.sendRedirect(Constants.LOGIN_PAGE); | ||
| 59 | + | ||
| 60 | + return; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + arg2.doFilter(arg0, arg1); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + @Override | ||
| 67 | + public void init(FilterConfig arg0) throws ServletException { | ||
| 68 | + | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + @Override | ||
| 72 | + public Class<?> getSecureObjectClass() { | ||
| 73 | + // TODO Auto-generated method stub | ||
| 74 | + return null; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + @Override | ||
| 78 | + public SecurityMetadataSource obtainSecurityMetadataSource() { | ||
| 79 | + // TODO Auto-generated method stub | ||
| 80 | + return null; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | +} |
src/main/java/com/bsth/security/util/SecurityUtils.java
| 1 | -package com.bsth.security.util; | ||
| 2 | - | ||
| 3 | -import org.slf4j.Logger; | ||
| 4 | -import org.slf4j.LoggerFactory; | ||
| 5 | -import org.springframework.security.core.context.SecurityContextHolder; | ||
| 6 | - | ||
| 7 | -import com.bsth.entity.sys.SysUser; | ||
| 8 | - | ||
| 9 | -/** | ||
| 10 | - * | ||
| 11 | - * @ClassName: SecurityUtils | ||
| 12 | - * @author PanZhao | ||
| 13 | - * @date 2016年3月30日 上午11:28:24 | ||
| 14 | - * | ||
| 15 | - */ | ||
| 16 | -public class SecurityUtils { | ||
| 17 | - | ||
| 18 | - static Logger logger = LoggerFactory.getLogger(SecurityUtils.class); | ||
| 19 | - | ||
| 20 | - /** | ||
| 21 | - * | ||
| 22 | - * @Title: getCurrentUser | ||
| 23 | - * @Description: TODO(获取当前用户) | ||
| 24 | - * @return SysUser 返回类型 | ||
| 25 | - * @throws | ||
| 26 | - */ | ||
| 27 | - public static SysUser getCurrentUser(){ | ||
| 28 | - SysUser user = null; | ||
| 29 | - try{ | ||
| 30 | - user = (SysUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); | ||
| 31 | - }catch(Exception e){ | ||
| 32 | - logger.error("", e); | ||
| 33 | - } | ||
| 34 | - return user; | ||
| 35 | - } | ||
| 36 | -} | 1 | +package com.bsth.security.util; |
| 2 | + | ||
| 3 | +import org.slf4j.Logger; | ||
| 4 | +import org.slf4j.LoggerFactory; | ||
| 5 | +import org.springframework.security.core.context.SecurityContextHolder; | ||
| 6 | + | ||
| 7 | +import com.bsth.entity.sys.SysUser; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * | ||
| 11 | + * @ClassName: SecurityUtils | ||
| 12 | + * @author PanZhao | ||
| 13 | + * @date 2016年3月30日 上午11:28:24 | ||
| 14 | + * | ||
| 15 | + */ | ||
| 16 | +public class SecurityUtils { | ||
| 17 | + | ||
| 18 | + static Logger logger = LoggerFactory.getLogger(SecurityUtils.class); | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * | ||
| 22 | + * @Title: getCurrentUser | ||
| 23 | + * @Description: TODO(获取当前用户) | ||
| 24 | + * @return SysUser 返回类型 | ||
| 25 | + * @throws | ||
| 26 | + */ | ||
| 27 | + public static SysUser getCurrentUser(){ | ||
| 28 | + SysUser user = null; | ||
| 29 | + try{ | ||
| 30 | + user = (SysUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); | ||
| 31 | + }catch(Exception e){ | ||
| 32 | + logger.error("", e); | ||
| 33 | + } | ||
| 34 | + return user; | ||
| 35 | + } | ||
| 36 | +} |
src/main/java/com/bsth/service/BaseService.java
| 1 | -package com.bsth.service; | ||
| 2 | - | ||
| 3 | -import java.io.Serializable; | ||
| 4 | -import java.util.Map; | ||
| 5 | - | ||
| 6 | -import org.springframework.data.domain.Page; | ||
| 7 | -import org.springframework.data.domain.Pageable; | ||
| 8 | - | ||
| 9 | -/** | ||
| 10 | - * | ||
| 11 | - * @ClassName: BaseService | ||
| 12 | - * @Description: TODO(基础的Service接口) | ||
| 13 | - * @author PanZhao | ||
| 14 | - * @date 2016年3月17日 下午12:48:43 | ||
| 15 | - * | ||
| 16 | - * @param <T> | ||
| 17 | - * @param <ID> | ||
| 18 | - */ | ||
| 19 | -public interface BaseService<T, ID extends Serializable> { | ||
| 20 | - /** | ||
| 21 | - * 根据主键获取单个对象 | ||
| 22 | - * @param id | ||
| 23 | - * @return | ||
| 24 | - */ | ||
| 25 | - T findById(ID id); | ||
| 26 | - | ||
| 27 | - /** | ||
| 28 | - * 保存 | ||
| 29 | - * @param t | ||
| 30 | - * @return | ||
| 31 | - */ | ||
| 32 | - Map<String, Object> save(T t); | ||
| 33 | - | ||
| 34 | - /** | ||
| 35 | - * | ||
| 36 | - * @Title: list | ||
| 37 | - * @Description: TODO(多条件分页查询) | ||
| 38 | - * @param @param map 查询条件 | ||
| 39 | - * @param @param pageable 分页对象 | ||
| 40 | - * @throws | ||
| 41 | - */ | ||
| 42 | - Page<T> list(Map<String, Object> map, Pageable pageable); | ||
| 43 | - | ||
| 44 | - /** | ||
| 45 | - * | ||
| 46 | - * @Title: list | ||
| 47 | - * @Description: TODO(多条件查询) | ||
| 48 | - * @throws | ||
| 49 | - */ | ||
| 50 | - Iterable<T> list(Map<String, Object> map); | ||
| 51 | - | ||
| 52 | - /** | ||
| 53 | - * 获取所有 | ||
| 54 | - * @return | ||
| 55 | - */ | ||
| 56 | - Iterable<T> findAll(); | ||
| 57 | - | ||
| 58 | - /** | ||
| 59 | - * | ||
| 60 | - * @Title: deleteById | ||
| 61 | - * @Description: TODO(根据主键删除对象) | ||
| 62 | - * @param @param id | ||
| 63 | - * @throws | ||
| 64 | - */ | ||
| 65 | - Map<String, Object> delete(ID id); | ||
| 66 | -} | 1 | +package com.bsth.service; |
| 2 | + | ||
| 3 | +import java.io.Serializable; | ||
| 4 | +import java.util.Map; | ||
| 5 | + | ||
| 6 | +import org.springframework.data.domain.Page; | ||
| 7 | +import org.springframework.data.domain.Pageable; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * | ||
| 11 | + * @ClassName: BaseService | ||
| 12 | + * @Description: TODO(基础的Service接口) | ||
| 13 | + * @author PanZhao | ||
| 14 | + * @date 2016年3月17日 下午12:48:43 | ||
| 15 | + * | ||
| 16 | + * @param <T> | ||
| 17 | + * @param <ID> | ||
| 18 | + */ | ||
| 19 | +public interface BaseService<T, ID extends Serializable> { | ||
| 20 | + /** | ||
| 21 | + * 根据主键获取单个对象 | ||
| 22 | + * @param id | ||
| 23 | + * @return | ||
| 24 | + */ | ||
| 25 | + T findById(ID id); | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * 保存 | ||
| 29 | + * @param t | ||
| 30 | + * @return | ||
| 31 | + */ | ||
| 32 | + Map<String, Object> save(T t); | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * | ||
| 36 | + * @Title: list | ||
| 37 | + * @Description: TODO(多条件分页查询) | ||
| 38 | + * @param @param map 查询条件 | ||
| 39 | + * @param @param pageable 分页对象 | ||
| 40 | + * @throws | ||
| 41 | + */ | ||
| 42 | + Page<T> list(Map<String, Object> map, Pageable pageable); | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * | ||
| 46 | + * @Title: list | ||
| 47 | + * @Description: TODO(多条件查询) | ||
| 48 | + * @throws | ||
| 49 | + */ | ||
| 50 | + Iterable<T> list(Map<String, Object> map); | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * 获取所有 | ||
| 54 | + * @return | ||
| 55 | + */ | ||
| 56 | + Iterable<T> findAll(); | ||
| 57 | + | ||
| 58 | + /** | ||
| 59 | + * | ||
| 60 | + * @Title: deleteById | ||
| 61 | + * @Description: TODO(根据主键删除对象) | ||
| 62 | + * @param @param id | ||
| 63 | + * @throws | ||
| 64 | + */ | ||
| 65 | + Map<String, Object> delete(ID id); | ||
| 66 | +} |
src/main/java/com/bsth/service/DictionaryService.java
| 1 | -package com.bsth.service; | ||
| 2 | - | ||
| 3 | -import com.bsth.entity.sys.Dictionary; | ||
| 4 | - | ||
| 5 | -public interface DictionaryService extends BaseService<Dictionary, Integer>{ | ||
| 6 | - | ||
| 7 | -} | 1 | +package com.bsth.service; |
| 2 | + | ||
| 3 | +import com.bsth.entity.sys.Dictionary; | ||
| 4 | + | ||
| 5 | +public interface DictionaryService extends BaseService<Dictionary, Integer>{ | ||
| 6 | + | ||
| 7 | +} |
src/main/java/com/bsth/service/ModuleService.java
| 1 | -package com.bsth.service; | ||
| 2 | - | ||
| 3 | -import java.util.List; | ||
| 4 | - | ||
| 5 | -import com.bsth.entity.sys.Module; | ||
| 6 | - | ||
| 7 | -public interface ModuleService extends BaseService<Module, Integer>{ | ||
| 8 | - | ||
| 9 | - public List<Module> findByGroupType(String group); | ||
| 10 | - | ||
| 11 | - public List<Module> findByCurrentUser(); | ||
| 12 | - | ||
| 13 | -} | 1 | +package com.bsth.service; |
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | + | ||
| 5 | +import com.bsth.entity.sys.Module; | ||
| 6 | + | ||
| 7 | +public interface ModuleService extends BaseService<Module, Integer>{ | ||
| 8 | + | ||
| 9 | + public List<Module> findByGroupType(String group); | ||
| 10 | + | ||
| 11 | + public List<Module> findByCurrentUser(); | ||
| 12 | + | ||
| 13 | +} |
src/main/java/com/bsth/service/ResourceService.java
| 1 | -package com.bsth.service; | ||
| 2 | - | ||
| 3 | -import java.util.List; | ||
| 4 | -import java.util.Map; | ||
| 5 | - | ||
| 6 | -import com.bsth.entity.sys.Resource; | ||
| 7 | - | ||
| 8 | -public interface ResourceService extends BaseService<Resource, Integer> { | ||
| 9 | - | ||
| 10 | - Map<String, Object> saveList(List<Resource> parseArray); | ||
| 11 | - | ||
| 12 | - List<Resource> findByRolesId(Integer id); | ||
| 13 | - | ||
| 14 | -} | 1 | +package com.bsth.service; |
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | +import java.util.Map; | ||
| 5 | + | ||
| 6 | +import com.bsth.entity.sys.Resource; | ||
| 7 | + | ||
| 8 | +public interface ResourceService extends BaseService<Resource, Integer> { | ||
| 9 | + | ||
| 10 | + Map<String, Object> saveList(List<Resource> parseArray); | ||
| 11 | + | ||
| 12 | + List<Resource> findByRolesId(Integer id); | ||
| 13 | + | ||
| 14 | +} |
src/main/java/com/bsth/service/RoleService.java
| 1 | -package com.bsth.service; | ||
| 2 | - | ||
| 3 | -import java.util.Map; | ||
| 4 | - | ||
| 5 | -import com.bsth.entity.sys.Role; | ||
| 6 | - | ||
| 7 | -public interface RoleService extends BaseService<Role, Integer>{ | ||
| 8 | - | ||
| 9 | - Map<String, Object> settRoleModules(Integer roleId, String mIds); | ||
| 10 | - | ||
| 11 | -} | 1 | +package com.bsth.service; |
| 2 | + | ||
| 3 | +import java.util.Map; | ||
| 4 | + | ||
| 5 | +import com.bsth.entity.sys.Role; | ||
| 6 | + | ||
| 7 | +public interface RoleService extends BaseService<Role, Integer>{ | ||
| 8 | + | ||
| 9 | + Map<String, Object> settRoleModules(Integer roleId, String mIds); | ||
| 10 | + | ||
| 11 | +} |
src/main/java/com/bsth/service/StationService.java
| 1 | package com.bsth.service; | 1 | package com.bsth.service; |
| 2 | 2 | ||
| 3 | +import java.util.Map; | ||
| 4 | + | ||
| 3 | import com.bsth.entity.Station; | 5 | import com.bsth.entity.Station; |
| 4 | 6 | ||
| 5 | /** | 7 | /** |
| @@ -18,5 +20,7 @@ import com.bsth.entity.Station; | @@ -18,5 +20,7 @@ import com.bsth.entity.Station; | ||
| 18 | * | 20 | * |
| 19 | */ | 21 | */ |
| 20 | public interface StationService extends BaseService<Station, Integer> { | 22 | public interface StationService extends BaseService<Station, Integer> { |
| 21 | - | 23 | + |
| 24 | + Map<String, Object> systemSaveStations(Map<String, Object> map); | ||
| 25 | + | ||
| 22 | } | 26 | } |
src/main/java/com/bsth/service/SysUserService.java
| 1 | -package com.bsth.service; | ||
| 2 | - | ||
| 3 | -import com.bsth.entity.sys.SysUser; | ||
| 4 | - | ||
| 5 | -public interface SysUserService extends BaseService<SysUser, Integer>{ | ||
| 6 | - | ||
| 7 | - SysUser findByUserName(String name); | ||
| 8 | -} | 1 | +package com.bsth.service; |
| 2 | + | ||
| 3 | +import com.bsth.entity.sys.SysUser; | ||
| 4 | + | ||
| 5 | +public interface SysUserService extends BaseService<SysUser, Integer>{ | ||
| 6 | + | ||
| 7 | + SysUser findByUserName(String name); | ||
| 8 | +} |
src/main/java/com/bsth/service/impl/BaseServiceImpl.java
| 1 | -package com.bsth.service.impl; | ||
| 2 | - | ||
| 3 | -import java.io.Serializable; | ||
| 4 | -import java.util.HashMap; | ||
| 5 | -import java.util.Map; | ||
| 6 | - | ||
| 7 | -import org.slf4j.Logger; | ||
| 8 | -import org.slf4j.LoggerFactory; | ||
| 9 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 10 | -import org.springframework.dao.DataIntegrityViolationException; | ||
| 11 | -import org.springframework.data.domain.Page; | ||
| 12 | -import org.springframework.data.domain.Pageable; | ||
| 13 | - | ||
| 14 | -import com.bsth.common.ResponseCode; | ||
| 15 | -import com.bsth.entity.search.CustomerSpecs; | ||
| 16 | -import com.bsth.repository.BaseRepository; | ||
| 17 | -import com.bsth.service.BaseService; | ||
| 18 | - | ||
| 19 | -public class BaseServiceImpl<T, ID extends Serializable> implements BaseService<T, ID>{ | ||
| 20 | - | ||
| 21 | - @Autowired | ||
| 22 | - private BaseRepository<T, ID> baseRepository; | ||
| 23 | - | ||
| 24 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 25 | - | ||
| 26 | - @Override | ||
| 27 | - public Page<T> list(Map<String, Object> map, Pageable pageable) { | ||
| 28 | - return this.baseRepository.findAll(new CustomerSpecs<T>(map), pageable); | ||
| 29 | - } | ||
| 30 | - | ||
| 31 | - @Override | ||
| 32 | - public Iterable<T> list(Map<String, Object> map) { | ||
| 33 | - return this.baseRepository.findAll(new CustomerSpecs<T>(map)); | ||
| 34 | - } | ||
| 35 | - | ||
| 36 | - @Override | ||
| 37 | - public T findById(ID id) { | ||
| 38 | - return baseRepository.findOne(id); | ||
| 39 | - } | ||
| 40 | - | ||
| 41 | - @Override | ||
| 42 | - public Map<String, Object> save(T t) { | ||
| 43 | - Map<String, Object> map = new HashMap<>(); | ||
| 44 | - try{ | ||
| 45 | - baseRepository.save(t); | ||
| 46 | - map.put("status", ResponseCode.SUCCESS); | ||
| 47 | - map.put("t", t); | ||
| 48 | - }catch(Exception e){ | ||
| 49 | - map.put("status", ResponseCode.ERROR); | ||
| 50 | - logger.error("save erro.", e); | ||
| 51 | - } | ||
| 52 | - return map; | ||
| 53 | - } | ||
| 54 | - | ||
| 55 | - | ||
| 56 | - @Override | ||
| 57 | - public Iterable<T> findAll() { | ||
| 58 | - return baseRepository.findAll(); | ||
| 59 | - } | ||
| 60 | - | ||
| 61 | - @Override | ||
| 62 | - public Map<String, Object> delete(ID id) { | ||
| 63 | - Map<String, Object> map = new HashMap<>(); | ||
| 64 | - try{ | ||
| 65 | - baseRepository.delete(id); | ||
| 66 | - map.put("status", ResponseCode.SUCCESS); | ||
| 67 | - }catch(DataIntegrityViolationException de){ | ||
| 68 | - map.put("status", ResponseCode.ERROR); | ||
| 69 | - map.put("msg", "“完整性约束”校验失败,请检查要删除的对象是否存在外键约束"); | ||
| 70 | - } | ||
| 71 | - return map; | ||
| 72 | - } | ||
| 73 | -} | 1 | +package com.bsth.service.impl; |
| 2 | + | ||
| 3 | +import java.io.Serializable; | ||
| 4 | +import java.util.HashMap; | ||
| 5 | +import java.util.Map; | ||
| 6 | + | ||
| 7 | +import org.slf4j.Logger; | ||
| 8 | +import org.slf4j.LoggerFactory; | ||
| 9 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 10 | +import org.springframework.dao.DataIntegrityViolationException; | ||
| 11 | +import org.springframework.data.domain.Page; | ||
| 12 | +import org.springframework.data.domain.Pageable; | ||
| 13 | + | ||
| 14 | +import com.bsth.common.ResponseCode; | ||
| 15 | +import com.bsth.entity.search.CustomerSpecs; | ||
| 16 | +import com.bsth.repository.BaseRepository; | ||
| 17 | +import com.bsth.service.BaseService; | ||
| 18 | + | ||
| 19 | +public class BaseServiceImpl<T, ID extends Serializable> implements BaseService<T, ID>{ | ||
| 20 | + | ||
| 21 | + @Autowired | ||
| 22 | + private BaseRepository<T, ID> baseRepository; | ||
| 23 | + | ||
| 24 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 25 | + | ||
| 26 | + @Override | ||
| 27 | + public Page<T> list(Map<String, Object> map, Pageable pageable) { | ||
| 28 | + return this.baseRepository.findAll(new CustomerSpecs<T>(map), pageable); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + @Override | ||
| 32 | + public Iterable<T> list(Map<String, Object> map) { | ||
| 33 | + return this.baseRepository.findAll(new CustomerSpecs<T>(map)); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + @Override | ||
| 37 | + public T findById(ID id) { | ||
| 38 | + return baseRepository.findOne(id); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + @Override | ||
| 42 | + public Map<String, Object> save(T t) { | ||
| 43 | + Map<String, Object> map = new HashMap<>(); | ||
| 44 | + try{ | ||
| 45 | + baseRepository.save(t); | ||
| 46 | + map.put("status", ResponseCode.SUCCESS); | ||
| 47 | + map.put("t", t); | ||
| 48 | + }catch(Exception e){ | ||
| 49 | + map.put("status", ResponseCode.ERROR); | ||
| 50 | + logger.error("save erro.", e); | ||
| 51 | + } | ||
| 52 | + return map; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + | ||
| 56 | + @Override | ||
| 57 | + public Iterable<T> findAll() { | ||
| 58 | + return baseRepository.findAll(); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + @Override | ||
| 62 | + public Map<String, Object> delete(ID id) { | ||
| 63 | + Map<String, Object> map = new HashMap<>(); | ||
| 64 | + try{ | ||
| 65 | + baseRepository.delete(id); | ||
| 66 | + map.put("status", ResponseCode.SUCCESS); | ||
| 67 | + }catch(DataIntegrityViolationException de){ | ||
| 68 | + map.put("status", ResponseCode.ERROR); | ||
| 69 | + map.put("msg", "“完整性约束”校验失败,请检查要删除的对象是否存在外键约束"); | ||
| 70 | + } | ||
| 71 | + return map; | ||
| 72 | + } | ||
| 73 | +} |
src/main/java/com/bsth/service/impl/DictionaryServiceImpl.java
| 1 | -package com.bsth.service.impl; | ||
| 2 | - | ||
| 3 | -import org.springframework.stereotype.Service; | ||
| 4 | - | ||
| 5 | -import com.bsth.entity.sys.Dictionary; | ||
| 6 | -import com.bsth.service.DictionaryService; | ||
| 7 | - | ||
| 8 | -@Service | ||
| 9 | -public class DictionaryServiceImpl extends BaseServiceImpl<Dictionary, Integer> implements DictionaryService{ | ||
| 10 | - | ||
| 11 | -} | 1 | +package com.bsth.service.impl; |
| 2 | + | ||
| 3 | +import org.springframework.stereotype.Service; | ||
| 4 | + | ||
| 5 | +import com.bsth.entity.sys.Dictionary; | ||
| 6 | +import com.bsth.service.DictionaryService; | ||
| 7 | + | ||
| 8 | +@Service | ||
| 9 | +public class DictionaryServiceImpl extends BaseServiceImpl<Dictionary, Integer> implements DictionaryService{ | ||
| 10 | + | ||
| 11 | +} |
src/main/java/com/bsth/service/impl/ModuleServiceImpl.java
| 1 | -package com.bsth.service.impl; | ||
| 2 | - | ||
| 3 | -import java.util.ArrayList; | ||
| 4 | -import java.util.HashMap; | ||
| 5 | -import java.util.HashSet; | ||
| 6 | -import java.util.List; | ||
| 7 | -import java.util.Map; | ||
| 8 | -import java.util.Set; | ||
| 9 | - | ||
| 10 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 11 | -import org.springframework.stereotype.Service; | ||
| 12 | - | ||
| 13 | -import com.bsth.common.ResponseCode; | ||
| 14 | -import com.bsth.entity.sys.Module; | ||
| 15 | -import com.bsth.entity.sys.Role; | ||
| 16 | -import com.bsth.entity.sys.SysUser; | ||
| 17 | -import com.bsth.repository.ModuleRepository; | ||
| 18 | -import com.bsth.security.util.SecurityUtils; | ||
| 19 | -import com.bsth.service.ModuleService; | ||
| 20 | - | ||
| 21 | -@Service | ||
| 22 | -public class ModuleServiceImpl extends BaseServiceImpl<Module, Integer> implements ModuleService{ | ||
| 23 | - | ||
| 24 | - @Autowired | ||
| 25 | - ModuleRepository moduleRepository; | ||
| 26 | - | ||
| 27 | - @Override | ||
| 28 | - public List<Module> findByGroupType(String group) { | ||
| 29 | - String[] array; | ||
| 30 | - if(group.indexOf(",") != -1){ | ||
| 31 | - array = group.split(","); | ||
| 32 | - } | ||
| 33 | - else | ||
| 34 | - array = new String[]{group}; | ||
| 35 | - return moduleRepository.findByGroupType(array); | ||
| 36 | - } | ||
| 37 | - | ||
| 38 | - @Override | ||
| 39 | - public Map<String, Object> delete(Integer id) { | ||
| 40 | - | ||
| 41 | - Map<String, Object> map = new HashMap<>(); | ||
| 42 | - | ||
| 43 | - //判断删除的节点是否有子节点 | ||
| 44 | - List<Module> list = moduleRepository.findByPId(id); | ||
| 45 | - | ||
| 46 | - if(null != list && list.size() > 0){ | ||
| 47 | - map.put("status", ResponseCode.ERROR); | ||
| 48 | - map.put("msg", "失败,要删除的项还存在子节点"); | ||
| 49 | - } | ||
| 50 | - else{ | ||
| 51 | - map = super.delete(id); | ||
| 52 | - } | ||
| 53 | - return map; | ||
| 54 | - } | ||
| 55 | - | ||
| 56 | - @Override | ||
| 57 | - public List<Module> findByCurrentUser() { | ||
| 58 | - | ||
| 59 | - SysUser user = SecurityUtils.getCurrentUser(); | ||
| 60 | - Set<Role> roles = user.getRoles(); | ||
| 61 | - | ||
| 62 | - List<Module> all = (List<Module>) moduleRepository.findAll() | ||
| 63 | - ,results = new ArrayList<>(); | ||
| 64 | - | ||
| 65 | - Map<Integer, Module> map = new HashMap<>(); | ||
| 66 | - for(Module m : all){ | ||
| 67 | - map.put(m.getId(), m); | ||
| 68 | - for(Role r : roles){ | ||
| 69 | - if(m.getRoles().contains(r)) | ||
| 70 | - results.add(m); | ||
| 71 | - } | ||
| 72 | - } | ||
| 73 | - | ||
| 74 | - //上层目录和组节点 | ||
| 75 | - Set<Module> pSet = new HashSet<>(); | ||
| 76 | - for(Module m : results){ | ||
| 77 | - searchParentNode(m, map, pSet); | ||
| 78 | - } | ||
| 79 | - results.addAll(pSet); | ||
| 80 | - return results; | ||
| 81 | - } | ||
| 82 | - | ||
| 83 | - /** | ||
| 84 | - * | ||
| 85 | - * @Title: searchParentNode | ||
| 86 | - * @Description: TODO(搜索上层节点) | ||
| 87 | - * @param @param m 当前节点 | ||
| 88 | - * @param @param idMap 全量的ID和节点对照 | ||
| 89 | - * @param @param pSet 上层节点容器 | ||
| 90 | - * @throws | ||
| 91 | - */ | ||
| 92 | - public void searchParentNode(Module m, Map<Integer, Module> idMap, Set<Module> pSet){ | ||
| 93 | - int pId = m.getpId(); | ||
| 94 | - if(pId > 0){ | ||
| 95 | - Module pModule = idMap.get(pId); | ||
| 96 | - pSet.add(pModule); | ||
| 97 | - | ||
| 98 | - if(null != pModule && | ||
| 99 | - null != pModule.getpId() | ||
| 100 | - && pModule.getpId() > 0) | ||
| 101 | - searchParentNode(pModule, idMap, pSet); | ||
| 102 | - } | ||
| 103 | - } | ||
| 104 | -} | 1 | +package com.bsth.service.impl; |
| 2 | + | ||
| 3 | +import java.util.ArrayList; | ||
| 4 | +import java.util.HashMap; | ||
| 5 | +import java.util.HashSet; | ||
| 6 | +import java.util.List; | ||
| 7 | +import java.util.Map; | ||
| 8 | +import java.util.Set; | ||
| 9 | + | ||
| 10 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 11 | +import org.springframework.stereotype.Service; | ||
| 12 | + | ||
| 13 | +import com.bsth.common.ResponseCode; | ||
| 14 | +import com.bsth.entity.sys.Module; | ||
| 15 | +import com.bsth.entity.sys.Role; | ||
| 16 | +import com.bsth.entity.sys.SysUser; | ||
| 17 | +import com.bsth.repository.ModuleRepository; | ||
| 18 | +import com.bsth.security.util.SecurityUtils; | ||
| 19 | +import com.bsth.service.ModuleService; | ||
| 20 | + | ||
| 21 | +@Service | ||
| 22 | +public class ModuleServiceImpl extends BaseServiceImpl<Module, Integer> implements ModuleService{ | ||
| 23 | + | ||
| 24 | + @Autowired | ||
| 25 | + ModuleRepository moduleRepository; | ||
| 26 | + | ||
| 27 | + @Override | ||
| 28 | + public List<Module> findByGroupType(String group) { | ||
| 29 | + String[] array; | ||
| 30 | + if(group.indexOf(",") != -1){ | ||
| 31 | + array = group.split(","); | ||
| 32 | + } | ||
| 33 | + else | ||
| 34 | + array = new String[]{group}; | ||
| 35 | + return moduleRepository.findByGroupType(array); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + @Override | ||
| 39 | + public Map<String, Object> delete(Integer id) { | ||
| 40 | + | ||
| 41 | + Map<String, Object> map = new HashMap<>(); | ||
| 42 | + | ||
| 43 | + //判断删除的节点是否有子节点 | ||
| 44 | + List<Module> list = moduleRepository.findByPId(id); | ||
| 45 | + | ||
| 46 | + if(null != list && list.size() > 0){ | ||
| 47 | + map.put("status", ResponseCode.ERROR); | ||
| 48 | + map.put("msg", "失败,要删除的项还存在子节点"); | ||
| 49 | + } | ||
| 50 | + else{ | ||
| 51 | + map = super.delete(id); | ||
| 52 | + } | ||
| 53 | + return map; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + @Override | ||
| 57 | + public List<Module> findByCurrentUser() { | ||
| 58 | + | ||
| 59 | + SysUser user = SecurityUtils.getCurrentUser(); | ||
| 60 | + Set<Role> roles = user.getRoles(); | ||
| 61 | + | ||
| 62 | + List<Module> all = (List<Module>) moduleRepository.findAll() | ||
| 63 | + ,results = new ArrayList<>(); | ||
| 64 | + | ||
| 65 | + Map<Integer, Module> map = new HashMap<>(); | ||
| 66 | + for(Module m : all){ | ||
| 67 | + map.put(m.getId(), m); | ||
| 68 | + for(Role r : roles){ | ||
| 69 | + if(m.getRoles().contains(r)) | ||
| 70 | + results.add(m); | ||
| 71 | + } | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + //上层目录和组节点 | ||
| 75 | + Set<Module> pSet = new HashSet<>(); | ||
| 76 | + for(Module m : results){ | ||
| 77 | + searchParentNode(m, map, pSet); | ||
| 78 | + } | ||
| 79 | + results.addAll(pSet); | ||
| 80 | + return results; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + /** | ||
| 84 | + * | ||
| 85 | + * @Title: searchParentNode | ||
| 86 | + * @Description: TODO(搜索上层节点) | ||
| 87 | + * @param @param m 当前节点 | ||
| 88 | + * @param @param idMap 全量的ID和节点对照 | ||
| 89 | + * @param @param pSet 上层节点容器 | ||
| 90 | + * @throws | ||
| 91 | + */ | ||
| 92 | + public void searchParentNode(Module m, Map<Integer, Module> idMap, Set<Module> pSet){ | ||
| 93 | + int pId = m.getpId(); | ||
| 94 | + if(pId > 0){ | ||
| 95 | + Module pModule = idMap.get(pId); | ||
| 96 | + pSet.add(pModule); | ||
| 97 | + | ||
| 98 | + if(null != pModule && | ||
| 99 | + null != pModule.getpId() | ||
| 100 | + && pModule.getpId() > 0) | ||
| 101 | + searchParentNode(pModule, idMap, pSet); | ||
| 102 | + } | ||
| 103 | + } | ||
| 104 | +} |
src/main/java/com/bsth/service/impl/ResourceServiceImpl.java
| 1 | -package com.bsth.service.impl; | ||
| 2 | - | ||
| 3 | -import java.util.HashMap; | ||
| 4 | -import java.util.List; | ||
| 5 | -import java.util.Map; | ||
| 6 | - | ||
| 7 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 8 | -import org.springframework.stereotype.Service; | ||
| 9 | - | ||
| 10 | -import com.bsth.common.ResponseCode; | ||
| 11 | -import com.bsth.entity.sys.Resource; | ||
| 12 | -import com.bsth.repository.ResourceRepository; | ||
| 13 | -import com.bsth.service.ResourceService; | ||
| 14 | - | ||
| 15 | -@Service | ||
| 16 | -public class ResourceServiceImpl extends BaseServiceImpl<Resource, Integer> implements ResourceService{ | ||
| 17 | - | ||
| 18 | - @Autowired | ||
| 19 | - ResourceRepository resourceRepository; | ||
| 20 | - | ||
| 21 | - @Override | ||
| 22 | - public Map<String, Object> saveList(List<Resource> array) { | ||
| 23 | - Map<String, Object> map = new HashMap<>(); | ||
| 24 | - try{ | ||
| 25 | - resourceRepository.save(array); | ||
| 26 | - map.put("status", ResponseCode.SUCCESS); | ||
| 27 | - }catch(Exception e){ | ||
| 28 | - map.put("status", ResponseCode.ERROR); | ||
| 29 | - logger.error("", e); | ||
| 30 | - } | ||
| 31 | - return map; | ||
| 32 | - } | ||
| 33 | - | ||
| 34 | - @Override | ||
| 35 | - public List<Resource> findByRolesId(Integer id) { | ||
| 36 | - return resourceRepository.findByRolesId(id); | ||
| 37 | - } | ||
| 38 | -} | 1 | +package com.bsth.service.impl; |
| 2 | + | ||
| 3 | +import java.util.HashMap; | ||
| 4 | +import java.util.List; | ||
| 5 | +import java.util.Map; | ||
| 6 | + | ||
| 7 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 8 | +import org.springframework.stereotype.Service; | ||
| 9 | + | ||
| 10 | +import com.bsth.common.ResponseCode; | ||
| 11 | +import com.bsth.entity.sys.Resource; | ||
| 12 | +import com.bsth.repository.ResourceRepository; | ||
| 13 | +import com.bsth.service.ResourceService; | ||
| 14 | + | ||
| 15 | +@Service | ||
| 16 | +public class ResourceServiceImpl extends BaseServiceImpl<Resource, Integer> implements ResourceService{ | ||
| 17 | + | ||
| 18 | + @Autowired | ||
| 19 | + ResourceRepository resourceRepository; | ||
| 20 | + | ||
| 21 | + @Override | ||
| 22 | + public Map<String, Object> saveList(List<Resource> array) { | ||
| 23 | + Map<String, Object> map = new HashMap<>(); | ||
| 24 | + try{ | ||
| 25 | + resourceRepository.save(array); | ||
| 26 | + map.put("status", ResponseCode.SUCCESS); | ||
| 27 | + }catch(Exception e){ | ||
| 28 | + map.put("status", ResponseCode.ERROR); | ||
| 29 | + logger.error("", e); | ||
| 30 | + } | ||
| 31 | + return map; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + @Override | ||
| 35 | + public List<Resource> findByRolesId(Integer id) { | ||
| 36 | + return resourceRepository.findByRolesId(id); | ||
| 37 | + } | ||
| 38 | +} |
src/main/java/com/bsth/service/impl/RoleServiceImpl.java
| 1 | -package com.bsth.service.impl; | ||
| 2 | - | ||
| 3 | -import java.util.ArrayList; | ||
| 4 | -import java.util.HashMap; | ||
| 5 | -import java.util.List; | ||
| 6 | -import java.util.Map; | ||
| 7 | -import java.util.Set; | ||
| 8 | - | ||
| 9 | -import org.slf4j.Logger; | ||
| 10 | -import org.slf4j.LoggerFactory; | ||
| 11 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 12 | -import org.springframework.stereotype.Service; | ||
| 13 | - | ||
| 14 | -import com.bsth.common.ResponseCode; | ||
| 15 | -import com.bsth.entity.sys.Module; | ||
| 16 | -import com.bsth.entity.sys.Role; | ||
| 17 | -import com.bsth.repository.ModuleRepository; | ||
| 18 | -import com.bsth.repository.RoleRepository; | ||
| 19 | -import com.bsth.service.RoleService; | ||
| 20 | - | ||
| 21 | -@Service | ||
| 22 | -public class RoleServiceImpl extends BaseServiceImpl<Role, Integer> implements | ||
| 23 | - RoleService { | ||
| 24 | - | ||
| 25 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 26 | - | ||
| 27 | - @Autowired | ||
| 28 | - RoleRepository roleRepository; | ||
| 29 | - | ||
| 30 | - @Autowired | ||
| 31 | - ModuleRepository moduleRepository; | ||
| 32 | - | ||
| 33 | - @Override | ||
| 34 | - public Map<String, Object> save(Role t) { | ||
| 35 | - if (t.getId() != null) { | ||
| 36 | - // 更新 | ||
| 37 | - Map<String, Object> map = new HashMap<>(); | ||
| 38 | - try { | ||
| 39 | - roleRepository.update(t.getCodeName(), t.getRoleName(), | ||
| 40 | - t.isEnable(), t.getDescriptions(), t.getId()); | ||
| 41 | - map.put("status", ResponseCode.SUCCESS); | ||
| 42 | - } catch (Exception e) { | ||
| 43 | - map.put("status", ResponseCode.ERROR); | ||
| 44 | - } | ||
| 45 | - return map; | ||
| 46 | - } | ||
| 47 | - return super.save(t); | ||
| 48 | - } | ||
| 49 | - | ||
| 50 | - @Override | ||
| 51 | - public Map<String, Object> settRoleModules(Integer roleId, String mIds) { | ||
| 52 | - | ||
| 53 | - Map<String, Object> map = new HashMap<>(); | ||
| 54 | - try { | ||
| 55 | - Role role = roleRepository.findOne(roleId); | ||
| 56 | - | ||
| 57 | - List<Integer> idList = new ArrayList<>(); | ||
| 58 | - String[] array = mIds.split(","); | ||
| 59 | - for (String id : array) { | ||
| 60 | - if (null == id || id.trim().equals("")) | ||
| 61 | - continue; | ||
| 62 | - idList.add(Integer.parseInt(id)); | ||
| 63 | - } | ||
| 64 | - | ||
| 65 | - Set<Module> mList = moduleRepository.findByIds(idList); | ||
| 66 | - role.setModules(mList); | ||
| 67 | - roleRepository.save(role); | ||
| 68 | - map.put("status", ResponseCode.SUCCESS); | ||
| 69 | - } catch (Exception e) { | ||
| 70 | - logger.error("", e); | ||
| 71 | - map.put("status", ResponseCode.ERROR); | ||
| 72 | - } | ||
| 73 | - return map; | ||
| 74 | - } | ||
| 75 | -} | 1 | +package com.bsth.service.impl; |
| 2 | + | ||
| 3 | +import java.util.ArrayList; | ||
| 4 | +import java.util.HashMap; | ||
| 5 | +import java.util.List; | ||
| 6 | +import java.util.Map; | ||
| 7 | +import java.util.Set; | ||
| 8 | + | ||
| 9 | +import org.slf4j.Logger; | ||
| 10 | +import org.slf4j.LoggerFactory; | ||
| 11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 12 | +import org.springframework.stereotype.Service; | ||
| 13 | + | ||
| 14 | +import com.bsth.common.ResponseCode; | ||
| 15 | +import com.bsth.entity.sys.Module; | ||
| 16 | +import com.bsth.entity.sys.Role; | ||
| 17 | +import com.bsth.repository.ModuleRepository; | ||
| 18 | +import com.bsth.repository.RoleRepository; | ||
| 19 | +import com.bsth.service.RoleService; | ||
| 20 | + | ||
| 21 | +@Service | ||
| 22 | +public class RoleServiceImpl extends BaseServiceImpl<Role, Integer> implements | ||
| 23 | + RoleService { | ||
| 24 | + | ||
| 25 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 26 | + | ||
| 27 | + @Autowired | ||
| 28 | + RoleRepository roleRepository; | ||
| 29 | + | ||
| 30 | + @Autowired | ||
| 31 | + ModuleRepository moduleRepository; | ||
| 32 | + | ||
| 33 | + @Override | ||
| 34 | + public Map<String, Object> save(Role t) { | ||
| 35 | + if (t.getId() != null) { | ||
| 36 | + // 更新 | ||
| 37 | + Map<String, Object> map = new HashMap<>(); | ||
| 38 | + try { | ||
| 39 | + roleRepository.update(t.getCodeName(), t.getRoleName(), | ||
| 40 | + t.isEnable(), t.getDescriptions(), t.getId()); | ||
| 41 | + map.put("status", ResponseCode.SUCCESS); | ||
| 42 | + } catch (Exception e) { | ||
| 43 | + map.put("status", ResponseCode.ERROR); | ||
| 44 | + } | ||
| 45 | + return map; | ||
| 46 | + } | ||
| 47 | + return super.save(t); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + @Override | ||
| 51 | + public Map<String, Object> settRoleModules(Integer roleId, String mIds) { | ||
| 52 | + | ||
| 53 | + Map<String, Object> map = new HashMap<>(); | ||
| 54 | + try { | ||
| 55 | + Role role = roleRepository.findOne(roleId); | ||
| 56 | + | ||
| 57 | + List<Integer> idList = new ArrayList<>(); | ||
| 58 | + String[] array = mIds.split(","); | ||
| 59 | + for (String id : array) { | ||
| 60 | + if (null == id || id.trim().equals("")) | ||
| 61 | + continue; | ||
| 62 | + idList.add(Integer.parseInt(id)); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + Set<Module> mList = moduleRepository.findByIds(idList); | ||
| 66 | + role.setModules(mList); | ||
| 67 | + roleRepository.save(role); | ||
| 68 | + map.put("status", ResponseCode.SUCCESS); | ||
| 69 | + } catch (Exception e) { | ||
| 70 | + logger.error("", e); | ||
| 71 | + map.put("status", ResponseCode.ERROR); | ||
| 72 | + } | ||
| 73 | + return map; | ||
| 74 | + } | ||
| 75 | +} |
src/main/java/com/bsth/service/impl/StationServiceImpl.java
| 1 | package com.bsth.service.impl; | 1 | package com.bsth.service.impl; |
| 2 | 2 | ||
| 3 | +import java.util.HashMap; | ||
| 4 | +import java.util.Map; | ||
| 5 | + | ||
| 3 | import org.springframework.stereotype.Service; | 6 | import org.springframework.stereotype.Service; |
| 4 | 7 | ||
| 5 | import com.bsth.entity.Station; | 8 | import com.bsth.entity.Station; |
| @@ -24,4 +27,12 @@ import com.bsth.service.StationService; | @@ -24,4 +27,12 @@ import com.bsth.service.StationService; | ||
| 24 | @Service | 27 | @Service |
| 25 | public class StationServiceImpl extends BaseServiceImpl<Station, Integer> implements StationService{ | 28 | public class StationServiceImpl extends BaseServiceImpl<Station, Integer> implements StationService{ |
| 26 | 29 | ||
| 30 | + @Override | ||
| 31 | + public Map<String, Object> systemSaveStations(Map<String, Object> map) { | ||
| 32 | + | ||
| 33 | + Map<String, Object> resultMap = new HashMap<String,Object>(); | ||
| 34 | + | ||
| 35 | + return null; | ||
| 36 | + } | ||
| 37 | + | ||
| 27 | } | 38 | } |
src/main/java/com/bsth/service/impl/SysUserServiceImpl.java
| 1 | -package com.bsth.service.impl; | ||
| 2 | - | ||
| 3 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 4 | -import org.springframework.stereotype.Service; | ||
| 5 | - | ||
| 6 | -import com.bsth.entity.sys.SysUser; | ||
| 7 | -import com.bsth.repository.SysUserRepository; | ||
| 8 | -import com.bsth.service.SysUserService; | ||
| 9 | - | ||
| 10 | -@Service | ||
| 11 | -public class SysUserServiceImpl extends BaseServiceImpl<SysUser, Integer> implements SysUserService{ | ||
| 12 | - | ||
| 13 | - @Autowired | ||
| 14 | - SysUserRepository sysUserRepository; | ||
| 15 | - | ||
| 16 | - @Override | ||
| 17 | - public SysUser findByUserName(String name) { | ||
| 18 | - return sysUserRepository.findByUserName(name); | ||
| 19 | - } | ||
| 20 | -} | 1 | +package com.bsth.service.impl; |
| 2 | + | ||
| 3 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 4 | +import org.springframework.stereotype.Service; | ||
| 5 | + | ||
| 6 | +import com.bsth.entity.sys.SysUser; | ||
| 7 | +import com.bsth.repository.SysUserRepository; | ||
| 8 | +import com.bsth.service.SysUserService; | ||
| 9 | + | ||
| 10 | +@Service | ||
| 11 | +public class SysUserServiceImpl extends BaseServiceImpl<SysUser, Integer> implements SysUserService{ | ||
| 12 | + | ||
| 13 | + @Autowired | ||
| 14 | + SysUserRepository sysUserRepository; | ||
| 15 | + | ||
| 16 | + @Override | ||
| 17 | + public SysUser findByUserName(String name) { | ||
| 18 | + return sysUserRepository.findByUserName(name); | ||
| 19 | + } | ||
| 20 | +} |