package com.yeejoin.amos.patrol.business.controller;

import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.patrol.business.param.CheckStatsListPageParam;
import com.yeejoin.amos.patrol.business.service.intfc.IQueryStatsService;
import com.yeejoin.amos.patrol.business.util.CheckStatsParamUtils;
import com.yeejoin.amos.patrol.business.util.CommonResponse;
import com.yeejoin.amos.patrol.business.util.CommonResponseUtil;
import com.yeejoin.amos.patrol.business.vo.CheckStatsVo;
import com.yeejoin.amos.patrol.core.common.request.CommonPageable;
import com.yeejoin.amos.patrol.core.common.request.CommonRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
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 org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;

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

@RestController
@RequestMapping(value = "/api/stats")
@Api(tags="巡检查询统计api")
public class QueryStatsController extends AbstractBaseController {
	
	@Autowired
	private IQueryStatsService iQueryStatsService;
	
	/**
	 * 查询巡检统计信息
	 * 
	 * @param point
	 * @return
	 */
	@TycloudOperation(ApiLevel = UserType.AGENCY)
	@ApiOperation(value = "查询巡检点信息", notes = "查询巡检点信息")
	@PostMapping(value = "/checkStats", produces = "application/json;charset=UTF-8")
	public CommonResponse queryCheckStats(
			@ApiParam(value = "查询条件", required = false) @RequestBody(required = false) List<CommonRequest> queryRequests,
			@ApiParam(value = "分页参数", required = true, defaultValue = "pageNumber=0&pageSize=10") CommonPageable commonPageable) {
		ReginParams reginParams = getSelectedOrgInfo();
        String loginOrgCode = getOrgCode(reginParams);
        String roleTypeName = getRoleTypeName(reginParams);
        HashMap<String, Object> paramMap = buildMybatisDaoCriterias(loginOrgCode, roleTypeName);
		CheckStatsListPageParam param = CheckStatsParamUtils.fillCheckInfoParam(queryRequests, commonPageable, paramMap);
		Page<CheckStatsVo> dataList = iQueryStatsService.queryCheckStats(param);
		return CommonResponseUtil.success(dataList);
	}
}
