Commit bf7c1eeb authored by dqjdda's avatar dqjdda
Browse files

代码优化完成,去除大量idea警告,代码生成器优化等

parent e3c3ebb1
......@@ -8,16 +8,11 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @author ${author}
* @date ${date}
*/
public interface ${className}Repository extends JpaRepository<${className}, ${pkColumnType}>, JpaSpecificationExecutor {
public interface ${className}Repository extends JpaRepository<${className}, ${pkColumnType}>, JpaSpecificationExecutor<${className}> {
<#if columns??>
<#list columns as column>
<#if column.columnKey = 'UNI'>
/**
* findBy${column.capitalColumnName}
* @param ${column.columnName}
* @return
*/
${className} findBy${column.capitalColumnName}(${column.columnType} ${column.columnName});
</#if>
</#list>
......
......@@ -3,9 +3,6 @@ package ${package}.service;
import ${package}.domain.${className};
import ${package}.service.dto.${className}DTO;
import ${package}.service.dto.${className}QueryCriteria;
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 java.util.Map;
import java.util.List;
......@@ -14,53 +11,33 @@ import java.util.List;
* @author ${author}
* @date ${date}
*/
//@CacheConfig(cacheNames = "${changeClassName}")
public interface ${className}Service {
/**
* 查询数据分页
* @param criteria
* @param pageable
* @return
* @param criteria 条件参数
* @param pageable 分页参数
* @return Map<String,Object>
*/
//@Cacheable
Map<String,Object> queryAll(${className}QueryCriteria criteria, Pageable pageable);
/**
* 查询所有数据不分页
* @param criteria
* @return
* @param criteria 条件参数
* @return List<${className}DTO>
*/
//@Cacheable
List<${className}DTO> queryAll(${className}QueryCriteria criteria);
/**
* 根据ID查询
* @param ${pkChangeColName}
* @return
* @param ${pkChangeColName} ID
* @return ${className}DTO
*/
//@Cacheable(key = "#p0")
${className}DTO findById(${pkColumnType} ${pkChangeColName});
/**
* 创建
* @param resources
* @return
*/
//@CacheEvict(allEntries = true)
${className}DTO create(${className} resources);
/**
* 编辑
* @param resources
*/
//@CacheEvict(allEntries = true)
void update(${className} resources);
/**
* 删除
* @param ${pkChangeColName}
*/
//@CacheEvict(allEntries = true)
void delete(${pkColumnType} ${pkChangeColName});
}
\ No newline at end of file
......@@ -16,11 +16,9 @@ import ${package}.service.${className}Service;
import ${package}.service.dto.${className}DTO;
import ${package}.service.dto.${className}QueryCriteria;
import ${package}.service.mapper.${className}Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.Optional;
<#if !auto && pkColumnType = 'Long'>
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
......@@ -28,6 +26,9 @@ import cn.hutool.core.util.IdUtil;
<#if !auto && pkColumnType = 'String'>
import cn.hutool.core.util.IdUtil;
</#if>
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import me.zhengjie.utils.PageUtil;
......@@ -40,34 +41,42 @@ import java.util.Map;
* @date ${date}
*/
@Service
@CacheConfig(cacheNames = "${changeClassName}")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class ${className}ServiceImpl implements ${className}Service {
@Autowired
private ${className}Repository ${changeClassName}Repository;
private final ${className}Repository ${changeClassName}Repository;
@Autowired
private ${className}Mapper ${changeClassName}Mapper;
private final ${className}Mapper ${changeClassName}Mapper;
public ${className}ServiceImpl(${className}Repository ${changeClassName}Repository, ${className}Mapper ${changeClassName}Mapper) {
this.${changeClassName}Repository = ${changeClassName}Repository;
this.${changeClassName}Mapper = ${changeClassName}Mapper;
}
@Override
@Cacheable
public Map<String,Object> queryAll(${className}QueryCriteria criteria, Pageable pageable){
Page<${className}> page = ${changeClassName}Repository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(${changeClassName}Mapper::toDto));
}
@Override
@Cacheable
public List<${className}DTO> queryAll(${className}QueryCriteria criteria){
return ${changeClassName}Mapper.toDto(${changeClassName}Repository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}
@Override
@Cacheable(key = "#p0")
public ${className}DTO findById(${pkColumnType} ${pkChangeColName}) {
Optional<${className}> ${changeClassName} = ${changeClassName}Repository.findById(${pkChangeColName});
ValidationUtil.isNull(${changeClassName},"${className}","${pkChangeColName}",${pkChangeColName});
return ${changeClassName}Mapper.toDto(${changeClassName}.get());
${className} ${changeClassName} = ${changeClassName}Repository.findById(${pkChangeColName}).orElseGet(${className}::new);
ValidationUtil.isNull(${changeClassName}.get${pkCapitalColName}(),"${className}","${pkChangeColName}",${pkChangeColName});
return ${changeClassName}Mapper.toDto(${changeClassName});
}
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public ${className}DTO create(${className} resources) {
<#if !auto && pkColumnType = 'Long'>
......@@ -90,11 +99,11 @@ public class ${className}ServiceImpl implements ${className}Service {
}
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public void update(${className} resources) {
Optional<${className}> optional${className} = ${changeClassName}Repository.findById(resources.get${pkCapitalColName}());
ValidationUtil.isNull( optional${className},"${className}","id",resources.get${pkCapitalColName}());
${className} ${changeClassName} = optional${className}.get();
${className} ${changeClassName} = ${changeClassName}Repository.findById(resources.get${pkCapitalColName}()).orElseGet(${className}::new);
ValidationUtil.isNull( ${changeClassName}.get${pkCapitalColName}(),"${className}","id",resources.get${pkCapitalColName}());
<#if columns??>
<#list columns as column>
<#if column.columnKey = 'UNI'>
......@@ -113,6 +122,7 @@ public class ${className}ServiceImpl implements ${className}Service {
}
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public void delete(${pkColumnType} ${pkChangeColName}) {
${changeClassName}Repository.deleteById(${pkChangeColName});
......
......@@ -13,6 +13,5 @@ public class EladminSystemApplicationTests {
public void contextLoads() {
}
}
......@@ -41,6 +41,9 @@ public class Picture implements Serializable {
@Column(name = "create_time")
private Timestamp createTime;
// 用于检测文件是否重复
private String md5Code;
@Override
public String toString() {
return "Picture{" +
......
......@@ -9,4 +9,8 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @date 2018-12-27
*/
public interface PictureRepository extends JpaRepository<Picture,Long>, JpaSpecificationExecutor<Picture> {
Picture findByUrl(String url);
Picture findByMd5Code(String code);
}
......@@ -9,7 +9,6 @@ import me.zhengjie.domain.vo.TradeVo;
import me.zhengjie.service.AlipayService;
import me.zhengjie.utils.AliPayStatusEnum;
import me.zhengjie.utils.AlipayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
......@@ -27,7 +26,7 @@ import java.util.Map;
@Slf4j
@RestController
@RequestMapping("/api/aliPay")
@Api(tags = "支付宝支付管理")
@Api(tags = "工具:支付宝管理")
public class AliPayController {
private final AlipayUtils alipayUtils;
......@@ -45,6 +44,7 @@ public class AliPayController {
}
@Log("配置支付宝")
@ApiOperation("配置支付宝")
@PutMapping
public ResponseEntity payConfig(@Validated @RequestBody AlipayConfig alipayConfig){
alipayConfig.setId(1L);
......@@ -53,7 +53,7 @@ public class AliPayController {
}
@Log("支付宝PC网页支付")
@ApiOperation(value = "PC网页支付")
@ApiOperation("PC网页支付")
@PostMapping(value = "/toPayAsPC")
public ResponseEntity<String> toPayAsPC(@Validated@RequestBody TradeVo trade) throws Exception{
AlipayConfig alipay = alipayService.find();
......@@ -63,7 +63,7 @@ public class AliPayController {
}
@Log("支付宝手机网页支付")
@ApiOperation(value = "手机网页支付")
@ApiOperation("手机网页支付")
@PostMapping(value = "/toPayAsWeb")
public ResponseEntity<String> toPayAsWeb(@Validated @RequestBody TradeVo trade) throws Exception{
AlipayConfig alipay = alipayService.find();
......@@ -74,8 +74,8 @@ public class AliPayController {
@ApiIgnore
@GetMapping("/return")
@ApiOperation(value = "支付之后跳转的链接")
public ResponseEntity<String> returnPage(HttpServletRequest request, HttpServletResponse response) throws Exception {
@ApiOperation("支付之后跳转的链接")
public ResponseEntity<String> returnPage(HttpServletRequest request, HttpServletResponse response){
AlipayConfig alipay = alipayService.find();
response.setContentType("text/html;charset=" + alipay.getCharset());
//内容验签,防止黑客篡改参数
......@@ -96,8 +96,8 @@ public class AliPayController {
@ApiIgnore
@RequestMapping("/notify")
@ApiOperation(value = "支付异步通知(要公网访问),接收异步通知,检查通知内容app_id、out_trade_no、total_amount是否与请求中的一致,根据trade_status进行后续业务处理")
public ResponseEntity notify(HttpServletRequest request) throws Exception{
@ApiOperation("支付异步通知(要公网访问),接收异步通知,检查通知内容app_id、out_trade_no、total_amount是否与请求中的一致,根据trade_status进行后续业务处理")
public ResponseEntity notify(HttpServletRequest request){
AlipayConfig alipay = alipayService.find();
Map<String, String[]> parameterMap = request.getParameterMap();
//内容验签,防止黑客篡改参数
......@@ -111,9 +111,9 @@ public class AliPayController {
//付款金额
String totalAmount = new String(request.getParameter("total_amount").getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
//验证
// if(tradeStatus.equals(AliPayStatusEnum.SUCCESS.getValue())||tradeStatus.equals(AliPayStatusEnum.FINISHED.getValue())){
// // 验证通过后应该根据业务需要处理订单
// }
if(tradeStatus.equals(AliPayStatusEnum.SUCCESS.getValue())||tradeStatus.equals(AliPayStatusEnum.FINISHED.getValue())){
// 验证通过后应该根据业务需要处理订单
}
return new ResponseEntity(HttpStatus.OK);
}
return new ResponseEntity(HttpStatus.BAD_REQUEST);
......
......@@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.*;
*/
@RestController
@RequestMapping("api/email")
@Api(tags = "邮件管理")
@Api(tags = "工具:邮件管理")
public class EmailController {
private final EmailService emailService;
......@@ -34,7 +34,7 @@ public class EmailController {
@Log("配置邮件")
@PutMapping
@ApiOperation(value = "配置邮件")
@ApiOperation("配置邮件")
public ResponseEntity emailConfig(@Validated @RequestBody EmailConfig emailConfig){
emailService.update(emailConfig,emailService.find());
return new ResponseEntity(HttpStatus.OK);
......@@ -42,7 +42,7 @@ public class EmailController {
@Log("发送邮件")
@PostMapping
@ApiOperation(value = "发送邮件")
@ApiOperation("发送邮件")
public ResponseEntity send(@Validated @RequestBody EmailVo emailVo) throws Exception {
emailService.send(emailVo,emailService.find());
return new ResponseEntity(HttpStatus.OK);
......
......@@ -17,7 +17,7 @@ import org.springframework.web.multipart.MultipartFile;
* @author Zheng Jie
* @date 2019-09-05
*/
@Api(tags = "本地存储管理")
@Api(tags = "工具:本地存储管理")
@RestController
@RequestMapping("/api/localStorage")
public class LocalStorageController {
......@@ -28,21 +28,21 @@ public class LocalStorageController {
this.localStorageService = localStorageService;
}
@ApiOperation(value = "查询文件")
@ApiOperation("查询文件")
@GetMapping
@PreAuthorize("hasAnyRole('ADMIN','LOCALSTORAGE_ALL','LOCALSTORAGE_SELECT')")
public ResponseEntity getLocalStorages(LocalStorageQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(localStorageService.queryAll(criteria,pageable),HttpStatus.OK);
}
@ApiOperation(value = "上传文件")
@ApiOperation("上传文件")
@PostMapping
@PreAuthorize("hasAnyRole('ADMIN','LOCALSTORAGE_ALL','LOCALSTORAGE_CREATE')")
public ResponseEntity create(@RequestParam String name, @RequestParam("file") MultipartFile file){
return new ResponseEntity<>(localStorageService.create(name, file),HttpStatus.CREATED);
}
@ApiOperation(value = "修改文件")
@ApiOperation("修改文件")
@PutMapping
@PreAuthorize("hasAnyRole('ADMIN','LOCALSTORAGE_ALL','LOCALSTORAGE_EDIT')")
public ResponseEntity update(@Validated @RequestBody LocalStorage resources){
......@@ -50,7 +50,7 @@ public class LocalStorageController {
return new ResponseEntity(HttpStatus.NO_CONTENT);
}
@ApiOperation(value = "删除文件")
@ApiOperation("删除文件")
@DeleteMapping(value = "/{id}")
@PreAuthorize("hasAnyRole('ADMIN','LOCALSTORAGE_ALL','LOCALSTORAGE_DELETE')")
public ResponseEntity delete(@PathVariable Long id){
......@@ -60,7 +60,7 @@ public class LocalStorageController {
@Log("多选删除")
@DeleteMapping
@ApiOperation(value = "多选删除")
@ApiOperation("多选删除")
public ResponseEntity deleteAll(@RequestBody Long[] ids) {
localStorageService.deleteAll(ids);
return new ResponseEntity(HttpStatus.OK);
......
......@@ -22,7 +22,7 @@ import java.util.Map;
*/
@RestController
@RequestMapping("/api/pictures")
@Api(tags = "免费图床管理")
@Api(tags = "工具:免费图床管理")
public class PictureController {
private final PictureService pictureService;
......@@ -34,7 +34,7 @@ public class PictureController {
@Log("查询图片")
@PreAuthorize("hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_SELECT')")
@GetMapping
@ApiOperation(value = "查询图片")
@ApiOperation("查询图片")
public ResponseEntity getRoles(PictureQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(pictureService.queryAll(criteria,pageable),HttpStatus.OK);
}
......@@ -42,7 +42,7 @@ public class PictureController {
@Log("上传图片")
@PreAuthorize("hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_UPLOAD')")
@PostMapping
@ApiOperation(value = "上传图片")
@ApiOperation("上传图片")
public ResponseEntity upload(@RequestParam MultipartFile file){
String userName = SecurityUtils.getUsername();
Picture picture = pictureService.upload(file,userName);
......@@ -54,7 +54,7 @@ public class PictureController {
}
@Log("删除图片")
@ApiOperation(value = "删除图片")
@ApiOperation("删除图片")
@PreAuthorize("hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_DELETE')")
@DeleteMapping(value = "/{id}")
public ResponseEntity delete(@PathVariable Long id) {
......@@ -63,7 +63,7 @@ public class PictureController {
}
@Log("多选删除图片")
@ApiOperation(value = "多选删除图片")
@ApiOperation("多选删除图片")
@PreAuthorize("hasAnyRole('ADMIN','PICTURE_ALL','PICTURE_DELETE')")
@DeleteMapping
public ResponseEntity deleteAll(@RequestBody Long[] ids) {
......
......@@ -24,8 +24,8 @@ import java.util.Map;
*/
@Slf4j
@RestController
@RequestMapping("api")
@Api(tags = "七牛云存储管理")
@RequestMapping("/api/qiNiuContent")
@Api(tags = "工具:七牛云存储管理")
public class QiniuController {
private final QiNiuService qiNiuService;
......@@ -34,14 +34,14 @@ public class QiniuController {
this.qiNiuService = qiNiuService;
}
@GetMapping(value = "/qiNiuConfig")
@GetMapping(value = "/config")
public ResponseEntity get(){
return new ResponseEntity<>(qiNiuService.find(), HttpStatus.OK);
}
@Log("配置七牛云存储")
@ApiOperation(value = "配置七牛云存储")
@PutMapping(value = "/qiNiuConfig")
@ApiOperation("配置七牛云存储")
@PutMapping(value = "/config")
public ResponseEntity emailConfig(@Validated @RequestBody QiniuConfig qiniuConfig){
qiNiuService.update(qiniuConfig);
qiNiuService.update(qiniuConfig.getType());
......@@ -49,15 +49,15 @@ public class QiniuController {
}
@Log("查询文件")
@ApiOperation(value = "查询文件")
@GetMapping(value = "/qiNiuContent")
@ApiOperation("查询文件")
@GetMapping
public ResponseEntity getRoles(QiniuQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(qiNiuService.queryAll(criteria,pageable),HttpStatus.OK);
}
@Log("上传文件")
@ApiOperation(value = "上传文件")
@PostMapping(value = "/qiNiuContent")
@ApiOperation("上传文件")
@PostMapping
public ResponseEntity upload(@RequestParam MultipartFile file){
QiniuContent qiniuContent = qiNiuService.upload(file,qiNiuService.find());
Map<String,Object> map = new HashMap<>(3);
......@@ -68,16 +68,16 @@ public class QiniuController {
}
@Log("同步七牛云数据")
@ApiOperation(value = "同步七牛云数据")
@PostMapping(value = "/qiNiuContent/synchronize")
@ApiOperation("同步七牛云数据")
@PostMapping(value = "/synchronize")
public ResponseEntity synchronize(){
qiNiuService.synchronize(qiNiuService.find());
return new ResponseEntity(HttpStatus.OK);
}
@Log("下载文件")
@ApiOperation(value = "下载文件")
@GetMapping(value = "/qiNiuContent/download/{id}")
@ApiOperation("下载文件")
@GetMapping(value = "/download/{id}")
public ResponseEntity download(@PathVariable Long id){
Map<String,Object> map = new HashMap<>(1);
map.put("url", qiNiuService.download(qiNiuService.findByContentId(id),qiNiuService.find()));
......@@ -85,16 +85,16 @@ public class QiniuController {
}
@Log("删除文件")
@ApiOperation(value = "删除文件")
@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);
}
@Log("删除多张图片")
@ApiOperation(value = "删除多张图片")
@DeleteMapping(value = "/qiNiuContent")
@ApiOperation("删除多张图片")
@DeleteMapping
public ResponseEntity deleteAll(@RequestBody Long[] ids) {
qiNiuService.deleteAll(ids, qiNiuService.find());
return new ResponseEntity(HttpStatus.OK);
......
......@@ -7,10 +7,8 @@ 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.Qualifier;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.web.bind.annotation.*;
/**
......@@ -18,21 +16,21 @@ import org.springframework.web.bind.annotation.*;
* @date 2018-12-26
*/
@RestController
@RequestMapping("api")
@Api(tags = "验证码管理")
@RequestMapping("/api/code")
@Api(tags = "工具:验证码管理")
public class VerificationCodeController {
private final VerificationCodeService verificationCodeService;
private final EmailService emailService;
public VerificationCodeController(VerificationCodeService verificationCodeService, @Qualifier("jwtUserDetailsService") UserDetailsService userDetailsService, EmailService emailService) {
public VerificationCodeController(VerificationCodeService verificationCodeService, EmailService emailService) {
this.verificationCodeService = verificationCodeService;
this.emailService = emailService;
}
@PostMapping(value = "/code/resetEmail")
@ApiOperation(value = "重置邮箱,发送验证码")
@PostMapping(value = "/resetEmail")
@ApiOperation("重置邮箱,发送验证码")
public ResponseEntity resetEmail(@RequestBody VerificationCode code) throws Exception {
code.setScenes(ElAdminConstant.RESET_MAIL);
EmailVo emailVo = verificationCodeService.sendEmail(code);
......@@ -40,8 +38,8 @@ public class VerificationCodeController {
return new ResponseEntity(HttpStatus.OK);
}
@PostMapping(value = "/code/email/resetPass")
@ApiOperation(value = "重置密码,发送验证码")
@PostMapping(value = "/email/resetPass")
@ApiOperation("重置密码,发送验证码")
public ResponseEntity resetPass(@RequestParam String email) throws Exception {
VerificationCode code = new VerificationCode();
code.setType("email");
......@@ -52,8 +50,8 @@ public class VerificationCodeController {
return new ResponseEntity(HttpStatus.OK);
}
@GetMapping(value = "/code/validated")
@ApiOperation(value = "验证码验证")
@GetMapping(value = "/validated")
@ApiOperation("验证码验证")
public ResponseEntity validated(VerificationCode code){
verificationCodeService.validated(code);
return new ResponseEntity(HttpStatus.OK);
......
......@@ -10,7 +10,6 @@ import org.springframework.cache.annotation.Cacheable;
* @author Zheng Jie
* @date 2018-12-31
*/
@CacheConfig(cacheNames = "alipay")
public interface AlipayService {
/**
......@@ -35,7 +34,6 @@ public interface AlipayService {
* 查询配置
* @return AlipayConfig
*/
@Cacheable(key = "'1'")
AlipayConfig find();
/**
......@@ -43,6 +41,5 @@ public interface AlipayService {
* @param alipayConfig 支付宝配置
* @return AlipayConfig
*/
@CachePut(key = "'1'")
AlipayConfig update(AlipayConfig alipayConfig);
}
......@@ -2,16 +2,12 @@ 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 {
/**
......@@ -20,14 +16,12 @@ public interface EmailService {
* @param old 旧的配置
* @return EmailConfig
*/
@CachePut(key = "'1'")
EmailConfig update(EmailConfig emailConfig, EmailConfig old);
/**
* 查询配置
* @return EmailConfig 邮件配置
*/
@Cacheable(key = "'1'")
EmailConfig find();
/**
......
......@@ -3,9 +3,6 @@ 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;
......@@ -13,61 +10,19 @@ import org.springframework.web.multipart.MultipartFile;
* @author Zheng Jie
* @date 2019-09-05
*/
@CacheConfig(cacheNames = "localStorage")
public interface LocalStorageService {
/**
* queryAll 分页
* @param criteria 条件参数
* @param pageable 分页参数
* @return Object
*/
@Cacheable
Object queryAll(LocalStorageQueryCriteria criteria, Pageable pageable);
/**
* queryAll 不分页
* @param criteria 条件参数
* @return Object
*/
@Cacheable
Object queryAll(LocalStorageQueryCriteria criteria);
/**
* findById
* @param id
* @return LocalStorageDTO
*/
@Cacheable(key = "#p0")
LocalStorageDTO findById(Long id);
/**
* create
* @param name 文件名称
* @param file 文件资源
* @return LocalStorageDTO
*/
@CacheEvict(allEntries = true)
LocalStorageDTO create(String name, MultipartFile file);
/**
* update
* @param resources 资源实体
*/
@CacheEvict(allEntries = true)
void update(LocalStorage resources);
/**
* delete
* @param id 文件ID
*/
@CacheEvict(allEntries = true)
void delete(Long id);
/**
* 多文件删除
* @param ids 文件数组
*/
@CacheEvict(allEntries = true)
void deleteAll(Long[] ids);
}
\ No newline at end of file
......@@ -2,55 +2,22 @@ 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;
/**
* @author Zheng Jie
* @date 2018-12-27
*/
@CacheConfig(cacheNames = "picture")
public interface PictureService {
/**
* 查询图片
* @param criteria 条件参数
* @param pageable 分页参数
* @return Object
*/
@Cacheable
Object queryAll(PictureQueryCriteria criteria, Pageable pageable);
/**
* 上传图片
* @param file 文件
* @param username 用户名
* @return
*/
@CacheEvict(allEntries = true)
Picture upload(MultipartFile file, String username);
/**
* 根据ID查询
* @param id 文件ID
* @return
*/
@Cacheable(key = "#p0")
Picture findById(Long id);
/**
* 删除图片
* @param picture 图片实体
*/
@CacheEvict(allEntries = true)
void delete(Picture picture);
/**
* 删除图片
* @param ids 文件ID数组
*/
@CacheEvict(allEntries = true)
void deleteAll(Long[] ids);
}
......@@ -3,66 +3,49 @@ 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;
/**
* @author Zheng Jie
* @date 2018-12-31
*/
@CacheConfig(cacheNames = "qiNiu")
public interface QiNiuService {
/**
* 查询文件
* @param criteria 条件参数
* @param pageable 分页参数
* @return Object
*/
@Cacheable
Object queryAll(QiniuQueryCriteria criteria, Pageable pageable);
/**
* 查配置
* @return Cacheable
*/
@Cacheable(cacheNames = "qiNiuConfig", key = "'1'")
QiniuConfig find();
/**
* 修改配置
* @param qiniuConfig
* @param qiniuConfig 配置
* @return QiniuConfig
*/
@CachePut(cacheNames = "qiNiuConfig", key = "'1'")
QiniuConfig update(QiniuConfig qiniuConfig);
/**
* 上传文件
* @param file
* @param qiniuConfig
* @param file 文件
* @param qiniuConfig 配置
* @return QiniuContent
*/
@CacheEvict(allEntries = true)
QiniuContent upload(MultipartFile file, QiniuConfig qiniuConfig);
/**
* 查询文件
* @param id
* @param id 文件ID
* @return QiniuContent
*/
@Cacheable(key = "'content:'+#p0")
QiniuContent findByContentId(Long id);
/**
* 下载文件
* @param content
* @param config
* @param content 文件信息
* @param config 配置
* @return String
*/
String download(QiniuContent content, QiniuConfig config);
......@@ -72,14 +55,12 @@ public interface QiNiuService {
* @param content 文件
* @param config 配置
*/
@CacheEvict(allEntries = true)
void delete(QiniuContent content, QiniuConfig config);
/**
* 同步数据
* @param config 配置
*/
@CacheEvict(allEntries = true)
void synchronize(QiniuConfig config);
/**
......@@ -87,13 +68,11 @@ public interface QiNiuService {
* @param ids 文件ID数组
* @param config 配置
*/
@CacheEvict(allEntries = true)
void deleteAll(Long[] ids, QiniuConfig config);
/**
* 更新数据
* @param type 类型
*/
@CacheEvict(allEntries = true)
void update(String type);
}
......@@ -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,7 +40,7 @@ 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(电脑网页版)
AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
......@@ -91,12 +93,14 @@ public class AlipayServiceImpl implements AlipayService {
}
@Override
@Cacheable(key = "'1'")
public AlipayConfig find() {
Optional<AlipayConfig> alipayConfig = alipayRepository.findById(1L);
return alipayConfig.orElseGet(AlipayConfig::new);
}
@Override
@CachePut(key = "'1'")
@Transactional(rollbackFor = Exception.class)
public AlipayConfig update(AlipayConfig alipayConfig) {
return alipayRepository.save(alipayConfig);
......
......@@ -8,6 +8,9 @@ import me.zhengjie.exception.BadRequestException;
import me.zhengjie.repository.EmailRepository;
import me.zhengjie.service.EmailService;
import me.zhengjie.utils.EncryptUtils;
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;
......@@ -18,6 +21,7 @@ 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 {
......@@ -28,6 +32,7 @@ public class EmailServiceImpl implements EmailService {
}
@Override
@CachePut(key = "'1'")
@Transactional(rollbackFor = Exception.class)
public EmailConfig update(EmailConfig emailConfig, EmailConfig old) {
try {
......@@ -42,6 +47,7 @@ public class EmailServiceImpl implements EmailService {
}
@Override
@Cacheable(key = "'1'")
public EmailConfig find() {
Optional<EmailConfig> emailConfig = emailRepository.findById(1L);
return emailConfig.orElseGet(EmailConfig::new);
......
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.*;
import me.zhengjie.repository.LocalStorageRepository;
import me.zhengjie.service.LocalStorageService;
......@@ -8,11 +10,13 @@ import me.zhengjie.service.dto.LocalStorageDTO;
import me.zhengjie.service.dto.LocalStorageQueryCriteria;
import me.zhengjie.service.mapper.LocalStorageMapper;
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 org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.multipart.MultipartFile;
......@@ -22,6 +26,7 @@ import org.springframework.web.multipart.MultipartFile;
* @date 2019-09-05
*/
@Service
@CacheConfig(cacheNames = "localStorage")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class LocalStorageServiceImpl implements LocalStorageService {
......@@ -41,24 +46,28 @@ public class LocalStorageServiceImpl implements LocalStorageService {
}
@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
@Cacheable
public Object 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 +76,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(
......@@ -86,28 +98,30 @@ public class LocalStorageServiceImpl implements LocalStorageService {
}
@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);
}
......
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