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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhgd.annotation.OperLog;
import com.zhgd.jeecg.common.api.vo.Result;
import com.zhgd.jeecg.common.util.PageUtil;
import com.zhgd.xmgl.modules.basicdata.entity.MonitorQuestion;
import com.zhgd.xmgl.modules.basicdata.service.IMonitorQuestionService;
import com.zhgd.xmgl.modules.basicdata.service.IProjectService;
import com.zhgd.xmgl.security.SecurityUser;
import com.zhgd.xmgl.security.SecurityUtil;
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.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
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.Date;
import java.util.List;
import java.util.Map;


/**
 * @Title: Controller
 * @Description: 视频抓拍记录
 * @author： pds
 * @date： 2023-02-28
 * @version： V1.0
 */
@RestController
@RequestMapping("/gov/monitorQuestion")
@Slf4j
@Api(tags = "抓拍记录")
public class GovMonitorQuestionController {
	@Autowired
	private IMonitorQuestionService monitorQuestionService;

	@Autowired
	private IProjectService projectService;

	/**
	 * 分页列表查询
	 *
	 * @return
	 */
	@OperLog(operModul = "视频抓拍管理", operType = "分页查询", operDesc = "分页列表查询视频抓拍记录信息")
	@ApiOperation(value = " 分页列表查询视频抓拍记录信息", notes = "分页列表查询视频抓拍记录信息", httpMethod = "POST")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "pageNo", value = "页数", paramType = "query", required = true, defaultValue = "1", dataType = "Integer"),
			@ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query", required = true, defaultValue = "10", dataType = "Integer")
	})
	@PostMapping(value = "/page")
	public Result<IPage<MonitorQuestion>> queryPageList(@RequestBody Map<String, Object> map) {
		QueryWrapper<MonitorQuestion> wrapper = Wrappers.<MonitorQuestion>query();
		Page<MonitorQuestion> page = PageUtil.getPage(map);
		SecurityUser user = SecurityUtil.getUser();
		List<String> projectSns = projectService.getSnListForGov(user.getSn());
		if (projectSns.size() > 0) {
			wrapper.in("q.project_sn", projectSns);
		}
		IPage<MonitorQuestion> pageList = monitorQuestionService.getPageListByGov(page, wrapper);
		return Result.success(pageList);
	}

	/**
	 *   添加
	 * @param monitorQuestion
	 * @return
	 */
	@OperLog(operModul = "视频抓拍管理", operType = "新增", operDesc = "添加视频抓拍记录信息")
	@ApiOperation(value = " 添加视频抓拍记录信息", notes = "添加视频抓拍记录信息" , httpMethod="POST")
	@PostMapping(value = "/add")
	public Result<Object> add(@RequestBody MonitorQuestion monitorQuestion) {
		Result<MonitorQuestion> result = new Result<MonitorQuestion>();
		monitorQuestion.setCreateTime(new Date());
		monitorQuestionService.save(monitorQuestion);
		return Result.ok("添加成功！");
	}

	/**
	 * 通过id查询
	 * @return
	 */
	@OperLog(operModul = "视频抓拍管理", operType = "查询", operDesc = "通过id查询视频抓拍记录信息")
	@ApiOperation(value = "通过id查询视频抓拍记录信息", notes = "通过id查询视频抓拍记录信息", httpMethod = "POST")
	@ApiImplicitParam(name = "id", value = "视频抓拍记录ID", paramType = "query", required = true, dataType = "String")
	@PostMapping(value = "/queryById")
	public Result<MonitorQuestion> queryById(@RequestBody Map<String, Object> map) {
		Result<MonitorQuestion> result = new Result<MonitorQuestion>();
		MonitorQuestion monitorQuestion = monitorQuestionService.getById(MapUtils.getString(map, "id"));
		if (monitorQuestion == null) {
			result.error500("未找到对应实体");
		} else {
			result.setResult(monitorQuestion);
			result.setSuccess(true);
		}
		return result;
	}
}
