package com.nantian.cloud.dbcapp.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nantian.cloud.dbcapp.entity.BelowGradeNotice;
import com.nantian.cloud.dbcapp.service.BelowGradeNoticeService;
import com.nantian.sc.cloud.common.core.util.R;
import com.nantian.sc.cloud.common.log.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@CrossOrigin
@RestController
@AllArgsConstructor
@RequestMapping("/belowGradeNotice")
@Api(value = "belowGradeNotice", tags = "不合格通知书")
public class BelowGradeNoticeController {

    @Autowired
    private BelowGradeNoticeService belowGradeNoticeService;

    @GetMapping("/manage")
    @SysLog("查询不合格通知书管理信息")
    @ApiOperation(value = "查询不合格通知书管理信息", notes = "查询不合格通知书管理信息")
    public R getManageInfo(Page page, BelowGradeNotice belowGradeNotice) {
        return  R.ok(belowGradeNoticeService.getManageInfo(page,belowGradeNotice));
    }

    @GetMapping("/detail")
    @SysLog("查询不合格通知书详细信息")
    @ApiOperation(value = "查询不合格通知书详细信息", notes = "查询不合格通知书详细信息")
    public R getDetailInfo(Page page, BelowGradeNotice belowGradeNotice) {
        if(belowGradeNotice.getPid() == 0){
            return R.ok("请选择具体需要查看的不合格通知书主题");
        }
        return R.ok(belowGradeNoticeService.getDetailInfo(page,belowGradeNotice));
    }

    @PostMapping("/batchUpload")
    @SysLog("批量上传不合格通知书")
    @ApiOperation(value = "批量上传不合格通知书", notes = "批量上传不合格通知书")
    public R batchUpload(@RequestParam MultipartFile multipartFile, Integer pid, String status, String content) throws Exception {
        return belowGradeNoticeService.batchUpload(multipartFile, pid, status, content);
    }

    @PostMapping("/renewManage")
    @SysLog("更新不合格通知书管理信息")
    @ApiOperation(value = "更新不合格通知书管理信息", notes = "更新不合格通知书管理信息")
    public R renewManage(@RequestBody BelowGradeNotice belowGradeNotice) {
        return belowGradeNoticeService.renewManage(belowGradeNotice);
    }

    @SneakyThrows
    @PostMapping("/renewDetail")
    @SysLog("更新不合格通知书详细信息")
    @ApiOperation(value = "更新不合格通知书详细信息", notes = "更新不合格通知书详细信息")
    public R renewDetail(@RequestParam MultipartFile multipartFile, BelowGradeNotice belowGradeNotice) throws Exception {
        return belowGradeNoticeService.renewDetail( multipartFile, belowGradeNotice);
    }





}
