package com.ruoyi.web.controller.ss;

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.domain.ValidGroup;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ss.app.domain.App;
import com.ruoyi.ss.app.domain.AppQuery;
import com.ruoyi.ss.app.domain.AppVO;
import com.ruoyi.ss.app.service.AppService;
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.*;

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

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

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

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

    /**
     * 导出APP信息列表
     */
    @PreAuthorize("@ss.hasPermi('ss:app:export')")
    @Log(title = "APP信息", businessType = BusinessType.EXPORT)
    @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('ss:app:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(appService.selectAppById(id));
    }

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

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

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