package com.younike.admin.controller.appUserManage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.younike.common.annotation.OpLog;
import com.younike.common.bean.APIResult;
import com.younike.common.bean.ResultGenerator;
import com.younike.common.constant.BusinessType;
import com.younike.common.core.controller.BaseController;
import com.younike.common.core.page.PageParam;
import com.younike.service.pojo.TAppUser;
import com.younike.service.service.ITAppUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * app用户管理Controller
 *
 * @author jiay
 * @date 2022-03-22
 */
@RestController
@RequestMapping("/appUser")
public class AppUserController extends BaseController {
    @Autowired
    private ITAppUserService tAppUserService;

    /**
     * 查询app用户列表
     */
    @RequiresPermissions("appUser:list")
    @PostMapping("/list")
    public Page list(@RequestBody PageParam<TAppUser> page) {

        return tAppUserService.page(page);
    }


    /**
     * 获取app用户详细信息
     */
    @RequiresPermissions("appUser:query")
    @GetMapping(value = "/{id}")
    public APIResult getInfo(@PathVariable("id") String id) {
        return ResultGenerator.getSuccessResult(tAppUserService.getById(id));
    }

    /**
     * 新增app用户
     */
    @RequiresPermissions("appUser:add")
    @OpLog(title = "app用户", type = BusinessType.INSERT)
    @PostMapping
    public APIResult add(@RequestBody TAppUser tAppUser) {
        return ResultGenerator.getSuccessResult(tAppUserService.save(tAppUser));
    }

    /**
     * 修改app用户
     */
    @RequiresPermissions("appUser:edit")
    @OpLog(title = "app用户", type = BusinessType.UPDATE)
    @PutMapping
    public APIResult edit(@RequestBody TAppUser tAppUser) {
        return ResultGenerator.getSuccessResult(tAppUserService.updateById(tAppUser));
    }

    /**
     * 删除app用户
     */
    @RequiresPermissions("appUser:remove")
    @OpLog(title = "app用户", type = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public APIResult remove(@PathVariable List<String> ids) {
        return ResultGenerator.getSuccessResult(tAppUserService.removeByIds(ids));
    }
}
