package com.ruoyi.web.work.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.web.work.domain.User;
import com.ruoyi.web.work.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 小程序用户
 *
 * @author lsw
 * @date 2024-07-29
 */
@RestController
@RequestMapping("/work/user")
public class UserController extends BaseController {
    @Autowired
    private IUserService userService;

    @PreAuthorize("@ss.hasPermi('work:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(User user) {
        startPage();
        List<User> list = userService.selectList(user);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('work:user:query')")
    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Long id) {
        return AjaxResult.success(userService.getById(id));
    }

    @PreAuthorize("@ss.hasPermi('work:user:add')")
    @Log(title = "小程序用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody User user) {
        return toAjax(userService.save(user));
    }

    @PreAuthorize("@ss.hasPermi('work:user:edit')")
    @Log(title = "小程序用户", businessType = BusinessType.UPDATE)
    @PostMapping("/enable")
    public AjaxResult enable(@RequestBody User user) {
        return userService.enable(user);
    }


    @PreAuthorize("@ss.hasPermi('work:user:remove')")
    @Log(title = "小程序用户", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return userService.remove(ids);
    }
}
