package com.cim.idm.controller;

import com.alibaba.fastjson.JSONObject;
import com.cim.idm.model.BarcodeListByInvoice;
import com.cim.idm.model.HoldAndReleaseDto;
import com.cim.idm.response.BaseResponse;
import com.cim.idm.response.RespGenerator;
import com.cim.idm.service.AllocateStockInService;
import com.cim.idm.utils.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/AllocateStockIn")
@Slf4j
@Api(tags = "调拨入库")
public class AllocateStockInController {

    private AllocateStockInService allocateStockInService;

    /**
     * 调拨入库过账
     * @param request
     * @param response
     * @param barcodeListByInvoice
     * @return
     */
    @RequestMapping(value = "/commit", method = RequestMethod.POST)
    public BaseResponse<Object> commit(HttpServletRequest request,
                                       HttpServletResponse response,
                                       @ApiParam(value = "调拨入库参数", required = true) @RequestBody BarcodeListByInvoice barcodeListByInvoice)  {
    log.info("AllocateStockInController commit {}", barcodeListByInvoice);
        try {
            allocateStockInService.allocateStockIn(barcodeListByInvoice.getShipRequestName(),
                    barcodeListByInvoice.getSiteName(),
                    barcodeListByInvoice.getUserId(),
                    barcodeListByInvoice.getErpLocation(),barcodeListByInvoice.getLocationName());
        } catch (Exception e) {
            return RespGenerator.returnError(e.toString());
        }

        return RespGenerator.returnOK(null);
    }
}
