package com.miaxis.applepay.controller;

import com.miaxis.applepay.domain.ApplepayOrder;
import com.miaxis.applepay.service.IApplepayOrderService;
import com.miaxis.common.annotation.Log;
import com.miaxis.common.core.controller.BaseController;
import com.miaxis.common.core.domain.Response;
import com.miaxis.common.core.page.ResponsePageInfo;
import com.miaxis.common.enums.BusinessTypeEnum;
import com.miaxis.common.utils.poi.ExcelUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 【苹果支付订单】Controller
 *
 * @author miaxis
 * @date 2022-09-26
 */
@RestController
@RequestMapping("/applepay/order")
@Api(tags={"【H5-苹果支付订单】"})
public class ApplepayOrderController extends BaseController{
    @Autowired
    private IApplepayOrderService applepayOrderService;

    /**
     * 查询苹果支付订单列表
     */
    @PreAuthorize("@ss.hasPermi('applepay:order:list')")
    @GetMapping("/list")
    @ApiOperation("查询苹果支付订单列表")
        @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<ApplepayOrder> list(@ModelAttribute ApplepayOrder applepayOrder){
        startPage();
        List<ApplepayOrder> list = applepayOrderService.selectApplepayOrderList(applepayOrder);
        return toResponsePageInfo(list);
    }

    /**
     * 导出苹果支付订单列表
     */
    @PreAuthorize("@ss.hasPermi('applepay:order:export')")
    @Log(title = "苹果支付订单", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出苹果支付订单列表Excel")
    public Response<String> export(@ModelAttribute ApplepayOrder applepayOrder){
        List<ApplepayOrder> list = applepayOrderService.selectApplepayOrderList(applepayOrder);
        ExcelUtil<ApplepayOrder> util = new ExcelUtil<ApplepayOrder>(ApplepayOrder.class);
        return util.exportExcel(list, "order");
    }

    /**
     * 获取苹果支付订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('applepay:order:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取苹果支付订单详细信息")
    public Response<ApplepayOrder> getInfo(
            @ApiParam(name = "id", value = "苹果支付订单参数", required = true)
            @PathVariable("id") Long id
    ){
        return Response.success(applepayOrderService.getById(id));
    }

    /**
     * 新增苹果支付订单
     */
    @PreAuthorize("@ss.hasPermi('applepay:order:add')")
    @Log(title = "苹果支付订单", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增苹果支付订单")
    public Response<Integer> add(@RequestBody ApplepayOrder applepayOrder){
        return toResponse(applepayOrderService.save(applepayOrder) ? 1 : 0);
    }

    /**
     * 修改苹果支付订单
     */
    @PreAuthorize("@ss.hasPermi('applepay:order:edit')")
    @Log(title = "苹果支付订单", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改苹果支付订单")
    public Response<Integer> edit(@RequestBody ApplepayOrder applepayOrder){
        return toResponse(applepayOrderService.updateById(applepayOrder) ? 1 : 0);
    }

    /**
     * 删除苹果支付订单
     */
    @PreAuthorize("@ss.hasPermi('applepay:order:remove')")
    @Log(title = "苹果支付订单", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除苹果支付订单")
    public  Response<Integer> remove(
            @ApiParam(name = "ids", value = "苹果支付订单ids参数", required = true)
            @PathVariable Long[] ids
    ){
        return toResponse(applepayOrderService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
