package com.qmth.sop.server.api;

import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.sop.business.entity.TBViolationDetail;
import com.qmth.sop.business.service.TBViolationDetailService;
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-09 10:33:08
 * @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_VIOLATION_DETAIL)
public class TBViolationDetailController {


    @Resource
    TBViolationDetailService tBViolationDetailService;


    @ApiOperation(value = "违规明细表查询接口")
    @RequestMapping(value = "/query", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "违规明细表查询结果", response = TBViolationDetail.class)})
    public Result query(@ApiParam(value = "sop违规登记表id", required = true) @RequestParam long id) {
//        List<TBViolationDetail> resultIPage = tBViolationDetailService.list(new QueryWrapper<TBViolationDetail>().lambda().eq(TBViolationDetail::getViolationId, id).orderByDesc(TBViolationDetail::getCreateTime));
        List<TBViolationDetail> resultIPage = tBViolationDetailService.listByViolationId(id);
        return ResultUtil.ok(resultIPage);
    }


    @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) TBViolationDetail tBViolationDetail, BindingResult bindingResult) throws InterruptedException {
        if (bindingResult.hasErrors()) {
            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        return ResultUtil.ok(tBViolationDetailService.saveTBViolationDetail(tBViolationDetail));
    }


}