package com.goldenwater.web.controller.gx;

import java.util.List;
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.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.gx.domain.GxExchangeApply;
import com.goldenwater.gx.service.IGxExchangeApplyService;

/**
 * 数据共享申请Controller
 */
@RestController
@RequestMapping("/gx/apply")
public class GxExchangeApplyController extends BaseController
{
    @Autowired
    private IGxExchangeApplyService gxExchangeApplyService;

    @PreAuthorize("@ss.hasPermi('gx:apply:list')")
    @GetMapping("/list")
    public TableDataInfo list(GxExchangeApply apply)
    {
        startPage();
        List<GxExchangeApply> list = gxExchangeApplyService.selectGxExchangeApplyList(apply);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('gx:apply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id)
    {
        return success(gxExchangeApplyService.selectGxExchangeApplyById(id));
    }

    @PreAuthorize("@ss.hasPermi('gx:apply:add')")
    @Log(title = "共享申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GxExchangeApply apply)
    {
        apply.setCreateBy(getUsername());
        return toAjax(gxExchangeApplyService.insertGxExchangeApply(apply));
    }

    /**
     * 审批数据共享申请
     */
    @PreAuthorize("@ss.hasPermi('gx:apply:edit')")
    @Log(title = "共享申请审批", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult audit(@RequestBody GxExchangeApply apply)
    {
        return toAjax(gxExchangeApplyService.auditApply(
                apply.getId(), apply.getApplyState(),
                getUsername(), apply.getApproveRemark()));
    }

    @PreAuthorize("@ss.hasPermi('gx:apply:remove')")
    @Log(title = "共享申请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gxExchangeApplyService.deleteGxExchangeApplyByIds(ids));
    }
}
