package org.linlinjava.jz.db.service;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.UnavailableSecurityManagerException;
import org.apache.shiro.subject.Subject;
import org.linlinjava.jz.db.dao.JzOrderLogMapper;
import org.linlinjava.jz.db.domain.JzOrderLog;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * 商城 订单操作日志处理类
 */
@Service
public class JzOrderLogService {

    @Resource
    private JzOrderLogMapper logMapper;

    @Async
    public void add(Integer order_id,String action,String log,short status,int userId) {
        JzOrderLog orderLog = new JzOrderLog();
        try {
            orderLog.setOrderId(order_id);
            orderLog.setAction(action);
            orderLog.setLog(log);
            orderLog.setOrderStatus(status);
            orderLog.setCreateTime(LocalDateTime.now());
            orderLog.setCreateUser(userId);
            orderLog.setCreateTime(LocalDateTime.now());
            logMapper.insertSelective(orderLog);
        } catch (UnavailableSecurityManagerException ex) {
            orderLog.setCreateUser(0);
            logMapper.insertSelective(orderLog);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    @Async
    public void add(JzOrderLog orderLog,int userId) {
        orderLog.setCreateUser(userId);
        orderLog.setCreateTime(LocalDateTime.now());
        logMapper.insertSelective(orderLog);

    }
}
