package com.app.controller.admin.basics;

import com.app.annotation.platform.OperationLog;
import com.app.dto.PageResult;
import com.app.dto.Result;
import com.app.dto.SearchDto;
import com.app.dto.basics.operation.SchoolDto;
import com.app.dto.basics.search.SearchSchoolDto;
import com.app.entity.basics.School;
import com.app.service.basics.SchoolService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 功能描述：学校
 *
 * @Auther: 梁展鹏
 * @Date: 2018/7/24 11:38
 */
@Api(description = "学校")
@Slf4j
@Validated
@RestController("AdminSchoolController")
@RequestMapping("/admin/school")
public class SchoolController {

    @Autowired
    private SchoolService schoolService;

    /**
     * 功能描述：查询所有[学校]
     *
     * @param params 查询对象
     * @return
     */
    @ApiOperation(value = "查询所有[学校]")
    @PostMapping("/page")
    public ResponseEntity<Result<PageResult<School>>> page(@Valid @RequestBody SearchSchoolDto params) {
        return new ResponseEntity(new Result().ok(schoolService.page(params)), HttpStatus.OK);
    }

    /**
     * 功能描述：保存/更新[学校]
     *
     * @param school
     * @return
     */
    @OperationLog("更新 - 学校")
    @ApiOperation(value = "保存/更新[学校]")
    @PostMapping("/save-or-update")
    public ResponseEntity<Result> saveOrUpdate(@Valid @RequestBody SchoolDto school) {
        schoolService.saveOrUpdate(school);
        return new ResponseEntity(new Result().ok(), HttpStatus.OK);
    }

    /**
     * 功能描述：替换[学校]删除状态
     *
     * @param searchdto
     * @return
     */
    @OperationLog("替换删除状态 - 学校")
    @ApiOperation(value = "替换[学校]删除状态")
    @PostMapping("/handle-is-del")
    public ResponseEntity<Result> handleIsDel(@Valid @RequestBody SearchDto searchdto) {
        schoolService.handleIsDel(searchdto.getId());
        return new ResponseEntity(new Result().ok(), HttpStatus.OK);
    }

    /**
     * 功能描述：把[学校]各个年级升级，高年级做毕业处理
     *
     * @param schoolId
     * @return
     */
    @OperationLog("更新 - 学校升年级")
    @ApiOperation(value = "把[学校]各个年级升级，高年级做毕业处理")
    @PostMapping("/{schoolId}/up-level")
    public ResponseEntity<Result> upLevel(@PathVariable("schoolId") String schoolId) {
        schoolService.upLevel(schoolId);
        return new ResponseEntity(new Result().ok(), HttpStatus.OK);
    }

}
