Commit f833e3ce by guojuxing

新建商户和超级管理员

parent 3fb0ab48
......@@ -5,13 +5,13 @@ import com.gic.auth.constant.UserConstants;
import com.gic.auth.dto.UserDTO;
import com.gic.auth.exception.StoreException;
import com.gic.auth.service.UserApiService;
import com.gic.auth.utils.CreatePasswordAutoUtil;
import com.gic.commons.util.Md5Util;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.enterprise.dto.EnterpriseDTO;
import com.gic.enterprise.error.ErrorCode;
import com.gic.enterprise.response.EnterpriseRestResponse;
import com.gic.enterprise.service.EnterpriseApiService;
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;
......@@ -36,27 +36,30 @@ public class EnterpriseController {
@RequestMapping("/save-enterprise")
@Transactional(rollbackFor = Exception.class)
public RestResponse saveEnterprise(@Validated({EnterpriseDTO.SaveEnterpriseValid.class}) EnterpriseDTO enterpriseDTO,
@Validated({UserDTO.SaveUserValid.class}) UserDTO userDTO) {
@Validated({UserDTO.UserQoValid.class}) UserDTO userDTO) {
ServiceResponse<Integer> enterpriseResult = enterpriseApiService.saveEnterprise(enterpriseDTO);
if (enterpriseResult.isSuccess()) {
int enterpriseId = enterpriseResult.getResult();
userDTO.setEnterpriseId(enterpriseId);
int passwordType = userDTO.getPasswordType();
String password;
//加密
if (UserConstants.CREATE_AUTO == passwordType) {
//自动随机生成
userDTO.setPassword(encryptPassword(CreatePasswordAutoUtil.getStringRandom(8)));
password = UserPasswordUtil.createPasswordAuto();
} else {
if (userDTO.getPassword().equals(userDTO.getConfirmPassword())) {
if (StringUtils.isNotBlank(userDTO.getPassword()) && userDTO.getPassword().equals(userDTO.getConfirmPassword())) {
//如果一致
userDTO.setPassword(encryptPassword(userDTO.getPassword()));
password = userDTO.getPassword();
} else {
RestResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "密码不一致");
return RestResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "密码不一致");
}
}
userDTO.setPassword(UserPasswordUtil.getEncryptPassword(password));
//新增
ServiceResponse userResult = userApiService.saveUser(userDTO);
if (userResult.isSuccess()) {
//todo 发送短信(如果是自动生成密码)
return RestResponse.success();
} else {
//回滚
......@@ -67,8 +70,44 @@ public class EnterpriseController {
}
}
private static String encryptPassword(String password) {
Md5Util md5 = new Md5Util();
return md5.encrypt(password + password);
@RequestMapping("/edit-enterprise")
public RestResponse editEnterprise(@Validated({EnterpriseDTO.EditEnterpriseValid.class, EnterpriseDTO.SaveEnterpriseValid.class})
EnterpriseDTO enterpriseDTO) {
ServiceResponse enterpriseResult = enterpriseApiService.saveEnterprise(enterpriseDTO);
if (enterpriseResult.isSuccess()) {
return RestResponse.success();
} else {
return EnterpriseRestResponse.failure(enterpriseResult);
}
}
@RequestMapping("/get-enterprise")
public RestResponse editEnterprise(Integer enterpriseId) {
ServiceResponse enterpriseResult = enterpriseApiService.getEnterpriseById(enterpriseId);
if (enterpriseResult.isSuccess()) {
return RestResponse.success();
} else {
return EnterpriseRestResponse.failure(enterpriseResult);
}
}
@RequestMapping("/enable-enterprise")
public RestResponse enableEnterprise(Integer enterpriseId) {
ServiceResponse enterpriseResult = enterpriseApiService.enableEnterprise(enterpriseId);
if (enterpriseResult.isSuccess()) {
return RestResponse.success();
} else {
return EnterpriseRestResponse.failure(enterpriseResult);
}
}
@RequestMapping("/disable-enterprise")
public RestResponse disableEnterprise(Integer enterpriseId) {
ServiceResponse enterpriseResult = enterpriseApiService.disableEnterprise(enterpriseId);
if (enterpriseResult.isSuccess()) {
return RestResponse.success();
} else {
return EnterpriseRestResponse.failure(enterpriseResult);
}
}
}
package com.gic.operation.web.controller;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.auth.constant.UserConstants;
import com.gic.auth.dto.UserDTO;
import com.gic.auth.service.UserApiService;
import com.gic.commons.webapi.reponse.RestResponse;
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 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;
/**
* @author guojx
* @date 2019/7/17 11:26 AM
*/
@RestController
@RequestMapping("/user")
public class UserController {
private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class);
@Autowired
private UserApiService userApiService;
@RequestMapping("/save-or-update-user")
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(), "密码不一致");
}
}
userDTO.setPassword(UserPasswordUtil.getEncryptPassword(password));
ServiceResponse userResult;
if (userDTO.getUserId() == null) {
userResult = userApiService.saveUser(userDTO);
} else {
userResult = userApiService.editUser(userDTO);
}
if (userResult.isSuccess()) {
return RestResponse.success();
} else {
return EnterpriseRestResponse.failure(userResult);
}
}
@RequestMapping("/get-user")
public RestResponse getUser(Integer userId) {
ServiceResponse enterpriseResult = userApiService.getUserById(userId);
if (enterpriseResult.isSuccess()) {
return RestResponse.success();
} else {
return EnterpriseRestResponse.failure(enterpriseResult);
}
}
}
package com.gic.operation.web.utils;
import com.gic.auth.utils.CreatePasswordAutoUtil;
import com.gic.commons.util.Md5Util;
/**
* @author guojx
* @date 2019/7/17 11:30 AM
*/
public class UserPasswordUtil {
public static String getEncryptPassword(String password) {
return encryptPassword(password);
}
public static String createPasswordAuto() {
return CreatePasswordAutoUtil.getStringRandom(8);
}
private static String encryptPassword(String password) {
Md5Util md5 = new Md5Util();
return md5.encrypt(password + password);
}
}
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