Commit 57a5894fcce7f1a7cdc60b68b21d40cbb260951d
1 parent
ba65ac60
添加线路页面,路段编码验证修改
Showing
4 changed files
with
45 additions
and
9 deletions
src/main/java/com/bsth/controller/LineController.java
| @@ -47,6 +47,16 @@ public class LineController extends BaseController<Line, Integer> { | @@ -47,6 +47,16 @@ public class LineController extends BaseController<Line, Integer> { | ||
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | /** | 49 | /** |
| 50 | + * 验证线路编码是否存在 | ||
| 51 | + * | ||
| 52 | + * @return Map < {valid: true }:是否通过验证> | ||
| 53 | + */ | ||
| 54 | + @RequestMapping(value = "lineCodeVerification", method = RequestMethod.GET) | ||
| 55 | + public String lineCodeVerification(@RequestParam(defaultValue = "lineCode") String lineCode) { | ||
| 56 | + return service.lineCodeVerification(lineCode); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + /** | ||
| 50 | * | 60 | * |
| 51 | * 保存 | 61 | * 保存 |
| 52 | * | 62 | * |
| @@ -59,7 +69,7 @@ public class LineController extends BaseController<Line, Integer> { | @@ -59,7 +69,7 @@ public class LineController extends BaseController<Line, Integer> { | ||
| 59 | t.setId(Integer.valueOf(t.getLineCode())); | 69 | t.setId(Integer.valueOf(t.getLineCode())); |
| 60 | 70 | ||
| 61 | } | 71 | } |
| 62 | - if( (t.getId().toString().length()) > 6) { | 72 | + if( (t.getId().toString().length()) > 6 || service.lineCodeVerification(t.getLineCode()).equals("false") ) { |
| 63 | 73 | ||
| 64 | map.put("status", ResponseCode.ERROR); | 74 | map.put("status", ResponseCode.ERROR); |
| 65 | return map; | 75 | return map; |
src/main/java/com/bsth/service/LineService.java
| 1 | package com.bsth.service; | 1 | package com.bsth.service; |
| 2 | 2 | ||
| 3 | +import java.util.Map; | ||
| 4 | + | ||
| 3 | import org.springframework.web.bind.annotation.RequestMapping; | 5 | import org.springframework.web.bind.annotation.RequestMapping; |
| 4 | import org.springframework.web.bind.annotation.RequestMethod; | 6 | import org.springframework.web.bind.annotation.RequestMethod; |
| 5 | 7 | ||
| @@ -32,4 +34,6 @@ public interface LineService extends BaseService<Line, Integer> { | @@ -32,4 +34,6 @@ public interface LineService extends BaseService<Line, Integer> { | ||
| 32 | Line findByLineCode(String lineCode); | 34 | Line findByLineCode(String lineCode); |
| 33 | 35 | ||
| 34 | Line findById(Integer id); | 36 | Line findById(Integer id); |
| 37 | + | ||
| 38 | + String lineCodeVerification(String lineCode); | ||
| 35 | } | 39 | } |
src/main/java/com/bsth/service/impl/LineServiceImpl.java
| 1 | package com.bsth.service.impl; | 1 | package com.bsth.service.impl; |
| 2 | 2 | ||
| 3 | +import java.util.HashMap; | ||
| 4 | +import java.util.Map; | ||
| 5 | + | ||
| 3 | import org.springframework.beans.factory.annotation.Autowired; | 6 | import org.springframework.beans.factory.annotation.Autowired; |
| 4 | import org.springframework.stereotype.Service; | 7 | import org.springframework.stereotype.Service; |
| 5 | 8 | ||
| @@ -50,4 +53,14 @@ public class LineServiceImpl extends BaseServiceImpl<Line, Integer> implements L | @@ -50,4 +53,14 @@ public class LineServiceImpl extends BaseServiceImpl<Line, Integer> implements L | ||
| 50 | return repository.findOne(id); | 53 | return repository.findOne(id); |
| 51 | } | 54 | } |
| 52 | 55 | ||
| 56 | + @Override | ||
| 57 | + public String lineCodeVerification(String lineCode) { | ||
| 58 | + String state = "true"; | ||
| 59 | + Line line = repository.findByLineCode(lineCode); | ||
| 60 | + if(line != null){ | ||
| 61 | + state = "false"; | ||
| 62 | + } | ||
| 63 | + return state; | ||
| 64 | + } | ||
| 65 | + | ||
| 53 | } | 66 | } |
src/main/resources/static/pages/base/line/js/line-add-form.js
| @@ -94,7 +94,13 @@ $(function(){ | @@ -94,7 +94,13 @@ $(function(){ | ||
| 94 | // 需要验证的表单元素 | 94 | // 需要验证的表单元素 |
| 95 | rules : { | 95 | rules : { |
| 96 | 'name' : {required : true,maxlength: 30},// 线路名称 必填项、 最大长度. | 96 | 'name' : {required : true,maxlength: 30},// 线路名称 必填项、 最大长度. |
| 97 | - 'lineCode' : {required : true,maxlength: 6},// 线路编码 必填项、最大长度. | 97 | + 'lineCode' : {required : true,maxlength: 6,digits:true ,remote:{type: 'GET', |
| 98 | + url: '/line/lineCodeVerification', | ||
| 99 | + data:{'lineCode':function(){ return $("#lineCodeInput").val();}}, | ||
| 100 | + dataFilter: function (data,type) { | ||
| 101 | + return data; //要返回data 否则会影响到后续验证 并且阻碍提交【即使验证通过】,也不会提交 | ||
| 102 | + }, | ||
| 103 | + delay: 2000}},// 线路编码 必填项、最大长度. | ||
| 98 | 'company' : {required : true,maxlength: 30},// 所属公司 必填项、最大长度. | 104 | 'company' : {required : true,maxlength: 30},// 所属公司 必填项、最大长度. |
| 99 | 'brancheCompany' : {required : true,maxlength: 30},// 所属分公司 必填项、最大长度. | 105 | 'brancheCompany' : {required : true,maxlength: 30},// 所属分公司 必填项、最大长度. |
| 100 | 'level' : {required : true,maxlength: 30},// 线路等级 必填项、最大长度. | 106 | 'level' : {required : true,maxlength: 30},// 线路等级 必填项、最大长度. |
| @@ -119,7 +125,11 @@ $(function(){ | @@ -119,7 +125,11 @@ $(function(){ | ||
| 119 | 'history' : {maxlength: 200},// 线路沿革 输入长度最多是 200 的字符串(汉字算一个字符)。 | 125 | 'history' : {maxlength: 200},// 线路沿革 输入长度最多是 200 的字符串(汉字算一个字符)。 |
| 120 | 'descriptions' : {maxlength: 200}// 描述/说明 输入长度最多是 200 的字符串(汉字算一个字符)。 | 126 | 'descriptions' : {maxlength: 200}// 描述/说明 输入长度最多是 200 的字符串(汉字算一个字符)。 |
| 121 | }, | 127 | }, |
| 122 | - | 128 | + messages:{ |
| 129 | + 'lineCode':{ | ||
| 130 | + remote: '此线路编码已存在!' | ||
| 131 | + } | ||
| 132 | + }, | ||
| 123 | /** | 133 | /** |
| 124 | * 类型:Callback。当未通过验证的表单提交时,可以在该回调函数中处理一些事情。 | 134 | * 类型:Callback。当未通过验证的表单提交时,可以在该回调函数中处理一些事情。 |
| 125 | * | 135 | * |
| @@ -183,12 +193,12 @@ $(function(){ | @@ -183,12 +193,12 @@ $(function(){ | ||
| 183 | 193 | ||
| 184 | // 隐藏错误提示 | 194 | // 隐藏错误提示 |
| 185 | error.hide(); | 195 | error.hide(); |
| 186 | - | ||
| 187 | // 表单序列化 | 196 | // 表单序列化 |
| 188 | var params = form.serializeJSON(); | 197 | var params = form.serializeJSON(); |
| 198 | + submit(); | ||
| 189 | 199 | ||
| 190 | // 查询线路编码的顺延号 | 200 | // 查询线路编码的顺延号 |
| 191 | - $get('/line/all', {lineCode_eq: params.lineCode},function(lineCode){ | 201 | + /*$get('/line/all', {lineCode_eq: params.lineCode},function(lineCode){ |
| 192 | 202 | ||
| 193 | // 定义返回值的长度 | 203 | // 定义返回值的长度 |
| 194 | var len = lineCode.length; | 204 | var len = lineCode.length; |
| @@ -196,7 +206,7 @@ $(function(){ | @@ -196,7 +206,7 @@ $(function(){ | ||
| 196 | // 如果大于零,则已存在录入的线路编码;否则不存在 | 206 | // 如果大于零,则已存在录入的线路编码;否则不存在 |
| 197 | if(len > 0) { | 207 | if(len > 0) { |
| 198 | 208 | ||
| 199 | - /*// 定义已有的线路编码 | 209 | + // 定义已有的线路编码 |
| 200 | var oldCode = params.lineCode; | 210 | var oldCode = params.lineCode; |
| 201 | 211 | ||
| 202 | // 自动获取线路编码 | 212 | // 自动获取线路编码 |
| @@ -210,7 +220,7 @@ $(function(){ | @@ -210,7 +220,7 @@ $(function(){ | ||
| 210 | btn : [ '确认提示并提交', '取消' ] | 220 | btn : [ '确认提示并提交', '取消' ] |
| 211 | }, submit); | 221 | }, submit); |
| 212 | 222 | ||
| 213 | - });*/ | 223 | + }); |
| 214 | layer.open({ | 224 | layer.open({ |
| 215 | title: '消息提示' | 225 | title: '消息提示' |
| 216 | ,content: '线路编码【'+params.lineCode+'】已存在,请重新输入编码!' | 226 | ,content: '线路编码【'+params.lineCode+'】已存在,请重新输入编码!' |
| @@ -221,7 +231,7 @@ $(function(){ | @@ -221,7 +231,7 @@ $(function(){ | ||
| 221 | submit(); | 231 | submit(); |
| 222 | 232 | ||
| 223 | } | 233 | } |
| 224 | - }); | 234 | + });*/ |
| 225 | 235 | ||
| 226 | 236 | ||
| 227 | // 提交 | 237 | // 提交 |
| @@ -229,7 +239,6 @@ $(function(){ | @@ -229,7 +239,6 @@ $(function(){ | ||
| 229 | 239 | ||
| 230 | // 添加数据 | 240 | // 添加数据 |
| 231 | $post('/line', params, function(result) { | 241 | $post('/line', params, function(result) { |
| 232 | - | ||
| 233 | // 如果返回结果不为空 | 242 | // 如果返回结果不为空 |
| 234 | if(result){ | 243 | if(result){ |
| 235 | 244 |