Commit fd9fb2a6 authored by dqjdda's avatar dqjdda
Browse files

Merge branch '2.3dev'

parents 7895e547 1839ef8d
package me.zhengjie.rest;
import lombok.extern.slf4j.Slf4j;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.zhengjie.aop.log.Log;
import me.zhengjie.domain.EmailConfig;
import me.zhengjie.domain.vo.EmailVo;
import me.zhengjie.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
......@@ -16,30 +16,34 @@ import org.springframework.web.bind.annotation.*;
* @author 郑杰
* @date 2018/09/28 6:55:53
*/
@Slf4j
@RestController
@RequestMapping("api")
@RequestMapping("api/email")
@Api(tags = "工具:邮件管理")
public class EmailController {
@Autowired
private EmailService emailService;
private final EmailService emailService;
@GetMapping(value = "/email")
public EmailController(EmailService emailService) {
this.emailService = emailService;
}
@GetMapping
public ResponseEntity get(){
return new ResponseEntity(emailService.find(),HttpStatus.OK);
return new ResponseEntity<>(emailService.find(),HttpStatus.OK);
}
@Log("配置邮件")
@PutMapping(value = "/email")
@PutMapping
@ApiOperation("配置邮件")
public ResponseEntity emailConfig(@Validated @RequestBody EmailConfig emailConfig){
emailService.update(emailConfig,emailService.find());
return new ResponseEntity(HttpStatus.OK);
}
@Log("发送邮件")
@PostMapping(value = "/email")
@PostMapping
@ApiOperation("发送邮件")
public ResponseEntity send(@Validated @RequestBody EmailVo emailVo) throws Exception {
log.warn("REST request to send Email : {}" +emailVo);
emailService.send(emailVo,emailService.find());
return new ResponseEntity(HttpStatus.OK);
}
......
......@@ -4,7 +4,6 @@ import me.zhengjie.aop.log.Log;
import me.zhengjie.domain.LocalStorage;
import me.zhengjie.service.LocalStorageService;
import me.zhengjie.service.dto.LocalStorageQueryCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
......@@ -14,55 +13,65 @@ import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @author Zheng Jie
* @date 2019-09-05
*/
@Api(tags = "本地存储管理")
@Api(tags = "工具:本地存储管理")
@RestController
@RequestMapping("api")
@RequestMapping("/api/localStorage")
public class LocalStorageController {
@Autowired
private LocalStorageService localStorageService;
private final LocalStorageService localStorageService;
public LocalStorageController(LocalStorageService localStorageService) {
this.localStorageService = localStorageService;
}
@ApiOperation(value = "查询文件")
@GetMapping(value = "/localStorage")
@PreAuthorize("hasAnyRole('ADMIN','LOCALSTORAGE_ALL','LOCALSTORAGE_SELECT')")
@ApiOperation("查询文件")
@GetMapping
@PreAuthorize("@el.check('storage:list')")
public ResponseEntity getLocalStorages(LocalStorageQueryCriteria criteria, Pageable pageable){
return new ResponseEntity(localStorageService.queryAll(criteria,pageable),HttpStatus.OK);
return new ResponseEntity<>(localStorageService.queryAll(criteria,pageable),HttpStatus.OK);
}
@Log("导出数据")
@ApiOperation("导出数据")
@GetMapping(value = "/download")
@PreAuthorize("@el.check('storage:list')")
public void download(HttpServletResponse response, LocalStorageQueryCriteria criteria) throws IOException {
localStorageService.download(localStorageService.queryAll(criteria), response);
}
@ApiOperation(value = "上传文件")
@PostMapping(value = "/localStorage")
@PreAuthorize("hasAnyRole('ADMIN','LOCALSTORAGE_ALL','LOCALSTORAGE_CREATE')")
@ApiOperation("上传文件")
@PostMapping
@PreAuthorize("@el.check('storage:add')")
public ResponseEntity create(@RequestParam String name, @RequestParam("file") MultipartFile file){
return new ResponseEntity(localStorageService.create(name, file),HttpStatus.CREATED);
return new ResponseEntity<>(localStorageService.create(name, file),HttpStatus.CREATED);
}
@ApiOperation(value = "修改文件")
@PutMapping(value = "/localStorage")
@PreAuthorize("hasAnyRole('ADMIN','LOCALSTORAGE_ALL','LOCALSTORAGE_EDIT')")
@ApiOperation("修改文件")
@PutMapping
@PreAuthorize("@el.check('storage:edit')")
public ResponseEntity update(@Validated @RequestBody LocalStorage resources){
localStorageService.update(resources);
return new ResponseEntity(HttpStatus.NO_CONTENT);
}
@ApiOperation(value = "删除文件")
@DeleteMapping(value = "/localStorage/{id}")
@PreAuthorize("hasAnyRole('ADMIN','LOCALSTORAGE_ALL','LOCALSTORAGE_DELETE')")
@ApiOperation("删除文件")
@DeleteMapping(value = "/{id}")
@PreAuthorize("@el.check('storage:del')")
public ResponseEntity delete(@PathVariable Long id){
localStorageService.delete(id);
return new ResponseEntity(HttpStatus.OK);
}
/**
* 删除多张图片
* @param ids
* @return
*/
@Log("删除图片")
@DeleteMapping(value = "/localStorage")
@Log("多选删除")
@DeleteMapping
@ApiOperation("多选删除")
public ResponseEntity deleteAll(@RequestBody Long[] ids) {
localStorageService.deleteAll(ids);
return new ResponseEntity(HttpStatus.OK);
......
package me.zhengjie.rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.zhengjie.aop.log.Log;
import me.zhengjie.domain.Picture;
import me.zhengjie.service.PictureService;
import me.zhengjie.service.dto.PictureQueryCriteria;
import me.zhengjie.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
......@@ -20,28 +24,36 @@ import java.util.Map;
* @date 2018/09/20 14:13:32
*/
@RestController
@RequestMapping("/api")
@RequestMapping("/api/pictures")
@Api(tags = "工具:免费图床管理")
public class PictureController {
@Autowired
private PictureService pictureService;
private final PictureService pictureService;
public PictureController(PictureService pictureService) {
this.pictureService = pictureService;
}
@Log("查询图片")
@PreAuthorize("hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_SELECT')")
@GetMapping(value = "/pictures")
@PreAuthorize("@el.check('pictures:list')")
@GetMapping
@ApiOperation("查询图片")
public ResponseEntity getRoles(PictureQueryCriteria criteria, Pageable pageable){
return new ResponseEntity(pictureService.queryAll(criteria,pageable),HttpStatus.OK);
return new ResponseEntity<>(pictureService.queryAll(criteria,pageable),HttpStatus.OK);
}
@Log("导出数据")
@ApiOperation("导出数据")
@GetMapping(value = "/download")
@PreAuthorize("@el.check('pictures:list')")
public void download(HttpServletResponse response, PictureQueryCriteria criteria) throws IOException {
pictureService.download(pictureService.queryAll(criteria), response);
}
/**
* 上传图片
* @param file
* @return
* @throws Exception
*/
@Log("上传图片")
@PreAuthorize("hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_UPLOAD')")
@PostMapping(value = "/pictures")
@PreAuthorize("@el.check('pictures:add')")
@PostMapping
@ApiOperation("上传图片")
public ResponseEntity upload(@RequestParam MultipartFile file){
String userName = SecurityUtils.getUsername();
Picture picture = pictureService.upload(file,userName);
......@@ -49,30 +61,22 @@ public class PictureController {
map.put("errno",0);
map.put("id",picture.getId());
map.put("data",new String[]{picture.getUrl()});
return new ResponseEntity(map,HttpStatus.OK);
return new ResponseEntity<>(map,HttpStatus.OK);
}
/**
* 删除图片
* @param id
* @return
*/
@Log("删除图片")
@PreAuthorize("hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_DELETE')")
@DeleteMapping(value = "/pictures/{id}")
@ApiOperation("删除图片")
@PreAuthorize("@el.check('pictures:del')")
@DeleteMapping(value = "/{id}")
public ResponseEntity delete(@PathVariable Long id) {
pictureService.delete(pictureService.findById(id));
return new ResponseEntity(HttpStatus.OK);
}
/**
* 删除多张图片
* @param ids
* @return
*/
@Log("删除图片")
@PreAuthorize("hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_DELETE')")
@DeleteMapping(value = "/pictures")
@Log("多选删除图片")
@ApiOperation("多选删除图片")
@PreAuthorize("@el.check('pictures:del')")
@DeleteMapping
public ResponseEntity deleteAll(@RequestBody Long[] ids) {
pictureService.deleteAll(ids);
return new ResponseEntity(HttpStatus.OK);
......
package me.zhengjie.rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.aop.log.Log;
import me.zhengjie.domain.QiniuConfig;
import me.zhengjie.domain.QiniuContent;
import me.zhengjie.service.QiNiuService;
import me.zhengjie.service.dto.QiniuQueryCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
......@@ -23,93 +26,84 @@ import java.util.Map;
*/
@Slf4j
@RestController
@RequestMapping("api")
@RequestMapping("/api/qiNiuContent")
@Api(tags = "工具:七牛云存储管理")
public class QiniuController {
@Autowired
private QiNiuService qiNiuService;
private final QiNiuService qiNiuService;
@GetMapping(value = "/qiNiuConfig")
public QiniuController(QiNiuService qiNiuService) {
this.qiNiuService = qiNiuService;
}
@GetMapping(value = "/config")
public ResponseEntity get(){
return new ResponseEntity(qiNiuService.find(), HttpStatus.OK);
return new ResponseEntity<>(qiNiuService.find(), HttpStatus.OK);
}
@Log("配置七牛云存储")
@PutMapping(value = "/qiNiuConfig")
@ApiOperation("配置七牛云存储")
@PutMapping(value = "/config")
public ResponseEntity emailConfig(@Validated @RequestBody QiniuConfig qiniuConfig){
qiNiuService.update(qiniuConfig);
qiNiuService.update(qiniuConfig.getType());
return new ResponseEntity(HttpStatus.OK);
}
@Log("导出数据")
@ApiOperation("导出数据")
@GetMapping(value = "/download/list")
public void download(HttpServletResponse response, QiniuQueryCriteria criteria) throws IOException {
qiNiuService.downloadList(qiNiuService.queryAll(criteria), response);
}
@Log("查询文件")
@GetMapping(value = "/qiNiuContent")
@ApiOperation("查询文件")
@GetMapping
public ResponseEntity getRoles(QiniuQueryCriteria criteria, Pageable pageable){
return new ResponseEntity(qiNiuService.queryAll(criteria,pageable),HttpStatus.OK);
return new ResponseEntity<>(qiNiuService.queryAll(criteria,pageable),HttpStatus.OK);
}
/**
* 上传文件到七牛云
* @param file
* @return
*/
@Log("上传文件")
@PostMapping(value = "/qiNiuContent")
@ApiOperation("上传文件")
@PostMapping
public ResponseEntity upload(@RequestParam MultipartFile file){
QiniuContent qiniuContent = qiNiuService.upload(file,qiNiuService.find());
Map map = new HashMap(3);
Map<String,Object> map = new HashMap<>(3);
map.put("id",qiniuContent.getId());
map.put("errno",0);
map.put("data",new String[]{qiniuContent.getUrl()});
return new ResponseEntity(map,HttpStatus.OK);
return new ResponseEntity<>(map,HttpStatus.OK);
}
/**
* 同步七牛云数据到数据库
* @return
*/
@Log("同步七牛云数据")
@PostMapping(value = "/qiNiuContent/synchronize")
@ApiOperation("同步七牛云数据")
@PostMapping(value = "/synchronize")
public ResponseEntity synchronize(){
log.warn("REST request to synchronize qiNiu : {}");
qiNiuService.synchronize(qiNiuService.find());
return new ResponseEntity(HttpStatus.OK);
}
/**
* 下载七牛云文件
* @param id
* @return
* @throws Exception
*/
@Log("下载文件")
@GetMapping(value = "/qiNiuContent/download/{id}")
@ApiOperation("下载文件")
@GetMapping(value = "/download/{id}")
public ResponseEntity download(@PathVariable Long id){
Map map = new HashMap(1);
Map<String,Object> map = new HashMap<>(1);
map.put("url", qiNiuService.download(qiNiuService.findByContentId(id),qiNiuService.find()));
return new ResponseEntity(map,HttpStatus.OK);
return new ResponseEntity<>(map,HttpStatus.OK);
}
/**
* 删除七牛云文件
* @param id
* @return
* @throws Exception
*/
@Log("删除文件")
@DeleteMapping(value = "/qiNiuContent/{id}")
@ApiOperation("删除文件")
@DeleteMapping(value = "/{id}")
public ResponseEntity delete(@PathVariable Long id){
qiNiuService.delete(qiNiuService.findByContentId(id),qiNiuService.find());
return new ResponseEntity(HttpStatus.OK);
}
/**
* 删除多张图片
* @param ids
* @return
*/
@Log("删除图片")
@DeleteMapping(value = "/qiNiuContent")
@Log("删除多张图片")
@ApiOperation("删除多张图片")
@DeleteMapping
public ResponseEntity deleteAll(@RequestBody Long[] ids) {
qiNiuService.deleteAll(ids, qiNiuService.find());
return new ResponseEntity(HttpStatus.OK);
......
package me.zhengjie.rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.zhengjie.domain.VerificationCode;
import me.zhengjie.domain.vo.EmailVo;
import me.zhengjie.service.EmailService;
import me.zhengjie.service.VerificationCodeService;
import me.zhengjie.utils.ElAdminConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.web.bind.annotation.*;
/**
......@@ -17,20 +16,21 @@ import org.springframework.web.bind.annotation.*;
* @date 2018-12-26
*/
@RestController
@RequestMapping("api")
@RequestMapping("/api/code")
@Api(tags = "工具:验证码管理")
public class VerificationCodeController {
@Autowired
private VerificationCodeService verificationCodeService;
private final VerificationCodeService verificationCodeService;
@Autowired
@Qualifier("jwtUserDetailsService")
private UserDetailsService userDetailsService;
private final EmailService emailService;
@Autowired
private EmailService emailService;
public VerificationCodeController(VerificationCodeService verificationCodeService, EmailService emailService) {
this.verificationCodeService = verificationCodeService;
this.emailService = emailService;
}
@PostMapping(value = "/code/resetEmail")
@PostMapping(value = "/resetEmail")
@ApiOperation("重置邮箱,发送验证码")
public ResponseEntity resetEmail(@RequestBody VerificationCode code) throws Exception {
code.setScenes(ElAdminConstant.RESET_MAIL);
EmailVo emailVo = verificationCodeService.sendEmail(code);
......@@ -38,7 +38,8 @@ public class VerificationCodeController {
return new ResponseEntity(HttpStatus.OK);
}
@PostMapping(value = "/code/email/resetPass")
@PostMapping(value = "/email/resetPass")
@ApiOperation("重置密码,发送验证码")
public ResponseEntity resetPass(@RequestParam String email) throws Exception {
VerificationCode code = new VerificationCode();
code.setType("email");
......@@ -49,7 +50,8 @@ public class VerificationCodeController {
return new ResponseEntity(HttpStatus.OK);
}
@GetMapping(value = "/code/validated")
@GetMapping(value = "/validated")
@ApiOperation("验证码验证")
public ResponseEntity validated(VerificationCode code){
verificationCodeService.validated(code);
return new ResponseEntity(HttpStatus.OK);
......
......@@ -2,47 +2,41 @@ package me.zhengjie.service;
import me.zhengjie.domain.AlipayConfig;
import me.zhengjie.domain.vo.TradeVo;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
/**
* @author Zheng Jie
* @date 2018-12-31
*/
@CacheConfig(cacheNames = "alipay")
public interface AlipayService {
/**
* 处理来自PC的交易请求
* @param alipay
* @param trade
* @return
* @throws Exception
* @param alipay 支付宝配置
* @param trade 交易详情
* @return String
* @throws Exception 异常
*/
String toPayAsPC(AlipayConfig alipay, TradeVo trade) throws Exception;
/**
* 处理来自手机网页的交易请求
* @param alipay
* @param trade
* @return
* @throws Exception
* @param alipay 支付宝配置
* @param trade 交易详情
* @return String
* @throws Exception 异常
*/
String toPayAsWeb(AlipayConfig alipay, TradeVo trade) throws Exception;
/**
* 查询配置
* @return
* @return AlipayConfig
*/
@Cacheable(key = "'1'")
AlipayConfig find();
/**
* 更新配置
* @param alipayConfig
* @return
* @param alipayConfig 支付宝配置
* @return AlipayConfig
*/
@CachePut(key = "'1'")
AlipayConfig update(AlipayConfig alipayConfig);
}
......@@ -2,39 +2,33 @@ package me.zhengjie.service;
import me.zhengjie.domain.EmailConfig;
import me.zhengjie.domain.vo.EmailVo;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.scheduling.annotation.Async;
/**
* @author Zheng Jie
* @date 2018-12-26
*/
@CacheConfig(cacheNames = "email")
public interface EmailService {
/**
* 更新邮件配置
* @param emailConfig
* @param old
* @return
* @param emailConfig 邮件配置
* @param old 旧的配置
* @return EmailConfig
*/
@CachePut(key = "'1'")
EmailConfig update(EmailConfig emailConfig, EmailConfig old);
/**
* 查询配置
* @return
* @return EmailConfig 邮件配置
*/
@Cacheable(key = "'1'")
EmailConfig find();
/**
* 发送邮件
* @param emailVo
* @param emailConfig
* @throws Exception
* @param emailVo 邮件发送的内容
* @param emailConfig 邮件配置
* @throws Exception /
*/
@Async
void send(EmailVo emailVo, EmailConfig emailConfig) throws Exception;
......
......@@ -3,67 +3,32 @@ package me.zhengjie.service;
import me.zhengjie.domain.LocalStorage;
import me.zhengjie.service.dto.LocalStorageDTO;
import me.zhengjie.service.dto.LocalStorageQueryCriteria;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
* @author Zheng Jie
* @date 2019-09-05
*/
@CacheConfig(cacheNames = "localStorage")
public interface LocalStorageService {
/**
* queryAll 分页
* @param criteria
* @param pageable
* @return
*/
@Cacheable
Object queryAll(LocalStorageQueryCriteria criteria, Pageable pageable);
/**
* queryAll 不分页
* @param criteria
* @return
*/
@Cacheable
public Object queryAll(LocalStorageQueryCriteria criteria);
List<LocalStorageDTO> queryAll(LocalStorageQueryCriteria criteria);
/**
* findById
* @param id
* @return
*/
@Cacheable(key = "#p0")
LocalStorageDTO findById(Long id);
/**
* create
* @param name
* @param file
* @return
*/
@CacheEvict(allEntries = true)
LocalStorageDTO create(String name, MultipartFile file);
/**
* update
* @param resources
*/
@CacheEvict(allEntries = true)
void update(LocalStorage resources);
/**
* delete
* @param id
*/
@CacheEvict(allEntries = true)
void delete(Long id);
@CacheEvict(allEntries = true)
void deleteAll(Long[] ids);
void download(List<LocalStorageDTO> queryAll, HttpServletResponse response) throws IOException;
}
\ No newline at end of file
......@@ -2,55 +2,30 @@ package me.zhengjie.service;
import me.zhengjie.domain.Picture;
import me.zhengjie.service.dto.PictureQueryCriteria;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
* @author Zheng Jie
* @date 2018-12-27
*/
@CacheConfig(cacheNames = "picture")
public interface PictureService {
/**
* 查询图片
* @param criteria
* @param pageable
* @return
*/
@Cacheable
Object queryAll(PictureQueryCriteria criteria, Pageable pageable);
List<Picture> queryAll(PictureQueryCriteria criteria);
/**
* 上传图片
* @param file
* @param username
* @return
*/
@CacheEvict(allEntries = true)
Picture upload(MultipartFile file, String username);
/**
* 根据ID查询
* @param id
* @return
*/
@Cacheable(key = "#p0")
Picture findById(Long id);
/**
* 删除图片
* @param picture
*/
@CacheEvict(allEntries = true)
void delete(Picture picture);
/**
* 删除图片
* @param ids
*/
@CacheEvict(allEntries = true)
void deleteAll(Long[] ids);
void download(List<Picture> queryAll, HttpServletResponse response) throws IOException;
}
......@@ -3,94 +3,89 @@ package me.zhengjie.service;
import me.zhengjie.domain.QiniuConfig;
import me.zhengjie.domain.QiniuContent;
import me.zhengjie.service.dto.QiniuQueryCriteria;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
* @author Zheng Jie
* @date 2018-12-31
*/
@CacheConfig(cacheNames = "qiNiu")
public interface QiNiuService {
/**
* 查询文件
* @param criteria
* @param pageable
* @return
*/
@Cacheable
Object queryAll(QiniuQueryCriteria criteria, Pageable pageable);
List<QiniuContent> queryAll(QiniuQueryCriteria criteria);
/**
* 查配置
* @return
* @return Cacheable
*/
@Cacheable(cacheNames = "qiNiuConfig", key = "'1'")
QiniuConfig find();
/**
* 修改配置
* @param qiniuConfig
* @return
* @param qiniuConfig 配置
* @return QiniuConfig
*/
@CachePut(cacheNames = "qiNiuConfig", key = "'1'")
QiniuConfig update(QiniuConfig qiniuConfig);
/**
* 上传文件
* @param file
* @param qiniuConfig
* @return
* @param file 文件
* @param qiniuConfig 配置
* @return QiniuContent
*/
@CacheEvict(allEntries = true)
QiniuContent upload(MultipartFile file, QiniuConfig qiniuConfig);
/**
* 查询文件
* @param id
* @return
* @param id 文件ID
* @return QiniuContent
*/
@Cacheable(key = "'content:'+#p0")
QiniuContent findByContentId(Long id);
/**
* 下载文件
* @param content
* @param config
* @return
* @param content 文件信息
* @param config 配置
* @return String
*/
String download(QiniuContent content, QiniuConfig config);
/**
* 删除文件
* @param content
* @param config
* @return
* @param content 文件
* @param config 配置
*/
@CacheEvict(allEntries = true)
void delete(QiniuContent content, QiniuConfig config);
/**
* 同步数据
* @param config
* @param config 配置
*/
@CacheEvict(allEntries = true)
void synchronize(QiniuConfig config);
/**
* 删除文件
* @param ids
* @param config
* @param ids 文件ID数组
* @param config 配置
*/
@CacheEvict(allEntries = true)
void deleteAll(Long[] ids, QiniuConfig config);
@CacheEvict(allEntries = true)
/**
* 更新数据
* @param type 类型
*/
void update(String type);
/**
* 导出数据
* @param queryAll /
* @param response /
*/
void downloadList(List<QiniuContent> queryAll, HttpServletResponse response) throws IOException;
}
......@@ -11,13 +11,14 @@ public interface VerificationCodeService {
/**
* 发送邮件验证码
* @param code
* @param code 验证码
* @return EmailVo
*/
EmailVo sendEmail(VerificationCode code);
/**
* 验证
* @param code
* @param code 验证码
*/
void validated(VerificationCode code);
}
package me.zhengjie.service.dto;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import java.sql.Timestamp;
import java.io.Serializable;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* @author Zheng Jie
* @date 2019-09-05
*/
@Data
public class LocalStorageDTO implements Serializable {
@Getter
@Setter
public class LocalStorageDTO implements Serializable {
// ID
private Long id;
......@@ -33,9 +34,5 @@ public class LocalStorageDTO implements Serializable {
// 操作人
private String operate;
// 创建日期
private Timestamp createTime;
// 修改日期
private Timestamp updateTime;
}
\ No newline at end of file
......@@ -14,4 +14,10 @@ public class LocalStorageQueryCriteria{
// 模糊
@Query(blurry = "name,suffix,type,operate,size")
private String blurry;
@Query(type = Query.Type.GREATER_THAN,propName = "createTime")
private Timestamp startTime;
@Query(type = Query.Type.LESS_THAN,propName = "createTime")
private Timestamp endTime;
}
\ No newline at end of file
......@@ -3,6 +3,8 @@ package me.zhengjie.service.dto;
import lombok.Data;
import me.zhengjie.annotation.Query;
import java.sql.Timestamp;
/**
* sm.ms图床
*
......@@ -17,4 +19,10 @@ public class PictureQueryCriteria{
@Query(type = Query.Type.INNER_LIKE)
private String username;
@Query(type = Query.Type.GREATER_THAN,propName = "createTime")
private Timestamp startTime;
@Query(type = Query.Type.LESS_THAN,propName = "createTime")
private Timestamp endTime;
}
......@@ -3,6 +3,8 @@ package me.zhengjie.service.dto;
import lombok.Data;
import me.zhengjie.annotation.Query;
import java.sql.Timestamp;
/**
* @author Zheng Jie
* @date 2019-6-4 09:54:37
......@@ -12,4 +14,10 @@ public class QiniuQueryCriteria{
@Query(type = Query.Type.INNER_LIKE)
private String key;
@Query(type = Query.Type.GREATER_THAN,propName = "updateTime")
private Timestamp startTime;
@Query(type = Query.Type.LESS_THAN,propName = "updateTime")
private Timestamp endTime;
}
......@@ -9,8 +9,9 @@ import me.zhengjie.domain.vo.TradeVo;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.repository.AlipayRepository;
import me.zhengjie.service.AlipayService;
import me.zhengjie.utils.AlipayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
......@@ -21,14 +22,15 @@ import java.util.Optional;
* @date 2018-12-31
*/
@Service
@CacheConfig(cacheNames = "alipay")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class AlipayServiceImpl implements AlipayService {
@Autowired
AlipayUtils alipayUtils;
private final AlipayRepository alipayRepository;
@Autowired
private AlipayRepository alipayRepository;
public AlipayServiceImpl(AlipayRepository alipayRepository) {
this.alipayRepository = alipayRepository;
}
@Override
public String toPayAsPC(AlipayConfig alipay, TradeVo trade) throws Exception {
......@@ -38,21 +40,15 @@ public class AlipayServiceImpl implements AlipayService {
}
AlipayClient alipayClient = new DefaultAlipayClient(alipay.getGatewayUrl(), alipay.getAppID(), alipay.getPrivateKey(), alipay.getFormat(), alipay.getCharset(), alipay.getPublicKey(), alipay.getSignType());
double money = Double.parseDouble(trade.getTotalAmount());
// double money = Double.parseDouble(trade.getTotalAmount());
/**
* 创建API对应的request(电脑网页版)
*/
// 创建API对应的request(电脑网页版)
AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
/**
* 订单完成后返回的页面和异步通知地址
*/
// 订单完成后返回的页面和异步通知地址
request.setReturnUrl(alipay.getReturnUrl());
request.setNotifyUrl(alipay.getNotifyUrl());
/**
* 填充订单参数
*/
// 填充订单参数
request.setBizContent("{" +
" \"out_trade_no\":\""+trade.getOutTradeNo()+"\"," +
" \"product_code\":\"FAST_INSTANT_TRADE_PAY\"," +
......@@ -63,10 +59,7 @@ public class AlipayServiceImpl implements AlipayService {
" \"sys_service_provider_id\":\""+alipay.getSysServiceProviderId()+"\"" +
" }"+
" }");//填充业务参数
/**
* 调用SDK生成表单
* 通过GET方式,口可以获取url
*/
// 调用SDK生成表单, 通过GET方式,口可以获取url
return alipayClient.pageExecute(request, "GET").getBody();
}
......@@ -82,20 +75,10 @@ public class AlipayServiceImpl implements AlipayService {
if(money <= 0 || money >= 5000){
throw new BadRequestException("测试金额过大");
}
/**
* 创建API对应的request(手机网页版)
*/
// 创建API对应的request(手机网页版)
AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
/**
* 订单完成后返回的页面和异步通知地址
*/
request.setReturnUrl(alipay.getReturnUrl());
request.setNotifyUrl(alipay.getNotifyUrl());
/**
* 填充订单参数
*/
request.setBizContent("{" +
" \"out_trade_no\":\""+trade.getOutTradeNo()+"\"," +
" \"product_code\":\"FAST_INSTANT_TRADE_PAY\"," +
......@@ -106,24 +89,18 @@ public class AlipayServiceImpl implements AlipayService {
" \"sys_service_provider_id\":\""+alipay.getSysServiceProviderId()+"\"" +
" }"+
" }");//填充业务参数
/**
* 调用SDK生成表单
* 通过GET方式,口可以获取url
*/
return alipayClient.pageExecute(request, "GET").getBody();
}
@Override
@Cacheable(key = "'1'")
public AlipayConfig find() {
Optional<AlipayConfig> alipayConfig = alipayRepository.findById(1L);
if (alipayConfig.isPresent()){
return alipayConfig.get();
} else {
return new AlipayConfig();
}
return alipayConfig.orElseGet(AlipayConfig::new);
}
@Override
@CachePut(key = "'1'")
@Transactional(rollbackFor = Exception.class)
public AlipayConfig update(AlipayConfig alipayConfig) {
return alipayRepository.save(alipayConfig);
......
......@@ -2,15 +2,15 @@ package me.zhengjie.service.impl;
import cn.hutool.extra.mail.Mail;
import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;
import me.zhengjie.domain.EmailConfig;
import me.zhengjie.domain.vo.EmailVo;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.repository.EmailRepository;
import me.zhengjie.service.EmailService;
import me.zhengjie.utils.ElAdminConstant;
import me.zhengjie.utils.EncryptUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
......@@ -21,13 +21,18 @@ import java.util.Optional;
* @date 2018-12-26
*/
@Service
@CacheConfig(cacheNames = "email")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class EmailServiceImpl implements EmailService {
@Autowired
private EmailRepository emailRepository;
private final EmailRepository emailRepository;
public EmailServiceImpl(EmailRepository emailRepository) {
this.emailRepository = emailRepository;
}
@Override
@CachePut(key = "'1'")
@Transactional(rollbackFor = Exception.class)
public EmailConfig update(EmailConfig emailConfig, EmailConfig old) {
try {
......@@ -42,13 +47,10 @@ public class EmailServiceImpl implements EmailService {
}
@Override
@Cacheable(key = "'1'")
public EmailConfig find() {
Optional<EmailConfig> emailConfig = emailRepository.findById(1L);
if(emailConfig.isPresent()){
return emailConfig.get();
} else {
return new EmailConfig();
}
return emailConfig.orElseGet(EmailConfig::new);
}
@Override
......@@ -57,9 +59,7 @@ public class EmailServiceImpl implements EmailService {
if(emailConfig == null){
throw new BadRequestException("请先配置,再操作");
}
/**
* 封装
*/
// 封装
MailAccount account = new MailAccount();
account.setHost(emailConfig.getHost());
account.setPort(Integer.parseInt(emailConfig.getPort()));
......@@ -71,15 +71,14 @@ public class EmailServiceImpl implements EmailService {
throw new BadRequestException(e.getMessage());
}
account.setFrom(emailConfig.getUser()+"<"+emailConfig.getFromUser()+">");
//ssl方式发送
// ssl方式发送
account.setSslEnable(true);
String content = emailVo.getContent();
/**
* 发送
*/
// 发送
try {
int size = emailVo.getTos().size();
Mail.create(account)
.setTos(emailVo.getTos().toArray(new String[emailVo.getTos().size()]))
.setTos(emailVo.getTos().toArray(new String[size]))
.setTitle(emailVo.getSubject())
.setContent(content)
.setHtml(true)
......
package me.zhengjie.service.impl;
import cn.hutool.core.util.ObjectUtil;
import me.zhengjie.domain.LocalStorage;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.utils.*;
......@@ -8,31 +9,38 @@ import me.zhengjie.service.LocalStorageService;
import me.zhengjie.service.dto.LocalStorageDTO;
import me.zhengjie.service.dto.LocalStorageQueryCriteria;
import me.zhengjie.service.mapper.LocalStorageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.io.File;
import java.util.Optional;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
/**
* @author Zheng Jie
* @date 2019-09-05
*/
@Service
@CacheConfig(cacheNames = "localStorage")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class LocalStorageServiceImpl implements LocalStorageService {
@Autowired
private LocalStorageRepository localStorageRepository;
private final LocalStorageRepository localStorageRepository;
@Autowired
private LocalStorageMapper localStorageMapper;
private final LocalStorageMapper localStorageMapper;
@Value("${file.path}")
private String path;
......@@ -40,25 +48,34 @@ public class LocalStorageServiceImpl implements LocalStorageService {
@Value("${file.maxSize}")
private long maxSize;
public LocalStorageServiceImpl(LocalStorageRepository localStorageRepository, LocalStorageMapper localStorageMapper) {
this.localStorageRepository = localStorageRepository;
this.localStorageMapper = localStorageMapper;
}
@Override
@Cacheable
public Object queryAll(LocalStorageQueryCriteria criteria, Pageable pageable){
Page<LocalStorage> page = localStorageRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(localStorageMapper::toDto));
}
@Override
public Object queryAll(LocalStorageQueryCriteria criteria){
@Cacheable
public List<LocalStorageDTO> queryAll(LocalStorageQueryCriteria criteria){
return localStorageMapper.toDto(localStorageRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}
@Override
public LocalStorageDTO findById(Long id) {
Optional<LocalStorage> localStorage = localStorageRepository.findById(id);
ValidationUtil.isNull(localStorage,"LocalStorage","id",id);
return localStorageMapper.toDto(localStorage.get());
@Cacheable(key = "#p0")
public LocalStorageDTO findById(Long id){
LocalStorage localStorage = localStorageRepository.findById(id).orElseGet(LocalStorage::new);
ValidationUtil.isNull(localStorage.getId(),"LocalStorage","id",id);
return localStorageMapper.toDto(localStorage);
}
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public LocalStorageDTO create(String name, MultipartFile multipartFile) {
FileUtil.checkSize(maxSize, multipartFile.getSize());
......@@ -67,6 +84,9 @@ public class LocalStorageServiceImpl implements LocalStorageService {
// String type = FileUtil.getFileTypeByMimeType(suffix);
String type = FileUtil.getFileType(suffix);
File file = FileUtil.upload(multipartFile, path + type + File.separator);
if(ObjectUtil.isNull(file)){
throw new BadRequestException("上传失败");
}
try {
name = StringUtils.isBlank(name) ? FileUtil.getFileNameNoEx(multipartFile.getOriginalFilename()) : name;
LocalStorage localStorage = new LocalStorage(
......@@ -85,36 +105,49 @@ public class LocalStorageServiceImpl implements LocalStorageService {
}
}
public static void main(String[] args) {
File file = new File("C:\\Users\\Jie\\Pictures\\Saved Pictures\\demo1.jpg");
System.out.println(FileUtil.getType(file));
}
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public void update(LocalStorage resources) {
Optional<LocalStorage> optionalLocalStorage = localStorageRepository.findById(resources.getId());
ValidationUtil.isNull( optionalLocalStorage,"LocalStorage","id",resources.getId());
LocalStorage localStorage = optionalLocalStorage.get();
LocalStorage localStorage = localStorageRepository.findById(resources.getId()).orElseGet(LocalStorage::new);
ValidationUtil.isNull( localStorage.getId(),"LocalStorage","id",resources.getId());
localStorage.copy(resources);
localStorageRepository.save(localStorage);
}
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
LocalStorage storage = localStorageRepository.findById(id).get();
LocalStorage storage = localStorageRepository.findById(id).orElseGet(LocalStorage::new);
FileUtil.del(storage.getPath());
localStorageRepository.delete(storage);
}
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public void deleteAll(Long[] ids) {
for (Long id : ids) {
LocalStorage storage = localStorageRepository.findById(id).get();
LocalStorage storage = localStorageRepository.findById(id).orElseGet(LocalStorage::new);
FileUtil.del(storage.getPath());
localStorageRepository.delete(storage);
}
}
@Override
public void download(List<LocalStorageDTO> queryAll, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (LocalStorageDTO localStorageDTO : queryAll) {
Map<String,Object> map = new LinkedHashMap<>();
map.put("文件名", localStorageDTO.getRealName());
map.put("备注名", localStorageDTO.getName());
map.put("文件类型", localStorageDTO.getType());
map.put("文件大小", localStorageDTO.getSize());
map.put("操作人", localStorageDTO.getOperate());
map.put("创建日期", localStorageDTO.getCreateTime());
list.add(map);
}
FileUtil.downloadExcel(list, response);
}
}
......@@ -11,15 +11,19 @@ import me.zhengjie.repository.PictureRepository;
import me.zhengjie.service.PictureService;
import me.zhengjie.service.dto.PictureQueryCriteria;
import me.zhengjie.utils.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.HashMap;
import java.util.Optional;
import java.io.IOException;
import java.util.*;
/**
* @author Zheng Jie
......@@ -27,41 +31,54 @@ import java.util.Optional;
*/
@Slf4j
@Service(value = "pictureService")
@CacheConfig(cacheNames = "picture")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class PictureServiceImpl implements PictureService {
@Autowired
private PictureRepository pictureRepository;
private final PictureRepository pictureRepository;
private static final String SUCCESS = "success";
public static final String SUCCESS = "success";
private static final String CODE = "code";
public static final String CODE = "code";
private static final String MSG = "message";
public static final String MSG = "message";
public PictureServiceImpl(PictureRepository pictureRepository) {
this.pictureRepository = pictureRepository;
}
@Override
@Cacheable
public Object queryAll(PictureQueryCriteria criteria, Pageable pageable){
return PageUtil.toPage(pictureRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable));
}
@Override
public List<Picture> queryAll(PictureQueryCriteria criteria) {
return pictureRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder));
}
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Throwable.class)
public Picture upload(MultipartFile multipartFile, String username) {
File file = FileUtil.toFile(multipartFile);
// 验证是否重复上传
Picture picture = pictureRepository.findByMd5Code(FileUtil.getMd5(file));
if(picture != null){
return picture;
}
HashMap<String, Object> paramMap = new HashMap<>(1);
paramMap.put("smfile", file);
String result= HttpUtil.post(ElAdminConstant.Url.SM_MS_URL, paramMap);
JSONObject jsonObject = JSONUtil.parseObj(result);
Picture picture = null;
if(!jsonObject.get(CODE).toString().equals(SUCCESS)){
throw new BadRequestException(TranslatorUtil.translate(jsonObject.get(MSG).toString()));
}
//转成实体类
picture = JSON.parseObject(jsonObject.get("data").toString(), Picture.class);
picture.setSize(FileUtil.getSize(Integer.valueOf(picture.getSize())));
picture.setSize(FileUtil.getSize(Integer.parseInt(picture.getSize())));
picture.setUsername(username);
picture.setMd5Code(FileUtil.getMd5(file));
picture.setFilename(FileUtil.getFileNameNoEx(multipartFile.getOriginalFilename())+"."+FileUtil.getExtensionName(multipartFile.getOriginalFilename()));
pictureRepository.save(picture);
//删除临时文件
......@@ -71,28 +88,48 @@ public class PictureServiceImpl implements PictureService {
}
@Override
@Cacheable(key = "#p0")
public Picture findById(Long id) {
Optional<Picture> picture = pictureRepository.findById(id);
ValidationUtil.isNull(picture,"Picture","id",id);
return picture.get();
Picture picture = pictureRepository.findById(id).orElseGet(Picture::new);
ValidationUtil.isNull(picture.getId(),"Picture","id",id);
return picture;
}
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public void delete(Picture picture) {
try {
String result= HttpUtil.get(picture.getDelete());
HttpUtil.get(picture.getDelete());
pictureRepository.delete(picture);
} catch(Exception e){
pictureRepository.delete(picture);
}
}
@Override
@CacheEvict(allEntries = true)
public void deleteAll(Long[] ids) {
for (Long id : ids) {
delete(findById(id));
}
}
@Override
public void download(List<Picture> queryAll, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (Picture picture : queryAll) {
Map<String,Object> map = new LinkedHashMap<>();
map.put("文件名", picture.getFilename());
map.put("图片地址", picture.getUrl());
map.put("文件大小", picture.getSize());
map.put("操作人", picture.getUsername());
map.put("高度", picture.getHeight());
map.put("宽度", picture.getWidth());
map.put("删除地址", picture.getDelete());
map.put("创建日期", picture.getCreateTime());
list.add(map);
}
FileUtil.downloadExcel(list, response);
}
}
......@@ -21,51 +21,62 @@ import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QiNiuUtil;
import me.zhengjie.utils.QueryHelp;
import me.zhengjie.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.util.Optional;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
/**
* @author Zheng Jie
* @date 2018-12-31
*/
@Service
@CacheConfig(cacheNames = "qiNiu")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class QiNiuServiceImpl implements QiNiuService {
@Autowired
private QiNiuConfigRepository qiNiuConfigRepository;
private final QiNiuConfigRepository qiNiuConfigRepository;
@Autowired
private QiniuContentRepository qiniuContentRepository;
private final QiniuContentRepository qiniuContentRepository;
public QiNiuServiceImpl(QiNiuConfigRepository qiNiuConfigRepository, QiniuContentRepository qiniuContentRepository) {
this.qiNiuConfigRepository = qiNiuConfigRepository;
this.qiniuContentRepository = qiniuContentRepository;
}
@Value("${qiniu.max-size}")
private Long maxSize;
private final String TYPE = "公开";
@Override
@Cacheable
public Object queryAll(QiniuQueryCriteria criteria, Pageable pageable){
return PageUtil.toPage(qiniuContentRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable));
}
@Override
public List<QiniuContent> queryAll(QiniuQueryCriteria criteria) {
return qiniuContentRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder));
}
@Override
@Cacheable(key = "'1'")
public QiniuConfig find() {
Optional<QiniuConfig> qiniuConfig = qiNiuConfigRepository.findById(1L);
if(qiniuConfig.isPresent()){
return qiniuConfig.get();
} else {
return new QiniuConfig();
}
return qiniuConfig.orElseGet(QiniuConfig::new);
}
@Override
@CachePut(cacheNames = "qiNiuConfig", key = "'1'")
@Transactional(rollbackFor = Exception.class)
public QiniuConfig update(QiniuConfig qiniuConfig) {
if (!(qiniuConfig.getHost().toLowerCase().startsWith("http://")||qiniuConfig.getHost().toLowerCase().startsWith("https://"))) {
......@@ -76,15 +87,14 @@ public class QiNiuServiceImpl implements QiNiuService {
}
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public QiniuContent upload(MultipartFile file, QiniuConfig qiniuConfig) {
FileUtil.checkSize(maxSize, file.getSize());
if(qiniuConfig.getId() == null){
throw new BadRequestException("请先添加相应配置,再操作");
}
/**
* 构造一个带指定Zone对象的配置类
*/
// 构造一个带指定Zone对象的配置类
Configuration cfg = new Configuration(QiNiuUtil.getRegion(qiniuConfig.getZone()));
UploadManager uploadManager = new UploadManager(cfg);
Auth auth = Auth.create(qiniuConfig.getAccessKey(), qiniuConfig.getSecretKey());
......@@ -113,22 +123,23 @@ public class QiNiuServiceImpl implements QiNiuService {
}
@Override
@Cacheable
public QiniuContent findByContentId(Long id) {
Optional<QiniuContent> qiniuContent = qiniuContentRepository.findById(id);
ValidationUtil.isNull(qiniuContent,"QiniuContent", "id",id);
return qiniuContent.get();
QiniuContent qiniuContent = qiniuContentRepository.findById(id).orElseGet(QiniuContent::new);
ValidationUtil.isNull(qiniuContent.getId(),"QiniuContent", "id",id);
return qiniuContent;
}
@Override
@Cacheable
public String download(QiniuContent content,QiniuConfig config){
String finalUrl = null;
String finalUrl;
String TYPE = "公开";
if(TYPE.equals(content.getType())){
finalUrl = content.getUrl();
} else {
Auth auth = Auth.create(config.getAccessKey(), config.getSecretKey());
/**
* 1小时,可以自定义链接过期时间
*/
// 1小时,可以自定义链接过期时间
long expireInSeconds = 3600;
finalUrl = auth.privateDownloadUrl(content.getUrl(), expireInSeconds);
}
......@@ -136,6 +147,7 @@ public class QiNiuServiceImpl implements QiNiuService {
}
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public void delete(QiniuContent content, QiniuConfig config) {
//构造一个带指定Zone对象的配置类
......@@ -151,6 +163,7 @@ public class QiNiuServiceImpl implements QiNiuService {
}
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public void synchronize(QiniuConfig config) {
if(config.getId() == null){
......@@ -170,7 +183,7 @@ public class QiNiuServiceImpl implements QiNiuService {
BucketManager.FileListIterator fileListIterator = bucketManager.createFileListIterator(config.getBucket(), prefix, limit, delimiter);
while (fileListIterator.hasNext()) {
//处理获取的file list结果
QiniuContent qiniuContent = null;
QiniuContent qiniuContent;
FileInfo[] items = fileListIterator.next();
for (FileInfo item : items) {
if(qiniuContentRepository.findByKey(FileUtil.getFileNameNoEx(item.key)) == null){
......@@ -188,6 +201,7 @@ public class QiNiuServiceImpl implements QiNiuService {
}
@Override
@CacheEvict(allEntries = true)
public void deleteAll(Long[] ids, QiniuConfig config) {
for (Long id : ids) {
delete(findByContentId(id), config);
......@@ -195,8 +209,25 @@ public class QiNiuServiceImpl implements QiNiuService {
}
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public void update(String type) {
qiNiuConfigRepository.update(type);
}
@Override
public void downloadList(List<QiniuContent> queryAll, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (QiniuContent content : queryAll) {
Map<String,Object> map = new LinkedHashMap<>();
map.put("文件名", content.getKey());
map.put("文件类型", content.getSuffix());
map.put("空间名称", content.getBucket());
map.put("文件大小", content.getSize());
map.put("空间类型", content.getType());
map.put("创建日期", content.getUpdateTime());
list.add(map);
}
FileUtil.downloadExcel(list, response);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment