Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
patzn-cloud-service-hmhj
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangweidong
patzn-cloud-service-hmhj
Commits
22150eb1
Commit
22150eb1
authored
Jul 04, 2022
by
lijingjing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
原铝散样,编号处理;
parent
27ab43bc
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
126 additions
and
38 deletions
+126
-38
ICodeRuleService.java
...tzn/cloud/service/lims/hmhj/service/ICodeRuleService.java
+3
-1
IEntrustSampleService.java
...loud/service/lims/hmhj/service/IEntrustSampleService.java
+4
-0
CodeRuleServiceImpl.java
...d/service/lims/hmhj/service/impl/CodeRuleServiceImpl.java
+43
-18
EntrustSampleServiceImpl.java
...vice/lims/hmhj/service/impl/EntrustSampleServiceImpl.java
+61
-10
EntrustServiceImpl.java
...ud/service/lims/hmhj/service/impl/EntrustServiceImpl.java
+15
-9
No files found.
src/main/java/com/patzn/cloud/service/lims/hmhj/service/ICodeRuleService.java
View file @
22150eb1
...
...
@@ -28,5 +28,7 @@ public interface ICodeRuleService extends IBaseService<CodeRule> {
String
getKey
(
String
prefix
,
String
rule
,
BaseEntity
entity
);
void
recycleCode
(
CodeTypeEnum
codeTypeEnum
,
List
<
String
>
codeList
,
Account
account
);
void
recycleCode
(
CodeTypeEnum
codeTypeEnum
,
List
<
String
>
codeList
,
String
curVary
,
Account
account
);
boolean
updateSn
(
CodeTypeEnum
codeTypeEnum
,
String
vary
,
Integer
sn
,
Account
account
);
}
src/main/java/com/patzn/cloud/service/lims/hmhj/service/IEntrustSampleService.java
View file @
22150eb1
...
...
@@ -32,6 +32,8 @@ public interface IEntrustSampleService extends IBaseService<EntrustSample> {
boolean
removeByIds
(
List
<
Long
>
ids
);
void
recyleCodes
(
List
<
EntrustSample
>
samples
);
List
<
EntrustSampleVO
>
obtainMakeInfo
(
Long
[]
ids
,
Account
account
);
Page
<
EntrustSampleVO
>
pageSampleReceive
(
Page
<
EntrustSampleVO
>
page
,
EntrustSampleVO
entrustSample
);
...
...
@@ -141,4 +143,6 @@ public interface IEntrustSampleService extends IBaseService<EntrustSample> {
boolean
deletePhysicalByEntrustIds
(
List
<
Long
>
ids
);
boolean
updateStatus
(
EntrustSampleStatusEnum
sampleStatus
,
List
<
Long
>
sampleIds
);
String
getCompatibleCode
(
EntrustSample
sample
);
}
src/main/java/com/patzn/cloud/service/lims/hmhj/service/impl/CodeRuleServiceImpl.java
View file @
22150eb1
...
...
@@ -51,6 +51,8 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul
@Autowired
private
ICodeRuleRecordService
codeRuleRecordService
;
private
static
final
String
SN
=
"#SN#"
;
@Override
public
Page
<
CodeRule
>
page
(
Page
<
CodeRule
>
page
,
CodeRule
codeRule
)
{
Wrapper
wrapper
=
new
EntityWrapper
<>(
codeRule
);
...
...
@@ -159,8 +161,6 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul
}
else
{
sn
=
CodeKeyUtils
.
getSn
(
codeRule
.
getSn
()
+
1
,
codeRule
.
getLength
());
}
// 更新规则序列号
nextSn
(
codeRule
.
getId
(),
codeRule
.
getSn
());
return
key
.
toString
().
replaceAll
(
CommonConstants
.
SN
,
sn
);
...
...
@@ -222,7 +222,7 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul
}
@Override
public
void
recycleCode
(
CodeTypeEnum
codeTypeEnum
,
List
<
String
>
codeList
,
Account
account
)
{
public
void
recycleCode
(
CodeTypeEnum
codeTypeEnum
,
List
<
String
>
codeList
,
String
curVary
,
Account
account
)
{
codeList
.
removeIf
(
StringUtils:
:
isBlank
);
if
(
CollectionUtils
.
isEmpty
(
codeList
))
{
return
;
...
...
@@ -241,9 +241,14 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul
List
<
Long
>
codeIdList
=
new
ArrayList
<>();
codeRuleList
.
forEach
((
lmsCode
->
codeIdList
.
add
(
lmsCode
.
getId
())));
// 查询编号记录表
List
<
Map
<
String
,
Object
>>
recordList
=
SqlRunner
.
db
().
selectList
(
"select * from code_rule_record where company_id = {0} and code_rule_id in {1} and vary like '%#SN#'"
,
account
.
getCompanyId
(),
codeIdList
);
String
sql
=
"select * from code_rule_record where company_id = {0} and code_rule_id in {1} and vary "
;
if
(
codeTypeEnum
==
CodeTypeEnum
.
AL_BULK_SAMPLE_CODE
)
{
sql
+=
" = '"
+
curVary
+
"'"
;
}
else
{
sql
+=
"like '%"
+
SN
+
"%'"
;
}
List
<
Map
<
String
,
Object
>>
recordList
=
SqlRunner
.
db
().
selectList
(
sql
,
account
.
getCompanyId
(),
codeIdList
);
if
(
CollectionUtils
.
isEmpty
(
recordList
))
{
// 如果没有配置顺序号,不予处理
return
;
...
...
@@ -260,8 +265,14 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul
while
(
iterator
.
hasNext
())
{
// 数据库中的编号记录
CodeRuleRecord
codeRuleRecord
=
iterator
.
next
();
// 这是数据库中存储的编号前缀
String
codeRulePrefix
=
codeRuleRecord
.
getVary
().
replace
(
"#SN#"
,
""
);
String
varyContent
=
codeRuleRecord
.
getVary
();
// 获取序号前半段
String
frontVary
=
varyContent
.
substring
(
0
,
varyContent
.
indexOf
(
SN
));
// 如果有后半段的话,需要处理后半段
String
hindVary
=
varyContent
.
replace
(
frontVary
,
""
).
replace
(
SN
,
""
);
// 这是数据库中存储的编号前缀+后缀
String
codeRulePrefix
=
frontVary
+
hindVary
;
// 先将实际编号后面的 sn 的长度删除, 删除之后就是实际编号的前缀了
CodeRule
lmsCodeRule
=
ruleMap
.
get
(
codeRuleRecord
.
getCodeRuleId
());
// tmpCode 就是实际的编号
...
...
@@ -274,25 +285,28 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul
// 如果实际编号长度减去配置的编号长度 <= 0, 说明编号的前缀极有可能不存在, 所以没有回收依据, 不予回收
continue
;
}
tmpCode
=
tmpCode
.
substring
(
0
,
tmpCode
.
length
()
-
length
);
// 假如说:样品编号是:220704A11121,其中A后面的1才是流水号,那么处理时需要注意截取内容
// 此处不改变运行逻辑,剔除后半段内容,再去做减法,然后再加上后半段比较
tmpCode
=
tmpCode
.
replace
(
hindVary
,
""
);
tmpCode
=
tmpCode
.
substring
(
0
,
tmpCode
.
length
()
-
length
)
+
hindVary
;
}
}
// 这里的 tmpCode 就是实际编号的前缀了
// 判断删除顺序号后的编号和编号前缀是否相同
if
(
Objects
.
equals
(
tmpCode
,
codeRulePrefix
)
||
(!
""
.
equals
(
codeRulePrefix
)
&&
tmpCode
.
startsWith
(
codeRulePrefix
)))
{
if
(
Objects
.
equals
(
tmpCode
,
codeRulePrefix
)
||
(!
""
.
equals
(
codeRulePrefix
)
&&
tmpCode
.
startsWith
(
codeRulePrefix
)))
{
// 相同
String
sn
=
code
.
replace
(
codeRulePrefix
,
""
);
// 更改:剔除前缀和后缀,这样做才是真正获取的流水号
String
sn
=
code
.
replace
(
frontVary
,
""
).
replace
(
hindVary
,
""
);
if
(
NumberUtils
.
isDigits
(
sn
))
{
if
(
codeMap
.
containsKey
(
codeRulePrefix
))
{
codeMap
.
get
(
codeRulePrefix
).
add
(
Integer
.
valueOf
(
sn
));
if
(
codeMap
.
containsKey
(
varyContent
))
{
codeMap
.
get
(
varyContent
).
add
(
Integer
.
valueOf
(
sn
));
}
else
{
List
<
Integer
>
list
=
new
ArrayList
<>();
list
.
add
(
Integer
.
valueOf
(
sn
));
codeMap
.
put
(
codeRulePrefix
,
list
);
codeMap
.
put
(
varyContent
,
list
);
}
// 放入 map
varyIdMap
.
put
(
codeRulePrefix
,
codeRuleRecord
.
getCodeRuleId
());
varyIdMap
.
put
(
varyContent
,
codeRuleRecord
.
getCodeRuleId
());
}
// 下一层外循环
break
;
...
...
@@ -303,10 +317,21 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul
Collections
.
sort
(
snList
);
LmsCodeRuleRecord
record
=
new
LmsCodeRuleRecord
();
record
.
setCodeRuleId
(
varyIdMap
.
get
(
vary
));
record
.
setVary
(
vary
+
"#SN#"
);
record
.
setVary
(
vary
);
record
.
setSn
(
snList
.
get
(
0
)
-
1
);
SqlRunner
.
db
().
update
(
"update code_rule_record set sn = {0} where code_rule_id = {1} and vary = {2}"
,
snList
.
get
(
0
)
-
1
,
varyIdMap
.
get
(
vary
),
vary
+
"#SN#"
);
snList
.
get
(
0
)
-
1
,
varyIdMap
.
get
(
vary
),
vary
);
});
}
@Override
public
boolean
updateSn
(
CodeTypeEnum
codeTypeEnum
,
String
vary
,
Integer
sn
,
Account
account
)
{
RestAssert
.
fail
(
null
==
codeTypeEnum
,
"编号类型为空"
);
RestAssert
.
fail
(
StringUtils
.
isBlank
(
vary
),
"编号规则为空"
);
RestAssert
.
fail
(
null
==
sn
,
"编号流水号为空"
);
CodeRule
codeRule
=
super
.
getOne
(
Condition
.
create
().
eq
(
"type"
,
codeTypeEnum
.
getValue
()).
last
(
"LIMIT 1"
));
RestAssert
.
fail
(
null
==
codeRule
,
"编号规则不存在"
);
return
SqlRunner
.
db
().
update
(
"update code_rule_record set sn = {0} where code_rule_id = {1} and vary = {2}"
,
sn
,
codeRule
.
getId
(),
vary
);
}
}
src/main/java/com/patzn/cloud/service/lims/hmhj/service/impl/EntrustSampleServiceImpl.java
View file @
22150eb1
...
...
@@ -676,13 +676,34 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
entrustSampleItemService
.
remove
(
Condition
.
create
().
in
(
"entrust_sample_id"
,
ids
));
// 查询要删除的样品编号
List
<
EntrustSample
>
samples
=
super
.
getBatchIds
(
ids
);
List
<
String
>
sampleCodes
=
samples
.
stream
().
map
(
EntrustSample:
:
getCode
).
collect
(
Collectors
.
toList
());
recyleCodes
(
samples
);
return
baseMapper
.
deleteBatchIds
(
ids
)
>
0
;
}
@Override
public
void
recyleCodes
(
List
<
EntrustSample
>
samples
)
{
if
(
CollectionUtils
.
isEmpty
(
samples
))
{
return
;
}
List
<
String
>
sampleCodes
=
new
ArrayList
<>();
// 需要对编号额外处理
String
vary
=
null
;
for
(
EntrustSample
s
:
samples
)
{
if
(
s
.
getCodeRuleType
()
==
CodeTypeEnum
.
AL_BULK_SAMPLE_CODE
.
getIntValue
())
{
String
str
=
s
.
getCode
().
replaceAll
(
"(A|B|C)"
,
"BC"
);
s
.
setCode
(
str
);
if
(
null
==
vary
)
{
vary
=
str
.
substring
(
0
,
8
)
+
"#SN#"
+
str
.
substring
(
9
);
}
}
sampleCodes
.
add
(
s
.
getCode
());
}
Integer
codeRuleType
=
samples
.
get
(
0
).
getCodeRuleType
();
// 不为空的情下触发编号回收机制
if
(
CollectionUtils
.
isNotEmpty
(
sampleCodes
)
&&
null
!=
codeRuleType
)
{
codeRuleService
.
recycleCode
(
CodeTypeEnum
.
get
(
codeRuleType
),
sampleCodes
,
LoginHelper
.
getAccount
());
codeRuleService
.
recycleCode
(
CodeTypeEnum
.
get
(
codeRuleType
),
sampleCodes
,
vary
,
LoginHelper
.
getAccount
());
}
return
baseMapper
.
deleteBatchIds
(
ids
)
>
0
;
}
@Override
...
...
@@ -2279,13 +2300,7 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
ids
.
forEach
(
id
->
{
// 只查询当前委托下的样品
List
<
EntrustSample
>
samples
=
sampleList
.
stream
().
filter
(
t
->
Objects
.
equals
(
t
.
getEntrustId
(),
id
)).
collect
(
Collectors
.
toList
());
if
(
CollectionUtils
.
isNotEmpty
(
samples
))
{
List
<
String
>
sampleCodes
=
samples
.
stream
().
map
(
EntrustSample:
:
getCode
).
collect
(
Collectors
.
toList
());
Integer
codeRuleType
=
samples
.
get
(
0
).
getCodeRuleType
();
if
(
null
!=
codeRuleType
&&
org
.
apache
.
commons
.
collections
.
CollectionUtils
.
isNotEmpty
(
sampleCodes
))
{
codeRuleService
.
recycleCode
(
CodeTypeEnum
.
get
(
codeRuleType
),
sampleCodes
,
LoginHelper
.
getAccount
());
}
}
recyleCodes
(
samples
);
});
// 删除备样
...
...
@@ -2327,6 +2342,42 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
return
update
(
entrustSample
,
Condition
.
create
().
in
(
"id"
,
sampleIds
));
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
String
getCompatibleCode
(
EntrustSample
sample
)
{
RestAssert
.
fail
(
StringUtils
.
isBlank
(
sample
.
getCode
()),
"匹配的样品编号为空!"
);
RestAssert
.
fail
(
Objects
.
isNull
(
sample
.
getCodeRuleType
()),
"匹配的样品编号类型为空!"
);
boolean
updateRule
=
false
;
String
sampleCode
=
sample
.
getCode
(),
front
=
sampleCode
.
substring
(
0
,
7
),
backend
=
sampleCode
.
substring
(
8
),
vary
=
front
.
substring
(
0
,
6
)
+
"BC"
+
CommonConstants
.
SN
+
backend
;
// 流水默认设置1
int
sn
=
1
;
while
(
isRepeatSampleCode
(
sample
))
{
updateRule
=
true
;
// 原铝散样处理方式
if
(
sample
.
getCodeRuleType
()
==
CodeTypeEnum
.
AL_BULK_SAMPLE_CODE
.
getIntValue
())
{
sn
=
Integer
.
parseInt
(
sampleCode
.
substring
(
7
,
8
))
+
1
;
sampleCode
=
front
+
sn
+
backend
;
sample
.
setCode
(
sampleCode
);
}
}
// 若生成的编号在数据库中查询不重复(例如:220704B63333),那么继续模糊匹配是否存在此时间段的初始编号,不存在,重置编号
if
(!
updateRule
)
{
// 使用初始编号查询,若查询不出,重置流水
sample
.
setCode
(
sampleCode
.
substring
(
0
,
7
)
+
sn
+
sampleCode
.
substring
(
8
));
if
(!
isRepeatSampleCode
(
sample
))
{
sampleCode
=
sample
.
getCode
();
updateRule
=
true
;
}
}
if
(
updateRule
)
{
codeRuleService
.
updateSn
(
CodeTypeEnum
.
get
(
sample
.
getCodeRuleType
()),
vary
,
sn
,
LoginHelper
.
getAccount
());
}
return
sampleCode
;
}
private
List
<
EntrustSampleItemIndex
>
getIndexList
(
Long
sampleId
)
{
if
(
null
==
sampleId
)
{
...
...
src/main/java/com/patzn/cloud/service/lims/hmhj/service/impl/EntrustServiceImpl.java
View file @
22150eb1
...
...
@@ -146,15 +146,11 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
ids
.
forEach
(
id
->
{
List
<
EntrustSample
>
samples
=
entrustSampleService
.
list
(
Condition
.
create
().
eq
(
"entrust_id"
,
id
));
if
(
CollectionUtils
.
isNotEmpty
(
samples
))
{
List
<
String
>
sampleCodes
=
samples
.
stream
().
map
(
EntrustSample:
:
getCode
).
collect
(
Collectors
.
toList
());
Integer
codeRuleType
=
samples
.
get
(
0
).
getCodeRuleType
();
if
(
null
!=
codeRuleType
&&
CollectionUtils
.
isNotEmpty
(
sampleCodes
))
{
codeRuleService
.
recycleCode
(
CodeTypeEnum
.
get
(
codeRuleType
),
sampleCodes
,
LoginHelper
.
getAccount
());
}
}
entrustSampleService
.
recyleCodes
(
samples
);
});
// entrustSampleService.recyleCodes();
entrustSampleService
.
remove
(
Condition
.
create
().
in
(
"entrust_id"
,
ids
));
entrustSampleItemService
.
remove
(
Condition
.
create
().
in
(
"entrust_id"
,
ids
));
// 是否根据条件回收委托编号
...
...
@@ -204,6 +200,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
/**
* 转换自动大写编号
*
* @param sample
*/
private
void
toSampleCodeUpperCase
(
EntrustSample
sample
)
{
...
...
@@ -321,8 +318,17 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
// 替换班次BC
sampleCode
=
sampleCode
.
replace
(
"BC"
,
DateKit
.
getShiftByNow
());
// YYMMDD+(A/C/E)+SN(1)+ 槽号(4)
String
queryKey
=
sampleCode
.
substring
(
0
,
7
)
+
"_"
+
sampleCode
.
substring
(
8
);
sampleCode
=
entrustSampleService
.
getNewCode
(
queryKey
,
7
,
1
);
// String queryKey = sampleCode.substring(0, 7) + "_" + sampleCode.substring(8);
// sampleCode = entrustSampleService.getNewCode(queryKey, 7, 1);
// 初始时,处理可能因a,b,c时间段重复编号
EntrustSample
example
=
new
EntrustSample
();
example
.
setId
(
sample
.
getId
());
example
.
setCode
(
sampleCode
).
setCodeRuleType
(
codeType
.
getIntValue
());
// example.setFirstCode(sampleCode.replaceAll("(A|B|C)", "_"));
String
newSampleCode
=
entrustSampleService
.
getCompatibleCode
(
example
);
if
(!
sampleCode
.
equals
(
newSampleCode
))
{
sampleCode
=
newSampleCode
;
}
}
// 电解质散样样品编号处理
// else if (CodeTypeEnum.ELECT_BULK_SAMPLE_CODE == codeType) {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment