package com.moral.api.controller; import groovy.util.logging.Slf4j; 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.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 java.util.Set; import javax.servlet.http.HttpServletRequest; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.moral.api.service.RegionService; import com.moral.constant.ResponseCodeEnum; import com.moral.constant.ResultMessage; import com.moral.util.WebUtils; @Slf4j @Api(tags = "区域贡献率模块") @CrossOrigin(origins = "*", maxAge = 3600) @RequestMapping("region") @RestController public class RegionController { @Autowired private RegionService regionService; @ApiOperation(value = "根据组织id获取所有区域列表", notes = "根据组织id获取所有区域列表") @GetMapping("getRegionsByOrganizationId") public ResultMessage getRegionsByOrganizationId(Integer organizationId) { if (ObjectUtils.isEmpty(organizationId)) { return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); } Set> response = regionService.getRegionsByOrganizationId(organizationId); return ResultMessage.ok(response); } @ApiOperation(value = "获取该组织下所选区域下所有传感器信息", notes = "获取该组织下所选区域下所有传感器信息") @GetMapping("getSensorByRegionCodes") @ApiImplicitParams({ @ApiImplicitParam(name = "organizationId", value = "组织id", required = true, paramType = "query", dataType = "Integer"), @ApiImplicitParam(name = "regionCodes", value = "乡镇区域码,多个逗号隔开", required = true, paramType = "query", dataType = "String") }) public ResultMessage getSensorByProfessions(HttpServletRequest request) { Map params = WebUtils.getParametersStartingWith(request, null); if (ObjectUtils.isEmpty(params.get("organizationId")) || ObjectUtils.isEmpty(params.get("regionCodes"))) { return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); } Set> response = regionService.getSensorByRegionCodesAndOrganizationId(params); return ResultMessage.ok(response); } @ApiOperation(value = "区域贡献率", notes = "区域贡献率") @GetMapping("regionContribution") @ApiImplicitParams({ @ApiImplicitParam(name = "organizationId", value = "组织id", required = true, paramType = "query", dataType = "Integer"), @ApiImplicitParam(name = "regionCodes", value = "乡镇区码,多个逗号隔开", required = true, paramType = "query", dataType = "String"), @ApiImplicitParam(name = "type", value = "类型,月(2021-12),日(2021-12-24)", required = true, paramType = "query", dataType = "String"), @ApiImplicitParam(name = "time", value = "时间", required = true, paramType = "query", dataType = "String"), @ApiImplicitParam(name = "sensorCode", value = "传感器code", required = true, paramType = "query", dataType = "String") }) public ResultMessage regionContribution(HttpServletRequest request) { Map params = WebUtils.getParametersStartingWith(request, null); if (ObjectUtils.isEmpty(params.get("organizationId")) || ObjectUtils.isEmpty(params.get("regionCodes")) || ObjectUtils.isEmpty(params.get("type")) || ObjectUtils.isEmpty(params.get("time")) || ObjectUtils.isEmpty(params.get("sensorCode"))) { return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); } Map response = regionService.regionContribution(params); return ResultMessage.ok(response); } }