package com.ningdatech.carapi.industry.controller;


import com.ningdatech.basic.model.PageVo;
import com.ningdatech.carapi.common.util.ExcelDownUtil;
import com.ningdatech.carapi.industry.enums.LabWorkerCertificateTypeEnum;
import com.ningdatech.carapi.industry.manage.LabWorkerCertificateManage;
import com.ningdatech.carapi.industry.model.req.LabWorkerCertificateAuditReq;
import com.ningdatech.carapi.industry.model.req.LabWorkerCertificateListReq;
import com.ningdatech.carapi.industry.model.req.LabWorkerCertificateReq;
import com.ningdatech.carapi.industry.model.vo.LabWorkerCertificateChangeListVo;
import com.ningdatech.carapi.industry.model.vo.LabWorkerCertificateListVo;
import com.ningdatech.carapi.industry.service.ILabWorkerCertificateService;
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-04
 */
@Api(tags = "行业服务-实验室人员从业资格证")
@RestController
@AllArgsConstructor
@RequestMapping("/api/v1/industry/lab-worker-certificate")
public class LabWorkerCertificateController {

    private final LabWorkerCertificateManage labWorkerCertificateManage;
    private final ILabWorkerCertificateService labWorkerCertificateService;

    @GetMapping("/list")
    @ApiOperation("实验室人员[从业资格证|继续教育合格证]列表")
    public PageVo<LabWorkerCertificateListVo> labWorkerCertificateList(@Valid LabWorkerCertificateListReq req) {
        return labWorkerCertificateManage.labWorkerCertificateList(req);
    }

    @DeleteMapping("/del/{id}/{type}")
    @ApiOperation("删除[从业资格证|继续教育合格证]")
    @WebLog(value = "删除[从业资格证|继续教育合格证]", modular = "行业服务")
    public void delLabWorkerCertificate(@PathVariable Long id, @PathVariable Integer type) {
        // 验证类型合法性
        LabWorkerCertificateTypeEnum.getByCode(type);
        labWorkerCertificateManage.delete(id);
    }

    @GetMapping("/export")
    @ApiOperation("导出实验室人员[从业资格证|继续教育合格证]")
    public void exportLabWorkerCertificate(@Valid LabWorkerCertificateListReq req, HttpServletResponse response) {
        ExcelDownUtil.downXls(response, req, labWorkerCertificateManage::labWorkerCertificateExport);
    }

    @PostMapping("/saveOrUpdate")
    @ApiOperation("保存/修改[从业资格证|继续教育合格证]")
    @WebLog(value = "保存/修改[从业资格证|继续教育合格证]", modular = "行业服务")
    public void saveLabWorkerCertificate(@Valid @RequestBody LabWorkerCertificateReq req) {
        labWorkerCertificateManage.saveOrUpdate(req);
    }

    @ApiOperation("实验室人员[从业资格证|继续教育合格证]换证列表")
    @GetMapping("/changeList")
    public PageVo<LabWorkerCertificateChangeListVo> changeList(@Valid LabWorkerCertificateListReq req) {
        return labWorkerCertificateManage.changeCertificate(req);
    }

    @ApiOperation("审核[从业资格证|继续教育合格证换证申请]")
    @PostMapping("/audit")
    public Boolean audit(@Valid @RequestBody LabWorkerCertificateAuditReq req){
        return labWorkerCertificateManage.audit(req, LoginUserUtil.getUserId());
    }

    @ApiOperation("从业资格证取消审核")
    @PostMapping("/cancelAudit")
    public Boolean cancelAudit(@Valid @RequestBody LabWorkerCertificateAuditReq req){
        return labWorkerCertificateManage.cancelAudit(req, LoginUserUtil.getUserId());
    }
}
