package com.microservices.zone.member.controller;

import com.microservices.common.core.web.controller.BaseController;
import com.microservices.common.core.web.domain.AjaxResult;
import com.microservices.common.core.web.domain.GenericsAjaxResult;
import com.microservices.common.core.web.page.GenericsTableDataInfo;
import com.microservices.common.log.annotation.Log;
import com.microservices.common.log.enums.BusinessType;
import com.microservices.common.security.annotation.RequiresPermissions;
import com.microservices.zone.member.domain.points.ZonePointsTransaction;
import com.microservices.zone.member.domain.vo.ZonePointsTransactionInputVo;
import com.microservices.zone.member.domain.vo.ZonePointsTransactionSearchVo;
import com.microservices.zone.member.domain.vo.ZonePointsTransactionUpdateVo;
import com.microservices.common.security.utils.SecurityUtils;
import com.microservices.zone.member.service.IZonePointsTransactionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 专区积分流水Controller
 *
 * @author otto
 */
@RestController
@RequestMapping("/points/transaction")
@Api(tags = "专区积分流水接口")
public class ZonePointsTransactionController extends BaseController {
    @Autowired
    private IZonePointsTransactionService zonePointsTransactionService;

    /**
     * 查询专区积分流水列表
     */
    @RequiresPermissions("zone:points:transaction:list")
    @GetMapping("/list")
    @ApiOperation("查询专区积分流水列表")
    public GenericsTableDataInfo<ZonePointsTransaction> list(ZonePointsTransactionSearchVo searchVo) {
        startPage();
        List<ZonePointsTransaction> list = zonePointsTransactionService.selectZonePointsTransactionList(searchVo.toZonePointsTransaction());
        return getGenericsDataTable(list);
    }

    /**
     * 获取专区积分流水详细信息
     */
    @RequiresPermissions("zone:points:transaction:query")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取专区积分流水详细信息")
    public GenericsAjaxResult<ZonePointsTransaction> getInfo(@PathVariable("id") Long id) {
        return genericsSuccess(zonePointsTransactionService.selectZonePointsTransactionById(id));
    }

    /**
     * 根据事件ID查询流水列表
     */
    @RequiresPermissions("zone:points:transaction:query")
    @GetMapping("/event/{eventId}")
    @ApiOperation(value = "根据事件ID查询流水列表")
    public GenericsAjaxResult<List<ZonePointsTransaction>> getByEventId(@PathVariable("eventId") String eventId) {
        return genericsSuccess(zonePointsTransactionService.selectZonePointsTransactionByEventId(eventId));
    }

    /**
     * 根据账户ID查询流水列表
     */
    @RequiresPermissions("zone:points:transaction:query")
    @GetMapping("/account/{accountId}")
    @ApiOperation(value = "根据账户ID查询流水列表")
    public GenericsAjaxResult<List<ZonePointsTransaction>> getByAccountId(@PathVariable("accountId") Long accountId) {
        return genericsSuccess(zonePointsTransactionService.selectZonePointsTransactionByAccountId(accountId));
    }

    /**
     * 根据用户ID和专区ID查询流水列表
     */
    @RequiresPermissions("zone:points:transaction:query")
    @GetMapping("/user/{userId}/zone/{zoneId}")
    @ApiOperation(value = "根据用户ID和专区ID查询流水列表")
    public GenericsAjaxResult<List<ZonePointsTransaction>> getByUserIdAndZoneId(@PathVariable("userId") Long userId,
                                                                                @PathVariable("zoneId") Long zoneId) {
        return genericsSuccess(zonePointsTransactionService.selectZonePointsTransactionByUserIdAndZoneId(userId, zoneId));
    }

    /**
     * 根据专区ID获取当前用户积分明细（分页）
     */
    @GetMapping("/my/{zoneId}")
    @ApiOperation(value = "根据专区ID获取当前用户积分明细（分页）")
    public GenericsTableDataInfo<ZonePointsTransaction> getMyPointsDetailsByZone(@PathVariable("zoneId") Long zoneId,
                                                                                 ZonePointsTransactionSearchVo searchVo) {
        startPage();
        List<ZonePointsTransaction> list = zonePointsTransactionService.selectMyPointsTransactionDetailsByZone(zoneId, SecurityUtils.getUserId(), searchVo.getTransactionType());
        return getGenericsDataTable(list);
    }

    /**
     * 分页查询当前登录用户流水列表（合并后所有业务字段已包含在流水中）
     */
    @GetMapping("/currentUser/{zoneId}")
    @ApiOperation(value = "分页查询当前登录用户流水列表")
    public GenericsTableDataInfo<ZonePointsTransaction> getCurrentUserTransactionList(@PathVariable("zoneId") Long zoneId) {
        startPage();
        List<ZonePointsTransaction> list = zonePointsTransactionService.selectCurrentUserTransactionWithEvent(SecurityUtils.getUserId(), zoneId);
        return getGenericsDataTable(list);
    }
}