package com.ruoyi.web.bst;

import com.ruoyi.bst.userApp.domain.UserApp;
import com.ruoyi.bst.userApp.domain.UserAppQuery;
import com.ruoyi.bst.userApp.domain.UserAppVO;
import com.ruoyi.bst.userApp.service.UserAppService;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 用户APP关联Controller
 *
 * @author ruoyi
 * @date 2025-03-14
 */
@RestController
@RequestMapping("/bst/userApp")
public class UserAppController extends BaseController
{
    @Autowired
    private UserAppService userAppService;

    /**
     * 查询用户APP关联列表
     */
    @PreAuthorize("@ss.hasPermi('bst:userApp:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserAppQuery query)
    {
        startPage();
        startOrderBy();
        List<UserAppVO> list = userAppService.selectUserAppList(query);
        return getDataTable(list);
    }

    /**
     * 导出用户APP关联列表
     */
    @PreAuthorize("@ss.hasPermi('bst:userApp:export')")
    @Log(title = "用户APP关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserAppQuery query)
    {
        List<UserAppVO> list = userAppService.selectUserAppList(query);
        ExcelUtil<UserAppVO> util = new ExcelUtil<UserAppVO>(UserAppVO.class);
        util.exportExcel(response, list, "用户APP关联数据");
    }

    /**
     * 获取用户APP关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('bst:userApp:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userAppService.selectUserAppById(id));
    }

    /**
     * 新增用户APP关联
     */
    @PreAuthorize("@ss.hasPermi('bst:userApp:add')")
    @Log(title = "用户APP关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserApp userApp)
    {
        return toAjax(userAppService.insertUserApp(userApp));
    }

    /**
     * 修改用户APP关联
     */
    @PreAuthorize("@ss.hasPermi('bst:userApp:edit')")
    @Log(title = "用户APP关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserApp userApp)
    {
        return toAjax(userAppService.updateUserApp(userApp));
    }

    /**
     * 删除用户APP关联
     */
    @PreAuthorize("@ss.hasPermi('bst:userApp:remove')")
    @Log(title = "用户APP关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userAppService.deleteUserAppByIds(ids));
    }
}
