package com.dk.mdm.controller.sale;

import com.dk.common.infrastructure.constant.Constant;
import com.dk.common.model.pojo.PageList;
import com.dk.common.response.ResponseResultVO;
import com.dk.mdm.mapper.pur.PurchaseItemMapper;
import com.dk.mdm.model.pojo.sale.Order;
import com.dk.common.service.BaseService;
import com.dk.mdm.model.query.sale.OrderQuery;
import com.dk.mdm.model.response.sale.OrderResponse;
import com.dk.mdm.model.vo.pur.PurchaseVO;
import com.dk.mdm.model.vo.sale.OrderVO;
import com.dk.mdm.service.pur.PurchaseService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import com.dk.mdm.service.sale.OrderService;

import java.util.Map;

@Api(tags = "销售订单API接口")
@RestController
@RequestMapping("/sale/order")
public class OrderController {

    public BaseService<Order> getService() {
        return orderService;
    }

    @Autowired
    private OrderService orderService;

    /**
     * @desc : 条件查询
     * @author : 付斌
     * @date : 2023/1/9 10:36
     */
    @ApiOperation(value = "分页、关联、条件查询", notes = "分页、关联、条件查询")
    @PostMapping({"list_by"})
    public ResponseResultVO<PageList<OrderResponse>> selectByCond(@RequestBody OrderQuery orderQuery) {
        return orderService.selectByCond(orderQuery);
    }

    /**
     * @desc : 条件查询(数量）小程序使用
     * @author : 周兴
     * @date : 2024/4/10 10:36
     */
    @ApiOperation(value = "条件查询(数量）小程序使用", notes = "条件查询(数量）小程序使用")
    @PostMapping({"count_order_by_cond"})
    public ResponseResultVO<?> countOrderByCond(@RequestBody OrderQuery orderQuery) {
        return orderService.countByCond(orderQuery);
    }

    /**
     * @desc : 以销定采 查询
     * @author : 王英杰
     * @date : 2023/3/14 10:36
     */
    @ApiOperation(value = "分页、关联、条件查询", notes = "分页、关联、条件查询")
    @PostMapping({"purchase_based_on_sales_list_by"})
    public ResponseResultVO<PageList<Map<String, Object>>> purSaleSelectByCond(@RequestBody OrderQuery orderQuery) {
        return orderService.purSaleSelectByCond(orderQuery);
    }


    /**
     * @desc :查询订单明细（货物、收款、附件）
     * @author : 付斌
     * @date : 2024-02-28 13:24
     */
    @PostMapping({"select_order_info_by_id/{id}"})
    public ResponseResultVO<Map<String, Object>> selectOrderInfoById(@PathVariable String id) {
        return orderService.selectOrderInfoById(id);
    }

    /**
     * @desc : 通过ID查询
     * @author : 付斌
     * @date : 2023/1/9 10:41
     */
    @PostMapping({"/{id}"})
    public ResponseResultVO selectById(@PathVariable String id) {
        return orderService.selectById(id);
    }


    /**
     * @desc : 新建订单
     * @author : 付斌
     * @date : 2023/1/9 10:48
     */
    @ApiOperation(value = "新建订单", notes = "新建订单")
    @PostMapping({"insert"})
    public ResponseResultVO<?> insert(@RequestBody OrderVO orderVO) {
        return orderService.insert(orderVO);
    }

    /**
     * @desc : 编辑订单
     * @author : 付斌
     * @date : 2023/1/9 10:49
     */
    @ApiOperation(value = "编辑订单", notes = "编辑订单")
    @PostMapping({"update"})
    public ResponseResultVO<?> update(@RequestBody OrderVO orderVO) {
        return orderService.update(orderVO);
    }

    /**
     * @desc : 作废
     * @author : 付斌
     * @date : 2024-03-08 16:36
     */
    @ApiOperation(value = "作废", notes = "作废")
    @PostMapping({"invalid/{id}"})
    public ResponseResultVO<?> invalid(@PathVariable String id) {
        return orderService.invalid(id);
    }

    /**
     * @desc : 获取订单信息（编辑用）
     * @author : 付斌
     * @date : 2024-03-03 9:28
     */
    @ApiOperation(value = "获取订单信息（编辑用）", notes = "获取订单信息（编辑用）")
    @PostMapping({"get_order_for_update/{id}"})
    public ResponseResultVO<?> getOrderForUpdate(@PathVariable String id) {
        return orderService.getOrderForUpdate(id);
    }

    /**
     * @desc : 获取订单信息（出库用）
     * @author : 付斌
     * @date : 2024-03-06 12:58
     */
    @ApiOperation(value = "获取订单信息（出库用）", notes = "获取订单信息（出库用）")
    @PostMapping({"get_order_for_out/{id}"})
    public ResponseResultVO<?> getOrderForOut(@PathVariable String id) {
        return orderService.getOrderForOut(id);
    }

    /**
     * @desc : 获取订单信息（退货用）
     * @author : 付斌
     * @date : 2024-03-06 12:58
     */
    @ApiOperation(value = "获取订单信息（退货用）", notes = "获取订单信息（退货用）")
    @PostMapping({"get_order_for_return/{id}"})
    public ResponseResultVO<?> getOrderForReturn(@PathVariable String id) {
        return orderService.getOrderForReturn(id);
    }



    /**
     * @desc : 条件查询(总单带明细)
     * @author : 于继渤
     * @date : 2023/1/9 10:36
     */
    @ApiOperation(value = "分页、关联、条件查询", notes = "分页、关联、条件查询")
    @PostMapping({"select_total_single_tape_detail_page"})
    public ResponseResultVO<PageList<OrderResponse>> selectTotalSingleTapeDetailPage(@RequestBody OrderQuery orderQuery) {
        return orderService.selectTotalSingleTapeDetailPage(orderQuery);
    }

    /**
     * @desc   : 销售跟踪报表
     * @author : 宋扬
     * @date   : 2024/4/24 17:16
     */
    @PostMapping("get_order_track_report")
    public ResponseResultVO<PageList> getOrderTrackReport(@RequestBody Map<String, Object> param) {
        return orderService.getOrderTrackReport(param);
    }
}
