package com.qunzhixinxi.hnqz.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import com.qunzhixinxi.hnqz.admin.api.entity.SingleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonth;
import com.qunzhixinxi.hnqz.admin.api.entity.SingleMemberSettleAmountOverrunInSeveralMonths;
import com.qunzhixinxi.hnqz.admin.api.entity.SingleMemberSettleSameAmountInSeveralMonths;
import com.qunzhixinxi.hnqz.admin.api.entity.SingleMemberWithoutSuchTaskTypesInSeveralMonths;
import com.qunzhixinxi.hnqz.admin.service.SingleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonthService;
import com.qunzhixinxi.hnqz.admin.service.SingleMemberSettleAmountOverrunInSeveralMonthsService;
import com.qunzhixinxi.hnqz.admin.service.SingleMemberSettleSameAmountInSeveralMonthsService;
import com.qunzhixinxi.hnqz.admin.service.SingleMemberWithoutSuchTaskTypesInSeveralMonthsService;
import com.qunzhixinxi.hnqz.common.core.util.R;
import lombok.AllArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 风险控制前端控制器
 *
 * @author jimmy
 * @version 1.0.0
 * @date 2022-06-02 13:16
 */
@RestController
@AllArgsConstructor
@RequestMapping(value = "/risk-control", produces = MediaType.APPLICATION_JSON_VALUE)
public class RiskControlController {

	private final SingleMemberSettleAmountOverrunInSeveralMonthsService singleMemberSettleAmountOverrunInSeveralMonthsService;
	private final SingleMemberSettleSameAmountInSeveralMonthsService singleMemberSettleSameAmountInSeveralMonthsService;
	private final SingleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonthService singleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonthService;
	private final SingleMemberWithoutSuchTaskTypesInSeveralMonthsService singleMemberWithoutSuchTaskTypesInSeveralMonthsService;

	/**
	 * 同一用户，连续2个月结算金额相同
	 *
	 * @return 风控结果
	 */
	@GetMapping(value = "/member/settle-same-amount/{uuid}")
	public R<?> pageSingleMemberSettleSameAmountInSeveralMonths(Page<SingleMemberSettleSameAmountInSeveralMonths> page, @PathVariable(value = "uuid") String uuid) {

		singleMemberSettleSameAmountInSeveralMonthsService.page(page, Wrappers.<SingleMemberSettleSameAmountInSeveralMonths>lambdaQuery()
				.eq(SingleMemberSettleSameAmountInSeveralMonths::getUuid, uuid)
				.orderByDesc(SingleMemberSettleSameAmountInSeveralMonths::getCreateTime));
		return R.ok(page);
	}

	/**
	 * 同一用户，连续2个月结算金额相同（导出）
	 *
	 * @return 风控结果
	 */
	@ResponseExcel(name = "SingleMemberSettleSameAmountInSeveralMonths", sheet = "风控数据")
	@GetMapping(value = "/member/settle-same-amount/export/{uuid}")
	public List<SingleMemberSettleSameAmountInSeveralMonths> exportSingleMemberSettleSameAmountInSeveralMonths(@PathVariable(value = "uuid") String uuid) {

		return singleMemberSettleSameAmountInSeveralMonthsService.list(Wrappers.<SingleMemberSettleSameAmountInSeveralMonths>lambdaQuery()
				.eq(SingleMemberSettleSameAmountInSeveralMonths::getUuid, uuid)
				.orderByDesc(SingleMemberSettleSameAmountInSeveralMonths::getCreateTime));
	}

	/**
	 * 同一企业，给2个及以上用户支付相同金额
	 *
	 * @return 风控结果
	 */
	@GetMapping(value = "/enterprise/settle-same-amount/{uuid}")
	public R<?> pageSingleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonth(Page<SingleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonth> page, @PathVariable(value = "uuid") String uuid) {

		singleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonthService.page(page, Wrappers.<SingleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonth>lambdaQuery()
				.eq(SingleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonth::getUuid, uuid)
				.orderByDesc(SingleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonth::getCreateTime));
		return R.ok(page);
	}

	/**
	 * 同一企业，给2个及以上用户支付相同金额（导出）
	 *
	 * @return 风控结果
	 */
	@ResponseExcel(name = "SingleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonth", sheet = "风控数据")
	@GetMapping(value = "/enterprise/settle-same-amount/export/{uuid}")
	public List<SingleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonth> exportSingleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonth(@PathVariable(value = "uuid") String uuid) {

		return singleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonthService.list(Wrappers.<SingleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonth>lambdaQuery()
				.eq(SingleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonth::getUuid, uuid)
				.orderByDesc(SingleEnterpriseSettleSameAmountForSeveralMembersInCurrentMonth::getCreateTime));
	}


	/**
	 * 同一用户，连续3个月结算金额超过14万
	 *
	 * @return 风控结果
	 */
	@GetMapping(value = "/member/settle-amount/overrun/{uuid}")
	public R<?> pageSingleMemberSettleAmountOverrunInSeveralMonths(Page<SingleMemberSettleAmountOverrunInSeveralMonths> page, @PathVariable(value = "uuid") String uuid) {

		singleMemberSettleAmountOverrunInSeveralMonthsService.page(page, Wrappers.<SingleMemberSettleAmountOverrunInSeveralMonths>lambdaQuery()
				.eq(SingleMemberSettleAmountOverrunInSeveralMonths::getUuid, uuid)
				.orderByDesc(SingleMemberSettleAmountOverrunInSeveralMonths::getCreateTime));
		return R.ok(page);
	}

	/**
	 * 同一用户，连续3个月结算金额超过14万（导出）
	 *
	 * @return 风控结果
	 */
	@ResponseExcel(name = "SingleMemberSettleAmountOverrunInSeveralMonths", sheet = "风控数据")
	@GetMapping(value = "/member/settle-amount/overrun/export/{uuid}")
	public List<SingleMemberSettleAmountOverrunInSeveralMonths> exportSingleMemberSettleAmountOverrunInSeveralMonths(@PathVariable(value = "uuid") String uuid) {

		return singleMemberSettleAmountOverrunInSeveralMonthsService.list(Wrappers.<SingleMemberSettleAmountOverrunInSeveralMonths>lambdaQuery()
				.eq(SingleMemberSettleAmountOverrunInSeveralMonths::getUuid, uuid)
				.orderByDesc(SingleMemberSettleAmountOverrunInSeveralMonths::getCreateTime));
	}


	/**
	 * 同一用户，连续多月没有指定任务类型
	 *
	 * @return 风控结果
	 */
	@GetMapping(value = "/member/task-type/{uuid}")
	public R<?> pageSingleMemberWithoutSuchTaskTypesInSeveralMonths(Page<SingleMemberWithoutSuchTaskTypesInSeveralMonths> page, @PathVariable(value = "uuid") String uuid) {

		singleMemberWithoutSuchTaskTypesInSeveralMonthsService.page(page, Wrappers.<SingleMemberWithoutSuchTaskTypesInSeveralMonths>lambdaQuery()
				.eq(SingleMemberWithoutSuchTaskTypesInSeveralMonths::getUuid, uuid)
				.orderByDesc(SingleMemberWithoutSuchTaskTypesInSeveralMonths::getCreateTime));
		return R.ok(page);
	}

	/**
	 * 同一用户，连续多月没有指定任务类型
	 *
	 * @return 风控结果
	 */
	@ResponseExcel(name = "SingleMemberWithoutSuchTaskTypesInSeveralMonths", sheet = "风控数据")
	@GetMapping(value = "/member/task-type/export/{uuid}")
	public List<SingleMemberWithoutSuchTaskTypesInSeveralMonths> exportSingleMemberWithoutSuchTaskTypesInSeveralMonths(@PathVariable(value = "uuid") String uuid) {

		return singleMemberWithoutSuchTaskTypesInSeveralMonthsService.list(Wrappers.<SingleMemberWithoutSuchTaskTypesInSeveralMonths>lambdaQuery()
				.eq(SingleMemberWithoutSuchTaskTypesInSeveralMonths::getUuid, uuid)
				.orderByDesc(SingleMemberWithoutSuchTaskTypesInSeveralMonths::getCreateTime));

	}
}
