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.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.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.enums.LogBizType;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 用户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, bizIdName = "arg0", bizType = LogBizType.USER_APP)
    @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, bizIdName = "arg0", bizType = LogBizType.USER_APP)
    @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, bizIdName = "arg0", bizType = LogBizType.USER_APP)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userAppService.deleteUserAppByIds(ids));
    }
}
