package com.pine.admin.modules.business.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.pine.common.dto.Page;
import com.pine.admin.modules.base.binder.BaseController;
import com.pine.common.dto.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMethod;
import com.pine.admin.modules.business.entity.SysLog;
import com.pine.admin.modules.business.service.SysLogService;


/**
 * 日志操作记录
 *
 * @author Pine
 * @email 771190883@qq.com
 * @date 2019-10-16 13:58:24
 */
@Api(value = "日志操作记录接口", tags = {"日志操作记录接口"})
@RestController
@RequestMapping("business/SysLog")
public class SysLogController extends BaseController {

    @Autowired
    private SysLogService sysLogService;


    /**
     * <p>获取全部记录。</p>
     */
    @ApiOperation(value = "获取所有日志操作记录数据", notes = "可以根据条件获取")
    @RequestMapping(value = "/all", method = RequestMethod.GET)
    public Result all(SysLog record) {
        List<SysLog> pp = sysLogService.getAllList(record);
        return Result.success(true, pp);
    }


    /**
     * <p>根据Id。</p>
     */
    @ApiOperation(value = "获取日志操作记录数据", notes = "根据id来获取日志操作记录详细信息")
    @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
    public Result getSysLogEntity(@PathVariable("id") String id) {
        SysLog data = sysLogService.getById(id);
        return Result.success(true, data);
    }

    /**
     * <p>根据条件获取。</p>
     */
    @ApiOperation(value = "获取日志操作记录数据", notes = "根据条件获取")
    @RequestMapping(value = "/getOne", method = RequestMethod.GET)
    public Result getOne(SysLog record) {
        SysLog data = sysLogService.getOne(record);
        return Result.success(true, data);
    }

    /**
     * <p>分页查询。</p>
     */
    @ApiOperation(value = "分页获取日志操作记录数据", notes = "根据条件获取")
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public Result page(Page page, SysLog record) {

        Map<String, Object> result = new HashMap<>();

        List<SysLog> pp = sysLogService.getByPage(page, record);

        result.put("page", page);
        result.put("pp", pp);
        return Result.success(true, result);
    }

    /**
     * <p>保存。</p>
     */
    @ApiOperation(value = "新增一条日志操作记录数据", notes = "新增一条日志操作记录数据")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result save(SysLog record) {

        boolean num = sysLogService.create(record);
        if (num) {
            return Result.success(true, record.getId());
        }
        return Result.error("保存异常");
    }

    /**
     * <p>更新信息。</p>
     */
    @ApiOperation(value = "更新一条日志操作记录数据", notes = "更新一条日志操作记录数据")
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    public Result updateSysLog(SysLog record) {

        boolean num = sysLogService.update(record);
        if (num) {
            return Result.success(true, "保存成功");
        }
        return Result.error("保存异常");
    }

    /**
     * <p>删除。</p>
     */
    @RequestMapping(value = "/del/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除一条日志操作记录数据", notes = "根据Id一条日志操作记录数据")
    public Result deleteSysLog(@PathVariable("id") String id) {

        boolean num = sysLogService.delete(id);
        if (num) {
            return Result.success(true, "删除成功");
        }
        return Result.error("删除异常");
    }

    /**
     * <p>批量删除。</p>
     */
    @RequestMapping(value = "/deltetByIds", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除多条日志操作记录数据", notes = "删除id的集合多个用英文逗号分隔")
    public Result delSysLogAll(@RequestParam(required = true, value = "ids") String ids) {

        boolean num = sysLogService.deltetByIds(ids);
        if (num) {
            return Result.success(true, "删除成功");
        }
        return Result.error("删除异常");
    }

}
