package com.younike.server.controller;

import java.util.List;
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.OrderRecord;
import com.younike.system.service.IOrderRecordService;
import com.younike.common.utils.poi.ExcelUtil;
import com.younike.common.core.page.TableDataInfo;

/**
 * 订单记录Controller
 * 
 * @author elev
 * @date 2022-01-08
 */
@Api("订单记录接口")
@RestController
@RequestMapping("/system/record")
public class ServerOrderRecordController extends BaseController {
    @Autowired
    private IOrderRecordService orderRecordService;

    /**
     * 查询订单记录列表
     */
    @ApiOperation("查询订单记录列表")
    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderRecord orderRecord) {
        startPage();
        List<OrderRecord> list = orderRecordService.selectOrderRecordList(orderRecord);
        return getDataTable(list);
    }

    /**
     * 导出订单记录列表
     */
    @ApiOperation("导出订单记录列表")
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "订单记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OrderRecord orderRecord) {
        List<OrderRecord> list = orderRecordService.selectOrderRecordList(orderRecord);
        ExcelUtil<OrderRecord> util = new ExcelUtil<OrderRecord>(OrderRecord.class);
        return util.exportExcel(list, "订单记录数据");
    }

    /**
     * 获取订单记录详细信息
     */
    @ApiOperation("获取订单记录详细信息")
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(orderRecordService.selectOrderRecordById(id));
    }

    /**
     * 新增订单记录
     */
    @ApiOperation("新增订单记录")
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "订单记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderRecord orderRecord) {
        return toAjax(orderRecordService.insertOrderRecord(orderRecord));
    }

    /**
     * 修改订单记录
     */
    @ApiOperation("修改订单记录")
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "订单记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderRecord orderRecord) {
        return toAjax(orderRecordService.updateOrderRecord(orderRecord));
    }

    /**
     * 删除订单记录
     */
    @ApiOperation("删除订单记录")
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "订单记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(orderRecordService.deleteOrderRecordByIds(ids));
    }
}
