
package cn.ysk.cashier.controller.order;

import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.annotation.rest.AnonymousPostMapping;
import cn.ysk.cashier.dto.order.TbOrderInfoDto;
import cn.ysk.cashier.dto.order.TbOrderInfoQueryCriteria;
import cn.ysk.cashier.dto.order.TbPayCountQueryCriteria;
import cn.ysk.cashier.pojo.order.TbOrderInfo;
import cn.ysk.cashier.service.order.TbOrderInfoService;
import cn.ysk.cashier.vo.TbOrderPayCountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
* @website https://eladmin.vip
* @author lyf
* @date 2024-03-02
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "订单管理")
@RequestMapping("/api/tbOrderInfo")
public class TbOrderInfoController {

    private final TbOrderInfoService tbOrderInfoService;

    @ApiOperation("导出数据")
    @PostMapping(value = "/download")
    public void exportTbOrderInfo(HttpServletResponse response, @RequestBody TbOrderInfoQueryCriteria criteria) throws IOException {
        tbOrderInfoService.download(tbOrderInfoService.queryAll(criteria), response);
    }

    @PostMapping("/date")
    @ApiOperation("查询订单")
    public ResponseEntity<Object> queryTbOrderInfo(@RequestBody TbOrderInfoQueryCriteria criteria){
        return new ResponseEntity<>(tbOrderInfoService.queryAllPage(criteria),HttpStatus.OK);
    }

    @PostMapping("/payCount")
    @ApiOperation("通过shopId查询支付统计")
    public List<TbOrderPayCountVo> queryTbOrderPayCount(@RequestBody TbPayCountQueryCriteria criteria){
        return tbOrderInfoService.queryTbOrderPayCount(criteria);
    }

    @GetMapping("/{id}")
    @ApiOperation("通过Id查询订单")
    public TbOrderInfoDto queryTbOrderInfo(@PathVariable("id") Integer id){
        return tbOrderInfoService.findById(id);
    }

//    @PostMapping
//    @ApiOperation("新增订单")
//    public ResponseEntity<Object> createTbOrderInfo(@Validated @RequestBody TbOrderInfo resources){
//        return new ResponseEntity<>(tbOrderInfoService.create(resources),HttpStatus.CREATED);
//    }

//    @PutMapping
//    @ApiOperation("修改订单")
//    public ResponseEntity<Object> updateTbOrderInfo(@Validated @RequestBody TbOrderInfo resources){
//        tbOrderInfoService.update(resources);
//        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
//    }

//    @DeleteMapping
//    @ApiOperation("删除订单")
//    public ResponseEntity<Object> deleteTbOrderInfo(@RequestBody Integer[] ids) {
//        tbOrderInfoService.deleteAll(ids);
//        return new ResponseEntity<>(HttpStatus.OK);
//    }
}
