package com.ruoyi.web.controller.doubleDefense;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.doubledefense.dto.ContractorDTO;
import com.ruoyi.doubledefense.service.IContractorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 承包商Controller
 *
 * @author ruoyi
 * @date 2023-08-04
 */
@Api(tags = "PC承包商相关接口")
@RestController
@RequestMapping("/doubledefense/contractor")
public class ContractorController extends BaseController
{
    @Autowired
    private IContractorService contractorService;

    /**
     * 查询承包商列表
     */
    @ApiOperation("查询承包商列表")
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:contractor:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContractorDTO contractor)
    {
        startPage();
        List<ContractorDTO> list = contractorService.selectContractorList(contractor);
        return getDataTable(list);
    }



    /**
     * 导出承包商列表
     */
    @ApiOperation("导出承包商列表")
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:contractor:export')")
    @Log(title = "承包商", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ContractorDTO contractor)
    {
        List<ContractorDTO> list = contractorService.selectContractorList(contractor);
        ExcelUtil<ContractorDTO> util = new ExcelUtil<ContractorDTO>(ContractorDTO.class);
        util.exportExcel(response, list, "承包商数据");
    }

    /**
     * 获取承包商详细信息
     */
    @ApiOperation("获取承包商详细信息")
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:contractor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(contractorService.selectContractorById(id));
    }

    /**
     * 新增承包商
     */
    @ApiOperation("新增承包商")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyName", value = "单位名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "socialCreditCode", value = "税码/社会信用代码", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "securityClearanceCode", value = "安全许可编号", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "contractorType", value = "承包商类型：1建筑工程，2设备安装，3检维修，4检测，5设计，6监理服务，7技术服务，8其他", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "postalAddress", value = "通信地址", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "manageName", value = "负责人名字", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "managePhone", value = "负责人电话", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "securityClearanceImage", value = "安全许可证证书图片", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "businessLicenseImage", value = "营业执照证书图片", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "businessQualification", value = "业务资质证书图片", dataType = "String", dataTypeClass = String.class)
    })
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:contractor:add')")
    @Log(title = "承包商", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContractorDTO contractor)
    {
        return toAjax(contractorService.insertContractor(contractor));
    }

    /**
     * 修改承包商
     */
    @ApiOperation("修改承包商")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "companyName", value = "单位名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "socialCreditCode", value = "税码/社会信用代码", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "securityClearanceCode", value = "安全许可编号", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "contractorType", value = "承包商类型：1建筑工程，2设备安装，3检维修，4检测，5设计，6监理服务，7技术服务，8其他", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "postalAddress", value = "通信地址", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "manageName", value = "负责人名字", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "managePhone", value = "负责人电话", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "securityClearanceImage", value = "安全许可证证书图片", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "businessLicenseImage", value = "营业执照证书图片", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "businessQualification", value = "业务资质证书图片", dataType = "String", dataTypeClass = String.class)
    })
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:contractor:edit')")
    @Log(title = "承包商", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContractorDTO contractor)
    {
        return toAjax(contractorService.updateContractor(contractor));
    }

    /**
     * 删除承包商
     */
    @ApiOperation("删除承包商")
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:contractor:remove')")
    @Log(title = "承包商", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(contractorService.deleteContractorByIds(ids));
    }
}
