6 files added
7 files modified
| | |
| | | // 全局配置 |
| | | GlobalConfig gc = new GlobalConfig(); |
| | | //String projectPath = System.getProperty("user.dir"); |
| | | String projectPath="C:\\Users\\cdl\\Desktop\\comProject\\newProject\\moral\\screen-api"; |
| | | String projectPath="D:\\gitproject\\newmoral\\screen-api"; |
| | | gc.setOutputDir(projectPath + "/src/main/java"); |
| | | gc.setAuthor("moral"); |
| | | gc.setOpen(false); |
| | |
| | | |
| | | // 数据源配置 |
| | | DataSourceConfig dsc = new DataSourceConfig(); |
| | | dsc.setUrl("jdbc:mysql://rm-bp1pr3rx9m3fnkwsk8o.mysql.rds.aliyuncs.com:3306/moral?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC"); |
| | | dsc.setUrl("jdbc:mysql://121.199.44.85:3306/moral?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC"); |
| | | //dsc.setUrl("jdbc:mysql://rm-bp1pr3rx9m3fnkwsk8o.mysql.rds.aliyuncs.com:3306/moral?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai"); |
| | | dsc.setDriverName("com.mysql.cj.jdbc.Driver"); |
| | | dsc.setUsername("root"); |
| | |
| | | import com.moral.api.service.CityAqiDailyService; |
| | | |
| | | import com.moral.api.service.CityAqiYearlyService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Required; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | 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 org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.*; |
| | | |
| | |
| | | return ResultMessage.ok(response); |
| | | } |
| | | |
| | | @GetMapping("compareO3New") |
| | | @ApiOperation(value = "预测和实测臭氧对比New", notes = "预测和实测臭氧对比New") |
| | | public ResultMessage compareO3New(@RequestParam @ApiParam(value = "regionCode",name = "城市code") String regionCode, |
| | | @RequestParam @ApiParam(value = "time",name = "日期") String time) { |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("regionCode",regionCode); |
| | | params.put("time",time); |
| | | List<Map<String, Object>> response = cityAqiService.measuredCompareForecastOfO3(params); |
| | | return ResultMessage.ok(response); |
| | | } |
| | | |
| | | @GetMapping("getO38H") |
| | | @ApiOperation(value = "预测和实测臭氧对比New", notes = "预测和实测臭氧对比New") |
| | | public ResultMessage getO38H(@RequestParam @ApiParam(value = "regionCode",name = "城市code") String regionCode, |
| | | @RequestParam @ApiParam(value = "time",name = "日期") String time) { |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("regionCode",regionCode); |
| | | params.put("time",time); |
| | | List<Map<String, Object>> response = cityAqiService.measuredCompareForecastOfO3_8H(params); |
| | | return ResultMessage.ok(response); |
| | | } |
| | | |
| | | /** |
| | | * @Description: 查询最新的6参和aqi数据 |
| | | * @Param: [regionCode] |
New file |
| | |
| | | package com.moral.api.controller; |
| | | |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.moral.api.entity.CityConfigAqi; |
| | | import com.moral.api.service.CityConfigAqiService; |
| | | import com.moral.constant.ResultMessage; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiParam; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @ClassName pubController |
| | | * @Description TODO |
| | | * @Author @lizijie |
| | | * @Date 2023-08-11 14:35 |
| | | * @Version 1.0 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/pub") |
| | | @CrossOrigin(origins = "*", maxAge = 3600) |
| | | @Api(tags = {"公共"}) |
| | | public class pubController { |
| | | @Autowired |
| | | private CityConfigAqiService cityConfigAqiService; |
| | | |
| | | @GetMapping("cityAll") |
| | | public ResultMessage airQualityBulletin(@RequestParam(required = false) @ApiParam(value = "regionCode",name = "城市code") String regionCode, |
| | | @RequestParam(required = false) @ApiParam(value = "regionName",name = "城市名称") String regionName) { |
| | | |
| | | List<CityConfigAqi> list = cityConfigAqiService.listAll(regionCode,regionName); |
| | | return ResultMessage.ok(list); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.moral.api.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.extension.activerecord.Model; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import java.io.Serializable; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | |
| | | /** |
| | | * <p> |
| | | * 城市配置表,用于从第三方接口获取数据 |
| | | * </p> |
| | | * |
| | | * @author moral |
| | | * @since 2023-08-11 |
| | | */ |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = false) |
| | | public class CityConfigAqi extends Model<CityConfigAqi> { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * 主键id |
| | | */ |
| | | @TableId(value = "id", type = IdType.AUTO) |
| | | private Integer id; |
| | | |
| | | /** |
| | | * 城市code |
| | | */ |
| | | private Integer cityCode; |
| | | |
| | | /** |
| | | * 城市名字 |
| | | */ |
| | | private String cityName; |
| | | |
| | | /** |
| | | * 从墨迹获取数据 |
| | | */ |
| | | private Integer cityId; |
| | | |
| | | /** |
| | | * 逻辑删除,0:不删除;1:删除 |
| | | */ |
| | | private String isDelete; |
| | | |
| | | |
| | | @Override |
| | | protected Serializable pkVal() { |
| | | return this.id; |
| | | } |
| | | |
| | | } |
| | |
| | | /* |
| | | |
| | | package com.moral.api.exception.consumer; |
| | | |
| | |
| | | import com.moral.constant.KafkaConstants; |
| | | |
| | | |
| | | */ |
| | | /* |
| | | * 走航车数据消费者 |
| | | * */ |
| | | * *//* |
| | | |
| | | |
| | | @Component |
| | | @Slf4j |
| | |
| | | } |
| | | } |
| | | |
| | | */ |
| | |
| | | /* |
| | | |
| | | package com.moral.api.exception.consumer; |
| | | |
| | |
| | | import java.util.concurrent.CopyOnWriteArraySet; |
| | | |
| | | |
| | | */ |
| | | /** |
| | | * @ClassName SecondsDataConsumer1 |
| | | * @Description TODO |
| | | * @Author 陈凯裕 |
| | | * @Date 2021/6/15 14:49 |
| | | * @Version TODO |
| | | **/ |
| | | **//* |
| | | |
| | | |
| | | @Component |
| | | @Slf4j |
| | |
| | | } |
| | | |
| | | |
| | | */ |
New file |
| | |
| | | package com.moral.api.mapper; |
| | | |
| | | import com.moral.api.entity.CityConfigAqi; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | |
| | | /** |
| | | * <p> |
| | | * 城市配置表,用于从第三方接口获取数据 Mapper 接口 |
| | | * </p> |
| | | * |
| | | * @author moral |
| | | * @since 2023-08-11 |
| | | */ |
| | | public interface CityConfigAqiMapper extends BaseMapper<CityConfigAqi> { |
| | | |
| | | } |
| | |
| | | //臭氧实测和预测对比 |
| | | List<Map<String, Object>> measuredCompareForecastOfO3(Map<String, Object> params); |
| | | |
| | | |
| | | List<Map<String, Object>> measuredCompareForecastOfO3_8H(Map<String, Object> params); |
| | | /** |
| | | * @Description: 根据地区码查询aqi以及6参 |
| | | * @Param: [regionCode] |
New file |
| | |
| | | package com.moral.api.service; |
| | | |
| | | import com.moral.api.entity.CityConfigAqi; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | | * 城市配置表,用于从第三方接口获取数据 服务类 |
| | | * </p> |
| | | * |
| | | * @author moral |
| | | * @since 2023-08-11 |
| | | */ |
| | | public interface CityConfigAqiService extends IService<CityConfigAqi> { |
| | | |
| | | List<CityConfigAqi> listAll(String regionCode,String regionName); |
| | | } |
| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import com.alibaba.excel.util.StringUtils; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> measuredCompareForecastOfO3_8H(Map<String, Object> params) { |
| | | String regionCode = params.get("regionCode").toString(); |
| | | String time = params.get("time").toString(); |
| | | Date endTime = DateUtils.getDate(time+" "+"23:00:00",DateUtils.yyyy_MM_dd_HH_mm_ss_EN); |
| | | Date startDate = DateUtils.getDate(time+" "+"00:00:00",DateUtils.yyyy_MM_dd_HH_mm_ss_EN); |
| | | Date startTime = DateUtils.addHours(startDate,-7); |
| | | //预测数据 |
| | | QueryWrapper<Forecast> forecastQueryWrapper = new QueryWrapper<>(); |
| | | forecastQueryWrapper.select("time", "value") |
| | | .eq("city_code", regionCode) |
| | | .between("time",startTime,endTime) |
| | | .orderByAsc("time"); |
| | | List<Map<String, Object>> forecastData = forecastMapper.selectMaps(forecastQueryWrapper); |
| | | //实测数据 |
| | | QueryWrapper<CityAqi> cityAqiQueryWrapper = new QueryWrapper<>(); |
| | | cityAqiQueryWrapper.select("time", "value") |
| | | .eq("city_code", regionCode) |
| | | .between("time",startTime,endTime).orderByAsc("time"); |
| | | List<Map<String, Object>> measuredData = cityAqiMapper.selectMaps(cityAqiQueryWrapper); |
| | | |
| | | List<Map<String, Object>> result = getO3_8H(forecastData,0,time); |
| | | result.addAll(getO3_8H(measuredData,1,time)); |
| | | return result; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Map<String, Object> queryCityAqiByRegionCode(Integer regionCode) { |
| | |
| | | } |
| | | return s; |
| | | } |
| | | |
| | | public List<Map<String, Object>> getO3_8H(List<Map<String, Object>> data , int type,String day) { |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | for(int i = 0 ;i<=23;i++){ |
| | | Map<String, Object> map = new HashMap<>(); |
| | | if(type == 0){ |
| | | map.put("type","预测"); |
| | | }else { |
| | | map.put("type","实测"); |
| | | } |
| | | String times = day+" "+i; |
| | | Date endDate = DateUtils.getDate(times,DateUtils.yyyy_MM_dd_HH_EN); |
| | | Date startDate = DateUtils.addHours(DateUtils.getDate(day+" "+i,DateUtils.yyyy_MM_dd_HH_EN),-7); |
| | | List<Double> value = new ArrayList<>(); |
| | | for(Map<String, Object> m : data){ |
| | | Date time = (Date) m.get("time"); |
| | | if(DateUtils.isTimeBeforE(time,startDate) && DateUtils.isTimeBeforE(endDate,time)){ |
| | | Map<String, Object> sensorValue = JSONObject.parseObject((String) m.get("value"), Map.class); |
| | | Double o3 = Double.parseDouble(sensorValue.get("O3").toString()); |
| | | value.add(o3); |
| | | |
| | | } |
| | | } |
| | | if (value.size() < 6) { |
| | | continue; |
| | | } |
| | | double average = value.stream().mapToDouble(aDouble -> aDouble).summaryStatistics().getAverage(); |
| | | map.put("O3", new BigDecimal(average).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue()); |
| | | map.put("time",times); |
| | | list.add(map); |
| | | } |
| | | |
| | | return list; |
| | | |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.moral.api.entity.CityConfigAqi; |
| | | import com.moral.api.mapper.CityConfigAqiMapper; |
| | | import com.moral.api.service.CityConfigAqiService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | | * 城市配置表,用于从第三方接口获取数据 服务实现类 |
| | | * </p> |
| | | * |
| | | * @author moral |
| | | * @since 2023-08-11 |
| | | */ |
| | | @Service |
| | | public class CityConfigAqiServiceImpl extends ServiceImpl<CityConfigAqiMapper, CityConfigAqi> implements CityConfigAqiService { |
| | | |
| | | @Override |
| | | public List<CityConfigAqi> listAll(String regionCode, String regionName) { |
| | | LambdaQueryChainWrapper<CityConfigAqi> wrapper = lambdaQuery(); |
| | | wrapper.eq(StringUtils.isNotEmpty(regionCode),CityConfigAqi::getCityCode,regionCode); |
| | | wrapper.like(StringUtils.isNotEmpty(regionName),CityConfigAqi::getCityName,regionName); |
| | | wrapper.eq(CityConfigAqi::getIsDelete,0); |
| | | wrapper.orderByAsc(CityConfigAqi::getCityCode,CityConfigAqi::getCityId); |
| | | return wrapper.list(); |
| | | } |
| | | } |
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.CityConfigAqiMapper"> |
| | | |
| | | <!-- 通用查询映射结果 --> |
| | | <resultMap id="BaseResultMap" type="com.moral.api.entity.CityConfigAqi"> |
| | | <id column="id" property="id" /> |
| | | <result column="city_code" property="cityCode" /> |
| | | <result column="city_name" property="cityName" /> |
| | | <result column="city_id" property="cityId" /> |
| | | <result column="is_delete" property="isDelete" /> |
| | | </resultMap> |
| | | |
| | | </mapper> |
| | |
| | | } |
| | | } |
| | | |
| | | public static boolean isTimeBeforE(Date nows, Date date) { |
| | | long hous = nows.getTime() - date.getTime(); |
| | | if (hous >= 0) { |
| | | return true; |
| | | } else { |
| | | return false; |
| | | } |
| | | } |
| | | /** |
| | | * 将小时数换算成返回以毫秒为单位的时间 |
| | | * |