| | |
| | | import com.moral.mapper.HangzhouAqiMapper; |
| | | import com.moral.mapper.OrganizationMapper; |
| | | import com.moral.service.HangzhouAqiService; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | private OrganizationMapper organizationMapper; |
| | | @Resource |
| | | private HangzhouAqiMapper hangzhouAqiMapper; |
| | | |
| | | public List<Map> queryAqiOfTimePeriod(String code,TimePeriod timePeriod) { |
| | | return hangzhouAqiMapper.selectAqisByCodeAndTimePeriod(code,timePeriod); |
| | | } |
| | | /** |
| | | * 根据组织id获取最近24小时国控aqi数据 |
| | | * @param orgId |
| | | * @return 返回长度为24的数组,查不到的数据设置为0 |
| | | */ |
| | | @Override |
| | | public List<Map> queryAqi24Hours(Integer orgId){ |
| | | return queryAqi24Hours(orgId,false); |
| | | } |
| | | private List<Map> queryAqi24Hours(Integer orgId,boolean isGetCity) { |
| | | public List<Map> queryAqi24Hours(Integer orgId) { |
| | | List<Map> aqi24HoursValues = new ArrayList<>(24); |
| | | Date now = ReportTimeFormat.getFormatDate(ReportTimeFormat.HOUR_FORMAT); |
| | | Date start = ReportTimeFormat.dateCalc(now, TimeUnits.HOUR,-24); |
| | | Date end = ReportTimeFormat.dateCalc(now, TimeUnits.MILLISECOND,-1);; |
| | | TimePeriod timePeriod = new TimePeriod(start,end,TimeUnits.HOUR); |
| | | Integer code = getCode(orgId,isGetCity); |
| | | if(code == null) { |
| | | throw new BusinessException("citeCode or areaCode is null;"); |
| | | } |
| | | List<Map> aqis = hangzhouAqiMapper.selectAqisByCodeAndTimePeriod(code.toString(),timePeriod); |
| | | Integer code = getCode(orgId,false); |
| | | List<Map> aqis = queryAqiOfTimePeriod(code.toString(),timePeriod); |
| | | List<String> timeList = ReportTimeFormat.makeTimeList(timePeriod); |
| | | if(aqis!=null && aqis.size()==0 && !isGetCity) { |
| | | return queryAqi24Hours(orgId,true); |
| | | if(CollectionUtils.isEmpty(aqis)) { |
| | | code = getCode(orgId,true); |
| | | aqis = queryAqiOfTimePeriod(code.toString(),timePeriod); |
| | | } |
| | | int mTemp = 0; |
| | | for(int n =0;n<timeList.size();n++) { |
| | |
| | | private Integer getCode(Integer orgId,boolean isGetCityCode) |
| | | { |
| | | Organization org = organizationMapper.selectByPrimaryKey(orgId); |
| | | Integer code = null; |
| | | if(isGetCityCode) { |
| | | return org.getCityCode(); |
| | | code = org.getCityCode(); |
| | | }else{ |
| | | return org.getAreaCode()!=null? org.getAreaCode() : org.getCityCode(); |
| | | code = org.getAreaCode(); |
| | | } |
| | | if(code == null) { |
| | | throw new BusinessException("citeCode or areaCode is null;"); |
| | | } |
| | | return code; |
| | | } |
| | | } |