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.SafetyEquipmentInstallUseCertificateOperationManage;
import com.ningdatech.carapi.industry.model.dto.UseCertOperatePageParamDTO;
import com.ningdatech.carapi.industry.model.dto.UseCertOperateUpdateDTO;
import com.ningdatech.carapi.industry.model.vo.SafetyEquipmentInstallUseCertificateOperationVO;
import com.ningdatech.carapi.user.util.LoginUserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * <p>
 * 安全设备安装使用证书操作信息 前端控制器
 * </p>
 *
 * @author CMM
 * @since 2022-11-26
 */
@RestController
@RequestMapping("/api/industry/safety-equipment-install-use-certificate-operation")
@Slf4j
@Validated
@Api(value = "SafetyEquipmentInstallUseCertificateOperation",tags = "行业服务-安全设备安装使用证书")
@RequiredArgsConstructor
public class SafetyEquipmentInstallUseCertificateOperationController {
    private final SafetyEquipmentInstallUseCertificateOperationManage safetyEquipmentInstallUseCertificateOperationManage;

    @ApiOperation(value = "证书操作信息列表", notes = "证书操作信息列表")
    @GetMapping("/list")
    public PageVo<SafetyEquipmentInstallUseCertificateOperationVO> list(@Valid @ModelAttribute UseCertOperatePageParamDTO param){
        return safetyEquipmentInstallUseCertificateOperationManage.list(param);
    }

    @ApiModelProperty("证书操作信息详情")
    @GetMapping("/detail/{id}")
    public SafetyEquipmentInstallUseCertificateOperationVO details(@Valid @PathVariable Long id){
        return safetyEquipmentInstallUseCertificateOperationManage.details(id);
    }

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

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

    @ApiOperation("安全设备安装使用证书信息列表导出")
    @GetMapping("/infoListExport")
    public void infoListExport(UseCertOperatePageParamDTO param, HttpServletResponse response){
        ExcelDownUtil.downXls(response, param, safetyEquipmentInstallUseCertificateOperationManage::infoListExport);
    }
}
