package com.fjhx.controller.order;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.enums.stock.OutTypeEnum;
import com.fjhx.params.order.IssueVo;
import com.fjhx.params.order.OrderInfoEx;
import com.fjhx.params.order.OrderInfoVo;
import com.fjhx.service.order.OrderDetailsService;
import com.fjhx.service.order.OrderInfoService;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * <p>
 * 销售订单 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-12-08
 */
@RestController
@RequestMapping("/orderJd")
public class OrderJdController {

    @Autowired
    private OrderInfoService orderInfoService;

    @Autowired
    private OrderDetailsService orderDetailsService;

    @PostMapping("/page")
    public R page(@RequestBody Map<String, Object> condition) {
        condition.put("type", 3);
        Page<OrderInfoEx> result = orderInfoService.getPage(condition);
        return R.success(result);
    }

    @PostMapping("/add")
    public R add(@RequestBody OrderInfoVo orderInfoVo) {
        orderInfoVo.setType(3);
        orderInfoService.add(orderInfoVo);
        return R.success();
    }

    @PostMapping("/edit")
    public R edit(@RequestBody OrderInfoVo orderInfoVo) {
        orderInfoService.edit(orderInfoVo);
        return R.success();
    }

    @PostMapping("/excelImport")
    public R excelImport(@RequestParam("file") MultipartFile file) {
        Long flag = orderInfoService.excelImport(file);
        return R.data(flag);
    }

    /**
     * 出库分页列表
     */
    @PostMapping("/issuePage")
    public R issuePage(@RequestBody Map<String, Object> condition) {
        condition.put("type", 3);
        condition.put("deliverable", true);
        Page<OrderInfoEx> result = orderInfoService.getPage(condition);
        return R.success(result);
    }

    /**
     * 京东出库
     */
    @PostMapping("/issue")
    public R issue(@RequestBody IssueVo issueVo) {
        issueVo.setOutTypeEnum(OutTypeEnum.JD);
        orderDetailsService.issue(issueVo);
        return R.success();
    }

}

