package com.ruoyi.generator.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.generator.domain.SourcePurchase;
import com.ruoyi.generator.service.ISourcePurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
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;

@RestController
@RequestMapping("/generator/sourcePurchase")
public class SourcePurchaseController extends BaseController
{
    @Autowired
    private ISourcePurchaseService sourcePurchaseService;

    @PreAuthorize("@ss.hasPermi('generator:sourcePurchase:list')")
    @GetMapping("/list")
    public TableDataInfo list(SourcePurchase sourcePurchase)
    {
        startPage();
        List<SourcePurchase> list = sourcePurchaseService.selectSourcePurchaseList(sourcePurchase);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('generator:sourcePurchase:export')")
    @Log(title = "源码购买记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SourcePurchase sourcePurchase)
    {
        List<SourcePurchase> list = sourcePurchaseService.selectSourcePurchaseList(sourcePurchase);
        ExcelUtil<SourcePurchase> util = new ExcelUtil<SourcePurchase>(SourcePurchase.class);
        util.exportExcel(response, list, "源码购买记录数据");
    }

    @PreAuthorize("@ss.hasPermi('generator:sourcePurchase:query')")
    @GetMapping(value = "/{purchaseId}")
    public AjaxResult getInfo(@PathVariable("purchaseId") Long purchaseId)
    {
        return success(sourcePurchaseService.selectSourcePurchaseByPurchaseId(purchaseId));
    }

    @PreAuthorize("@ss.hasPermi('generator:sourcePurchase:edit')")
    @Log(title = "源码购买记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SourcePurchase sourcePurchase)
    {
        return toAjax(sourcePurchaseService.updateSourcePurchase(sourcePurchase));
    }
}
