package com.ruoyi.web.controller.projectV2;

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

import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.projectV2.ZsyzSkcy;
import com.ruoyi.system.service.projectV2.IZsyzSkcyService;
import org.apache.commons.lang3.ArrayUtils;
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.common.core.page.TableDataInfo;

/**
 * 省库产业Controller
 * 
 * @author boman
 * @date 2023-03-29
 */
@RestController
@RequestMapping("/projectV2/skcy")
public class ZsyzSkcyController extends BaseController
{
    @Autowired
    private IZsyzSkcyService zsyzSkcyService;

    /**
     * 查询省库产业列表
     */
    @GetMapping("/list")
    public AjaxResult list(ZsyzSkcy zsyzSkcy)
    {
        List<ZsyzSkcy> list = zsyzSkcyService.selectZsyzSkcyList(zsyzSkcy);
        return success(list);
    }

    /**
     * 导出省库产业列表
     */
    @PreAuthorize("@ss.hasPermi('projectV2:skcy:export')")
    @Log(title = "省库产业", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZsyzSkcy zsyzSkcy)
    {
        List<ZsyzSkcy> list = zsyzSkcyService.selectZsyzSkcyList(zsyzSkcy);
        ExcelUtil<ZsyzSkcy> util = new ExcelUtil<ZsyzSkcy>(ZsyzSkcy.class);
        util.exportExcel(response, list, "省库产业数据");
    }

    /**
     * 获取省库产业详细信息
     */
    @PreAuthorize("@ss.hasPermi('projectV2:skcy:query')")
    @GetMapping(value = "/{skcyId}")
    public AjaxResult getInfo(@PathVariable("skcyId") Long skcyId)
    {
        return success(zsyzSkcyService.selectZsyzSkcyBySkcyId(skcyId));
    }

    /**
     * 新增省库产业
     */
    @PreAuthorize("@ss.hasPermi('projectV2:skcy:add')")
    @Log(title = "省库产业", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZsyzSkcy zsyzSkcy)
    {
        return toAjax(zsyzSkcyService.insertZsyzSkcy(zsyzSkcy));
    }

    /**
     * 修改省库产业
     */
    @PreAuthorize("@ss.hasPermi('projectV2:skcy:edit')")
    @Log(title = "省库产业", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody ZsyzSkcy zsyzSkcy)
    {
        return toAjax(zsyzSkcyService.updateZsyzSkcy(zsyzSkcy));
    }

    /**
     * 删除省库产业
     */
    @PreAuthorize("@ss.hasPermi('projectV2:skcy:remove')")
    @Log(title = "省库产业", businessType = BusinessType.DELETE)
	@GetMapping("/delete/{skcyIds}")
    public AjaxResult remove(@PathVariable Long skcyId)
    {
        if (zsyzSkcyService.hasChildBySkcyId(skcyId))
        {
            return warn("存在下级产业,不允许删除");
        }
        return toAjax(zsyzSkcyService.deleteZsyzSkcyBySkcyId(skcyId));
    }
}
