
package com.wzj.soopin.order.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzj.soopin.order.convert.AftersaleItemConvert;
import com.wzj.soopin.order.domain.bo.AftersaleItemBo;
import com.wzj.soopin.order.domain.entity.AftersaleItem;
import com.wzj.soopin.order.domain.vo.AftersaleItemVO;
import com.wzj.soopin.order.service.AftersaleItemService;
import com.wzj.soopin.order.service.impl.AftersaleItemServiceImpl;
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.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单售后Controller
 *
 * @author zcc
 * @date 2022-12-29
 */
@Tag(name = "订单售后接口列表")
@RestController
@RequestMapping("/oms/aftersaleItem")
@RequiredArgsConstructor
public class AftersaleItemController extends BaseController {

    private final AftersaleItemServiceImpl service;
    private final AftersaleItemConvert convert;
    private final AftersaleItemService aftersaleItemService;

    @Operation(summary = "查询订单售后列表")
    @PostMapping("/list")
    public R<Page<AftersaleItemVO>> list(@RequestBody AftersaleItemBo query, Page<AftersaleItem> page) {
        Page<AftersaleItem> list =  aftersaleItemService.page(page,query.toWrapper() );
        return R.ok(convert.toVO(list));
    }

    @Operation(summary = "导出订单售后列表")
    @Log(title = "订单售后", businessType = BusinessType.EXPORT)
    @PostMapping("export")
    public R<String> export(AftersaleItemBo query) {
        List<AftersaleItem> list = service.list(query.toWrapper());
        ExcelUtil<AftersaleItemVO> util = new ExcelUtil<>(AftersaleItemVO.class);
        return R.ok(util.writeExcel(convert.toVO(list), "订单售后数据"));
    }

    @Operation(summary = "获取订单售后详细信息")
    @GetMapping(value = "/{id}")
    public ResponseEntity<AftersaleItem> getInfo(@PathVariable("id") Long id) {
        return ResponseEntity.ok(service.getById(id));
    }

    @Operation(summary = "新增订单售后")
    @Log(title = "订单售后", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R add(@RequestBody AftersaleItemBo aftersaleItem) {
        return R.ok(service.save(convert.toPo(aftersaleItem)));
    }


    @Operation(summary = "修改订单售后")
    @Log(title = "订单售后", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public R edit(@RequestBody AftersaleItem aftersaleItem) {
        return R.ok(service.updateById(aftersaleItem));
    }


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