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.common.security.utils.SecurityUtils;
import com.microservices.zone.member.domain.points.ZonePointsApply;
import com.microservices.zone.member.domain.vo.ZonePointsApplyDetailVo;
import com.microservices.zone.member.domain.vo.ZonePointsApplyInputVo;
import com.microservices.zone.member.domain.vo.ZonePointsApplySearchVo;
import com.microservices.zone.member.domain.vo.ZonePointsApplyUpdateVo;
import com.microservices.zone.member.service.IZonePointsApplyService;
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/apply")
@Api(tags = "积分申请表接口")
public class ZonePointsApplyController extends BaseController {
    @Autowired
    private IZonePointsApplyService zonePointsApplyService;

    /**
     * 查询积分申请列表
     */
    @RequiresPermissions("zone:points:apply:list")
    @GetMapping("/list")
    @ApiOperation("查询积分申请列表")
    public GenericsTableDataInfo<ZonePointsApplyDetailVo> list(ZonePointsApplySearchVo searchVo) {
        startPage();
        return zonePointsApplyService.selectZonePointsApplyList(searchVo);
    }

    /**
     * 查询我的积分申请列表
     */
    @GetMapping("/my/list")
    @ApiOperation("查询我的积分申请列表")
    public GenericsTableDataInfo<ZonePointsApplyDetailVo> myList(ZonePointsApplySearchVo searchVo) {
        startPage();
        searchVo.setUserId(SecurityUtils.getUserId());
        return zonePointsApplyService.selectZonePointsApplyList(searchVo);
    }

    /**
     * 获取积分申请详细信息
     */
    @RequiresPermissions("zone:points:apply:query")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取积分申请详细信息")
    public GenericsAjaxResult<ZonePointsApply> getInfo(@PathVariable("id") Long id) {
        return genericsSuccess(zonePointsApplyService.selectZonePointsApplyById(id));
    }

    /**
     * 新增积分申请
     */
    @RequiresPermissions("zone:points:apply:add")
    @Log(title = "积分申请", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增积分申请")
    public AjaxResult add(@RequestBody ZonePointsApplyInputVo inputVo) {
        return toAjax(zonePointsApplyService.insertZonePointsApply(inputVo));
    }

    /**
     * 修改积分申请
     */
    @RequiresPermissions("zone:points:apply:edit")
    @Log(title = "积分申请", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改积分申请")
    public AjaxResult edit(@RequestBody ZonePointsApplyUpdateVo updateVo) {
        return toAjax(zonePointsApplyService.updateZonePointsApply(updateVo));
    }

    /**
     * 删除积分申请
     */
    @RequiresPermissions("zone:points:apply:remove")
    @Log(title = "积分申请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除积分申请")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(zonePointsApplyService.deleteZonePointsApplyByIds(ids));
    }

    /**
     * 根据用户ID和专区ID查询积分申请列表
     */
    @RequiresPermissions("zone:points:apply:query")
    @GetMapping("/user/{userId}/zone/{zoneId}")
    @ApiOperation(value = "根据用户ID和专区ID查询积分申请列表")
    public GenericsAjaxResult<List<ZonePointsApply>> getByUserIdAndZoneId(@PathVariable("userId") Long userId,
                                                                          @PathVariable("zoneId") Long zoneId) {
        return genericsSuccess(zonePointsApplyService.selectZonePointsApplyByUserIdAndZoneId(userId, zoneId));
    }
}