package org.springblade.app.controller;

import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springblade.community.entity.Room;
import org.springblade.community.feign.IRoomClient;
import org.springblade.community.vo.RoomVO;
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 java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created By lidexi in 2021/4/26
 **/
@RestController
@RequiredArgsConstructor
@Api(value = "", tags = "接口")
@RequestMapping(value = "/app/room")
@Slf4j
public class RoomController {

	private final IRoomClient roomClient;

	/**
	 * 功能描述: 通过单元id获取房间列表
	 *
	 * @param map {
	 *            unit_id   :   单元id,
	 *            org_id    :   机构授权org_id，机构id
	 *            token     :   对接令牌
	 *            }
	 * @return ResultBean<hashMap> 返回结果
	 */
	@PostMapping(value = "/getByUnitId")
	public Map<String, Object> getByUnitId(@RequestBody Map<String, String> map) {

		Map<String, Object> hashMap = new HashMap<>();
		//result_code:0-失败  1-成功
		hashMap.put("result_code", 0);
		hashMap.put("result_msg", "查询失败");
		try {
			Long unit_id = Long.valueOf(map.get("unit_id"));


			if (unit_id == null) {
				hashMap.put("result_msg", "单元id不能为空");
				return hashMap;
			}
			Room room = new Room();
			room.setUnitId(unit_id);
			List<RoomVO> rooms = this.roomClient.list(room);
			hashMap.put("result_code", 1);

			hashMap.put("list", rooms);
			if (rooms.size() == 0) {
				hashMap.put("result_msg", "没有相关房屋信息");
			} else {
				hashMap.put("result_msg", "获取房屋信息成功");
			}
		} catch (Exception e) {
			log.error("异常", e);
			hashMap.put("result_msg", "后台程序异常");
		}
		return hashMap;
	}

}
