package com.ruoyi.model.controller;

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.model.domain.AppletTask;
import com.ruoyi.model.domain.AppletTaskUser;
import com.ruoyi.model.service.IAppletTaskService;
import com.ruoyi.model.service.IAppletTaskUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 任务中心Controller
 *
 * @author daixiande
 * @date 2025-04-24
 */
@RestController
@RequestMapping("/model/AppletTaskUser")
public class AppletTaskUserController extends BaseController {
    @Autowired
    private IAppletTaskUserService appletTaskUserService;

    /**
     * 查询任务中心列表
     */
    @PreAuthorize("@ss.hasPermi('model:AppletTaskUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppletTaskUser appletTask) {
        startPage();
        List<AppletTaskUser> list = appletTaskUserService.selectAppletTaskList(appletTask);
        return getDataTable(list);
    }

    /**
     * 导出任务中心列表
     */
    @PreAuthorize("@ss.hasPermi('model:AppletTaskUser:export')")
    @Log(title = "任务中心", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppletTaskUser appletTask) {
        List<AppletTaskUser> list = appletTaskUserService.selectAppletTaskList(appletTask);
        ExcelUtil<AppletTaskUser> util = new ExcelUtil<AppletTaskUser>(AppletTaskUser.class);
        return util.exportExcel(list, "任务中心数据");
    }

    /**
     * 获取任务中心详细信息
     */
    @PreAuthorize("@ss.hasPermi('model:AppletTaskUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(appletTaskUserService.selectAppletTaskById(id));
    }

    /**
     * 新增任务中心
     */
    @PreAuthorize("@ss.hasPermi('model:AppletTaskUser:add')")
    @Log(title = "任务中心", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppletTaskUser appletTask) {
        return toAjax(appletTaskUserService.insertAppletTask(appletTask));
    }

    /**
     * 修改任务中心
     */
    @PreAuthorize("@ss.hasPermi('model:AppletTaskUser:edit')")
    @Log(title = "任务中心", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppletTaskUser appletTask) {
        return toAjax(appletTaskUserService.updateAppletTask(appletTask));
    }

    /**
     * 删除任务中心
     */
    @PreAuthorize("@ss.hasPermi('model:AppletTaskUser:remove')")
    @Log(title = "任务中心", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appletTaskUserService.deleteAppletTaskByIds(ids));
    }
}