mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 17:21:53 +08:00
售后日志优化
This commit is contained in:
parent
b7c0fef63f
commit
2f0aaee823
@ -25,8 +25,6 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class SpringExpressionUtils {
|
public class SpringExpressionUtils {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* spel表达式解析器
|
* spel表达式解析器
|
||||||
*/
|
*/
|
||||||
@ -92,14 +90,14 @@ public class SpringExpressionUtils {
|
|||||||
/**
|
/**
|
||||||
* JoinPoint 切面 批量解析 EL 表达式,转换 jspl参数
|
* JoinPoint 切面 批量解析 EL 表达式,转换 jspl参数
|
||||||
*
|
*
|
||||||
* @param joinPoint 切面点
|
* @param joinPoint 切面点
|
||||||
* @param rvt 返回值
|
* @param info 返回值
|
||||||
* @param expressionStrings EL 表达式数组
|
* @param expressionStrings EL 表达式数组
|
||||||
* @return java.lang.String 结果
|
* @return Map<String, Object> 结果
|
||||||
* @author 陈賝
|
* @author 陈賝
|
||||||
* @since 2023/6/18 11:20
|
* @since 2023/6/18 11:20
|
||||||
*/
|
*/
|
||||||
public static Map<String, Object> parseExpression(JoinPoint joinPoint, Object rvt, List<String> expressionStrings) {
|
public static Map<String, Object> parseExpression(JoinPoint joinPoint, Object info, List<String> expressionStrings) {
|
||||||
// 如果为空,则不进行解析
|
// 如果为空,则不进行解析
|
||||||
if (CollUtil.isEmpty(expressionStrings)) {
|
if (CollUtil.isEmpty(expressionStrings)) {
|
||||||
return MapUtil.newHashMap();
|
return MapUtil.newHashMap();
|
||||||
@ -120,7 +118,7 @@ public class SpringExpressionUtils {
|
|||||||
//替换spel里的变量值为实际值, 比如 #user --> user对象
|
//替换spel里的变量值为实际值, 比如 #user --> user对象
|
||||||
context.setVariable(parameterNames[i], args[i]);
|
context.setVariable(parameterNames[i], args[i]);
|
||||||
}
|
}
|
||||||
context.setVariable("rvt", rvt);
|
context.setVariable("info", info);
|
||||||
}
|
}
|
||||||
// 第二步,逐个参数解析
|
// 第二步,逐个参数解析
|
||||||
Map<String, Object> result = MapUtil.newHashMap(expressionStrings.size(), true);
|
Map<String, Object> result = MapUtil.newHashMap(expressionStrings.size(), true);
|
||||||
|
@ -1,21 +1,22 @@
|
|||||||
package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.enums;
|
package cn.iocoder.yudao.module.trade.enums.aftersale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 售后状态的枚举
|
* 售后操作类型的枚举
|
||||||
*
|
*
|
||||||
* @author 陈賝
|
* @author 陈賝
|
||||||
* @since 2023/6/13 13:53
|
* @since 2023/6/13 13:53
|
||||||
*/
|
*/
|
||||||
public enum AfterSaleStatusEnum {
|
public enum AfterSaleOperateTypeEnum {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 申请中
|
* 用户申请
|
||||||
*/
|
*/
|
||||||
APPLY("申请中");
|
APPLY("用户申请"),
|
||||||
|
;
|
||||||
|
|
||||||
private final String description;
|
private final String description;
|
||||||
|
|
||||||
AfterSaleStatusEnum(String description) {
|
AfterSaleOperateTypeEnum(String description) {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
@ -11,11 +11,8 @@ import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSal
|
|||||||
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSalePageReqVO;
|
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSalePageReqVO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleRefuseReqVO;
|
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleRefuseReqVO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleRespPageItemVO;
|
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleRespPageItemVO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleCreateReqVO;
|
|
||||||
import cn.iocoder.yudao.module.trade.convert.aftersale.TradeAfterSaleConvert;
|
import cn.iocoder.yudao.module.trade.convert.aftersale.TradeAfterSaleConvert;
|
||||||
import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO;
|
import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO;
|
||||||
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.annotations.AfterSaleLog;
|
|
||||||
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.enums.AfterSaleStatusEnum;
|
|
||||||
import cn.iocoder.yudao.module.trade.service.aftersale.TradeAfterSaleService;
|
import cn.iocoder.yudao.module.trade.service.aftersale.TradeAfterSaleService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
@ -113,20 +110,4 @@ public class TradeAfterSaleController {
|
|||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO @陈賝:后续要删除下
|
|
||||||
/**
|
|
||||||
* 售后日志测试
|
|
||||||
*
|
|
||||||
* @param createReqVO
|
|
||||||
* @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Long>
|
|
||||||
* @author 陈賝
|
|
||||||
* @date 2023/6/14 21:39
|
|
||||||
*/
|
|
||||||
@PostMapping(value = "/create")
|
|
||||||
@AfterSaleLog(id = "#createReqVO.orderItemId", content = "'申请售后:售后编号['+#createReqVO.orderItemId+'] , '", operateType = AfterSaleStatusEnum.APPLY)
|
|
||||||
public CommonResult<Long> createAfterSale(@RequestBody AppTradeAfterSaleCreateReqVO createReqVO) {
|
|
||||||
return success(1L);
|
|
||||||
// return success(afterSaleService.createAfterSale(getLoginUserId(), createReqVO));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSa
|
|||||||
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleDeliveryReqVO;
|
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleDeliveryReqVO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSalePageItemRespVO;
|
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSalePageItemRespVO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.app.base.property.AppProductPropertyValueDetailRespVO;
|
import cn.iocoder.yudao.module.trade.controller.app.base.property.AppProductPropertyValueDetailRespVO;
|
||||||
|
import cn.iocoder.yudao.module.trade.enums.aftersale.AfterSaleOperateTypeEnum;
|
||||||
|
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.annotations.AfterSaleLog;
|
||||||
import cn.iocoder.yudao.module.trade.service.aftersale.TradeAfterSaleService;
|
import cn.iocoder.yudao.module.trade.service.aftersale.TradeAfterSaleService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
@ -78,6 +80,7 @@ public class AppTradeAfterSaleController {
|
|||||||
|
|
||||||
@PostMapping(value = "/create")
|
@PostMapping(value = "/create")
|
||||||
@Operation(summary = "申请售后")
|
@Operation(summary = "申请售后")
|
||||||
|
@AfterSaleLog(id = "#info.data", content = "'申请售后:售后编号['+#info.data+'],订单编号['+#createReqVO.orderItemId+'], '", operateType = AfterSaleOperateTypeEnum.APPLY)
|
||||||
public CommonResult<Long> createAfterSale(@RequestBody AppTradeAfterSaleCreateReqVO createReqVO) {
|
public CommonResult<Long> createAfterSale(@RequestBody AppTradeAfterSaleCreateReqVO createReqVO) {
|
||||||
return success(afterSaleService.createAfterSale(getLoginUserId(), createReqVO));
|
return success(afterSaleService.createAfterSale(getLoginUserId(), createReqVO));
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package cn.iocoder.yudao.module.trade.framework.aftersalelog.config;
|
package cn.iocoder.yudao.module.trade.framework.aftersalelog.config;
|
||||||
|
|
||||||
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.aop.AfterSaleLogAspect;
|
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.aop.AfterSaleLogAspect;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* trade 模块的 afterSaleLog 组件的 Configuration
|
* trade 模块的 afterSaleLog 组件的 Configuration
|
||||||
@ -10,7 +10,7 @@ import org.springframework.context.annotation.Bean;
|
|||||||
* @author 陈賝
|
* @author 陈賝
|
||||||
* @since 2023/6/18 11:09
|
* @since 2023/6/18 11:09
|
||||||
*/
|
*/
|
||||||
@AutoConfiguration
|
@Configuration(proxyBeanMethods = false)
|
||||||
public class AfterSaleLogConfiguration {
|
public class AfterSaleLogConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.annotations;
|
package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.annotations;
|
||||||
|
|
||||||
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.enums.AfterSaleStatusEnum;
|
import cn.iocoder.yudao.module.trade.enums.aftersale.AfterSaleOperateTypeEnum;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
@ -10,7 +10,7 @@ import java.lang.annotation.*;
|
|||||||
* @author 陈賝
|
* @author 陈賝
|
||||||
* @since 2023/6/8 17:04
|
* @since 2023/6/8 17:04
|
||||||
*/
|
*/
|
||||||
@Target({ElementType.METHOD,ElementType.TYPE})
|
@Target({ElementType.METHOD, ElementType.TYPE})
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Documented
|
@Documented
|
||||||
public @interface AfterSaleLog {
|
public @interface AfterSaleLog {
|
||||||
@ -23,7 +23,7 @@ public @interface AfterSaleLog {
|
|||||||
/**
|
/**
|
||||||
* 操作类型
|
* 操作类型
|
||||||
*/
|
*/
|
||||||
AfterSaleStatusEnum operateType() default AfterSaleStatusEnum.APPLY;
|
AfterSaleOperateTypeEnum operateType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 日志内容
|
* 日志内容
|
||||||
|
@ -4,13 +4,12 @@ import cn.hutool.core.map.MapUtil;
|
|||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.iocoder.yudao.framework.common.util.spring.SpringExpressionUtils;
|
import cn.iocoder.yudao.framework.common.util.spring.SpringExpressionUtils;
|
||||||
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
|
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
|
||||||
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO;
|
|
||||||
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.annotations.AfterSaleLog;
|
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.annotations.AfterSaleLog;
|
||||||
|
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO;
|
||||||
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service.AfterSaleLogService;
|
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service.AfterSaleLogService;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
|
||||||
import org.aspectj.lang.annotation.AfterReturning;
|
import org.aspectj.lang.annotation.AfterReturning;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.reflect.MethodSignature;
|
import org.aspectj.lang.reflect.MethodSignature;
|
||||||
@ -34,6 +33,11 @@ public class AfterSaleLogAspect {
|
|||||||
@Resource
|
@Resource
|
||||||
private AfterSaleLogService saleLogService;
|
private AfterSaleLogService saleLogService;
|
||||||
|
|
||||||
|
private final static String OPERATE_TYPE = "operateType", ID = "id", CONTENT = "content";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 切面存入日志
|
||||||
|
*/
|
||||||
@AfterReturning(pointcut = "@annotation(afterSaleLog)", returning = "info")
|
@AfterReturning(pointcut = "@annotation(afterSaleLog)", returning = "info")
|
||||||
public void doAfterReturning(JoinPoint joinPoint, AfterSaleLog afterSaleLog, Object info) {
|
public void doAfterReturning(JoinPoint joinPoint, AfterSaleLog afterSaleLog, Object info) {
|
||||||
try {
|
try {
|
||||||
@ -42,10 +46,11 @@ public class AfterSaleLogAspect {
|
|||||||
Long id = WebFrameworkUtils.getLoginUserId();
|
Long id = WebFrameworkUtils.getLoginUserId();
|
||||||
Map<String, String> formatObj = spelFormat(joinPoint, info);
|
Map<String, String> formatObj = spelFormat(joinPoint, info);
|
||||||
TradeAfterSaleLogCreateReqDTO dto = new TradeAfterSaleLogCreateReqDTO()
|
TradeAfterSaleLogCreateReqDTO dto = new TradeAfterSaleLogCreateReqDTO()
|
||||||
.setUserId(id).setUserType(userType)
|
.setUserId(id)
|
||||||
.setAfterSaleId(MapUtil.getLong(formatObj, "id"))
|
.setUserType(userType)
|
||||||
.setContent(formatObj.get("content"))
|
.setAfterSaleId(MapUtil.getLong(formatObj, ID))
|
||||||
.setOperateType(formatObj.get("operateType"));
|
.setOperateType(MapUtil.getStr(formatObj, OPERATE_TYPE))
|
||||||
|
.setContent(MapUtil.getStr(formatObj, CONTENT));
|
||||||
// 异步存入数据库
|
// 异步存入数据库
|
||||||
saleLogService.createLog(dto);
|
saleLogService.createLog(dto);
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
@ -59,21 +64,21 @@ public class AfterSaleLogAspect {
|
|||||||
public static Map<String, String> spelFormat(JoinPoint joinPoint, Object info) {
|
public static Map<String, String> spelFormat(JoinPoint joinPoint, Object info) {
|
||||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||||
AfterSaleLog afterSaleLogPoint = signature.getMethod().getAnnotation(AfterSaleLog.class);
|
AfterSaleLog afterSaleLogPoint = signature.getMethod().getAnnotation(AfterSaleLog.class);
|
||||||
HashMap<String, String> result = Maps.newHashMapWithExpectedSize(3);
|
HashMap<String, String> result = Maps.newHashMapWithExpectedSize(2);
|
||||||
Map<String, Object> spelMap = SpringExpressionUtils.parseExpression(joinPoint, info,
|
Map<String, Object> spelMap = SpringExpressionUtils.parseExpression(joinPoint, info,
|
||||||
asList(afterSaleLogPoint.id(), afterSaleLogPoint.operateType().description(), afterSaleLogPoint.content()));
|
asList(afterSaleLogPoint.id(), afterSaleLogPoint.content()));
|
||||||
// 售后ID
|
// 售后ID
|
||||||
String id = MapUtil.getStr(spelMap, afterSaleLogPoint.id());
|
String id = MapUtil.getStr(spelMap, afterSaleLogPoint.id());
|
||||||
result.put("id", id);
|
result.put(ID, id);
|
||||||
// 操作类型
|
// 操作类型
|
||||||
String operateType = MapUtil.getStr(spelMap, afterSaleLogPoint.operateType().description());
|
String operateType = afterSaleLogPoint.operateType().description();
|
||||||
result.put("operateType", operateType);
|
result.put(OPERATE_TYPE, operateType);
|
||||||
// 日志内容
|
// 日志内容
|
||||||
String content = MapUtil.getStr(spelMap, afterSaleLogPoint.content());
|
String content = MapUtil.getStr(spelMap, afterSaleLogPoint.content());
|
||||||
if (ObjectUtil.isNotNull(afterSaleLogPoint.operateType())) {
|
if (ObjectUtil.isNotNull(afterSaleLogPoint.operateType())) {
|
||||||
content += MapUtil.getStr(spelMap, afterSaleLogPoint.operateType().description());
|
content += operateType;
|
||||||
}
|
}
|
||||||
result.put("content", content);
|
result.put(CONTENT, content);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,6 @@ public class TradeAfterSaleServiceTest extends BaseDbUnitTest {
|
|||||||
AppTradeAfterSaleCreateReqVO createReqVO = new AppTradeAfterSaleCreateReqVO()
|
AppTradeAfterSaleCreateReqVO createReqVO = new AppTradeAfterSaleCreateReqVO()
|
||||||
.setOrderItemId(1L).setRefundPrice(100).setWay(TradeAfterSaleWayEnum.RETURN_AND_REFUND.getWay())
|
.setOrderItemId(1L).setRefundPrice(100).setWay(TradeAfterSaleWayEnum.RETURN_AND_REFUND.getWay())
|
||||||
.setApplyReason("退钱").setApplyDescription("快退")
|
.setApplyReason("退钱").setApplyDescription("快退")
|
||||||
.setOperateType("APPLY")
|
|
||||||
.setApplyPicUrls(asList("https://www.baidu.com/1.png", "https://www.baidu.com/2.png"));
|
.setApplyPicUrls(asList("https://www.baidu.com/1.png", "https://www.baidu.com/2.png"));
|
||||||
// mock 方法(交易订单项)
|
// mock 方法(交易订单项)
|
||||||
TradeOrderItemDO orderItem = randomPojo(TradeOrderItemDO.class, o -> {
|
TradeOrderItemDO orderItem = randomPojo(TradeOrderItemDO.class, o -> {
|
||||||
@ -103,8 +102,6 @@ public class TradeAfterSaleServiceTest extends BaseDbUnitTest {
|
|||||||
assertEquals(afterSaleLog.getUserType(), UserTypeEnum.MEMBER.getValue());
|
assertEquals(afterSaleLog.getUserType(), UserTypeEnum.MEMBER.getValue());
|
||||||
assertEquals(afterSaleLog.getAfterSaleId(), afterSaleId);
|
assertEquals(afterSaleLog.getAfterSaleId(), afterSaleId);
|
||||||
assertPojoEquals(afterSale, orderItem, "id", "creator", "createTime", "updater", "updateTime");
|
assertPojoEquals(afterSale, orderItem, "id", "creator", "createTime", "updater", "updateTime");
|
||||||
// assertNull(afterSaleLog.getBeforeStatus());
|
|
||||||
// assertEquals(afterSaleLog.getAfterStatus(), TradeAfterSaleStatusEnum.APPLY.getStatus());
|
|
||||||
assertEquals(afterSaleLog.getContent(), TradeAfterSaleStatusEnum.APPLY.getContent());
|
assertEquals(afterSaleLog.getContent(), TradeAfterSaleStatusEnum.APPLY.getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user