package com.app.controller.admin.basics;

import com.app.annotation.platform.OperationLog;
import com.app.constant.SystemConstant;
import com.app.dto.Result;
import com.app.dto.basics.SchoolYearSemesterDto;
import com.app.entity.basics.YearSemester;
import com.app.service.basics.YearSemesterService;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 功能描述：学年学期
 *
 * @Auther: 梁展鹏
 * @Date: 2018/7/24 11:38
 */
@Api(tags = "学年学期")
@Slf4j
@Validated
@RestController("AdminOrganYearSemesterController")
@RequestMapping("/admin/year-semester")
public class YearSemesterController {

    @Autowired
    private YearSemesterService service;

    /**
     * 功能描述：查询[学年学期]
     *
     * @return
     */
    @ApiOperation(value = "查询[学年学期]")
    @PostMapping("/find")
    public ResponseEntity<Result<YearSemester>> find() {
        String organId = SystemConstant.organId;
        return new ResponseEntity(new Result().ok(service.find(organId)), HttpStatus.OK);
    }

    /**
     * 功能描述：保存/更新[学年学期]
     *
     * @param dto
     * @return
     */
    @OperationLog("更新 - 学年学期")
    @ApiOperation(value = "保存/更新[学年学期]")
    @PostMapping("/save-or-update")
    public ResponseEntity<Result> saveOrUpdate(@Valid @RequestBody SchoolYearSemesterDto dto) {
        String organId = SystemConstant.organId;
        service.saveOrUpdate(organId, dto.getSchoolYear(), dto.getSemester());
        return new ResponseEntity(new Result().ok(), HttpStatus.OK);
    }

}
