Commit e62f55c3 authored by tangf's avatar tangf

修改注册流程

parent 070f27d6
......@@ -6,6 +6,8 @@ import com.pangding.web.authority.vo.cloudvo.LoginResVo;
import com.pangding.web.vo.system.req.LoginReqVo;
import com.yanzuoguang.util.helper.CheckerHelper;
import com.yanzuoguang.util.vo.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -21,6 +23,7 @@ import java.io.IOException;
*/
@RestController
@RequestMapping(value="login")
@Api(value = "用户登录类")
public class LoginController {
@Autowired
RegisterService registerServiceImpl;
......@@ -34,6 +37,7 @@ public class LoginController {
* @param reqVo
* @return
*/
@ApiOperation(value ="登录", notes = "返回登录信息")
@RequestMapping(value = "/login", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseResult<LoginResVo> mobile(@RequestBody LoginReqVo reqVo) throws Exception {
CheckerHelper.newInstance()
......
......@@ -6,11 +6,14 @@ import com.pangding.web.authority.vo.reqvo.*;
import com.pangding.web.authority.service.UserService;
import com.pangding.web.authority.vo.resvo.WebUserResVo;
import com.pangding.web.util.RSAUtils;
import com.pangding.web.vo.system.req.authority.SaveUserReqVo;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.CheckerHelper;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.vo.PageSizeData;
import com.yanzuoguang.util.vo.ResponseResult;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
......@@ -105,4 +108,24 @@ public class UserController {
return ResponseResult.result(userServiceImpl.getUserById(webUserReqVo.getId()));
}
/**
* 注册用户(新)
* @param //id
* @return
*/
@ApiOperation(value ="注册", notes = "返回注册信息")
@RequestMapping(value = "/registerUser", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseResult<String> registerUser(@RequestBody SaveUserReqVo saveUserReqVo){
CheckerHelper.newInstance()
.notBlankCheck("account",saveUserReqVo.getAccount())
.notBlankCheck("password", saveUserReqVo.getPassword())
.notBlankCheck("confirmPassword", saveUserReqVo.getConfirmPassword())
.notBlankCheck("companyType", saveUserReqVo.getCompanyType())
.notBlankCheck("invitationCode", saveUserReqVo.getInvitationCode())
.checkException();
return userServiceImpl.registerSaveUser(saveUserReqVo);
}
}
......@@ -3,6 +3,7 @@ package com.pangding.web.authority.dao.impl;
import com.pangding.web.authority.dao.CompanyDao;
import com.pangding.web.authority.vo.reqvo.ListCompanyReqVo;
import com.pangding.web.vo.system.pd.company.CompanyVo;
import com.yanzuoguang.dao.DaoConst;
import com.yanzuoguang.dao.impl.BaseDaoImpl;
import com.yanzuoguang.util.vo.PageSizeData;
import org.springframework.stereotype.Component;
......@@ -27,6 +28,9 @@ public class CompanyDaoImpl extends BaseDaoImpl implements CompanyDao {
.add("companyAttribute","and company_attribute = ? ")
.add("examineStatus","and examine_status = ?")
.add("companyId","and invitation_company_id = ? ");
getSql(DaoConst.LOAD).addCode("{FIELD}", ",b.*", "{INNER}", "INNER JOIN pd_compnay_extend b ON a.id = b.id");
}
@Override
......
......@@ -5,7 +5,9 @@ import com.pangding.web.authority.vo.*;
import com.pangding.web.authority.vo.resvo.WebUserResVo;
import com.pangding.web.vo.system.pd.authority.RoleVo;
import com.pangding.web.vo.system.pd.authority.UserVo;
import com.pangding.web.vo.system.req.authority.SaveUserReqVo;
import com.yanzuoguang.util.vo.PageSizeData;
import com.yanzuoguang.util.vo.ResponseResult;
import java.util.List;
......@@ -140,4 +142,12 @@ public interface UserService {
List<RoleVo> getRoleListByUserId(String userId);
void checkEmail(String email);
/**
* 用户注册(新tangfang)
* @param saveUserReqVo
* @return
*/
ResponseResult<String> registerSaveUser(SaveUserReqVo saveUserReqVo);
}
......@@ -321,14 +321,14 @@ public class RegisterServiceImpl implements RegisterService {
/*保存或更新商户表*/
MerchantCreateReqVo req = new MerchantCreateReqVo();
req.setReqId(StringHelper.getNewID());
// req.setReqId(StringHelper.getNewID());
req.setName(reqVo.getMerchantName());
req.setType(reqVo.getCompanyAttribute());
req.setProductCompanyId(reqVo.getId());
req.setUserId(userVo.getId());
req.setUsername(userVo.getAccount());
if (null == reqVo.getMerchantId() || "".equals(reqVo.getMerchantId())) {
req.setId(StringHelper.getNewID());
// req.setId(StringHelper.getNewID());
} else {
req.setId(reqVo.getMerchantId());
}
......
package com.pangding.web.authority.service.impl;
import com.pangding.web.authority.dao.RoleDao;
import com.pangding.web.authority.dao.UserDao;
import com.pangding.web.authority.dao.UserRoleDao;
import com.pangding.web.authority.dao.*;
import com.pangding.web.authority.util.CompanyConstant;
import com.pangding.web.authority.util.RsaConstant;
import com.pangding.web.authority.vo.reqvo.*;
import com.pangding.web.authority.service.UserService;
import com.pangding.web.authority.vo.*;
import com.pangding.web.authority.vo.resvo.WebUserResVo;
import com.pangding.web.constant.AuthorityConstant;
import com.pangding.web.util.RSAUtils;
import com.pangding.web.vo.system.pd.authority.RoleAuthorityVo;
import com.pangding.web.vo.system.pd.authority.RoleVo;
import com.pangding.web.vo.system.pd.authority.UserVo;
import com.pangding.web.vo.system.pd.company.CompanyExtendVo;
import com.pangding.web.vo.system.pd.company.CompanyVo;
import com.pangding.web.vo.system.req.authority.AuthorityReqVo;
import com.pangding.web.vo.system.req.authority.SaveUserReqVo;
import com.pangding.web.vo.system.req.authority.UserReqVo;
import com.pangding.web.vo.system.req.company.CompanyExtendReqVo;
import com.pangding.web.vo.system.req.company.CompanyReqVo;
import com.pangding.web.vo.system.res.authority.AuthorityResVo;
import com.pangding.web.vo.system.res.company.CompanyResVo;
import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.DateHelper;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.vo.PageSizeData;
import com.yanzuoguang.util.vo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
......@@ -30,12 +43,18 @@ public class UserServiceImpl implements UserService {
@Autowired
UserDao userDao;
@Autowired
UserRoleDao userRoleDao;
@Autowired
RoleDao roleDao;
@Autowired
private AuthorityDao authorityDao;
@Autowired
private RoleAuthorityDao roleAuthorityDao;
@Autowired
private CompanyDao companyDao;
@Autowired
private CompanyExtendDao companyExtendDao;
@Override
@Transactional(rollbackFor = Exception.class)
......@@ -113,8 +132,8 @@ public class UserServiceImpl implements UserService {
this.isValid(webUserReqVo.getAccount());
this.checkAccount(webUserReqVo);
this.checkPhone(webUserReqVo);
ObjectHelper.writeWithFrom(userVo, webUserReqVo);
}else{
ObjectHelper.writeWithFrom(userVo, webUserReqVo);
} else {
userVo.setRemark(webUserReqVo.getPassword());
userVo.setPassword(this.passwordEncoder(webUserReqVo.getPassword()));
}
......@@ -304,4 +323,97 @@ public class UserServiceImpl implements UserService {
}
return null;
}
/**
* tangfang
* 注册保存用户信息
*
* @param saveUserReqVo
*/
@Override
public ResponseResult<String> registerSaveUser(SaveUserReqVo saveUserReqVo){
// 用户名是否存在
UserReqVo userReqVo = new UserReqVo();
userReqVo.setAccount(saveUserReqVo.getAccount());
UserVo userVo = userDao.load(userReqVo, UserVo.class);
if (!StringHelper.isEmpty(userVo)) {
// 用户名已存在
return ResponseResult.error("99", "该用户名已存在");
}
try{
/*将RSA加密后的密码解密*/
String password = RSAUtils.decryptionByPrivateKey(saveUserReqVo.getPassword(), RsaConstant.privateKey);
String confirmPassword = RSAUtils.decryptionByPrivateKey(saveUserReqVo.getConfirmPassword(), RsaConstant.privateKey);
if (!StringHelper.compare(password, confirmPassword)) {
return ResponseResult.error("99", "两次填写的密码不相等");
}
// 验证邀请码是否正确
CompanyReqVo companyReqVo = new CompanyReqVo();
companyReqVo.setInvitationCode(saveUserReqVo.getInvitationCode());
CompanyResVo companyResVo = companyDao.load(companyReqVo, CompanyResVo.class);
if(StringHelper.isEmpty(companyResVo)){
// 邀请码不正确
return ResponseResult.error("99", "邀请码错误");
}
// TODO 是否需要判断商户的状态
String companyId = StringHelper.getNewID();
String userId = StringHelper.getNewID();
// 保存用户表
userVo = new UserVo();
userVo.setId(userId);
userVo.setAccount(saveUserReqVo.getAccount());
userVo.setPassword(this.passwordEncoder(password));
userVo.setRemark(password);
userVo.setCompanyId(companyId);
userVo.setCreateTime(DateHelper.getNow());
userVo.setCreateId(userId);
userVo.setCreateName(saveUserReqVo.getAccount());
userDao.create(userVo);
// 保存公司表
CompanyVo companyVo = new CompanyVo();
companyVo.setId(companyId);
companyVo.setInvitationCompanyId(companyResVo.getId());
companyVo.setStatus(CompanyConstant.COMPANY_STATUS_INIT);
companyDao.create(companyVo);
// 保存公司扩展信息表
CompanyExtendVo companyExtendVo = new CompanyExtendVo();
companyExtendVo.setId(companyId);
companyExtendDao.create(companyExtendVo);
String roleId = StringHelper.getNewID();
// 保存角色表
RoleVo roleVo = new RoleVo();
roleVo.setId(roleId);
roleVo.setCompanyId(companyId);
roleVo.setName(saveUserReqVo + "Admin");
roleVo.setRemark(saveUserReqVo + "Admin");
// 保存角色用户表
UserRoleVo userRoleVo = new UserRoleVo();
userRoleVo.setId(StringHelper.getNewID());
userRoleVo.setUserId(userId);
userRoleVo.setRoleId(roleId);
// 保存角色权限表 先查询默认权限,跟角色添加默认权限
AuthorityReqVo authorityReqVo = new AuthorityReqVo();
authorityReqVo.setAuthorityLevel(AuthorityConstant.AUTHORITY_LEVEL_DEFAULT);
List<AuthorityResVo> authorityResVoList = authorityDao.loadList(authorityReqVo, AuthorityResVo.class);
for(int i = 0; i < authorityResVoList.size(); i++){
AuthorityResVo authorityResVo = authorityResVoList.get(i);
RoleAuthorityVo roleAuthorityVo = new RoleAuthorityVo();
roleAuthorityVo.setId(StringHelper.getNewID());
roleAuthorityVo.setAuthorityId(authorityResVo.getId());
roleAuthorityVo.setRoleId(roleId);
roleAuthorityDao.create(roleAuthorityVo);
}
return ResponseResult.result("注册成功");
}catch (Exception e){
return ResponseResult.error("99", e.getMessage());
}
}
}
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