
package com.wzj.soopin.order.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzj.soopin.order.convert.OrderOperateHistoryConvert;
import com.wzj.soopin.order.domain.bo.OrderOperateHistoryBo;
import com.wzj.soopin.order.domain.entity.OrderOperateHistory;
import com.wzj.soopin.order.domain.vo.OrderOperateHistoryVO;
import com.wzj.soopin.order.service.impl.OrderOperateHistoryServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.web.core.BaseController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单操作历史记录
 *
 * @author zcc
 * @date 2022-12-01
 */
@Tag(name = "订单操作历史记录")
@RestController
@RequestMapping("/oms/orderOperateHistory")
@RequiredArgsConstructor
public class OrderOperateHistoryController extends BaseController {


    private final OrderOperateHistoryServiceImpl service;
    private final OrderOperateHistoryConvert convert;

    @Operation(summary = "查询订单操作历史记录列表")
    @PostMapping("/list")
    public R<IPage<OrderOperateHistoryVO>> list(@RequestBody OrderOperateHistoryBo query, Page<OrderOperateHistory> page) {
        Page<OrderOperateHistory> list = service.page(page,query.toWrapper() );
        return R.ok(convert.toVO(list));
    }


    @Operation(summary = "导出订单操作历史记录列表")
    @Log(title = "订单操作历史记录", businessType = BusinessType.EXPORT)
    @PostMapping("export")
    public R<String> export(OrderOperateHistoryBo query) {
        List<OrderOperateHistory> list = service.list(query.toWrapper());
        ExcelUtil<OrderOperateHistoryVO> util = new ExcelUtil<>(OrderOperateHistoryVO.class);
        return R.ok(util.writeExcel(convert.toVO(list), "订单操作历史记录数据"));
    }

    @Operation(summary = "获取订单操作历史记录详细信息")
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") Long id) {
        return R.ok(service.getById(id));
    }

    @Operation(summary = "新增订单操作历史记录")
    @Log(title = "订单操作历史记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R add(@RequestBody OrderOperateHistory orderOperateHistory) {
        return R.ok(service.save(orderOperateHistory));
    }

    @Operation(summary = "修改订单操作历史记录")
    @Log(title = "订单操作历史记录", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public R edit(@RequestBody OrderOperateHistory orderOperateHistory) {
        return R.ok(service.updateById(orderOperateHistory));
    }

    @Operation(summary = "删除订单操作历史记录")
    @Log(title = "订单操作历史记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R remove(@PathVariable Long id) {
        return R.ok(service.removeById(id));
    }
}
