| | |
| | | package com.moral.common.convert; |
| | | |
| | | import com.moral.common.exception.BusinessException; |
| | | import com.moral.common.util.StringUtils; |
| | | import org.apache.log4j.Logger; |
| | | import org.springframework.core.convert.converter.Converter; |
| | | |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | |
| | | * @version $Id: StringToDateConverter.java, v 0.1 2015年9月24日 下午7:19:41 byshome Exp $ |
| | | */ |
| | | public class StringToDateConverter implements Converter<String, Date> { |
| | | // private static final String dateFormat = "yyyy-MM-dd HH:mm:ss"; |
| | | Logger log = Logger.getLogger(StringToDateConverter.class); |
| | | private static final String dateFormat = "yyyy-MM-dd HH:mm:ss"; |
| | | // private static final String shortDateFormat = "yyyy-MM-dd"; |
| | | |
| | | private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat); |
| | | /** |
| | | * @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object) |
| | | */ |
| | | @Override |
| | | public Date convert(String source) { |
| | | if(StringUtils.isNullOrEmpty(source)){ |
| | | throw new RuntimeException(String.format("parser %s to Date fail", source)); |
| | | }; |
| | | return new Date(Long.parseLong(source)); |
| | | throw new BusinessException(String.format("parser %s to Date fail", source)); |
| | | } |
| | | if("null".equals(source)){ |
| | | return null; |
| | | } |
| | | if(StringUtils.isNumericZidai(source)){ |
| | | return new Date(Long.parseLong(source)); |
| | | } |
| | | try { |
| | | return simpleDateFormat.parse(source); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | log.error(e.getMessage()); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | } |
| | |
| | | sbuffer.append(suffix); |
| | | return sbuffer.toString(); |
| | | } |
| | | public static boolean isNumericZidai(String str) { |
| | | for (int i = 0; i < str.length(); i++) { |
| | | System.out.println(str.charAt(i)); |
| | | if (!Character.isDigit(str.charAt(i))) { |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | } |
| | |
| | | package com.moral.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.moral.common.bean.ResultBean; |
| | | import com.moral.entity.Alarm; |
| | | import com.moral.entity.Device; |
| | | import com.moral.entity.Sensor; |
| | | import com.moral.entity.alarm.AlarmConfig; |
| | | import com.moral.entity.alarm.AlarmConfigValue; |
| | | import com.moral.service.AlarmConfigService; |
| | | import com.moral.service.DeviceService; |
| | | import com.moral.service.HistoryService; |
| | | import com.moral.service.SensorService; |
| | | import com.moral.entity.charts.TimeUnits; |
| | | import com.moral.service.*; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.log4j.Logger; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | import javax.annotation.Resource; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | @RestController |
| | | @RequestMapping("alarm") |
| | |
| | | HistoryService historyService; |
| | | @Resource |
| | | AlarmConfigService alarmConfigService; |
| | | @Resource |
| | | AlarmService alarmService; |
| | | @RequestMapping(value = "/count-by-times", method = RequestMethod.GET) |
| | | public ResultBean<List<Map>> countByTimes(Date start, Date end,@RequestParam(value = "timeUnits")Optional<TimeUnits> timeUnits){ |
| | | return new ResultBean<>(alarmService.countByTimes(start,end,timeUnits.isPresent()?timeUnits.get():null)); |
| | | } |
| | | /** |
| | | * |
| | | * @param alarm |
| | |
| | | import com.moral.service.DeviceService; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | |
| | | public class DeviceController { |
| | | @Resource |
| | | DeviceService deviceService; |
| | | @GetMapping("count-by-example") |
| | | public ResultBean<Integer> countByExample(PageBean pageBean){ |
| | | return new ResultBean<Integer>(deviceService.countByExample(pageBean)); |
| | | } |
| | | @GetMapping("count-by-times") |
| | | public ResultBean<List<Map>> countByTimes(Date start, Date end){ |
| | | return new ResultBean<List<Map>>(deviceService.countByTimes(start,end,"%Y-%m")); |
| | | } |
| | | @GetMapping("page-list") |
| | | public PageBean pageList(PageBean pageBean) { |
| | | return deviceService.queryByPageBean(pageBean); |
| | |
| | | package com.moral.mapper;
|
| | |
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import com.moral.common.mapper.BaseMapper;
|
| | | import com.moral.entity.Alarm;
|
| | | import org.apache.ibatis.annotations.Param;
|
| | |
|
| | | public interface AlarmMapper extends BaseMapper<Alarm> {
|
| | |
|
| | | List<Map<String, Object>> getAlarmData(Map<String, Object> parameters);
|
| | |
|
| | | List<Map> countByTimes(@Param("start")Date start, @Param("end")Date end, @Param("format")String format);
|
| | | } |
| | |
| | | package com.moral.mapper;
|
| | |
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | |
| | | List<Device> selectByOrgIdAndMpId(@Param("orgId")Integer orgId,@Param("mpId")Integer mpId);
|
| | | List<Device> selectByMap(Map<String, Object> params);
|
| | | Device selectWithOrgIdsByMac(String mac);
|
| | | |
| | | List<Integer> getDeviceVersionIdByAreaCode(Map<String, Object> parameters);
|
| | |
|
| | | Integer getDeviceCountByRegion(Map<String, Object> parameters);
|
| | |
|
| | | List<Map> countByTimes(@Param("start")Date start,@Param("end")Date end,@Param("format")String format);
|
| | | } |
| | |
| | | package com.moral.service;
|
| | |
|
| | | import com.moral.entity.charts.TimeUnits;
|
| | |
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | @SuppressWarnings("rawtypes")
|
| | | public interface AlarmService {
|
| | |
|
| | | Map getPieData(Map<String, Object> parameters);
|
| | | List<Map> countByTimes(Date start, Date end, TimeUnits timeUnits);
|
| | |
|
| | | Map getPieData(Map<String, Object> parameters);
|
| | |
|
| | | }
|
| | |
| | | package com.moral.service;
|
| | |
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import com.moral.common.bean.PageBean;
|
| | |
| | |
|
| | | PageResult query(Integer orgId, Integer mpId, Integer pageSize, Integer pageNo);
|
| | |
|
| | | PageBean queryByPageBean(PageBean pageBean);
|
| | | int countByExample(PageBean pageBean);
|
| | |
|
| | | PageBean queryByPageBean(PageBean pageBean);
|
| | |
|
| | | void deleteByIds(Integer[] ids);
|
| | |
|
| | | void addOrModify(Device device);
|
| | |
|
| | | List<Map> countByTimes(Date start, Date end, String format);
|
| | |
|
| | | List<Device> getDevicesByMonitorPointId(Integer monitorPointId);
|
| | |
|
| | | List<Map<String,String>> queryDevicesState(List<String> macList,Boolean withData);
|
| | |
| | | package com.moral.service.impl;
|
| | |
|
| | | import java.text.ParseException;
|
| | | import java.util.ArrayList;
|
| | | import java.util.HashMap;
|
| | | import java.util.LinkedHashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.*;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import com.moral.entity.charts.TimeUnits;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.util.ObjectUtils;
|
| | |
|
| | |
| | |
|
| | | @Resource
|
| | | private HistoryMinutelyService historyMinutelyService;
|
| | | @Override
|
| | | public List<Map> countByTimes(Date start, Date end, TimeUnits timeUnits){
|
| | | String format = null;
|
| | | if(timeUnits!=null){
|
| | | switch (timeUnits){
|
| | | case MONTH: format = "%Y-%m";
|
| | | case DAY: format = "%Y-%m-%d";
|
| | | }
|
| | | }
|
| | |
|
| | | return alarmMapper.countByTimes(start, end, format);
|
| | | }
|
| | | @Override
|
| | | public Map getPieData(Map<String, Object> parameters) {
|
| | | Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
|
| | |
| | | import com.moral.common.bean.Constants;
|
| | | import com.moral.common.bean.PageBean;
|
| | | import com.moral.common.bean.PageResult;
|
| | | import com.moral.common.exception.BusinessException;
|
| | | import com.moral.common.util.ExampleUtil;
|
| | | import com.moral.common.util.RedisUtils;
|
| | | import com.moral.mapper.MonitorPointMapper;
|
| | | import org.apache.commons.collections.MapUtils;
|
| | | import org.apache.commons.lang3.BooleanUtils;
|
| | | import org.apache.commons.lang3.StringUtils;
|
| | | import org.apache.log4j.Logger;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import org.springframework.util.ObjectUtils;
|
| | |
| | |
|
| | | @Service
|
| | | public class DeviceServiceImpl implements DeviceService {
|
| | | Logger log = Logger.getLogger(DeviceServiceImpl.class);
|
| | | //-----------------------redis key前缀-开始---------------------------------
|
| | | private static String AlARM = "alarm";//警报阀值储存key前缀
|
| | | private static String ADJUST="adjust";//校准值存储key前缀
|
| | |
| | | }
|
| | | }
|
| | | @Override
|
| | | public PageBean queryByPageBean(PageBean pageBean) {
|
| | | public int countByExample(PageBean pageBean){
|
| | | Example example = ExampleUtil.generateExample(ENTITY_CLASS,pageBean);
|
| | | addDeletesToExample(example);
|
| | | return deviceMapper.selectCountByExample(example);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 增加删除条件过滤
|
| | | * @param example
|
| | | */
|
| | | private void addDeletesToExample(Example example){
|
| | | List<Example.Criteria> criteriaList = example.getOredCriteria();
|
| | | if(criteriaList!=null&&criteriaList.size()>0){
|
| | | for(Example.Criteria cri : criteriaList){
|
| | |
| | | }else {
|
| | | example.or().andNotEqualTo("isDelete",Constants.IS_DELETE_TRUE);
|
| | | }
|
| | | }
|
| | | @Override
|
| | | public PageBean queryByPageBean(PageBean pageBean) {
|
| | | Example example = ExampleUtil.generateExample(ENTITY_CLASS,pageBean);
|
| | | addDeletesToExample(example);
|
| | | if(pageBean.getPageSize()>0){
|
| | | PageHelper.startPage(pageBean.getPageIndex(),pageBean.getPageSize());
|
| | | }
|
| | |
| | | throw ex;
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<Map> countByTimes(Date start,Date end,String format){
|
| | | if(start==null||end==null||StringUtils.isBlank(format)){
|
| | | log.error("some params is null");
|
| | | throw new BusinessException("some params is null");
|
| | | }
|
| | | return deviceMapper.countByTimes(start, end, format);
|
| | | }
|
| | | @Override
|
| | | public List<Device> getDevicesByMonitorPointId(Integer monitorPointId) {
|
| | | Device device = new Device();
|
| | |
| | | </if>
|
| | |
|
| | | </select>
|
| | | |
| | | <select id="countByTimes" resultType="java.util.Map">
|
| | | select
|
| | | <if test="format !=null">
|
| | | DATE_FORMAT(time,#{format}) as time,
|
| | | </if>
|
| | | COUNT(*) as count from alarm
|
| | | <where>
|
| | | <if test="start != null">
|
| | | time >= #{start}
|
| | | </if>
|
| | | <if test="end != null">
|
| | | and time
|
| | | <![CDATA[
|
| | | <=
|
| | | ]]> #{end}
|
| | | </if>
|
| | | </where>
|
| | | <if test="format !=null">
|
| | | GROUP BY DATE_FORMAT(time,#{format}) ;
|
| | | </if>
|
| | | </select>
|
| | | </mapper> |
| | |
| | | id, name, address, longitude, latitude, mac, operate_user_id, state, is_delete, create_time, |
| | | install_time, monitor_point_id, device_version_id |
| | | </sql> |
| | | <select id="countByTimes" resultType="java.util.Map"> |
| | | select DATE_FORMAT(create_time,#{format}) as time, COUNT(*) as count from device |
| | | where create_time >= #{start} |
| | | and create_time |
| | | <![CDATA[ |
| | | <= |
| | | ]]> #{end} |
| | | and is_delete <![CDATA[ |
| | | <> |
| | | ]]> 1 |
| | | GROUP BY DATE_FORMAT(create_time,#{format}) ; |
| | | </select> |
| | | <select id="selectWithRelationData" parameterType="tk.mybatis.mapper.entity.Example" resultMap="BaseResultMap"> |
| | | select |
| | | dev.*, |