package com.community.huiju.controller;


import com.community.huiju.common.base.BaseController;
import com.community.huiju.common.base.ResponseBean;
import com.community.huiju.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 小区楼栋资料表 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2019-05-15
 */
@RestController
@RequestMapping("/")
@Api(value = "楼栋资料 API", description = "楼栋资料 API")
public class TpAddressController extends BaseController {

    @Autowired
    private ITpPhaseService iTpPhaseService;

    @Autowired
    private ITpBuildingService iTpBuildingService;

    @Autowired
    private ITpLevelService iTpLevelService;

    @Autowired
    private ITpUnitService iTpUnitService;

    @Autowired
    private ITpRoomNoService iTpRoomNoService;

    @RequestMapping(value = "/building/info", method = RequestMethod.GET)
    @ApiOperation(value = "查询 期/栋/单元/楼层/户号 列表", notes = "查询 期/栋/单元/楼层/户号 列表")
    @ApiImplicitParams({
            @ApiImplicitParam(dataTypeClass = Integer.class, paramType = "query", name = "communityId", value = "小区id"),
            @ApiImplicitParam(dataTypeClass = Integer.class, paramType = "query", name = "phaseId", value = "期id"),
            @ApiImplicitParam(dataTypeClass = Integer.class, paramType = "query", name = "buildingId", value = "楼栋id"),
            @ApiImplicitParam(dataTypeClass = Integer.class, paramType = "query", name = "unitId", value = "单元id"),
            @ApiImplicitParam(dataTypeClass = Integer.class, paramType = "query", name = "levelId", value = "楼层id"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "query", name = "appid", value = "appid"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "query", name = "datetime", value = "时间戳"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "query", name = "encrypt", value = "加密方式"),
            @ApiImplicitParam(dataTypeClass = String.class, paramType = "query", name = "sign", value = "签名"),
    })
    public ResponseBean getBuildingInfo(@RequestParam("communityId") Integer communityId,
                                        @RequestParam(value = "phaseId", required = false) Integer phaseId,
                                        @RequestParam(value = "buildingId", required = false) Integer buildingId,
                                        @RequestParam(value = "unitId", required = false) Integer unitId,
                                        @RequestParam(value = "levelId", required = false) Integer levelId) {

        ResponseBean responseBean = new ResponseBean();
        if (null == phaseId && null == buildingId && null == unitId && null == levelId) {
            responseBean = iTpPhaseService.getPhase(communityId);
        } else if (null == buildingId && null == unitId && null == levelId) {
            responseBean = iTpBuildingService.getBuilding(communityId, phaseId);
        } else if (null == unitId && null == levelId) {
            responseBean = iTpUnitService.getUnit(communityId, phaseId, buildingId);
        } else if (null == levelId) {
            responseBean = iTpLevelService.getLevel(communityId, phaseId, buildingId, unitId);
        } else {
            responseBean = iTpRoomNoService.getRoomNo(communityId, phaseId, buildingId, unitId, levelId);
        }

        return responseBean;

    }

}
