package com.ruoyi.web.controller.buyerapi;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.buyerapi.domain.BuyerOrderRecord;
import com.ruoyi.buyerapi.service.IBuyerOrderRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单记录Controller
 *
 * @author ruoyi
 * @date 2022-09-19
 */
@Api(tags = "订单记录")
@RestController
@RequestMapping("/buyer/record")
public class BuyerOrderRecordController extends BaseController
{
    @Autowired
    private IBuyerOrderRecordService buyerOrderRecordService;

    /**
     * 查询订单记录列表
     */
    @ApiOperation(value = "查询订单记录列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "no", value = "订单号", required = true, paramType = "query"),
            @ApiImplicitParam(name = "company", value = "企业名称", required = true, paramType = "query"),
            @ApiImplicitParam(name = "payPrice", value = "实付金额", required = true, paramType = "query"),
            @ApiImplicitParam(name = "goodsName", value = "商品名称", required = true, paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", required = true, paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", required = true, paramType = "query"),
            @ApiImplicitParam(name = "payStatus", value = "支付状态（0未支付1已支付）", required = true, paramType = "query"),
            @ApiImplicitParam(name = "orderStatus", value = "订单状态(0：待支付，1：交易完成，2：订单已关闭", required = true, paramType = "query"),
            @ApiImplicitParam(name = "payType", value = "支付方式", required = true, paramType = "query"),
            @ApiImplicitParam(name = "memberPayDuration", value = "服务时长", required = true, paramType = "query"),
            @ApiImplicitParam(name = "billStatus", value = "开票状态（0：可开票，1：开票中，2：已开票）", required = true, paramType = "query")
    })
    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(BuyerOrderRecord buyerOrderRecord)
    {
        startPage();
        buyerOrderRecord.setDeptId(SecurityUtils.getCompanyId());
        List<BuyerOrderRecord> list = buyerOrderRecordService.selectBuyerOrderRecordList(buyerOrderRecord);
        return getDataTable(list);
    }

    /**
     * 导出订单记录列表
     */
    @ApiOperation(value = "导出订单记录列表")
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "订单记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyerOrderRecord buyerOrderRecord)
    {
        List<BuyerOrderRecord> list = buyerOrderRecordService.selectBuyerOrderRecordList(buyerOrderRecord);
        ExcelUtil<BuyerOrderRecord> util = new ExcelUtil<BuyerOrderRecord>(BuyerOrderRecord.class);
        util.exportExcel(response, list, "订单记录数据");
    }

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

    /**
     * 新增订单记录
     */
    @ApiOperation(value = "新增订单记录")
    @Log(title = "订单记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuyerOrderRecord buyerOrderRecord)
    {
        buyerOrderRecord.setId(IdUtil.simpleUUID());
        buyerOrderRecord.setCreateBy(getUsername());
        return toAjax(buyerOrderRecordService.insertBuyerOrderRecord(buyerOrderRecord));
    }

    /**
     * 修改订单记录
     */
    @ApiOperation(value = "修改订单记录")
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "订单记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuyerOrderRecord buyerOrderRecord)
    {
        buyerOrderRecord.setUpdateBy(getUsername());
        return toAjax(buyerOrderRecordService.updateBuyerOrderRecord(buyerOrderRecord));
    }

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