package com.persagy.bdtp.adm.controller;

import com.persagy.bdtp.adm.common.AdmRequest;
import com.persagy.bdtp.adm.common.AdmResult;
import com.persagy.bdtp.adm.service.ISyncOldAdm;
import com.persagy.bdtp.adm.service.ISyncSpace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/manage")
public class ManageController {

	@Autowired
	private ISyncOldAdm syncOldAdm;

	@Autowired
	private ISyncSpace syncSpace;

	@RequestMapping("/syncOldAdm")
	public AdmResult<Object> syncOldAdm(@RequestBody AdmRequest req){
		String groupCode = req.getGroupCode();
		String projectId = req.getProjectId();

		Map<String, Object> syncResult = syncOldAdm.syncData(groupCode, projectId);
		syncOldAdm.handleJobSpace(projectId);
		syncOldAdm.uploadFloorMap(groupCode, projectId);
		return AdmResult.success(syncResult);
	}

	@RequestMapping("/syncSpace")
	public AdmResult<Object> syncSpace(@RequestBody AdmRequest req){
		Map<String, Object> syncResult = syncSpace.sync(req.getGroupCode(), req.getProjectId(), req.getUserId(), req.getFloorId(), "GeneralZone");
		return AdmResult.success(syncResult);
	}

}
