/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package com.chushang.system.controller;

import com.chushang.common.core.web.AjaxResult;
import com.chushang.common.log.annotation.SysLog;
import com.chushang.common.log.entity.dto.ListLogDTO;
import com.chushang.common.log.enums.BusinessType;
import com.chushang.common.log.service.SysLogService;
import com.chushang.common.mybatis.utils.PageResult;
import com.chushang.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 系统日志
 *
 * @author Mark sunlightcs@gmail.com
 */
@RestController
@RequestMapping("/v1/log")
public class SysLogController {
	@Autowired
	private SysLogService sysLogService;

	/**
	 * 列表
	 */
	@GetMapping("/list")
	@RequiresPermissions("system:log:list")
	public AjaxResult list(ListLogDTO params){
		PageResult page = sysLogService.queryPage(params);
		return AjaxResult.success(page);
	}

	@DeleteMapping(value = "/clean")
	@SysLog(value = "日志",businessType = BusinessType.CLEAR)
	@RequiresPermissions(value = "system:log:delete")
	public AjaxResult cleanLog(){
		sysLogService.cleanLog();
		return AjaxResult.success();
	}

	@DeleteMapping(value = "/{logId}")
	@SysLog(value = "日志",businessType = BusinessType.DELETE)
	@RequiresPermissions(value = "system:log:delete")
	public AjaxResult delLog(@PathVariable Long logId){
		sysLogService.removeById(logId);
		return AjaxResult.success();
	}

}
