package com.ym.mec.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ym.mec.biz.dal.entity.School;
import com.ym.mec.biz.dal.page.SchoolQueryInfo;
import com.ym.mec.biz.service.SchoolService;
import com.ym.mec.common.controller.BaseController;

@RequestMapping("school")
@Api(tags = "学校(教学点)服务")
@RestController
public class SchoolController extends BaseController {

    @Autowired
    private SchoolService schoolService;

    @ApiOperation(value = "新增学校")
    @PostMapping("/add")
    public Object add(School school){
        schoolService.insert(school);
        return succeed();
    }

    @ApiOperation(value = "删除学校")
    @PostMapping("/del/{id}")
    public Object del(@ApiParam(value = "学校编号", required = true) @PathVariable("id") Integer id){
        schoolService.delete(id);
        return succeed();
    }

    @ApiOperation(value = "修改学校")
    @PostMapping("/update")
    public Object update(School school){
        school.setUpdateTime(new Date());
        schoolService.update(school);
        return succeed();
    }

    @ApiOperation(value = "根据学校编号查询学校")
    @GetMapping("/get/{id}")
    public Object get(@ApiParam(value = "学校编号", required = true) @PathVariable("id") Integer id){
        return succeed(schoolService.get(id));
    }

    @ApiOperation(value = "分页查询学校列表")
    @GetMapping("/queryPage")
    public Object queryPage(SchoolQueryInfo queryInfo){
        return succeed(schoolService.queryPage(queryInfo));
    }

    @ApiOperation(value = "根据机构编号获取学校列表")
    @GetMapping("/queryByOrganId")
    public Object queryByOrganId(@RequestParam Integer organId){
        return succeed(schoolService.queryByOrganId(organId,null));
    }
}
