package com.ruoyi.web.controller.doubleDefense;

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

import com.ruoyi.doubledefense.dto.ContractorProfessionDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.doubledefense.domain.ContractorProfession;
import com.ruoyi.doubledefense.service.IContractorProfessionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 承包商工种Controller
 *
 * @author ruoyi
 * @date 2023-08-04
 */
@Api(tags = "承包商工种")
@RestController
@RequestMapping("/doubledefense/profession")
public class ContractorProfessionController extends BaseController
{
    @Autowired
    private IContractorProfessionService contractorProfessionService;

    /**
     * 查询承包商工种列表
     */
    @ApiOperation("查询承包商工种列表")
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:profession:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContractorProfessionDTO contractorProfession)
    {
        startPage();
        List<ContractorProfessionDTO> list = contractorProfessionService.selectContractorProfessionList(contractorProfession);
        return getDataTable(list);
    }

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

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

    /**
     * 新增承包商工种
     */
    @ApiOperation("新增承包商工种")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "contractorId", value = "承包商UUID", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "professionName", value = "工种名称", dataType = "String", dataTypeClass = String.class)
    })
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:profession:add')")
    @Log(title = "承包商工种", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContractorProfessionDTO contractorProfession)
    {
        return toAjax(contractorProfessionService.insertContractorProfession(contractorProfession));
    }

    /**
     * 修改承包商工种
     */
    @ApiOperation("修改承包商工种")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "contractorId", value = "承包商UUID", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "professionName", value = "工种名称", dataType = "String", dataTypeClass = String.class)
    })
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:profession:edit')")
    @Log(title = "承包商工种", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContractorProfessionDTO contractorProfession)
    {
        return toAjax(contractorProfessionService.updateContractorProfession(contractorProfession));
    }

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