package com.fjs.scenic.service.system.impl;

import com.fjs.scenic.dto.LogsVo;
import com.fjs.scenic.entity.system.Logs;
import com.fjs.scenic.mapper.system.LogsMapper;
import com.fjs.scenic.utils.ReturnResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service
public class LogsService {

    @Autowired
    public LogsMapper logsMapper;

    /**
     * 分页查询日志列表
     *
     * @param logs
     * @return
     */
    public List<HashMap<String, Object>> page(LogsVo logs) {
        return logsMapper.selectByCondition(logs);
    }

    /**
     * 根据id查询日志
     *
     * @param id
     * @return
     */
    public ReturnResult findLogsById(Long id) {
        return ReturnResult.ok(logsMapper.selectByPrimaryKey(id));
    }

    /**
     * 添加或修改日志
     *
     * @param logs
     * @return
     */
    public ReturnResult optionLogs(Logs logs) {
        int i = 0;
        if (logs.getId() == null || logs.getId() == 0) {
            i = logsMapper.insert(logs);
        } else {
            i = logsMapper.updateByPrimaryKey(logs);
        }
        if (i == 1) {
            return ReturnResult.ok("保存成功");
        } else {
            return ReturnResult.build(500, "保存失败");
        }
    }

    /**
     * 根据主键删除日志
     *
     * @param id
     * @return
     */
    public ReturnResult deleteLogsById(Long id) {
        int i = logsMapper.deleteByPrimaryKey(id);
        if (i == 1) {
            return ReturnResult.ok("删除成功");
        } else {
            return ReturnResult.build(500, "删除失败");
        }
    }

}
