package com.zhgd.xmgl.modules.basicdata.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhgd.annotation.OperLog;
import com.zhgd.jeecg.common.api.vo.Result;
import com.zhgd.jeecg.common.mybatis.EntityMap;
import com.zhgd.xmgl.modules.basicdata.entity.OperationLog;
import com.zhgd.xmgl.modules.basicdata.service.IOperationLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * @Title: Controller
 * @Description: 操作日志表
 * @author： pds
 * @date：   2021-05-07
 * @version： V1.0
 */
@RestController
@RequestMapping("/xmgl/operationLog")
@Slf4j
@Api(tags = "操作日志表")
public class OperationLogController {
	@Autowired
	private IOperationLogService operationLogService;
	
	/**
	  * 分页列表查询
	 */
	@OperLog(operModul = "系统日志管理", operType = "分页查询", operDesc = "分页列表查询操作日志表信息")
    @ApiOperation(value = " 分页列表查询操作日志表信息", notes = "分页列表查询操作日志表信息", httpMethod="POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName", value = "操作人", paramType = "query", required = false, dataType = "String"),
            @ApiImplicitParam(name = "operName", value = "操作名称", paramType = "query", required = false, dataType = "String"),
            @ApiImplicitParam(name = "startTime", value = "开始时间，格式2021-08-15", paramType = "query", required = false, dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间，格式2021-08-15", paramType = "query", required = false, dataType = "String"),
            @ApiImplicitParam(name = "sn", value = "项目SN或企业sn", paramType = "query", required = true, dataType = "String"),
            @ApiImplicitParam(name = "pageNo", value = "第几页", paramType = "query", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", paramType = "query", required = true, dataType = "Integer"),
    })
    @PostMapping(value = "/page")
    public Result<IPage<EntityMap>> queryPageList(@RequestBody Map<String,Object> map) {
        return Result.success(operationLogService.selectOperationLogPage(map));
    }
	/**
	  *   添加
	 * @param operationLog
	 * @return
	 */
	@OperLog(operModul = "系统日志管理", operType = "新增", operDesc = "添加操作日志表信息")
	@ApiOperation(value = " 添加操作日志表信息", notes = "添加操作日志表信息" , httpMethod="POST")
	@PostMapping(value = "/add")
	public Result<OperationLog> add(@RequestBody OperationLog operationLog) {
		Result<OperationLog> result = new Result<OperationLog>();
		operationLogService.save(operationLog);
		result.successMsg("添加成功！");
		return result;
	}
	

	
	/**
	  *   通过id删除
	 * @param id
	 * @return
	 */
	@OperLog(operModul = "系统日志管理", operType = "删除", operDesc = "删除操作日志表信息")
	@ApiOperation(value = "删除操作日志表信息", notes = "删除操作日志表信息" , httpMethod="DELETE")
	@ApiImplicitParam(name = "id", value = "操作日志表ID", paramType = "query", required = true, dataType = "Integer")
	@DeleteMapping(value = "/delete")
	public Result<OperationLog> delete(@RequestParam(name="id",required=true) String id) {
		Result<OperationLog> result = new Result<OperationLog>();
		OperationLog operationLog = operationLogService.getById(id);
		if(operationLog==null) {
			result.error500("未找到对应实体");
		}else {
			boolean ok = operationLogService.removeById(id);
			if(ok) {
				result.successMsg("删除成功!");
			}
		}
		
		return result;
	}
	
	/**
	  *  批量删除
	 * @param ids
	 * @return
	 */
	@OperLog(operModul = "系统日志管理", operType = "批量删除", operDesc = "批量删除操作日志表信息")
	@ApiOperation(value = "批量删除操作日志表信息", notes = "批量删除操作日志表信息",  httpMethod="DELETE")
    @ApiImplicitParam(name = "id", value = "操作日志表ID字符串", paramType = "query", required = true, dataType = "String")
	@DeleteMapping(value = "/deleteBatch")
	public Result<OperationLog> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		Result<OperationLog> result = new Result<OperationLog>();
		if(ids==null || "".equals(ids.trim())) {
			result.error500("参数不识别！");
		}else {
			this.operationLogService.removeByIds(Arrays.asList(ids.split(",")));
			result.successMsg("删除成功!");
		}
		return result;
	}
	
	/**
	  * 通过id查询
	 * @param id
	 * @return
	 */
	@OperLog(operModul = "系统日志管理", operType = "查询", operDesc = "通过id查询操作日志表信息")
	@ApiOperation(value = "通过id查询操作日志表信息", notes = "通过id查询操作日志表信息" , httpMethod="GET")
    @ApiImplicitParam(name = "id", value = "操作日志表ID", paramType = "query", required = true, dataType = "Integer")
	@GetMapping(value = "/queryById")
	public Result<OperationLog> queryById(@RequestParam(name="id",required=true) String id) {
		Result<OperationLog> result = new Result<OperationLog>();
		OperationLog operationLog = operationLogService.getById(id);
		if(operationLog==null) {
			result.error500("未找到对应实体");
		}else {
			result.setResult(operationLog);
			result.setSuccess(true);
		}
		return result;
	}


}
