package com.imdroid.secapi.dto;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OpLogManager {
    public final static Short OP_TYPE_ADD     = 1;
    public final static Short OP_TYPE_UPDATE  = 2;
    public final static Short OP_TYPE_DEL     = 3;
    public final static Short OP_TYPE_CMD     = 4;

    public final static Short OP_TYPE_LOGIN    = 5;
    public final static Short OP_TYPE_LOGOUT   = 6;

    public final static Short OP_OBJ_USER      = 3;
    public final static Short OP_OBJ_TENANT    = 4;
    public final static Short OP_OBJ_DEVICE    = 5;
    public final static Short OP_OBJ_GROUP     = 6;
    public final static Short OP_OBJ_WARNING   = 7;
    public final static Short OP_OBJ_SYS       = 8;
    public final static Short OP_OBJ_FWD_RECORD = 9;


    @Autowired
    OpLogMapper opLogMapper;

    public void addLog(String userName, Integer tenantId, Short type, Short obj, String content)
    {
        if(userName != null) {
            OperationLog opLog = new OperationLog();
            opLog.setUser_name(userName);
            opLog.setTenantid(tenantId);
            opLog.setOp_type(type);
            opLog.setOp_object(obj);
            if(content.length()>256) content = content.substring(0,250)+"...";
            opLog.setContent(content);
            opLogMapper.insert(opLog);
        }
    }
}
