commit message
This commit is contained in:
21
common-api/src/main/java/cn/lili/CommonApiApplication.java
Normal file
21
common-api/src/main/java/cn/lili/CommonApiApplication.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package cn.lili;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
|
||||
/**
|
||||
* 基础API
|
||||
*
|
||||
* @author Chopper
|
||||
* @date 2020/11/17 3:38 下午
|
||||
*/
|
||||
@EnableCaching
|
||||
@SpringBootApplication
|
||||
public class CommonApiApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CommonApiApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package cn.lili.controller.common;
|
||||
|
||||
import cn.lili.common.cache.Cache;
|
||||
import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.common.security.AuthUser;
|
||||
import cn.lili.common.security.context.UserContext;
|
||||
import cn.lili.common.security.enums.UserEnums;
|
||||
import cn.lili.common.utils.ResultUtil;
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.common.vo.ResultMessage;
|
||||
import cn.lili.common.vo.SearchVO;
|
||||
import cn.lili.modules.file.entity.File;
|
||||
import cn.lili.modules.file.entity.dto.FileOwnerDTO;
|
||||
import cn.lili.modules.file.service.FileService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 文件管理管理接口
|
||||
*
|
||||
* @author Chopper
|
||||
* @date 2020/11/26 15:41
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "文件管理管理接口")
|
||||
@RequestMapping("/common/file")
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class FileController {
|
||||
|
||||
private final FileService fileService;
|
||||
|
||||
private final Cache cache;
|
||||
|
||||
@ApiOperation(value = "获取自己的图片资源")
|
||||
@GetMapping
|
||||
@ApiImplicitParam(name = "title", value = "名称模糊匹配")
|
||||
public ResultMessage<IPage<File>> getFileList(@RequestHeader String accessToken, File file, SearchVO searchVO, PageVO pageVo) {
|
||||
|
||||
AuthUser authUser = UserContext.getAuthUser(cache, accessToken);
|
||||
FileOwnerDTO fileOwnerDTO = new FileOwnerDTO();
|
||||
//只有买家才写入自己id
|
||||
if (authUser.getRole().equals(UserEnums.MEMBER)) {
|
||||
fileOwnerDTO.setOwnerId(authUser.getId());
|
||||
}//如果是店铺,则写入店铺id
|
||||
else if (authUser.getRole().equals(UserEnums.STORE)) {
|
||||
fileOwnerDTO.setOwnerId(authUser.getStoreId());
|
||||
}
|
||||
fileOwnerDTO.setUserEnums(authUser.getRole().name());
|
||||
return ResultUtil.data(fileService.customerPageOwner(fileOwnerDTO, file, searchVO, pageVo));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "文件重命名")
|
||||
@PostMapping(value = "/rename")
|
||||
public ResultMessage<File> upload(@RequestHeader String accessToken, String id, String newName) {
|
||||
|
||||
AuthUser authUser = UserContext.getAuthUser(cache, accessToken);
|
||||
File file = fileService.getById(id);
|
||||
file.setName(newName);
|
||||
//操作图片属性判定
|
||||
switch (authUser.getRole()) {
|
||||
case MEMBER:
|
||||
if (file.getOwnerId().equals(authUser.getId()) && file.getUserEnums().equals(authUser.getRole().name())) {
|
||||
break;
|
||||
}
|
||||
throw new ServiceException(ResultCode.USER_AUTHORITY_ERROR);
|
||||
case STORE:
|
||||
if (file.getOwnerId().equals(authUser.getStoreId()) && file.getUserEnums().equals(authUser.getRole().name())) {
|
||||
break;
|
||||
}
|
||||
throw new ServiceException(ResultCode.USER_AUTHORITY_ERROR);
|
||||
case MANAGER:
|
||||
if (file.getUserEnums().equals(authUser.getRole().name())) {
|
||||
break;
|
||||
}
|
||||
throw new ServiceException(ResultCode.USER_AUTHORITY_ERROR);
|
||||
}
|
||||
fileService.updateById(file);
|
||||
return ResultUtil.data(file);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "文件删除")
|
||||
@DeleteMapping(value = "/delete/{ids}")
|
||||
public ResultMessage delete(@RequestHeader String accessToken, @PathVariable List<String> ids) {
|
||||
|
||||
AuthUser authUser = UserContext.getAuthUser(cache, accessToken);
|
||||
fileService.batchDelete(ids, authUser);
|
||||
return ResultUtil.success(ResultCode.SUCCESS);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package cn.lili.controller.common;
|
||||
|
||||
import cn.lili.common.utils.ResultUtil;
|
||||
import cn.lili.common.vo.ResultMessage;
|
||||
import cn.lili.modules.system.entity.enums.SettingEnum;
|
||||
import cn.lili.modules.system.service.SettingService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
/**
|
||||
* 文件管理管理接口
|
||||
*
|
||||
* @author Chopper
|
||||
* @date 2020/11/26 15:41
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "文件管理管理接口")
|
||||
@RequestMapping("/common/logo")
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class LogoController {
|
||||
|
||||
@Autowired
|
||||
private SettingService settingService;
|
||||
|
||||
@ApiOperation(value = "获取logo")
|
||||
@GetMapping
|
||||
public ResultMessage<Object> getFileList() {
|
||||
return ResultUtil.data(settingService.get(SettingEnum.BASE_SETTING.name()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package cn.lili.controller.common;
|
||||
|
||||
import cn.lili.common.utils.ResultUtil;
|
||||
import cn.lili.common.vo.ResultMessage;
|
||||
import cn.lili.modules.base.service.RegionService;
|
||||
import cn.lili.modules.system.entity.dos.Region;
|
||||
import cn.lili.modules.system.entity.vo.RegionVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 地址信息接口
|
||||
*
|
||||
* @author Chopper
|
||||
* @date: 2020/11/16 10:07 下午
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "地址信息接口")
|
||||
@RequestMapping("/common/region")
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class RegionController {
|
||||
|
||||
|
||||
private final RegionService regionService;
|
||||
|
||||
@ApiOperation(value = "点地图获取地址信息")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "cityCode", value = "城市code", dataType = "String", paramType = "query"),
|
||||
@ApiImplicitParam(name = "townName", value = "镇名称", dataType = "Long", paramType = "query")
|
||||
})
|
||||
@GetMapping(value = "/region")
|
||||
public ResultMessage<Object> getRegion(@RequestParam String cityCode,@RequestParam String townName) {
|
||||
return ResultUtil.data(regionService.getRegion(cityCode,townName));
|
||||
}
|
||||
|
||||
|
||||
@GetMapping(value = "/item/{id}")
|
||||
@ApiImplicitParam(name = "id", value = "地区ID", required = true, dataType = "String", paramType = "path")
|
||||
@ApiOperation(value = "通过id获取子地区")
|
||||
public ResultMessage<List<Region>> getItem(@PathVariable String id) {
|
||||
return ResultUtil.data(regionService.getItem(id));
|
||||
}
|
||||
|
||||
@GetMapping(value = "/allCity")
|
||||
@ApiOperation(value = "获取所有的省-市")
|
||||
public ResultMessage<List<RegionVO>> getAllCity() {
|
||||
return ResultUtil.data(regionService.getAllCity());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package cn.lili.controller.common;
|
||||
|
||||
import cn.lili.common.aop.limiter.annotation.LimitPoint;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.common.utils.ResultUtil;
|
||||
import cn.lili.common.verification.enums.VerificationEnums;
|
||||
import cn.lili.common.verification.service.VerificationService;
|
||||
import cn.lili.common.vo.ResultMessage;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 滑块验证码接口
|
||||
*
|
||||
* @author Chopper
|
||||
* @date 2020/11/26 15:41
|
||||
*/
|
||||
@RequestMapping("/common/slider")
|
||||
@RestController
|
||||
@Api(tags = "滑块验证码接口")
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class SliderImageController {
|
||||
|
||||
|
||||
private final VerificationService verificationService;
|
||||
|
||||
//一分钟同一个ip请求10次
|
||||
@LimitPoint(name = "slider_image", key = "verification")
|
||||
@GetMapping("/{verificationEnums}")
|
||||
@ApiOperation(value = "获取校验接口")
|
||||
public ResultMessage getSliderImage(@RequestHeader String uuid, @PathVariable VerificationEnums verificationEnums) {
|
||||
try {
|
||||
return ResultUtil.data(verificationService.createVerification(verificationEnums, uuid));
|
||||
} catch (ServiceException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@LimitPoint(name = "slider_image", key = "verification_pre_check", limit = 600)
|
||||
@PostMapping("/{verificationEnums}")
|
||||
@ApiOperation(value = "验证码预校验")
|
||||
public ResultMessage verificationImage(Integer xPos, @RequestHeader String uuid, @PathVariable VerificationEnums verificationEnums) {
|
||||
return ResultUtil.data(verificationService.preCheck(xPos, uuid, verificationEnums));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package cn.lili.controller.common;
|
||||
|
||||
import cn.lili.common.aop.limiter.annotation.LimitPoint;
|
||||
import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.common.sms.SmsUtil;
|
||||
import cn.lili.common.utils.ResultUtil;
|
||||
import cn.lili.common.verification.enums.VerificationEnums;
|
||||
import cn.lili.common.verification.service.VerificationService;
|
||||
import cn.lili.common.vo.ResultMessage;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 短信验证码接口
|
||||
*
|
||||
* @author Chopper
|
||||
* @date 2020/11/26 15:41
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "短信验证码接口")
|
||||
@RequestMapping("/common/sms")
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class SmsController {
|
||||
|
||||
private final SmsUtil smsUtil;
|
||||
|
||||
private final VerificationService verificationService;
|
||||
|
||||
//一分钟同一个ip请求1次
|
||||
@LimitPoint(name = "sms_send", key = "sms")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(paramType = "path", dataType = "String", name = "mobile", value = "手机号"),
|
||||
@ApiImplicitParam(paramType = "header", dataType = "String", name = "uuid", value = "uuid"),
|
||||
})
|
||||
@GetMapping("/{verificationEnums}/{mobile}")
|
||||
@ApiOperation(value = "发送短信验证码")
|
||||
public ResultMessage getSmsCode(
|
||||
@RequestHeader String uuid,
|
||||
@PathVariable String mobile,
|
||||
@PathVariable VerificationEnums verificationEnums) {
|
||||
if (verificationService.check(uuid, verificationEnums)) {
|
||||
smsUtil.sendSmsCode(mobile, verificationEnums, uuid);
|
||||
return ResultUtil.success(ResultCode.VERIFICATION_SEND_SUCCESS);
|
||||
} else {
|
||||
return ResultUtil.error(ResultCode.VERIFICATION_SMS_EXPIRED_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package cn.lili.controller.common;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.lili.common.cache.Cache;
|
||||
import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.common.security.AuthUser;
|
||||
import cn.lili.common.security.context.UserContext;
|
||||
import cn.lili.common.security.enums.UserEnums;
|
||||
import cn.lili.common.utils.Base64DecodeMultipartFile;
|
||||
import cn.lili.common.utils.CommonUtil;
|
||||
import cn.lili.common.utils.ResultUtil;
|
||||
import cn.lili.common.utils.StringUtils;
|
||||
import cn.lili.common.vo.ResultMessage;
|
||||
import cn.lili.modules.file.entity.File;
|
||||
import cn.lili.modules.file.plugin.FileManagerPlugin;
|
||||
import cn.lili.modules.file.service.FileService;
|
||||
import cn.lili.modules.system.entity.dos.Setting;
|
||||
import cn.lili.modules.system.entity.enums.SettingEnum;
|
||||
import cn.lili.modules.system.service.SettingService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* 文件上传接口
|
||||
*
|
||||
* @author Chopper
|
||||
* @date 2020/11/26 15:41
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Api(tags = "文件上传接口")
|
||||
@RequestMapping("/common/upload")
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class UploadController {
|
||||
|
||||
private final FileService fileService;
|
||||
|
||||
private final SettingService settingService;
|
||||
|
||||
private final FileManagerPlugin fileManagerPlugin;
|
||||
|
||||
private final Cache cache;
|
||||
|
||||
@ApiOperation(value = "文件上传")
|
||||
@PostMapping(value = "/file")
|
||||
public ResultMessage<Object> upload(MultipartFile file,
|
||||
String base64,
|
||||
@RequestHeader String accessToken) {
|
||||
|
||||
|
||||
AuthUser authUser = UserContext.getAuthUser(cache, accessToken);
|
||||
//如果用户未登录,则无法上传图片
|
||||
if (authUser == null) {
|
||||
throw new ServiceException(ResultCode.USER_AUTHORITY_ERROR);
|
||||
}
|
||||
Setting setting = settingService.getById(SettingEnum.OSS_SETTING.name());
|
||||
if (setting == null || StrUtil.isBlank(setting.getSettingValue())) {
|
||||
throw new ServiceException(ResultCode.OSS_NOT_EXIST);
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(base64)) {
|
||||
// base64上传
|
||||
file = Base64DecodeMultipartFile.base64Convert(base64);
|
||||
}
|
||||
String result = "";
|
||||
String fileKey = CommonUtil.rename(file.getOriginalFilename());
|
||||
File newFile = new File();
|
||||
try {
|
||||
InputStream inputStream = file.getInputStream();
|
||||
// 上传至第三方云服务或服务器
|
||||
result = fileManagerPlugin.inputStreamUpload(inputStream, fileKey);
|
||||
// 保存数据信息至数据库
|
||||
newFile.setName(file.getOriginalFilename());
|
||||
newFile.setFileSize(file.getSize());
|
||||
newFile.setFileType(file.getContentType());
|
||||
newFile.setFileKey(fileKey);
|
||||
newFile.setUrl(result);
|
||||
newFile.setCreateBy(authUser.getUsername());
|
||||
newFile.setUserEnums(authUser.getRole().name());
|
||||
//如果是店铺,则记录店铺id
|
||||
if (authUser.getRole().equals(UserEnums.STORE.name())) {
|
||||
newFile.setOwnerId(authUser.getStoreId());
|
||||
} else {
|
||||
newFile.setOwnerId(authUser.getId());
|
||||
}
|
||||
fileService.save(newFile);
|
||||
} catch (Exception e) {
|
||||
log.error("文件上传失败", e);
|
||||
return ResultUtil.error(400, e.toString());
|
||||
}
|
||||
return ResultUtil.data(result);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package cn.lili.controller.security;
|
||||
|
||||
import cn.lili.common.cache.Cache;
|
||||
import cn.lili.common.security.CustomAccessDeniedHandler;
|
||||
import cn.lili.config.properties.IgnoredUrlsProperties;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
|
||||
import org.springframework.web.cors.CorsConfigurationSource;
|
||||
|
||||
/**
|
||||
* spring Security 核心配置类 通用安全
|
||||
*
|
||||
* @author Chopper
|
||||
* @version v4.0
|
||||
* @Description:
|
||||
* @since 2020/11/14 16:20
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class CommonSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
|
||||
/**
|
||||
* 忽略验权配置
|
||||
*/
|
||||
private final IgnoredUrlsProperties ignoredUrlsProperties;
|
||||
|
||||
/**
|
||||
* spring security -》 权限不足处理
|
||||
*/
|
||||
private final CustomAccessDeniedHandler accessDeniedHandler;
|
||||
|
||||
|
||||
private final Cache<String> cache;
|
||||
|
||||
private final CorsConfigurationSource corsConfigurationSource;
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
|
||||
ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry = http
|
||||
.authorizeRequests();
|
||||
registry
|
||||
.and()
|
||||
// 禁止网页iframe
|
||||
.headers().frameOptions().disable()
|
||||
.and()
|
||||
.authorizeRequests()
|
||||
// 任何请求
|
||||
.anyRequest()
|
||||
// 需要身份认证
|
||||
.permitAll()
|
||||
.and()
|
||||
// 允许跨域
|
||||
.cors().configurationSource(corsConfigurationSource).and()
|
||||
// 关闭跨站请求防护
|
||||
.csrf().disable();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user