@@ -0,0 +1,21 @@ | |||
*.class | |||
# Mobile Tools for Java (J2ME) | |||
.mtj.tmp/ | |||
# Package Files # | |||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | |||
hs_err_pid* | |||
/.idea/ | |||
*.iml | |||
target | |||
*/target | |||
**/rebel.xml | |||
**/.rebel.xml.bak | |||
doc | |||
*.log |
@@ -0,0 +1,57 @@ | |||
## 项目结构 | |||
* fumao-app | |||
* 对外接口和WEB的配置项 | |||
* fumao-common | |||
* 一些常用的工具类 | |||
* fumao-company | |||
* 集团端代码 | |||
* fumao-system | |||
* 系统端代码 | |||
* fumao-service | |||
* controller里面调用, 聚合其他几个模块的代码 | |||
## jpa相关 | |||
### 快速查询 | |||
``` | |||
@QueryItem(type = QueryType.Eq) 等等 | |||
用于快速开发查询接口 | |||
QueryBuilder.build(条件对象) 返回 Predicate 可交给SpringData 查询 | |||
``` | |||
### 非外键原则 | |||
``` | |||
@Fetch(FetchMode.JOIN) | |||
@ManyToOne() | |||
@JoinColumn(name = "本实体ID", referencedColumnName = "关联ID", insertable = false, updatable = false, foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT)) | |||
@NotFound(action=NotFoundAction.IGNORE) | |||
``` | |||
## 权限 | |||
``` | |||
使用spring security | |||
``` | |||
* 配置项 | |||
* WebSecurityConfig | |||
* 过滤器 | |||
* SecurityFilter | |||
* 注解 | |||
* PreAuthorize(AuthRoles.xxxExp) | |||
* 使用 | |||
* 实现LoginUser接口 | |||
* 调用JwtUtils.encode | |||
* 方法或者类上面加PreAuthorize注解 | |||
* 动态角色实现 AccessDecisionManager 接口 | |||
## 集团实例 | |||
``` | |||
新建集团的时候会手动跑Flyway方法, 创建一个新实例 | |||
``` |
@@ -0,0 +1,62 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<project xmlns="http://maven.apache.org/POM/4.0.0" | |||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |||
<parent> | |||
<artifactId>fumao</artifactId> | |||
<groupId>com.aki</groupId> | |||
<version>0.0.1-SNAPSHOT</version> | |||
</parent> | |||
<modelVersion>4.0.0</modelVersion> | |||
<artifactId>fumao-app</artifactId> | |||
<dependencies> | |||
<dependency> | |||
<groupId>org.springframework.boot</groupId> | |||
<artifactId>spring-boot-starter-web</artifactId> | |||
<exclusions> | |||
<exclusion> | |||
<groupId>org.springframework.boot</groupId> | |||
<artifactId>spring-boot-starter-tomcat</artifactId> | |||
</exclusion> | |||
</exclusions> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.springframework.boot</groupId> | |||
<artifactId>spring-boot-starter-undertow</artifactId> | |||
</dependency> | |||
<!--<dependency>--> | |||
<!--<groupId>org.springframework.boot</groupId>--> | |||
<!--<artifactId>spring-boot-starter-websocket</artifactId>--> | |||
<!--</dependency>--> | |||
<dependency> | |||
<groupId>com.aki</groupId> | |||
<artifactId>fumao-service</artifactId> | |||
<version>${project.version}</version> | |||
</dependency> | |||
</dependencies> | |||
<build> | |||
<plugins> | |||
<plugin> | |||
<groupId>org.springframework.boot</groupId> | |||
<artifactId>spring-boot-maven-plugin</artifactId> | |||
<executions> | |||
<execution> | |||
<goals> | |||
<goal>build-info</goal> | |||
</goals> | |||
</execution> | |||
</executions> | |||
<configuration> | |||
<fork>true</fork> | |||
<includeSystemScope>true</includeSystemScope> | |||
</configuration> | |||
</plugin> | |||
</plugins> | |||
</build> | |||
</project> |
@@ -0,0 +1,48 @@ | |||
package com.chilunyc.fumao; | |||
import com.chilunyc.fumao.common.config.ApplicationProperty; | |||
import com.chilunyc.fumao.config.bean.MultiBeanNameGenerator; | |||
import com.alibaba.fastjson.parser.ParserConfig; | |||
import org.springframework.boot.autoconfigure.SpringBootApplication; | |||
import org.springframework.boot.builder.SpringApplicationBuilder; | |||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | |||
import org.springframework.boot.system.ApplicationPidFileWriter; | |||
import org.springframework.boot.web.servlet.ServletComponentScan; | |||
import org.springframework.context.ConfigurableApplicationContext; | |||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | |||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | |||
import org.springframework.scheduling.annotation.EnableAsync; | |||
import org.springframework.scheduling.annotation.EnableScheduling; | |||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; | |||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | |||
import org.springframework.transaction.annotation.EnableTransactionManagement; | |||
/** | |||
* | |||
*/ | |||
@SpringBootApplication() | |||
@EnableAsync | |||
@EnableScheduling | |||
@EnableJpaRepositories | |||
@EnableJpaAuditing | |||
@EnableTransactionManagement | |||
@EnableWebSecurity | |||
@EnableGlobalMethodSecurity( | |||
prePostEnabled = true | |||
) | |||
@ServletComponentScan() | |||
@EnableConfigurationProperties(ApplicationProperty.class) | |||
public class Application { | |||
public static void main(String[] args) { | |||
// | |||
ParserConfig.getGlobalInstance().setAutoTypeSupport(true); | |||
// | |||
ConfigurableApplicationContext run = new SpringApplicationBuilder(Application.class) | |||
.addCommandLineProperties(false) | |||
.listeners(new ApplicationPidFileWriter("./app.pid")) | |||
.beanNameGenerator(new MultiBeanNameGenerator()) | |||
.run(args); | |||
} | |||
} |
@@ -0,0 +1,104 @@ | |||
package com.chilunyc.fumao.api.company; | |||
import com.chilunyc.fumao.common.exception.SystemException; | |||
import com.chilunyc.fumao.common.request.IdsRequest; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import com.chilunyc.fumao.common.shiro.AuthRoles; | |||
import com.chilunyc.fumao.company.model.Company; | |||
import com.chilunyc.fumao.company.model.CompanyAdmin; | |||
import com.chilunyc.fumao.company.request.companyAdmin.CompanyAdminEditRequest; | |||
import com.chilunyc.fumao.company.request.companyAdmin.CompanyAdminPageRequest; | |||
import com.chilunyc.fumao.company.service.CompanyAdminService; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiImplicitParam; | |||
import io.swagger.annotations.ApiImplicitParams; | |||
import io.swagger.annotations.ApiOperation; | |||
import lombok.extern.log4j.Log4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.data.domain.Page; | |||
import org.springframework.security.access.prepost.PreAuthorize; | |||
import org.springframework.web.bind.annotation.*; | |||
import javax.validation.Valid; | |||
import java.util.List; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@Api(description = "集团管理员") | |||
@RestController | |||
@RequestMapping("/company/admin") | |||
@PreAuthorize(AuthRoles.CompanyAdminExp) | |||
class CompanyAdminController { | |||
@Autowired | |||
CompanyAdminService companyAdminService; | |||
@ApiOperation(value = "分页") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "PageRequest") | |||
}) | |||
@RequestMapping(value = "/find", method = RequestMethod.POST) | |||
JsonResponse<Page<CompanyAdmin>> page(CompanyAdmin companyAdmin, @RequestBody CompanyAdminPageRequest request) { | |||
request.setCompanyId(companyAdmin.getCompanyId()); | |||
Page<CompanyAdmin> page = companyAdminService.page(request); | |||
return JsonResponse.success(page); | |||
} | |||
@ApiOperation(value = "详情") | |||
@ApiImplicitParams({ | |||
}) | |||
@RequestMapping(value = "/find/{id}", method = RequestMethod.GET) | |||
JsonResponse<CompanyAdmin> info(CompanyAdmin companyAdmin, @PathVariable Long id) { | |||
CompanyAdmin companyAdminResponse = companyAdminService.findByCompanyId(id, companyAdmin.getCompanyId()); | |||
return JsonResponse.success(companyAdminResponse); | |||
} | |||
@ApiOperation(value = "新增 | 编辑") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "CompanyAdmin") | |||
}) | |||
@RequestMapping(value = "/edit", method = RequestMethod.POST) | |||
JsonResponse edit(CompanyAdmin companyAdmin, @RequestBody @Valid CompanyAdminEditRequest request) { | |||
request.setCompanyId(companyAdmin.getCompanyId()); | |||
companyAdminService.edit(request); | |||
return JsonResponse.success(); | |||
} | |||
@ApiOperation(value = "删除") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "IdRequest") | |||
}) | |||
@RequestMapping(value = "/delete", method = RequestMethod.POST) | |||
JsonResponse remove(CompanyAdmin companyAdmin, @RequestBody @Valid IdsRequest<Long> request) { | |||
if (request.getIds().contains(companyAdmin.getId())){ | |||
throw new SystemException("100001"); | |||
} | |||
companyAdminService.removeByCompanyId(request, companyAdmin.getCompanyId()); | |||
return JsonResponse.success(); | |||
} | |||
@ApiOperation(value = "重置密码") | |||
@ApiImplicitParams({ | |||
}) | |||
@RequestMapping(value = "/reset/password/{id}", method = RequestMethod.GET) | |||
JsonResponse resetPassword(CompanyAdmin companyAdmin, @PathVariable Long id) { | |||
companyAdminService.resetPassword(id, companyAdmin.getCompanyId()); | |||
log.info(String.format("集团管理员[ %s ]重置密码 => [ %s ]", companyAdmin.getId(), id)); | |||
return JsonResponse.success(); | |||
} | |||
@ApiOperation(value = "所有") | |||
@ApiImplicitParams({ | |||
}) | |||
@RequestMapping(value = "/find/all", method = RequestMethod.GET) | |||
JsonResponse<List<CompanyAdmin>> all(CompanyAdminPageRequest request) { | |||
List<CompanyAdmin> result = companyAdminService.all(request); | |||
return JsonResponse.success(result); | |||
} | |||
} |
@@ -0,0 +1,54 @@ | |||
package com.chilunyc.fumao.api.company; | |||
import com.chilunyc.fumao.common.request.ChangePwdRequest; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import com.chilunyc.fumao.common.sms.model.SmsType; | |||
import com.chilunyc.fumao.common.sms.request.SmsSendRequest; | |||
import com.chilunyc.fumao.common.sms.service.SmsService; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiImplicitParam; | |||
import io.swagger.annotations.ApiImplicitParams; | |||
import io.swagger.annotations.ApiOperation; | |||
import lombok.extern.log4j.Log4j; | |||
import org.apache.commons.lang3.RandomStringUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.RequestBody; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RequestMethod; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import javax.validation.Valid; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@Api(description = "找回密码") | |||
@RestController | |||
@RequestMapping("/company/find/pwd") | |||
class FindPwdController { | |||
@Autowired | |||
SmsService smsService; | |||
@ApiOperation(value = "改密码") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "ChangePwdRequest") | |||
}) | |||
@RequestMapping(value = "/", method = RequestMethod.POST) | |||
JsonResponse login(@RequestBody @Valid ChangePwdRequest request) { | |||
return JsonResponse.success(); | |||
} | |||
@ApiOperation(value = "改密码发短信") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "SmsSendRequest") | |||
}) | |||
@RequestMapping(value = "/send", method = RequestMethod.POST) | |||
JsonResponse login(@RequestBody @Valid SmsSendRequest request) { | |||
request.setContent(RandomStringUtils.randomNumeric(4)); | |||
request.setType(SmsType.CustomerFindPwd); | |||
smsService.send(request); | |||
return JsonResponse.success(); | |||
} | |||
} |
@@ -0,0 +1,54 @@ | |||
package com.chilunyc.fumao.api.company; | |||
import com.chilunyc.fumao.common.request.LoginRequest; | |||
import com.chilunyc.fumao.common.request.LoginRequestWithCaptcha; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import com.chilunyc.fumao.common.util.jwt.JwtUtils; | |||
import com.chilunyc.fumao.company.model.CompanyAdmin; | |||
import com.chilunyc.fumao.company.service.CompanyAdminService; | |||
import com.chilunyc.fumao.company.service.CompanyService; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiImplicitParam; | |||
import io.swagger.annotations.ApiImplicitParams; | |||
import io.swagger.annotations.ApiOperation; | |||
import lombok.extern.log4j.Log4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.RequestBody; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RequestMethod; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import javax.validation.Valid; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@Api(description = "登录登出") | |||
@RestController | |||
@RequestMapping("/company") | |||
class LoginLogoutController { | |||
@Autowired | |||
CompanyAdminService companyAdminService; | |||
@ApiOperation(value = "登录") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "LoginRequest") | |||
}) | |||
@RequestMapping(value = "/login", method = RequestMethod.POST) | |||
JsonResponse login(@RequestBody @Valid LoginRequest request) { | |||
CompanyAdmin companyAdmin = companyAdminService.login(request); | |||
return JsonResponse.success( | |||
JwtUtils.encode(JwtUtils.T.Company, companyAdmin) | |||
); | |||
} | |||
@ApiOperation(value = "登出") | |||
@ApiImplicitParams({ | |||
}) | |||
@RequestMapping(value = "/logout", method = RequestMethod.GET) | |||
JsonResponse logout() { | |||
return JsonResponse.success(); | |||
} | |||
} |
@@ -0,0 +1,91 @@ | |||
package com.chilunyc.fumao.api.company; | |||
import com.chilunyc.fumao.common.request.IdsRequest; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import com.chilunyc.fumao.common.shiro.AuthRoles; | |||
import com.chilunyc.fumao.company.model.CompanyAdmin; | |||
import com.chilunyc.fumao.company.model.PlaceAdmin; | |||
import com.chilunyc.fumao.company.model.enums.PlaceAdminType; | |||
import com.chilunyc.fumao.company.request.placeAdmin.PlaceAdminEditRequest; | |||
import com.chilunyc.fumao.company.request.placeAdmin.PlaceAdminPageRequest; | |||
import com.chilunyc.fumao.company.service.PlaceAdminService; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiImplicitParam; | |||
import io.swagger.annotations.ApiImplicitParams; | |||
import io.swagger.annotations.ApiOperation; | |||
import lombok.extern.log4j.Log4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.data.domain.Page; | |||
import org.springframework.security.access.prepost.PreAuthorize; | |||
import org.springframework.web.bind.annotation.*; | |||
import javax.validation.Valid; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@Api(description = "商场管理员") | |||
@RestController | |||
@RequestMapping("/company/place/admin") | |||
@PreAuthorize(AuthRoles.CompanyAdminExp) | |||
class PlaceAdminController { | |||
@Autowired | |||
PlaceAdminService placeAdminService; | |||
@ApiOperation(value = "分页") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "PageRequest") | |||
}) | |||
@RequestMapping(value = "/find", method = RequestMethod.POST) | |||
JsonResponse<Page<PlaceAdmin>> page(CompanyAdmin companyAdmin, @RequestBody PlaceAdminPageRequest request) { | |||
request.setCompanyId(companyAdmin.getCompanyId()); | |||
Page<PlaceAdmin> page = placeAdminService.page(request); | |||
return JsonResponse.success(page); | |||
} | |||
@ApiOperation(value = "详情") | |||
@ApiImplicitParams({ | |||
}) | |||
@RequestMapping(value = "/find/{id}", method = RequestMethod.GET) | |||
JsonResponse<PlaceAdmin> info(@PathVariable Long id) { | |||
PlaceAdmin placeAdminResponse = placeAdminService.find(id); | |||
return JsonResponse.success(placeAdminResponse); | |||
} | |||
@ApiOperation(value = "新增 | 编辑") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "PlaceAdmin") | |||
}) | |||
@RequestMapping(value = "/edit", method = RequestMethod.POST) | |||
JsonResponse edit(CompanyAdmin companyAdmin, @RequestBody @Valid PlaceAdminEditRequest request) { | |||
request.setPlaceAdminType(PlaceAdminType.Manager); | |||
request.setCompanyId(companyAdmin.getCompanyId()); | |||
placeAdminService.edit(request); | |||
return JsonResponse.success(); | |||
} | |||
@ApiOperation(value = "删除") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "IdRequest") | |||
}) | |||
@RequestMapping(value = "/delete", method = RequestMethod.POST) | |||
JsonResponse remove(@RequestBody @Valid IdsRequest<Long> request) { | |||
placeAdminService.remove(request); | |||
return JsonResponse.success(); | |||
} | |||
@ApiOperation(value = "重置密码") | |||
@ApiImplicitParams({ | |||
}) | |||
@RequestMapping(value = "/reset/password/{id}", method = RequestMethod.GET) | |||
JsonResponse resetPassword(CompanyAdmin companyAdmin, @PathVariable Long id) { | |||
placeAdminService.resetPassword(id, companyAdmin.getCompanyId()); | |||
log.info(String.format("商场管理员[ %s ]重置密码 => [ %s ]", companyAdmin.getId(), id)); | |||
return JsonResponse.success(); | |||
} | |||
} |
@@ -0,0 +1,87 @@ | |||
package com.chilunyc.fumao.api.company; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import com.chilunyc.fumao.common.shiro.AuthRoles; | |||
import com.chilunyc.fumao.company.model.Company; | |||
import com.chilunyc.fumao.company.model.CompanyAdmin; | |||
import com.chilunyc.fumao.company.model.Place; | |||
import com.chilunyc.fumao.company.request.place.PlacePageRequest; | |||
import com.chilunyc.fumao.company.service.PlaceService; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiImplicitParam; | |||
import io.swagger.annotations.ApiImplicitParams; | |||
import io.swagger.annotations.ApiOperation; | |||
import lombok.extern.log4j.Log4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.data.domain.Page; | |||
import org.springframework.security.access.prepost.PreAuthorize; | |||
import org.springframework.web.bind.annotation.*; | |||
import java.util.List; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@Api(description = "商场") | |||
@RestController | |||
@RequestMapping("/company/place") | |||
@PreAuthorize(AuthRoles.CompanyAdminExp) | |||
class PlaceController { | |||
@Autowired | |||
PlaceService placeService; | |||
@ApiOperation(value = "分页") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "PageRequest") | |||
}) | |||
@RequestMapping(value = "/find", method = RequestMethod.POST) | |||
JsonResponse<Page<Place>> page(CompanyAdmin companyAdmin, @RequestBody PlacePageRequest request) { | |||
request.setCompanyId(companyAdmin.getCompanyId()); | |||
Page<Place> page = placeService.page(request); | |||
return JsonResponse.success(page); | |||
} | |||
@ApiOperation(value = "详情") | |||
@ApiImplicitParams({ | |||
}) | |||
@RequestMapping(value = "/find/{id}", method = RequestMethod.GET) | |||
JsonResponse<Place> info(@PathVariable Long id) { | |||
Place placeResponse = placeService.find(id); | |||
return JsonResponse.success(placeResponse); | |||
} | |||
// @ApiOperation(value = "新增 | 编辑") | |||
// @ApiImplicitParams({ | |||
// @ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "Place") | |||
// }) | |||
// @RequestMapping(value = "/edit", method = RequestMethod.POST) | |||
// JsonResponse edit(@RequestBody @Valid PlaceEditRequest request) { | |||
// marketService.edit(request); | |||
// return JsonResponse.success(); | |||
// } | |||
// | |||
// @ApiOperation(value = "删除") | |||
// @ApiImplicitParams({ | |||
// @ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "IdRequest") | |||
// }) | |||
// @RequestMapping(value = "/delete", method = RequestMethod.POST) | |||
// JsonResponse remove(@RequestBody @Valid IdsRequest request) { | |||
// marketService.remove(request); | |||
// return JsonResponse.success(); | |||
// } | |||
@ApiOperation(value = "所有") | |||
@ApiImplicitParams({ | |||
}) | |||
@RequestMapping(value = "/find/all", method = RequestMethod.GET) | |||
JsonResponse<List<Place>> all(CompanyAdmin companyAdmin, PlacePageRequest request) { | |||
request.setCompanyId(companyAdmin.getCompanyId()); | |||
List<Place> result = placeService.all(request); | |||
return JsonResponse.success(result); | |||
} | |||
} |
@@ -0,0 +1,44 @@ | |||
package com.chilunyc.fumao.api.company; | |||
import com.chilunyc.fumao.common.request.IdsRequest; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import com.chilunyc.fumao.company.model.ShopApply; | |||
import com.chilunyc.fumao.company.request.shopApply.ShopApplyEditRequest; | |||
import com.chilunyc.fumao.company.request.shopApply.ShopApplyPageRequest; | |||
import com.chilunyc.fumao.company.service.ShopApplyService; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiImplicitParam; | |||
import io.swagger.annotations.ApiImplicitParams; | |||
import io.swagger.annotations.ApiOperation; | |||
import lombok.extern.log4j.Log4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.data.domain.Page; | |||
import org.springframework.web.bind.annotation.*; | |||
import javax.validation.Valid; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@Api(description = "商铺申请") | |||
@RestController | |||
@RequestMapping("/company/shop/apply") | |||
class ShopApplyController { | |||
@Autowired | |||
ShopApplyService shopApplyService; | |||
@ApiOperation(value = "新增 | 编辑") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "ShopApply") | |||
}) | |||
@RequestMapping(value = "/edit", method = RequestMethod.POST) | |||
JsonResponse edit(@RequestBody @Valid ShopApplyEditRequest request) { | |||
shopApplyService.edit(request); | |||
return JsonResponse.success(); | |||
} | |||
} |
@@ -0,0 +1,81 @@ | |||
package com.chilunyc.fumao.api.customer; | |||
import io.swagger.annotations.Api; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
/** | |||
* 80347471@qq.com | |||
*/ | |||
@Api("小程序接口") | |||
@RestController | |||
@RequestMapping("/customer/wx/ma") | |||
public class WxMaController { | |||
// @Autowired | |||
// WxMaService wxMaService; | |||
// | |||
// @Autowired | |||
// StringRedisTemplate redisTemplate; | |||
// | |||
// /** | |||
// * 转换code | |||
// */ | |||
// @RequestMapping(value = "/code", method = RequestMethod.GET) | |||
// public JsonResponse code(String code) throws WxErrorException { | |||
// if (StringUtils.isBlank(code)) { | |||
// return JsonResponse.fail("参数错误"); | |||
// } | |||
// WxMaJscode2SessionResult session = this.wxMaService.getUserService().getSessionInfo(code); | |||
// redisTemplate.boundValueOps(String.format("%s_session", session.getOpenid())).set(session.getSessionKey()); | |||
// return JsonResponse.success( | |||
// MapBuilder | |||
// .builder() | |||
// .put("openId", session.getOpenid()) | |||
// .getMap() | |||
// ); | |||
// } | |||
// | |||
// /** | |||
// * 转换info | |||
// */ | |||
// @RequestMapping(value = "/info", method = RequestMethod.POST) | |||
// public JsonResponse info(@RequestBody @Valid WxMaUserInfoRequest request) throws WxErrorException { | |||
// String sessionKey = redisTemplate.boundValueOps(String.format("%s_session", request.getOpenId())).get(); | |||
// if (StringUtils.isBlank(sessionKey)) { | |||
// throw new SystemException("000008"); | |||
// } | |||
// | |||
// | |||
// // 用户信息校验 | |||
// if (!this.wxMaService.getUserService().checkUserInfo(sessionKey, request.getRawData(), request.getSignature())) { | |||
// return JsonResponse.fail("校验失败"); | |||
// } | |||
// | |||
// // 解密用户信息 | |||
// WxMaUserInfo userInfo = this.wxMaService.getUserService().getUserInfo(sessionKey, request.getEncryptedData(), request.getIv()); | |||
// | |||
// return JsonResponse.success(); | |||
// } | |||
// | |||
// /** | |||
// * 转换number | |||
// */ | |||
// @RequestMapping(value = "/number", method = RequestMethod.POST) | |||
// public JsonResponse number(@RequestBody @Valid WxMaUserInfoRequest request) throws WxErrorException { | |||
// String sessionKey = redisTemplate.boundValueOps(String.format("%s_session", request.getOpenId())).get(); | |||
// if (StringUtils.isBlank(sessionKey)) { | |||
// throw new SystemException("000008"); | |||
// } | |||
// | |||
// // 用户信息校验 | |||
// if (!this.wxMaService.getUserService().checkUserInfo(sessionKey, request.getRawData(), request.getSignature())) { | |||
// return JsonResponse.fail("校验失败"); | |||
// } | |||
// | |||
// // 解密用户信息 | |||
// WxMaPhoneNumberInfo phoneNoInfo = this.wxMaService.getUserService().getPhoneNoInfo(sessionKey, request.getEncryptedData(), request.getIv()); | |||
// return JsonResponse.success(); | |||
// } | |||
} |
@@ -0,0 +1,49 @@ | |||
package com.chilunyc.fumao.api.market; | |||
import com.chilunyc.fumao.common.request.LoginRequest; | |||
import com.chilunyc.fumao.common.request.LoginRequestWithCaptcha; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import com.chilunyc.fumao.company.service.PlaceAdminService; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiImplicitParam; | |||
import io.swagger.annotations.ApiImplicitParams; | |||
import io.swagger.annotations.ApiOperation; | |||
import lombok.extern.log4j.Log4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.RequestBody; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RequestMethod; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import javax.validation.Valid; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@Api(description = "登录登出") | |||
@RestController | |||
@RequestMapping("/place") | |||
class LoginLogoutController { | |||
@Autowired | |||
PlaceAdminService placeAdminService; | |||
@ApiOperation(value = "登录") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "LoginRequest") | |||
}) | |||
@RequestMapping(value = "/login", method = RequestMethod.POST) | |||
JsonResponse login(@RequestBody @Valid LoginRequest request) { | |||
placeAdminService.login(request); | |||
return null; | |||
} | |||
@ApiOperation(value = "登出") | |||
@ApiImplicitParams({ | |||
}) | |||
@RequestMapping(value = "/logout", method = RequestMethod.GET) | |||
JsonResponse logout() { | |||
return JsonResponse.success(); | |||
} | |||
} |
@@ -0,0 +1,81 @@ | |||
package com.chilunyc.fumao.api.merchant; | |||
import io.swagger.annotations.Api; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
/** | |||
* 80347471@qq.com | |||
*/ | |||
@Api("小程序接口") | |||
@RestController | |||
@RequestMapping("/merchant/wx/ma") | |||
public class WxMaController { | |||
// @Autowired | |||
// WxMaService wxMaService; | |||
// | |||
// @Autowired | |||
// StringRedisTemplate redisTemplate; | |||
// | |||
// /** | |||
// * 转换code | |||
// */ | |||
// @RequestMapping(value = "/code", method = RequestMethod.GET) | |||
// public JsonResponse code(String code) throws WxErrorException { | |||
// if (StringUtils.isBlank(code)) { | |||
// return JsonResponse.fail("参数错误"); | |||
// } | |||
// WxMaJscode2SessionResult session = this.wxMaService.getUserService().getSessionInfo(code); | |||
// redisTemplate.boundValueOps(String.format("%s_session", session.getOpenid())).set(session.getSessionKey()); | |||
// return JsonResponse.success( | |||
// MapBuilder | |||
// .builder() | |||
// .put("openId", session.getOpenid()) | |||
// .getMap() | |||
// ); | |||
// } | |||
// | |||
// /** | |||
// * 转换info | |||
// */ | |||
// @RequestMapping(value = "/info", method = RequestMethod.POST) | |||
// public JsonResponse info(@RequestBody @Valid WxMaUserInfoRequest request) throws WxErrorException { | |||
// String sessionKey = redisTemplate.boundValueOps(String.format("%s_session", request.getOpenId())).get(); | |||
// if (StringUtils.isBlank(sessionKey)) { | |||
// throw new SystemException("000008"); | |||
// } | |||
// | |||
// | |||
// // 用户信息校验 | |||
// if (!this.wxMaService.getUserService().checkUserInfo(sessionKey, request.getRawData(), request.getSignature())) { | |||
// return JsonResponse.fail("校验失败"); | |||
// } | |||
// | |||
// // 解密用户信息 | |||
// WxMaUserInfo userInfo = this.wxMaService.getUserService().getUserInfo(sessionKey, request.getEncryptedData(), request.getIv()); | |||
// | |||
// return JsonResponse.success(); | |||
// } | |||
// | |||
// /** | |||
// * 转换number | |||
// */ | |||
// @RequestMapping(value = "/number", method = RequestMethod.POST) | |||
// public JsonResponse number(@RequestBody @Valid WxMaUserInfoRequest request) throws WxErrorException { | |||
// String sessionKey = redisTemplate.boundValueOps(String.format("%s_session", request.getOpenId())).get(); | |||
// if (StringUtils.isBlank(sessionKey)) { | |||
// throw new SystemException("000008"); | |||
// } | |||
// | |||
// // 用户信息校验 | |||
// if (!this.wxMaService.getUserService().checkUserInfo(sessionKey, request.getRawData(), request.getSignature())) { | |||
// return JsonResponse.fail("校验失败"); | |||
// } | |||
// | |||
// // 解密用户信息 | |||
// WxMaPhoneNumberInfo phoneNoInfo = this.wxMaService.getUserService().getPhoneNoInfo(sessionKey, request.getEncryptedData(), request.getIv()); | |||
// return JsonResponse.success(); | |||
// } | |||
} |
@@ -0,0 +1,86 @@ | |||
package com.chilunyc.fumao.api.system; | |||
import com.chilunyc.fumao.common.request.IdsRequest; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import com.chilunyc.fumao.common.shiro.AuthRoles; | |||
import com.chilunyc.fumao.company.model.CompanyAdmin; | |||
import com.chilunyc.fumao.company.request.companyAdmin.CompanyAdminEditRequest; | |||
import com.chilunyc.fumao.company.request.companyAdmin.CompanyAdminPageRequest; | |||
import com.chilunyc.fumao.company.service.CompanyAdminService; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiImplicitParam; | |||
import io.swagger.annotations.ApiImplicitParams; | |||
import io.swagger.annotations.ApiOperation; | |||
import lombok.extern.log4j.Log4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.data.domain.Page; | |||
import org.springframework.security.access.prepost.PreAuthorize; | |||
import org.springframework.web.bind.annotation.*; | |||
import javax.validation.Valid; | |||
import java.util.List; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@Api(description = "集团管理员") | |||
@RestController | |||
@RequestMapping("/system/company/admin") | |||
@PreAuthorize(AuthRoles.SystemAdminExp) | |||
class CompanyAdminController { | |||
@Autowired | |||
CompanyAdminService companyAdminService; | |||
@ApiOperation(value = "分页") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "PageRequest") | |||
}) | |||
@RequestMapping(value = "/find", method = RequestMethod.POST) | |||
JsonResponse<Page<CompanyAdmin>> page(@RequestBody CompanyAdminPageRequest request) { | |||
Page<CompanyAdmin> page = companyAdminService.page(request); | |||
return JsonResponse.success(page); | |||
} | |||
@ApiOperation(value = "详情") | |||
@ApiImplicitParams({ | |||
}) | |||
@RequestMapping(value = "/find/{id}", method = RequestMethod.GET) | |||
JsonResponse<CompanyAdmin> info(@PathVariable Long id) { | |||
CompanyAdmin companyAdminResponse = companyAdminService.find(id); | |||
return JsonResponse.success(companyAdminResponse); | |||
} | |||
@ApiOperation(value = "新增 | 编辑") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "CompanyAdmin") | |||
}) | |||
@RequestMapping(value = "/edit", method = RequestMethod.POST) | |||
JsonResponse edit(@RequestBody @Valid CompanyAdminEditRequest request) { | |||
companyAdminService.edit(request); | |||
return JsonResponse.success(); | |||
} | |||
@ApiOperation(value = "删除") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "IdRequest") | |||
}) | |||
@RequestMapping(value = "/delete", method = RequestMethod.POST) | |||
JsonResponse remove(@RequestBody @Valid IdsRequest<Long> request) { | |||
companyAdminService.remove(request); | |||
return JsonResponse.success(); | |||
} | |||
@ApiOperation(value = "所有") | |||
@ApiImplicitParams({ | |||
}) | |||
@RequestMapping(value = "/find/all", method = RequestMethod.GET) | |||
JsonResponse<List<CompanyAdmin>> all(CompanyAdminPageRequest request) { | |||
List<CompanyAdmin> result = companyAdminService.all(request); | |||
return JsonResponse.success(result); | |||
} | |||
} |
@@ -0,0 +1,86 @@ | |||
package com.chilunyc.fumao.api.system; | |||
import com.chilunyc.fumao.common.request.IdsRequest; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import com.chilunyc.fumao.common.shiro.AuthRoles; | |||
import com.chilunyc.fumao.company.model.Company; | |||
import com.chilunyc.fumao.company.request.company.CompanyEditRequest; | |||
import com.chilunyc.fumao.company.request.company.CompanyPageRequest; | |||
import com.chilunyc.fumao.company.service.CompanyService; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiImplicitParam; | |||
import io.swagger.annotations.ApiImplicitParams; | |||
import io.swagger.annotations.ApiOperation; | |||
import lombok.extern.log4j.Log4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.data.domain.Page; | |||
import org.springframework.security.access.prepost.PreAuthorize; | |||
import org.springframework.web.bind.annotation.*; | |||
import javax.validation.Valid; | |||
import java.util.List; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@Api(description = "集团") | |||
@RestController | |||
@RequestMapping("/system/company") | |||
@PreAuthorize(AuthRoles.SystemAdminExp) | |||
class CompanyController { | |||
@Autowired | |||
CompanyService companyService; | |||
@ApiOperation(value = "分页") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "PageRequest") | |||
}) | |||
@RequestMapping(value = "/find", method = RequestMethod.POST) | |||
JsonResponse<Page<Company>> page(@RequestBody CompanyPageRequest request) { | |||
Page<Company> page = companyService.page(request); | |||
return JsonResponse.success(page); | |||
} | |||
@ApiOperation(value = "详情") | |||
@ApiImplicitParams({ | |||
}) | |||
@RequestMapping(value = "/find/{id}", method = RequestMethod.GET) | |||
JsonResponse<Company> info(@PathVariable Long id) { | |||
Company companyResponse = companyService.find(id); | |||
return JsonResponse.success(companyResponse); | |||
} | |||
@ApiOperation(value = "新增 | 编辑") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "Company") | |||
}) | |||
@RequestMapping(value = "/edit", method = RequestMethod.POST) | |||
JsonResponse edit(@RequestBody @Valid CompanyEditRequest request) { | |||
Company edit = companyService.edit(request); | |||
return JsonResponse.success(edit); | |||
} | |||
@ApiOperation(value = "删除") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "IdRequest") | |||
}) | |||
@RequestMapping(value = "/delete", method = RequestMethod.POST) | |||
JsonResponse remove(@RequestBody @Valid IdsRequest<Long> request) { | |||
companyService.remove(request); | |||
return JsonResponse.success(); | |||
} | |||
@ApiOperation(value = "所有") | |||
@ApiImplicitParams({ | |||
}) | |||
@RequestMapping(value = "/find/all", method = RequestMethod.GET) | |||
JsonResponse<List<Company>> all(CompanyPageRequest request) { | |||
List<Company> result = companyService.all(request); | |||
return JsonResponse.success(result); | |||
} | |||
} |
@@ -0,0 +1,54 @@ | |||
package com.chilunyc.fumao.api.system; | |||
import com.chilunyc.fumao.common.request.ChangePwdRequest; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import com.chilunyc.fumao.common.sms.model.SmsType; | |||
import com.chilunyc.fumao.common.sms.request.SmsSendRequest; | |||
import com.chilunyc.fumao.common.sms.service.SmsService; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiImplicitParam; | |||
import io.swagger.annotations.ApiImplicitParams; | |||
import io.swagger.annotations.ApiOperation; | |||
import lombok.extern.log4j.Log4j; | |||
import org.apache.commons.lang3.RandomStringUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.RequestBody; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RequestMethod; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import javax.validation.Valid; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@Api(description = "找回密码") | |||
@RestController | |||
@RequestMapping("/system/find/pwd") | |||
class FindPwdController { | |||
@Autowired | |||
SmsService smsService; | |||
@ApiOperation(value = "改密码") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "ChangePwdRequest") | |||
}) | |||
@RequestMapping(value = "/", method = RequestMethod.POST) | |||
JsonResponse login(@RequestBody @Valid ChangePwdRequest request) { | |||
return JsonResponse.success(); | |||
} | |||
@ApiOperation(value = "改密码发短信") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "SmsSendRequest") | |||
}) | |||
@RequestMapping(value = "/send", method = RequestMethod.POST) | |||
JsonResponse login(@RequestBody @Valid SmsSendRequest request) { | |||
request.setContent(RandomStringUtils.randomNumeric(4)); | |||
request.setType(SmsType.CustomerFindPwd); | |||
smsService.send(request); | |||
return JsonResponse.success(); | |||
} | |||
} |
@@ -0,0 +1,42 @@ | |||
package com.chilunyc.fumao.api.system; | |||
import com.chilunyc.fumao.common.lbs.request.LBSPoiRequest; | |||
import com.chilunyc.fumao.common.lbs.service.LBSService; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import com.chilunyc.fumao.common.shiro.AuthRoles; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiImplicitParam; | |||
import io.swagger.annotations.ApiImplicitParams; | |||
import io.swagger.annotations.ApiOperation; | |||
import lombok.extern.log4j.Log4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.security.access.prepost.PreAuthorize; | |||
import org.springframework.web.bind.annotation.RequestBody; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RequestMethod; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import javax.validation.Valid; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@Api(description = "登录登出") | |||
@RestController | |||
@RequestMapping("/system/lbs") | |||
@PreAuthorize(AuthRoles.SystemAdminExp) | |||
class LBSController { | |||
@Autowired | |||
LBSService lbsService; | |||
@ApiOperation(value = "登录") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "LoginRequest") | |||
}) | |||
@RequestMapping(value = "/poi/find", method = RequestMethod.POST) | |||
JsonResponse login(@RequestBody @Valid LBSPoiRequest request) { | |||
return JsonResponse.success(lbsService.findPoi(request)); | |||
} | |||
} |
@@ -0,0 +1,52 @@ | |||
package com.chilunyc.fumao.api.system; | |||
import com.chilunyc.fumao.common.request.LoginRequest; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import com.chilunyc.fumao.common.util.jwt.JwtUtils; | |||
import com.chilunyc.fumao.system.model.SystemAdmin; | |||
import com.chilunyc.fumao.system.service.SystemAdminService; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiImplicitParam; | |||
import io.swagger.annotations.ApiImplicitParams; | |||
import io.swagger.annotations.ApiOperation; | |||
import lombok.extern.log4j.Log4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.RequestBody; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RequestMethod; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import javax.validation.Valid; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@Api(description = "登录登出") | |||
@RestController | |||
@RequestMapping("/system") | |||
class LoginLogoutController { | |||
@Autowired | |||
SystemAdminService systemAdminService; | |||
@ApiOperation(value = "登录") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "LoginRequest") | |||
}) | |||
@RequestMapping(value = "/login", method = RequestMethod.POST) | |||
JsonResponse login(@RequestBody @Valid LoginRequest request) { | |||
SystemAdmin systemAdmin = systemAdminService.login(request); | |||
return JsonResponse.success( | |||
JwtUtils.encode(JwtUtils.T.System, systemAdmin) | |||
); | |||
} | |||
@ApiOperation(value = "登出") | |||
@ApiImplicitParams({ | |||
}) | |||
@RequestMapping(value = "/logout", method = RequestMethod.GET) | |||
JsonResponse logout() { | |||
return JsonResponse.success(); | |||
} | |||
} |
@@ -0,0 +1,79 @@ | |||
package com.chilunyc.fumao.api.system; | |||
import com.chilunyc.fumao.common.request.IdsRequest; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import com.chilunyc.fumao.common.shiro.AuthRoles; | |||
import com.chilunyc.fumao.company.model.PlaceAdmin; | |||
import com.chilunyc.fumao.company.model.enums.PlaceAdminType; | |||
import com.chilunyc.fumao.company.request.placeAdmin.PlaceAdminEditRequest; | |||
import com.chilunyc.fumao.company.request.placeAdmin.PlaceAdminPageRequest; | |||
import com.chilunyc.fumao.company.service.PlaceAdminService; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiImplicitParam; | |||
import io.swagger.annotations.ApiImplicitParams; | |||
import io.swagger.annotations.ApiOperation; | |||
import lombok.extern.log4j.Log4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.data.domain.Page; | |||
import org.springframework.security.access.prepost.PreAuthorize; | |||
import org.springframework.web.bind.annotation.*; | |||
import javax.validation.Valid; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@Api(description = "商场管理员") | |||
@RestController | |||
@RequestMapping("/system/place/admin") | |||
@PreAuthorize(AuthRoles.SystemAdminExp) | |||
class PlaceAdminController { | |||
@Autowired | |||
PlaceAdminService placeAdminService; | |||
@ApiOperation(value = "分页") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "PageRequest") | |||
}) | |||
@RequestMapping(value = "/find", method = RequestMethod.POST) | |||
JsonResponse<Page<PlaceAdmin>> page(@RequestBody PlaceAdminPageRequest request) { | |||
Page<PlaceAdmin> page = placeAdminService.page(request); | |||
return JsonResponse.success(page); | |||
} | |||
@ApiOperation(value = "详情") | |||
@ApiImplicitParams({ | |||
}) | |||
@RequestMapping(value = "/find/{id}", method = RequestMethod.GET) | |||
JsonResponse<PlaceAdmin> info(@PathVariable Long id) { | |||
PlaceAdmin placeAdminResponse = placeAdminService.find(id); | |||
return JsonResponse.success(placeAdminResponse); | |||
} | |||
@ApiOperation(value = "新增 | 编辑") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "PlaceAdmin") | |||
}) | |||
@RequestMapping(value = "/edit", method = RequestMethod.POST) | |||
JsonResponse edit(@RequestBody @Valid PlaceAdminEditRequest request) { | |||
request.setPlaceAdminType(PlaceAdminType.Manager); | |||
placeAdminService.edit(request); | |||
return JsonResponse.success(); | |||
} | |||
@ApiOperation(value = "删除") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "IdRequest") | |||
}) | |||
@RequestMapping(value = "/delete", method = RequestMethod.POST) | |||
JsonResponse remove(@RequestBody @Valid IdsRequest<Long> request) { | |||
placeAdminService.remove(request); | |||
return JsonResponse.success(); | |||
} | |||
} |
@@ -0,0 +1,86 @@ | |||
package com.chilunyc.fumao.api.system; | |||
import com.chilunyc.fumao.common.request.IdsRequest; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import com.chilunyc.fumao.common.shiro.AuthRoles; | |||
import com.chilunyc.fumao.company.model.Place; | |||
import com.chilunyc.fumao.company.request.place.PlaceEditRequest; | |||
import com.chilunyc.fumao.company.request.place.PlacePageRequest; | |||
import com.chilunyc.fumao.company.service.PlaceService; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiImplicitParam; | |||
import io.swagger.annotations.ApiImplicitParams; | |||
import io.swagger.annotations.ApiOperation; | |||
import lombok.extern.log4j.Log4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.data.domain.Page; | |||
import org.springframework.security.access.prepost.PreAuthorize; | |||
import org.springframework.web.bind.annotation.*; | |||
import javax.validation.Valid; | |||
import java.util.List; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@Api(description = "商场") | |||
@RestController | |||
@RequestMapping("/system/place") | |||
@PreAuthorize(AuthRoles.SystemAdminExp) | |||
class PlaceController { | |||
@Autowired | |||
PlaceService placeService; | |||
@ApiOperation(value = "分页") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "PageRequest") | |||
}) | |||
@RequestMapping(value = "/find", method = RequestMethod.POST) | |||
JsonResponse<Page<Place>> page(@RequestBody PlacePageRequest request) { | |||
Page<Place> page = placeService.page(request); | |||
return JsonResponse.success(page); | |||
} | |||
@ApiOperation(value = "详情") | |||
@ApiImplicitParams({ | |||
}) | |||
@RequestMapping(value = "/find/{id}", method = RequestMethod.GET) | |||
JsonResponse<Place> info(@PathVariable Long id) { | |||
Place placeResponse = placeService.find(id); | |||
return JsonResponse.success(placeResponse); | |||
} | |||
@ApiOperation(value = "新增 | 编辑") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "Place") | |||
}) | |||
@RequestMapping(value = "/edit", method = RequestMethod.POST) | |||
JsonResponse edit(@RequestBody @Valid PlaceEditRequest request) { | |||
Place edit = placeService.edit(request); | |||
return JsonResponse.success(edit); | |||
} | |||
@ApiOperation(value = "删除") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "IdRequest") | |||
}) | |||
@RequestMapping(value = "/delete", method = RequestMethod.POST) | |||
JsonResponse remove(@RequestBody @Valid IdsRequest<Long> request) { | |||
placeService.remove(request); | |||
return JsonResponse.success(); | |||
} | |||
@ApiOperation(value = "所有") | |||
@ApiImplicitParams({ | |||
}) | |||
@RequestMapping(value = "/find/all", method = RequestMethod.POST) | |||
JsonResponse<List<Place>> all(@RequestBody PlacePageRequest request) { | |||
List<Place> result = placeService.all(request); | |||
return JsonResponse.success(result); | |||
} | |||
} |
@@ -0,0 +1,78 @@ | |||
package com.chilunyc.fumao.api.system; | |||
import com.chilunyc.fumao.common.request.IdsRequest; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import com.chilunyc.fumao.common.shiro.AuthRoles; | |||
import com.chilunyc.fumao.company.model.PlaceFloor; | |||
import com.chilunyc.fumao.company.request.placeFloor.PlaceFloorEditRequest; | |||
import com.chilunyc.fumao.company.request.placeFloor.PlaceFloorPageRequest; | |||
import com.chilunyc.fumao.company.service.PlaceFloorService; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiImplicitParam; | |||
import io.swagger.annotations.ApiImplicitParams; | |||
import io.swagger.annotations.ApiOperation; | |||
import lombok.extern.log4j.Log4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.data.domain.Page; | |||
import org.springframework.security.access.prepost.PreAuthorize; | |||
import org.springframework.web.bind.annotation.*; | |||
import javax.validation.Valid; | |||
import java.util.List; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@Api(description = "商场楼层") | |||
@RestController | |||
@RequestMapping("/system/place/floor") | |||
@PreAuthorize(AuthRoles.SystemAdminExp) | |||
class PlaceFloorController { | |||
@Autowired | |||
PlaceFloorService placeFloorService; | |||
@ApiOperation(value = "分页") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "PageRequest") | |||
}) | |||
@RequestMapping(value = "/find/all", method = RequestMethod.POST) | |||
JsonResponse<List<PlaceFloor>> all(@RequestBody PlaceFloorPageRequest request) { | |||
List<PlaceFloor> page = placeFloorService.all(request); | |||
return JsonResponse.success(page); | |||
} | |||
@ApiOperation(value = "详情") | |||
@ApiImplicitParams({ | |||
}) | |||
@RequestMapping(value = "/find/{id}", method = RequestMethod.GET) | |||
JsonResponse<PlaceFloor> info(@PathVariable Long id) { | |||
PlaceFloor placeFloorResponse = placeFloorService.find(id); | |||
return JsonResponse.success(placeFloorResponse); | |||
} | |||
@ApiOperation(value = "新增 | 编辑") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "PlaceFloor") | |||
}) | |||
@RequestMapping(value = "/edit", method = RequestMethod.POST) | |||
JsonResponse edit(@RequestBody @Valid PlaceFloorEditRequest request) { | |||
placeFloorService.edit(request); | |||
return JsonResponse.success(); | |||
} | |||
@ApiOperation(value = "删除") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "IdRequest") | |||
}) | |||
@RequestMapping(value = "/delete", method = RequestMethod.POST) | |||
JsonResponse remove(@RequestBody @Valid IdsRequest request) { | |||
placeFloorService.remove(request); | |||
return JsonResponse.success(); | |||
} | |||
} |
@@ -0,0 +1,65 @@ | |||
package com.chilunyc.fumao.api.system; | |||
import com.chilunyc.fumao.common.request.IdsRequest; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import com.chilunyc.fumao.common.shiro.AuthRoles; | |||
import com.chilunyc.fumao.company.model.ShopApply; | |||
import com.chilunyc.fumao.company.request.shopApply.ShopApplyEditRequest; | |||
import com.chilunyc.fumao.company.request.shopApply.ShopApplyPageRequest; | |||
import com.chilunyc.fumao.company.service.ShopApplyService; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiImplicitParam; | |||
import io.swagger.annotations.ApiImplicitParams; | |||
import io.swagger.annotations.ApiOperation; | |||
import lombok.extern.log4j.Log4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.data.domain.Page; | |||
import org.springframework.security.access.prepost.PreAuthorize; | |||
import org.springframework.web.bind.annotation.*; | |||
import javax.validation.Valid; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@Api(description = "商铺申请") | |||
@RestController | |||
@RequestMapping("/system/shop/apply") | |||
@PreAuthorize(AuthRoles.SystemAdminExp) | |||
class ShopApplyController { | |||
@Autowired | |||
ShopApplyService shopApplyService; | |||
@ApiOperation(value = "分页") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "PageRequest") | |||
}) | |||
@RequestMapping(value = "/find", method = RequestMethod.POST) | |||
JsonResponse<Page<ShopApply>> page(@RequestBody ShopApplyPageRequest request) { | |||
Page<ShopApply> page = shopApplyService.page(request); | |||
return JsonResponse.success(page); | |||
} | |||
@ApiOperation(value = "详情") | |||
@ApiImplicitParams({ | |||
}) | |||
@RequestMapping(value = "/find/{id}", method = RequestMethod.GET) | |||
JsonResponse<ShopApply> info(@PathVariable Long id) { | |||
ShopApply shopApplyResponse = shopApplyService.find(id); | |||
return JsonResponse.success(shopApplyResponse); | |||
} | |||
@ApiOperation(value = "删除") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "IdRequest") | |||
}) | |||
@RequestMapping(value = "/delete", method = RequestMethod.POST) | |||
JsonResponse remove(@RequestBody @Valid IdsRequest request) { | |||
shopApplyService.remove(request); | |||
return JsonResponse.success(); | |||
} | |||
} |
@@ -0,0 +1,77 @@ | |||
package com.chilunyc.fumao.api.system; | |||
import com.chilunyc.fumao.common.request.IdsRequest; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import com.chilunyc.fumao.common.shiro.AuthRoles; | |||
import com.chilunyc.fumao.system.model.SystemAdmin; | |||
import com.chilunyc.fumao.system.request.systemAdmin.SystemAdminEditRequest; | |||
import com.chilunyc.fumao.system.request.systemAdmin.SystemAdminPageRequest; | |||
import com.chilunyc.fumao.system.service.SystemAdminService; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiImplicitParam; | |||
import io.swagger.annotations.ApiImplicitParams; | |||
import io.swagger.annotations.ApiOperation; | |||
import lombok.extern.log4j.Log4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.data.domain.Page; | |||
import org.springframework.security.access.prepost.PreAuthorize; | |||
import org.springframework.web.bind.annotation.*; | |||
import javax.validation.Valid; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@Api(description = "系统管理员") | |||
@RestController | |||
@RequestMapping("/system/admin") | |||
@PreAuthorize(AuthRoles.SystemAdminExp) | |||
class SystemAdminController { | |||
@Autowired | |||
SystemAdminService systemAdminService; | |||
@ApiOperation(value = "分页") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "PageRequest") | |||
}) | |||
@RequestMapping(value = "/find", method = RequestMethod.POST) | |||
JsonResponse<Page<SystemAdmin>> page(@RequestBody SystemAdminPageRequest request) { | |||
Page<SystemAdmin> page = systemAdminService.page(request); | |||
return JsonResponse.success(page); | |||
} | |||
@ApiOperation(value = "详情") | |||
@ApiImplicitParams({ | |||
}) | |||
@RequestMapping(value = "/find/{id}", method = RequestMethod.GET) | |||
JsonResponse<SystemAdmin> info(@PathVariable Long id) { | |||
SystemAdmin systemAdminResponse = systemAdminService.find(id); | |||
return JsonResponse.success(systemAdminResponse); | |||
} | |||
@ApiOperation(value = "新增 | 编辑") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "SystemAdmin") | |||
}) | |||
@RequestMapping(value = "/edit", method = RequestMethod.POST) | |||
JsonResponse edit(@RequestBody @Valid SystemAdminEditRequest request) { | |||
systemAdminService.edit(request); | |||
return JsonResponse.success(); | |||
} | |||
@ApiOperation(value = "删除") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "IdRequest") | |||
}) | |||
@RequestMapping(value = "/delete", method = RequestMethod.POST) | |||
JsonResponse remove(@RequestBody @Valid IdsRequest request) { | |||
systemAdminService.remove(request); | |||
return JsonResponse.success(); | |||
} | |||
} |
@@ -0,0 +1,21 @@ | |||
package com.chilunyc.fumao.config.bean; | |||
import org.apache.commons.lang3.StringUtils; | |||
import org.springframework.beans.factory.config.BeanDefinition; | |||
import org.springframework.beans.factory.support.BeanDefinitionRegistry; | |||
import org.springframework.context.annotation.AnnotationBeanNameGenerator; | |||
/** | |||
* | |||
*/ | |||
public class MultiBeanNameGenerator extends AnnotationBeanNameGenerator { | |||
@Override | |||
public String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry beanDefinitionRegistry) { | |||
String beanClassName = beanDefinition.getBeanClassName(); | |||
if (StringUtils.startsWith(beanClassName, "com.chilunyc") && StringUtils.endsWith(beanClassName, "Controller")) { | |||
return beanClassName; | |||
} | |||
return super.generateBeanName(beanDefinition, beanDefinitionRegistry); | |||
} | |||
} |
@@ -0,0 +1,32 @@ | |||
package com.chilunyc.fumao.config.captcha; | |||
import com.google.code.kaptcha.impl.DefaultKaptcha; | |||
import com.google.code.kaptcha.util.Config; | |||
import org.springframework.context.annotation.Bean; | |||
import org.springframework.context.annotation.Configuration; | |||
import java.util.Properties; | |||
/** | |||
* | |||
*/ | |||
@Configuration | |||
public class CaptchaConfig { | |||
@Bean | |||
public DefaultKaptcha captchaProducer() { | |||
DefaultKaptcha captchaProducer = new DefaultKaptcha(); | |||
Properties properties = new Properties(); | |||
properties.setProperty("kaptcha.border", "yes"); | |||
properties.setProperty("kaptcha.border.color", "105,179,90"); | |||
properties.setProperty("kaptcha.textproducer.font.color", "blue"); | |||
properties.setProperty("kaptcha.image.width", "150"); | |||
properties.setProperty("kaptcha.image.height", "60"); | |||
properties.setProperty("kaptcha.textproducer.font.size", "45"); | |||
properties.setProperty("kaptcha.session.key", "code"); | |||
properties.setProperty("kaptcha.textproducer.char.length", "4"); | |||
Config config = new Config(properties); | |||
captchaProducer.setConfig(config); | |||
return captchaProducer; | |||
} | |||
} |
@@ -0,0 +1,76 @@ | |||
package com.chilunyc.fumao.config.swagger; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import com.fasterxml.classmate.TypeResolver; | |||
import com.google.common.base.Predicate; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | |||
import org.springframework.context.annotation.Bean; | |||
import org.springframework.context.annotation.Configuration; | |||
import org.springframework.http.ResponseEntity; | |||
import springfox.documentation.builders.ApiInfoBuilder; | |||
import springfox.documentation.schema.AlternateTypeRules; | |||
import springfox.documentation.schema.WildcardType; | |||
import springfox.documentation.spi.DocumentationType; | |||
import springfox.documentation.spring.web.plugins.Docket; | |||
import springfox.documentation.swagger2.annotations.EnableSwagger2; | |||
/** | |||
* | |||
*/ | |||
@Configuration | |||
@ConditionalOnProperty(value = "app.test", havingValue = "true") | |||
@EnableSwagger2 | |||
public class SwaggerConfig { | |||
@Autowired | |||
private TypeResolver typeResolver; | |||
@Bean | |||
Docket all() { | |||
return build("所有", "/", "所有接口"); | |||
} | |||
/** | |||
* @param group | |||
* @param path | |||
* @param title | |||
* @return | |||
*/ | |||
Docket build(String group, String path, String title) { | |||
return new Docket(DocumentationType.SWAGGER_2) | |||
.select() | |||
.paths(includePath(path)) | |||
.build() | |||
.groupName(group) | |||
.ignoredParameterTypes( | |||
) | |||
.apiInfo( | |||
new ApiInfoBuilder() | |||
.title(title) | |||
.version("1.0") | |||
.build()) | |||
.genericModelSubstitutes(ResponseEntity.class) | |||
.alternateTypeRules( | |||
AlternateTypeRules.newRule( | |||
typeResolver.resolve(ResponseEntity.class, typeResolver.resolve(JsonResponse.class, WildcardType.class)), | |||
typeResolver.resolve(WildcardType.class) | |||
) | |||
) | |||
.useDefaultResponseMessages(false) | |||
; | |||
} | |||
/** | |||
* @param path | |||
* @return | |||
*/ | |||
Predicate<String> includePath(final String path) { | |||
return new Predicate<String>() { | |||
@Override | |||
public boolean apply(String input) { | |||
return input.startsWith(path); | |||
} | |||
}; | |||
} | |||
} |
@@ -0,0 +1,21 @@ | |||
package com.chilunyc.fumao.config.web; | |||
import com.fasterxml.jackson.core.JsonParser; | |||
import com.fasterxml.jackson.core.JsonToken; | |||
import com.fasterxml.jackson.databind.DeserializationContext; | |||
import com.fasterxml.jackson.databind.JsonDeserializer; | |||
import org.springframework.boot.jackson.JsonComponent; | |||
import java.io.IOException; | |||
/** | |||
* | |||
*/ | |||
@JsonComponent | |||
public class JsonConfig extends JsonDeserializer<String> { | |||
@Override | |||
public String deserialize(JsonParser parser, DeserializationContext context) throws IOException { | |||
return parser.hasToken(JsonToken.VALUE_STRING) ? parser.getText().trim() : null; | |||
} | |||
} |
@@ -0,0 +1,78 @@ | |||
package com.chilunyc.fumao.config.web; | |||
import com.chilunyc.fumao.common.config.ApplicationProperty; | |||
import com.chilunyc.fumao.config.web.arguments.DateArgumentResolver; | |||
import com.chilunyc.fumao.config.web.arguments.LoginUserArgumentResolver; | |||
import com.chilunyc.fumao.config.web.interceptor.AuthInterceptor; | |||
import com.chilunyc.fumao.config.web.interceptor.CorsInterceptor; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.context.annotation.Configuration; | |||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | |||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | |||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | |||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | |||
import java.util.List; | |||
/** | |||
* | |||
*/ | |||
@Configuration | |||
public class WebConfig extends WebMvcConfigurerAdapter { | |||
@Autowired | |||
private AuthInterceptor authInterceptor; | |||
@Autowired | |||
private CorsInterceptor corsInterceptor; | |||
@Autowired | |||
private LoginUserArgumentResolver jwtValueArgumentResolver; | |||
@Autowired | |||
private ApplicationProperty applicationConfig; | |||
/** | |||
* 跨域访问 | |||
* | |||
* @param registry | |||
*/ | |||
@Override | |||
public void addCorsMappings(CorsRegistry registry) { | |||
registry | |||
.addMapping("/**/*") | |||
.allowedOrigins("*") | |||
.allowedMethods("*") | |||
.allowedHeaders("*") | |||
.allowCredentials(true) | |||
; | |||
} | |||
@Override | |||
public void addInterceptors(InterceptorRegistry registry) { | |||
registry.addInterceptor(corsInterceptor); | |||
// registry.addInterceptor(authInterceptor).excludePathPatterns( | |||
// "/**/login", | |||
// "/**/login/**", | |||
// "/**/logout", | |||
// "/upload", | |||
// "/**/register/**", | |||
// "/**/find/pwd/", | |||
// "/**/find/pwd/**", | |||
// "/swagger/**", | |||
// "/swagger-resources/**", | |||
// "/webjars/**", | |||
// "/captcha", | |||
// "/wx/**", | |||
// "/error" | |||
// ); | |||
} | |||
@Override | |||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) { | |||
argumentResolvers.add(jwtValueArgumentResolver); | |||
argumentResolvers.add(new DateArgumentResolver()); | |||
} | |||
} |
@@ -0,0 +1,58 @@ | |||
package com.chilunyc.fumao.config.web; | |||
import com.chilunyc.fumao.config.web.security.SecurityFilter; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.context.annotation.Configuration; | |||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | |||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | |||
import org.springframework.security.config.http.SessionCreationPolicy; | |||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; | |||
/** | |||
* Created by Tkk on 2018/7/23. | |||
*/ | |||
@Configuration | |||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | |||
@Autowired | |||
SecurityFilter securityFilter; | |||
@Override | |||
protected void configure(HttpSecurity http) throws Exception { | |||
http | |||
// 开启跨域 | |||
.cors() | |||
// 取消session | |||
.and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER) | |||
// 关闭csrf | |||
.and().csrf().disable() | |||
.authorizeRequests() | |||
// 放行登录 | |||
.antMatchers( | |||
"/login", | |||
"/login/**", | |||
"/**/login", | |||
"/**/login/**") | |||
.permitAll() | |||
// 放行通用 | |||
.antMatchers( | |||
"/common/**") | |||
.permitAll() | |||
// 其他全部校验 | |||
.anyRequest() | |||
.authenticated() | |||
// 增加过滤器, 过滤权限 | |||
.and() | |||
.addFilterBefore(securityFilter, UsernamePasswordAuthenticationFilter.class); | |||
} | |||
} |
@@ -0,0 +1,38 @@ | |||
package com.chilunyc.fumao.config.web.arguments; | |||
import org.apache.commons.lang3.ClassUtils; | |||
import org.apache.commons.lang3.StringUtils; | |||
import org.apache.commons.lang3.time.DateUtils; | |||
import org.springframework.core.MethodParameter; | |||
import org.springframework.web.bind.support.WebDataBinderFactory; | |||
import org.springframework.web.context.request.NativeWebRequest; | |||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | |||
import org.springframework.web.method.support.ModelAndViewContainer; | |||
import java.util.Date; | |||
/** | |||
* | |||
*/ | |||
public class DateArgumentResolver implements HandlerMethodArgumentResolver { | |||
@Override | |||
public boolean supportsParameter(MethodParameter methodParameter) { | |||
return ClassUtils.isAssignable(methodParameter.getParameterType(), Date.class); | |||
} | |||
@Override | |||
public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, NativeWebRequest nativeWebRequest, WebDataBinderFactory webDataBinderFactory) throws Exception { | |||
String parameterName = methodParameter.getParameterName(); | |||
String value = nativeWebRequest.getParameter(parameterName); | |||
if (StringUtils.isBlank(value) || StringUtils.equalsIgnoreCase("undefined", value)) { | |||
return null; | |||
} else if (value.length() <= 10) { | |||
return DateUtils.parseDate(value, "yyyy-MM-dd"); | |||
} else if (value.length() > 16) { | |||
return DateUtils.parseDate(value, "yyyy-MM-dd HH:mm:ss"); | |||
} else { | |||
return null; | |||
} | |||
} | |||
} |
@@ -0,0 +1,34 @@ | |||
package com.chilunyc.fumao.config.web.arguments; | |||
import com.chilunyc.fumao.common.context.RequestHolder; | |||
import com.chilunyc.fumao.common.exception.SystemException; | |||
import com.chilunyc.fumao.common.context.LoginUser; | |||
import io.jsonwebtoken.Claims; | |||
import org.apache.commons.lang3.ClassUtils; | |||
import org.springframework.core.MethodParameter; | |||
import org.springframework.stereotype.Component; | |||
import org.springframework.web.bind.support.WebDataBinderFactory; | |||
import org.springframework.web.context.request.NativeWebRequest; | |||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | |||
import org.springframework.web.method.support.ModelAndViewContainer; | |||
/** | |||
* | |||
*/ | |||
@Component | |||
public class LoginUserArgumentResolver implements HandlerMethodArgumentResolver { | |||
@Override | |||
public boolean supportsParameter(MethodParameter methodParameter) { | |||
return ClassUtils.isAssignable(methodParameter.getParameterType(), LoginUser.class); | |||
} | |||
@Override | |||
public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, NativeWebRequest nativeWebRequest, WebDataBinderFactory webDataBinderFactory) throws Exception { | |||
LoginUser o = (LoginUser) methodParameter.getParameterType().newInstance(); | |||
Claims jwtValue = RequestHolder.get().getJwtValue(); | |||
o.fromJwt(jwtValue); | |||
return o; | |||
} | |||
} |
@@ -0,0 +1,36 @@ | |||
package com.chilunyc.fumao.config.web.interceptor; | |||
import com.chilunyc.fumao.common.config.ApplicationProperty; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Component; | |||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
/** | |||
* | |||
*/ | |||
@Component | |||
public class AuthInterceptor extends HandlerInterceptorAdapter { | |||
@Autowired | |||
private ApplicationProperty applicationProperty; | |||
/** | |||
* 做权限过滤 | |||
* | |||
* @param servletRequest | |||
* @param response | |||
* @param handler | |||
* @return | |||
* @throws Exception | |||
*/ | |||
@Override | |||
public boolean preHandle(HttpServletRequest servletRequest, HttpServletResponse response, Object handler) throws Exception { | |||
return true; | |||
} | |||
} |
@@ -0,0 +1,54 @@ | |||
package com.chilunyc.fumao.config.web.interceptor; | |||
import com.chilunyc.fumao.common.context.RequestHolder; | |||
import org.springframework.beans.BeansException; | |||
import org.springframework.context.ApplicationContext; | |||
import org.springframework.context.ApplicationContextAware; | |||
import org.springframework.stereotype.Component; | |||
import org.springframework.web.cors.CorsConfiguration; | |||
import org.springframework.web.servlet.handler.AbstractHandlerMapping; | |||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
import java.util.ArrayList; | |||
import java.util.Map; | |||
/** | |||
* | |||
*/ | |||
@Component | |||
public class CorsInterceptor extends HandlerInterceptorAdapter implements ApplicationContextAware { | |||
private AbstractHandlerMapping handlerMapping; | |||
private CorsConfiguration cors; | |||
private ApplicationContext applicationContext; | |||
@Override | |||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | |||
if (handlerMapping == null) { | |||
synchronized (applicationContext) { | |||
if (handlerMapping == null) { | |||
handlerMapping = applicationContext.getBean(AbstractHandlerMapping.class); | |||
Map<String, CorsConfiguration> corsConfigurations = handlerMapping.getCorsConfigurations(); | |||
this.cors = new ArrayList<>(corsConfigurations.values()).get(0); | |||
} | |||
} | |||
} | |||
// | |||
handlerMapping.getCorsProcessor().processRequest(cors, request, response); | |||
return super.preHandle(request, response, handler); | |||
} | |||
@Override | |||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | |||
this.applicationContext = applicationContext; | |||
} | |||
@Override | |||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { | |||
super.afterCompletion(request, response, handler, ex); | |||
RequestHolder.clean(); | |||
} | |||
} |
@@ -0,0 +1,26 @@ | |||
package com.chilunyc.fumao.config.web.security; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import lombok.extern.log4j.Log4j; | |||
import org.springframework.security.core.AuthenticationException; | |||
import org.springframework.security.web.AuthenticationEntryPoint; | |||
import org.springframework.stereotype.Component; | |||
import javax.servlet.ServletException; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
import java.io.IOException; | |||
/** | |||
* Created by Tkk on 2018/7/23. | |||
*/ | |||
@Log4j | |||
@Component | |||
public class SecurityEntryPoint implements AuthenticationEntryPoint { | |||
@Override | |||
public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException { | |||
httpServletResponse.setContentType("application/json"); | |||
httpServletResponse.getWriter().write(JsonResponse.fail("000002", "尚未登录").toString()); | |||
} | |||
} |
@@ -0,0 +1,141 @@ | |||
package com.chilunyc.fumao.config.web.security; | |||
import com.chilunyc.fumao.common.context.Request; | |||
import com.chilunyc.fumao.common.context.RequestHolder; | |||
import com.chilunyc.fumao.common.exception.SystemException; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import com.chilunyc.fumao.common.shiro.AuthUser; | |||
import com.chilunyc.fumao.common.util.jwt.JwtUtils; | |||
import com.chilunyc.fumao.config.web.arguments.LoginUserArgumentResolver; | |||
import io.jsonwebtoken.Claims; | |||
import lombok.extern.log4j.Log4j; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.context.MessageSource; | |||
import org.springframework.context.NoSuchMessageException; | |||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | |||
import org.springframework.security.core.authority.SimpleGrantedAuthority; | |||
import org.springframework.security.core.context.SecurityContextHolder; | |||
import org.springframework.stereotype.Component; | |||
import org.springframework.web.filter.OncePerRequestFilter; | |||
import org.springframework.web.util.ContentCachingRequestWrapper; | |||
import javax.servlet.FilterChain; | |||
import javax.servlet.ServletException; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
import java.io.IOException; | |||
import java.util.Collections; | |||
import java.util.List; | |||
import java.util.Locale; | |||
import java.util.stream.Collectors; | |||
/** | |||
* 把JWT转换为security的对象 | |||
* Created by Tkk on 2018/7/23. | |||
*/ | |||
@Component | |||
@Log4j | |||
public class SecurityFilter extends OncePerRequestFilter { | |||
@Autowired | |||
MessageSource messageSource; | |||
@Override | |||
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException { | |||
// 区分什么请求 | |||
Request build = Request | |||
.builder() | |||
.request(httpServletRequest) | |||
.build(); | |||
String servletPath = httpServletRequest.getServletPath(); | |||
String prefix = org.apache.commons.lang3.StringUtils.substringBetween(servletPath, "/", "/"); | |||
switch (prefix) { | |||
case "system": | |||
build.setJwtType(JwtUtils.T.System); | |||
break; | |||
case "company": | |||
build.setJwtType(JwtUtils.T.Company); | |||
break; | |||
case "place": | |||
build.setJwtType(JwtUtils.T.Market); | |||
break; | |||
case "customer": | |||
build.setJwtType(JwtUtils.T.APP_C); | |||
break; | |||
case "merchant": | |||
build.setJwtType(JwtUtils.T.APP_B); | |||
break; | |||
} | |||
try { | |||
RequestHolder.set(build); | |||
String token = httpServletRequest.getHeader("token"); | |||
if (StringUtils.isNotBlank(token)) { | |||
// | |||
Claims claims = JwtUtils.decode(build.getJwtType(), httpServletRequest.getHeader("token")); | |||
AuthUser authUser = toAuthUser(claims); | |||
// 放入jwt数值, 用于后面转换方法对面 | |||
build.setJwtValue(claims); | |||
// 如果能转换成功, 说明登录没问题, 那么转换为security对象, 做权限处理 | |||
UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = toAuthToken(authUser); | |||
SecurityContextHolder.getContext().setAuthentication(usernamePasswordAuthenticationToken); | |||
} | |||
// 包装request对象, 可以之后做日志处理, 可以反复读取请求体 | |||
ContentCachingRequestWrapper r = new ContentCachingRequestWrapper(httpServletRequest); | |||
filterChain.doFilter(r, httpServletResponse); | |||
} | |||
// 业务一次 | |||
catch (SystemException e) { | |||
log.error(e.getMessage(), e); | |||
httpServletResponse.setCharacterEncoding("UTF-8"); | |||
httpServletResponse.getWriter().write( | |||
JsonResponse.fail(e.getErrorCode(), getMessage(e.getErrorCode(), e.getParams())).toString() | |||
); | |||
} | |||
// 所有异常 | |||
catch (Exception e) { | |||
log.error(e.getMessage(), e); | |||
httpServletResponse.setCharacterEncoding("UTF-8"); | |||
httpServletResponse.getWriter().write( | |||
JsonResponse.fail().toString() | |||
); | |||
} finally { | |||
RequestHolder.clean(); | |||
} | |||
} | |||
/** | |||
* @param claims | |||
* @return | |||
*/ | |||
private AuthUser toAuthUser(Claims claims) { | |||
List<String> roles = (List<String>) claims.get("role"); | |||
if (roles == null) { | |||
roles = Collections.emptyList(); | |||
} | |||
return AuthUser | |||
.builder() | |||
.id(Long.parseLong(claims.getSubject())) | |||
.authorities( | |||
roles.stream() | |||
.map(SimpleGrantedAuthority::new) | |||
.collect(Collectors.toList())) | |||
.build(); | |||
} | |||
private UsernamePasswordAuthenticationToken toAuthToken(AuthUser authUser) { | |||
return new UsernamePasswordAuthenticationToken(authUser, null, authUser.getAuthorities()); | |||
} | |||
protected String getMessage(String code, Object[] params) { | |||
try { | |||
return messageSource.getMessage(code, params, Locale.CHINA); | |||
} catch (NoSuchMessageException e) { | |||
return code; | |||
} | |||
} | |||
} |
@@ -0,0 +1,62 @@ | |||
package com.chilunyc.fumao.controller; | |||
import com.chilunyc.fumao.common.request.ChangePwdRequest; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import com.chilunyc.fumao.common.sms.model.SmsType; | |||
import com.chilunyc.fumao.common.sms.request.SmsSendRequest; | |||
import com.chilunyc.fumao.common.sms.service.SmsService; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiImplicitParam; | |||
import io.swagger.annotations.ApiImplicitParams; | |||
import io.swagger.annotations.ApiOperation; | |||
import lombok.extern.log4j.Log4j; | |||
import org.apache.commons.lang3.RandomStringUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.RequestBody; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RequestMethod; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import javax.validation.Valid; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@Api(description = "找回密码") | |||
@RestController | |||
@RequestMapping("/find/pwd") | |||
class FindPwdController { | |||
@Autowired | |||
SmsService smsService; | |||
@ApiOperation(value = "改密码") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "UserChangePwdRequest") | |||
}) | |||
@RequestMapping(value = "/", method = RequestMethod.POST) | |||
JsonResponse login(@RequestBody @Valid ChangePwdRequest request) { | |||
// | |||
return JsonResponse.success(); | |||
} | |||
@ApiOperation(value = "改密码发短信") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "SmsSendRequest") | |||
}) | |||
@RequestMapping(value = "/send", method = RequestMethod.POST) | |||
JsonResponse login(@RequestBody @Valid SmsSendRequest request) { | |||
//1. 校验是否存在 | |||
// if (!userService.isExist(request.getMobile())) { | |||
// throw new SystemException("000010"); | |||
// } | |||
//2. 发送 | |||
request.setContent(RandomStringUtils.randomNumeric(4)); | |||
request.setType(SmsType.CustomerFindPwd); | |||
smsService.send(request); | |||
return JsonResponse.success(); | |||
} | |||
} |
@@ -0,0 +1,58 @@ | |||
package com.chilunyc.fumao.controller.common; | |||
import com.google.code.kaptcha.Constants; | |||
import com.google.code.kaptcha.Producer; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiOperation; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Controller; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RequestMethod; | |||
import org.springframework.web.servlet.ModelAndView; | |||
import javax.imageio.ImageIO; | |||
import javax.servlet.ServletOutputStream; | |||
import javax.servlet.http.HttpServletResponse; | |||
import javax.servlet.http.HttpSession; | |||
import java.awt.image.BufferedImage; | |||
/** | |||
* | |||
*/ | |||
@Api(description = "验证码") | |||
@Controller | |||
@RequestMapping("/common/captcha") | |||
class CaptchaController { | |||
@Autowired | |||
Producer captchaProducer; | |||
/** | |||
* 验证码 | |||
* | |||
* @param response | |||
* @param session | |||
* @return | |||
* @throws Exception | |||
*/ | |||
@ApiOperation(value = "生成验证码图片") | |||
@RequestMapping(value = "", method = RequestMethod.GET) | |||
ModelAndView index(HttpServletResponse response, HttpSession session) throws Exception { | |||
response.setDateHeader("Expires", 0); | |||
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); | |||
response.addHeader("Cache-Control", "post-checkExist=0, pre-checkExist=0"); | |||
response.setHeader("Pragma", "no-cache"); | |||
response.setContentType("image/jpeg"); | |||
String capText = captchaProducer.createText(); | |||
session.setAttribute(Constants.KAPTCHA_SESSION_KEY, capText); | |||
BufferedImage bi = captchaProducer.createImage(capText); | |||
ServletOutputStream out = response.getOutputStream(); | |||
ImageIO.write(bi, "jpg", out); | |||
try { | |||
out.flush(); | |||
} finally { | |||
out.close(); | |||
} | |||
return null; | |||
} | |||
} |
@@ -0,0 +1,43 @@ | |||
package com.chilunyc.fumao.controller.common; | |||
import com.chilunyc.fumao.common.log.repository.EventMapper; | |||
import com.chilunyc.fumao.common.log.request.LogPageRequest; | |||
import com.chilunyc.fumao.common.log.response.LogResponse; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import com.github.pagehelper.Page; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiImplicitParam; | |||
import io.swagger.annotations.ApiImplicitParams; | |||
import io.swagger.annotations.ApiOperation; | |||
import org.apache.ibatis.session.RowBounds; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.data.domain.PageImpl; | |||
import org.springframework.web.bind.annotation.RequestBody; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RequestMethod; | |||
import org.springframework.web.bind.annotation.RestController; | |||
/** | |||
* | |||
*/ | |||
@Api("日志") | |||
@RestController | |||
@RequestMapping("/log") | |||
class LogController { | |||
@Autowired | |||
EventMapper eventMapper; | |||
@ApiOperation(value = "分页") | |||
@ApiImplicitParams({ | |||
@ApiImplicitParam(name = "request", required = true, paramType = "body", dataType = "LogPageRequest") | |||
}) | |||
@RequestMapping(value = "", method = RequestMethod.POST) | |||
JsonResponse page(@RequestBody LogPageRequest request) { | |||
RowBounds rowBounds = new RowBounds(request.getStart(), request.getSize()); | |||
Page<LogResponse> page = eventMapper.page(request, rowBounds); | |||
return JsonResponse.success( | |||
new PageImpl<>(page, request.getPage(), page.getTotal()) | |||
); | |||
} | |||
} |
@@ -0,0 +1,34 @@ | |||
package com.chilunyc.fumao.controller.common; | |||
import com.chilunyc.fumao.common.context.LoginUser; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import com.chilunyc.fumao.common.upload.response.UploadResponse; | |||
import com.chilunyc.fumao.common.upload.service.UploadService; | |||
import io.swagger.annotations.Api; | |||
import io.swagger.annotations.ApiOperation; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.http.ResponseEntity; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RequestMethod; | |||
import org.springframework.web.bind.annotation.RestController; | |||
/** | |||
* | |||
*/ | |||
@Api(description = "上传服务") | |||
@RestController | |||
@RequestMapping("/upload") | |||
class UploadController { | |||
@Autowired | |||
UploadService uploadService; | |||
/** | |||
* @return | |||
*/ | |||
@ApiOperation(value = "获取上传凭证") | |||
@RequestMapping(value = "", method = RequestMethod.GET) | |||
ResponseEntity<JsonResponse<UploadResponse>> index(LoginUser loginUser) { | |||
return ResponseEntity.ok(JsonResponse.success(uploadService.getAuth())); | |||
} | |||
} |
@@ -0,0 +1,177 @@ | |||
package com.chilunyc.fumao.controller.error; | |||
import com.chilunyc.fumao.common.config.ApplicationProperty; | |||
import com.chilunyc.fumao.common.exception.SystemException; | |||
import com.chilunyc.fumao.common.log.model.EventTarget; | |||
import com.chilunyc.fumao.common.log.model.EventType; | |||
import com.chilunyc.fumao.common.log.service.EventService; | |||
import com.chilunyc.fumao.common.context.RequestHolder; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import lombok.extern.log4j.Log4j; | |||
import org.apache.commons.io.IOUtils; | |||
import org.apache.commons.lang3.StringUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.context.MessageSource; | |||
import org.springframework.context.NoSuchMessageException; | |||
import org.springframework.dao.EmptyResultDataAccessException; | |||
import org.springframework.http.HttpStatus; | |||
import org.springframework.validation.BindException; | |||
import org.springframework.validation.FieldError; | |||
import org.springframework.web.bind.MethodArgumentNotValidException; | |||
import org.springframework.web.bind.annotation.ControllerAdvice; | |||
import org.springframework.web.bind.annotation.ExceptionHandler; | |||
import org.springframework.web.bind.annotation.ResponseBody; | |||
import org.springframework.web.bind.annotation.ResponseStatus; | |||
import org.springframework.web.util.ContentCachingRequestWrapper; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
import java.util.Locale; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@ControllerAdvice | |||
class ExceptionController { | |||
@Autowired | |||
MessageSource messageSource; | |||
@Autowired | |||
EventService eventService; | |||
@Autowired | |||
ApplicationProperty applicationProperty; | |||
/** | |||
* 业务异常 | |||
* | |||
* @param request | |||
* @param ex | |||
* @return | |||
*/ | |||
@ExceptionHandler(SystemException.class) | |||
@ResponseStatus(HttpStatus.OK) | |||
@ResponseBody | |||
JsonResponse systemExceptionHandler(ContentCachingRequestWrapper request, SystemException ex) { | |||
String errorCode = ex.getErrorCode(); | |||
if (StringUtils.isEmpty(errorCode)) { | |||
errorCode = "000001"; | |||
} | |||
String msg = this.getMessage(errorCode, ex.getParams()); | |||
String requestContent = ""; | |||
try { | |||
requestContent = IOUtils.toString(request.getContentAsByteArray(), "UTF-8"); | |||
} catch (Exception e) { | |||
} | |||
if (applicationProperty.isTest()) { | |||
log.error(request.getServletPath() + " => " + errorCode + " => " + requestContent + " ==> " + msg, ex); | |||
} else { | |||
String errorMsg = request.getServletPath() + " => " + errorCode + " => " + requestContent + " ==> " + msg + " || " + this.getStackJson(ex); | |||
eventService.add(RequestHolder.get(), EventTarget.None, EventType.Error, null, errorMsg); | |||
} | |||
return JsonResponse.fail(errorCode, msg); | |||
} | |||
/** | |||
* 参数验证 | |||
* | |||
* @param ex | |||
* @return | |||
*/ | |||
@ExceptionHandler(MethodArgumentNotValidException.class) | |||
@ResponseStatus(HttpStatus.OK) | |||
@ResponseBody | |||
JsonResponse validationHandler(MethodArgumentNotValidException ex) { | |||
List<FieldError> fieldErrors = ex.getBindingResult().getFieldErrors(); | |||
FieldError fr = fieldErrors.get(fieldErrors.size() - 1); | |||
return JsonResponse.fail("000003", fr.getDefaultMessage()); | |||
} | |||
/** | |||
* 参数验证 | |||
* | |||
* @param ex | |||
* @return | |||
*/ | |||
@ExceptionHandler(BindException.class) | |||
@ResponseStatus(HttpStatus.OK) | |||
@ResponseBody | |||
JsonResponse validationHandler(BindException ex) { | |||
List<FieldError> fieldErrors = ex.getBindingResult().getFieldErrors(); | |||
FieldError fr = fieldErrors.get(fieldErrors.size() - 1); | |||
return JsonResponse.fail("000003", fr.getDefaultMessage()); | |||
} | |||
/** | |||
* 数据不存在 | |||
* | |||
* @param ex | |||
* @return | |||
*/ | |||
@ExceptionHandler(EmptyResultDataAccessException.class) | |||
@ResponseStatus(HttpStatus.OK) | |||
@ResponseBody | |||
JsonResponse noDataHandler(EmptyResultDataAccessException ex) { | |||
log.error(ex.getMessage(), ex); | |||
return JsonResponse.fail("000004", this.getMessage("000004", null)); | |||
} | |||
/** | |||
* 错误统一处理 | |||
* | |||
* @param request | |||
* @param ex | |||
* @return | |||
* @throws Exception | |||
*/ | |||
@ExceptionHandler | |||
@ResponseBody | |||
JsonResponse defaultExceptionHandler(ContentCachingRequestWrapper request, Exception ex) throws Exception { | |||
String requestContent = ""; | |||
try { | |||
requestContent = IOUtils.toString(request.getContentAsByteArray(), "UTF-8"); | |||
} catch (Exception e) { | |||
} | |||
if (applicationProperty.isTest()) { | |||
log.error(request.getServletPath() + " => " + requestContent + " ==> " + ex.getMessage(), ex); | |||
return JsonResponse.fail(ex.getMessage()); | |||
} else { | |||
String errorMsg = request.getServletPath() + " => " + requestContent + " ==> " + ex.getMessage() + " || " + this.getStackJson(ex); | |||
eventService.add(RequestHolder.get(), EventTarget.None, EventType.Error, null, errorMsg); | |||
return JsonResponse.fail(); | |||
} | |||
} | |||
protected String getMessage(String code, Object[] params) { | |||
try { | |||
return messageSource.getMessage(code, params, Locale.CHINA); | |||
} catch (NoSuchMessageException e) { | |||
return code; | |||
} | |||
} | |||
private String getStackJson(Throwable e) { | |||
String result = ""; | |||
if (null != e) { | |||
StackTraceElement[] s = e.getStackTrace(); | |||
if (null != s) { | |||
if (s.length > 10) { | |||
s = Arrays.copyOfRange(s, 0, 9); | |||
} | |||
result = "\n"; | |||
for (StackTraceElement ste : s) { | |||
result += ("\tat " + ste + "\n"); | |||
} | |||
if (null != e.getCause()) { | |||
result += "Cause By:" + StringUtils.trimToEmpty(e.getCause().getMessage()); | |||
result += getStackJson(e.getCause()); | |||
} | |||
} | |||
} | |||
return result; | |||
} | |||
} |
@@ -0,0 +1,44 @@ | |||
package com.chilunyc.fumao.controller.error; | |||
import com.chilunyc.fumao.common.response.JsonResponse; | |||
import com.alibaba.fastjson.JSON; | |||
import lombok.extern.log4j.Log4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.boot.autoconfigure.web.ErrorAttributes; | |||
import org.springframework.boot.autoconfigure.web.ErrorController; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import org.springframework.web.context.request.RequestAttributes; | |||
import org.springframework.web.context.request.ServletRequestAttributes; | |||
import javax.servlet.http.HttpServletRequest; | |||
import java.util.Map; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@RestController | |||
@RequestMapping("/error") | |||
public class PanicController implements ErrorController { | |||
@Autowired | |||
ErrorAttributes errorAttributes; | |||
@Autowired | |||
ExceptionController exceptionController; | |||
@Override | |||
public String getErrorPath() { | |||
return "/error"; | |||
} | |||
@RequestMapping | |||
public JsonResponse error(HttpServletRequest aRequest) throws Exception { | |||
RequestAttributes requestAttributes = new ServletRequestAttributes(aRequest); | |||
Map<String, Object> errorAttributes = this.errorAttributes.getErrorAttributes(requestAttributes, false); | |||
log.error(String.format("[%s] => [%s]", errorAttributes.get("path"), JSON.toJSONString(errorAttributes))); | |||
return errorAttributes.get("error") != null ? JsonResponse.fail(errorAttributes.get("error").toString()) : JsonResponse.fail(); | |||
} | |||
} |
@@ -0,0 +1,111 @@ | |||
###### | |||
## | |||
###### | |||
logging.level.root=INFO | |||
logging.level.com.aki=INFO | |||
logging.level.org.springframework=INFO | |||
logging.config=/opt/projects/config/logback.xml | |||
###### | |||
## | |||
###### | |||
server.address=127.0.0.1 | |||
server.port=8088 | |||
spring.data.redis.repositories.enabled=false | |||
server.undertow.io-threads=100 | |||
###### | |||
## spring boot admin | |||
###### | |||
#spring.boot.admin.url=http://localhost:18081 | |||
endpoints.enabled=false | |||
#endpoints.metrics.endabled=true | |||
#endpoints.health.endabled=true | |||
#endpoints.dump.endabled=true | |||
#management.context-path=/monitor | |||
#management.security.enabled=false | |||
###### | |||
## | |||
###### | |||
app.test=false | |||
app.role=true | |||
app.save-error=true | |||
app.config-path=classpath:/config.json | |||
###### | |||
## \u90AE\u4EF6\u53D1\u9001 | |||
###### | |||
#spring.mail.host= | |||
#spring.mail.username= | |||
#spring.mail.password= | |||
#spring.mail.properties.mail.smtp.auth=true | |||
#spring.mail.properties.mail.smtp.starttls.enable=true | |||
#spring.mail.properties.mail.smtp.starttls.required=true | |||
###### | |||
## redis | |||
###### | |||
spring.redis.host=127.0.0.1 | |||
spring.redis.port=6379 | |||
spring.redis.pool.max-idle=50 | |||
spring.redis.pool.min-idle=50 | |||
spring.redis.pool.max-active=50 | |||
spring.redis.pool.max-wait=-1 | |||
###### | |||
## \u6570\u636E\u6E90 | |||
###### | |||
mybatis.mapper-locations=classpath*:com/aki/**/*Mapper.xml | |||
mybatis.configuration.default-fetch-size=100 | |||
mybatis.configuration.default-statement-timeout=30 | |||
mybatis.configuration.map-underscore-to-camel-case=true | |||
pagehelper.helperDialect=mysql | |||
pagehelper.reasonable=true | |||
pagehelper.row-bounds-with-count=true | |||
pagehelper.supportMethodsArguments=tru | |||
spring.jpa.open-in-view=false | |||
spring.datasource.url= | |||
spring.datasource.username= | |||
spring.datasource.password= | |||
spring.datasource.initial-size=20 | |||
spring.datasource.min-idle=20 | |||
spring.datasource.max-idle=100 | |||
spring.datasource.max-wait=10000 | |||
spring.datasource.testOnBorrow=true | |||
spring.datasource.validation-query=SELECT 1 | |||
##### | |||
## \u963F\u91CC\u4E91 - OSS | |||
###### | |||
aliyun.oss.access-id= | |||
aliyun.oss.access-key= | |||
aliyun.oss.end-point= | |||
aliyun.oss.bucket= | |||
###### | |||
## \u963F\u91CC\u4E91 - \u77ED\u4FE1 | |||
###### | |||
aliyun.sms.type=sms | |||
aliyun.sms.access-id= | |||
aliyun.sms.access-key= | |||
aliyun.sms.end-point= | |||
aliyun.sms.sign-name= | |||
aliyun.sms.param-name=content | |||
aliyun.sms.topic= | |||
aliyun.sms.expired-duration=2 | |||
###### | |||
## \u5FAE\u4FE1 | |||
###### | |||
wechat.mp.app-id= | |||
wechat.mp.secret= | |||
wechat.mp.token= | |||
wechat.mp.aesKey= | |||
wechat.mp.mch-id= | |||
wechat.mp.mch-key= | |||
wechat.mp.key-path= | |||
wechat.ma.app-id= | |||
wechat.ma.secret= |
@@ -0,0 +1,99 @@ | |||
###### | |||
## | |||
###### | |||
logging.level.root=INFO | |||
logging.level.com.aki=TRACE | |||
logging.level.org.springframework=INFO | |||
logging.level.org.hibernate=INFO | |||
###### | |||
## | |||
###### | |||
server.address=0.0.0.0 | |||
server.port=8088 | |||
server.session.timeout=36000000 | |||
spring.data.redis.repositories.enabled=false | |||
spring.output.ansi.enabled=ALWAYS | |||
###### | |||
## spring boot admin | |||
###### | |||
#spring.boot.admin.url=http://localhost:18081 | |||
#endpoints.enabled=false | |||
#endpoints.metrics.endabled=true | |||
#endpoints.health.endabled=true | |||
#endpoints.dump.endabled=true | |||
management.context-path=/monitor | |||
management.security.enabled=false | |||
###### | |||
## \u7CFB\u7EDF\u914D\u7F6E | |||
###### | |||
app.test=true | |||
app.role=true | |||
app.cache-time=3600 | |||
app.save-error=false | |||
app.config-path=classpath:config.json | |||
###### | |||
## \u6570\u636E\u6E90 | |||
###### | |||
mybatis.mapper-locations=classpath*:com/chilunyc/**/*Mapper.xml | |||
mybatis.configuration.default-fetch-size=100 | |||
mybatis.configuration.default-statement-timeout=30 | |||
mybatis.configuration.map-underscore-to-camel-case=true | |||
pagehelper.helperDialect=mysql | |||
pagehelper.reasonable=true | |||
pagehelper.row-bounds-with-count=true | |||
pagehelper.supportMethodsArguments=true | |||
spring.jpa.hibernate.ddl-auto=update | |||
spring.jpa.show-sql=true | |||
spring.jpa.open-in-view=false | |||
spring.datasource.testOnBorrow=true | |||
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/demo?characterEncoding=UTF-8&&zeroDateTimeBehavior=convertToNull&autoReconnect=true&failOverReadOnly=false&connectTimeout=0 | |||
#spring.datasource.url=jdbc:mysql://127.0.0.1:3306/demo?characterEncoding=UTF-8&&zeroDateTimeBehavior=convertToNull&autoReconnect=true&failOverReadOnly=false&connectTimeout=0&useSSL=true | |||
spring.datasource.username=root | |||
spring.datasource.password= | |||
###### | |||
## redis | |||
###### | |||
spring.redis.host=127.0.0.1 | |||
#spring.redis.password= | |||
spring.redis.port=6379 | |||
spring.redis.pool.max-idle=10 | |||
spring.redis.pool.min-idle=10 | |||
spring.redis.pool.max-active=10 | |||
spring.redis.pool.max-wait=-1 | |||
###### | |||
## \u963F\u91CC\u4E91 - OSS | |||
###### | |||
aliyun.oss.access-id= | |||
aliyun.oss.access-key= | |||
aliyun.oss.end-point= | |||
aliyun.oss.bucket= | |||
###### | |||
## \u963F\u91CC\u4E91 - \u77ED\u4FE1 mns | sms | |||
###### | |||
sms.name=\u5BCC\u8302\u79D1\u6280\u6709\u9650\u516C\u53F8 | |||
sms.bid=46565 | |||
sms.account=15626593768 | |||
sms.secret=7305150347587283553aa8898e7dbf20 | |||
sms.publick-key=classpath://sms.key | |||
###### | |||
## \u5FAE\u4FE1 | |||
###### | |||
wechat.mp.app-id= | |||
wechat.mp.secret= | |||
wechat.mp.token= | |||
wechat.mp.aesKey= | |||
wechat.mp.mch-id= | |||
wechat.mp.mch-key= | |||
wechat.mp.key-path= | |||
###### | |||
## \u767E\u5EA6 | |||
###### | |||
baidu.lbs.ak=UU7tWzU6kz4UesVqXnmOSWsFGkUQrRZs |
@@ -0,0 +1,17 @@ | |||
TTTTTTTTTTTTTTTTTTTTTTT kkkkkkkk kkkkkkkk | |||
T:::::::::::::::::::::T k::::::k k::::::k | |||
T:::::::::::::::::::::T k::::::k k::::::k | |||
T:::::TT:::::::TT:::::T k::::::k k::::::k | |||
TTTTTT T:::::T TTTTTT k:::::k kkkkkkk k:::::k kkkkkkk | |||
T:::::T k:::::k k:::::k k:::::k k:::::k | |||
T:::::T k:::::k k:::::k k:::::k k:::::k | |||
T:::::T k:::::k k:::::k k:::::k k:::::k | |||
T:::::T k::::::k:::::k k::::::k:::::k | |||
T:::::T k:::::::::::k k:::::::::::k | |||
T:::::T k:::::::::::k k:::::::::::k | |||
T:::::T k::::::k:::::k k::::::k:::::k | |||
TT:::::::TT k::::::k k:::::k k::::::k k:::::k | |||
T:::::::::T k::::::k k:::::k k::::::k k:::::k | |||
T:::::::::T k::::::k k:::::k k::::::k k:::::k | |||
TTTTTTTTTTT kkkkkkkk kkkkkkk kkkkkkkk kkkkkkk |
@@ -0,0 +1,3 @@ | |||
{ | |||
} |
@@ -0,0 +1,13 @@ | |||
000000=ok | |||
000001=\u7CFB\u7EDF\u9519\u8BEF | |||
000002=\u5C1A\u672A\u767B\u5F55 | |||
000003=\u53C2\u6570\u9519\u8BEF | |||
000004=\u7528\u6237\u540D\u6216\u5BC6\u7801\u9519\u8BEF | |||
000005=\u5FAE\u4FE1\u9519\u8BEF | |||
000006=\u6CA1\u6709\u6743\u9650\u8BBF\u95EE | |||
000007=\u8BBF\u95EE\u9891\u7E41, {0} | |||
000008=\u767E\u5EA6\u63A5\u53E3\u8FD4\u56DE\u9519\u8BEF | |||
100000=\u5DF2\u5B58\u5728\u76F8\u540C\u7684\u624B\u673A\u53F7 | |||
100001=\u4E0D\u80FD\u5220\u9664\u81EA\u5DF1 |
@@ -0,0 +1,8 @@ | |||
[ | |||
{ | |||
"name": "", | |||
"url": "", | |||
"method": "", | |||
"order": 0 | |||
} | |||
] |
@@ -0,0 +1,13 @@ | |||
-----BEGIN PUBLIC KEY----- | |||
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAvh8j/zagfxQdnSh5OIic | |||
MzN+MuRuWQJPjgu4Gza4+gX3j5Ln2xNDBOTjpwyuLBjh/JcBd1cGO3lAaKCwcaix | |||
smhTq56wVXXUMgDiAChu4ud8FSvRc8G8tdZAirKVAIi3NW+/pYgpWBs/0wnF8hz4 | |||
8no4pyJHl9Jc1LH3VNIMz8vqzKUPc4ack4pFUXlcNj6C+sBlaurmI4/vwLqNxBGs | |||
7/zyM7dv6oy3DSU/Y1qBArM1YPjfL2dNun8rmtPgJvlPwXqA7uoHPwQ2Ym3aUn59 | |||
pkS7QI6IE8uuqNkfSte8BXLd2nIqPLFxLYLDmdll7eoyRblHcHqAYSj8stK6StC7 | |||
DNryNKEjTEwbgf9trUI0uvF1pfgTy2gpclnY69FtD/m0+FvLyorMq+nmBqYMjka5 | |||
K0txDQJPOa7gsi//uXd/cJW2SAXY9MSO1AfMi8Xq/YKRQzN9FW5iapskXFHca7uX | |||
g5NhH7flr6DW+QInFlpoN6WIEAuDF1aj4O49Ikm3WxwhTqnvEkdSCfivpYQkp9Sh | |||
4kQ/SQdxuT7VX+Nz6k+uMx2z4cySk33bHi0KoHbA9QFGg/54Qd0+eU4qZnd4mrgh | |||
hH7/QQhL7Z9eF1U5UPrsHq2Vq3rEnN+tYQ26AuKeU8vzTxBrC/SxC6C/SMFt3f/Y | |||
nuFh1UnNJZleZwyQt+ZdGO0CAwEAAQ== |
@@ -0,0 +1,243 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<project xmlns="http://maven.apache.org/POM/4.0.0" | |||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |||
<parent> | |||
<artifactId>fumao</artifactId> | |||
<groupId>com.aki</groupId> | |||
<version>0.0.1-SNAPSHOT</version> | |||
</parent> | |||
<modelVersion>4.0.0</modelVersion> | |||
<artifactId>fumao-common</artifactId> | |||
<dependencies> | |||
<dependency> | |||
<groupId>javax.servlet</groupId> | |||
<artifactId>servlet-api</artifactId> | |||
<version>2.5</version> | |||
<scope>provided</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.github.penggle</groupId> | |||
<artifactId>kaptcha</artifactId> | |||
<version>2.3.2</version> | |||
</dependency> | |||
<!-- --> | |||
<dependency> | |||
<groupId>com.squareup.okhttp3</groupId> | |||
<artifactId>okhttp</artifactId> | |||
<version>3.10.0</version> | |||
</dependency> | |||
<!-- aliyun --> | |||
<dependency> | |||
<groupId>com.aliyun.mns</groupId> | |||
<artifactId>aliyun-sdk-mns</artifactId> | |||
<version>1.1.8.4</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.aliyun.oss</groupId> | |||
<artifactId>aliyun-sdk-oss</artifactId> | |||
<version>2.6.1</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.aliyun</groupId> | |||
<artifactId>aliyun-java-sdk-core</artifactId> | |||
<version>3.2.3</version> | |||
<scope>system</scope> | |||
<systemPath>${project.basedir}/src/main/lib/aliyun-java-sdk-core-3.2.2.jar</systemPath> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.aliyun</groupId> | |||
<artifactId>aliyun-java-sdk-dysmsapi</artifactId> | |||
<version>1.0.0</version> | |||
<scope>system</scope> | |||
<systemPath>${project.basedir}/src/main/lib/aliyun-java-sdk-dysmsapi-1.0.0-SANPSHOT.jar</systemPath> | |||
</dependency> | |||
<!-- 权限框架 --> | |||
<dependency> | |||
<groupId>org.springframework.boot</groupId> | |||
<artifactId>spring-boot-starter-security</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.springframework.security</groupId> | |||
<artifactId>spring-security-jwt</artifactId> | |||
</dependency> | |||
<!-- weixin --> | |||
<dependency> | |||
<groupId>com.github.binarywang</groupId> | |||
<artifactId>weixin-java-mp</artifactId> | |||
<version>${weixin.version}</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.github.binarywang</groupId> | |||
<artifactId>weixin-java-pay</artifactId> | |||
<version>${weixin.version}</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.github.binarywang</groupId> | |||
<artifactId>weixin-java-miniapp</artifactId> | |||
<version>${weixin.version}</version> | |||
</dependency> | |||
<!-- Swagger --> | |||
<dependency> | |||
<groupId>io.springfox</groupId> | |||
<artifactId>springfox-swagger-ui</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>io.springfox</groupId> | |||
<artifactId>springfox-swagger2</artifactId> | |||
</dependency> | |||
<!-- --> | |||
<dependency> | |||
<groupId>org.projectlombok</groupId> | |||
<artifactId>lombok</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.alibaba</groupId> | |||
<artifactId>fastjson</artifactId> | |||
<version>1.2.33</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.redisson</groupId> | |||
<artifactId>redisson</artifactId> | |||
<version>3.5.7</version> | |||
</dependency> | |||
<!-- jwt --> | |||
<dependency> | |||
<groupId>io.jsonwebtoken</groupId> | |||
<artifactId>jjwt</artifactId> | |||
<version>${jjwt.version}</version> | |||
</dependency> | |||
<!-- --> | |||
<dependency> | |||
<groupId>org.apache.commons</groupId> | |||
<artifactId>commons-lang3</artifactId> | |||
<version>3.4</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>commons-codec</groupId> | |||
<artifactId>commons-codec</artifactId> | |||
<version>1.10</version> | |||
</dependency> | |||
<!-- mybatis --> | |||
<dependency> | |||
<groupId>org.mybatis.spring.boot</groupId> | |||
<artifactId>mybatis-spring-boot-starter</artifactId> | |||
<version>1.3.0</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.github.pagehelper</groupId> | |||
<artifactId>pagehelper-spring-boot-starter</artifactId> | |||
<version>1.1.2</version> | |||
</dependency> | |||
<!-- jpa --> | |||
<dependency> | |||
<groupId>org.springframework.boot</groupId> | |||
<artifactId>spring-boot-starter-data-jpa</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.zaxxer</groupId> | |||
<artifactId>HikariCP</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>io.dropwizard.metrics</groupId> | |||
<artifactId>metrics-core</artifactId> | |||
<optional>true</optional> | |||
</dependency> | |||
<dependency> | |||
<groupId>mysql</groupId> | |||
<artifactId>mysql-connector-java</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.h2database</groupId> | |||
<artifactId>h2</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.hibernate</groupId> | |||
<artifactId>hibernate-validator</artifactId> | |||
</dependency> | |||
<!-- jackson --> | |||
<dependency> | |||
<groupId>com.fasterxml.jackson.core</groupId> | |||
<artifactId>jackson-core</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.fasterxml.jackson.core</groupId> | |||
<artifactId>jackson-annotations</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.fasterxml.jackson.core</groupId> | |||
<artifactId>jackson-databind</artifactId> | |||
</dependency> | |||
<!-- redis --> | |||
<dependency> | |||
<groupId>org.springframework.data</groupId> | |||
<artifactId>spring-data-redis</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.springframework.boot</groupId> | |||
<artifactId>spring-boot-starter-redis</artifactId> | |||
<version>1.4.7.RELEASE</version> | |||
</dependency> | |||
<!-- spring boot admin --> | |||
<!--<dependency>--> | |||
<!--<groupId>de.codecentric</groupId>--> | |||
<!--<artifactId>spring-boot-admin-starter-client</artifactId>--> | |||
<!--<version>1.5.7</version>--> | |||
<!--</dependency>--> | |||
<!--<dependency>--> | |||
<!--<groupId>org.springframework.boot</groupId>--> | |||
<!--<artifactId>spring-boot-starter-actuator</artifactId>--> | |||
<!--</dependency>--> | |||
<!-- excel --> | |||
<dependency> | |||
<groupId>org.apache.poi</groupId> | |||
<artifactId>poi</artifactId> | |||
<version>3.17</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.poi</groupId> | |||
<artifactId>poi-ooxml</artifactId> | |||
<version>3.17</version> | |||
</dependency> | |||
<!-- 扩展时间 --> | |||
<dependency> | |||
<groupId>joda-time</groupId> | |||
<artifactId>joda-time</artifactId> | |||
<version>2.9.9</version> | |||
</dependency> | |||
<!-- word --> | |||
<dependency> | |||
<groupId>com.deepoove</groupId> | |||
<artifactId>poi-tl</artifactId> | |||
<version>1.2.0</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.springframework.boot</groupId> | |||
<artifactId>spring-boot-starter-test</artifactId> | |||
<scope>test</scope> | |||
</dependency> | |||
</dependencies> | |||
</project> |
@@ -0,0 +1,49 @@ | |||
package com.chilunyc.fumao.common.aop; | |||
import javassist.*; | |||
import org.aspectj.lang.JoinPoint; | |||
import org.aspectj.lang.reflect.MethodSignature; | |||
import org.springframework.core.LocalVariableTableParameterNameDiscoverer; | |||
import java.lang.reflect.Method; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
/** | |||
* | |||
*/ | |||
public abstract class BaseAop { | |||
/** | |||
* @param point | |||
* @param clazz | |||
* @param <T> | |||
* @return | |||
*/ | |||
protected <T> T getAnnotation(JoinPoint point, Class clazz) throws NoSuchMethodException { | |||
MethodSignature signature = (MethodSignature) point.getSignature(); | |||
Method method = point.getTarget().getClass().getMethod(signature.getName(), signature.getParameterTypes()); | |||
return (T) method.getAnnotation(clazz); | |||
} | |||
/** | |||
* @param point | |||
* @return | |||
*/ | |||
protected String getMethodName(JoinPoint point) { | |||
MethodSignature signature = (MethodSignature) point.getSignature(); | |||
Method method = signature.getMethod(); | |||
return method.getName(); | |||
} | |||
protected Map<String, Object> getArgs(JoinPoint point) throws NotFoundException { | |||
MethodSignature signature = (MethodSignature) point.getSignature(); | |||
Map<String, Object> map = new HashMap<>(); | |||
LocalVariableTableParameterNameDiscoverer u = new LocalVariableTableParameterNameDiscoverer(); | |||
String[] parameterNames = u.getParameterNames(signature.getMethod()); | |||
for (int i = 0; i < parameterNames.length; i++) { | |||
map.put(parameterNames[i], point.getArgs()[i]);//paramNames即参数名 | |||
} | |||
return map; | |||
} | |||
} |
@@ -0,0 +1,130 @@ | |||
package com.chilunyc.fumao.common.aop.cache; | |||
import com.chilunyc.fumao.common.aop.BaseAop; | |||
import com.chilunyc.fumao.common.util.SpelHelper; | |||
import lombok.extern.log4j.Log4j; | |||
import org.apache.commons.codec.binary.Hex; | |||
import org.apache.commons.lang.SerializationUtils; | |||
import org.apache.commons.lang3.StringUtils; | |||
import org.aspectj.lang.JoinPoint; | |||
import org.aspectj.lang.ProceedingJoinPoint; | |||
import org.aspectj.lang.annotation.Around; | |||
import org.aspectj.lang.annotation.Aspect; | |||
import org.aspectj.lang.annotation.Before; | |||
import org.springframework.beans.factory.InitializingBean; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.data.redis.core.BoundValueOperations; | |||
import org.springframework.data.redis.core.StringRedisTemplate; | |||
import org.springframework.data.redis.core.script.DefaultRedisScript; | |||
import org.springframework.stereotype.Component; | |||
import java.io.Serializable; | |||
import java.util.Collections; | |||
import java.util.Map; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@Component | |||
@Aspect | |||
public class CacheAop extends BaseAop implements InitializingBean { | |||
@Autowired | |||
private StringRedisTemplate redisTemplate; | |||
private DefaultRedisScript luaRemoveAllScript; | |||
/** | |||
* 缓存cache | |||
* | |||
* @param proceedingJoinPoint | |||
* @throws Throwable | |||
*/ | |||
@Around("@annotation(com.chilunyc.fumao.common.aop.cache.Cacheable)") | |||
Object cacheable(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { | |||
try { | |||
Cacheable annotation = getAnnotation(proceedingJoinPoint, Cacheable.class); | |||
Map<String, Object> args = getArgs(proceedingJoinPoint); | |||
String redisKey = annotation.value() + SpelHelper.exec(annotation.key(), args); | |||
BoundValueOperations<String, String> value = redisTemplate.boundValueOps(redisKey); | |||
// 有值 | |||
String result = value.get(); | |||
if (StringUtils.isNotBlank(result)) { | |||
byte[] bytes = Hex.decodeHex(result.toCharArray()); | |||
return SerializationUtils.deserialize(bytes); | |||
} | |||
// 没有值, 调用缓存 | |||
else { | |||
Object proceed = proceedingJoinPoint.proceed(proceedingJoinPoint.getArgs()); | |||
if (proceed == null) { | |||
return null; | |||
} | |||
//判断是否要存 | |||
if (StringUtils.isNotBlank(annotation.exclude())) { | |||
args.put("result", proceed); | |||
Boolean isNotSave = SpelHelper.exec(annotation.exclude(), args); | |||
if (isNotSave) { | |||
return proceed; | |||
} | |||
} | |||
//开始存 | |||
byte[] serialize = SerializationUtils.serialize((Serializable) proceed); | |||
String s = Hex.encodeHexString(serialize); | |||
if (annotation.timeout() != -1L) { | |||
value.set(s, annotation.timeout(), annotation.unit()); | |||
} else { | |||
value.set(s); | |||
} | |||
// 放入一个list, 后面可以删除 | |||
if (StringUtils.isNotBlank(annotation.value())) { | |||
redisTemplate.boundListOps(annotation.value()).leftPush(redisKey); | |||
} | |||
return proceed; | |||
} | |||
} catch (Exception e) { | |||
log.error(e); | |||
return proceedingJoinPoint.proceed(); | |||
} | |||
} | |||
/** | |||
* 清空cache | |||
* | |||
* @param joinPoint | |||
* @throws Throwable | |||
*/ | |||
@Before("@annotation(com.chilunyc.fumao.common.aop.cache.CacheEvict)") | |||
void cacheEvict(JoinPoint joinPoint) throws Throwable { | |||
CacheEvict annotation = getAnnotation(joinPoint, CacheEvict.class); | |||
// 清空所有 | |||
if (annotation.allEntries()) { | |||
if (annotation.value().length > 0) { | |||
for (String v : annotation.value()) { | |||
redisTemplate.execute(luaRemoveAllScript, Collections.singletonList(v)); | |||
} | |||
} | |||
} | |||
// 清空单个 | |||
else { | |||
String v = annotation.value()[0]; | |||
Map<String, Object> args = getArgs(joinPoint); | |||
String redisKey = v + SpelHelper.exec(annotation.key(), args); | |||
redisTemplate.delete(redisKey); | |||
redisTemplate.boundListOps(v).remove(1, redisKey); | |||
} | |||
} | |||
@Override | |||
public void afterPropertiesSet() throws Exception { | |||
this.luaRemoveAllScript = new DefaultRedisScript<>(); | |||
this.luaRemoveAllScript.setScriptText("local size = redis.call('llen', KEYS[1])\n" + | |||
"local vs = redis.call('lrange', KEYS[1], 0, size)\n" + | |||
"for x,y in ipairs(vs) do\n" + | |||
" redis.call('del', y)\n" + | |||
"end\n" + | |||
"redis.call('ltrim', KEYS[1], size, -1)"); | |||
} | |||
} |
@@ -0,0 +1,19 @@ | |||
package com.chilunyc.fumao.common.aop.cache; | |||
import java.lang.annotation.*; | |||
/** | |||
* | |||
*/ | |||
@Target({ElementType.METHOD, ElementType.TYPE}) | |||
@Retention(RetentionPolicy.RUNTIME) | |||
@Inherited | |||
@Documented | |||
public @interface CacheEvict { | |||
String[] value() default ""; | |||
String key() default ""; | |||
boolean allEntries() default false; | |||
} |
@@ -0,0 +1,24 @@ | |||
package com.chilunyc.fumao.common.aop.cache; | |||
import java.lang.annotation.*; | |||
import java.util.concurrent.TimeUnit; | |||
/** | |||
* | |||
*/ | |||
@Target({ElementType.METHOD}) | |||
@Retention(RetentionPolicy.RUNTIME) | |||
@Inherited | |||
@Documented | |||
public @interface Cacheable { | |||
String value() default ""; | |||
String key() default ""; | |||
long timeout() default -1L; | |||
String exclude() default ""; | |||
TimeUnit unit() default TimeUnit.SECONDS; | |||
} |
@@ -0,0 +1,23 @@ | |||
package com.chilunyc.fumao.common.aop.limit; | |||
import java.lang.annotation.ElementType; | |||
import java.lang.annotation.Retention; | |||
import java.lang.annotation.RetentionPolicy; | |||
import java.lang.annotation.Target; | |||
import java.util.concurrent.TimeUnit; | |||
/** | |||
* | |||
*/ | |||
@Target({ElementType.METHOD}) | |||
@Retention(RetentionPolicy.RUNTIME) | |||
public @interface Limit { | |||
String key() default ""; | |||
long timeout() default 5l; | |||
TimeUnit unit() default TimeUnit.SECONDS; | |||
String message() default "请忽重复提交"; | |||
} |
@@ -0,0 +1,41 @@ | |||
package com.chilunyc.fumao.common.aop.limit; | |||
import com.chilunyc.fumao.common.aop.BaseAop; | |||
import com.chilunyc.fumao.common.exception.SystemException; | |||
import com.chilunyc.fumao.common.util.SpelHelper; | |||
import org.apache.commons.lang3.StringUtils; | |||
import org.aspectj.lang.JoinPoint; | |||
import org.aspectj.lang.annotation.Aspect; | |||
import org.aspectj.lang.annotation.Before; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.data.redis.core.StringRedisTemplate; | |||
import org.springframework.stereotype.Component; | |||
import java.util.Map; | |||
/** | |||
* | |||
*/ | |||
@Component | |||
@Aspect | |||
public class LimitAop extends BaseAop { | |||
@Autowired | |||
private StringRedisTemplate redisTemplate; | |||
@Before("@annotation(com.chilunyc.fumao.common.aop.limit.Limit)") | |||
void execute(JoinPoint joinPoint) throws Throwable { | |||
Limit annotation = getAnnotation(joinPoint, Limit.class); | |||
Map<String, Object> args = getArgs(joinPoint); | |||
String redisKey = getMethodName(joinPoint) + (StringUtils.isBlank(annotation.key()) ? "" : SpelHelper.exec(annotation.key(), args)); | |||
// 没值, 缓存一下 | |||
if (redisTemplate.opsForValue().setIfAbsent(redisKey, "v")) { | |||
redisTemplate.expire(redisKey, annotation.timeout(), annotation.unit()); | |||
} | |||
// 有值, 所有有人提交过了, 出错 | |||
else { | |||
throw new SystemException("000007", new Object[]{annotation.message()}); | |||
} | |||
} | |||
} |
@@ -0,0 +1,23 @@ | |||
package com.chilunyc.fumao.common.aop.lock; | |||
import java.lang.annotation.ElementType; | |||
import java.lang.annotation.Retention; | |||
import java.lang.annotation.RetentionPolicy; | |||
import java.lang.annotation.Target; | |||
import java.util.concurrent.TimeUnit; | |||
/** | |||
* | |||
*/ | |||
@Target({ElementType.METHOD}) | |||
@Retention(RetentionPolicy.RUNTIME) | |||
public @interface Lock { | |||
String key() default ""; | |||
long timeout() default -1; | |||
TimeUnit unit() default TimeUnit.SECONDS; | |||
String message() default "请稍候重试"; | |||
} |
@@ -0,0 +1,38 @@ | |||
package com.chilunyc.fumao.common.aop.lock; | |||
import com.chilunyc.fumao.common.aop.BaseAop; | |||
import com.chilunyc.fumao.common.util.SpelHelper; | |||
import org.aspectj.lang.ProceedingJoinPoint; | |||
import org.aspectj.lang.annotation.Around; | |||
import org.aspectj.lang.annotation.Aspect; | |||
import org.redisson.api.RLock; | |||
import org.redisson.api.RedissonClient; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Component; | |||
import java.util.Map; | |||
/** | |||
* | |||
*/ | |||
@Component | |||
@Aspect | |||
public class LockAop extends BaseAop { | |||
@Autowired | |||
private RedissonClient redissonClient; | |||
@Around("@annotation(com.chilunyc.fumao.common.aop.lock.Lock)") | |||
Object execute(ProceedingJoinPoint joinPoint) throws Throwable { | |||
Lock annotation = getAnnotation(joinPoint, Lock.class); | |||
Map<String, Object> args = getArgs(joinPoint); | |||
String redisKey = getMethodName(joinPoint) + "_" + SpelHelper.exec(annotation.key(), args); | |||
RLock lock = redissonClient.getLock(redisKey); | |||
try { | |||
lock.lock(); | |||
return joinPoint.proceed(); | |||
} finally { | |||
lock.unlock(); | |||
} | |||
} | |||
} |
@@ -0,0 +1,22 @@ | |||
package com.chilunyc.fumao.common.aop.retry; | |||
import java.lang.annotation.ElementType; | |||
import java.lang.annotation.Retention; | |||
import java.lang.annotation.RetentionPolicy; | |||
import java.lang.annotation.Target; | |||
/** | |||
* | |||
*/ | |||
@Target({ElementType.METHOD}) | |||
@Retention(RetentionPolicy.RUNTIME) | |||
public @interface Retry { | |||
String scene() default ""; | |||
/** | |||
* 最大次数 | |||
* @return | |||
*/ | |||
int maxTimes() default 3; | |||
} |
@@ -0,0 +1,32 @@ | |||
package com.chilunyc.fumao.common.aop.retry; | |||
import com.chilunyc.fumao.common.aop.BaseAop; | |||
import lombok.extern.log4j.Log4j; | |||
import org.aspectj.lang.ProceedingJoinPoint; | |||
import org.aspectj.lang.annotation.Around; | |||
import org.aspectj.lang.annotation.Aspect; | |||
import org.springframework.stereotype.Component; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@Component | |||
@Aspect | |||
public class RetryAop extends BaseAop { | |||
@Around("@annotation(com.chilunyc.fumao.common.aop.retry.Retry)") | |||
Object execute(ProceedingJoinPoint joinPoint) throws Throwable { | |||
Retry annotation = getAnnotation(joinPoint, Retry.class); | |||
int times = 0; | |||
Object result = null; | |||
while (times++ < annotation.maxTimes()) { | |||
try { | |||
result = joinPoint.proceed(); | |||
} catch (Exception e) { | |||
log.error(String.format("重试, 场景[%s], 参数[%s], 次数[%s] => 失败[%s]", annotation.scene(), joinPoint.getArgs(), times, e.getMessage())); | |||
} | |||
} | |||
return result; | |||
} | |||
} |
@@ -0,0 +1,24 @@ | |||
package com.chilunyc.fumao.common.config; | |||
import lombok.Data; | |||
import org.springframework.boot.context.properties.ConfigurationProperties; | |||
/** | |||
* | |||
*/ | |||
@Data | |||
@ConfigurationProperties(prefix = "app") | |||
public class ApplicationProperty { | |||
private boolean test; | |||
private boolean role; | |||
private boolean auth; | |||
private boolean saveError; | |||
private String configPath; | |||
private String aesKey; | |||
} |
@@ -0,0 +1,9 @@ | |||
package com.chilunyc.fumao.common.config; | |||
/** | |||
* | |||
*/ | |||
public interface CacheEnums { | |||
String Permission = "Permission"; | |||
} |
@@ -0,0 +1,8 @@ | |||
package com.chilunyc.fumao.common.config; | |||
/** | |||
* | |||
*/ | |||
public enum ConfigEnum { | |||
} |
@@ -0,0 +1,14 @@ | |||
package com.chilunyc.fumao.common.config; | |||
import lombok.Data; | |||
/** | |||
* | |||
*/ | |||
@Data | |||
public class ConfigRequest { | |||
private ConfigEnum key; | |||
private String value; | |||
} |
@@ -0,0 +1,46 @@ | |||
package com.chilunyc.fumao.common.config; | |||
import com.alibaba.fastjson.JSON; | |||
import lombok.extern.log4j.Log4j; | |||
import org.apache.commons.io.IOUtils; | |||
import org.springframework.beans.factory.InitializingBean; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.core.io.DefaultResourceLoader; | |||
import org.springframework.data.redis.core.BoundHashOperations; | |||
import org.springframework.data.redis.core.RedisTemplate; | |||
import org.springframework.stereotype.Service; | |||
import java.io.InputStream; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@Service | |||
public class ConfigService implements InitializingBean { | |||
@Autowired | |||
private RedisTemplate<String, String> redisTemplate; | |||
@Autowired | |||
private ApplicationProperty applicationProperty; | |||
private BoundHashOperations<String, Object, Object> ops; | |||
public void set(ConfigEnum key, Object v) { | |||
this.ops.put(key.name(), v); | |||
} | |||
public <T> T get(ConfigEnum key) { | |||
return (T) this.ops.get(key.name()); | |||
} | |||
@Override | |||
public void afterPropertiesSet() throws Exception { | |||
this.ops = redisTemplate.boundHashOps(ConfigService.class.getName()); | |||
if (this.ops.size() == 0) { | |||
InputStream inputStream = new DefaultResourceLoader().getResource(applicationProperty.getConfigPath()).getInputStream(); | |||
String configContent = IOUtils.toString(inputStream, "utf-8"); | |||
this.ops.putAll(JSON.parseObject(configContent)); | |||
} | |||
} | |||
} |
@@ -0,0 +1,23 @@ | |||
package com.chilunyc.fumao.common.config; | |||
import org.redisson.Redisson; | |||
import org.redisson.api.RedissonClient; | |||
import org.redisson.config.Config; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.boot.autoconfigure.data.redis.RedisProperties; | |||
import org.springframework.context.annotation.Bean; | |||
import org.springframework.context.annotation.Configuration; | |||
@Configuration | |||
public class RedissonConfig { | |||
@Autowired | |||
private RedisProperties redisProperties; | |||
@Bean | |||
RedissonClient redissonClient() { | |||
Config config = new Config(); | |||
config.useSingleServer().setAddress(String.format("redis://%s:%s", redisProperties.getHost(), redisProperties.getPort())); | |||
return Redisson.create(config); | |||
} | |||
} |
@@ -0,0 +1,42 @@ | |||
package com.chilunyc.fumao.common.context; | |||
import io.jsonwebtoken.Claims; | |||
import io.jsonwebtoken.JwtBuilder; | |||
/** | |||
* | |||
*/ | |||
public interface LoginUser<T> { | |||
/** | |||
* Id | |||
* | |||
* @return | |||
*/ | |||
T getId(); | |||
/** | |||
* 用户名 | |||
* | |||
* @return | |||
*/ | |||
String getName(); | |||
/** | |||
* @return | |||
*/ | |||
String[] toRoles(); | |||
/** | |||
* | |||
* @param claims | |||
*/ | |||
void fromJwt(Claims claims); | |||
/** | |||
* | |||
* @param claims | |||
*/ | |||
void toJwt(JwtBuilder claims); | |||
} |
@@ -0,0 +1,77 @@ | |||
package com.chilunyc.fumao.common.context; | |||
import com.chilunyc.fumao.common.util.jwt.JwtUtils; | |||
import io.jsonwebtoken.Claims; | |||
import lombok.AllArgsConstructor; | |||
import lombok.Builder; | |||
import lombok.Data; | |||
import lombok.NoArgsConstructor; | |||
import org.apache.commons.lang3.StringUtils; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpSession; | |||
/** | |||
* | |||
*/ | |||
@Data | |||
@Builder | |||
@NoArgsConstructor | |||
@AllArgsConstructor | |||
public class Request { | |||
private JwtUtils.T jwtType; | |||
private Claims jwtValue; | |||
public String getIp() { | |||
String ip = request.getHeader("x-real-ip"); | |||
if (StringUtils.isBlank(ip)) { | |||
return request.getRemoteAddr(); | |||
} | |||
return ip; | |||
} | |||
public String getHost() { | |||
return request.getServerName(); | |||
} | |||
private String getPort() { | |||
int port = request.getServerPort(); | |||
return port == 80 ? "" : ":" + String.valueOf(port); | |||
} | |||
private HttpServletRequest request; | |||
private LoginUser loginUser; | |||
public <T> T getLoginUserId() { | |||
LoginUser loginUser = getLoginUser(); | |||
if (loginUser == null) { | |||
return null; | |||
} else { | |||
return (T) loginUser.getId(); | |||
} | |||
} | |||
/** | |||
* @return | |||
*/ | |||
public String getSite() { | |||
return String.format("%s://%s%s", StringUtils.contains(request.getProtocol(), "https") ? "https" : "http", getHost(), getPort()); | |||
} | |||
/** | |||
* @return | |||
*/ | |||
public HttpSession getSession() { | |||
return request.getSession(true); | |||
} | |||
/** | |||
* @return | |||
*/ | |||
public String getJwt() { | |||
return request.getHeader("token"); | |||
} | |||
} |
@@ -0,0 +1,20 @@ | |||
package com.chilunyc.fumao.common.context; | |||
/** | |||
* | |||
*/ | |||
public class RequestHolder { | |||
private static final ThreadLocal<Request> r = new ThreadLocal<>(); | |||
public static Request get() { | |||
return r.get(); | |||
} | |||
public static void set(Request request) { | |||
r.set(request); | |||
} | |||
public static void clean() { | |||
r.remove(); | |||
} | |||
} |
@@ -0,0 +1,10 @@ | |||
package com.chilunyc.fumao.common.enums; | |||
/** | |||
* 80347471@qq.com | |||
*/ | |||
public enum Comparing { | |||
Big, | |||
Equal, | |||
Small | |||
} |
@@ -0,0 +1,10 @@ | |||
package com.chilunyc.fumao.common.enums; | |||
/** | |||
* | |||
*/ | |||
public enum YesOrNo { | |||
Yes, | |||
No | |||
} |
@@ -0,0 +1,48 @@ | |||
package com.chilunyc.fumao.common.exception; | |||
import lombok.Data; | |||
/** | |||
* | |||
*/ | |||
@Data | |||
public class SystemException extends RuntimeException { | |||
private String errorCode; | |||
private Object[] params; | |||
public SystemException() { | |||
super(); | |||
this.errorCode = "KK-000001"; | |||
} | |||
public SystemException(String errorCode) { | |||
super(); | |||
this.errorCode = errorCode; | |||
} | |||
public SystemException(String errorCode, Object... params) { | |||
this.errorCode = errorCode; | |||
this.params = params; | |||
} | |||
public SystemException(String errorCode, Throwable cause) { | |||
super(cause); | |||
this.errorCode = errorCode; | |||
} | |||
public SystemException(String errorCode, Object[] params, Throwable cause) { | |||
super(cause); | |||
this.errorCode = errorCode; | |||
this.params = params; | |||
} | |||
// public KKException(Throwable cause) { | |||
// super(cause); | |||
// } | |||
// public KKException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { | |||
// super(message, cause, enableSuppression, writableStackTrace); | |||
// } | |||
} |
@@ -0,0 +1,12 @@ | |||
package com.chilunyc.fumao.common.lbs.config; | |||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | |||
import org.springframework.context.annotation.Configuration; | |||
/** | |||
* | |||
*/ | |||
@Configuration | |||
@EnableConfigurationProperties(LBSProperties.class) | |||
public class LBSConfig { | |||
} |
@@ -0,0 +1,14 @@ | |||
package com.chilunyc.fumao.common.lbs.config; | |||
import lombok.Data; | |||
import org.springframework.boot.context.properties.ConfigurationProperties; | |||
/** | |||
* | |||
*/ | |||
@Data | |||
@ConfigurationProperties("baidu.lbs") | |||
public class LBSProperties { | |||
private String ak; | |||
} |
@@ -0,0 +1,20 @@ | |||
package com.chilunyc.fumao.common.lbs.model; | |||
import lombok.Data; | |||
/** | |||
* | |||
*/ | |||
@Data | |||
public class LBSAddress { | |||
private Double lat; | |||
private Double lng; | |||
private String province; | |||
private String city; | |||
private String county; | |||
} |
@@ -0,0 +1,42 @@ | |||
package com.chilunyc.fumao.common.lbs.model; | |||
import com.alibaba.fastjson.annotation.JSONField; | |||
import lombok.AllArgsConstructor; | |||
import lombok.Builder; | |||
import lombok.Data; | |||
import lombok.NoArgsConstructor; | |||
import java.math.BigDecimal; | |||
/** | |||
* Created by Tkk on 2018/7/24. | |||
*/ | |||
@Data | |||
@NoArgsConstructor | |||
@AllArgsConstructor | |||
@Builder | |||
public class LBSPoi { | |||
@Data | |||
@NoArgsConstructor | |||
public static class Location { | |||
@JSONField(name = "lat") | |||
private String lat; | |||
@JSONField(name = "lng") | |||
private String lng; | |||
} | |||
private Location location; | |||
@JSONField(name = "uid") | |||
private String poi; | |||
private String province; | |||
private String city; | |||
private String address; | |||
private String name; | |||
} |
@@ -0,0 +1,15 @@ | |||
package com.chilunyc.fumao.common.lbs.request; | |||
import com.chilunyc.fumao.common.request.PageRequest; | |||
import lombok.Data; | |||
/** | |||
* Created by Tkk on 2018/7/24. | |||
*/ | |||
@Data | |||
public class LBSPoiRequest extends PageRequest { | |||
private String query; | |||
private String city; | |||
} |
@@ -0,0 +1,78 @@ | |||
package com.chilunyc.fumao.common.lbs.service; | |||
import com.chilunyc.fumao.common.exception.SystemException; | |||
import com.chilunyc.fumao.common.lbs.config.LBSProperties; | |||
import com.chilunyc.fumao.common.lbs.model.LBSPoi; | |||
import com.chilunyc.fumao.common.lbs.request.LBSPoiRequest; | |||
import com.chilunyc.fumao.common.util.http.service.HttpClient; | |||
import com.chilunyc.fumao.common.util.http.service.HttpParams; | |||
import com.chilunyc.fumao.common.util.http.service.result.ResultExecute; | |||
import com.alibaba.fastjson.JSON; | |||
import com.alibaba.fastjson.JSONArray; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.fasterxml.jackson.databind.ObjectMapper; | |||
import lombok.extern.log4j.Log4j; | |||
import okhttp3.Request; | |||
import okhttp3.Response; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.data.domain.Page; | |||
import org.springframework.data.domain.PageImpl; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.util.StopWatch; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@Service | |||
public class LBSService implements ResultExecute<String> { | |||
@Autowired | |||
private HttpClient httpClient; | |||
@Autowired | |||
private LBSProperties lbsProperties; | |||
private ObjectMapper objectMapper = new ObjectMapper(); | |||
/** | |||
* @param request | |||
* @return | |||
*/ | |||
public Page<LBSPoi> findPoi(LBSPoiRequest request) { | |||
HttpParams httpParams = HttpParams.get("http://api.map.baidu.com/place/v2/search"); | |||
httpParams | |||
.put("query", request.getQuery()) | |||
.put("region", request.getCity()) | |||
.put("page_size", request.getSize()) | |||
.put("page_num", request.getPageI()) | |||
.put("output", "json") | |||
.put("ak", lbsProperties.getAk()); | |||
String body = httpClient.execute(httpParams, this); | |||
JSONObject object = JSON.parseObject(body); | |||
JSONArray jsonArray = object.getJSONArray("results"); | |||
int total = object.getIntValue("total"); | |||
List<LBSPoi> pois = new ArrayList<>(jsonArray.size()); | |||
for (int i = 0; i < jsonArray.size(); i++) { | |||
JSONObject jsonObject = jsonArray.getJSONObject(i); | |||
LBSPoi lbsPoi = jsonObject.toJavaObject(LBSPoi.class); | |||
lbsPoi.setLocation(jsonObject.getJSONObject("location").toJavaObject(LBSPoi.Location.class)); | |||
pois.add(lbsPoi); | |||
} | |||
return new PageImpl<>(pois, request.getPage(), total); | |||
} | |||
@Override | |||
public String toBody(Response response, Request request, StopWatch stopWatch) throws Exception { | |||
String string = response.body().string(); | |||
if (StringUtils.contains(string, "\"status\":0")) { | |||
return string; | |||
} | |||
log.error(string); | |||
throw new SystemException("000008"); | |||
} | |||
} |
@@ -0,0 +1,64 @@ | |||
package com.chilunyc.fumao.common.log.model; | |||
import lombok.AllArgsConstructor; | |||
import lombok.Builder; | |||
import lombok.Data; | |||
import lombok.NoArgsConstructor; | |||
import javax.persistence.*; | |||
import java.util.Date; | |||
/** | |||
* | |||
*/ | |||
@Data | |||
@Builder | |||
@NoArgsConstructor | |||
@AllArgsConstructor | |||
@Entity | |||
@Table(name = "fumao_event_log", indexes = { | |||
@Index(name = "event_log_operator", columnList = "operator"), | |||
@Index(name = "event_log_targetId", columnList = "targetId"), | |||
@Index(name = "event_log_type", columnList = "type"), | |||
@Index(name = "event_log_target", columnList = "target"), | |||
}) | |||
public class Event { | |||
@Id | |||
@GeneratedValue | |||
private Long id; | |||
@Column(length = 1) | |||
private EventTarget target; | |||
@Column(length = 1) | |||
private EventType type; | |||
/** | |||
* 操作人 | |||
*/ | |||
@Column(length = 32) | |||
private String operator; | |||
/** | |||
* | |||
*/ | |||
@Column(length = 32) | |||
private String targetId; | |||
/** | |||
* | |||
*/ | |||
@Lob | |||
private String content; | |||
/** | |||
* | |||
*/ | |||
private String ip; | |||
/** | |||
* | |||
*/ | |||
private Date createTime; | |||
} |
@@ -0,0 +1,8 @@ | |||
package com.chilunyc.fumao.common.log.model; | |||
/** | |||
* | |||
*/ | |||
public enum EventTarget { | |||
System, Company, None | |||
} |
@@ -0,0 +1,12 @@ | |||
package com.chilunyc.fumao.common.log.model; | |||
/** | |||
* | |||
*/ | |||
public enum EventType { | |||
Error, | |||
// 权限 | |||
RoleEdit, RoleDelete, PermissionEdit, PermissionRemove, SendMsg, 编辑系统管理员, 删除系统管理员, 编辑集团, 删除集团, 编辑商场, 删除商场, 编辑商场楼层, 删除商场楼层, 编辑集团申请, 删除集团申请, 编辑商铺申请, 删除商铺申请, 编辑集团管理员, 删除集团管理员, 编辑商场管理员角色, 删除商场管理员角色, 编辑商场管理员, 删除商场管理员, | |||
} |
@@ -0,0 +1,16 @@ | |||
package com.chilunyc.fumao.common.log.repository; | |||
import com.chilunyc.fumao.common.log.request.LogPageRequest; | |||
import com.chilunyc.fumao.common.log.response.LogResponse; | |||
import com.github.pagehelper.Page; | |||
import org.apache.ibatis.annotations.Mapper; | |||
import org.apache.ibatis.session.RowBounds; | |||
/** | |||
* | |||
*/ | |||
@Mapper | |||
public interface EventMapper { | |||
Page<LogResponse> page(LogPageRequest request, RowBounds rowBounds); | |||
} |
@@ -0,0 +1,12 @@ | |||
package com.chilunyc.fumao.common.log.repository; | |||
import com.chilunyc.fumao.common.log.model.Event; | |||
import org.springframework.data.jpa.repository.JpaRepository; | |||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | |||
/** | |||
* | |||
*/ | |||
public interface EventRepository extends JpaRepository<Event, Long>, JpaSpecificationExecutor<Event> { | |||
} |
@@ -0,0 +1,21 @@ | |||
package com.chilunyc.fumao.common.log.request; | |||
import com.chilunyc.fumao.common.request.PageRequest; | |||
import lombok.Data; | |||
import java.util.Date; | |||
/** | |||
* | |||
*/ | |||
@Data | |||
public class LogPageRequest extends PageRequest { | |||
private String eventType; | |||
private String eventTarget; | |||
private Date startTime; | |||
private Date endTime; | |||
} |
@@ -0,0 +1,24 @@ | |||
package com.chilunyc.fumao.common.log.response; | |||
import lombok.Data; | |||
import java.util.Date; | |||
/** | |||
* | |||
*/ | |||
@Data | |||
public class LogResponse { | |||
private String name; | |||
private String eventType; | |||
private String eventTarget; | |||
private String content; | |||
private String ip; | |||
private Date createTime; | |||
} |
@@ -0,0 +1,77 @@ | |||
package com.chilunyc.fumao.common.log.service; | |||
import com.chilunyc.fumao.common.log.model.Event; | |||
import com.chilunyc.fumao.common.log.model.EventTarget; | |||
import com.chilunyc.fumao.common.log.model.EventType; | |||
import com.chilunyc.fumao.common.log.repository.EventRepository; | |||
import com.chilunyc.fumao.common.context.Request; | |||
import com.alibaba.fastjson.JSON; | |||
import lombok.extern.log4j.Log4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.scheduling.annotation.Async; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.transaction.annotation.Transactional; | |||
import java.io.Serializable; | |||
import java.util.Date; | |||
/** | |||
* | |||
*/ | |||
@Log4j | |||
@Service | |||
@Transactional | |||
@Async | |||
public class EventService { | |||
@Autowired | |||
private EventRepository eventRepository; | |||
public void add(Request request, EventTarget target, EventType type, String targetId) { | |||
add(request, target, type, targetId, null); | |||
} | |||
public void add(Request request, EventType type, String targetId, Object content) { | |||
add(request, EventTarget.None, type, targetId, content); | |||
} | |||
public void add(Request request, EventType type, Object content) { | |||
add(request, EventTarget.None, type, null, content); | |||
} | |||
public void add(Request request, EventTarget target, EventType type) { | |||
add(request, target, type, null, null); | |||
} | |||
/** | |||
* @param request | |||
* @param target | |||
* @param type | |||
* @param targetId | |||
* @param content | |||
*/ | |||
public void add(Request request, EventTarget target, EventType type, Serializable targetId, Object content) { | |||
String contentStr = ""; | |||
if (content != null && !content.getClass().isAssignableFrom(String.class)) { | |||
contentStr = JSON.toJSONString(content); | |||
} else if (content != null) { | |||
contentStr = content.toString(); | |||
} | |||
String operator = ""; | |||
if (request != null && request.getLoginUser() != null) { | |||
operator = request.getLoginUser().getId().toString(); | |||
} | |||
Event build = Event | |||
.builder() | |||
.target(target) | |||
.ip(request == null ? "" : request.getIp()) | |||
.type(type) | |||
.operator(operator) | |||
.targetId(targetId != null ? target.toString() : null) | |||
.content(contentStr) | |||
.createTime(new Date()) | |||
.build(); | |||
eventRepository.save(build); | |||
} | |||
} |
@@ -0,0 +1,20 @@ | |||
package com.chilunyc.fumao.common.request; | |||
import lombok.Data; | |||
import org.hibernate.validator.constraints.NotBlank; | |||
import javax.validation.constraints.Size; | |||
import java.util.List; | |||
/** | |||
* | |||
*/ | |||
@Data | |||
public class AssignsRequest { | |||
@Size(min = 0, message = "目标不存在") | |||
private List<String> id; | |||
@NotBlank(message = "分配数据为空") | |||
private String targetId; | |||
} |
@@ -0,0 +1,15 @@ | |||
package com.chilunyc.fumao.common.request; | |||
import com.chilunyc.fumao.common.sms.request.SmsCheckRequest; | |||
import lombok.Data; | |||
import org.hibernate.validator.constraints.NotBlank; | |||
/** | |||
* | |||
*/ | |||
@Data | |||
public class ChangePwdRequest extends SmsCheckRequest { | |||
@NotBlank(message = "请输入密码") | |||
private String password; | |||
} |
@@ -0,0 +1,23 @@ | |||
package com.chilunyc.fumao.common.request; | |||
import io.swagger.annotations.ApiModel; | |||
import io.swagger.annotations.ApiModelProperty; | |||
import lombok.Data; | |||
import javax.validation.constraints.NotNull; | |||
import javax.validation.constraints.Size; | |||
import java.io.Serializable; | |||
import java.util.List; | |||
/** | |||
* | |||
*/ | |||
@ApiModel | |||
@Data | |||
public class IdsRequest<T extends Serializable> { | |||
@ApiModelProperty(value = "批量操作") | |||
@NotNull(message = "编号不能为空") | |||
@Size(min = 1, message = "编号不能为空") | |||
private List<T> ids; | |||
} |
@@ -0,0 +1,24 @@ | |||
package com.chilunyc.fumao.common.request; | |||
import io.swagger.annotations.ApiModel; | |||
import io.swagger.annotations.ApiModelProperty; | |||
import lombok.Data; | |||
import org.hibernate.validator.constraints.NotBlank; | |||
/** | |||
* | |||
*/ | |||
@ApiModel | |||
@Data | |||
public class LoginRequest { | |||
@ApiModelProperty(value = "手机号") | |||
@NotBlank(message = "请输入手机号") | |||
private String mobile; | |||
@ApiModelProperty(value = "密码") | |||
@NotBlank(message = "请输入密码") | |||
private String password; | |||
} |
@@ -0,0 +1,21 @@ | |||
package com.chilunyc.fumao.common.request; | |||
import com.chilunyc.fumao.common.util.valid.Captcha; | |||
import io.swagger.annotations.ApiModel; | |||
import io.swagger.annotations.ApiModelProperty; | |||
import lombok.Data; | |||
import org.hibernate.validator.constraints.NotBlank; | |||
/** | |||
* | |||
*/ | |||
@ApiModel | |||
@Data | |||
public class LoginRequestWithCaptcha extends LoginRequest { | |||
@ApiModelProperty(value = "密码") | |||
@Captcha | |||
@NotBlank(message = "请输入验证码") | |||
private String captcha; | |||
} |
@@ -0,0 +1,19 @@ | |||
package com.chilunyc.fumao.common.request; | |||
import io.swagger.annotations.ApiModel; | |||
import io.swagger.annotations.ApiModelProperty; | |||
import lombok.Data; | |||
import org.hibernate.validator.constraints.NotBlank; | |||
/** | |||
* | |||
*/ | |||
@ApiModel | |||
@Data | |||
public class LoginRequestWithSMS extends LoginRequest { | |||
@ApiModelProperty(value = "短信验证码") | |||
@NotBlank(message = "请输入短信验证码") | |||
private String code; | |||
} |
@@ -0,0 +1,45 @@ | |||
package com.chilunyc.fumao.common.request; | |||
import lombok.Data; | |||
import java.util.Date; | |||
/** | |||
* | |||
*/ | |||
@Data | |||
public class PageRequest { | |||
private int size; | |||
private int page; | |||
private Date[] timeRange; | |||
public Date getStartTime(){ | |||
return timeRange != null && timeRange.length == 2 ? timeRange[0] : null; | |||
} | |||
public Date getEndTime(){ | |||
return timeRange != null && timeRange.length == 2 ? timeRange[1] : null; | |||
} | |||
/** | |||
* @return | |||
*/ | |||
public int getStart() { | |||
return (page < 0 ? 0 : page) * getSize(); | |||
} | |||
public int getPageI() { | |||
return page < 0 ? 0 : page; | |||
} | |||
public int getSize() { | |||
return size <= 0 || size > 100 ? 10 : size; | |||
} | |||
public org.springframework.data.domain.PageRequest getPage() { | |||
return new org.springframework.data.domain.PageRequest(getPageI(), getSize()); | |||
} | |||
} |
@@ -0,0 +1,78 @@ | |||
package com.chilunyc.fumao.common.response; | |||
import com.alibaba.fastjson.JSON; | |||
import io.swagger.annotations.ApiModel; | |||
import io.swagger.annotations.ApiModelProperty; | |||
import lombok.AllArgsConstructor; | |||
import lombok.Builder; | |||
import lombok.Data; | |||
import lombok.NoArgsConstructor; | |||
/** | |||
* | |||
*/ | |||
@ApiModel | |||
@Data | |||
@Builder | |||
@NoArgsConstructor | |||
@AllArgsConstructor | |||
public class JsonResponse<T> { | |||
@ApiModelProperty(value = "状态码 000000 正常, 000000 不正常") | |||
private String result; | |||
@ApiModelProperty(value = "当result为 000000 获取这个值") | |||
private T data; | |||
@ApiModelProperty(value = "当result不为 000000 获取这个值") | |||
private String error; | |||
/** | |||
* @param object | |||
* @return | |||
*/ | |||
public static <T> JsonResponse<T> success(T object) { | |||
JsonResponse<T> o = new JsonResponse<>(); | |||
o.setData(object); | |||
o.setResult("000000"); | |||
return o; | |||
} | |||
/** | |||
* @return | |||
*/ | |||
public static JsonResponse success() { | |||
return success(""); | |||
} | |||
/** | |||
* @param message | |||
* @return | |||
*/ | |||
public static JsonResponse fail(String errorCode, String message) { | |||
return JsonResponse | |||
.builder() | |||
.result(errorCode) | |||
.error(message) | |||
.build(); | |||
} | |||
/** | |||
* @return | |||
*/ | |||
public static JsonResponse fail() { | |||
return fail("000001", "系统错误"); | |||
} | |||
/** | |||
* @param message | |||
* @return | |||
*/ | |||
public static JsonResponse fail(String message) { | |||
return fail("000001", message); | |||
} | |||
public String toString() { | |||
return JSON.toJSONString(this); | |||
} | |||
} |
@@ -0,0 +1,15 @@ | |||
package com.chilunyc.fumao.common.response; | |||
import lombok.AllArgsConstructor; | |||
import lombok.Builder; | |||
import lombok.Data; | |||
import lombok.NoArgsConstructor; | |||
@Data | |||
@NoArgsConstructor | |||
@AllArgsConstructor | |||
@Builder | |||
public class KeyValue { | |||
private String key; | |||
private Object value; | |||
} |
@@ -0,0 +1,18 @@ | |||
package com.chilunyc.fumao.common.response; | |||
import lombok.AllArgsConstructor; | |||
import lombok.Builder; | |||
import lombok.Data; | |||
import lombok.NoArgsConstructor; | |||
import java.util.List; | |||
@Data | |||
@NoArgsConstructor | |||
@AllArgsConstructor | |||
@Builder | |||
public class KeyValues<T> { | |||
private String key; | |||
private List<T> values; | |||
} |
@@ -0,0 +1,24 @@ | |||
package com.chilunyc.fumao.common.response; | |||
import lombok.AllArgsConstructor; | |||
import lombok.Builder; | |||
import lombok.Data; | |||
import lombok.NoArgsConstructor; | |||
import java.util.List; | |||
/** | |||
* | |||
*/ | |||
@Data | |||
@Builder | |||
@NoArgsConstructor | |||
@AllArgsConstructor | |||
public class NodeResponse { | |||
private String label; | |||
private String value; | |||
private List<NodeResponse> children; | |||
} |
@@ -0,0 +1,25 @@ | |||
package com.chilunyc.fumao.common.shiro; | |||
/** | |||
* Created by Tkk on 2018/7/23. | |||
*/ | |||
public interface AuthRoles { | |||
/** | |||
* | |||
*/ | |||
String SystemAdmin = "SystemAdmin"; | |||
String SystemAdminExp = "hasAuthority('SystemAdmin')"; | |||
/** | |||
* | |||
*/ | |||
String CompanyAdmin = "CompanyAdmin"; | |||
String CompanyAdminExp = "hasAuthority('CompanyAdmin')"; | |||
/** | |||
* | |||
*/ | |||
String MarketAdmin = "MarketAdmin"; | |||
String MarketAdminExp = "hasAuthority('MarketAdmin')"; | |||
} |
@@ -0,0 +1,72 @@ | |||
package com.chilunyc.fumao.common.shiro; | |||
import lombok.AllArgsConstructor; | |||
import lombok.Builder; | |||
import lombok.Data; | |||
import lombok.NoArgsConstructor; | |||
import org.springframework.security.core.GrantedAuthority; | |||
import org.springframework.security.core.authority.SimpleGrantedAuthority; | |||
import org.springframework.security.core.userdetails.UserDetails; | |||
import java.util.Collection; | |||
import java.util.List; | |||
import java.util.stream.Collectors; | |||
import java.util.stream.Stream; | |||
/** | |||
* Created by Tkk on 2018/7/23. | |||
*/ | |||
@Data | |||
@AllArgsConstructor | |||
@NoArgsConstructor | |||
@Builder | |||
public class AuthUser implements UserDetails { | |||
private Long id; | |||
private String username; | |||
private String password; | |||
private List<? extends GrantedAuthority> authorities; | |||
public AuthUser setRole(String... roles) { | |||
this.authorities = Stream.of(roles).map(SimpleGrantedAuthority::new).collect(Collectors.toList()); | |||
return this; | |||
} | |||
@Override | |||
public Collection<? extends GrantedAuthority> getAuthorities() { | |||
return authorities; | |||
} | |||
@Override | |||
public String getPassword() { | |||
return password; | |||
} | |||
@Override | |||
public String getUsername() { | |||
return username; | |||
} | |||
@Override | |||
public boolean isAccountNonExpired() { | |||
return true; | |||
} | |||
@Override | |||
public boolean isAccountNonLocked() { | |||
return true; | |||
} | |||
@Override | |||
public boolean isCredentialsNonExpired() { | |||
return true; | |||
} | |||
@Override | |||
public boolean isEnabled() { | |||
return true; | |||
} | |||
} |
@@ -0,0 +1,17 @@ | |||
package com.chilunyc.fumao.common.sms.config; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | |||
import org.springframework.context.annotation.Configuration; | |||
/** | |||
* | |||
*/ | |||
@Configuration | |||
@EnableConfigurationProperties(SmsProperties.class) | |||
public class SmsConfig { | |||
@Autowired | |||
private SmsProperties smsProperties; | |||
} |
@@ -0,0 +1,37 @@ | |||
package com.chilunyc.fumao.common.sms.config; | |||
import lombok.Data; | |||
import org.apache.commons.io.IOUtils; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.springframework.beans.factory.InitializingBean; | |||
import org.springframework.boot.context.properties.ConfigurationProperties; | |||
import org.springframework.core.io.DefaultResourceLoader; | |||
import java.io.InputStream; | |||
/** | |||
* | |||
*/ | |||
@Data | |||
@ConfigurationProperties("sms") | |||
public class SmsProperties implements InitializingBean { | |||
private String name; | |||
private String bid; | |||
private String account; | |||
private String secret; | |||
private String publicKey; | |||
@Override | |||
public void afterPropertiesSet() throws Exception { | |||
if (StringUtils.isNotBlank(publicKey)) { | |||
InputStream inputStream = new DefaultResourceLoader().getResource(publicKey).getInputStream(); | |||
publicKey = IOUtils.toString(inputStream, "utf-8"); | |||
IOUtils.closeQuietly(inputStream); | |||
} | |||
} | |||
} |