1 files deleted
7 files added
12 files modified
| | |
| | | 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.service.DeviceService; |
| | | import com.moral.api.service.HistoryDailyService; |
| | | import com.moral.api.service.HistoryFiveMinutelyService; |
| | | import com.moral.api.service.HistoryHourlyService; |
| | | import com.moral.api.service.SysAreaService; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.constant.ResultMessage; |
| | | import com.moral.util.WebUtils; |
| | |
| | | |
| | | @Autowired |
| | | private HistoryDailyService historyDailyService; |
| | | |
| | | @Autowired |
| | | private HistoryFiveMinutelyService historyFiveMinutelyService; |
| | | |
| | | @Autowired |
| | | private DeviceService deviceService; |
| | | |
| | | @Autowired |
| | | private SysAreaService sysAreaService; |
| | | |
| | | @GetMapping("getHourlyAqi") |
| | | @ApiOperation(value = "获取一小时AQI", notes = "获取一小时AQI") |
| | |
| | | return ResultMessage.ok(result); |
| | | } |
| | | |
| | | @GetMapping("getWindData") |
| | | @ApiOperation(value = "获取风场数据", notes = "获取风场数据") |
| | | @ApiImplicitParams(value = { |
| | | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"), |
| | | @ApiImplicitParam(name = "monitorPointId", value = "站点id", required = true, paramType = "query", dataType = "String") |
| | | }) |
| | | public ResultMessage getWindData(HttpServletRequest request) { |
| | | Map<String, Object> params = WebUtils.getParametersStartingWith(request, null); |
| | | if (!params.containsKey("monitorPointIds")) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | String[] monitorPointIds = params.remove("monitorPointIds").toString().split(","); |
| | | params.put("monitorPointIds", monitorPointIds); |
| | | List<Object> result = historyFiveMinutelyService.getAreaWindData(params); |
| | | return ResultMessage.ok(result); |
| | | } |
| | | |
| | | @GetMapping("getMacSensors") |
| | | @ApiOperation(value = "根据mac获取对应所有因子", notes = "根据mac获取对应所有因子") |
| | | @ApiImplicitParams(value = { |
| | | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"), |
| | | @ApiImplicitParam(name = "mac", value = "设备mac", required = true, paramType = "query", dataType = "String") |
| | | }) |
| | | public ResultMessage getMacSensors(HttpServletRequest request) { |
| | | Map<String, Object> params = WebUtils.getParametersStartingWith(request, null); |
| | | if (!params.containsKey("mac")) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | Map<String, Object> sensorsInfo = deviceService.getSensorsByMac(params.get("mac").toString()); |
| | | return ResultMessage.ok(sensorsInfo); |
| | | } |
| | | |
| | | @GetMapping("getTrendChartData") |
| | | @ApiOperation(value = "获取监测因子趋势图数据", notes = "获取监测因子趋势图数据") |
| | | @ApiImplicitParams(value = { |
| | | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"), |
| | | @ApiImplicitParam(name = "mac", value = "设备mac", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "sensorCode", value = "因子code", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "type", value = "数据类型,日(day),月(month),年(year)", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "time", value = "数据时间", required = true, paramType = "query", dataType = "String") |
| | | }) |
| | | public ResultMessage getTrendChartData(HttpServletRequest request) { |
| | | Map<String, Object> params = WebUtils.getParametersStartingWith(request, null); |
| | | if (!params.containsKey("mac") || !params.containsKey("sensorCode") || !params.containsKey("type") || !params.containsKey("time")) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | List<Map<String, Object>> sensorsInfo = deviceService.getTrendChartData(params); |
| | | return ResultMessage.ok(sensorsInfo); |
| | | } |
| | | |
| | | @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>> result = sysAreaService.getMapPath(Integer.parseInt(params.get("organizationId").toString())); |
| | | return ResultMessage.ok(result); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.moral.api.entity; |
| | | |
| | | import com.baomidou.mybatisplus.extension.activerecord.Model; |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | |
| | | /** |
| | | * <p> |
| | | * 月数据 |
| | | * </p> |
| | | * |
| | | * @author moral |
| | | * @since 2021-07-20 |
| | | */ |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = false) |
| | | public class HistoryMonthly extends Model<HistoryMonthly> { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * 设备mac |
| | | */ |
| | | private String mac; |
| | | |
| | | /** |
| | | * 时间 |
| | | */ |
| | | private Date time; |
| | | |
| | | /** |
| | | * 数据 |
| | | */ |
| | | private String value; |
| | | |
| | | |
| | | @Override |
| | | protected Serializable pkVal() { |
| | | return null; |
| | | } |
| | | |
| | | } |
| | |
| | | package com.moral.api.mapper; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import com.moral.api.entity.Device; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | |
| | |
| | | */ |
| | | public interface DeviceMapper extends BaseMapper<Device> { |
| | | |
| | | /*监测因子趋势图数据*/ |
| | | List<Map<String, Object>> getTrendChartData(Map<String, Object> params); |
| | | |
| | | } |
| | |
| | | package com.moral.api.mapper; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import com.moral.api.entity.HistoryFiveMinutely; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.moral.api.pojo.dto.Wind.WindData; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | */ |
| | | public interface HistoryFiveMinutelyMapper extends BaseMapper<HistoryFiveMinutely> { |
| | | |
| | | List<WindData> getAreaWindData(Map<String, Object> params); |
| | | |
| | | } |
New file |
| | |
| | | package com.moral.api.mapper; |
| | | |
| | | import com.moral.api.entity.HistoryMonthly; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | |
| | | /** |
| | | * <p> |
| | | * 月数据 Mapper 接口 |
| | | * </p> |
| | | * |
| | | * @author moral |
| | | * @since 2021-07-20 |
| | | */ |
| | | public interface HistoryMonthlyMapper extends BaseMapper<HistoryMonthly> { |
| | | |
| | | } |
New file |
| | |
| | | package com.moral.api.pojo.dto.Wind; |
| | | |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class WindData { |
| | | |
| | | //经度 |
| | | private Double longitude; |
| | | |
| | | //纬度 |
| | | private Double latitude; |
| | | |
| | | //风向角度 |
| | | private Double windDir; |
| | | |
| | | //风速 |
| | | private Double windSpeed; |
| | | |
| | | } |
| | |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @since 2021-06-28 |
| | | */ |
| | | public interface DeviceService extends IService<Device> { |
| | | |
| | | List<Device> getDevicesByMonitorPointId(Integer monitorPointId); |
| | | |
| | | //根据mac获取因子信息 |
| | | Map<String, Object> getSensorsByMac(String mac); |
| | | |
| | | //获取监测因子趋势图数据 |
| | | List<Map<String, Object>> getTrendChartData(Map<String,Object> params); |
| | | |
| | | } |
| | |
| | | import com.moral.api.pojo.form.historyFiveMinutely.QueryDeviceAndFiveMinuteDataForm; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @Date: 2021/7/16 |
| | | */ |
| | | List<DeviceAndFiveMinuteDataDTO> queryDeviceAndFiveMinuteData(QueryDeviceAndFiveMinuteDataForm form); |
| | | |
| | | //获取5分钟风场数据 |
| | | List<Object> getAreaWindData(Map<String,Object> params); |
| | | } |
New file |
| | |
| | | package com.moral.api.service; |
| | | |
| | | import com.moral.api.entity.HistoryMonthly; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | |
| | | /** |
| | | * <p> |
| | | * 月数据 服务类 |
| | | * </p> |
| | | * |
| | | * @author moral |
| | | * @since 2021-07-20 |
| | | */ |
| | | public interface HistoryMonthlyService extends IService<HistoryMonthly> { |
| | | |
| | | } |
| | |
| | | package com.moral.api.service; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import com.moral.api.entity.SysArea; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | |
| | |
| | | */ |
| | | public interface SysAreaService extends IService<SysArea> { |
| | | |
| | | List<Map<String, Object>> getMapPath(Integer orgId); |
| | | |
| | | } |
| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.moral.api.entity.Device; |
| | | import com.moral.api.entity.Sensor; |
| | | import com.moral.api.mapper.DeviceMapper; |
| | | import com.moral.api.service.DeviceService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.api.service.HistoryHourlyService; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.constant.RedisConstants; |
| | | import com.moral.util.DateUtils; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Autowired |
| | | DeviceMapper deviceMapper; |
| | | |
| | | @Autowired |
| | | private RedisTemplate redisTemplate; |
| | | |
| | | @Override |
| | | public List<Device> getDevicesByMonitorPointId(Integer monitorPointId) { |
| | | QueryWrapper<Device> wrapper = new QueryWrapper(); |
| | | wrapper.eq("is_delete", Constants.NOT_DELETE); |
| | | wrapper.eq("monitor_point_id",monitorPointId); |
| | | wrapper.eq("monitor_point_id", monitorPointId); |
| | | List<Device> devices = deviceMapper.selectList(wrapper); |
| | | return devices; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getSensorsByMac(String mac) { |
| | | //从redis中获取设备因子信息 |
| | | Device device = (Device) redisTemplate.opsForHash().get(RedisConstants.DEVICE_INFO, mac); |
| | | List<Sensor> sensors = device.getVersion().getSensors(); |
| | | Map<String, Object> result = new HashMap<>(); |
| | | for (Sensor sensor : sensors) { |
| | | String sensorCode = sensor.getCode(); |
| | | String name = sensor.getName(); |
| | | result.put(sensorCode, name); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getTrendChartData(Map<String, Object> params) { |
| | | Object type = params.get("type"); |
| | | String start = params.remove("time").toString(); |
| | | String end; |
| | | String timeUnits; |
| | | String dateFormat; |
| | | List<Map<String, Object>> result = new ArrayList<>(); |
| | | if ("day".equals(type)) { |
| | | end = DateUtils.getDateAddDay(start, 1); |
| | | timeUnits = "hourly"; |
| | | dateFormat = "%H"; |
| | | } else if ("month".equals(type)) { |
| | | end = DateUtils.getDateAddMonth(start, 1); |
| | | timeUnits = "daily"; |
| | | dateFormat = "%d"; |
| | | } else { |
| | | end = DateUtils.getDateAddYear(start, 1); |
| | | timeUnits = "monthly"; |
| | | dateFormat = "%m"; |
| | | } |
| | | params.put("dateFormat", dateFormat); |
| | | params.put("timeUnits", timeUnits); |
| | | params.put("start", start); |
| | | params.put("end", end); |
| | | return deviceMapper.getTrendChartData(params); |
| | | } |
| | | |
| | | } |
| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.moral.api.entity.Device; |
| | | import com.moral.api.entity.HistoryFiveMinutely; |
| | | import com.moral.api.entity.MonitorPoint; |
| | | import com.moral.api.mapper.HistoryFiveMinutelyMapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.api.pojo.dto.Wind.WindData; |
| | | import com.moral.api.pojo.dto.historyFiveMinutely.DeviceAndFiveMinuteDataDTO; |
| | | import com.moral.api.pojo.form.device.MonitorPointQueryForm; |
| | | import com.moral.api.pojo.form.historyFiveMinutely.QueryDeviceAndFiveMinuteDataForm; |
| | | import com.moral.api.service.HistoryFiveMinutelyService; |
| | | import com.moral.api.service.MonitorPointService; |
| | | import com.moral.constant.RedisConstants; |
| | | import com.moral.util.DateUtils; |
| | | |
| | | import io.lettuce.core.GeoCoordinates; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | |
| | | @Autowired |
| | | MonitorPointService monitorPointService; |
| | | |
| | | @Autowired |
| | | RedisTemplate redisTemplate; |
| | | |
| | | @Autowired |
| | | private HistoryFiveMinutelyMapper historyFiveMinutelyMapper; |
| | | |
| | | @Override |
| | | public List<DeviceAndFiveMinuteDataDTO> queryDeviceAndFiveMinuteData(QueryDeviceAndFiveMinuteDataForm form) { |
| | |
| | | DeviceAndFiveMinuteDataDTO dto = new DeviceAndFiveMinuteDataDTO(); |
| | | String mac = device.getMac(); |
| | | Map<String, Object> sensorValues = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.DATA_FIVE_MINUTES, mac); |
| | | Map<String,Object> value = new HashMap<>(); |
| | | if (sensorValues!=null&&sensorValues.get(sensorCode) != null) |
| | | value.put(sensorCode,sensorValues.get(sensorCode)); |
| | | Map<String, Object> value = new HashMap<>(); |
| | | if (sensorValues != null && sensorValues.get(sensorCode) != null) |
| | | value.put(sensorCode, sensorValues.get(sensorCode)); |
| | | else |
| | | value.put(sensorCode,null); |
| | | value.put(sensorCode, null); |
| | | dto.setDevice(device); |
| | | dto.setSensorValue(value); |
| | | dtos.add(dto); |
| | |
| | | return dtos; |
| | | } |
| | | |
| | | @Override |
| | | public List<Object> getAreaWindData(Map<String, Object> params) { |
| | | String timeUnits = DateUtils.dateToDateString(new Date(), DateUtils.yyyyMM_EN); |
| | | params.put("timeUnits", timeUnits); |
| | | //风场数据 |
| | | List<WindData> windData = historyFiveMinutelyMapper.getAreaWindData(params); |
| | | return getWindData(windData); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据输入的地点坐标计算中心点 |
| | | * |
| | | * @param geoCoordinateList |
| | | * @return |
| | | */ |
| | | public Map<String, Double> getCenterPoint(List<GeoCoordinates> geoCoordinateList) { |
| | | int total = geoCoordinateList.size(); |
| | | double X = 0, Y = 0, Z = 0; |
| | | for (GeoCoordinates g : geoCoordinateList) { |
| | | double lat, lon, x, y, z; |
| | | lat = (double) g.getY() * Math.PI / 180; |
| | | lon = (double) g.getX() * Math.PI / 180; |
| | | x = Math.cos(lat) * Math.cos(lon); |
| | | y = Math.cos(lat) * Math.sin(lon); |
| | | z = Math.sin(lat); |
| | | X += x; |
| | | Y += y; |
| | | Z += z; |
| | | } |
| | | |
| | | X = X / total; |
| | | Y = Y / total; |
| | | Z = Z / total; |
| | | double Lon = Math.atan2(Y, X); |
| | | double Hyp = Math.sqrt(X * X + Y * Y); |
| | | double Lat = Math.atan2(Z, Hyp); |
| | | |
| | | Map<String, Double> map = new HashMap<>(); |
| | | map.put("lng", Lon * 180 / Math.PI); |
| | | map.put("lat", Lat * 180 / Math.PI); |
| | | return map; |
| | | } |
| | | |
| | | public List<Object> getWindData(List<WindData> windData) { |
| | | List<GeoCoordinates> points = new ArrayList<>(); |
| | | int length = 2000; |
| | | int perdlen = 200; |
| | | Double loma = 0d; |
| | | Double lomi = 0d; |
| | | Double lama = 0d; |
| | | Double lami = 0d; |
| | | List<Double> loList = new ArrayList<>(); |
| | | List<Double> laList = new ArrayList<>(); |
| | | Double U; |
| | | Double V; |
| | | //结果集 |
| | | List<Object> list = new ArrayList<>(); |
| | | List<Map<String, Object>> mapList = new ArrayList<>(); |
| | | for (WindData data : windData) { |
| | | Double longitude = data.getLongitude(); |
| | | Double latitude = data.getLatitude(); |
| | | GeoCoordinates geoCoordinates = GeoCoordinates.create(longitude, latitude); |
| | | points.add(geoCoordinates); |
| | | loList.add(longitude); |
| | | laList.add(latitude); |
| | | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | Double windDir = data.getWindDir(); |
| | | Double windSpeed = data.getWindSpeed(); |
| | | if (windDir == null) { |
| | | windDir = 0d; |
| | | windSpeed = 0d; |
| | | } |
| | | double dir = (360.0 - (windDir + 180.0) * Math.PI / 180.0); |
| | | U = windSpeed * Math.cos(dir); |
| | | V = windSpeed * Math.sin(dir); |
| | | map.put("lo", longitude); |
| | | map.put("la", latitude); |
| | | map.put("U", U); |
| | | map.put("V", V); |
| | | mapList.add(map); |
| | | } |
| | | |
| | | //根据所有多个站点经纬度获取中心点 |
| | | Map<String, Double> centerPoint = getCenterPoint(points); |
| | | |
| | | if (loList.size() > 0) { |
| | | loma = Collections.max(loList); |
| | | lomi = Collections.min(loList); |
| | | } |
| | | if (laList.size() > 0) { |
| | | lama = Collections.max(laList); |
| | | lami = Collections.min(laList); |
| | | } |
| | | Map<String, Object> laLaMap = new HashMap<>(); |
| | | laLaMap.put("maxLo", loma); |
| | | laLaMap.put("minLo", lomi); |
| | | laLaMap.put("maxLa", lama); |
| | | laLaMap.put("minLa", lami); |
| | | |
| | | Double lo1 = lomi - length * 0.00001141; |
| | | Double lo2 = loma + length * 0.00001141; |
| | | Double la2 = lami - length * 0.00000899; |
| | | Double la1 = lama + length * 0.00000899; |
| | | |
| | | double dx = 0.00001141 * perdlen; |
| | | double dy = 0.00000899 * perdlen; |
| | | int nx = (int) Math.floor((lo2 - lo1) / dx); |
| | | int ny = (int) Math.floor((la1 - la2) / dy); |
| | | |
| | | |
| | | List<Double> uList = new ArrayList<>(); |
| | | List<Double> vList = new ArrayList<>(); |
| | | int x; |
| | | int y; |
| | | |
| | | for (int i = 0; i < mapList.size(); i++) { |
| | | Double lo = (Double) mapList.get(i).get("lo"); |
| | | Double la = (Double) mapList.get(i).get("la"); |
| | | x = (int) Math.floor((lo - lo1) / dx); |
| | | y = Math.abs((int) Math.floor((la - la1) / dy)); |
| | | U = (Double) mapList.get(i).get("U"); |
| | | V = (Double) mapList.get(i).get("V"); |
| | | if (i == 0) { |
| | | for (int j = 0; j < nx * ny; j++) { |
| | | uList.add(0.0); |
| | | vList.add(0.0); |
| | | } |
| | | } |
| | | for (int j = 0; j < nx * ny; j++) { |
| | | if (i == 0) { |
| | | if ((y >= 2 && j == (y) * nx + x)) { |
| | | int k; |
| | | for (k = j - 2 * nx; k <= j + 2 * nx; k = k + nx) { |
| | | uList.set(k, U); |
| | | uList.set(k - 1, U); |
| | | uList.set(k - 2, U); |
| | | uList.set(k + 1, U); |
| | | uList.set(k + 2, U); |
| | | vList.set(k, V); |
| | | vList.set(k - 1, V); |
| | | vList.set(k - 2, V); |
| | | vList.set(k + 1, V); |
| | | vList.set(k + 2, V); |
| | | } |
| | | } |
| | | } else { |
| | | if (y >= 1 && j == y * nx + x) { |
| | | int k; |
| | | for (k = j - 2 * nx; k <= j + 2 * nx; ) { |
| | | uList.set(k - 1, U); |
| | | uList.set(k - 2, U); |
| | | uList.set(k + 1, U); |
| | | uList.set(k + 2, U); |
| | | vList.set(k - 1, V); |
| | | vList.set(k - 2, V); |
| | | vList.set(k + 1, V); |
| | | vList.set(k + 2, V); |
| | | k = k + nx; |
| | | } |
| | | uList.set(j, U); |
| | | vList.set(j, V); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | String uData = "\"" + "data" + "\"" + ": " + uList; |
| | | String vData = "\"" + "data" + "\"" + ": " + vList; |
| | | |
| | | String header1 = "\"" + "header" + "\"" + ": " + "{" + "\"" + "parameterUnit" + "\"" + ": " + "\"" + "m/s" + "\"" + ", " + "\"" + "parameterNumber" + "\"" + ": " + 2 + |
| | | ", " + "\"" + "dx" + "\"" + ": " + dx + ", " + "\"" + "dy" + "\"" + ": " + dy + |
| | | ", " + "\"" + "parameterNumberName" + "\"" + ": " + "\"" + "eastward_wind" + "\"" + ", " + "\"" + "la1" + "\"" + ": " + la1 + ", " + "\"" + "la2" + "\"" + ": " + la2 + |
| | | ", " + "\"" + "parameterCategory" + "\"" + ": " + 2 + ", " + "\"" + "lo1" + "\"" + ": " + lo1 + ", " + "\"" + "lo2" + "\"" + ": " + lo2 + |
| | | ", " + "\"" + "nx" + "\"" + ": " + nx + ", " + "\"" + "ny" + "\"" + ": " + ny + ", " + "\"" + "refTime" + "\"" + ": " + "\"" + "2020-07-22 23:00:00" + "\"" + "}"; |
| | | |
| | | String header2 = "\"" + "header" + "\"" + ": " + "{" + "\"" + "parameterUnit" + "\"" + ": " + "\"" + "m/s" + "\"" + ", " + "\"" + "parameterNumber" + "\"" + ": " + 3 + |
| | | ", " + "\"" + "dx" + "\"" + ": " + dx + ", " + "\"" + "dy" + "\"" + ": " + dy + |
| | | ", " + "\"" + "parameterNumberName" + "\"" + ": " + "\"" + "eastward_wind" + "\"" + ", " + "\"" + "la1" + "\"" + ": " + la1 + ", " + "\"" + "la2" + "\"" + ": " + la2 + |
| | | ", " + "\"" + "parameterCategory" + "\"" + ": " + 2 + ", " + "\"" + "lo1" + "\"" + ": " + lo1 + ", " + "\"" + "lo2" + "\"" + ": " + lo2 + |
| | | ", " + "\"" + "nx" + "\"" + ": " + nx + ", " + "\"" + "ny" + "\"" + ": " + ny + ", " + "\"" + "refTime" + "\"" + ": " + "\"" + "2020-07-22 23:00:00" + "\"" + "}"; |
| | | |
| | | |
| | | String s1 = "[" + "{" + header1 + ", " + uData + "}" + ", " + "{" + header2 + ", " + vData + "}" + "]"; |
| | | JSONArray jsonArray = JSONArray.parseArray(s1); |
| | | |
| | | list.add(jsonArray); |
| | | list.add(centerPoint.get("lng")); |
| | | list.add(centerPoint.get("lat")); |
| | | list.add(laLaMap); |
| | | return list; |
| | | } |
| | | } |
New file |
| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import com.moral.api.entity.HistoryMonthly; |
| | | import com.moral.api.mapper.HistoryMonthlyMapper; |
| | | import com.moral.api.service.HistoryMonthlyService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | /** |
| | | * <p> |
| | | * 月数据 服务实现类 |
| | | * </p> |
| | | * |
| | | * @author moral |
| | | * @since 2021-07-20 |
| | | */ |
| | | @Service |
| | | public class HistoryMonthlyServiceImpl extends ServiceImpl<HistoryMonthlyMapper, HistoryMonthly> implements HistoryMonthlyService { |
| | | |
| | | } |
| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.moral.api.entity.Menu; |
| | | import com.moral.api.entity.MonitorPoint; |
| | | import com.moral.api.entity.SysArea; |
| | | import com.moral.api.mapper.MonitorPointMapper; |
| | | import com.moral.api.mapper.SysAreaMapper; |
| | | import com.moral.api.service.SysAreaService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.constant.Constants; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Comparator; |
| | | import java.util.HashSet; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class SysAreaServiceImpl extends ServiceImpl<SysAreaMapper, SysArea> implements SysAreaService { |
| | | |
| | | @Autowired |
| | | private SysAreaMapper sysAreaMapper; |
| | | |
| | | @Autowired |
| | | private MonitorPointMapper monitorPointMapper; |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getMapPath(Integer orgId) { |
| | | //根据组织id查询所有站点 |
| | | QueryWrapper<MonitorPoint> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.select("province_code", "city_code", "area_code") |
| | | .eq("organization_id", orgId) |
| | | .eq("is_delete", Constants.NOT_DELETE); |
| | | List<MonitorPoint> monitorPoints = monitorPointMapper.selectList(queryWrapper); |
| | | Set<Integer> cityCodes = new HashSet<>(); |
| | | for (MonitorPoint monitorPoint : monitorPoints) { |
| | | cityCodes.add(monitorPoint.getProvinceCode()); |
| | | cityCodes.add(monitorPoint.getCityCode()); |
| | | cityCodes.add(monitorPoint.getAreaCode()); |
| | | } |
| | | |
| | | QueryWrapper<SysArea> sysAreaQueryWrapper = new QueryWrapper<>(); |
| | | sysAreaQueryWrapper.select("area_code", "area_name", "parent_code").in("area_code", cityCodes); |
| | | List<SysArea> allAreas = sysAreaMapper.selectList(sysAreaQueryWrapper); |
| | | |
| | | //第一级城市 |
| | | List<SysArea> oneSysArea = allAreas.stream() |
| | | .filter(o -> o.getParentCode().equals(0)) |
| | | .sorted(Comparator.comparing(SysArea::getAreaCode)) |
| | | .collect(Collectors.toList()); |
| | | |
| | | List<Map<String, Object>> newList = new ArrayList<>(); |
| | | //遍历一级菜单 |
| | | oneSysArea.forEach(o -> { |
| | | Map<String, Object> sysAreaMap = new LinkedHashMap<>(); |
| | | sysAreaMap.put("provinceCode", o.getAreaCode()); |
| | | sysAreaMap.put("provinceName", o.getAreaName()); |
| | | sysAreaMap.put("cities", getAreasByRecursion(o, allAreas)); |
| | | newList.add(sysAreaMap); |
| | | }); |
| | | return newList; |
| | | } |
| | | |
| | | //获取用户层级菜单递归方法 |
| | | private List<Map<String, Object>> getAreasByRecursion(SysArea sysArea, List<SysArea> sysAreas) { |
| | | SysArea newSysArea = new SysArea(); |
| | | newSysArea.setParentCode(sysArea.getAreaCode()); |
| | | //筛选出下一级城市信息 |
| | | List<SysArea> nextLevel = sysAreas.stream() |
| | | .filter(o -> o.getParentCode().equals(sysArea.getAreaCode())) |
| | | .collect(Collectors.toList()); |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | |
| | | if (nextLevel.size() > 0) { |
| | | nextLevel.forEach(o -> { |
| | | Map<String, Object> sysMap = new LinkedHashMap<>(); |
| | | if (o.getAreaCode().toString().endsWith("00")) { |
| | | sysMap.put("cityCode", o.getAreaCode()); |
| | | sysMap.put("cityName", o.getAreaName()); |
| | | sysMap.put("provinceCode", o.getParentCode()); |
| | | sysMap.put("areas", getAreasByRecursion(o, sysAreas)); |
| | | } else { |
| | | sysMap.put("areaCode", o.getAreaCode()); |
| | | sysMap.put("areaName", o.getAreaName()); |
| | | sysMap.put("cityCode", o.getParentCode()); |
| | | } |
| | | list.add(sysMap); |
| | | }); |
| | | } |
| | | return list; |
| | | } |
| | | } |
| | |
| | | nextLevelMenus.forEach(o -> { |
| | | Map<String, Object> menuMap = new LinkedHashMap<>(); |
| | | menuMap.put("id", o.getId()); |
| | | menuMap.put("name", o.getName()); |
| | | menuMap.put("label", o.getName()); |
| | | menuMap.put("url", o.getUrl()); |
| | | menuMap.put("icon", o.getIcon()); |
| | | //调用递归体 |
| | | menuMap.put("child", getMenusByRecursion(o, menus)); |
| | | menuMap.put("children", getMenusByRecursion(o, menus)); |
| | | list.add(menuMap); |
| | | }); |
| | | } |
| | |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.moral.api.mapper.DeviceMapper"> |
| | | |
| | | <!-- 通用查询映射结果 --> |
| | | <resultMap id="BaseResultMap" type="com.moral.api.entity.Device"> |
| | | <id column="id" property="id" /> |
| | | <result column="name" property="name" /> |
| | | <result column="mac" property="mac" /> |
| | | <result column="address" property="address" /> |
| | | <result column="longitude" property="longitude" /> |
| | | <result column="latitude" property="latitude" /> |
| | | <result column="state" property="state" /> |
| | | <result column="operate_ids" property="operateIds" /> |
| | | <result column="monitor_point_id" property="monitorPointId" /> |
| | | <result column="organization_id" property="organizationId" /> |
| | | <result column="device_version_id" property="deviceVersionId" /> |
| | | <result column="profession" property="profession" /> |
| | | <result column="tech" property="tech" /> |
| | | <result column="detector" property="detector" /> |
| | | <result column="purchaser" property="purchaser" /> |
| | | <result column="create_time" property="createTime" /> |
| | | <result column="update_time" property="updateTime" /> |
| | | <result column="install_time" property="installTime" /> |
| | | <result column="is_delete" property="isDelete" /> |
| | | <result column="extend" property="extend" /> |
| | | </resultMap> |
| | | <!-- 通用查询映射结果 --> |
| | | <resultMap id="BaseResultMap" type="com.moral.api.entity.Device"> |
| | | <id column="id" property="id"/> |
| | | <result column="name" property="name"/> |
| | | <result column="mac" property="mac"/> |
| | | <result column="address" property="address"/> |
| | | <result column="longitude" property="longitude"/> |
| | | <result column="latitude" property="latitude"/> |
| | | <result column="state" property="state"/> |
| | | <result column="operate_ids" property="operateIds"/> |
| | | <result column="monitor_point_id" property="monitorPointId"/> |
| | | <result column="organization_id" property="organizationId"/> |
| | | <result column="device_version_id" property="deviceVersionId"/> |
| | | <result column="profession" property="profession"/> |
| | | <result column="tech" property="tech"/> |
| | | <result column="detector" property="detector"/> |
| | | <result column="purchaser" property="purchaser"/> |
| | | <result column="create_time" property="createTime"/> |
| | | <result column="update_time" property="updateTime"/> |
| | | <result column="install_time" property="installTime"/> |
| | | <result column="is_delete" property="isDelete"/> |
| | | <result column="extend" property="extend"/> |
| | | </resultMap> |
| | | |
| | | <!--监测因子趋势图数据--> |
| | | <select id="getTrendChartData" resultType="java.util.Map"> |
| | | SELECT |
| | | DATE_FORMAT(`time`,#{dateFormat}) AS `time`, |
| | | `value`->'$.${sensorCode}' AS '${sensorCode}' |
| | | FROM history_${timeUnits} |
| | | WHERE mac = #{mac} |
| | | AND `time` <![CDATA[>=]]> #{start} |
| | | AND `time` <![CDATA[<]]> #{end} |
| | | ORDER BY `time` |
| | | </select> |
| | | </mapper> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.moral.api.mapper.HistoryFiveMinutelyMapper"> |
| | | |
| | | <!--获取5分钟风场数据--> |
| | | <select id="getAreaWindData" resultType="com.moral.api.pojo.dto.Wind.WindData"> |
| | | SELECT |
| | | d.longitude AS longitude, |
| | | d.latitude AS latitude, |
| | | CASE WHEN |
| | | h.value->'$.a01007' = 0 THEN 0.1 ELSE h.value->'$.a01007' END AS windSpeed, |
| | | h.value->'$.a01008' AS windDir |
| | | FROM history_five_minutely_${timeUnits} h , |
| | | `device` AS d |
| | | WHERE d.mac = h.mac |
| | | AND d.mac IN |
| | | (SELECT mac FROM device WHERE monitor_point_id IN |
| | | <foreach item="monitorPointId" collection="monitorPointIds" index="index" open="(" separator="," close=")"> |
| | | #{monitorPointId} |
| | | </foreach> |
| | | ) |
| | | AND h.time = (SELECT max(time) FROM history_five_minutely_${timeUnits}) |
| | | </select> |
| | | |
| | | </mapper> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.moral.api.mapper.HistoryMonthlyMapper"> |
| | | |
| | | <!-- 通用查询映射结果 --> |
| | | <resultMap id="BaseResultMap" type="com.moral.api.entity.HistoryMonthly"> |
| | | <result column="mac" property="mac"/> |
| | | <result column="time" property="time"/> |
| | | <result column="value" property="value"/> |
| | | </resultMap> |
| | | |
| | | </mapper> |
| | |
| | | |
| | | public class DateUtils { |
| | | /** |
| | | * 日期格式(yyyy) |
| | | */ |
| | | public static final String yyyy = "yyyy"; |
| | | /** |
| | | * 日期格式(yyyy-MM-dd) |
| | | */ |
| | | public static final String yyyy_MM_dd_EN = "yyyy-MM-dd"; |
| | |
| | | * @param days |
| | | * @return |
| | | */ |
| | | public static String getDateAddDay(String date, int days, String format) { |
| | | DateFormat df = getDateFormat(format); |
| | | public static String getDateAddDay(String date, int days) { |
| | | DateFormat df = getDateFormat(yyyy_MM_dd_EN); |
| | | try { |
| | | Calendar cal = Calendar.getInstance(); |
| | | cal.setTime(df.parse(date)); |
| | |
| | | * @return |
| | | */ |
| | | public static String getDateAddMonth(String date, int m) { |
| | | DateFormat df = getDateFormat(yyyyMM_EN); |
| | | DateFormat df = getDateFormat(yyyy_MM_EN); |
| | | try { |
| | | Calendar cal = Calendar.getInstance(); |
| | | cal.setTime(df.parse(date)); |
| | |
| | | return getDate(dateToDateString(calendar.getTime(), yyyy_MM_dd_EN)); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | System.out.println(getFirstDayOfCurrMonth()); |
| | | |
| | | /*获取指定年后年*/ |
| | | public static String getDateAddYear(String date, int year) { |
| | | DateFormat df = getDateFormat(yyyy); |
| | | try { |
| | | Calendar cal = Calendar.getInstance(); |
| | | cal.setTime(df.parse(date)); |
| | | cal.add(Calendar.YEAR, year); |
| | | date = df.format(cal.getTime()); |
| | | } catch (ParseException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | return date; |
| | | } |
| | | } |