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.UnitDto;
import com.srs.dormitory.service.IDmsDormitoryUnitService;
import com.srs.dormitory.utils.DmsOperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 单元表 前端控制器
 * </p>
 *
 * @author 猪油骨
 * @since 2023-07-14
 */
@Api(tags = "宿舍单元管理")
@RestController
@RequestMapping("/dormitory/dms-dormitory-unit")
public class DmsDormitoryUnitController extends BaseController {
    @Autowired
    private IDmsDormitoryUnitService dmsDormitoryUnitService;

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-unit:add')")
    @ApiOperation(value = "添加宿舍楼单元")
    @PostMapping("/add")
    public AjaxResult addDmsDormitoryUnit(@RequestBody UnitDto unitDto){
        return dmsDormitoryUnitService.addDmsDormitoryUnit(unitDto,getUsername());
    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-unit:list')")
    @ApiOperation(value = "查看单元列表",notes = "只需要传入buildingId宿舍楼id，不传则显示所有单元")
    @PostMapping("/list")
    public TableDataInfo getDmsDormitoryUnitList(@RequestBody UnitDto unitDto){
        startPage();
        return getDataTable(dmsDormitoryUnitService.getDmsDormitoryUnitList(unitDto));
    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-unit:query')")
    @ApiOperation("查看单元详情")
    @GetMapping("/{id}")
    public AjaxResult getDmsDormitoryUnitInfo(@PathVariable Long id){
        return dmsDormitoryUnitService.getDmsDormitoryUnitInfo(id);
    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-unit:edit')")
    @ApiOperation(value = "修改宿舍楼单元")
    @PostMapping("/update")
    public AjaxResult updateDmsDormitoryUnit(@RequestBody UnitDto unitDto){
        return dmsDormitoryUnitService.updateDmsDormitoryUnit(unitDto,getUsername());
    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-unit:remove')")
    @ApiOperation("删除宿舍单元")
    @DeleteMapping("/delete/{id}")
    public AjaxResult deleteDmsDormitoryUnit(@PathVariable Long id){
        List<Long> ids = new ArrayList<>();
        ids.add(id);
        return dmsDormitoryUnitService.batchDeleteDmsDormitoryUnit(ids);
    }

//    @PreAuthorize("@ss.hasPermi('dormitory:dms-dormitory-unit:remove')")
    @ApiOperation("批量删除宿舍单元")
    @DeleteMapping("/delete")
    public AjaxResult batchDeleteDmsDormitoryUnit(@RequestBody List<Long> ids){
        return dmsDormitoryUnitService.batchDeleteDmsDormitoryUnit(ids);
    }
}
