package com.goldenwater.web.controller.gx;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.goldenwater.common.annotation.Anonymous;
import com.goldenwater.common.annotation.Log;
import com.goldenwater.common.core.controller.BaseController;
import com.goldenwater.common.core.domain.AjaxResult;
import com.goldenwater.common.core.page.TableDataInfo;
import com.goldenwater.common.enums.BusinessType;
import com.goldenwater.common.utils.poi.ExcelUtil;
import com.goldenwater.gx.domain.GxExchangeBiz;
import com.goldenwater.gx.service.IGxExchangeBizService;

/**
 * 数据交换业务域Controller
 */
@RestController
@RequestMapping("/gx/biz")
public class GxExchangeBizController extends BaseController
{
    @Autowired
    private IGxExchangeBizService gxExchangeBizService;

    /**
     * 查询数据交换业务域列表
     */
    @PreAuthorize("@ss.hasPermi('gx:biz:list')")
    @GetMapping("/list")
    public TableDataInfo list(GxExchangeBiz gxExchangeBiz)
    {
        startPage();
        List<GxExchangeBiz> list = gxExchangeBizService.selectGxExchangeBizList(gxExchangeBiz);
        return getDataTable(list);
    }

    /**
     * 导出数据交换业务域列表
     */
    @PreAuthorize("@ss.hasPermi('gx:biz:export')")
    @Log(title = "业务域管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GxExchangeBiz gxExchangeBiz)
    {
        List<GxExchangeBiz> list = gxExchangeBizService.selectGxExchangeBizList(gxExchangeBiz);
        ExcelUtil<GxExchangeBiz> util = new ExcelUtil<GxExchangeBiz>(GxExchangeBiz.class);
        util.exportExcel(response, list, "业务域数据");
    }

    /**
     * 获取数据交换业务域详细信息
     */
    @PreAuthorize("@ss.hasPermi('gx:biz:query')")
    @GetMapping(value = { "/", "/{id}" })
    public AjaxResult getInfo(@PathVariable(value = "id", required = false) Long id)
    {
        if (id != null)
        {
            return success(gxExchangeBizService.selectGxExchangeBizById(id));
        }
        return success();
    }

    /**
     * 新增数据交换业务域
     */
    @PreAuthorize("@ss.hasPermi('gx:biz:add')")
    @Log(title = "业务域管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GxExchangeBiz gxExchangeBiz)
    {
        gxExchangeBiz.setCreateBy(getUsername());
        return toAjax(gxExchangeBizService.insertGxExchangeBiz(gxExchangeBiz));
    }

    /**
     * 修改数据交换业务域
     */
    @PreAuthorize("@ss.hasPermi('gx:biz:edit')")
    @Log(title = "业务域管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GxExchangeBiz gxExchangeBiz)
    {
        gxExchangeBiz.setUpdateBy(getUsername());
        return toAjax(gxExchangeBizService.updateGxExchangeBiz(gxExchangeBiz));
    }

    /**
     * 删除数据交换业务域
     */
    @PreAuthorize("@ss.hasPermi('gx:biz:remove')")
    @Log(title = "业务域管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gxExchangeBizService.deleteGxExchangeBizByIds(ids));
    }

    @Anonymous
    @GetMapping("/front/list")
    public AjaxResult frontList(@RequestParam(value = "bizUnit", required = false) String bizUnit)
    {
        GxExchangeBiz biz = new GxExchangeBiz();
        biz.setBizUnit(bizUnit);
        return success(gxExchangeBizService.selectGxExchangeBizList(biz));
    }
}
