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.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")
	public R<?> pageSingleMemberSettleSameAmountInSeveralMonths(Page<SingleMemberSettleSameAmountInSeveralMonths> page) {

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

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

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

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

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

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

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


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

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

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

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


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

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

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

		return singleMemberWithoutSuchTaskTypesInSeveralMonthsService.list(Wrappers.<SingleMemberWithoutSuchTaskTypesInSeveralMonths>lambdaQuery().orderByDesc(SingleMemberWithoutSuchTaskTypesInSeveralMonths::getCreateTime));

	}
}
