package com.sf.system.deployment.controller;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sf.common.annotation.Log;
import com.sf.common.core.controller.BaseController;
import com.sf.common.core.domain.AjaxResult;
import com.sf.common.core.page.TableDataInfo;
import com.sf.common.enums.BusinessType;
import com.sf.common.utils.poi.ExcelUtil;
import com.sf.system.deployment.domain.DeploymentApplyEnvironment;
import com.sf.system.deployment.service.IDeploymentApplyEnvironmentService;

/**
 * 环境维护Controller
 * 
 * @author ztzh
 * @date 2024-04-19
 */
@RestController
@RequestMapping("/deployment/environment")
public class DeploymentApplyEnvironmentController extends BaseController
{
    @Autowired
    private IDeploymentApplyEnvironmentService deploymentApplyEnvironmentService;

    /**
     * 查询环境维护列表
     */
    @PreAuthorize("@ss.hasPermi('deployment:environment:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeploymentApplyEnvironment deploymentApplyEnvironment)
    {
        startPage();
        List<DeploymentApplyEnvironment> list = deploymentApplyEnvironmentService.selectDeploymentApplyEnvironmentList(deploymentApplyEnvironment);
        return getDataTable(list);
    }

    /**
     * 导出环境维护列表
     */
    @PreAuthorize("@ss.hasPermi('deployment:environment:export')")
    @Log(title = "环境维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeploymentApplyEnvironment deploymentApplyEnvironment)
    {
        List<DeploymentApplyEnvironment> list = deploymentApplyEnvironmentService.selectDeploymentApplyEnvironmentList(deploymentApplyEnvironment);
        ExcelUtil<DeploymentApplyEnvironment> util = new ExcelUtil<DeploymentApplyEnvironment>(DeploymentApplyEnvironment.class);
        util.exportExcel(response, list, "环境维护数据");
    }

    /**
     * 获取环境维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('deployment:environment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deploymentApplyEnvironmentService.selectDeploymentApplyEnvironmentById(id));
    }

    /**
     * 新增环境维护
     */
    @PreAuthorize("@ss.hasPermi('deployment:environment:add')")
    @Log(title = "环境维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeploymentApplyEnvironment deploymentApplyEnvironment)
    {
        return toAjax(deploymentApplyEnvironmentService.insertDeploymentApplyEnvironment(deploymentApplyEnvironment));
    }

    /**
     * 修改环境维护
     */
    @PreAuthorize("@ss.hasPermi('deployment:environment:edit')")
    @Log(title = "环境维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeploymentApplyEnvironment deploymentApplyEnvironment)
    {
        return toAjax(deploymentApplyEnvironmentService.updateDeploymentApplyEnvironment(deploymentApplyEnvironment));
    }

    /**
     * 删除环境维护
     */
    @PreAuthorize("@ss.hasPermi('deployment:environment:remove')")
    @Log(title = "环境维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deploymentApplyEnvironmentService.deleteDeploymentApplyEnvironmentByIds(ids));
    }
}
