package com.yida.data.system.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.system.Dept;
import com.yida.data.common.core.entity.system.EduDeptWxPublic;
import com.yida.data.system.mapper.EduDeptWxPublicMapper;
import com.yida.data.system.service.IDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Validated
@Api(tags = "部门管理（无鉴权 外部使用）")
@RestController
@RequestMapping("/out/dept")
@RequiredArgsConstructor
public class OutDeptController {

    private final IDeptService deptService;
    private final EduDeptWxPublicMapper eduDeptWxPublicMapper;

    @ApiOperation("根据公众号id查询学校")
    @GetMapping("/getSchoolByAppId")
    public ResultBean<Dept> getSchoolByAppId(String appId) {
        Dept school = null;
        EduDeptWxPublic deptWxPublic = eduDeptWxPublicMapper.selectOne(Wrappers.<EduDeptWxPublic>lambdaQuery()
            .eq(EduDeptWxPublic::getAppId, appId));
        if (deptWxPublic != null) {
            school = deptService.getById(deptWxPublic.getDeptId());
        }
        return ResultBean.buildSuccess(school);
    }
}
