package com.ruoyi.web.controller.benyun;

import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.vo.OpenAccountVO;
import com.ruoyi.system.service.AccountService;
import com.ruoyi.system.service.IUserinfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController
@RequiredArgsConstructor
public class IUserinfoController {
    @Autowired
    private IUserinfoService iUserinfoService;

    @Autowired
    private AccountService accountService;


    /**
     * 创建管理员
     * @param openAccountVO
     * @return
     */
    @PostMapping("/createAdmin")
    public R createAdmin(@Validated @RequestBody OpenAccountVO openAccountVO) {
        ArrayList<Integer> integers = new ArrayList<>();
        integers.add(1); //管理员
        openAccountVO.setRoles(integers);
        R admin = iUserinfoService.createAdmin(openAccountVO);
        return admin;
    }

    /**
     * 创建用户
     * @param openAccountVO
     * @return
     */
    @PostMapping("/createUser")
    public R createUser(@Validated @RequestBody OpenAccountVO openAccountVO) {
        ArrayList<Integer> integers = new ArrayList<>();
        integers.add(2); //管理员
        openAccountVO.setRoles(integers);
        R user = iUserinfoService.createUser(openAccountVO);
        return user;
    }


    @PostMapping("/disableUser")
    public R disableUser(@Validated @RequestBody OpenAccountVO openAccountVO) {
        iUserinfoService.disableUser(openAccountVO);
        return R.ok();
    }


    /**
     * uId免密登录
     * @Author Yyz
     * @Date 2020/12/1 13:58
     */
    @SaIgnore
    @PostMapping("/loginByUId")
    public R login(String uId)  {
        return R.ok(accountService.login(uId));
    }

}
