package com.younike.server.controller;

import java.util.List;

import com.younike.framework.config.AnonymousAccess;
import com.younike.system.domain.vo.OrderGoodsVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
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.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.younike.common.core.controller.BaseController;
import com.younike.common.core.domain.AjaxResult;
import com.younike.common.enums.BusinessType;
import com.younike.system.domain.OrderGoods;
import com.younike.system.service.IOrderGoodsService;
import com.younike.common.utils.poi.ExcelUtil;
import com.younike.common.core.page.TableDataInfo;

/**
 * 订单商品Controller
 * 
 * @author elev
 * @date 2022-01-06
 */
@Api("订单商品接口")
@RestController
@RequestMapping("/server/goods")
public class ServerOrderGoodsController extends BaseController {
    @Autowired
    private IOrderGoodsService orderGoodsService;

    /**
     * 查询订单商品列表
     */
    @ApiOperation("查询订单商品列表")
    @PreAuthorize("@ss.hasPermi('system:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderGoods orderGoods) {
        startPage();
        List<OrderGoods> list = orderGoodsService.selectOrderGoodsList(orderGoods);
        return getDataTable(list);
    }

    /**
     * 导出订单商品列表
     */
    @ApiOperation("导出订单商品列表")
    @PreAuthorize("@ss.hasPermi('system:goods:export')")
    @Log(title = "订单商品", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OrderGoods orderGoods) {
        List<OrderGoods> list = orderGoodsService.selectOrderGoodsList(orderGoods);
        ExcelUtil<OrderGoods> util = new ExcelUtil<OrderGoods>(OrderGoods.class);
        return util.exportExcel(list, "订单商品数据");
    }

    /**
     * 获取订单商品详细信息
     */
    @ApiOperation("获取订单商品详细信息")
    @PreAuthorize("@ss.hasPermi('system:goods:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId) {
        return AjaxResult.success(orderGoodsService.selectOrderGoodsByOrderId(orderId));
    }

    /**
     * 新增订单商品
     */
    @ApiOperation("新增订单商品")
    @PreAuthorize("@ss.hasPermi('system:goods:add')")
    @Log(title = "订单商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderGoods orderGoods) {
        return toAjax(orderGoodsService.insertOrderGoods(orderGoods));
    }

    /**
     * 修改订单商品
     */
    @ApiOperation("修改订单商品")
    @PreAuthorize("@ss.hasPermi('system:goods:edit')")
    @Log(title = "订单商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderGoods orderGoods) {
        return toAjax(orderGoodsService.updateOrderGoods(orderGoods));
    }

    /**
     * 删除订单商品
     */
    @ApiOperation("删除订单商品")
    @PreAuthorize("@ss.hasPermi('system:goods:remove')")
    @Log(title = "订单商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds) {
        return toAjax(orderGoodsService.deleteOrderGoodsByOrderIds(orderIds));
    }

    /**
     * 获取服务端首页本周数值
     */
    @ApiOperation("获取服务端首页本周数值")
    @PostMapping("/getNowWeekDate")
    @AnonymousAccess
    public AjaxResult getNowWeekDate(@RequestBody OrderGoodsVo orderGoodsVo) {
        return AjaxResult.success(orderGoodsService.getNowWeekDate(orderGoodsVo));
    }
    /**
     * 获取服务端首页本周数值
     */
    @ApiOperation("获取服务端数值")
    @PostMapping("/getOrderNumDate")
    @AnonymousAccess
    public AjaxResult getOrderNumDate(@RequestBody OrderGoodsVo orderGoodsVo) {
        return AjaxResult.success(orderGoodsService.getOrderNumDate(orderGoodsVo));
    }

    /**
     * 获取订单列表
     */
    @ApiOperation("获取订单列表")
    @GetMapping("/getOrderList")
    @AnonymousAccess
    public TableDataInfo getOrderList(OrderGoodsVo orderGoodsVo) {
        startPage();
        List<OrderGoodsVo> list = orderGoodsService.getOrderList(orderGoodsVo);
        return getDataTable(list);
    }

    /**
     * 获取订单详情
     */
    @ApiOperation("获取订单详情")
    @PostMapping("/getOrderInfo")
    @AnonymousAccess
    public AjaxResult getOrderInfo(@RequestBody OrderGoodsVo orderGoodsVo) {
        OrderGoodsVo info = orderGoodsService.getOrderInfo(orderGoodsVo);
        return AjaxResult.success(info);
    }
}
