package com.qmth.sop.server.api;

import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.sop.business.entity.TBDelayWarnDetail;
import com.qmth.sop.business.service.TBDelayWarnDetailService;
import com.qmth.sop.common.annotation.OperationLog;
import com.qmth.sop.common.contant.SystemConstant;
import com.qmth.sop.common.enums.LogTypeEnum;
import com.qmth.sop.common.util.Result;
import com.qmth.sop.common.util.ResultUtil;
import io.swagger.annotations.*;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 延期预警明细表 控制器
 *
 * @author: shudonghui
 * @date: 2023-08-08 16:02:22
 * @version: 1.0
 * @email: shudonghui@qmth.com.cn
 * @Company: www.qmth.com.cn
 */
@Api(tags = "延期预警明细表 Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_DELAY_WARN_DETAIL)
public class TBDelayWarnDetailController {


    @Resource
    TBDelayWarnDetailService tBDelayWarnDetailService;


    @ApiOperation(value = "延期预警明细表查询接口")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "延期预警明细表查询结果", response = TBDelayWarnDetail.class)})
    public Result list(@ApiParam(value = "延期预警表id", required = true) @RequestParam(required = true) long id) {
        List<TBDelayWarnDetail> tbDelayWarnDetails = tBDelayWarnDetailService.list(id);
        return ResultUtil.ok(tbDelayWarnDetails);
    }


    @ApiOperation(value = "延期预警明细表新增修改接口")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})
    @OperationLog(logType = LogTypeEnum.EDIT)
    public Result save(@Valid @ApiParam(value = "延期预警明细表信息", required = true) @RequestBody(required = true) TBDelayWarnDetail tBDelayWarnDetail, BindingResult bindingResult) throws InterruptedException {
        if (bindingResult.hasErrors()) {
            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        return ResultUtil.ok(tBDelayWarnDetailService.saveTBDelayWarnDetail(tBDelayWarnDetail));
    }


}