package com.srs.web.controller.dormitory;

import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.core.page.TableDataInfo;
import com.srs.dormitory.domain.Dto.CampusDto;
import com.srs.dormitory.domain.Vo.CampusVo;
import com.srs.dormitory.service.IDmsCampusService;
import com.srs.dormitory.utils.DmsOperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 校区表 前端控制器
 * </p>
 *
 * @author 猪油骨
 * @since 2023-07-14
 */
@RestController
@RequestMapping("/dormitory/dms-campus")
@Api(tags = "校区管理")
@AllArgsConstructor
public class DmsCampusController extends BaseController {
    private final IDmsCampusService iDmsCampusService;

    @PostMapping("/add")
    @ApiOperation(value = "添加校区", notes = "添加校区不用传id", response = CampusDto.class)
    public AjaxResult addCampus(@RequestBody CampusDto campusDto) {
        return iDmsCampusService.addCampus(campusDto, getUsername());
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改校区", notes = "传入id修改校区", response = CampusDto.class)
    public AjaxResult updateCampus(@RequestBody CampusDto campusDto) {
        return iDmsCampusService.updateCampus(campusDto, getUsername());
    }

    @GetMapping("/list")
    @ApiOperation(value = "校区列表")
    public TableDataInfo campusList(@RequestParam(required = false) String name) {
        startPage();
        List<CampusVo> list = iDmsCampusService.campusList(name);
        return getDataTable(list);
    }

    @ApiOperation("校区详情")
    @GetMapping("/{id}")
    public AjaxResult getCampus(@PathVariable Long id) {
        return iDmsCampusService.getCampus(id);
    }

    @PostMapping("/delete/{id}")
    @ApiOperation(value = "根据id删除校区", notes = "传校区id")
    public AjaxResult deleteCampusById(@PathVariable Long id) {
        return iDmsCampusService.deleteCampusById(id);
    }

    @PostMapping("/delete")
    @ApiOperation(value = "批量删除校区", notes = "传校区id列表")
    public AjaxResult deleteCampus(@RequestBody List<Long> ids) {
        return iDmsCampusService.deleteCampus(ids);
    }

    @ApiOperation("校区园区宿舍楼级联列表")
    @GetMapping("/cascadingList")
    public AjaxResult cascadingList() {
        return iDmsCampusService.cascadingList();
    }

}
