package com.seer.teach.mp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seer.teach.mp.entity.MpAgentActivityLogEntity;
import com.seer.teach.mp.mapper.MpAgentActivityLogMapper;
import com.seer.teach.mp.service.IMpAgentActivityLogService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 代理商活动操作日志表 服务实现类
 * </p>
 *
 * @author Lingma
 * @since 2025-12-29
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class MpAgentActivityLogServiceImpl extends ServiceImpl<MpAgentActivityLogMapper, MpAgentActivityLogEntity> implements IMpAgentActivityLogService {

    @Override
    public boolean logOperation(Integer activityId, String operatorId, String operationType,
                               String description, String beforeData, String afterData) {
        try {
            MpAgentActivityLogEntity logEntity = new MpAgentActivityLogEntity();
            logEntity.setActivityId(activityId);
            logEntity.setOperatorId(operatorId);
            logEntity.setOperationType(operationType);
            logEntity.setDescription(description);
            logEntity.setBeforeData(beforeData);
            logEntity.setAfterData(afterData);

            boolean result = this.save(logEntity);
            if (result) {
                log.info("代理商活动操作日志记录成功，活动ID: {}, 操作类型: {}", activityId, operationType);
            } else {
                log.warn("代理商活动操作日志记录失败，活动ID: {}", activityId);
            }
            return result;
        } catch (Exception e) {
            log.error("记录代理商活动操作日志时发生异常，活动ID: {}", activityId, e);
            return false;
        }
    }
}