Compare commits
6 Commits
feature/me
...
b14c03fc32
Author | SHA1 | Date | |
---|---|---|---|
b14c03fc32 | |||
ba34fa4a2b | |||
b015f5d1c4 | |||
6335fa03b1 | |||
5215fded9c | |||
c30cca8f6a |
@@ -2,6 +2,8 @@ package xyz.zhouxy.plusone.constant;
|
||||
|
||||
public class ErrorCodeConsts {
|
||||
public static final int DEFAULT_ERROR_CODE = 9999999;
|
||||
public static final int DEFAULT_SYS_ERROR_CODE = 5000000;
|
||||
public static final int DEFAULT_BIZ_ERROR_CODE = 4000000;
|
||||
|
||||
private ErrorCodeConsts() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
|
@@ -8,7 +8,7 @@ import java.sql.SQLException;
|
||||
*
|
||||
* <p>
|
||||
* 通过在 {@link #map(ResultSet)} 中配置 {@link ResultSet} 到对象的映射,
|
||||
* 可将 {@link #rowMapper(ResultSet, int)} 的方法应用,
|
||||
* 可将 {@link #rowMapper(ResultSet, int)} 的方法引用,
|
||||
* 直接当成 {@link org.springframework.jdbc.core.RowMapper} 对象传给
|
||||
* {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate}
|
||||
* 的查询方法,
|
||||
|
@@ -1,8 +1,17 @@
|
||||
package xyz.zhouxy.plusone.oss;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.csource.common.MyException;
|
||||
import org.csource.common.NameValuePair;
|
||||
@@ -14,7 +23,10 @@ import org.csource.fastdfs.TrackerServer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
|
||||
import lombok.Getter;
|
||||
import xyz.zhouxy.plusone.exception.SysException;
|
||||
|
||||
public class FastDFSUtil {
|
||||
|
||||
@@ -44,7 +56,7 @@ public class FastDFSUtil {
|
||||
* @throws FastDFSException
|
||||
*/
|
||||
public String[] upload(FastDFSFile file) throws FastDFSException {
|
||||
logger.info("File Name: {}, File Length: {}", file.getName(), file.getContent().length);
|
||||
logger.info("File Name: {}, File Length: {}", file.getFileName(), file.getContent().length);
|
||||
|
||||
NameValuePair[] metaList = new NameValuePair[1];
|
||||
metaList[0] = new NameValuePair("author", file.getAuthor());
|
||||
@@ -63,7 +75,7 @@ public class FastDFSUtil {
|
||||
uploadResults[0], uploadResults[1], System.currentTimeMillis() - startTime);
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new FastDFSException("IO Exception when uploadind the file:" + file.getName(), e);
|
||||
throw new FastDFSException("IO Exception when uploadind the file:" + file.getFileName(), e);
|
||||
} catch (MyException e) {
|
||||
throw new FastDFSException(e);
|
||||
}
|
||||
@@ -109,18 +121,68 @@ public class FastDFSUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static final class FastDFSFile {
|
||||
private String name;
|
||||
private byte[] content;
|
||||
private String ext;
|
||||
private String md5;
|
||||
private String author;
|
||||
@Getter
|
||||
private final String fileName;
|
||||
private final byte[] content;
|
||||
@Getter
|
||||
private final String ext;
|
||||
@Getter
|
||||
private final String md5;
|
||||
@Getter
|
||||
private final String author;
|
||||
|
||||
public FastDFSFile(String name, byte[] content, String ext) {
|
||||
this.name = name;
|
||||
private FastDFSFile(@Nonnull File file, @Nullable String author) throws IOException {
|
||||
this.fileName = file.getName();
|
||||
this.content = Files.toByteArray(file);
|
||||
this.ext = Files.getFileExtension(fileName);
|
||||
this.md5 = md5Hex(content);
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
private FastDFSFile(@Nonnull String fileName, @Nonnull byte[] content, @Nullable String author) {
|
||||
this.fileName = fileName;
|
||||
this.content = content;
|
||||
this.ext = ext;
|
||||
this.ext = Files.getFileExtension(fileName);
|
||||
this.md5 = md5Hex(content);
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static FastDFSFile of(@Nonnull File file) throws IOException {
|
||||
return new FastDFSFile(file, null);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static FastDFSFile of(@Nonnull File file, @Nullable String author) throws IOException {
|
||||
return new FastDFSFile(file, author);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static FastDFSFile of(@Nonnull String fileName, @Nonnull byte[] content) {
|
||||
return new FastDFSFile(fileName, content, null);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static FastDFSFile of(@Nonnull String fileName, @Nonnull byte[] content, @Nullable String author) {
|
||||
return new FastDFSFile(fileName, content, author);
|
||||
}
|
||||
|
||||
public byte[] getContent() {
|
||||
return Arrays.copyOf(content, content.length);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private static String md5Hex(byte[] data) {
|
||||
try {
|
||||
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
|
||||
messageDigest.update(data);
|
||||
byte[] result = messageDigest.digest();
|
||||
var sha512Hex = new BigInteger(1, result).toString(16);
|
||||
return Objects.requireNonNull(sha512Hex);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new SysException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,5 @@
|
||||
package xyz.zhouxy.plusone.sms;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.tencentcloudapi.common.Credential;
|
||||
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
||||
import com.tencentcloudapi.common.profile.ClientProfile;
|
||||
@@ -10,8 +8,11 @@ import com.tencentcloudapi.sms.v20210111.SmsClient;
|
||||
import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
|
||||
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import xyz.zhouxy.plusone.exception.SysException;
|
||||
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
|
||||
import xyz.zhouxy.plusone.exception.BizException;
|
||||
import xyz.zhouxy.plusone.sms.SmsProperties.SmsCredentialProperties;
|
||||
import xyz.zhouxy.plusone.sms.SmsProperties.SmsHttpProperties;
|
||||
import xyz.zhouxy.plusone.sms.SmsProperties.SmsProxyProperties;
|
||||
@@ -61,13 +62,14 @@ public class TencentSmsServiceImpl implements SmsService {
|
||||
var res = client.SendSms(req);
|
||||
|
||||
// 输出json格式的字符串回包
|
||||
log.info(SendSmsResponse.toJsonString(res));
|
||||
System.out.println(SendSmsResponse.toJsonString(res));
|
||||
|
||||
// 也可以取出单个值,你可以通过官网接口文档或跳转到response对象的定义处查看返回字段的定义
|
||||
// System.out.println(res.getRequestId());
|
||||
|
||||
} catch (TencentCloudSDKException e) {
|
||||
throw new SysException(e);
|
||||
log.error(e.getMessage(), e);
|
||||
throw new BizException(ErrorCodeConsts.DEFAULT_ERROR_CODE, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,12 +1,11 @@
|
||||
package xyz.zhouxy.plusone;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@@ -24,10 +23,7 @@ class FastDFSTests {
|
||||
|
||||
@Test
|
||||
void testOSS() throws FileNotFoundException, IOException, FastDFSException {
|
||||
try (FileInputStream in = new FileInputStream("D:\\ZhouXY\\Desktop\\666.png");) {
|
||||
byte[] content = IOUtils.toByteArray(in);
|
||||
String[] upload = fastDFSUtil.upload(new FastDFSFile("666.png", content, "png"));
|
||||
log.info(String.join("/", upload));
|
||||
}
|
||||
String[] upload = fastDFSUtil.upload(FastDFSFile.of(new File("D:\\ZhouXY\\Desktop\\666.png")));
|
||||
log.info(String.join("/", upload));
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import xyz.zhouxy.plusone.system.application.query.params.MenuQueryParams;
|
||||
import xyz.zhouxy.plusone.system.application.service.MenuManagementService;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.CreateMenuCommand;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.UpdateMenuCommand;
|
||||
@@ -67,14 +66,7 @@ public class MenuManagementController {
|
||||
public RestfulResult findById(@PathVariable("id") Long id) {
|
||||
adminAuthLogic.checkPermission("sys-menu-details");
|
||||
var result = service.findById(id);
|
||||
return success("查询成功", result);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public RestfulResult queryMenuTree(MenuQueryParams queryParams) {
|
||||
adminAuthLogic.checkPermission("sys-menu-query");
|
||||
var result = service.queryMenuTree(queryParams);
|
||||
return success("查询成功", result);
|
||||
return RestfulResult.success("查询成功", result);
|
||||
}
|
||||
|
||||
@GetMapping("queryByAccountId")
|
||||
|
@@ -1,23 +0,0 @@
|
||||
package xyz.zhouxy.plusone.system.application.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import xyz.zhouxy.plusone.system.application.query.params.MenuQueryParams;
|
||||
import xyz.zhouxy.plusone.system.application.query.result.MenuViewObject;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||
*/
|
||||
@Component
|
||||
public class MenuQueries {
|
||||
|
||||
public List<MenuViewObject> queryMenuTree(MenuQueryParams queryParams) {
|
||||
// TODO【添加】 实现该查询
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
package xyz.zhouxy.plusone.system.application.query;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||
*/
|
||||
public interface PermissionQueries {
|
||||
// TODO【添加】 权限信息查询器
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
package xyz.zhouxy.plusone.system.application.query.params;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import xyz.zhouxy.plusone.constant.EntityStatus;
|
||||
|
||||
@ToString
|
||||
public class MenuQueryParams {
|
||||
private @Getter @Setter String name;
|
||||
private @Getter @Setter String path;
|
||||
private @Getter @Setter String title;
|
||||
private @Getter @Setter Boolean hidden;
|
||||
private @Getter @Setter EntityStatus status;
|
||||
private @Getter @Setter String component;
|
||||
private @Getter @Setter Boolean cache;
|
||||
private @Getter @Setter String resource;
|
||||
}
|
@@ -25,28 +25,60 @@ import xyz.zhouxy.plusone.system.domain.model.menu.Menu.MenuType;
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class MenuViewObject implements IWithOrderNumber {
|
||||
|
||||
private @Getter @Setter Integer type;
|
||||
@Getter
|
||||
@Setter
|
||||
Integer type;
|
||||
|
||||
private @Getter @Setter String typeName;
|
||||
@Getter
|
||||
@Setter
|
||||
String typeName;
|
||||
|
||||
private @Getter @Setter Long id;
|
||||
private @Getter @Setter Long parentId;
|
||||
@Getter
|
||||
@Setter
|
||||
Long id;
|
||||
@Getter
|
||||
@Setter
|
||||
Long parentId;
|
||||
|
||||
private @Getter @Setter String name;
|
||||
@Getter
|
||||
@Setter
|
||||
String name;
|
||||
// 若 type 为 MENU_ITEM 且 path 以 http:// 或 https:// 开头则被识别为外链
|
||||
private @Getter @Setter String path;
|
||||
private @Getter @Setter String title;
|
||||
private @Getter @Setter String icon;
|
||||
private @Getter @Setter boolean hidden;
|
||||
private @Getter @Setter int orderNumber;
|
||||
private @Getter @Setter Integer status;
|
||||
private @Getter @Setter String remarks;
|
||||
@Getter
|
||||
@Setter
|
||||
String path;
|
||||
@Getter
|
||||
@Setter
|
||||
String title;
|
||||
@Getter
|
||||
@Setter
|
||||
String icon;
|
||||
@Getter
|
||||
@Setter
|
||||
boolean hidden;
|
||||
@Getter
|
||||
@Setter
|
||||
int orderNumber;
|
||||
@Getter
|
||||
@Setter
|
||||
Integer status;
|
||||
@Getter
|
||||
@Setter
|
||||
String remarks;
|
||||
|
||||
// MENU_ITEM
|
||||
private @Getter @Setter String component;
|
||||
private @Getter @Setter Boolean cache;
|
||||
private @Getter @Setter String resource;
|
||||
private @Getter @Setter List<Action> actions;
|
||||
@Getter
|
||||
@Setter
|
||||
String component;
|
||||
@Getter
|
||||
@Setter
|
||||
Boolean cache;
|
||||
@Getter
|
||||
@Setter
|
||||
String resource;
|
||||
@Getter
|
||||
@Setter
|
||||
List<Action> actions;
|
||||
|
||||
// MENU_LIST
|
||||
List<MenuViewObject> children;
|
||||
|
@@ -17,8 +17,6 @@ import xyz.zhouxy.plusone.constant.EntityStatus;
|
||||
import xyz.zhouxy.plusone.domain.IWithOrderNumber;
|
||||
import xyz.zhouxy.plusone.exception.DataNotExistException;
|
||||
import xyz.zhouxy.plusone.system.application.exception.UnsupportedMenuTypeException;
|
||||
import xyz.zhouxy.plusone.system.application.query.MenuQueries;
|
||||
import xyz.zhouxy.plusone.system.application.query.params.MenuQueryParams;
|
||||
import xyz.zhouxy.plusone.system.application.query.result.MenuViewObject;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.CreateMenuCommand;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.UpdateMenuCommand;
|
||||
@@ -38,12 +36,10 @@ public class MenuManagementService {
|
||||
|
||||
private final MenuService menuService;
|
||||
private final MenuRepository menuRepository;
|
||||
private final MenuQueries menuQueries;
|
||||
|
||||
MenuManagementService(MenuService menuService, MenuRepository menuRepository, MenuQueries menuQueries) {
|
||||
this.menuService = menuService;
|
||||
MenuManagementService(MenuService roleRepository, MenuRepository menuRepository) {
|
||||
this.menuService = roleRepository;
|
||||
this.menuRepository = menuRepository;
|
||||
this.menuQueries = menuQueries;
|
||||
}
|
||||
|
||||
// ==================== create ====================
|
||||
@@ -127,11 +123,6 @@ public class MenuManagementService {
|
||||
return MenuViewObject.of(menu.orElseThrow(DataNotExistException::new));
|
||||
}
|
||||
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public List<MenuViewObject> queryMenuTree(MenuQueryParams queryParams) {
|
||||
return menuQueries.queryMenuTree(queryParams);
|
||||
}
|
||||
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public List<MenuViewObject> queryByAccountId(Long accountId) {
|
||||
var menus = menuService.queryAllMenuListByAccountId(accountId);
|
||||
|
@@ -4,10 +4,12 @@ import java.math.BigInteger;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import xyz.zhouxy.plusone.exception.SysException;
|
||||
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
|
||||
import xyz.zhouxy.plusone.exception.BizException;
|
||||
import xyz.zhouxy.plusone.util.RandomUtil;
|
||||
|
||||
/**
|
||||
@@ -32,11 +34,12 @@ public final class PasswordUtil {
|
||||
int i = length > 0 ? length / 2 : 0;
|
||||
var passwordWithSalt = salt.substring(0, i)
|
||||
+ password
|
||||
+ salt.substring(i);
|
||||
+ salt.substring(1);
|
||||
|
||||
try {
|
||||
return sha512Hex(passwordWithSalt);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new SysException(e);
|
||||
} catch (Exception e) {
|
||||
throw new BizException(ErrorCodeConsts.DEFAULT_ERROR_CODE, "哈希加密失败!", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,11 +58,11 @@ public final class PasswordUtil {
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@SuppressWarnings("null")
|
||||
private static String sha512Hex(String data) throws NoSuchAlgorithmException {
|
||||
MessageDigest messageDigest = MessageDigest.getInstance("SHA-512");
|
||||
messageDigest.update(data.getBytes(StandardCharsets.UTF_8));
|
||||
byte[] result = messageDigest.digest();
|
||||
return new BigInteger(1, result).toString(16);
|
||||
var sha512Hex = new BigInteger(1, result).toString(16);
|
||||
return Objects.requireNonNull(sha512Hex);
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import lombok.ToString;
|
||||
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
|
||||
import xyz.zhouxy.plusone.domain.AggregateRoot;
|
||||
import xyz.zhouxy.plusone.domain.IWithVersion;
|
||||
import xyz.zhouxy.plusone.exception.UserOperationException;
|
||||
@@ -164,6 +165,7 @@ public class Account extends AggregateRoot<Long> implements IWithVersion {
|
||||
return newInstance;
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(Account.class)
|
||||
public static Account register(
|
||||
Username username,
|
||||
Email email,
|
||||
@@ -193,6 +195,7 @@ public class Account extends AggregateRoot<Long> implements IWithVersion {
|
||||
password, status, accountInfo, roleRefs, createdBy, updatedBy, version);
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(Account.class)
|
||||
public static Account newInstance(
|
||||
String username,
|
||||
String email,
|
||||
@@ -210,6 +213,7 @@ public class Account extends AggregateRoot<Long> implements IWithVersion {
|
||||
return newInstance;
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(Account.class)
|
||||
public static Account register(
|
||||
String username,
|
||||
String email,
|
||||
|
@@ -4,6 +4,7 @@ import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import cn.hutool.core.util.DesensitizedUtil;
|
||||
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
|
||||
import xyz.zhouxy.plusone.commons.constant.PatternConsts;
|
||||
|
||||
/**
|
||||
@@ -26,10 +27,12 @@ public class Email extends Principal {
|
||||
}
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(Email.class)
|
||||
public static Email of(String email) {
|
||||
return new Email(email);
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(Email.class)
|
||||
public static Email ofNullable(String email) {
|
||||
return Objects.nonNull(email) ? new Email(email) : null;
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import cn.hutool.core.util.DesensitizedUtil;
|
||||
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
|
||||
import xyz.zhouxy.plusone.commons.constant.PatternConsts;
|
||||
|
||||
/**
|
||||
@@ -26,10 +27,12 @@ public class MobilePhone extends Principal {
|
||||
}
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(MobilePhone.class)
|
||||
public static MobilePhone of(String mobilePhone) {
|
||||
return new MobilePhone(mobilePhone);
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(MobilePhone.class)
|
||||
public static MobilePhone ofNullable(String mobilePhone) {
|
||||
return Objects.nonNull(mobilePhone) ? new MobilePhone(mobilePhone) : null;
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package xyz.zhouxy.plusone.system.domain.model.account;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
|
||||
import xyz.zhouxy.plusone.commons.constant.PatternConsts;
|
||||
import xyz.zhouxy.plusone.domain.ValidatableStringRecord;
|
||||
|
||||
@@ -26,10 +27,12 @@ public class Nickname extends ValidatableStringRecord {
|
||||
}
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(Nickname.class)
|
||||
public static Nickname of(String nickname) {
|
||||
return new Nickname(nickname);
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(Nickname.class)
|
||||
public static Nickname ofNullable(String nickname) {
|
||||
return Objects.nonNull(nickname) ? new Nickname(nickname) : null;
|
||||
}
|
||||
|
@@ -7,9 +7,11 @@ import javax.annotation.Nonnull;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
|
||||
import xyz.zhouxy.plusone.commons.constant.PatternConsts;
|
||||
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
|
||||
import xyz.zhouxy.plusone.domain.IValueObject;
|
||||
import xyz.zhouxy.plusone.exception.SysException;
|
||||
import xyz.zhouxy.plusone.exception.BizException;
|
||||
import xyz.zhouxy.plusone.system.util.PasswordUtil;
|
||||
|
||||
/**
|
||||
@@ -36,7 +38,7 @@ public class Password implements IValueObject {
|
||||
}
|
||||
var salt = PasswordUtil.generateRandomSalt();
|
||||
if (salt == null) {
|
||||
throw new SysException("未知错误:生成随机盐失败");
|
||||
throw new BizException(ErrorCodeConsts.DEFAULT_ERROR_CODE, "未知错误:生成随机盐失败");
|
||||
}
|
||||
this.saltVal = salt;
|
||||
this.passwordVal = PasswordUtil.hashPassword(password, salt);
|
||||
@@ -50,15 +52,18 @@ public class Password implements IValueObject {
|
||||
this.saltVal = salt;
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(Password.class)
|
||||
public static Password of(String password, String salt) {
|
||||
return new Password(password, salt);
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(Password.class)
|
||||
public static Password newPassword(String newPassword, String passwordConfirmation) {
|
||||
Assert.isTrue(Objects.equals(newPassword, passwordConfirmation), "两次输入的密码不一致");
|
||||
return newPassword(newPassword);
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(Password.class)
|
||||
public static Password newPassword(String newPassword) {
|
||||
return new Password(newPassword);
|
||||
}
|
||||
@@ -79,6 +84,7 @@ public class Password implements IValueObject {
|
||||
return saltVal;
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(Nickname.class)
|
||||
public static Password newDefaultPassword() {
|
||||
return newPassword(DEFAULT_PASSWORD);
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import java.util.Collection;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
|
||||
import xyz.zhouxy.plusone.commons.util.Enumeration;
|
||||
import xyz.zhouxy.plusone.domain.IValueObject;
|
||||
|
||||
@@ -27,6 +28,7 @@ public final class Sex extends Enumeration<Sex> implements IValueObject {
|
||||
private static final ValueSet<Sex> VALUE_SET = new ValueSet<>(UNSET, MALE, FEMALE);
|
||||
|
||||
@Nonnull
|
||||
@StaticFactoryMethod(Sex.class)
|
||||
public static Sex of(int value) {
|
||||
return VALUE_SET.get(value);
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package xyz.zhouxy.plusone.system.domain.model.account;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
|
||||
import xyz.zhouxy.plusone.commons.constant.PatternConsts;
|
||||
|
||||
/**
|
||||
@@ -24,6 +25,7 @@ public class Username extends Principal {
|
||||
}
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(Username.class)
|
||||
public static Username of(String username) {
|
||||
return new Username(username);
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import lombok.ToString;
|
||||
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
|
||||
import xyz.zhouxy.plusone.domain.AggregateRoot;
|
||||
import xyz.zhouxy.plusone.domain.IWithLabel;
|
||||
import xyz.zhouxy.plusone.domain.IWithVersion;
|
||||
@@ -70,12 +71,14 @@ public class Dict extends AggregateRoot<Long> implements IWithLabel, IWithVersio
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(Dict.class)
|
||||
public static Dict newInstance(
|
||||
String dictType,
|
||||
String dictLabel) {
|
||||
return new Dict(null, dictType, dictLabel, Collections.emptySet(), 0);
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(Dict.class)
|
||||
public static Dict newInstance(
|
||||
String dictType,
|
||||
String dictLabel,
|
||||
@@ -83,6 +86,7 @@ public class Dict extends AggregateRoot<Long> implements IWithLabel, IWithVersio
|
||||
return new Dict(null, dictType, dictLabel, values, 0);
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(Dict.class)
|
||||
public static Dict newInstance(
|
||||
String dictType,
|
||||
String dictLabel,
|
||||
|
@@ -4,6 +4,7 @@ import java.util.Objects;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
|
||||
import xyz.zhouxy.plusone.domain.IValueObject;
|
||||
|
||||
/**
|
||||
@@ -25,6 +26,7 @@ public class DictValue implements IValueObject {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(DictValue.class)
|
||||
public static DictValue of(int key, String label) {
|
||||
return new DictValue(key, label);
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package xyz.zhouxy.plusone.system.domain.model.menu;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
|
||||
import xyz.zhouxy.plusone.constant.EntityStatus;
|
||||
import xyz.zhouxy.plusone.system.domain.model.menu.Menu.MenuType;
|
||||
|
||||
@@ -16,6 +17,7 @@ public class MenuConstructor {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(Menu.class)
|
||||
public static Menu newMenuItem(
|
||||
long parentId,
|
||||
String path,
|
||||
@@ -39,6 +41,7 @@ public class MenuConstructor {
|
||||
remarks, component, cache, resource, actions, 0L);
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(Menu.class)
|
||||
public static Menu newMenuList(
|
||||
long parentId,
|
||||
String path,
|
||||
|
@@ -3,6 +3,7 @@ package xyz.zhouxy.plusone.system.domain.model.permission;
|
||||
import java.util.Optional;
|
||||
|
||||
import lombok.Getter;
|
||||
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
|
||||
import xyz.zhouxy.plusone.domain.Entity;
|
||||
import xyz.zhouxy.plusone.domain.IWithLabel;
|
||||
import xyz.zhouxy.plusone.domain.IWithVersion;
|
||||
@@ -20,7 +21,7 @@ public class Action extends Entity<Long> implements IWithLabel, IWithVersion {
|
||||
@Getter String label;
|
||||
@Getter long version;
|
||||
|
||||
public Action(Long id, String resource, String identifier, String label, long version) {
|
||||
private Action(Long id, String resource, String identifier, String label, long version) {
|
||||
this.id = id;
|
||||
this.resource = resource;
|
||||
this.identifier = identifier;
|
||||
@@ -28,10 +29,12 @@ public class Action extends Entity<Long> implements IWithLabel, IWithVersion {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(Action.class)
|
||||
static Action newInstance(String resource, String identifier, String label) {
|
||||
return new Action(null, resource, identifier, label, 0L);
|
||||
}
|
||||
|
||||
@StaticFactoryMethod(Action.class)
|
||||
static Action existingInstance(Long id, String resource, String action, String label, Long version) {
|
||||
return new Action(id, resource, action, label, version);
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import lombok.Getter;
|
||||
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
|
||||
import xyz.zhouxy.plusone.domain.AggregateRoot;
|
||||
import xyz.zhouxy.plusone.domain.IWithVersion;
|
||||
|
||||
@@ -37,6 +38,7 @@ public class Permission extends AggregateRoot<Long> implements IWithVersion {
|
||||
|
||||
// ==================== 实例化 ====================
|
||||
|
||||
@StaticFactoryMethod(Permission.class)
|
||||
public static Permission newInstance(String resource) {
|
||||
return new Permission(
|
||||
null, resource,
|
||||
|
Reference in New Issue
Block a user