package com.changhu.module.securityManagement.controller;

import cn.hutool.core.lang.Dict;
import cn.hutool.core.lang.func.LambdaUtil;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.changhu.common.annotation.CheckUserType;
import com.changhu.common.annotation.JsonBody;
import com.changhu.common.db.enums.IsEnable;
import com.changhu.common.db.enums.MiniProgramUserIdentity;
import com.changhu.common.db.enums.UserType;
import com.changhu.common.pojo.vo.SelectNodeVo;
import com.changhu.common.utils.UserUtil;
import com.changhu.pojo.entity.MiniProgramUser;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 20252
 * @createTime 2024/11/22 上午10:16
 * @desc SecurityController...
 */
@Tag(name = "保安后台-通用接口")
@JsonBody
@RequestMapping("/m3")
@CheckUserType(userTypes = UserType.MANAGEMENT_SECURITY)
@RestController
public class SecurityController {

    @Operation(summary = "查询单位下的项目经理")
    @GetMapping("/list_p_m")
    public List<SelectNodeVo<Long>> listProjectManager() {
        String tel = LambdaUtil.getFieldName(MiniProgramUser::getTelephone);
        String sex = LambdaUtil.getFieldName(MiniProgramUser::getSex);
        return Db.lambdaQuery(MiniProgramUser.class)
                .eq(MiniProgramUser::getIsEnable, IsEnable.TRUE)
                .eq(MiniProgramUser::getIdentity, MiniProgramUserIdentity.PROJECT_MANAGER)
                .eq(MiniProgramUser::getUnitId, UserUtil.getUnitId())
                .list()
                .stream()
                .map(item -> SelectNodeVo.<Long>builder()
                        .value(item.getSnowFlakeId())
                        .label(item.getName())
                        .extData(Dict.of(
                                tel, item.getTelephone(),
                                sex, item.getSex()
                        ))
                        .build())
                .toList();
    }
}
