package com.xjrsoft.module.base.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.xjrsoft.common.exception.MyException;
import com.xjrsoft.common.model.result.RT;
import com.xjrsoft.module.base.dto.BaseOfficeBuildChangeStatusDto;
import com.xjrsoft.module.base.entity.BaseOfficeBuild;
import com.xjrsoft.module.base.service.IBaseOfficeBuildService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
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;

/**
* @title: 区域楼栋管理
* @Author dzx
* @Date: 2024年3月28日
* @Version 1.0
*/
@RestController
@RequestMapping("/officebuild")
@Api(value = "/officebuild",tags = "区域楼栋管理")
@AllArgsConstructor
public class OfficeBuildController {
    private final IBaseOfficeBuildService baseOfficeBuildService;


    @PostMapping(value = "/change-status")
    @ApiOperation(value="修改状态")
    @SaCheckPermission("officebuild:detail")
    public RT<Boolean> changeStatus(@Valid @RequestBody BaseOfficeBuildChangeStatusDto dto) throws Exception {
        BaseOfficeBuild officeBuild = baseOfficeBuildService.getById(dto.getId());
        if(officeBuild == null){
            throw new MyException("未能找到楼栋信息");
        }
        officeBuild.setStatus(dto.getStatus());
        baseOfficeBuildService.updateById(officeBuild);
        return RT.ok(true);
    }

    @DeleteMapping
    @ApiOperation(value = "删除")
    @SaCheckPermission("officebuild:delete")
    public RT<Boolean> delete(@Valid @RequestBody Long id){
        return RT.ok(baseOfficeBuildService.removeById(id));
    }
}