Commit d4c7e947e91d04a3e778ba835e42811dbdc8a02b
1 parent
da807888
update...
Showing
8 changed files
with
273 additions
and
32 deletions
src/main/java/com/bsth/controller/realcontrol/anomalyCheckController.java
0 → 100644
| 1 | +package com.bsth.controller.realcontrol; | |
| 2 | + | |
| 3 | +import com.bsth.data.schedule.DayOfSchedule; | |
| 4 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 5 | +import org.slf4j.Logger; | |
| 6 | +import org.slf4j.LoggerFactory; | |
| 7 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 8 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 9 | +import org.springframework.web.bind.annotation.RequestMethod; | |
| 10 | +import org.springframework.web.bind.annotation.RequestParam; | |
| 11 | +import org.springframework.web.bind.annotation.RestController; | |
| 12 | + | |
| 13 | +import java.util.HashSet; | |
| 14 | +import java.util.List; | |
| 15 | +import java.util.Set; | |
| 16 | + | |
| 17 | +/** | |
| 18 | + * 相关数据异常检测 | |
| 19 | + * Created by panzhao on 2017/4/14. | |
| 20 | + */ | |
| 21 | +@RestController | |
| 22 | +@RequestMapping("anomalyCheck") | |
| 23 | +public class anomalyCheckController { | |
| 24 | + | |
| 25 | + | |
| 26 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 27 | + | |
| 28 | + @Autowired | |
| 29 | + DayOfSchedule dayOfSchedule; | |
| 30 | + /** | |
| 31 | + * 出现重复班次的车辆 | |
| 32 | + * @param nbbm | |
| 33 | + */ | |
| 34 | + @RequestMapping(value = "/schRepeat", method = RequestMethod.POST) | |
| 35 | + public void schRepeat(@RequestParam String nbbm){ | |
| 36 | + logger.info("前端通知,车辆 " + nbbm + "出现重复班次,开始检测..."); | |
| 37 | + List<ScheduleRealInfo> list = dayOfSchedule.findByNbbm(nbbm); | |
| 38 | + | |
| 39 | + Set<ScheduleRealInfo> set = new HashSet<>(); | |
| 40 | + for(ScheduleRealInfo sch : list){ | |
| 41 | + if(!set.add(sch)){ | |
| 42 | + logger.info("出现一次重复班次,班次ID:" + sch.getId()); | |
| 43 | + } | |
| 44 | + } | |
| 45 | + | |
| 46 | + if(set.size() > 0){ | |
| 47 | + dayOfSchedule.replaceByNbbm(nbbm, set); | |
| 48 | + } | |
| 49 | + } | |
| 50 | +} | ... | ... |
src/main/java/com/bsth/data/schedule/DayOfSchedule.java
| ... | ... | @@ -902,4 +902,16 @@ public class DayOfSchedule implements CommandLineRunner { |
| 902 | 902 | } |
| 903 | 903 | return rs; |
| 904 | 904 | } |
| 905 | + | |
| 906 | + /** | |
| 907 | + * 覆盖一辆车的所有班次 | |
| 908 | + * @param nbbm | |
| 909 | + * @param sets | |
| 910 | + */ | |
| 911 | + public void replaceByNbbm(String nbbm, Set<ScheduleRealInfo> sets){ | |
| 912 | + nbbmScheduleMap.removeAll(nbbm); | |
| 913 | + nbbmScheduleMap.putAll(nbbm, sets); | |
| 914 | + //重新计算班次应到时间 | |
| 915 | + updateQdzTimePlan(nbbm); | |
| 916 | + } | |
| 905 | 917 | } |
| 906 | 918 | \ No newline at end of file | ... | ... |
src/main/resources/fatso/handle_real_ctl.js
0 → 100644
| 1 | +/** | |
| 2 | + * 处理线调文件 | |
| 3 | + */ | |
| 4 | +var fs = require('fs') | |
| 5 | + ,cheerio = require('cheerio') | |
| 6 | + ,minifier = require('./minifier') | |
| 7 | + ,crypto = require("crypto") | |
| 8 | + ,CleanCSS = require('clean-css') | |
| 9 | + ,UglifyJS = require("uglify-js");; | |
| 10 | + | |
| 11 | +//不参与的目录 | |
| 12 | +var pName = 'bsth_control' | |
| 13 | + ,path = process.cwd() | |
| 14 | + //根目录 | |
| 15 | + ,root = path.substr(0, path.indexOf('\\src\\main')) | |
| 16 | + ,workspace = root.substr(0, root.indexOf('\\' + pName)) | |
| 17 | + //临时目录 | |
| 18 | + ,dest = (workspace + '\\' + pName+'@fatso_copy').replace(/\//g,'\\') | |
| 19 | + ,_static = '\\src\\main\\resources\\static'; | |
| 20 | + | |
| 21 | + | |
| 22 | +var mainFile = dest + _static + '\\real_control_v2\\main.html'; | |
| 23 | +var realCtl = { | |
| 24 | + /** | |
| 25 | + * 处理线调首页 | |
| 26 | + */ | |
| 27 | + handleMain: function(cb){ | |
| 28 | + //读取文件 | |
| 29 | + var data = fs.readFileSync(mainFile, 'utf-8') | |
| 30 | + ,$ = cheerio.load(data); | |
| 31 | + | |
| 32 | + handleCss($, function () { | |
| 33 | + handleJs($, cb); | |
| 34 | + }); | |
| 35 | + } | |
| 36 | +}; | |
| 37 | + | |
| 38 | +/** | |
| 39 | + * 处理css | |
| 40 | + * @type {any} | |
| 41 | + */ | |
| 42 | +var handleCss = function ($, cb) { | |
| 43 | + var cssArray = $('link[rel=stylesheet][merge]'); | |
| 44 | + //按 merge 值分组 | |
| 45 | + var cssMap = {}, mergeName; | |
| 46 | + for(var i = 0, c; c = cssArray[i++];){ | |
| 47 | + mergeName = $(c).attr('merge'); | |
| 48 | + if(!cssMap[mergeName]) | |
| 49 | + cssMap[mergeName] = []; | |
| 50 | + cssMap[mergeName].push(dest + _static + $(c).attr('href')); | |
| 51 | + //remove | |
| 52 | + $(c).remove(); | |
| 53 | + } | |
| 54 | + //按 merge 合并压缩css | |
| 55 | + var ks = get_keys(cssMap), index=0; | |
| 56 | + (function () { | |
| 57 | + if(index >= ks.length){ | |
| 58 | + cb && cb(); | |
| 59 | + return; | |
| 60 | + } | |
| 61 | + var k = ks[index]; | |
| 62 | + index ++; | |
| 63 | + var f = arguments.callee; | |
| 64 | + //合并css | |
| 65 | + new CleanCSS().minify(cssMap[k], function (error, out) { | |
| 66 | + var data = out.styles; | |
| 67 | + var fName = (k + '_' + md5(data)) + '.css'; | |
| 68 | + //写入 assets css 目录下 | |
| 69 | + var descFile = dest + _static + '\\real_control_v2\\assets\\css\\' + fName; | |
| 70 | + fs.open(descFile, 'a', function(err, fd){ | |
| 71 | + | |
| 72 | + fs.write(fd, data, function(){ | |
| 73 | + $('head').append('<link rel="stylesheet" href="/real_control_v2/assets/css/'+fName+'"/>'); | |
| 74 | + console.log(k + ' css', '结束,下一个'); | |
| 75 | + f(); | |
| 76 | + }); | |
| 77 | + }); | |
| 78 | + }); | |
| 79 | + })(); | |
| 80 | +}; | |
| 81 | + | |
| 82 | +/** | |
| 83 | + * 处理js | |
| 84 | + */ | |
| 85 | +var handleJs = function ($, cb) { | |
| 86 | + var scriptArray = $('script[merge]'); | |
| 87 | + //按 merge 值分组 | |
| 88 | + var jsMap = {}, mergeName; | |
| 89 | + for(var i = 0, s; s = scriptArray[i++];){ | |
| 90 | + mergeName = $(s).attr('merge'); | |
| 91 | + if(!jsMap[mergeName]) | |
| 92 | + jsMap[mergeName] = []; | |
| 93 | + jsMap[mergeName].push(dest + _static + $(s).attr('src')); | |
| 94 | + //remove | |
| 95 | + $(s).remove(); | |
| 96 | + } | |
| 97 | + | |
| 98 | + //按 merge 合并压缩js | |
| 99 | + var ks = get_keys(jsMap), index=0; | |
| 100 | + (function () { | |
| 101 | + if(index >= ks.length){ | |
| 102 | + write(mainFile, $.html()); | |
| 103 | + console.log('线调处理结束'.green); | |
| 104 | + cb && cb(); | |
| 105 | + return; | |
| 106 | + } | |
| 107 | + var k = ks[index]; | |
| 108 | + index ++; | |
| 109 | + var f = arguments.callee; | |
| 110 | + //合并压缩js | |
| 111 | + var result = UglifyJS.minify(jsMap[k]); | |
| 112 | + var data = result.code; | |
| 113 | + var fName = (k + '_' + md5(data)) + '.js'; | |
| 114 | + //写入 assets js 目录下 | |
| 115 | + var descFile = dest + _static + '\\real_control_v2\\assets\\js\\' + fName; | |
| 116 | + fs.open(descFile, 'a', function(err, fd){ | |
| 117 | + | |
| 118 | + fs.write(fd, data, function(){ | |
| 119 | + $('body').append('<script src="/real_control_v2/assets/js/'+fName+'"></script>'); | |
| 120 | + console.log(k + ' js', '结束,下一个'); | |
| 121 | + f(); | |
| 122 | + }); | |
| 123 | + }); | |
| 124 | + })(); | |
| 125 | +}; | |
| 126 | + | |
| 127 | +var get_keys = function (json) { | |
| 128 | + var array = []; | |
| 129 | + for (var key in json) { | |
| 130 | + array.push(key); | |
| 131 | + } | |
| 132 | + return array; | |
| 133 | +}; | |
| 134 | + | |
| 135 | +function md5(text){ | |
| 136 | + return crypto.createHash("md5").update(text).digest("hex"); | |
| 137 | +} | |
| 138 | + | |
| 139 | +function write(file, text){ | |
| 140 | + fs.writeFile(file, text, function (err) { | |
| 141 | + if (err){ | |
| 142 | + console.log(err.toString().red); | |
| 143 | + process.exit(); | |
| 144 | + } | |
| 145 | + console.log(file.green); | |
| 146 | + }); | |
| 147 | +} | |
| 148 | + | |
| 149 | + | |
| 150 | +module.exports = realCtl; | |
| 0 | 151 | \ No newline at end of file | ... | ... |
src/main/resources/fatso/package.json
| 1 | -{ | |
| 2 | - "name": "fatso", | |
| 3 | - "version": "1.0.0", | |
| 4 | - "description": "子页面js检查、合并、压缩等处理", | |
| 5 | - "main": "start.js", | |
| 6 | - "scripts": { | |
| 7 | - "test": "echo \"Error: no test specified\" && exit 1" | |
| 8 | - }, | |
| 9 | - "author": "panzhaov5", | |
| 10 | - "license": "ISC", | |
| 11 | - "dependencies": { | |
| 12 | - "cheerio": "^0.20.0", | |
| 13 | - "colors": "^1.1.2", | |
| 14 | - "eventproxy": "^0.3.4", | |
| 15 | - "uglify-js": "^2.6.2" | |
| 16 | - } | |
| 17 | -} | |
| 1 | +{ | |
| 2 | + "name": "fatso", | |
| 3 | + "version": "1.0.0", | |
| 4 | + "description": "子页面js检查、合并、压缩等处理", | |
| 5 | + "main": "start.js", | |
| 6 | + "scripts": { | |
| 7 | + "test": "echo \"Error: no test specified\" && exit 1" | |
| 8 | + }, | |
| 9 | + "author": "panzhaov5", | |
| 10 | + "license": "ISC", | |
| 11 | + "dependencies": { | |
| 12 | + "cheerio": "^0.20.0", | |
| 13 | + "clean-css": "^4.0.12", | |
| 14 | + "colors": "^1.1.2", | |
| 15 | + "eventproxy": "^0.3.4", | |
| 16 | + "uglify-js": "^2.6.2" | |
| 17 | + } | |
| 18 | +} | ... | ... |
src/main/resources/fatso/parse.js
src/main/resources/fatso/start.js
| ... | ... | @@ -8,7 +8,8 @@ var fs = require('fs') |
| 8 | 8 | ,EventProxy = require('eventproxy') |
| 9 | 9 | ,parse = require('./parse') |
| 10 | 10 | ,minifier = require('./minifier') |
| 11 | - ,crypto = require("crypto"); | |
| 11 | + ,crypto = require("crypto") | |
| 12 | + ,handle_real_ctl = require('./handle_real_ctl'); | |
| 12 | 13 | |
| 13 | 14 | //不参与的目录 |
| 14 | 15 | var excludes = ['scheduleApp', 'trafficManage', 'control'] |
| ... | ... | @@ -74,15 +75,18 @@ ep.tail('check-js', function(){ |
| 74 | 75 | //合并压缩JS |
| 75 | 76 | ep.tail('minifier-js', function(){ |
| 76 | 77 | logInfo('handle index.html...'); |
| 77 | - | |
| 78 | - //先处理首页 | |
| 78 | + | |
| 79 | + //再处理首页 | |
| 79 | 80 | ep.emit('handle-index', function(){ |
| 80 | 81 | //递归处理片段 |
| 81 | 82 | walk(dest + _static + '\\pages', function(item){ |
| 82 | 83 | ep.emit('handle-fragment', item); |
| 83 | 84 | }, |
| 84 | 85 | function(){ |
| 85 | - ep.emit('package-jar'); | |
| 86 | + //处理线调 | |
| 87 | + handle_real_ctl.handleMain(function () { | |
| 88 | + ep.emit('package-jar'); | |
| 89 | + }); | |
| 86 | 90 | }); |
| 87 | 91 | }); |
| 88 | 92 | }); | ... | ... |
src/main/resources/static/real_control_v2/js/line_schedule/sch_table.js
| ... | ... | @@ -11,6 +11,27 @@ var gb_schedule_table = (function () { |
| 11 | 11 | return s1.fcsjT - s2.fcsjT; |
| 12 | 12 | }; |
| 13 | 13 | |
| 14 | + /** | |
| 15 | + * 检查是否存在重复班次 | |
| 16 | + * @param list | |
| 17 | + */ | |
| 18 | + var isRepeatData = function (list) { | |
| 19 | + var map = {}, reps = []; | |
| 20 | + for(var i = 0,sch;sch=list[i++];){ | |
| 21 | + if(map[sch.id]){ | |
| 22 | + reps.push(sch.clZbh); | |
| 23 | + } | |
| 24 | + map[sch.id] = sch; | |
| 25 | + } | |
| 26 | + | |
| 27 | + //通知服务端数据有异常 | |
| 28 | + $.each(reps, function () { | |
| 29 | + $.post('/anomalyCheck/schRepeat', {nbbm: this}); | |
| 30 | + }); | |
| 31 | + | |
| 32 | + return gb_common.get_vals(map); | |
| 33 | + }; | |
| 34 | + | |
| 14 | 35 | var show = function (cb) { |
| 15 | 36 | //从服务器获取班次数据 |
| 16 | 37 | $.get('/realSchedule/lines', { |
| ... | ... | @@ -20,6 +41,9 @@ var gb_schedule_table = (function () { |
| 20 | 41 | //排序 |
| 21 | 42 | rs[lineCode].sort(schedule_sort); |
| 22 | 43 | line2Schedule[lineCode] = {}; |
| 44 | + //------是否有重复班次 #临时代码,为服务端提供诊断信息已解决这个问题 | |
| 45 | + rs[lineCode] = isRepeatData(line2Schedule[lineCode]); | |
| 46 | + | |
| 23 | 47 | //calc shift |
| 24 | 48 | $.each(rs[lineCode], function () { |
| 25 | 49 | calc_sch_real_shift(this); | ... | ... |
src/main/resources/static/real_control_v2/main.html
| ... | ... | @@ -32,7 +32,7 @@ |
| 32 | 32 | <link rel="stylesheet" href="/real_control_v2/assets/plugins/jstree/default/style.min.css"/> |
| 33 | 33 | <!-- tooltip css--> |
| 34 | 34 | <link rel="stylesheet" href="/real_control_v2/assets/plugins/qtip/jquery.qtip.min.css"/> |
| 35 | - <link rel="stylesheet" href="/real_control_v2/css/pace.css"/> | |
| 35 | + <link rel="stylesheet" href="/real_control_v2/css/pace.css" merge="custom_style"/> | |
| 36 | 36 | |
| 37 | 37 | <link rel="stylesheet" href="/real_control_v2/css/modal_extend.css" merge="custom_style"/> |
| 38 | 38 | </head> |
| ... | ... | @@ -100,9 +100,9 @@ |
| 100 | 100 | <!-- jquery --> |
| 101 | 101 | <script src="/real_control_v2/assets/js/jquery.min.js"></script> |
| 102 | 102 | <!-- jquery actual --> |
| 103 | -<script src="/real_control_v2/assets/js/jquery.actual.min.js"></script> | |
| 103 | +<script src="/real_control_v2/assets/js/jquery.actual.min.js" merge="plugins"></script> | |
| 104 | 104 | <!-- jquery.serializejson JSON序列化插件 --> |
| 105 | -<script src="/assets/plugins/jquery.serializejson.js"></script> | |
| 105 | +<script src="/assets/plugins/jquery.serializejson.js" merge="plugins"></script> | |
| 106 | 106 | <!-- moment.js 日期处理类库 --> |
| 107 | 107 | <script src="/assets/plugins/moment-with-locales.js"></script> |
| 108 | 108 | <!-- common js --> |
| ... | ... | @@ -126,18 +126,18 @@ |
| 126 | 126 | <script src="/real_control_v2/assets/plugins/uikit-2.27.1/components/lightbox.min.js" merge="uikit_js"></script> |
| 127 | 127 | |
| 128 | 128 | <!-- jquery contextMenu --> |
| 129 | -<script src="/real_control_v2/assets/js/jquery.contextMenu.min.js"></script> | |
| 130 | -<script src="/real_control_v2/assets/js/jquery.ui.position.min.js"></script> | |
| 129 | +<script src="/real_control_v2/assets/js/jquery.contextMenu.min.js" merge="plugins"></script> | |
| 130 | +<script src="/real_control_v2/assets/js/jquery.ui.position.min.js" merge="plugins"></script> | |
| 131 | 131 | <!-- formvalidation- --> |
| 132 | -<script src="/real_control_v2/assets/plugins/formvalidation/formValidation.min.js"></script> | |
| 133 | -<script src="/real_control_v2/assets/plugins/formvalidation/zh_CN.js"></script> | |
| 134 | -<script src="/real_control_v2/assets/plugins/formvalidation/uikit.min.js"></script> | |
| 132 | +<script src="/real_control_v2/assets/plugins/formvalidation/formValidation.min.js" merge="plugins"></script> | |
| 133 | +<script src="/real_control_v2/assets/plugins/formvalidation/zh_CN.js" merge="plugins"></script> | |
| 134 | +<script src="/real_control_v2/assets/plugins/formvalidation/uikit.min.js" merge="plugins"></script> | |
| 135 | 135 | <!-- js tree --> |
| 136 | -<script src="/real_control_v2/assets/plugins/jstree/jstree.min.js"></script> | |
| 136 | +<script src="/real_control_v2/assets/plugins/jstree/jstree.min.js" merge="plugins"></script> | |
| 137 | 137 | <!-- simple pinyin --> |
| 138 | 138 | <script src="/assets/plugins/pinyin.js"></script> |
| 139 | 139 | <!-- qtip --> |
| 140 | -<script src="/real_control_v2/assets/plugins/qtip/jquery.qtip.min.js"></script> | |
| 140 | +<script src="/real_control_v2/assets/plugins/qtip/jquery.qtip.min.js" merge="plugins"></script> | |
| 141 | 141 | |
| 142 | 142 | <!-- 数据 --> |
| 143 | 143 | <script src="/real_control_v2/js/data/data_basic.js" merge="custom_js"></script> | ... | ... |