package com.younike.merchant;

import com.younike.common.annotation.Log;
import com.younike.common.core.controller.BaseController;
import com.younike.common.core.domain.AjaxResult;
import com.younike.common.core.page.TableDataInfo;
import com.younike.common.enums.BusinessType;
import com.younike.system.domain.OrderRecord;
import com.younike.system.service.IMerchantOrderRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单记录Controller
 *
 * @author jubs
 * @date 2022-01-11
 */
@Api("订单记录接口")
@RestController
@RequestMapping("/order/record")
public class MerchantOrderRecordController extends BaseController {
    @Autowired
    private IMerchantOrderRecordService orderRecordService;

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