

package com.nantian.sc.cloud.admin.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nantian.sc.cloud.admin.api.entity.SysLog;
import com.nantian.sc.cloud.admin.api.vo.PreLogVo;
import com.nantian.sc.cloud.admin.service.SysLogService;
import com.nantian.sc.cloud.common.core.util.R;
import com.nantian.sc.cloud.common.security.annotation.Inner;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 日志表 前端控制器
 * </p>
 *
 *
 * @since 2017-11-20
 */
@RestController
@AllArgsConstructor
@RequestMapping("/log")
@Api(value = "log", tags = "日志管理模块")
public class SysLogController {
	private final SysLogService sysLogService;

	/**
	 * 简单分页查询
	 *
	 * @param page   分页对象
	 * @param sysLog 系统日志
	 * @param mold 日志类别（1操作日志 2登录日志）
	 * @param beginDate 查询开始日期
	 * @param endDate 查询结束日期
	 * @return
	 */
	@GetMapping("/page")
	public R getLogPage(Page page, SysLog sysLog,String mold,String beginDate,String endDate) {
		return R.ok(sysLogService.getLogPage(page, sysLog,mold,beginDate,endDate));
	}
//	public R getLogPage(Page page, SysLog sysLog) {
//		return R.ok(sysLogService.page(page, Wrappers.query(sysLog)));
//	}
	/**
	 * 删除日志
	 *
	 * @param id ID
	 * @return success/false
	 */
	@DeleteMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('sys_log_del')")
	public R removeById(@PathVariable Long id) {
		return R.ok(sysLogService.removeById(id));
	}

	/**
	 * 插入日志
	 *
	 * @param sysLog 日志实体
	 * @return success/false
	 */
	@Inner
	@PostMapping("/save")
	public R save(@Valid @RequestBody SysLog sysLog) {
		return R.ok(sysLogService.save(sysLog));
	}

	/**
	 * 批量插入前端异常日志
	 *
	 * @param preLogVoList 日志实体
	 * @return success/false
	 */
	@PostMapping("/logs")
	public R saveBatchLogs(@RequestBody List<PreLogVo> preLogVoList) {
		return R.ok(sysLogService.saveBatchLogs(preLogVoList));
	}
}
