package com.ruoyi.enterprise.controller;

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

import org.springframework.security.access.prepost.PreAuthorize;
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 java.util.Arrays;

import com.ruoyi.common.core.controller.BaseController;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.enterprise.domain.CIndicationEnterprise;
import com.ruoyi.enterprise.service.ICIndicationEnterpriseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 地理标志核准企业Controller
 *
 * @author ruoyi
 * @date 2023-04-28
 */
@RestController
@RequestMapping("/enterprise/cIndicationEnterprise")
public class CIndicationEnterpriseController extends BaseController {
    private final ICIndicationEnterpriseService cIndicationEnterpriseService;

    public CIndicationEnterpriseController(ICIndicationEnterpriseService cIndicationEnterpriseService) {
        this.cIndicationEnterpriseService = cIndicationEnterpriseService;
    }


    /**
     * 查询地理标志核准企业列表
     *
     * @param cIndicationEnterprise 地理标志核准企业
     * @return 地理标志核准企业集合
     * @date 2023-04-28
     */
    @PreAuthorize("@ss.hasPermi('enterprise:cIndicationEnterprise:list')")
    @GetMapping("/list")
    public TableDataInfo list(CIndicationEnterprise cIndicationEnterprise) {
        startPage();
        List<CIndicationEnterprise> list = cIndicationEnterpriseService.queryList(cIndicationEnterprise);
        return getDataTable(list);
    }


    /**
     * 导出地理标志核准企业列表
     *
     * @param cIndicationEnterprise 地理标志核准企业
     * @date 2023-04-28
     */
    @PreAuthorize("@ss.hasPermi('enterprise:cIndicationEnterprise:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, CIndicationEnterprise cIndicationEnterprise) {
        List<CIndicationEnterprise> list = cIndicationEnterpriseService.list(new QueryWrapper<>());
        ExcelUtil<CIndicationEnterprise> util = new ExcelUtil<>(CIndicationEnterprise. class);
        util.exportExcel(response, list, "地理标志核准企业数据");
    }

    /**
     * 获取地理标志核准企业详细信息
     *
     * @param id 主键id
     * @return 结果
     * @date 2023-04-28
     */
    @PreAuthorize("@ss.hasPermi('enterprise:cIndicationEnterprise:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(cIndicationEnterpriseService.getById(id));
    }


    /**
     * 新增地理标志核准企业信息
     *
     * @param cIndicationEnterprise 地理标志核准企业
     * @return 结果
     * @date 2023-04-28
     */
    @PreAuthorize("@ss.hasPermi('enterprise:cIndicationEnterprise:add')")
    @Log(title = "地理标志核准企业", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CIndicationEnterprise cIndicationEnterprise) {
        return toAjax(cIndicationEnterpriseService.save(cIndicationEnterprise));
    }


    /**
     * 修改地理标志核准企业信息
     *
     * @param cIndicationEnterprise 地理标志核准企业
     * @return 结果
     * @date 2023-04-28
     */
    @PreAuthorize("@ss.hasPermi('enterprise:cIndicationEnterprise:edit')")
    @Log(title = "地理标志核准企业", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CIndicationEnterprise cIndicationEnterprise) {
        return toAjax(cIndicationEnterpriseService.updateById(cIndicationEnterprise));
    }


    /**
     * 删除地理标志核准企业信息
     *
     * @param ids 主键ids
     * @return 结果
     * @date 2023-04-28
     */
    @PreAuthorize("@ss.hasPermi('enterprise:cIndicationEnterprise:remove')")
    @Log(title = "地理标志核准企业", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(cIndicationEnterpriseService.removeByIds(Arrays.asList(ids)));
    }


}
