当前位置:网站首页>On the escape of inequality value
On the escape of inequality value
2022-06-26 18:45:00 【51CTO】
Recently I met a need , Front end filling inequality , The back end needs to be stored , It is necessary to translate the inequality into the form of interval , Let's share some general solutions , For reference only .
One 、 Agree with the front end on the data format to be transmitted
The front page display is like this

The parameter transfer format agreed with the front end is
utilize @ Symbols separate symbols from version numbers , This symbol can also be used for subsequent stock in , There are multiple rules that can be passed to a string array , You can also pass comma separated strings
Two 、 Verify before warehousing
// Check the maximum and minimum version numbers of multiple rules
versionRangeList :
=
strings
.
Split(
body
.
VersionRange,
",")
switch
len(
versionRangeList) {
case
1:
version :
=
strings
.
Split(
versionRangeList[
0],
"@")
switch
version[
0] {
case
GT,
GE,
LT,
LE,
EQ,
NE:
// Normal rule
default:
return
tracerr
.
NewError(
" The rules are illegal , Parameter transfer exception :"
+
versionRangeList[
0])
}
case
2:
version1 :
=
strings
.
Split(
versionRangeList[
0],
"@")
version2 :
=
strings
.
Split(
versionRangeList[
1],
"@")
switch
version1[
0] {
case
GT,
GE:
if
version1[
1]
>=
version2[
1]
|| (
version2[
0]
!=
LT
&&
version2[
0]
!=
LE) {
return
tracerr
.
NewError(
" The rules are illegal , The minimum version number is not less than the maximum version number ")
}
case
LT,
LE:
if
version1[
1]
<=
version2[
1]
|| (
version2[
0]
!=
GT
&&
version2[
0]
!=
GE) {
return
tracerr
.
NewError(
" The rules are illegal , The minimum version number is not less than the maximum version number ")
}
default:
return
tracerr
.
NewError(
" The rules are illegal , Multiple rules can only be selected :gt,ge,lt,le")
}
default:
return
tracerr
.
NewError(
" The rules are illegal , The number of rules is abnormal , The number of rules is :"
+
strconv
.
Itoa(
len(
versionRangeList)))
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
3、 ... and 、 Escape to interval
Because it is necessary to convert inequality into interval form and transmit it to other modules , So I chose to create one map, Establish the corresponding relationship between inequality and interval scheme
// Inequality constant
const (
GT
=
"gt"
// Greater than
GE
=
"ge"
// Greater than or equal to
LT
=
"lt"
// Less than
LE
=
"le"
// Less than or equal to
EQ
=
"eq"
// be equal to
NE
=
"ne"
// It's not equal to
)
func
RuleReversal(
versionRange []
string) (
reversalResult
string) {
// Reverse the rules Map
ruleReversalMap :
=
map[
string]
string{
GT:
"(,Ver]",
GE:
"(,Ver)",
LT:
"[Ver,)",
LE:
"(Ver,)",
EQ:
"(,Ver),(Ver,)",
NE:
"[Ver]",
}
switch
len(
versionRange) {
case
1:
version :
=
strings
.
Split(
versionRange[
0],
"@")
reversalResult
=
strings
.
ReplaceAll(
ruleReversalMap[
version[
0]],
"Ver",
version[
1])
case
2:
version1 :
=
strings
.
Split(
versionRange[
0],
"@")
version2 :
=
strings
.
Split(
versionRange[
1],
"@")
switch
version1[
0] {
case
GT,
GE:
reversalResult
=
strings
.
ReplaceAll(
ruleReversalMap[
version1[
0]],
"Ver",
version1[
1])
+
","
+
strings
.
ReplaceAll(
ruleReversalMap[
version2[
0]],
"Ver",
version2[
1])
case
LT,
LE:
reversalResult
=
strings
.
ReplaceAll(
ruleReversalMap[
version1[
0]],
"Ver",
version1[
1])
+
","
+
strings
.
ReplaceAll(
ruleReversalMap[
version2[
0]],
"Ver",
version2[
1])
default:
tracerr
.
Print(
errors
.
New(
" The rules are illegal , Version inequality exception :"
+
version1[
0]))
return
""
}
default:
tracerr
.
Print(
errors
.
New(
" The rules are illegal , The number of rules is abnormal , The number of rules is :"
+
strconv
.
Itoa(
len(
versionRange))))
return
""
}
return
reversalResult
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
utilize @ Symbols separate symbols from version numbers , Remove the separated inequality symbols map Get the corresponding interval format in , Then, the separated version number is matched to the... In the obtained interval format Ver Replace it .
边栏推荐
- Using cache in vuex to solve the problem of data loss in refreshing state
- 微服务版单点登陆系统(SSO)
- ROS的发布消息Publishers和订阅消息Subscribers
- Paging query and join Association query optimization
- Jsonutils tool class (based on Alibaba fastjson)
- Micro service single sign on system (SSO)
- 字符串String转换为jsonArray并解析
- LeetCode 238 除自身以外数组的乘积
- 8VC Venture Cup 2017 - Final Round C. Nikita and stack
- Analysis on development technology of NFT meta universe chain game system
猜你喜欢

Feign remote call

50 lines of code to crawl TOP500 books and import TXT documents

最小生成树、最短路径、拓扑排序、关键路径

Paging query and join Association query optimization

Redis single sign on system + voting system

mysql的充值问题

Crawl Douban to read top250 and import it into SqList database (or excel table)

JVM entry door (1)

Micro service single sign on system (SSO)

项目实战六:分布式事务-Seata
随机推荐
問題解决:虛擬機無法複制粘貼文件
SSO微服务工程中用户行为日志的记录
Résolution du problème: la machine virtuelle n'a pas pu copier et coller le fichier
8VC Venture Cup 2017 - Final Round C. Nikita and stack
图像二值化处理
Interview key points that must be mastered index and affairs (with B-tree and b+ tree)
Deep learning: numpy
Logstash安装及使用
LeetCode 238 除自身以外数组的乘积
The eigen library calculates the angle between two vectors
Handwritten numeral recognition based on tensorflow
VCD video disc
成功解决之Jenkins报错:The goal you specified requires a project to execute but there is no POM
Wechat applet custom pop-up components
微服务架构
Request method 'POST' not supported
(树) 树状数组
CD-CompactDisk
Boyun, standing at the forefront of China's container industry
Using recursion to find all gray codes with n bits