package com.bonus.zlpt.company.controller;

import com.bonus.zlpt.common.core.web.controller.BaseController;
import com.bonus.zlpt.common.core.web.domain.AjaxResult;
import com.bonus.zlpt.common.security.utils.SecurityUtils;
import com.bonus.zlpt.system.api.domain.SysUser;
import com.bonus.zlpt.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/sun")
public class SunAccountController extends BaseController {

    @Autowired(required = false)
    private ISysUserService iSysUserService;

    /**
     * 获取此账号下的子账号信息
     * @param
     * @return
     */
    @GetMapping("/selectUserList")
    public List<SysUser> selectUserList() {
        SysUser sysUser = new SysUser();
        int parentId = Math.toIntExact(SecurityUtils.getUserId());
        sysUser.setParentId(parentId);
        List<SysUser> sysUsersList = iSysUserService.selectUserList(sysUser);
        return sysUsersList;
    }

    /**
     * 添加子账号
     * @param sysUser
     * @return
     */
    @PostMapping("/sunAdd")
    public AjaxResult sunAdd(@RequestBody SysUser sysUser) {

        int parentId = Math.toIntExact(SecurityUtils.getUserId());
        sysUser.setParentId(parentId);
        iSysUserService.insertUser(sysUser);

        return success("添加成功！");
    }

    /**
     * 修改子账号状态
     * @param sysUser
     * @return
     */
    @PostMapping("/updateUserStatus")
    public AjaxResult updateUserStatus(@RequestBody SysUser sysUser) {

        iSysUserService.updateUserStatus(sysUser);
        return success("修改成功！");
    }

    /**
     * 删除子账号
     * @param
     * @return
     */
    @PostMapping("/deleteUserById/{id}")
    public AjaxResult deleteUserById(@PathVariable Long id) {

        iSysUserService.deleteUserById(id);
        return success("删除成功！");
    }


}
