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.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(@RequestBody OpenAccountVO openAccountVO) {
        ArrayList<Integer> integers = new ArrayList<>();
        integers.add(1);
        openAccountVO.setRoles(integers);
        iUserinfoService.createAdmin(openAccountVO);
        return R.ok();
    }

    /**
     * 创建用户
     * @param openAccountVO
     * @return
     */
    @PostMapping("/createUser")
    public R createUser(@RequestBody OpenAccountVO openAccountVO) {
        openAccountVO.setRoles(null);
        iUserinfoService.createUser(openAccountVO);
        return R.ok();
    }


    @PostMapping("/disableUser")
    public R disableUser(@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));
    }

}
