package com.koobietech.eas.controller;

import com.github.pagehelper.PageHelper;
import com.koobietech.eas.common.result.JsonResult;
import com.koobietech.eas.common.result.PageDataResult;
import com.koobietech.eas.mbg.model.EasSysUserinfo;
import com.koobietech.eas.service.EasSysUserInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Tag(name = "用户信息模块")
@RequestMapping("/userinfo")
public class EasSysUserInfoController {

    @Resource
    EasSysUserInfoService easSysUserInfoService;

    @PostMapping("/add")
    @Operation(summary = "添加用户信息", description = "录入基本用户信息")
    public JsonResult add(@RequestBody EasSysUserinfo userinfo) {
        Boolean ret = easSysUserInfoService.add(userinfo);
        if (ret) {
            return JsonResult.ok();
        }
        return JsonResult.fail();
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除用户信息", description = "删除用户信息表数据根据ID")
    public JsonResult delete(@RequestParam Long id) {
        Boolean ret = easSysUserInfoService.delete(id);
        if (ret) {
            return JsonResult.ok();
        }
        return JsonResult.fail();
    }

    @PutMapping("/update")
    @Operation(summary = "更新用户信息", description = "更新用户信息表信息")
    public JsonResult update(@RequestBody EasSysUserinfo userinfo) {
        Boolean ret = easSysUserInfoService.update(userinfo);
        if (ret) {
            return JsonResult.ok();
        }
        return JsonResult.fail();
    }

    @PostMapping("/query")
    @Operation(summary = "查询用户信息", description = "根据参数查询用户信息表信息")
    public JsonResult query(@RequestBody(required = false) EasSysUserinfo userinfo,
                            @RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        PageDataResult ret = easSysUserInfoService.query(userinfo);
        return JsonResult.data(ret);
    }
}
