package com.saye.hrs.controller;

import com.google.common.base.Joiner;
import com.saye.hrs.service.CountAuthService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

/**
 * @author Mr.zs
 * @date 2025/2/8
 */
@Controller
@RequestMapping("/api")
@RequiredArgsConstructor
@Slf4j
public class CountAuthController {

    private final CountAuthService countAuthService;

    // 查询有权限的用户列表
    @RequestMapping("/getAutho")
    @ResponseBody
    public HashMap<String, Object> getAutho() {
        HashMap<String, Object> resMap = new HashMap<>();
        resMap.put("code", 200);
        resMap.put("msg", "查询有权限的用户列表");
        List<String> list = countAuthService.getAutherList();
        if (list != null) {
            resMap.put("data", list);
            return resMap;
        }
        return null;
    }

    // 查询用户的权限列表
    @RequestMapping("/getAuthoList")
    @ResponseBody
    public Object getAuthoList(String openid) {
        HashMap<String, Object> resMap = new HashMap<>();
        resMap.put("code", 200);
        resMap.put("msg", "查询用户的权限列表");
        List<String> list = countAuthService.getAuthoList(openid);
        if (list != null) {
            resMap.put("data", list);
            return resMap;
        }
        return null;
    }

    // 查询用户的科室权限列表
    @RequestMapping("/getDeptAuthList")
    @ResponseBody
    public Object getDeptAuthList(String openid) {
        HashMap<String, Object> resMap = new HashMap<>();
        resMap.put("code", 200);
        resMap.put("msg", "查询用户的权限列表");
        List<String> depts = countAuthService.getDeptAuthList(openid);

        String result = Joiner.on(",").skipNulls().join(depts);
        System.out.println("list " + result);
        if (depts != null) {
            resMap.put("data", result);
            return resMap;
        }
        return null;
    }
}
