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.SafetyEquipmentIntallUserCertificateManage;
import com.ningdatech.carapi.industry.model.dto.UseCertPageParamDTO;
import com.ningdatech.carapi.industry.model.dto.UseCertSaveDTO;
import com.ningdatech.carapi.industry.model.dto.UseCertUpdateDTO;
import com.ningdatech.carapi.industry.model.vo.SafetyEquipmentInstallUseCertificateVO;
import com.ningdatech.carapi.user.util.LoginUserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * <p>
 * 安全设备安装使用证书信息 前端控制器
 * </p>
 *
 * @author PoffyZhang
 * @since 2022-11-09
 */
@Controller
@RequestMapping("/api/industry/safety-equipment-install-use-certificate")
@Slf4j
@Validated
@RestController
@Api(value = "SafetyEquipmentInstallUseCertificate", tags = "行业服务-安全设备安装使用证书")
@RequiredArgsConstructor
public class SafetyEquipmentInstallUseCertificateController {

    private final SafetyEquipmentIntallUserCertificateManage safetyEquipmentIntallUserCertificateManage;

    @ApiOperation(value = "证书信息列表", notes = "证书信息列表")
    @GetMapping("/list")
    public PageVo<SafetyEquipmentInstallUseCertificateVO> list(@Valid @ModelAttribute UseCertPageParamDTO param) {
        return safetyEquipmentIntallUserCertificateManage.list(param);
    }

    @ApiOperation(value = "证书信息详情", notes = "证书信息详情")
    @GetMapping("/details/{id}")
    public SafetyEquipmentInstallUseCertificateVO details(@Valid @PathVariable Long id) {
        return safetyEquipmentIntallUserCertificateManage.details(id);
    }

    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/save")
    public SafetyEquipmentInstallUseCertificateVO save(@Valid @RequestBody UseCertSaveDTO data) {
        return safetyEquipmentIntallUserCertificateManage.save(data, LoginUserUtil.getUserId());
    }

    @ApiOperation(value = "编辑", notes = "编辑")
    @PostMapping("/modify")
    public SafetyEquipmentInstallUseCertificateVO modify(@Valid @RequestBody UseCertUpdateDTO data) {
        return safetyEquipmentIntallUserCertificateManage.modify(data, LoginUserUtil.getUserId());
    }

    @ApiOperation(value = "删除", notes = "删除")
    @DeleteMapping("/remove/{id}")
    public Boolean remove(@Valid @PathVariable Long id) {
        return safetyEquipmentIntallUserCertificateManage.remove(id, LoginUserUtil.getUserId());
    }

    @ApiOperation("信息列表导出")
    @GetMapping("/infoListExport")
    public void infoListExport(UseCertPageParamDTO param, HttpServletResponse response){
        ExcelDownUtil.downXls(response, param, safetyEquipmentIntallUserCertificateManage::infoListExport);
    }
}
