
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.OrderDeliveryHistoryConvert;
import com.wzj.soopin.order.domain.bo.OrderDeliveryHistoryBo;
import com.wzj.soopin.order.domain.entity.OrderDeliveryHistory;
import com.wzj.soopin.order.domain.vo.OrderDeliveryHistoryVO;
import com.wzj.soopin.order.service.OrderDeliveryHistoryService;
import com.wzj.soopin.order.service.impl.OrderDeliveryHistoryServiceImpl;
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;

/**
 * 订单发货记录Controller
 *
 * @author zcc
 * @date 2022-12-01
 */
@Tag(name = "订单发货记录")
@RestController
@RequestMapping("/oms/orderDeliveryHistory")
@RequiredArgsConstructor
public class OrderDeliveryHistoryController extends BaseController {

    private final OrderDeliveryHistoryServiceImpl service;
    private final OrderDeliveryHistoryConvert convert;
    private final OrderDeliveryHistoryService historyService;

    @Operation(summary = "查询订单发货列表")
    @PostMapping("/list")
    public R<IPage<OrderDeliveryHistoryVO>> list(@RequestBody OrderDeliveryHistoryBo query, Page<OrderDeliveryHistory> page) {
        Page<OrderDeliveryHistory> list =  historyService.page(page,query.toWrapper() );
        return R.ok(convert.toVO(list));
    }

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


    @Operation(summary = "获取订单发货记录详细信息")
    @GetMapping(value = "/{id}")
    public R<OrderDeliveryHistory> getInfo(@PathVariable("id") Long id) {
        return R.ok(service.getById(id));
    }


    @Operation(summary = "新增订单发货记录")
    @Log(title = "订单发货记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R add(@RequestBody OrderDeliveryHistory orderDeliveryHistory) {
        return R.ok(service.save(orderDeliveryHistory));
    }

    @Operation(summary = "修改订单发货记录")
    @Log(title = "订单发货记录", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public R edit(@RequestBody OrderDeliveryHistory orderDeliveryHistory) {
        return R.ok(service.updateById(orderDeliveryHistory));
    }

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