package com.qmth.jkserver.controller.system;

import com.google.gson.reflect.TypeToken;
import com.qmth.jkserver.constant.SystemConstant;
import com.qmth.jkserver.dto.result.BasicSchoolResult;
import com.qmth.jkserver.model.BasicSchool;
import com.qmth.jkserver.service.BasicSchoolService;
import com.qmth.jkserver.util.GsonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * @Description: 系统controller
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2023/6/30
 */
@Api(tags = "系统Controller")
@RestController
@RequestMapping(SystemConstant.PREFIX_URL_COMMON)
public class SysController {
    private final static Logger log = LoggerFactory.getLogger(SysController.class);

    @Resource
    BasicSchoolService basicSchoolService;

    @ApiOperation(value = "获取学校信息")
    @RequestMapping(value = "/find/school/list", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "学校信息", response = BasicSchool.class)})
    public Object findSchoolList() {
        List<BasicSchool> basicSchoolList = basicSchoolService.list();
        if (!CollectionUtils.isEmpty(basicSchoolList)) {
            List<BasicSchoolResult> basicSchoolResultList = GsonUtil.fromJson(GsonUtil.toJson(basicSchoolList), new TypeToken<List<BasicSchoolResult>>() {
            }.getType());
            return basicSchoolResultList;
        } else {
            return null;
        }
    }
}
