package com.ruoyi.web.bst;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
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;

import com.ruoyi.bst.app.domain.App;
import com.ruoyi.bst.app.domain.AppQuery;
import com.ruoyi.bst.app.domain.AppVO;
import com.ruoyi.bst.app.domain.vo.AppAllVO;
import com.ruoyi.bst.app.service.AppService;
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.core.validate.ValidGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.LogBizType;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * APP信息Controller
 *
 * @author ruoyi
 * @date 2025-01-08
 */
@RestController
@RequestMapping("/bst/app")
public class AppController extends BaseController
{
    @Autowired
    private AppService appService;

    /**
     * 查询APP信息列表
     */
    @PreAuthorize("@ss.hasPermi('bst:app:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppQuery query)
    {
        startPage();
        startOrderBy();
        List<AppVO> list = appService.selectAppList(query);
        return getDataTable(list);
    }

    /**
     * 查询所有APP信息
     * @return
     */
    @GetMapping("/all")
    public AjaxResult all() {
        List<AppAllVO> list = appService.selectAll();
        return success(list);
    }

    /**
     * 根据id集合查询APP信息列表
     */
    @PreAuthorize("@ss.hasPermi('bst:app:list')")
    @PostMapping("/listByIds")
    public AjaxResult listByIds(@RequestBody List<Long> ids)
    {
        List<AppVO> list = appService.selectByIds(ids);
        return success(list);
    }

    /**
     * 导出APP信息列表
     */
    @PreAuthorize("@ss.hasPermi('bst:app:export')")
    @Log(title = "APP信息导出", businessType = BusinessType.EXPORT, bizType = LogBizType.APP)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppQuery query)
    {
        List<AppVO> list = appService.selectAppList(query);
        ExcelUtil<AppVO> util = new ExcelUtil<AppVO>(AppVO.class);
        util.exportExcel(response, list, "APP信息数据");
    }

    /**
     * 获取APP信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('bst:app:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(appService.selectAppById(id));
    }

    /**
     * 新增APP信息
     */
    @PreAuthorize("@ss.hasPermi('bst:app:add')")
    @Log(title = "新增APP信息", businessType = BusinessType.INSERT, bizIdName = "arg0", bizType = LogBizType.APP)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated(ValidGroup.Create.class) App app)
    {
        return toAjax(appService.insertApp(app));
    }

    /**
     * 修改APP信息
     */
    @PreAuthorize("@ss.hasPermi('bst:app:edit')")
    @Log(title = "修改APP信息", businessType = BusinessType.UPDATE, bizIdName = "arg0", bizType = LogBizType.APP)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated(ValidGroup.Create.class) App app)
    {
        return toAjax(appService.updateApp(app));
    }

    /**
     * 删除APP信息
     */
    @PreAuthorize("@ss.hasPermi('bst:app:remove')")
    @Log(title = "删除APP信息", businessType = BusinessType.DELETE, bizIdName = "arg0", bizType = LogBizType.APP)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appService.deleteAppByIds(ids));
    }
}
