package org.dromara.zhishu.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.dromara.zhishu.domain.vo.ProductForm;
import org.dromara.zhishu.service.IRunningLogFileService;
import org.dromara.zhishu.util.MapUtils;
import org.dromara.zhishu.util.RunningLogUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;


/**
 * 勾选/Excel表发布商品
 */
@Aspect
@Component
public class GoodsAddAspect {

    // 定义 ThreadLocal 用于存储日志上下文 ID 或操作标识
    private static final ThreadLocal<String> LOG_CONTEXT = new InheritableThreadLocal<>();

    @Autowired
    private IRunningLogFileService runningLogFileService;

    //定义文件类型 goodsAdd
    private final String fileType = "goodsAdd";


    @Pointcut(value = "execution(* org.dromara.zhishu.service.impl.ZhishuShopGoodsServiceImpl.goodsAdd(java.util.Map)) && args(map)", argNames = "map")
    public void goodsAdd(Map map){}


    @Around(value = "goodsAdd(form)", argNames = "joinPoint,form")
    public void goodsAddLog(ProceedingJoinPoint joinPoint, ProductForm form) {
        String contextId = UUID.randomUUID().toString();
        LOG_CONTEXT.set(contextId);
        RunningLogUtils.init(runningLogFileService);
        //写日志
        RunningLogUtils.runningLog(joinPoint, MapUtils.convertToMap(form),"勾选/Excel表发布商品",fileType);
    }


}