5 files added
11 files modified
| | |
| | | import java.util.List; |
| | | |
| | | public class ReportTimeFormat { |
| | | // 保持mysql format格式和java里format格式一致 |
| | | public final static String YEAR_FORMAT = "yyyy"; |
| | | public final static String MONTH_FORMAT = "yyyy-MM"; |
| | | public final static String DAY_FORMAT = "yyyy-MM-dd"; |
| | | public final static String HOUR_FORMAT = "yyyy-MM-dd/HH"; |
| | | public final static String MINUTE_FORMAT = "yyyy-MM-dd/HH:mm"; |
| | | public final static String YEAR_FORMAT_OF_MYSQL = "%Y"; |
| | | public final static String MONTH_FORMAT_OF_MYSQL = "%Y-%m"; |
| | | public final static String DAY_FORMAT_OF_MYSQL = "%Y-%m-%d"; |
| | | public final static String HOUR_FORMAT_OF_MYSQL = "%Y-%m-%d/%H"; |
| | | public final static String MINUTE_FORMAT_OF_MYSQL = "%Y-%m-%d/%H:%i"; |
| | | public static String toMySqlTimeFormat(TimeUnits timeUnits){ |
| | | switch (timeUnits){ |
| | | case YEAR: return "%Y"; |
| | | case MONTH: return "%Y-%m"; |
| | | case DAY: return "%Y-%m-%d"; |
| | | case HOUR: return "%Y-%m-%d/%H"; |
| | | case MINUTE:return "%Y-%m-%d/%H:%i"; |
| | | case YEAR: return YEAR_FORMAT_OF_MYSQL; |
| | | case MONTH: return MONTH_FORMAT_OF_MYSQL; |
| | | case DAY: return DAY_FORMAT_OF_MYSQL; |
| | | case HOUR: return HOUR_FORMAT_OF_MYSQL; |
| | | case MINUTE:return MINUTE_FORMAT_OF_MYSQL; |
| | | } |
| | | return "%Y-%m-%d%H:%i:%s"; |
| | | } |
| | |
| | | } |
| | | return "%s"; |
| | | } |
| | | |
| | | /** |
| | | * 获取 时间区间数组 从小到大 |
| | | * @param timePeriod |
| | | * @return |
| | | */ |
| | | public static List<String> makeTimeList(TimePeriod timePeriod){ |
| | | Calendar start = Calendar.getInstance(); |
| | | start.setTime(timePeriod.getStartTime()); |
| | |
| | | String formatStyle = ""; |
| | | int timeUnit = 0; |
| | | switch (timePeriod.getTimeUnits()){ |
| | | case YEAR: formatStyle ="yyyy"; |
| | | case YEAR: formatStyle = YEAR_FORMAT; |
| | | timeUnit = Calendar.YEAR;break; |
| | | case MONTH: formatStyle ="yyyy-MM"; |
| | | case MONTH: formatStyle =MONTH_FORMAT; |
| | | timeUnit = Calendar.MONTH;break; |
| | | case DAY: formatStyle ="yyyy-MM-dd"; |
| | | case DAY: formatStyle =DAY_FORMAT; |
| | | timeUnit = Calendar.DAY_OF_YEAR;break; |
| | | case HOUR: formatStyle ="yyyy-MM-dd/HH"; |
| | | case HOUR: formatStyle =HOUR_FORMAT; |
| | | timeUnit = Calendar.HOUR;break; |
| | | case MINUTE: formatStyle ="yyyy-MM-dd/HH:mm"; |
| | | case MINUTE: formatStyle =MINUTE_FORMAT; |
| | | timeUnit = Calendar.MINUTE;break; |
| | | } |
| | | do{ |
| | |
| | | while (start.getTimeInMillis()<end.getTimeInMillis()); |
| | | return timeList; |
| | | } |
| | | |
| | | /** |
| | | * 时间计算方法 |
| | | * @param date 待计算方法 |
| | | * @param timeUnits 处理单位,年,月,日,时,分 |
| | | * @param amount 差值,负数为减,正数为加 |
| | | * @return |
| | | */ |
| | | public static Date dateCalc(Date date,TimeUnits timeUnits,Integer amount) { |
| | | Calendar rightNow = Calendar.getInstance(); |
| | | rightNow.setTime(date); |
| | | rightNow.add(toCalendarTimeUnit(timeUnits), amount); |
| | | return rightNow.getTime(); |
| | | } |
| | | private static int toCalendarTimeUnit(TimeUnits timeUnits) { |
| | | switch (timeUnits) { |
| | | case YEAR: return Calendar.YEAR; |
| | | case MONTH: return Calendar.MONTH; |
| | | case DAY: return Calendar.DAY_OF_YEAR; |
| | | case HOUR: return Calendar.HOUR; |
| | | default: return Calendar.MINUTE; |
| | | } |
| | | } |
| | | /**"yyyy-MM-dd hh:mm:ss" |
| | | * 把指定的date类型时间转换为指定格式的字符串 |
| | | * @param date |
| | |
| | | Object orgId = resultMap.get("orgId");
|
| | | if(resultMap.get("orgId")!=null && resultMap.get("orgId") instanceof Integer) {
|
| | | StringBuilder areaNamesBuilder = new StringBuilder("中国");
|
| | | if((Integer) orgId != dictionaryDataService.querySupperOrgId()) {
|
| | | if(!((Integer) orgId).equals(dictionaryDataService.querySupperOrgId())) {
|
| | | Organization organization = organizationService.getOrganizationById((Integer) orgId);
|
| | | if(organization.getAreaNames()!=null){
|
| | | AreaNames areaNames = organization.getAreaNames();
|
| | |
| | | MonitorPoint monitorPoint = monitorPointService.queryMonitorPointById(monitorPointId);
|
| | | return new ResultBean<>(monitorPoint);
|
| | | }
|
| | | @Resource
|
| | | HangzhouAqiService hangzhouAqiService;
|
| | | @GetMapping("aqi24hours")
|
| | | @ApiOperation(value = "最近24小时aqi数值", notes = "最近24小时国控aqi数值")
|
| | | @ApiImplicitParams(value = {
|
| | | @ApiImplicitParam(name = "orgid",defaultValue = "5",value = "组织id", required = true, paramType = "query", dataType = "Integer"),
|
| | | })
|
| | | public ResultBean<List<Map>> getAqi24HoursNC(@RequestParam("orgid") Integer organizationId) {
|
| | | return new ResultBean<>(hangzhouAqiService.queryAqi24Hours(organizationId));
|
| | | }
|
| | | @GetMapping("mpt-dev-summary")
|
| | | @ApiOperation(value = "监控总数和设备状态信息", notes = "监控总数和设备状态信息")
|
| | | @ApiImplicitParams(value = {
|
| | | @ApiImplicitParam(name = "orgid",defaultValue = "5",value = "组织id", required = true, paramType = "query", dataType = "Integer"),
|
| | | })
|
| | | public ResultBean<Map> getMptAndDevSummary(@RequestParam("orgid") Integer organizationId){
|
| | | Map<String,Map> result = new HashMap<>(2);
|
| | | Integer mptCount = monitorPointService.countOfSubOrgs(organizationId);
|
| | | Map monitorPointSummary = new HashMap();
|
| | | monitorPointSummary.put("all",mptCount);
|
| | | Map deviceSummary = deviceService.queryDeviceStateSummary(organizationId);
|
| | | result.put("monitorPoint",monitorPointSummary);
|
| | | result.put("device",deviceSummary);
|
| | | return new ResultBean<>(result);
|
| | | }
|
| | | }
|
New file |
| | |
| | | package com.moral.entity; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.util.Date; |
| | | |
| | | @Data |
| | | public class HangzhouAqi { |
| | | private Date time; |
| | | |
| | | private Object aqiJson; |
| | | |
| | | private String cityCode; |
| | | |
| | | public Date getTime() { |
| | | return time; |
| | | } |
| | | } |
| | |
| | | |
| | | @Data |
| | | public class TimePeriod { |
| | | public TimePeriod (Date startTime,Date endTime,TimeUnits timeUnits) |
| | | { |
| | | this.startTime = startTime; |
| | | this.endTime = endTime; |
| | | this.timeUnits = timeUnits; |
| | | } |
| | | private TimeUnits timeUnits;//区间单位 |
| | | private Date startTime;//开始时间 |
| | | private Date endTime;//结束时间 |
| | |
| | | |
| | | public interface DictionaryDataMapper extends BaseMapper<DictionaryData> { |
| | | public Integer selectSupperOrgId(); |
| | | public boolean isSupperOrgId(Integer orgId); |
| | | } |
New file |
| | |
| | | package com.moral.mapper; |
| | | |
| | | import com.moral.common.mapper.BaseMapper; |
| | | import com.moral.entity.HangzhouAqi; |
| | | import com.moral.entity.charts.TimePeriod; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | public interface HangzhouAqiMapper extends BaseMapper<HangzhouAqi> { |
| | | public List<Map> selectAqisByCodeAndTimePeriod(@Param("code")String code,@Param("timePeriod") TimePeriod timePeriod); |
| | | } |
| | |
| | | public interface OrganizationMapper extends BaseMapper<Organization> {
|
| | | List<Organization> selectWithAreaNameByExample(Example example);
|
| | | List<Organization> getOrganizationsByAreaName(Map<String, Object> parameters);
|
| | |
|
| | | /**
|
| | | * 所有下级组织,包括自己id,自己id位置在0
|
| | | * @param orgId
|
| | | * @return
|
| | | */
|
| | | List<Integer> selectLowerOrgIds(Integer orgId);
|
| | | } |
| | |
| | | List<Device> getDevicesByProfessionId(Map<String, Object> parameters);
|
| | |
|
| | | List<Device> getDevicesByOrganizationId(Map<String, Object> parameters);
|
| | |
|
| | | Map<String,Long> queryDeviceStateSummary(Integer orgId);
|
| | | }
|
New file |
| | |
| | | package com.moral.service; |
| | | |
| | | import javax.validation.constraints.NotNull; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @Auther: fengxiang |
| | | * @Date: 2018/8/24 10:30 |
| | | * @Description: 国控api服务接口 |
| | | */ |
| | | public interface HangzhouAqiService { |
| | | public List<Map> queryAqi24Hours(@NotNull Integer orgId); |
| | | } |
| | |
| | | List<MonitorPoint> getMonitorPointsByName(String name);
|
| | | List<Map<String,String>> queryMonitroPointsState(List<Integer> idList);
|
| | |
|
| | | Integer countOfSubOrgs(Integer orgId);
|
| | |
|
| | | List<MonitorPoint> getMonitorPointsByOrganizationId(Integer orgId);
|
| | |
|
| | | List<MonitorPoint> getMonitorPointsByRegion(Map<String, Object> parameters);
|
| | |
| | | import java.util.stream.Collectors;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import javax.validation.constraints.NotNull;
|
| | |
|
| | | import com.alibaba.fastjson.TypeReference;
|
| | | import com.github.pagehelper.Page;
|
| | |
| | | import com.moral.common.util.ExampleUtil;
|
| | | import com.moral.common.util.RedisUtils;
|
| | | import com.moral.entity.DeviceVersion;
|
| | | import com.moral.mapper.DeviceVersionMapper;
|
| | | import com.moral.mapper.MonitorPointMapper;
|
| | | import com.moral.mapper.OrganizationMapper;
|
| | | import com.moral.mapper.*;
|
| | | import org.apache.commons.collections.MapUtils;
|
| | | import org.apache.commons.lang3.BooleanUtils;
|
| | | import org.apache.commons.lang3.StringUtils;
|
| | |
| | | import com.github.pagehelper.PageHelper;
|
| | | import com.moral.common.util.ValidateUtil;
|
| | | import com.moral.entity.Device;
|
| | | import com.moral.mapper.DeviceMapper;
|
| | | import com.moral.service.AccountService;
|
| | | import com.moral.service.DeviceService;
|
| | | import tk.mybatis.mapper.entity.Example;
|
| | |
| | | DeviceVersionMapper deviceVersionMapper;
|
| | | @Resource
|
| | | RedisUtils redisUtils;
|
| | | @Resource
|
| | | OrganizationMapper organizationMapper;
|
| | | @Resource
|
| | | DictionaryDataMapper dictionaryDataMapper;
|
| | | @Override
|
| | | public Map<String, Object> getDeviceStatesByAccount(Map<String, Object> parameters) {
|
| | | ValidateUtil.notNull(parameters.get("accountId"), "param.is.null");
|
| | |
| | | ValidateUtil.notNull(parameters.get("organizationId"), "param.is.null");
|
| | | return deviceMapper.getDevicesByOrganizationId(parameters);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Map<String,Long> queryDeviceStateSummary(@NotNull Integer orgId){
|
| | | Map<String,Object> params = new HashMap<>();
|
| | | if(!dictionaryDataMapper.isSupperOrgId(orgId)){
|
| | | List<Integer> orgIds = organizationMapper.selectLowerOrgIds(orgId);
|
| | | params.put("orgIds",orgIds);
|
| | | }
|
| | | List<Map<String, Object>> list = deviceMapper.getDeviceStatesByAccount(params);
|
| | | Long all = 0L, normal = 0L, abnormal = 0L, stop = 0L;
|
| | | for (Map<String, Object> map : list) {
|
| | | Long count = (Long) map.get("count");
|
| | | all += count;
|
| | | switch (Integer.valueOf((String) map.get("state"))) {
|
| | | case 0:
|
| | | normal = count;
|
| | | break;
|
| | | case 4:
|
| | | stop = count;
|
| | | break;
|
| | | default:
|
| | | abnormal += count;
|
| | | }
|
| | | }
|
| | | Map<String,Long> result = new HashMap<>();
|
| | | result.put("all", all);
|
| | | result.put("normal", normal);
|
| | | result.put("abnormal", abnormal);
|
| | | result.put("stop", stop);
|
| | | return result;
|
| | | }
|
| | | }
|
New file |
| | |
| | | package com.moral.service.impl; |
| | | |
| | | import com.moral.common.exception.BusinessException; |
| | | import com.moral.common.util.ReportTimeFormat; |
| | | import com.moral.entity.Organization; |
| | | import com.moral.entity.charts.TimePeriod; |
| | | import com.moral.entity.charts.TimeUnits; |
| | | import com.moral.mapper.HangzhouAqiMapper; |
| | | import com.moral.mapper.OrganizationMapper; |
| | | import com.moral.service.HangzhouAqiService; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @Auther: fengxiang |
| | | * @Date: 2018/8/24 10:32 |
| | | * @Description:国控api服务实现类 |
| | | */ |
| | | @Service |
| | | public class HangzhouAqiServiceImpl implements HangzhouAqiService{ |
| | | @Resource |
| | | private OrganizationMapper organizationMapper; |
| | | @Resource |
| | | private HangzhouAqiMapper hangzhouAqiMapper; |
| | | /** |
| | | * 根据组织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) { |
| | | List<Map> aqi24HoursValues = new ArrayList<>(24); |
| | | Date start = ReportTimeFormat.dateCalc(new Date(), TimeUnits.HOUR,-24); |
| | | Date end = new Date(); |
| | | 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); |
| | | List<String> timeList = ReportTimeFormat.makeTimeList(timePeriod); |
| | | if(aqis!=null && aqis.size()==0 && !isGetCity) { |
| | | return queryAqi24Hours(orgId,true); |
| | | } |
| | | int mTemp = 0; |
| | | for(int n =0;n<timeList.size();n++) { |
| | | String time = timeList.get(n); |
| | | Object aqiValue = null; |
| | | for(int m =mTemp;m<aqis.size();m++) { |
| | | Map<String,Object> rowData = aqis.get(m); |
| | | Object dbTime = rowData.get("time"); |
| | | if(time.equals(dbTime)){ |
| | | mTemp = m+1; |
| | | aqiValue = rowData.get("aqi"); |
| | | } |
| | | } |
| | | Map<String,Object> aqiItem = new HashMap<>(); |
| | | aqiItem.put("time",time); |
| | | aqiValue = aqiValue!=null?Float.valueOf(aqiValue.toString().replace("\"","")):null; |
| | | aqiItem.put("aqi",aqiValue); |
| | | aqi24HoursValues.add(aqiItem); |
| | | } |
| | | return aqi24HoursValues; |
| | | } |
| | | private Integer getCode(Integer orgId,boolean isGetCityCode) |
| | | { |
| | | Organization org = organizationMapper.selectByPrimaryKey(orgId); |
| | | if(isGetCityCode) { |
| | | return org.getCityCode(); |
| | | }else{ |
| | | return org.getAreaCode()!=null? org.getAreaCode() : org.getCityCode(); |
| | | } |
| | | } |
| | | } |
| | |
| | | import java.util.stream.Collectors;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import javax.validation.constraints.NotNull;
|
| | |
|
| | | import com.moral.mapper.DictionaryDataMapper;
|
| | | import com.moral.mapper.OrganizationMapper;
|
| | | import org.apache.commons.collections.CollectionUtils;
|
| | |
| | | public PageBean queryByPageBean(PageBean pageBean) {
|
| | | Example example = ExampleUtil.generateExample(ENTITY_CLASS,pageBean);
|
| | | List<Example.Criteria> criteriaList = example.getOredCriteria();
|
| | | if(criteriaList!=null&&criteriaList.size()>0){
|
| | | for(Example.Criteria cri : criteriaList){
|
| | | cri.andNotEqualTo("isDelete", Constants.IS_DELETE_TRUE);
|
| | | }
|
| | | }else {
|
| | | example.or().andNotEqualTo("isDelete",Constants.IS_DELETE_TRUE);
|
| | | }
|
| | | PageHelper.startPage(pageBean.getPageIndex(),pageBean.getPageSize());
|
| | | List<MonitorPoint> monitorPointList = monitorPointMapper.selectWithAreaNameByExample(example);
|
| | | return new PageBean(monitorPointList);
|
| | |
| | | return list;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取所属组织的监控点总数
|
| | | * @param orgId
|
| | | * @return
|
| | | */
|
| | | @Override
|
| | | public Integer countOfSubOrgs(@NotNull Integer orgId){
|
| | | Example example = new Example(ENTITY_CLASS);
|
| | | //过滤超级管理员账号
|
| | | if(!dictionaryDataMapper.isSupperOrgId(orgId)){
|
| | | List<Integer> orgIds = orgMapper.selectLowerOrgIds(orgId);
|
| | | example.or().andIn("organizationId",orgIds);
|
| | | }
|
| | | return monitorPointMapper.selectCountByExample(example);
|
| | | }
|
| | | @Override
|
| | | public List<MonitorPoint> getMonitorPointsByOrganizationId(Integer orgId) {
|
| | | Example example = new Example(MonitorPoint.class);
|
| | |
| | | id, dict_id, dict_data_key, dict_data_name, dict_data_value, is_fixed, is_delete, |
| | | parent_id, description |
| | | </sql> |
| | | <select id="selectSupperOrgId" parameterType="java.lang.String" resultType="java.lang.Integer"> |
| | | <select id="selectSupperOrgId" resultType="java.lang.Integer"> |
| | | select dict_data_value from dictionary_data |
| | | where dict_data_key = 'auth_config_super_org' |
| | | </select> |
| | | <select id="isSupperOrgId" resultType="java.lang.Boolean"> |
| | | select count(*) from dictionary_data |
| | | where dict_data_key = 'auth_config_super_org' and dict_data_value = #{orgId,jdbcType=INTEGER} |
| | | </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.mapper.HangzhouAqiMapper" > |
| | | <resultMap id="BaseResultMap" type="com.moral.entity.HangzhouAqi" > |
| | | <id column="time" property="time" jdbcType="TIMESTAMP" /> |
| | | <result column="aqi_json" property="aqiJson" jdbcType="OTHER" /> |
| | | <result column="city_code" property="cityCode" jdbcType="VARCHAR" /> |
| | | </resultMap> |
| | | <sql id="Base_Column_List" > |
| | | time, aqi_json, city_code |
| | | </sql> |
| | | <!--<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.util.Date" >--> |
| | | <!--select--> |
| | | <!--<include refid="Base_Column_List" />--> |
| | | <!--from hangzhou_aqi--> |
| | | <!--where time = #{time,jdbcType=TIMESTAMP}--> |
| | | <!--</select>--> |
| | | <select id="selectAqisByCodeAndTimePeriod" resultType="map" parameterType="java.util.Date" > |
| | | select |
| | | aqi_json->'$.AQI' as aqi,DATE_FORMAT(time,'${@com.moral.common.util.ReportTimeFormat@toMySqlTimeFormat(timePeriod.timeUnits)}') as 'time' |
| | | from hangzhou_aqi |
| | | where |
| | | ( |
| | | time >= #{timePeriod.startTime} |
| | | and time <![CDATA[<=]]> #{timePeriod.endTime} |
| | | ) |
| | | and |
| | | ( |
| | | city_code = #{code} |
| | | or |
| | | aqi_json->'$.city_code' = #{code} |
| | | ) |
| | | order by time asc |
| | | </select> |
| | | </mapper> |
| | |
| | | AND time < #{end}
|
| | | </select>
|
| | |
|
| | | <select id="getMonitorPointOrDeviceAvgData" resultType="java.util.LinkedHashMap">
|
| | | <select id="getMonitorPointOrDeviceAvgData" resultType="java.util.Map">
|
| | | SELECT
|
| | | DATE_FORMAT(time, #{typeFormat}) time
|
| | | <foreach collection="sensorKeys" open="," separator="," item="sensorKey">
|