Commit d01bcaba by zhiwj

Merge remote-tracking branch 'origin/developer' into developer

parents 7d622d36 65bf9322
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) {
......
......@@ -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)));
}
}
package com.gic.operation.web.exception;
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.StoreGroupException;
import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindException;
......@@ -13,13 +17,10 @@ import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Set;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.enterprise.error.ErrorCode;
import com.gic.enterprise.exception.EnterpriseException;
import com.gic.store.exception.StoreException;
/**
* 全局异常处理类
......@@ -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(StoreGroupException.class)
public RestResponse customException(StoreGroupException e) {
@ExceptionHandler(StoreException.class)
public RestResponse customException(StoreException e) {
return getRestResponse(e.getErrorCode(), e.getMessage());
}
@ResponseBody
......
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(), "密码不一致");
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment