11 Commits
2b27f02a41
...
5e736e20dd
25 changed files with 644 additions and 479 deletions
-
96src/main/java/com/example/demo/RabbitMQ/CashCollectionAspect.java
-
73src/main/java/com/example/demo/RabbitMQ/CashCollectionConsumer.java
-
96src/main/java/com/example/demo/RabbitMQ/CashRefundAspect.java
-
72src/main/java/com/example/demo/RabbitMQ/CashRefundConsumer.java
-
233src/main/java/com/example/demo/config/RabbitMQConfig.java
-
18src/main/java/com/example/demo/config/interfac/Message.java
-
2src/main/java/com/example/demo/controller/cash/CashRefundController.java
-
67src/main/java/com/example/demo/controller/cash/MessageController.java
-
14src/main/java/com/example/demo/domain/DTO/IdRequest.java
-
28src/main/java/com/example/demo/domain/DTO/MessageDTO.java
-
11src/main/java/com/example/demo/domain/vo/cash/CashCollection.java
-
2src/main/java/com/example/demo/domain/vo/cash/CashRecordRefund.java
-
37src/main/java/com/example/demo/domain/vo/coin/Messages.java
-
2src/main/java/com/example/demo/mapper/cash/CashRefundMapper.java
-
22src/main/java/com/example/demo/mapper/cash/MessageMapper.java
-
15src/main/java/com/example/demo/mapper/coin/OperationLogMapper.java
-
21src/main/java/com/example/demo/service/cash/MessageService.java
-
45src/main/java/com/example/demo/serviceImpl/cash/CashCollectionServiceImpl.java
-
115src/main/java/com/example/demo/serviceImpl/cash/CashRefundServiceImpl.java
-
39src/main/java/com/example/demo/serviceImpl/cash/MessageServiceImpl.java
-
32src/main/resources/cashMapper/CashCollectionMapper.xml
-
37src/main/resources/cashMapper/CashRefundMapper.xml
-
23src/main/resources/cashMapper/MessageMapper.xml
-
17src/main/resources/mapper/MarketMapper.xml
-
6src/main/resources/mapper/RechargeActivityCenterMapper.xml
@ -0,0 +1,96 @@ |
|||
package com.example.demo.RabbitMQ; |
|||
|
|||
import com.example.demo.Util.SecurityUtils; |
|||
import com.example.demo.config.RabbitMQConfig; |
|||
import com.example.demo.config.interfac.Message; |
|||
import com.example.demo.domain.DTO.MessageDTO; |
|||
import com.example.demo.mapper.coin.OperationLogMapper; |
|||
import com.example.demo.mapper.coin.UserMapper; |
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.aspectj.lang.ProceedingJoinPoint; |
|||
import org.aspectj.lang.annotation.Around; |
|||
import org.aspectj.lang.annotation.Aspect; |
|||
import org.aspectj.lang.reflect.MethodSignature; |
|||
import org.springframework.amqp.rabbit.core.RabbitTemplate; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
/** |
|||
* @program: GOLD |
|||
* @ClassName CashCollectionAspect |
|||
* @description: |
|||
* @author: huangqizhen |
|||
* @create: 2025−11-14 19:10 |
|||
* @Version 1.0 |
|||
**/ |
|||
@Aspect |
|||
@Component |
|||
@Slf4j |
|||
public class CashCollectionAspect { |
|||
@Autowired |
|||
private RabbitTemplate rabbitTemplate; |
|||
@Autowired |
|||
private UserMapper userMapper; |
|||
@Autowired |
|||
private OperationLogMapper operationLogMapper; |
|||
@Around("@annotation(com.example.demo.config.interfac.Message)") |
|||
public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable { |
|||
long startTime = System.currentTimeMillis(); |
|||
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); |
|||
String methodName = signature.getName(); |
|||
String className = signature.getDeclaringTypeName(); |
|||
Object[] args = joinPoint.getArgs(); |
|||
|
|||
Message logAnnotation = signature.getMethod().getAnnotation(Message.class); |
|||
String action = logAnnotation.value(); |
|||
|
|||
// ✅ 使用 Spring Security 获取真实用户 |
|||
String username = SecurityUtils.getCurrentUsername(); |
|||
Integer userId = SecurityUtils.getCurrentUserId(); |
|||
String name = userMapper.selectUserByJwcode(Integer.valueOf(username)).getName(); |
|||
|
|||
// 添加空值检查 |
|||
if (userId == null) { |
|||
log.warn("无法获取当前用户ID,使用默认值 -1"); |
|||
userId = -1; // 或者使用其他默认值 |
|||
} |
|||
|
|||
ObjectMapper mapper = new ObjectMapper(); |
|||
String argsJson = "[]"; |
|||
try { |
|||
argsJson = mapper.writeValueAsString(args); |
|||
} catch (Exception e) { |
|||
argsJson = "serialize failed"; |
|||
} |
|||
|
|||
Object result; |
|||
try { |
|||
result = joinPoint.proceed(); |
|||
} catch (Exception e) { |
|||
log.error("方法执行异常: {}", e.getMessage()); |
|||
throw e; |
|||
} |
|||
|
|||
long duration = System.currentTimeMillis() - startTime; |
|||
|
|||
// ✅ 构造日志消息 DTO |
|||
MessageDTO messageDTO = new MessageDTO(); |
|||
messageDTO.setJwcode(Integer.valueOf(username)); |
|||
messageDTO.setName(name); |
|||
messageDTO.setTitle(action); |
|||
messageDTO.setDesc(username+"有一条消息需要处理"); |
|||
// operationLogMapper.insertMessage(messageDTO); |
|||
|
|||
// ✅ 发送消息到 RabbitMQ(不等待) |
|||
try { |
|||
rabbitTemplate.convertAndSend(RabbitMQConfig.CASH_COLLECTION_EXCHANGE, "cash.collection.save", messageDTO); |
|||
log.info("📩 日志消息已发送到 RabbitMQ: {}", action); |
|||
} catch (Exception e) { |
|||
log.error("发送日志消息到 RabbitMQ 失败", e); |
|||
} |
|||
log.info("✅ AOP 拦截完成: {} 执行 [{}] 耗时 {}ms", username, action, duration); |
|||
return result; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,96 @@ |
|||
package com.example.demo.RabbitMQ; |
|||
|
|||
import com.example.demo.Util.SecurityUtils; |
|||
import com.example.demo.config.RabbitMQConfig; |
|||
import com.example.demo.config.interfac.Message; |
|||
import com.example.demo.domain.DTO.MessageDTO; |
|||
import com.example.demo.mapper.coin.OperationLogMapper; |
|||
import com.example.demo.mapper.coin.UserMapper; |
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.aspectj.lang.ProceedingJoinPoint; |
|||
import org.aspectj.lang.annotation.Around; |
|||
import org.aspectj.lang.annotation.Aspect; |
|||
import org.aspectj.lang.reflect.MethodSignature; |
|||
import org.springframework.amqp.rabbit.core.RabbitTemplate; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
/** |
|||
* @program: GOLD |
|||
* @ClassName CashRefundAspect |
|||
* @description: |
|||
* @author: huangqizhen |
|||
* @create: 2025−11-14 19:10 |
|||
* @Version 1.0 |
|||
**/ |
|||
@Aspect |
|||
@Component |
|||
@Slf4j |
|||
public class CashRefundAspect { |
|||
@Autowired |
|||
private RabbitTemplate rabbitTemplate; |
|||
@Autowired |
|||
private UserMapper userMapper; |
|||
@Autowired |
|||
private OperationLogMapper operationLogMapper; |
|||
@Around("@annotation(com.example.demo.config.interfac.Message)") |
|||
public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable { |
|||
long startTime = System.currentTimeMillis(); |
|||
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); |
|||
String methodName = signature.getName(); |
|||
String className = signature.getDeclaringTypeName(); |
|||
Object[] args = joinPoint.getArgs(); |
|||
|
|||
Message logAnnotation = signature.getMethod().getAnnotation(Message.class); |
|||
String action = logAnnotation.value(); |
|||
|
|||
// ✅ 使用 Spring Security 获取真实用户 |
|||
String username = SecurityUtils.getCurrentUsername(); |
|||
Integer userId = SecurityUtils.getCurrentUserId(); |
|||
String name = userMapper.selectUserByJwcode(Integer.valueOf(username)).getName(); |
|||
|
|||
// 添加空值检查 |
|||
if (userId == null) { |
|||
log.warn("无法获取当前用户ID,使用默认值 -1"); |
|||
userId = -1; // 或者使用其他默认值 |
|||
} |
|||
|
|||
ObjectMapper mapper = new ObjectMapper(); |
|||
String argsJson = "[]"; |
|||
try { |
|||
argsJson = mapper.writeValueAsString(args); |
|||
} catch (Exception e) { |
|||
argsJson = "serialize failed"; |
|||
} |
|||
|
|||
Object result; |
|||
try { |
|||
result = joinPoint.proceed(); |
|||
} catch (Exception e) { |
|||
log.error("方法执行异常: {}", e.getMessage()); |
|||
throw e; |
|||
} |
|||
|
|||
long duration = System.currentTimeMillis() - startTime; |
|||
|
|||
// ✅ 构造日志消息 DTO |
|||
MessageDTO messageDTO = new MessageDTO(); |
|||
messageDTO.setJwcode(Integer.valueOf(username)); |
|||
messageDTO.setName(name); |
|||
messageDTO.setTitle(action); |
|||
messageDTO.setDesc(username+"有一条消息需要处理"); |
|||
// operationLogMapper.insertMessage(messageDTO); |
|||
|
|||
// ✅ 发送消息到 RabbitMQ(不等待) |
|||
try { |
|||
rabbitTemplate.convertAndSend(RabbitMQConfig.CASH_COLLECTION_EXCHANGE, "cash.collection.save", messageDTO); |
|||
log.info("📩 日志消息已发送到 RabbitMQ: {}", action); |
|||
} catch (Exception e) { |
|||
log.error("发送日志消息到 RabbitMQ 失败", e); |
|||
} |
|||
log.info("✅ AOP 拦截完成: {} 执行 [{}] 耗时 {}ms", username, action, duration); |
|||
return result; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
package com.example.demo.config.interfac; |
|||
|
|||
import java.lang.annotation.*; |
|||
|
|||
/** |
|||
* @program: GOLD |
|||
* @ClassName Message |
|||
* @description: |
|||
* @author: huangqizhen |
|||
* @create: 2025−11-14 19:12 |
|||
* @Version 1.0 |
|||
**/ |
|||
@Target(ElementType.METHOD) |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
@Documented |
|||
public @interface Message { |
|||
String value() default ""; |
|||
} |
|||
@ -0,0 +1,67 @@ |
|||
package com.example.demo.controller.cash; |
|||
|
|||
import com.example.demo.Util.JWTUtil; |
|||
import com.example.demo.domain.DTO.IdRequest; |
|||
import com.example.demo.domain.entity.Admin; |
|||
import com.example.demo.domain.vo.coin.Result; |
|||
import com.example.demo.service.cash.MessageService; |
|||
import com.example.demo.service.coin.MarketService; |
|||
import jakarta.servlet.http.HttpServletRequest; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
import org.springframework.web.context.request.RequestContextHolder; |
|||
import org.springframework.web.context.request.ServletRequestAttributes; |
|||
|
|||
|
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @program: GOLD |
|||
* @ClassName MessageController |
|||
* @description: |
|||
* @author: huangqizhen |
|||
* @create: 2025−11-14 22:12 |
|||
* @Version 1.0 |
|||
**/ |
|||
@RestController |
|||
@RequestMapping("/getMessage") |
|||
@RequiredArgsConstructor |
|||
@Slf4j |
|||
@CrossOrigin |
|||
public class MessageController { |
|||
@Autowired |
|||
private MessageService messageService; |
|||
@Autowired |
|||
private MarketService marketService; |
|||
@PostMapping |
|||
public Result getMessage() throws Exception { |
|||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
|||
String token = request.getHeader("token"); |
|||
|
|||
// 解析 token 获取用户信息 |
|||
Admin admin = (Admin) JWTUtil.getUserDetailsList(String.valueOf(token), Admin.class); |
|||
List<String> userMarkets = Arrays.asList(StringUtils.split(admin.getMarkets(), ",")); |
|||
List<String> markets = marketService.getMarketIds(userMarkets); |
|||
|
|||
// 权限校验逻辑 |
|||
if (markets.contains("9") || markets.contains("9999")) { |
|||
markets=null; |
|||
} |
|||
return Result.success(messageService.getMessage(markets)); |
|||
} |
|||
@PostMapping("/update") |
|||
public Result update(@RequestBody IdRequest idRequest) throws Exception { |
|||
try { |
|||
Integer id = idRequest.getId(); |
|||
messageService.update(id); |
|||
return Result.success(); |
|||
} |
|||
catch (Exception e) { |
|||
return Result.error("更新失败"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
package com.example.demo.domain.DTO; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
|
|||
// 1. 定义一个极简 DTO(可复用) |
|||
@Data |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class IdRequest { |
|||
private Integer id; |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
package com.example.demo.domain.DTO; |
|||
|
|||
import com.stripe.model.tax.Registration; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
/** |
|||
* @program: GOLD |
|||
* @ClassName MessageDTO |
|||
* @description: |
|||
* @author: huangqizhen |
|||
* @create: 2025−11-14 19:15 |
|||
* @Version 1.0 |
|||
**/ |
|||
@Data |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class MessageDTO { |
|||
private Integer id; |
|||
private Integer jwcode; |
|||
private String name; |
|||
private String title; |
|||
private String desc; |
|||
private Integer status; |
|||
private Integer type; |
|||
private Integer typeId; |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
package com.example.demo.domain.vo.coin; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.stripe.model.tax.Registration; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* @program: GOLD |
|||
* @ClassName Messages |
|||
* @description: |
|||
* @author: huangqizhen |
|||
* @create: 2025−11-14 18:01 |
|||
* @Version 1.0 |
|||
**/ |
|||
@Data |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class Messages { |
|||
private Integer id;//id |
|||
private Integer jwcode;//精网号 |
|||
private String name;// 姓名 |
|||
private String title;//标题 |
|||
private String desc; |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai") |
|||
private Date czTime; // 创建时间 |
|||
private Integer status;//状态 |
|||
private Integer type; |
|||
private Integer typeId; |
|||
private Integer market; |
|||
private Integer flag; |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
package com.example.demo.mapper.cash; |
|||
|
|||
import com.example.demo.domain.vo.coin.Messages; |
|||
import com.example.demo.service.cash.MessageService; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @program: GOLD |
|||
* @ClassName MessageMapper |
|||
* @description: |
|||
* @author: huangqizhen |
|||
* @create: 2025−11-14 22:24 |
|||
* @Version 1.0 |
|||
**/ |
|||
@Mapper |
|||
public interface MessageMapper { |
|||
List<Messages> getMessage(List<String> markets); |
|||
|
|||
void update(Integer id); |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
package com.example.demo.service.cash; |
|||
|
|||
import com.example.demo.domain.vo.coin.Messages; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @program: GOLD |
|||
* @ClassName MessageService |
|||
* @description: |
|||
* @author: huangqizhen |
|||
* @create: 2025−11-14 22:13 |
|||
* @Version 1.0 |
|||
**/ |
|||
@Service |
|||
public interface MessageService { |
|||
List<Messages> getMessage(List<String> markets); |
|||
|
|||
void update(Integer id) throws Exception; |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
package com.example.demo.serviceImpl.cash; |
|||
|
|||
import com.example.demo.domain.vo.coin.Messages; |
|||
import com.example.demo.service.cash.MessageService; |
|||
import com.example.demo.mapper.cash.MessageMapper; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @program: GOLD |
|||
* @ClassName MessageServiceImpl |
|||
* @description: |
|||
* @author: huangqizhen |
|||
* @create: 2025−11-14 22:23 |
|||
* @Version 1.0 |
|||
**/ |
|||
@Service |
|||
@Transactional |
|||
public class MessageServiceImpl implements MessageService { |
|||
@Autowired |
|||
private MessageMapper messageMapper; |
|||
@Override |
|||
public List<Messages> getMessage(List<String> markets) { |
|||
return messageMapper.getMessage(markets) ; |
|||
} |
|||
|
|||
@Override |
|||
public void update(Integer id) throws Exception { |
|||
try { |
|||
messageMapper.update(id); |
|||
} |
|||
catch (Exception e){ |
|||
throw new Exception("更新失败"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
<mapper namespace="com.example.demo.mapper.cash.MessageMapper"> |
|||
<update id="update"> |
|||
update message |
|||
set flag=1 |
|||
where id=#{id} |
|||
</update> |
|||
<select id="getMessage" resultType="com.example.demo.domain.vo.coin.Messages"> |
|||
SELECT id, jwcode, name, title, `desc`, status, market,type, type_id,flag,cz_time |
|||
FROM message |
|||
<where> |
|||
<choose> |
|||
<when test="markets != null and markets.size() > 0"> |
|||
market IN |
|||
<foreach item="item" collection="markets" open="(" separator="," close=")"> |
|||
#{item} |
|||
</foreach> |
|||
</when> |
|||
</choose> |
|||
</where> |
|||
</select> |
|||
</mapper> |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue