package com.cim.idm.controller;

import com.cim.idm.model.HoldAndReleaseDto;
import com.cim.idm.response.BaseResponse;
import com.cim.idm.response.RespGenerator;
import com.cim.idm.service.HoldAndReleaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

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

@RestController
@RequestMapping("/holdAndRelease")
@Slf4j
@Api(tags = "HoldAndReleaseController", description = "冻结解冻库存")
public class HoldAndReleaseController {

    @Autowired
    private HoldAndReleaseService holdAndReleaseService;

    @PostMapping("/holdAndReleaseM")
    @ApiOperation(value = "冻结解冻库存")
    public BaseResponse<Object> hold(HttpServletRequest request,
                                     HttpServletResponse response,
                                     @ApiParam(value = "冻结解冻参数", required = true) @RequestBody HoldAndReleaseDto HoldAndReleaseDto){
        log.info("HoldAndReleaseController hold {}", HoldAndReleaseDto);
        try {
            if (HoldAndReleaseDto == null) {
                return RespGenerator.returnError("参数错误");
            }
            holdAndReleaseService.hold(HoldAndReleaseDto);
        } catch (Exception e) {
            log.error("HoldAndReleaseController hold error", e);
            return RespGenerator.returnError("参数错误");
        }
        return RespGenerator.returnOK(null);
    }

}
