package com.app.controller.admin.organ;

import com.app.annotation.platform.OperationLog;
import com.app.dto.Result;
import com.app.dto.organ.OrganBranchSchoolResponseDto;
import com.app.entity.organ.Organ;
import com.app.service.organ.OrganSchoolService;
import com.app.service.organ.OrganService;
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;
import java.util.List;

/**
 * 功能描述：学校
 *
 * @Auther: 梁展鹏
 * @Date: 2018/7/24 11:38
 */
@Api("机构")
@Slf4j
@Validated
@RestController("AdminOrganController")
@RequestMapping("/admin/organ")
public class OrganController {

    @Autowired
    private OrganService service;

    @Autowired
    private OrganSchoolService organSchoolService;

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

    @ApiOperation(value = "查询[机构]")
    @PostMapping("/find-organ/{id}")
    public  ResponseEntity<Result<OrganBranchSchoolResponseDto>> findOrgan(@PathVariable String id) {
        return new ResponseEntity(new Result().ok(service.findOrgan(id)), HttpStatus.OK);
    }

    @ApiOperation(value = "查询所有[机构]")
    @PostMapping("/find-organ/selectOrgan")
    public  ResponseEntity<Result<List<Organ>>> findAllOrgan() {
        return new ResponseEntity(new Result().ok(service.findAllOrgan()), HttpStatus.OK);
    }

    /**
     * 功能描述：删除机构分校
     *
     * @param id 机构分校标识
     * @return
     */
    @OperationLog("删除 - 机构分校")
    @ApiOperation(value = "删除机构分校")
    @DeleteMapping("/school/{id}")
    public ResponseEntity<Result<?>> delete(@PathVariable String id) {
        organSchoolService.delete(id);
        return new ResponseEntity(new Result().ok(), HttpStatus.OK);
    }

}
