package com.dk.mdm.controller.pur;

import com.dk.common.model.pojo.PageList;
import com.dk.common.response.ResponseResultVO;
import com.dk.mdm.model.pojo.pur.Purchase;
import com.dk.common.service.BaseService;
import com.dk.mdm.model.query.pur.PurchaseQuery;
import com.dk.mdm.model.response.pur.PurchaseResponse;
import com.dk.mdm.model.vo.pur.PurchaseVO;
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.pur.PurchaseService;

import javax.validation.Valid;
import java.util.Map;

@Api(tags = "采购订单API接口")
@RestController
@RequestMapping("/pur/purchase")
public class PurchaseController{

    public BaseService<Purchase> getService() {
        return purchaseService;
    }

    @Autowired
    private PurchaseService purchaseService;

    /**
     * @desc   : 条件查询
     * @author : 常皓宁
     * @date   : 2024/2/28 9:46
     */
    @ApiOperation(
            value = "分页、关联、条件查询",
            notes = "分页、关联、条件查询"
    )
    @PostMapping({"list_by"})
    public ResponseResultVO<PageList<PurchaseResponse>> selectByCond(@RequestBody PurchaseQuery purchaseQuery) {
        return purchaseService.selectByCond(purchaseQuery);
    }
    /**
     * @desc   : 条件查询 带明细（采购入库 查询采购订单 过滤已入库数据）
     * @author : 王英杰
     * @date   : 2024/2/28 9:46
     */
    @ApiOperation(
            value = "分页、关联、条件查询",
            notes = "分页、关联、条件查询"
    )
    @PostMapping({"list_by_item"})
    public ResponseResultVO<PageList<Map<String, Object>>> selectByCondItem(@RequestBody PurchaseQuery purchaseQuery) {
        return purchaseService.selectByCondItem(purchaseQuery);
    }
    /**
     * @desc   : 采购订单 待入库查询
     * @author : 王英杰
     * @date   : 2024/2/28 9:46
     */
    @ApiOperation(
            value = "分页、关联、条件查询",
            notes = "分页、关联、条件查询"
    )
    @PostMapping({"no_storedlist_by"})
    public ResponseResultVO<PageList<PurchaseResponse>> noStoredSelectByCond(@RequestBody PurchaseQuery purchaseQuery) {
        return purchaseService.noStoredSelectByCond(purchaseQuery);
    }
    @ApiOperation(
            value = "新建",
            notes = "新建"
    )
    @PostMapping("insert")
    public ResponseResultVO<?> insert(@RequestBody PurchaseVO Purchasevo) {
        return purchaseService.insert(Purchasevo);
    }

    /**
     * @desc   : 通过ID查询
     * @author : 常皓宁
     * @date   : 2024/2/28 14:56
     */
    @PostMapping({"/{id}"})
    public ResponseResultVO selectById(@PathVariable String id) {
        return purchaseService.selectById(id);
    }

    /**
     * @desc   : 转入库 查询采购订单 总单带明细(过滤明细已入库数据)
     * @author : 王英杰
     * @date   : 2024/2/28 14:56
     */
    @PostMapping({"pur_select_id/{id}"})
    public ResponseResultVO purSelectById(@PathVariable String id) {
        return purchaseService.purSelectById(id);
    }

    @ApiOperation(
            value = "编辑",
            notes = "编辑"
    )
    @PostMapping("update")
    public ResponseResultVO<Boolean> update(@RequestBody  PurchaseVO Purchasevo) {
        return purchaseService.update(Purchasevo);
    }

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

    /**
     * @desc   : 采购订单 转 采购入库   （目前废弃）
     * @author : 王英杰
     * @date   : 2024年3月11日
     */
    @PostMapping("insert_inbound")
    public ResponseResultVO<Boolean> insertInbound(@RequestBody  PurchaseVO Purchasevo) {
        return purchaseService.insertInbound(Purchasevo);
    }

    /**
     * @desc   : 采购跟踪
     * @author : 常皓宁
     * @date   : 2024/4/22 10:19
     */
    @PostMapping("select_track_report")
    public ResponseResultVO<PageList> selectTrackReport(@RequestBody Map<String, Object> param) {
        return purchaseService.selectTrackReport(param);
    }
}
