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.dto.SchoolInformationDTO;
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 io.swagger.annotations.ApiParam;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@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);
    }

    @ApiOperation("根据名称查询教育局缴费学校列表")
    @GetMapping("/listPaySchool")
    public ResultBean<List<SchoolInformationDTO>> listPaySchool(
            @ApiParam(value = "教育局或代理商id", required = true) @RequestParam Long deptId,
            @ApiParam(value = "学校名称") String schoolName) {
        List<SchoolInformationDTO> list = deptService.listPaySchool(deptId, schoolName);
        return ResultBean.buildSuccess(list);
    }
}
