package com.younike.member.controller;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import com.younike.common.bean.APIResult;
import com.younike.common.bean.ResultGenerator;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import com.younike.common.core.page.PageParam;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.younike.common.annotation.OpLog;
import com.younike.common.core.controller.BaseController;
import com.younike.common.core.dto.AjaxResult;
import com.younike.common.constant.BusinessType;
import com.younike.service.pojo.Order;
import com.younike.service.service.IOrderService;
import com.younike.common.core.page.TableResult;

/**
 * 订单Controller
 *
 * @author dail
 * @date 2022-05-24
 */
@RestController
@RequestMapping("/order")
public class OrderController extends BaseController {
    @Autowired
    private IOrderService orderService;

    /**
     * 查询订单列表
     */
    @RequiresPermissions("order:list")
    @PostMapping("/list")
    public Page list(@RequestBody PageParam<Order> page) {

        return orderService.page(page);
    }


    /**
     * 获取订单详细信息
     */
    @RequiresPermissions("order:query")
    @GetMapping(value = "/{orderId}")
    public APIResult getInfo(@PathVariable("orderId") String orderId) {
        return ResultGenerator.getSuccessResult(orderService.getById(orderId));
    }

    /**
     * 新增订单
     */
    @RequiresPermissions("order:add")
    @OpLog(title = "订单", type = BusinessType.INSERT)
    @PostMapping
    public APIResult add(@RequestBody Order order) {
        return ResultGenerator.getSuccessResult(orderService.save(order));
    }

    /**
     * 修改订单
     */
    @RequiresPermissions("order:edit")
    @OpLog(title = "订单", type = BusinessType.UPDATE)
    @PutMapping
    public APIResult edit(@RequestBody Order order) {
        return ResultGenerator.getSuccessResult(orderService.updateById(order));
    }

    /**
     * 删除订单
     */
    @RequiresPermissions("order:remove")
    @OpLog(title = "订单", type = BusinessType.DELETE)
    @DeleteMapping("/{orderIds}")
    public APIResult remove(@PathVariable List<String> orderIds) {
        return ResultGenerator.getSuccessResult(orderService.removeByIds(orderIds));
    }
}
