package com.sw.mes.yb.alloy.controller;

import com.sw.mes.core.response.Result;
import com.sw.mes.core.response.ResultGenerator;
import com.sw.mes.yb.alloy.dto.FeedingConfirmationDto;
import com.sw.mes.yb.alloy.dto.FurnaceCodeDto;
import com.sw.mes.yb.alloy.service.FeedingConfirmationService;
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.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author lf
 * @description
 * @date 2024/3/5 10:01
 */
@RestController
@RequestMapping("/feedingConfirmation")
@Slf4j
@Api(description = "母合金加料确认")
public class FeedingConfirmationController {

    @Autowired
    private FeedingConfirmationService feedingConfirmationService;


    @ApiOperation(value = "根据炉台号查询复投次数")
    @GetMapping("/findByFurnaceCode")
    public Result<FurnaceCodeDto> findAgainNumByCode(@RequestParam @ApiParam(value = "炉台号") String furnaceCode) {
        return ResultGenerator.success(feedingConfirmationService.findAgainNumByCode(furnaceCode));
    }

    @ApiOperation(value = "母合金加料确认")
    @PostMapping("/feedingConfirmation")
    public Result feedingConfirmation(@RequestBody @Valid @ApiParam(value = "母合金加料对象") FeedingConfirmationDto feedingConfirmationDto, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultGenerator.fail(bindingResult.getFieldError().getDefaultMessage());
        }
        feedingConfirmationService.feedingConfirmation(feedingConfirmationDto);
        return ResultGenerator.success();
    }
}
