package com.moral.api.controller;
|
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.util.ObjectUtils;
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import com.moral.api.entity.Organization;
|
import com.moral.api.service.DeviceService;
|
import com.moral.api.service.OrganizationService;
|
import com.moral.api.service.SysAreaService;
|
import com.moral.constant.ResponseCodeEnum;
|
import com.moral.constant.ResultMessage;
|
import com.moral.util.WebUtils;
|
|
@Slf4j
|
@Api(tags = {"组织"})
|
@RestController
|
@CrossOrigin(origins = "*", maxAge = 3600)
|
@RequestMapping("/organization")
|
public class OrganizationController {
|
|
@Autowired
|
private SysAreaService sysAreaService;
|
|
@Autowired
|
private DeviceService deviceService;
|
|
@Autowired
|
private OrganizationService organizationService;
|
|
/**
|
* @param request 请求信息
|
* @return 返回请求成功后的对象信息
|
*/
|
@GetMapping("getMapPath")
|
@ApiOperation(value = "获取当前用户地图权限", notes = "获取当前用户地图权限")
|
@ApiImplicitParams(value = {
|
@ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
|
@ApiImplicitParam(name = "organizationId", value = "组织id", required = true, paramType = "query", dataType = "String")
|
})
|
public ResultMessage getMapPath(HttpServletRequest request) {
|
Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
|
if (!params.containsKey("organizationId")) {
|
return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
|
}
|
List<Map<String, Object>> response = sysAreaService.getMapPath(Integer.parseInt(params.get("organizationId").toString()));
|
return ResultMessage.ok(response);
|
}
|
|
/**
|
* @param request 请求信息
|
* @return 返回请求成功后的对象信息
|
*/
|
@GetMapping("getDevicesByOrganizationId")
|
@ApiOperation(value = "获取当前组织下设备列表", notes = "获取当前组织下设备列表")
|
@ApiImplicitParams(value = {
|
@ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
|
@ApiImplicitParam(name = "organizationId", value = "组织id", required = true, paramType = "query", dataType = "String")
|
})
|
public ResultMessage getDevicesByOrganizationId(HttpServletRequest request) {
|
Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
|
if (!params.containsKey("organizationId")) {
|
return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
|
}
|
List<Map<String, Object>> response = deviceService.getDevicesByOrganizationId(Integer.parseInt(params.get("organizationId").toString()));
|
return ResultMessage.ok(response);
|
}
|
|
|
@GetMapping("getOrganizationId")
|
@ApiOperation("根据账号查询组织")
|
public ResultMessage getOrganizationId(){
|
List<Organization> organizations = organizationService.getOrganizationId();
|
return ResultMessage.ok(ObjectUtils.isEmpty(organizations)?"0":organizations);
|
}
|
|
|
@GetMapping("queryDevices")
|
@ApiOperation("查询组织信息")
|
public ResultMessage queryDevices(){
|
List<Organization> organizations = organizationService.queryDevices();
|
return ResultMessage.ok(organizations);
|
}
|
}
|