package com.blueland.sys.log.web;


import java.util.Map;
import javax.servlet.http.HttpServletRequest;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blueland.core.util.UserUtils;
import com.blueland.model.TPfSysOplog;
import com.blueland.result.R;
import com.blueland.service.ISysOplogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.blueland.core.util.LogUtil;
import com.blueland.bo.SysOplogEntity;

import io.swagger.annotations.Api;


@Api(value = "sysOplog")
@RestController
@RequestMapping(value = "/api/sysOplog")
public class SysOplogRest {
	@Autowired
	private ISysOplogService sysOplogService;
	
	
	/**
	 *查询list
	 */
	@ResponseBody
	@RequestMapping(value="/list", method = RequestMethod.GET,produces = "application/json;charset=UTF-8")
	public Page<SysOplogEntity> listPage(@RequestParam Map<String,Object> queryParams){
    	queryParams.put("orderByColumns", "T1.create_time DESC");
		Page<SysOplogEntity> page = sysOplogService.findSysOplogPageListByParams(queryParams,Integer.parseInt(queryParams.get("pageNum").toString()),Integer.parseInt(queryParams.get("pageSize").toString()));
		return page;
	}
	
	/**
	 *新增一条操作日志记录
	 */
	@RequestMapping(value="/add", method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
	public void addSysOplog(HttpServletRequest request,
			@RequestParam String bizId,@RequestParam String bizType,@RequestParam String type,
			@RequestParam String content,@RequestParam String status,@RequestParam String sys,@RequestParam String remark){
			
			LogUtil.addSysOplog(request, bizId, bizType, type, content, status, sys,remark);
	}
	
	
	/** 
	 * 搜索对象 
	 **/
	@RequestMapping(value = "",method = RequestMethod.GET,produces = "application/json;charset=UTF-8")
	@ResponseBody
	@CrossOrigin
	public R<Page<SysOplogEntity>> list(SysOplogEntity sysOplogEntity) {
		Page<SysOplogEntity> page = sysOplogService.findPage(sysOplogEntity);
		return R.ok(page);
	}

	
	/** 
	 * 查看对象
	 **/
	@RequestMapping(value = "/{id}",method = RequestMethod.GET,produces = "application/json;charset=UTF-8")
	@ResponseBody
	@CrossOrigin
	public R<TPfSysOplog> view(@PathVariable String id)  {
		TPfSysOplog sysOplogEntity  = sysOplogService.getById(id);
		return R.ok(sysOplogEntity);
	}


	/** 
	 * 查看对象（支持多条件查询）
	 **/
	@RequestMapping(value = "get",method = RequestMethod.GET,produces = "application/json;charset=UTF-8")
	@ResponseBody
	@CrossOrigin
	public R<TPfSysOplog> get(SysOplogEntity model)  {
		TPfSysOplog sysOplogEntity = sysOplogService.get(model);
		return R.ok(sysOplogEntity);
	}
	
	
	/** 
	 * 新增对象
	 **/
	@RequestMapping(value = "",method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
	@ResponseBody
	@CrossOrigin
	public R<SysOplogEntity> save(@RequestBody SysOplogEntity model)  {
		TPfSysOplog tPfSysOplog = BeanUtil.copyProperties(model, TPfSysOplog.class);
		tPfSysOplog.setAppId(UserUtils.getTenantId());
		sysOplogService.save(tPfSysOplog);
		return R.ok(model);
	}
	
	
	/**
	 * 更新对象
	 * @return 
	 **/
	@RequestMapping(value = "",method = RequestMethod.PUT,produces = "application/json;charset=UTF-8")
	@ResponseBody
	@CrossOrigin
	public R<SysOplogEntity> update(@RequestBody SysOplogEntity model)  {
		TPfSysOplog tPfSysOplog = BeanUtil.copyProperties(model, TPfSysOplog.class);
		tPfSysOplog.setAppId(UserUtils.getTenantId());
		sysOplogService.updateById(tPfSysOplog);
		return R.ok(model);
	}
	
	/**
	 * 删除对象
	 * @return 
	 **/
	@RequestMapping(value = "/{id}",method = RequestMethod.DELETE,produces = "application/json;charset=UTF-8")
	@ResponseBody
	@CrossOrigin
	public R<Boolean> delete(@PathVariable String id) {
		sysOplogService.removeById(id);
		return R.ok();
	}
	
	/**
	 *  批量删除对象
	 * @return 
	 **/
	@RequestMapping(value = "deleteBatch",method = RequestMethod.DELETE,produces = "application/json;charset=UTF-8")
	@ResponseBody
	@CrossOrigin
	public R<Boolean> deleteBatch(String[] ids) {
		for (int i = 0; i < ids.length; i++) {
			sysOplogService.removeById(ids[i]);
		}
		return R.ok();
	}
	
}



