package com.ningdatech.carapi.industry.controller;


import com.ningdatech.basic.model.PageVo;
import com.ningdatech.carapi.common.util.ExcelDownUtil;
import com.ningdatech.carapi.industry.manage.LabAcceptanceCertificateManage;
import com.ningdatech.carapi.industry.model.req.LabAcceptanceCertificateListReq;
import com.ningdatech.carapi.industry.model.req.LabAcceptanceCertificateReq;
import com.ningdatech.carapi.industry.model.req.LabWorkerCertificateAuditReq;
import com.ningdatech.carapi.industry.model.vo.LabAcceptanceCertificateChangeListVo;
import com.ningdatech.carapi.industry.model.vo.LabAcceptanceCertificateListVo;
import com.ningdatech.carapi.industry.service.ILabAcceptanceCertificateService;
import com.ningdatech.carapi.user.util.LoginUserUtil;
import com.ningdatech.log.annotation.WebLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * <p>
 * 实验室验收合格证 前端控制器
 * </p>
 *
 * @author WendyYang
 * @since 2022-11-08
 */
@RestController
@Api(tags = "行业服务-实验室验收合格证")
@AllArgsConstructor
@RequestMapping("/api/v1/industry/lab-acceptance-certificate")
public class LabAcceptanceCertificateController {

    private final LabAcceptanceCertificateManage labAcceptanceCertificateManage;
    private final ILabAcceptanceCertificateService labAcceptanceCertificateService;

    @GetMapping("/list")
    @ApiOperation("列表查询")
    public PageVo<LabAcceptanceCertificateListVo> list(LabAcceptanceCertificateListReq req) {
        return labAcceptanceCertificateManage.labAcceptanceCertificateList(req);
    }

    @GetMapping("/changeList")
    @ApiOperation("变更列表查询")
    public PageVo<LabAcceptanceCertificateChangeListVo> changeList(LabAcceptanceCertificateListReq req) {
        return labAcceptanceCertificateManage.changeList(req);
    }

    @GetMapping("/export")
    @ApiOperation("导出")
    public void export(LabAcceptanceCertificateListReq req, HttpServletResponse response) {
        ExcelDownUtil.downXls(response, req, labAcceptanceCertificateManage::exportLabAcceptanceCertificate);
    }

    @DeleteMapping("/del/{id}")
    @ApiOperation("删除")
    @WebLog(value = "删除")
    public void delete(@PathVariable Long id) {
        labAcceptanceCertificateManage.delete(id);
    }

    @PostMapping("/saveOrUpdate")
    @ApiOperation("新增/修改")
    @WebLog(value = "新增/修改")
    public void saveOrUpdate(@Valid @RequestBody LabAcceptanceCertificateReq req) {
        labAcceptanceCertificateManage.saveOrUpdate(req);
    }

    @ApiOperation("审核验收合格证换证申请]")
    @PostMapping("/audit")
    public Boolean audit(@Valid @RequestBody LabWorkerCertificateAuditReq req){
        return labAcceptanceCertificateManage.audit(req, LoginUserUtil.getUserId());
    }
}
