JinPengYong
2020-04-26 cda3fcb63a6cebb154a3770c4c6c288cd660d762
src/main/java/com/moral/service/impl/HangzhouAqiServiceImpl.java
@@ -25,24 +25,26 @@
 * @Description:国控api服务实现类
 */
@Service
public class HangzhouAqiServiceImpl implements HangzhouAqiService{
    @Resource
    private OrganizationMapper organizationMapper;
    @Resource
    private HangzhouAqiMapper hangzhouAqiMapper;
public class HangzhouAqiServiceImpl implements HangzhouAqiService {
  @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
     */
    @SuppressWarnings("serial")
   @Override
    public List<Map<String, Object>> queryAqi24Hours(Integer orgId) {
        List<Map<String, Object>> aqi24HoursValues = new ArrayList<>(24);
  public List<Map> queryAqiOfTimePeriod(String code, TimePeriod timePeriod) {
    return hangzhouAqiMapper.selectAqisByCodeAndTimePeriod(code, timePeriod);
  }
  /**
   * 根据组织id获取最近24小时国控aqi数据
   *
   * @param orgId
   * @return 返回长度为24的数组,查不到的数据设置为0
   */
  @SuppressWarnings("serial")
  @Override
  public List<Map<String, Object>> queryAqi24Hours(Integer orgId) {
    List<Map<String, Object>> aqi24HoursValues = new ArrayList<>(24);
/*
        Date now = ReportTimeFormat.getFormatDate(ReportTimeFormat.HOUR_FORMAT);
        Date start = ReportTimeFormat.dateCalc(now, TimeUnits.HOUR,-24);
@@ -73,33 +75,38 @@
            aqiItem.put("aqi",aqiValue);
            aqi24HoursValues.add(aqiItem);
        }
*/
        Organization organization = organizationMapper.selectByPrimaryKey(orgId);
*/
    Organization organization = organizationMapper.selectByPrimaryKey(orgId);
        Map<String, Object> parameters = new HashMap<String, Object>(){{
           put("end", LocalDateTime.now());
           put("cityCode", organization.getAreaCode());
        }};
        aqi24HoursValues = hangzhouAqiMapper.getAqisByOrganizationId(parameters);
        if (ObjectUtils.isEmpty(aqi24HoursValues)) {
           parameters.put("cityCode", organization.getCityCode());
           aqi24HoursValues = hangzhouAqiMapper.getAqisByOrganizationId(parameters);
      }
        Collections.reverse(aqi24HoursValues);
        return aqi24HoursValues;
    Map<String, Object> parameters = new HashMap<String, Object>() {{
      put("end", LocalDateTime.now());
      put("cityCode", organization.getAreaCode());
    }};
    aqi24HoursValues = hangzhouAqiMapper.getAqisByOrganizationId(parameters);
    if (ObjectUtils.isEmpty(aqi24HoursValues)) {
      parameters.put("cityCode", organization.getCityCode());
      aqi24HoursValues = hangzhouAqiMapper.getAqisByOrganizationId(parameters);
    }
    private Integer getCode(Integer orgId,boolean isGetCityCode)
    {
        Organization org = organizationMapper.selectByPrimaryKey(orgId);
        Integer code  = null;
        if(isGetCityCode) {
            code  =  org.getCityCode();
        }else{
            code  =  org.getAreaCode();
        }
        if(code == null) {
            throw new BusinessException("citeCode or areaCode is null;");
        }
        return  code;
    Collections.reverse(aqi24HoursValues);
    return aqi24HoursValues;
  }
  private Integer getCode(Integer orgId, boolean isGetCityCode) {
    Organization org = organizationMapper.selectByPrimaryKey(orgId);
    Integer code = null;
    if (isGetCityCode) {
      code = org.getCityCode();
    } else {
      code = org.getAreaCode();
    }
    if (code == null) {
      throw new BusinessException("citeCode or areaCode is null;");
    }
    return code;
  }
  @Override
  public Integer queryCityCode(Integer areaCode) {
    return  hangzhouAqiMapper.queryCityCode(areaCode);
  }
}