Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
JSH ERP
Commits
7f1cd5f1
Commit
7f1cd5f1
authored
Feb 20, 2019
by
cjl
Browse files
添加商品类别编号唯一校验
parent
6bbc0aef
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/com/jsh/erp/constants/ExceptionConstants.java
View file @
7f1cd5f1
...
...
@@ -72,6 +72,9 @@ public class ExceptionConstants {
//修改商品类别信息失败
public
static
final
int
MATERIAL_CATEGORY_EDIT_FAILED_CODE
=
7500002
;
public
static
final
String
MATERIAL_CATEGORY_EDIT_FAILED_MSG
=
"添加商品类别信息失败"
;
//商品类别编号已存在
public
static
final
int
MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_CODE
=
7500003
;
public
static
final
String
MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_MSG
=
"商品类别编号已存在"
;
/**
* 标准正常返回/操作成功返回
...
...
src/main/java/com/jsh/erp/datasource/mappers/MaterialCategoryMapperEx.java
View file @
7f1cd5f1
...
...
@@ -32,4 +32,6 @@ public interface MaterialCategoryMapperEx {
int
batchDeleteMaterialCategoryByIds
(
@Param
(
"updateTime"
)
Date
updateTime
,
@Param
(
"updater"
)
Long
updater
,
@Param
(
"ids"
)
String
ids
[]);
int
editMaterialCategory
(
MaterialCategory
mc
);
List
<
MaterialCategory
>
getMaterialCategoryBySerialNo
(
@Param
(
"serialNo"
)
String
serialNo
);
}
src/main/java/com/jsh/erp/service/materialCategory/MaterialCategoryService.java
View file @
7f1cd5f1
...
...
@@ -2,12 +2,14 @@ package com.jsh.erp.service.materialCategory;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.constants.BusinessConstants
;
import
com.jsh.erp.constants.ExceptionConstants
;
import
com.jsh.erp.datasource.entities.MaterialCategory
;
import
com.jsh.erp.datasource.entities.MaterialCategoryExample
;
import
com.jsh.erp.datasource.entities.User
;
import
com.jsh.erp.datasource.mappers.MaterialCategoryMapper
;
import
com.jsh.erp.datasource.mappers.MaterialCategoryMapperEx
;
import
com.jsh.erp.datasource.vo.TreeNode
;
import
com.jsh.erp.exception.BusinessRunTimeException
;
import
com.jsh.erp.service.user.UserService
;
import
com.jsh.erp.utils.StringUtil
;
import
org.slf4j.Logger
;
...
...
@@ -117,6 +119,8 @@ public class MaterialCategoryService {
//没有给定父级目录的id,默认设置父级目录为根目录
mc
.
setParentid
(
BusinessConstants
.
MATERIAL_CATEGORY_ROOT_ID
);
}
//检查商品类型编号是否已存在
checkMaterialCategorySerialNo
(
mc
);
//数据状态新增时默认设置为启用
mc
.
setStatus
(
BusinessConstants
.
MATERIAL_CATEGORY_STATUS_ENABLE
);
Date
date
=
new
Date
();
...
...
@@ -147,6 +151,8 @@ public class MaterialCategoryService {
}
public
int
editMaterialCategory
(
MaterialCategory
mc
)
{
//检查商品类型编号是否已存在
checkMaterialCategorySerialNo
(
mc
);
//更新时间
mc
.
setUpdateTime
(
new
Date
());
//更新人
...
...
@@ -154,4 +160,37 @@ public class MaterialCategoryService {
mc
.
setUpdater
(
userInfo
==
null
?
null
:
userInfo
.
getId
());
return
materialCategoryMapperEx
.
editMaterialCategory
(
mc
);
}
/**
* 根据商品类别编号判断商品类别是否已存在
* */
public
void
checkMaterialCategorySerialNo
(
MaterialCategory
mc
)
{
if
(
mc
==
null
){
return
;
}
if
(
StringUtil
.
isEmpty
(
mc
.
getSerialNo
())){
return
;
}
//根据商品类别编号查询商品类别
List
<
MaterialCategory
>
mList
=
materialCategoryMapperEx
.
getMaterialCategoryBySerialNo
(
mc
.
getSerialNo
());
if
(
mList
==
null
||
mList
.
size
()<
1
){
//未查询到对应数据,编号可用
return
;
}
if
(
mList
.
size
()>
1
){
//查询到的数据条数大于1,编号已存在
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_CODE
,
ExceptionConstants
.
MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_MSG
);
}
if
(
mc
.
getId
()==
null
){
//新增时,编号已存在
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_CODE
,
ExceptionConstants
.
MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_MSG
);
}
if
(
mc
.
getId
()!=
mList
.
get
(
0
).
getId
()){
//修改时,相同编号,id不同
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_CODE
,
ExceptionConstants
.
MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_MSG
);
}
}
}
src/main/resources/mapper_xml/MaterialCategoryMapperEx.xml
View file @
7f1cd5f1
...
...
@@ -91,5 +91,13 @@
name=#{name},remark=#{remark}
where id =#{id}
</update>
<select
id=
"getMaterialCategoryBySerialNo"
resultMap=
"com.jsh.erp.datasource.mappers.MaterialCategoryMapper.BaseResultMap"
>
select
<include
refid=
"com.jsh.erp.datasource.mappers.MaterialCategoryMapper.Base_Column_List"
/>
FROM jsh_materialcategory
where 1=1
and serial_no=#{serialNo}
and status !='2'
</select>
</mapper>
\ No newline at end of file
Write
Preview
Supports
Markdown
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