Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gic-platform-enterprise
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
base_platform_enterprise
gic-platform-enterprise
Commits
198e92bf
Commit
198e92bf
authored
Aug 07, 2019
by
guojuxing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
商户、用户操作代码优化
parent
d8a5cf45
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
120 deletions
+89
-120
EnterpriseController.java
...om/gic/operation/web/controller/EnterpriseController.java
+45
-88
UserController.java
...java/com/gic/operation/web/controller/UserController.java
+12
-29
GlobalExceptionHandler.java
...m/gic/operation/web/exception/GlobalExceptionHandler.java
+4
-3
UserPasswordUtil.java
...in/java/com/gic/operation/web/utils/UserPasswordUtil.java
+28
-0
No files found.
gic-platform-operation-web/src/main/java/com/gic/operation/web/controller/EnterpriseController.java
View file @
198e92bf
package
com
.
gic
.
operation
.
web
.
controller
;
import
com.gic.api.base.commons.ServiceResponse
;
import
com.gic.auth.constant.UserConstants
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.gic.auth.dto.UserDTO
;
import
com.gic.auth.service.UserApiService
;
import
com.gic.commons.webapi.reponse.RestResponse
;
...
...
@@ -9,28 +19,18 @@ import com.gic.enterprise.constant.EnterpriseListOrderByEnum;
import
com.gic.enterprise.constant.EnterpriseVersionStatusEnum
;
import
com.gic.enterprise.dto.EnterpriseDTO
;
import
com.gic.enterprise.dto.EnterpriseInitDTO
;
import
com.gic.enterprise.error.ErrorCode
;
import
com.gic.enterprise.response.EnterpriseRestResponse
;
import
com.gic.enterprise.service.EnterpriseApiService
;
import
com.gic.enterprise.service.EnterpriseInitApiService
;
import
com.gic.operation.web.qo.PageQO
;
import
com.gic.operation.web.utils.UserPasswordUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
com.gic.store.utils.CommonResultControllerUtils
;
/**
* @author guojx
* @date 2019/7/17 10:32 AM
* 商户相关操作
* @ClassName: EnterpriseController
* @Description:
* @author guojuxing
* @date 2019/8/7 5:23 PM
*/
@RestController
@RequestMapping
(
"/enterprise"
)
...
...
@@ -44,43 +44,25 @@ public class EnterpriseController {
private
EnterpriseInitApiService
enterpriseInitApiService
;
@RequestMapping
(
"/save-enterprise"
)
public
RestResponse
saveEnterprise
(
@Validated
({
EnterpriseDTO
.
SaveEnterpriseValid
.
class
})
EnterpriseDTO
enterpriseDTO
,
@Validated
({
UserDTO
.
UserQoValid
.
class
})
UserDTO
userDTO
)
{
int
passwordType
=
userDTO
.
getPasswordType
();
String
password
;
//加密
if
(
UserConstants
.
CREATE_AUTO
==
passwordType
)
{
//自动随机生成
password
=
UserPasswordUtil
.
createPasswordAuto
();
}
else
{
if
(
StringUtils
.
isNotBlank
(
userDTO
.
getPassword
())
&&
userDTO
.
getPassword
().
equals
(
userDTO
.
getConfirmPassword
()))
{
//如果一致
password
=
userDTO
.
getPassword
();
}
else
{
return
RestResponse
.
failure
(
ErrorCode
.
PARAMETER_ERROR
.
getCode
(),
"密码不一致"
);
}
}
public
RestResponse
saveEnterprise
(
@Validated
({
EnterpriseDTO
.
SaveEnterpriseValid
.
class
})
EnterpriseDTO
enterpriseDTO
,
@Validated
({
UserDTO
.
UserQoValid
.
class
})
UserDTO
userDTO
)
{
String
password
=
UserPasswordUtil
.
validPassword
(
userDTO
.
getPasswordType
(),
userDTO
.
getPassword
(),
userDTO
.
getConfirmPassword
());
userDTO
.
setPassword
(
UserPasswordUtil
.
getEncryptPassword
(
password
));
ServiceResponse
<
Integer
>
enterpriseResult
=
enterpriseApiService
.
saveEnterprise
(
enterpriseDTO
,
userDTO
);
if
(
enterpriseResult
.
isSuccess
())
{
return
RestResponse
.
success
();
}
else
{
return
EnterpriseRestResponse
.
failure
(
enterpriseResult
);
}
return
RestResponse
.
success
(
CommonResultControllerUtils
.
commonResult
(
enterpriseApiService
.
saveEnterprise
(
enterpriseDTO
,
userDTO
)));
}
@RequestMapping
(
"/list-enterprise"
)
public
RestResponse
listEnterprise
(
String
search
,
Integer
serviceVersion
,
Integer
serviceStatus
,
Integer
orderBy
,
PageQO
pageQO
)
{
public
RestResponse
listEnterprise
(
String
search
,
Integer
serviceVersion
,
Integer
serviceStatus
,
Integer
orderBy
,
PageQO
pageQO
)
{
if
(
orderBy
==
null
)
{
orderBy
=
0
;
}
ServiceResponse
enterpriseResult
=
enterpriseApiService
.
listEnterprise
(
search
,
serviceVersion
,
serviceStatus
,
EnterpriseListOrderByEnum
.
getOrderBy
(
orderBy
),
pageQO
.
getCurrentPage
(),
pageQO
.
getPageSize
());
if
(
enterpriseResult
.
isSuccess
())
{
return
RestResponse
.
success
(
enterpriseResult
.
getResult
());
}
else
{
return
EnterpriseRestResponse
.
failure
(
enterpriseResult
);
}
return
RestResponse
.
success
(
CommonResultControllerUtils
.
commonResult
(
enterpriseApiService
.
listEnterprise
(
search
,
serviceVersion
,
serviceStatus
,
EnterpriseListOrderByEnum
.
getOrderBy
(
orderBy
),
pageQO
.
getCurrentPage
(),
pageQO
.
getPageSize
())));
}
@RequestMapping
(
"/list-enterprise-version-status"
)
...
...
@@ -94,65 +76,40 @@ public class EnterpriseController {
@RequestMapping
(
"/init-enterprise"
)
public
RestResponse
initEnterprise
(
Integer
enterpriseId
)
{
ServiceResponse
enterpriseResult
=
enterpriseApiService
.
initEnterprise
(
enterpriseId
);
if
(
enterpriseResult
.
isSuccess
())
{
return
RestResponse
.
success
();
}
else
{
return
EnterpriseRestResponse
.
failure
(
enterpriseResult
);
}
return
RestResponse
.
success
(
CommonResultControllerUtils
.
commonResult
(
enterpriseApiService
.
initEnterprise
(
enterpriseId
)));
}
@RequestMapping
(
"/list-enterprise-init-info"
)
public
RestResponse
listEnterpriseInitInfo
(
Integer
enterpriseId
)
{
ServiceResponse
<
List
<
EnterpriseInitDTO
>>
response
=
enterpriseInitApiService
.
listByEnterpriseId
(
enterpriseId
);
if
(
response
.
isSuccess
())
{
List
<
EnterpriseInitDTO
>
dtoList
=
response
.
getResult
();
return
RestResponse
.
success
(
changeListToTree
(
0
,
dtoList
));
}
else
{
return
EnterpriseRestResponse
.
failure
(
response
);
}
List
<
EnterpriseInitDTO
>
dtoList
=
(
List
<
EnterpriseInitDTO
>)
CommonResultControllerUtils
.
commonResult
(
enterpriseInitApiService
.
listByEnterpriseId
(
enterpriseId
));
return
RestResponse
.
success
(
changeListToTree
(
0
,
dtoList
));
}
@RequestMapping
(
"/edit-enterprise"
)
public
RestResponse
editEnterprise
(
@Validated
({
EnterpriseDTO
.
EditEnterpriseValid
.
class
,
EnterpriseDTO
.
SaveEnterpriseValid
.
class
})
EnterpriseDTO
enterpriseDTO
)
{
ServiceResponse
enterpriseResult
=
enterpriseApiService
.
editEnterprise
(
enterpriseDTO
);
if
(
enterpriseResult
.
isSuccess
())
{
return
RestResponse
.
success
();
}
else
{
return
EnterpriseRestResponse
.
failure
(
enterpriseResult
);
}
public
RestResponse
editEnterprise
(
@Validated
({
EnterpriseDTO
.
EditEnterpriseValid
.
class
,
EnterpriseDTO
.
SaveEnterpriseValid
.
class
})
EnterpriseDTO
enterpriseDTO
)
{
return
RestResponse
.
success
(
CommonResultControllerUtils
.
commonResult
(
enterpriseApiService
.
editEnterprise
(
enterpriseDTO
)));
}
@RequestMapping
(
"/get-enterprise"
)
public
RestResponse
editEnterprise
(
Integer
enterpriseId
)
{
ServiceResponse
<
EnterpriseDTO
>
enterpriseResult
=
enterpriseApiService
.
getEnterpriseById
(
enterpriseId
);
if
(
enterpriseResult
.
isSuccess
())
{
return
RestResponse
.
success
(
enterpriseResult
.
getResult
());
}
else
{
return
EnterpriseRestResponse
.
failure
(
enterpriseResult
);
}
return
RestResponse
.
success
(
CommonResultControllerUtils
.
commonResult
(
enterpriseApiService
.
getEnterpriseById
(
enterpriseId
)));
}
@RequestMapping
(
"/enable-enterprise"
)
public
RestResponse
enableEnterprise
(
Integer
enterpriseId
)
{
ServiceResponse
enterpriseResult
=
enterpriseApiService
.
enableEnterprise
(
enterpriseId
);
if
(
enterpriseResult
.
isSuccess
())
{
return
RestResponse
.
success
();
}
else
{
return
EnterpriseRestResponse
.
failure
(
enterpriseResult
);
}
return
RestResponse
.
success
(
CommonResultControllerUtils
.
commonResult
(
enterpriseApiService
.
enableEnterprise
(
enterpriseId
)));
}
@RequestMapping
(
"/disable-enterprise"
)
public
RestResponse
disableEnterprise
(
Integer
enterpriseId
)
{
ServiceResponse
enterpriseResult
=
enterpriseApiService
.
disableEnterprise
(
enterpriseId
);
if
(
enterpriseResult
.
isSuccess
())
{
return
RestResponse
.
success
();
}
else
{
return
EnterpriseRestResponse
.
failure
(
enterpriseResult
);
}
return
RestResponse
.
success
(
CommonResultControllerUtils
.
commonResult
(
enterpriseApiService
.
disableEnterprise
(
enterpriseId
)));
}
public
static
List
<
Map
<
String
,
Object
>>
changeListToTree
(
int
initId
,
List
<
EnterpriseInitDTO
>
list
)
{
...
...
gic-platform-operation-web/src/main/java/com/gic/operation/web/controller/UserController.java
View file @
198e92bf
...
...
@@ -9,6 +9,7 @@ import com.gic.enterprise.error.ErrorCode;
import
com.gic.enterprise.response.EnterpriseRestResponse
;
import
com.gic.operation.web.utils.UserPasswordUtil
;
import
com.gic.store.constant.StoreGroupConstant
;
import
com.gic.store.utils.CommonResultControllerUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -18,8 +19,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RestController
;
/**
* @author guojx
* @date 2019/7/17 11:26 AM
* 用户操作
* @ClassName: UserController
* @Description:
* @author guojuxing
* @date 2019/8/7 5:26 PM
*/
@RestController
@RequestMapping
(
"/user"
)
...
...
@@ -29,22 +33,10 @@ public class UserController {
private
UserApiService
userApiService
;
@RequestMapping
(
"/save-or-update-user"
)
public
RestResponse
editUser
(
@Validated
({
UserDTO
.
UserQoValid
.
class
})
UserDTO
userDTO
)
{
public
RestResponse
editUser
(
@Validated
({
UserDTO
.
UserQoValid
.
class
})
UserDTO
userDTO
)
{
userDTO
.
setEnterpriseId
(
StoreGroupConstant
.
TEST_ENTERPRISE_ID
);
int
passwordType
=
userDTO
.
getPasswordType
();
String
password
;
//加密
if
(
UserConstants
.
CREATE_AUTO
==
passwordType
)
{
//自动随机生成
password
=
UserPasswordUtil
.
createPasswordAuto
();
}
else
{
if
(
StringUtils
.
isNotBlank
(
userDTO
.
getPassword
())
&&
userDTO
.
getPassword
().
equals
(
userDTO
.
getConfirmPassword
()))
{
//如果一致
password
=
userDTO
.
getPassword
();
}
else
{
return
RestResponse
.
failure
(
ErrorCode
.
PARAMETER_ERROR
.
getCode
(),
"密码不一致"
);
}
}
String
password
=
UserPasswordUtil
.
validPassword
(
userDTO
.
getPasswordType
(),
userDTO
.
getPassword
(),
userDTO
.
getConfirmPassword
());
userDTO
.
setPassword
(
UserPasswordUtil
.
getEncryptPassword
(
password
));
ServiceResponse
userResult
;
if
(
userDTO
.
getUserId
()
==
null
)
{
...
...
@@ -61,21 +53,12 @@ public class UserController {
@RequestMapping
(
"/get-user-by-id"
)
public
RestResponse
getUserById
(
Integer
userId
)
{
ServiceResponse
<
UserDTO
>
enterpriseResult
=
userApiService
.
getUserById
(
userId
);
if
(
enterpriseResult
.
isSuccess
())
{
return
RestResponse
.
success
(
enterpriseResult
.
getResult
());
}
else
{
return
EnterpriseRestResponse
.
failure
(
enterpriseResult
);
}
return
RestResponse
.
success
(
CommonResultControllerUtils
.
commonResult
(
userApiService
.
getUserById
(
userId
)));
}
@RequestMapping
(
"/get-user"
)
public
RestResponse
getUser
()
{
ServiceResponse
<
UserDTO
>
enterpriseResult
=
userApiService
.
getUserByEnterpriseId
(
StoreGroupConstant
.
TEST_ENTERPRISE_ID
);
if
(
enterpriseResult
.
isSuccess
())
{
return
RestResponse
.
success
(
enterpriseResult
.
getResult
());
}
else
{
return
EnterpriseRestResponse
.
failure
(
enterpriseResult
);
}
return
RestResponse
.
success
(
CommonResultControllerUtils
.
commonResult
(
userApiService
.
getUserByEnterpriseId
(
StoreGroupConstant
.
TEST_ENTERPRISE_ID
)));
}
}
gic-platform-operation-web/src/main/java/com/gic/operation/web/exception/GlobalExceptionHandler.java
View file @
198e92bf
...
...
@@ -4,6 +4,7 @@ import com.gic.commons.webapi.reponse.RestResponse;
import
com.gic.enterprise.error.ErrorCode
;
import
com.gic.enterprise.exception.EnterpriseException
;
import
com.gic.store.constant.StoreGroupErrorEnum
;
import
com.gic.store.exception.StoreException
;
import
com.gic.store.exception.StoreGroupException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -67,7 +68,7 @@ public class GlobalExceptionHandler {
.
append
(
fieldError
.
getDefaultMessage
())
.
append
(
","
);
});
return
getRestResponse
(
StoreGroupErrorEnum
.
Error
.
getCode
(),
errorMessage
.
toString
());
return
getRestResponse
(
ErrorCode
.
PARAMETER_ERROR
.
getCode
(),
errorMessage
.
toString
());
}
@ResponseBody
...
...
@@ -85,8 +86,8 @@ public class GlobalExceptionHandler {
* @return
*/
@ResponseBody
@ExceptionHandler
(
Store
Group
Exception
.
class
)
public
RestResponse
customException
(
Store
Group
Exception
e
)
{
@ExceptionHandler
(
StoreException
.
class
)
public
RestResponse
customException
(
StoreException
e
)
{
return
getRestResponse
(
e
.
getErrorCode
(),
e
.
getMessage
());
}
@ResponseBody
...
...
gic-platform-operation-web/src/main/java/com/gic/operation/web/utils/UserPasswordUtil.java
View file @
198e92bf
package
com
.
gic
.
operation
.
web
.
utils
;
import
com.gic.auth.constant.UserConstants
;
import
com.gic.auth.utils.CreatePasswordAutoUtil
;
import
com.gic.commons.util.Md5Util
;
import
com.gic.commons.webapi.reponse.RestResponse
;
import
com.gic.enterprise.error.ErrorCode
;
import
com.gic.enterprise.exception.EnterpriseException
;
import
org.apache.commons.lang3.StringUtils
;
/**
* @author guojx
...
...
@@ -21,4 +26,27 @@ public class UserPasswordUtil {
Md5Util
md5
=
new
Md5Util
();
return
md5
.
encrypt
(
password
+
password
);
}
/**
* 获取密码
* @param passwordType
* @param password
* @param confirmPassword
* @return
*/
public
static
String
validPassword
(
int
passwordType
,
String
password
,
String
confirmPassword
)
{
//加密
if
(
UserConstants
.
CREATE_AUTO
==
passwordType
)
{
//自动随机生成
return
UserPasswordUtil
.
createPasswordAuto
();
}
else
{
if
(
StringUtils
.
isNotBlank
(
password
)
&&
password
.
equals
(
confirmPassword
))
{
//如果一致
return
password
;
}
else
{
throw
new
EnterpriseException
(
ErrorCode
.
PARAMETER_ERROR
.
getCode
(),
"密码不一致"
);
}
}
}
}
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