fengxiang
2018-04-25 51f3652b96a09c150554ff8cbca7585e932235cd
微信页面详情 完善
1 files added
2 files modified
70 ■■■■■ changed files
src/main/java/com/moral/common/convert/StringToDateConverter.java 28 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/config/MvcConfiguration.java 23 ●●●●● patch | view | raw | blame | history
src/main/webapp/view/alarm/device-data.jsp 19 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/common/convert/StringToDateConverter.java
New file
@@ -0,0 +1,28 @@
package com.moral.common.convert;
import com.moral.common.util.StringUtils;
import org.springframework.core.convert.converter.Converter;
import java.util.Date;
/**
 * 字符串转日期的转换器
 * @author byshome
 * @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";
//    private static final String shortDateFormat = "yyyy-MM-dd";
    /**
     * @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));
    }
}
src/main/java/com/moral/config/MvcConfiguration.java
@@ -1,10 +1,17 @@
package com.moral.config;
import com.moral.common.convert.StringToDateConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import javax.annotation.PostConstruct;
@Configuration
@EnableWebMvc
@@ -21,4 +28,20 @@
            DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }
    @Autowired
    private RequestMappingHandlerAdapter handlerAdapter;
    /**
     * 增加字符串转日期的功能
     */
    @PostConstruct
    public void initEditableValidation() {
        ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) handlerAdapter
                .getWebBindingInitializer();
        if (initializer.getConversionService() != null) {
            GenericConversionService genericConversionService = (GenericConversionService) initializer
                    .getConversionService();
            genericConversionService.addConverter(new StringToDateConverter());
        }
    }
}
src/main/webapp/view/alarm/device-data.jsp
@@ -289,6 +289,16 @@
            .attr("dy", "1em")
            .text(function(d) { return d.subtitle; });
    }
    /**
     *
     * @param sortKeys 排序好的key数组
     * @param data  监控数据
     * @param sensors 设备明细
     * @param alarmData 报警数据
     * @param alarmLevels 报警阀值配置
     * @returns {Array}
     */
    function createBulletData(sortKeys,data,sensors,alarmData,alarmLevels) {
        var bullets = [];
        for(var index = 0; index<sortKeys.length;index++){
@@ -298,22 +308,22 @@
                    return value.sensorKey == sensorKey;
              });
            sensorLevel = alarmLevels[sensorKey];
            if(!sensor||!sensorLevel) break;
            if(!sensor) break;
            bullet.title = !!sensor["description"]?sensor["description"]:sensor.name;
            bullet.subtitle = sensor.unit;
            bullet.state = !!alarmData[sensorKey]?alarmData[sensorKey]:0;
            bullet.measures.push(data[sensorKey]);
            bullet.markers.push(data[sensorKey]);
            if(!!sensorLevel.enable){
                var start = 0;
            var start = 0;
            if(!!sensorLevel&&!!sensorLevel.enable){
                var ranges = sensorLevel.increment;
                if(!!sensorLevel.degressEnable){
                    var inFirst = sensorLevel.increment[0];
                    var deFirst = sensorLevel.degression[0];
                    start = (inFirst+deFirst)/2;
                    ranges = Math.abs(data[sensorKey]-inFirst) >  Math.abs(data[sensorKey]-deFirst) ? sensorLevel.degression:sensorLevel.increment;
                    bullet.startPoint = start;
                }
                bullet.startPoint = start;
                bullet.ranges = ranges;
            }else {
                var range = data[sensorKey]*10;
@@ -323,6 +333,7 @@
            }
            bullets.push(bullet);
        }
        console.log(bullets);
        return bullets;
    }
    // init page