scheduleJobForm.jsp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. <%@ page contentType="text/html;charset=UTF-8" %>
  2. <%@ include file="/webpage/include/taglib.jsp"%>
  3. <html>
  4. <head>
  5. <title>定时任务管理</title>
  6. <meta name="decorator" content="ani"/>
  7. <script type="text/javascript">
  8. function isCronExpress(cronExpression){
  9. var cronParams = cronExpression.split(" ");
  10. if (cronParams.length < 6 || cronParams.length > 7) {
  11. return false;
  12. }
  13. //CronTrigger cronTrigger = new CronTrigger();
  14. //cronTrigger.setCronExpression( cronExpression );
  15. if (cronParams[3] == "?" || cronParams[5]=="?") {
  16. //Check seconds param
  17. if (!checkSecondsField(cronParams[0])) {
  18. return false;
  19. }
  20. //Check minutes param
  21. if (!checkMinutesField(cronParams[1])) {
  22. return false;
  23. }
  24. //Check hours param
  25. if (!checkHoursField(cronParams[2])) {
  26. return false;
  27. }
  28. //Check day-of-month param
  29. if (!checkDayOfMonthField(cronParams[3])) {
  30. return false;
  31. }
  32. //Check months param
  33. if (!checkMonthsField(cronParams[4])) {
  34. return false;
  35. }
  36. //Check day-of-week param
  37. if (!checkDayOfWeekField(cronParams[5])) {
  38. return false;
  39. }
  40. //Check year param
  41. if (cronParams.length == 7) {
  42. if (!checkYearField(cronParams[6])) {
  43. return false;
  44. }
  45. }
  46. return true;
  47. } else {
  48. return false;
  49. }
  50. }
  51. function checkSecondsField(secondsField) {
  52. return checkField(secondsField, 0, 59);
  53. }
  54. function checkField(secondsField, minimal, maximal) {
  55. if (secondsField.indexOf("-") > -1 ) {
  56. var startValue = secondsField.substring(0, secondsField.indexOf( "-" ));
  57. var endValue = secondsField.substring(secondsField.indexOf( "-" ) + 1);
  58. if (!(checkIntValue(startValue, minimal, maximal, true) && checkIntValue(endValue, minimal, maximal, true))) {
  59. return false;
  60. }
  61. try {
  62. var startVal = parseInt(startValue, 10);
  63. var endVal = parseInt(endValue, 10);
  64. return endVal > startVal;
  65. } catch (e) {
  66. return false;
  67. }
  68. } else if (secondsField.indexOf(",") > -1) {
  69. return checkListField(secondsField, minimal, maximal);
  70. } else if (secondsField.indexOf( "/" ) > -1) {
  71. return checkIncrementField( secondsField, minimal, maximal );
  72. } else if (secondsField.indexOf( "*" ) != -1) {
  73. return true;
  74. } else {
  75. return checkIntValue(secondsField, minimal, maximal);
  76. }
  77. }
  78. function checkIntValue(value, minimal, maximal, checkExtremity) {
  79. try {
  80. var val = parseInt(value, 10);
  81. //判断是否为整数
  82. if (value == val) {
  83. if (checkExtremity) {
  84. if (val < minimal || val > maximal) {
  85. return false;
  86. }
  87. }
  88. return true;
  89. }
  90. return false;
  91. } catch (e) {
  92. return false;
  93. }
  94. }
  95. function checkMinutesField(minutesField) {
  96. return checkField(minutesField, 0, 59);
  97. }
  98. function checkHoursField(hoursField) {
  99. return checkField(hoursField, 0, 23);
  100. }
  101. function checkDayOfMonthField(dayOfMonthField) {
  102. if (dayOfMonthField == "?") {
  103. return true;
  104. }
  105. if (dayOfMonthField.indexOf("L") >= 0) {
  106. return checkFieldWithLetter(dayOfMonthField, "L", 1, 7, -1, -1);
  107. } else if ( dayOfMonthField.indexOf("W") >= 0) {
  108. return checkFieldWithLetter(dayOfMonthField, "W", 1, 31, -1, -1);
  109. } else if (dayOfMonthField.indexOf("C") >= 0) {
  110. return checkFieldWithLetter(dayOfMonthField, "C", 1, 31, -1, -1);
  111. } else {
  112. return checkField( dayOfMonthField, 1, 31 );
  113. }
  114. }
  115. function checkMonthsField(monthsField) {
  116. /* monthsField = StringUtils.replace( monthsField, "JAN", "1" );
  117. monthsField = StringUtils.replace( monthsField, "FEB", "2" );
  118. monthsField = StringUtils.replace( monthsField, "MAR", "3" );
  119. monthsField = StringUtils.replace( monthsField, "APR", "4" );
  120. monthsField = StringUtils.replace( monthsField, "MAY", "5" );
  121. monthsField = StringUtils.replace( monthsField, "JUN", "6" );
  122. monthsField = StringUtils.replace( monthsField, "JUL", "7" );
  123. monthsField = StringUtils.replace( monthsField, "AUG", "8" );
  124. monthsField = StringUtils.replace( monthsField, "SEP", "9" );
  125. monthsField = StringUtils.replace( monthsField, "OCT", "10" );
  126. monthsField = StringUtils.replace( monthsField, "NOV", "11" );
  127. monthsField = StringUtils.replace( monthsField, "DEC", "12" );*/
  128. monthsField.replace("JAN", "1");
  129. monthsField.replace("FEB", "2");
  130. monthsField.replace("MAR", "3");
  131. monthsField.replace("APR", "4");
  132. monthsField.replace("MAY", "5");
  133. monthsField.replace("JUN", "6");
  134. monthsField.replace("JUL", "7");
  135. monthsField.replace("AUG", "8");
  136. monthsField.replace("SEP", "9");
  137. monthsField.replace("OCT", "10");
  138. monthsField.replace("NOV", "11");
  139. monthsField.replace("DEC", "12");
  140. return checkField(monthsField, 1, 31);
  141. }
  142. function checkDayOfWeekField(dayOfWeekField) {
  143. /* dayOfWeekField = StringUtils.replace( dayOfWeekField, "SUN", "1" );
  144. dayOfWeekField = StringUtils.replace( dayOfWeekField, "MON", "2" );
  145. dayOfWeekField = StringUtils.replace( dayOfWeekField, "TUE", "3" );
  146. dayOfWeekField = StringUtils.replace( dayOfWeekField, "WED", "4" );
  147. dayOfWeekField = StringUtils.replace( dayOfWeekField, "THU", "5" );
  148. dayOfWeekField = StringUtils.replace( dayOfWeekField, "FRI", "6" );
  149. dayOfWeekField = StringUtils.replace( dayOfWeekField, "SAT", "7" );*/
  150. dayOfWeekField.replace("SUN", "1" );
  151. dayOfWeekField.replace("MON", "2" );
  152. dayOfWeekField.replace("TUE", "3" );
  153. dayOfWeekField.replace("WED", "4" );
  154. dayOfWeekField.replace("THU", "5" );
  155. dayOfWeekField.replace("FRI", "6" );
  156. dayOfWeekField.replace("SAT", "7" );
  157. if (dayOfWeekField == "?") {
  158. return true;
  159. }
  160. if (dayOfWeekField.indexOf("L") >= 0) {
  161. return checkFieldWithLetter(dayOfWeekField, "L", 1, 7, -1, -1);
  162. } else if (dayOfWeekField.indexOf("C") >= 0) {
  163. return checkFieldWithLetter(dayOfWeekField, "C", 1, 7, -1, -1);
  164. } else if (dayOfWeekField.indexOf("#") >= 0) {
  165. return checkFieldWithLetter(dayOfWeekField, "#", 1, 7, 1, 5);
  166. } else {
  167. return checkField(dayOfWeekField, 1, 7);
  168. }
  169. }
  170. function checkYearField(yearField) {
  171. return checkField(yearField, 1970, 2099);
  172. }
  173. function checkFieldWithLetter(value, letter, minimalBefore, maximalBefore,
  174. minimalAfter, maximalAfter) {
  175. var canBeAlone = false;
  176. var canHaveIntBefore = false;
  177. var canHaveIntAfter = false;
  178. var mustHaveIntBefore = false;
  179. var mustHaveIntAfter = false;
  180. if (letter == "L") {
  181. canBeAlone = true;
  182. canHaveIntBefore = true;
  183. canHaveIntAfter = false;
  184. mustHaveIntBefore = false;
  185. mustHaveIntAfter = false;
  186. }
  187. if (letter == "W" || letter == "C") {
  188. canBeAlone = false;
  189. canHaveIntBefore = true;
  190. canHaveIntAfter = false;
  191. mustHaveIntBefore = true;
  192. mustHaveIntAfter = false;
  193. }
  194. if (letter == "#") {
  195. canBeAlone = false;
  196. canHaveIntBefore = true;
  197. canHaveIntAfter = true;
  198. mustHaveIntBefore = true;
  199. mustHaveIntAfter = true;
  200. }
  201. var beforeLetter = "";
  202. var afterLetter = "";
  203. if (value.indexOf(letter) >= 0 ) {
  204. beforeLetter = value.substring( 0, value.indexOf(letter));
  205. }
  206. if (!value.endsWith(letter)) {
  207. afterLetter = value.substring( value.indexOf( letter ) + 1 );
  208. }
  209. if (value.indexOf(letter) >= 0) {
  210. if (letter == value) {
  211. return canBeAlone;
  212. }
  213. if (canHaveIntBefore) {
  214. if (mustHaveIntBefore && beforeLetter.length == 0) {
  215. return false;
  216. }
  217. if (!checkIntValue(beforeLetter, minimalBefore, maximalBefore, true)){
  218. return false;
  219. }
  220. } else {
  221. if (beforeLetter.length > 0 ) {
  222. return false;
  223. }
  224. }
  225. if (canHaveIntAfter) {
  226. if ( mustHaveIntAfter && afterLetter.length == 0 ) {
  227. return false;
  228. }
  229. if (!checkIntValue(afterLetter, minimalAfter, maximalAfter, true)) {
  230. return false;
  231. }
  232. } else {
  233. if (afterLetter.length > 0) {
  234. return false;
  235. }
  236. }
  237. }
  238. return true;
  239. }
  240. /* function checkIntValue(value, minimal, maximal) {
  241. return checkIntValue(value, minimal, maximal, true);
  242. } */
  243. function checkIncrementField(value, minimal, maximal) {
  244. var start = value.substring(0, value.indexOf("/"));
  245. var increment = value.substring(value.indexOf("/") + 1);
  246. if (!("*" == start)) {
  247. return checkIntValue(start, minimal, maximal, true) && checkIntValue(increment, minimal, maximal, false);
  248. } else {
  249. return checkIntValue(increment, minimal, maximal, true);
  250. }
  251. }
  252. function checkListField(value, minimal, maximal ) {
  253. var st = value.split(",");
  254. var values = new Array(st.length);
  255. for(var j = 0; j < st.length; j++) {
  256. values[j] = st[j];
  257. }
  258. var previousValue = -1;
  259. for (var i= 0; i < values.length; i++) {
  260. var currentValue = values[i];
  261. if (!checkIntValue(currentValue, minimal, maximal, true)) {
  262. return false;
  263. }
  264. try {
  265. var val = parseInt(currentValue, 10);
  266. if (val <= previousValue) {
  267. return false;
  268. } else {
  269. previousValue = val;
  270. }
  271. } catch (e) {
  272. // we have always an int
  273. }
  274. }
  275. return true;
  276. }
  277. // cron表达式验证
  278. jQuery.validator.addMethod("isCronExpress", function(value, element) {
  279. return this.optional(element) || isCronExpress(value);
  280. }, "cron表达式不正确");
  281. $(document).ready(function() {
  282. $("#inputForm").validate({
  283. rules: {
  284. className: {remote: "${ctx}/monitor/scheduleJob/existsClass?" }
  285. },
  286. messages: {
  287. className: {remote: "任务类不存在!"}
  288. }
  289. });
  290. jp.ajaxForm("#inputForm",function(data){
  291. if(data.success){
  292. jp.toastr.success(data.msg);
  293. jp.go("${ctx}/monitor/scheduleJob");
  294. }else{
  295. jp.toastr.error(data.msg);
  296. }
  297. })
  298. });
  299. </script>
  300. </head>
  301. <body>
  302. <div class="wrapper wrapper-content">
  303. <div class="row">
  304. <div class="col-md-12">
  305. <div class="panel panel-primary">
  306. <div class="panel-heading">
  307. <h3 class="panel-title">
  308. <a class="panelButton" href="${ctx}/monitor/scheduleJob"><i class="ti-angle-left"></i> 返回</a>
  309. </h3>
  310. </div>
  311. <div class="panel-body">
  312. <form:form id="inputForm" modelAttribute="scheduleJob" action="${ctx}/monitor/scheduleJob/save" method="post" class="form-horizontal">
  313. <form:hidden path="id"/>
  314. <div class="form-group">
  315. <label class="col-sm-2 control-label"><font color="red">*</font>任务名:</label>
  316. <div class="col-sm-10">
  317. <form:input path="name" htmlEscape="false" class="form-control required"/>
  318. </div>
  319. </div>
  320. <div class="form-group">
  321. <label class="col-sm-2 control-label"><font color="red">*</font>任务组:</label>
  322. <div class="col-sm-10">
  323. <form:select path="group" class="form-control required">
  324. <form:option value="" label=""/>
  325. <form:options items="${fns:getDictList('schedule_task_group')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
  326. </form:select>
  327. </div>
  328. </div>
  329. <div class="form-group">
  330. <label class="col-sm-2 control-label"><font color="red">*</font>定时规则:</label>
  331. <div class="col-sm-10">
  332. <form:input path="cronExpression" htmlEscape="false" class="form-control required isCronExpress"/>
  333. <div style="margin-top: 10px;" class="alert alert-info alert-dismissable">
  334. <strong>Cron示例:</strong>前后不要有空格<br>
  335. &nbsp;*/5 * * * * ? 每隔5秒执行<br>
  336. &nbsp;0 */1 * * * ? 每隔1分钟执行<br>
  337. &nbsp;0 0 23 * * ? 每天23点执行<br>
  338. </div>
  339. </div>
  340. </div>
  341. <div class="form-group">
  342. <label class="col-sm-2 control-label"><font color="red">*</font>启用状态:</label>
  343. <div class="col-sm-10">
  344. <form:select path="status" class="form-control required">
  345. <form:option value="" label=""/>
  346. <form:options items="${fns:getDictList('yes_no')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
  347. </form:select>
  348. </div>
  349. </div>
  350. <div class="form-group">
  351. <label class="col-sm-2 control-label">事件触发时通知用户:</label>
  352. <div class="col-sm-10">
  353. <form:select path="isInfo" class="form-control ">
  354. <form:option value="" label=""/>
  355. <form:options items="${fns:getDictList('schedule_task_info')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
  356. </form:select>
  357. </div>
  358. </div>
  359. <div class="form-group">
  360. <label class="col-sm-2 control-label"><font color="red">*</font>任务类:</label>
  361. <div class="col-sm-10">
  362. <form:input path="className" htmlEscape="false" class="form-control required"/>
  363. </div>
  364. </div>
  365. <div class="form-group">
  366. <label class="col-sm-2 control-label">描述:</label>
  367. <div class="col-sm-10">
  368. <form:textarea path="description" htmlEscape="false" rows="4" class="form-control "/>
  369. </div>
  370. </div>
  371. <div class="col-lg-3"></div>
  372. <div class="col-lg-6">
  373. <div class="form-group text-center">
  374. <label></label>
  375. <div>
  376. <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
  377. </div>
  378. </div>
  379. </div>
  380. </form:form>
  381. </div>
  382. </div>
  383. </div>
  384. </div>
  385. </div>
  386. </body>
  387. </html>