saas1提交 #2

Merged
niuwu666 merged 1 commits from dev.zhang into master 2024-09-26 14:46:44 +08:00
14 changed files with 241 additions and 19 deletions

View File

@ -66,7 +66,7 @@ public class TokenController {
@PostMapping("register")
public Result<?> register (@RequestBody RegisterBody registerBody) {
// 用户注册
sysLoginService.register(registerBody.getUsername(), registerBody.getPassword());
sysLoginService.register(registerBody);
return Result.success();
}
}

View File

@ -7,12 +7,6 @@ package com.muyu.auth.form;
*/
public class LoginBody {
/**
*
*/
private Integer firmName;
/**
*
*/

View File

@ -1,10 +1,35 @@
package com.muyu.auth.form;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
*
*
* @author muyu
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class RegisterBody extends LoginBody {
/**
*
*/
private String firmName;
/**
*
*/
private String email;
/**
*
*/
private String phoneNumber;
}

View File

@ -1,5 +1,6 @@
package com.muyu.auth.service;
import com.muyu.auth.form.RegisterBody;
import com.muyu.common.core.constant.CacheConstants;
import com.muyu.common.core.constant.Constants;
import com.muyu.common.core.constant.SecurityConstants;
@ -12,6 +13,8 @@ import com.muyu.common.core.utils.StringUtils;
import com.muyu.common.core.utils.ip.IpUtils;
import com.muyu.common.redis.service.RedisService;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.Firm;
import com.muyu.common.system.remote.RemoteFirmService;
import com.muyu.common.system.remote.RemoteUserService;
import com.muyu.common.system.domain.SysUser;
import com.muyu.common.system.domain.LoginUser;
@ -28,6 +31,9 @@ public class SysLoginService {
@Autowired
private RemoteUserService remoteUserService;
@Autowired
private RemoteFirmService remoteFirmService;
@Autowired
private SysPasswordService passwordService;
@ -98,31 +104,39 @@ public class SysLoginService {
/**
*
*/
public void register (String username, String password) {
public void register (RegisterBody registerBody) {
// 用户名或密码为空 错误
if (StringUtils.isAnyBlank(username, password)) {
if (StringUtils.isAnyBlank(registerBody.getUsername(), registerBody.getPassword())) {
throw new ServiceException("用户/密码必须填写");
}
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|| username.length() > UserConstants.USERNAME_MAX_LENGTH) {
if (registerBody.getUsername().length() < UserConstants.USERNAME_MIN_LENGTH
|| registerBody.getUsername().length() > UserConstants.USERNAME_MAX_LENGTH) {
throw new ServiceException("账户长度必须在2到20个字符之间");
}
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH) {
if (registerBody.getPassword().length() < UserConstants.PASSWORD_MIN_LENGTH
|| registerBody.getPassword().length() > UserConstants.PASSWORD_MAX_LENGTH) {
throw new ServiceException("密码长度必须在5到20个字符之间");
}
String firmName = registerBody.getFirmName();
Result<Firm> byFirmName = remoteFirmService.findByFirmName(firmName);
Firm data = byFirmName.getData();
if (null != data){
throw new ServiceException("公司名称已经存在");
}
// 注册用户信息
SysUser sysUser = new SysUser();
sysUser.setUserName(username);
sysUser.setNickName(username);
sysUser.setPassword(SecurityUtils.encryptPassword(password));
sysUser.setUserName(registerBody.getUsername());
sysUser.setEmail(registerBody.getEmail());
sysUser.setPhonenumber(registerBody.getPhoneNumber());
sysUser.setPassword(SecurityUtils.encryptPassword(registerBody.getPassword()));
Result<?> registerResult = remoteUserService.registerUserInfo(sysUser, SecurityConstants.INNER);
if (Result.FAIL == registerResult.getCode()) {
throw new ServiceException(registerResult.getMsg());
}
recordLogService.recordLogininfor(username, Constants.REGISTER, "注册成功");
recordLogService.recordLogininfor(registerBody.getUsername(), Constants.REGISTER, "注册成功");
}
}

View File

@ -0,0 +1,35 @@
package com.muyu.common.system.domain;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author
* @Packagecom.muyu.common.system.domain
* @Projectcloud-server-8
* @nameFirm
* @Date2024/9/25 22:03
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Firm {
/**
*
*/
private Integer firmId;
/**
*
*/
private String firmName;
/**
*
*/
private String databaseName;
}

View File

@ -0,0 +1,23 @@
package com.muyu.common.system.remote;
import com.muyu.common.core.constant.ServiceNameConstants;
import com.muyu.common.core.domain.Result;
import com.muyu.common.system.domain.Firm;
import com.muyu.common.system.remote.factory.RemoteFirmFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @Author
* @Packagecom.muyu.common.system.remote
* @Projectcloud-server-8
* @nameRemoteFirmService
* @Date2024/9/25 22:21
*/
@FeignClient(contextId = "remoteFirmService", value = ServiceNameConstants.SYSTEM_SERVICE,fallbackFactory = RemoteFirmFallbackFactory.class)
public interface RemoteFirmService {
@RequestMapping("/firm/findByFirmName/{firmName}")
public Result<Firm> findByFirmName(@PathVariable("firmName") String firmName);
}

View File

@ -0,0 +1,29 @@
package com.muyu.common.system.remote.factory;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.exception.ServiceException;
import com.muyu.common.system.domain.Firm;
import com.muyu.common.system.remote.RemoteFirmService;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
/**
* @Author
* @Packagecom.muyu.common.system.remote.factory
* @Projectcloud-server-8
* @nameRemoteFirmFallbackFactory
* @Date2024/9/25 22:22
*/
@Component
public class RemoteFirmFallbackFactory implements FallbackFactory<RemoteFirmService> {
@Override
public RemoteFirmService create(Throwable cause) {
return new RemoteFirmService() {
@Override
public Result<Firm> findByFirmName(String firmName) {
throw new ServiceException(cause.getCause().toString());
}
};
}
}

View File

@ -1,3 +1,4 @@
com.muyu.common.system.remote.factory.RemoteUserFallbackFactory
com.muyu.common.system.remote.factory.RemoteLogFallbackFactory
com.muyu.common.system.remote.factory.RemoteFileFallbackFactory
com.muyu.common.system.remote.factory.RemoteFirmFallbackFactory

View File

@ -0,0 +1,31 @@
package com.muyu.system.controller;
import com.muyu.common.core.domain.Result;
import com.muyu.common.system.domain.Firm;
import com.muyu.system.service.FirmService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Author
* @Packagecom.muyu.system.controller
* @Projectcloud-server-8
* @nameFirmController
* @Date2024/9/25 22:18
*/
@RestController
@RequestMapping("/firm")
@AllArgsConstructor
public class FirmController {
private final FirmService firmService;
@RequestMapping("/findByFirmName/{firmName}")
public Result<Firm> findByFirmName(@PathVariable("firmName") String firmName){
Firm firmServiceByFirmName = firmService.findByFirmName(firmName);
return Result.success(firmServiceByFirmName);
}
}

View File

@ -127,9 +127,9 @@ public class SysUserController extends BaseController {
@PostMapping("/register")
public Result<Boolean> register (@RequestBody SysUser sysUser) {
String username = sysUser.getUserName();
if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
/* if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
return Result.error("当前系统没有开启注册功能!");
}
}*/
if (!userService.checkUserNameUnique(sysUser)) {
return Result.error("保存用户'" + username + "'失败,注册账号已存在");
}

View File

@ -0,0 +1,17 @@
package com.muyu.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.common.system.domain.Firm;
import org.apache.ibatis.annotations.Param;
/**
* @Author
* @Packagecom.muyu.system.mapper
* @Projectcloud-server-8
* @nameFirmMapper
* @Date2024/9/25 22:17
*/
public interface FirmMapper extends BaseMapper<Firm> {
Firm findByFirmName(@Param("firmName") String firmName);
}

View File

@ -0,0 +1,15 @@
package com.muyu.system.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.common.system.domain.Firm;
/**
* @Author
* @Packagecom.muyu.system.service
* @Projectcloud-server-8
* @nameFirmService
* @Date2024/9/25 22:17
*/
public interface FirmService extends IService<Firm> {
Firm findByFirmName(String firmName);
}

View File

@ -0,0 +1,28 @@
package com.muyu.system.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.system.domain.Firm;
import com.muyu.system.mapper.FirmMapper;
import com.muyu.system.service.FirmService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
/**
* @Author
* @Packagecom.muyu.system.service.impl
* @Projectcloud-server-8
* @nameFirmServiceImpl
* @Date2024/9/25 22:17
*/
@Service
@AllArgsConstructor
public class FirmServiceImpl
extends ServiceImpl<FirmMapper, Firm> implements FirmService {
private final FirmMapper firmMapper;
@Override
public Firm findByFirmName(String firmName) {
return firmMapper.findByFirmName(firmName);
}
}

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.muyu.system.mapper.FirmMapper">
<select id="findByFirmName" resultType="com.muyu.common.system.domain.Firm">
select * from firm where firm_name = #{firmName}
</select>
</mapper>