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.WechatPaymentHistoryConvert;
import com.wzj.soopin.order.domain.bo.WechatPaymentHistoryBo;
import com.wzj.soopin.order.domain.entity.WechatPaymentHistory;
import com.wzj.soopin.order.domain.vo.WechatPaymentHistoryVO;
import com.wzj.soopin.order.service.WechatPaymentHistoryService;
import com.wzj.soopin.order.service.impl.WechatPaymentHistoryServiceImpl;
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
 * &#064;date  2023-07-12
 */
@Tag(name ="微信订单表接口列表")
@RestController
@RequestMapping("/pms/omsWechatPaymentHistory")
@RequiredArgsConstructor
public class WechatPaymentHistoryController extends BaseController {

    private final WechatPaymentHistoryServiceImpl service;
    private final WechatPaymentHistoryConvert convert;
    private final WechatPaymentHistoryService wechatPaymentHistoryService;
    @Tag(name ="查询微信订单表列表")
    @PostMapping("/list")
    public R<IPage<WechatPaymentHistoryVO>> list(@RequestBody WechatPaymentHistoryBo query, Page<WechatPaymentHistory> page) {
        Page<WechatPaymentHistory> list = wechatPaymentHistoryService.page(page,query.toWrapper() );
        return R.ok(convert.toVO(list));
    }

    @Tag(name ="导出微信订单表列表")
    @Log(title = "微信订单表", businessType = BusinessType.EXPORT)
    @PostMapping("export")
    public R<String> export(WechatPaymentHistoryBo query) {
        List<WechatPaymentHistory> list = service.list(query.toWrapper());
        ExcelUtil<WechatPaymentHistoryVO> util = new ExcelUtil<>(WechatPaymentHistoryVO.class);
        return R.ok(util.writeExcel(convert.toVO(list), "微信订单表数据"));
    }

    @Tag(name ="获取微信订单表详细信息")
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") Long id) {
       return R.ok(service.getById(id));
    }

    @Tag(name ="新增微信订单表")
    @Log(title = "微信订单表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R add(@RequestBody WechatPaymentHistory wechatPaymentHistory) {
        return R.ok(service.save(wechatPaymentHistory));
    }

    @Tag(name ="修改微信订单表")
    @Log(title = "微信订单表", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public R edit(@RequestBody WechatPaymentHistory wechatPaymentHistory) {
        return R.ok(service.updateById(wechatPaymentHistory));
    }

    @Tag(name ="删除微信订单表")
    @Log(title = "微信订单表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public R remove(@PathVariable Long id) {
       return R.ok(service.removeById(id));
    }
}
