package com.dayou.controller;

import com.dayou.dto.TaskRecordDTO;
import com.dayou.vo.ProductionOutWarehouseApplyVO;
import com.dayou.workflow.annotation.FinishTask;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.RestController;
import com.dayou.controller.BaseController;
import com.dayou.service.IProductionOutWarehouseService;
import com.dayou.entity.ProductionOutWarehouse;
import com.dayou.common.RestResponse;
import org.springframework.web.bind.annotation.*;
import com.dayou.utils.ConvertUtil;
import com.dayou.utils.HttpKit;
import com.dayou.exception.ErrorCode;
import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.http.MediaType;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;

/**
 * 产品提前出库申请
 *
 * @author wucl
 * @since 2023-12-12
 */
@RestController
@RequestMapping("productionOutWarehouse")
@Slf4j
public class ProductionOutWarehouseController extends BaseController {
    @Autowired
    private IProductionOutWarehouseService productionOutWarehouseService;


    /**
    * 产品提前出库申请列表
    */
    @GetMapping("")
    public RestResponse<Page<ProductionOutWarehouse>> page(ProductionOutWarehouse productionOutWarehouse, Page page,String keyword){
        Page<ProductionOutWarehouse> pages=productionOutWarehouseService.selectPage(page,productionOutWarehouse,keyword);
        return RestResponse.data(pages);
    }

    /**
     * 产品提前出库申请详情
     */
    @GetMapping("/{id}")
    public RestResponse<ProductionOutWarehouse> detail(@PathVariable Long id){
        ProductionOutWarehouse xProductionOutWarehouse =productionOutWarehouseService.detail(id);
        return RestResponse.data(xProductionOutWarehouse);
     }

    /**
     * 产品提前出库申请新增
     */
    @FinishTask
    @PostMapping("")
    public RestResponse<Boolean> save(@RequestBody @Valid TaskRecordDTO<ProductionOutWarehouse> taskRecordDTO) {
        Boolean ret = productionOutWarehouseService.add(taskRecordDTO);
        return RestResponse.data(ret);
    }

    /**
     * 产品提前出库申请更新
     */
    @FinishTask
    @PutMapping("")
    public RestResponse<Boolean> update(@RequestBody TaskRecordDTO<ProductionOutWarehouse> taskRecordDTO) {
        Boolean ret = productionOutWarehouseService.update(taskRecordDTO);
        return RestResponse.data(ret);
    }

    /**
     * 产品提前出库申请删除
     */
    @DeleteMapping("/{id}")
    public RestResponse<Boolean> delete(@PathVariable Long id) {
        Boolean ret = productionOutWarehouseService.delete(id);
        return RestResponse.data(ret);
    }

    /**
     * 出库申请列表
     * @param id
     * @return
     */
    @GetMapping("/apply/{id}")
    public RestResponse<List<ProductionOutWarehouseApplyVO>> getList(@PathVariable("id") Long id){
        List<ProductionOutWarehouseApplyVO> list = productionOutWarehouseService.getList(id);
        return RestResponse.data(list);
    }

    /**
     * 大中型出库申请列表 (业务类型和产品id查询)
     * @return
     */
    @GetMapping("/production/{businessType}/{productionId}")
    public RestResponse<List<ProductionOutWarehouseApplyVO>> getListByBizTypeProductionId(@PathVariable("businessType") String businessType,
                                                                                   @PathVariable("productionId") Long productionId){
        List<ProductionOutWarehouseApplyVO> list = productionOutWarehouseService.getListByBizTypeProductionId(businessType,productionId);
        return RestResponse.data(list);
    }

    /**
     * 个贷出库申请列表
     * @return
     */
    @GetMapping("/personal/{orderId}")
    public RestResponse<List<ProductionOutWarehouseApplyVO>> getPersonalByOrderId(@PathVariable("orderId") Long orderId){
        List<ProductionOutWarehouseApplyVO> list = productionOutWarehouseService.getPersonalByOrderId(orderId);
        return RestResponse.data(list);
    }

    /**
     * 撤销申请
     * @param id
     * @return
     */
    @GetMapping("/cancel/{id}")
    public RestResponse<Boolean> cancel(@PathVariable("id") Long id){
       Boolean ret =  productionOutWarehouseService.cancel(id);
       return RestResponse.data(ret);
    }
}

