package com.njcn.system.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.dto.LogInfoDTO;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.system.pojo.dto.PqFrontLogsDTO;
import com.njcn.system.pojo.param.PqFrontLogsChildParam;
import com.njcn.system.pojo.param.PqFrontLogsParam;
import com.njcn.system.pojo.po.PqFrontLogsChild;
import com.njcn.system.pojo.po.UserLog;
import com.njcn.system.pojo.vo.PqFrontLogsVO;
import com.njcn.system.service.IUserLogService;
import com.njcn.system.service.PqFrontLogsService;
import com.njcn.web.controller.BaseController;
import com.njcn.web.pojo.param.BaseParam;
import com.njcn.web.utils.RequestUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;


/**
 * <p>
 * 前端控制器（行政区域）
 * </p>
 *
 * @author hongawen
 * @since 2021-12-13
 */
@Validated
@Slf4j
@RestController
@RequestMapping("/frontLog")
@Api(tags = "前置日志管理")
@AllArgsConstructor
public class PqFrontLogsController extends BaseController {

    private final PqFrontLogsService pqFrontLogsService;

    /**
     * 插入审计日志
     */
    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
    @PostMapping("/add")
    @ApiOperation("插入前置日志")
    @ApiImplicitParam(name = "pqFrontLogsDTO", value = "插入日志参数", required = true)
    public HttpResult<Object> addFrontLogs(@RequestBody PqFrontLogsDTO pqFrontLogsDTO) {
        String methodDescribe = getMethodDescribe("addFrontLogs");
        pqFrontLogsService.addFrontLogs(pqFrontLogsDTO);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.QUERY)
    @PostMapping("/query")
    @ApiOperation("查询前置日志")
    @ApiImplicitParam(name = "baseParam", value = "查询日志参数", required = true)
    public HttpResult<Page<PqFrontLogsVO>> queryFrontLogs(@RequestBody PqFrontLogsParam baseParam) {
        String methodDescribe = getMethodDescribe("queryFrontLogs");
        Page<PqFrontLogsVO> list = pqFrontLogsService.queryPage(baseParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }
    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.QUERY)
    @PostMapping("/queryLogCHild")
    @ApiOperation("查询前置日志子日志")
    @ApiImplicitParam(name = "baseParam", value = "查询日志参数", required = true)
    public HttpResult<Page<PqFrontLogsChild>> queryLogCHild(@RequestBody PqFrontLogsChildParam baseParam) {
        String methodDescribe = getMethodDescribe("queryFrontLogs");
        Page<PqFrontLogsChild> list = pqFrontLogsService.queryLogCHild(baseParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }
}

