|
@ -1,10 +1,12 @@ |
|
|
package com.example.demo.controller; |
|
|
package com.example.demo.controller; |
|
|
|
|
|
|
|
|
import com.example.demo.Util.BusinessException; |
|
|
import com.example.demo.Util.BusinessException; |
|
|
|
|
|
import com.example.demo.Util.JWTUtil; |
|
|
import com.example.demo.Util.RedisLockUtil; |
|
|
import com.example.demo.Util.RedisLockUtil; |
|
|
import com.example.demo.domain.DTO.ConsumeDTO; |
|
|
import com.example.demo.domain.DTO.ConsumeDTO; |
|
|
import com.example.demo.domain.DTO.RechargeDTO; |
|
|
import com.example.demo.domain.DTO.RechargeDTO; |
|
|
import com.example.demo.domain.DTO.RefundDTO; |
|
|
import com.example.demo.domain.DTO.RefundDTO; |
|
|
|
|
|
import com.example.demo.domain.entity.Admin; |
|
|
import com.example.demo.domain.entity.Export; |
|
|
import com.example.demo.domain.entity.Export; |
|
|
import com.example.demo.domain.vo.Result; |
|
|
import com.example.demo.domain.vo.Result; |
|
|
import com.example.demo.service.ExportExcelService; |
|
|
import com.example.demo.service.ExportExcelService; |
|
@ -14,6 +16,7 @@ import jakarta.validation.Valid; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.security.core.userdetails.UserDetails; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
import java.util.List; |
|
@ -42,12 +45,14 @@ public class ExportController { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private ExportService exportService; |
|
|
private ExportService exportService; |
|
|
@PostMapping("/export") |
|
|
@PostMapping("/export") |
|
|
public Result export(@RequestBody Export Export)throws Exception{ |
|
|
|
|
|
|
|
|
public Result export(@Valid @RequestBody Export export, @RequestHeader("token") String token) throws Exception { |
|
|
try { |
|
|
try { |
|
|
return Result.success(exportExcelService.getExcel(Export)); |
|
|
|
|
|
|
|
|
UserDetails token1= JWTUtil.getUserDetailsList(String.valueOf(token), Admin.class); |
|
|
|
|
|
export.setAccount(Integer.valueOf(token1.getUsername())); |
|
|
|
|
|
return Result.success(exportExcelService.getExcel(export)); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
log.error("导出失败", e.getMessage()); |
|
|
log.error("导出失败", e.getMessage()); |
|
|
return Result.error("导出失败"+e.getMessage()); |
|
|
|
|
|
|
|
|
return Result.error("导出失败" + e.getMessage()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@PostMapping("/exportRecharge") |
|
|
@PostMapping("/exportRecharge") |
|
@ -90,15 +95,10 @@ public class ExportController { |
|
|
String requestId = UUID.randomUUID().toString(); // 请求 ID(防止误删锁) |
|
|
String requestId = UUID.randomUUID().toString(); // 请求 ID(防止误删锁) |
|
|
long expireTime = 5000; // 锁过期时间(5秒)s |
|
|
long expireTime = 5000; // 锁过期时间(5秒)s |
|
|
try { |
|
|
try { |
|
|
// 尝试获取锁 |
|
|
|
|
|
if (!redisLockUtil.tryLock(lockKey, requestId, expireTime)) { |
|
|
|
|
|
throw new BusinessException("操作太频繁,请稍后重试"); |
|
|
|
|
|
} |
|
|
|
|
|
// 执行业务逻辑 |
|
|
|
|
|
return exportService.addExportConsume(dto); |
|
|
return exportService.addExportConsume(dto); |
|
|
} finally { |
|
|
} finally { |
|
|
// 释放锁 |
|
|
// 释放锁 |
|
|
redisLockUtil.unlock(lockKey, requestId); |
|
|
redisLockUtil.unlock(lockKey, requestId); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |