Compare commits

..
7 Commits
Author SHA1 Message Date
timi e3236d262d Merge pull request 'v1.0.16' (#25) from dev into master
Reviewed-on: #25
2026-08-16 03:37:08 +00:00
Timi 3d4e32e5da v1.0.16
CI / build-deploy (pull_request) Successful in 23s
CI / notify-on-failure (pull_request) Skipped
2026-08-16 11:36:02 +08:00
timi c8e2e16ba5 Merge pull request 'v1.0.15' (#24) from dev into master
Reviewed-on: #24
2026-08-15 17:49:51 +00:00
Timi bdc4cbb240 v1.0.15
CI / build-deploy (pull_request) Successful in 27s
CI / notify-on-failure (pull_request) Skipped
2026-08-16 01:49:18 +08:00
timi 99b44faf09 Merge pull request 'v1.0.15' (#23) from dev into master
Reviewed-on: #23
2026-08-15 17:45:26 +00:00
Timi 7f6cebd4e2 v1.0.15
CI / build-deploy (pull_request) Failing after 6s
CI / notify-on-failure (pull_request) Successful in 0s
2026-08-16 01:44:45 +08:00
Timi 75fd4bed18 fix event save fail for limit == 1 2026-08-15 15:01:08 +08:00
11 changed files with 104 additions and 26 deletions
+5
View File
@@ -46,6 +46,11 @@ jobs:
<username>${{ vars.TIMI_NEXUS_USERNAME }}</username>
<password>${{ vars.TIMI_NEXUS_PASSWORD }}</password>
</server>
<server>
<id>e2ins_nexus</id>
<username>${{ vars.E2INS_NEXUS_USERNAME }}</username>
<password>${{ vars.E2INS_NEXUS_PASSWORD }}</password>
</server>
</servers>
</settings>
EOF
+16 -1
View File
@@ -11,7 +11,7 @@
<groupId>com.imyeyu.timiserverapi</groupId>
<artifactId>TimiServerAPI</artifactId>
<version>1.0.14</version>
<version>1.0.16</version>
<packaging>jar</packaging>
<name>TimiServerAPI</name>
<description>imyeyu.com API</description>
@@ -167,6 +167,16 @@
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>e2ins_nexus</id>
<url>https://nexus.e2ins.com/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
@@ -225,6 +235,11 @@
<groupId>org.flywaydb</groupId>
<artifactId>flyway-mysql</artifactId>
</dependency>
<dependency>
<groupId>com.e2ins.ms.notify</groupId>
<artifactId>e2ins-msg-notify-service-sdk</artifactId>
<version>0.0.9</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
@@ -1,5 +1,6 @@
package com.imyeyu.api.config;
import com.e2ins.ms.notify.SmsNotifyService;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
@@ -31,6 +32,12 @@ public class BeanConfig {
.build();
}
@Bean
public SmsNotifyService smsNotifyService() {
// TODO
return new SmsNotifyService(null, null);
}
@Bean
public Yaml yaml() {
return new Yaml();
@@ -12,7 +12,7 @@ public class GaoUserInviteCache {
/// 发起邀请的用户 ID
private String inviterUserId;
/// 门店 ID
/// 门店 IDGLOBAL_MANAGER 可为空
private String storeId;
/// 角色 ID
@@ -62,7 +62,9 @@ public class GaoEventController {
@RequireGaoPermission(GaoPermissionCode.EVENT_READ)
@PostMapping("/detail")
public GaoEvent detail(@RequestParam String id) {
return service.get(id);
GaoEvent event = service.get(id);
event.setRoleCodeList(service.listRoleCode(event.getId()));
return event;
}
@AOPLog
@@ -377,7 +377,7 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
}
private void changeInvitedCount(String customerId, long delta) {
if (delta == 0) {
if (TimiJava.isEmpty(customerId) || delta == 0) {
return;
}
GaoCustomer customer = get(customerId);
@@ -221,7 +221,7 @@ public class GaoEventServiceImplement extends AbstractEntityService<GaoEvent, St
TimiException.required(event.getValueUnit(), "NUMBER 事件必须配置数值单位");
}
if (TimiJava.isNotEmpty(event.getLimitType()) && event.getLimitType() != GaoEvent.LimitType.NONE) {
TimiException.requiredTrue(event.getLimitType().getMin() < event.getLimitValue(), "约束值最低 %s".formatted(event.getLimitType().getMin()));
TimiException.requiredTrue(event.getLimitType().getMin() <= event.getLimitValue(), "约束值最低 %s".formatted(event.getLimitType().getMin()));
}
if (event.getBeginAt() != null || event.getEndAt() != null) {
TimiException.requiredTrue(event.getBeginAt() == null || event.getEndAt() == null || event.getBeginAt() <= event.getEndAt(), "invalid beginAt or endAt");
@@ -1,5 +1,6 @@
package com.imyeyu.api.modules.gao.service.implement;
import com.imyeyu.api.bean.CoreRoleCode;
import com.imyeyu.api.bean.ModuleCode;
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
import com.imyeyu.api.modules.gao.bean.GaoUserInviteCache;
@@ -96,30 +97,36 @@ public class GaoUserInviteServiceImplement implements GaoUserInviteService {
String inviterUserId = userLoginService.getRequireLoginUserId();
logger.setUserId(inviterUserId);
permissionChecker.checkAny(ModuleCode.GAO, GaoPermissionCode.USER_CREATE.getValue());
Role requestedRole = roleService.get(req.getRoleId());
boolean adminInviteGlobalManager = roleChecker.hasAny(ModuleCode.CORE, CoreRoleCode.ADMIN.name())
&& isGlobalManagerRole(requestedRole);
boolean globalManager = authorizationScopeService.isSystemAdmin(inviterUserId)
|| roleChecker.hasAny(ModuleCode.GAO, GaoRoleCode.GLOBAL_MANAGER.name());
boolean storeManager = !globalManager;
GaoStore loginStore = storeManager ? gaoStoreService.getByUserId(inviterUserId) : null;
String storeId = storeManager ? loginStore == null ? null : loginStore.getId() : req.getStoreId();
TimiException.required(storeId, "not found storeId");
checkStoreScope(inviterUserId, storeId);
GaoStore store = requireActiveStore(storeId);
String storeId = adminInviteGlobalManager ? null : storeManager ? loginStore == null ? null : loginStore.getId() : req.getStoreId();
if (!adminInviteGlobalManager) {
TimiException.required(storeId, "not found storeId");
checkStoreScope(inviterUserId, storeId);
}
if (storeId != null) {
requireActiveStore(storeId);
}
Role role = requireInvitableRole(inviterUserId, req.getRoleId(), storeId);
long createdAt = Time.now();
long expireAt = createdAt + INVITE_TTL;
GaoUserInviteCache cache = new GaoUserInviteCache();
cache.setInviterUserId(inviterUserId);
cache.setStoreId(store.getId());
cache.setStoreId(storeId);
cache.setRoleId(role.getId());
cache.setScene(storeManager ? "STORE_MANAGER" : "STORE_MANAGEMENT");
cache.setScene(adminInviteGlobalManager ? "CORE_ADMIN" : storeManager ? "STORE_MANAGER" : "STORE_MANAGEMENT");
cache.setCreatedAt(createdAt);
cache.setExpireAt(expireAt);
String code = saveInvite(cache);
logger.setContent("storeId=%s;roleId=%s;scene=%s;createdAt=%d;expireAt=%d".formatted(
store.getId(), role.getId(), cache.getScene(), createdAt, expireAt));
storeId, role.getId(), cache.getScene(), createdAt, expireAt));
logger.setResult("created");
return new GaoUserInviteCreateResponse(code, expireAt);
} catch (TimiException e) {
@@ -141,8 +148,7 @@ public class GaoUserInviteServiceImplement implements GaoUserInviteService {
TimiException.required(code, "not found code");
checkCodeRateLimit(code);
GaoUserInviteCache cache = requireValidInvite(code);
requireActiveStore(cache.getStoreId());
requireValidRole(cache.getRoleId(), cache.getStoreId());
validateInviteTarget(cache);
return new GaoUserInviteValidateResponse(true, cache.getExpireAt());
}
@@ -163,8 +169,7 @@ public class GaoUserInviteServiceImplement implements GaoUserInviteService {
try {
cache = requireValidInvite(code);
logger.setContent(buildLogContent(cache));
requireActiveStore(cache.getStoreId());
requireValidRole(cache.getRoleId(), cache.getStoreId());
validateInviteTarget(cache);
TimiException.requiredNull(userService.getByName(data.getName()), "existed user name");
TimiException.requiredNull(userService.getByPhoneNo(data.getPhoneNo()), "existed phone number");
if (!redisInvite.destroy(getInviteKey(code))) {
@@ -176,10 +181,16 @@ public class GaoUserInviteServiceImplement implements GaoUserInviteService {
user.setPhoneNo(data.getPhoneNo());
user.setPassword(data.getPassword());
GaoUser gaoUser = new GaoUser();
gaoUser.setStoreId(cache.getStoreId());
gaoUser.setUser(user);
gaoUserService.create(gaoUser);
if (cache.getStoreId() == null) {
// TODO 用更好的方式
userService.create(user);
userService.verifyPhoneNo(user.getId());
} else {
GaoUser gaoUser = new GaoUser();
gaoUser.setStoreId(cache.getStoreId());
gaoUser.setUser(user);
gaoUserService.create(gaoUser);
}
UserRole userRole = new UserRole();
userRole.setId(UUID.randomUUID().toString());
@@ -265,7 +276,7 @@ public class GaoUserInviteServiceImplement implements GaoUserInviteService {
private Role requireValidRole(String roleId, String storeId) {
Role role = roleService.get(roleId);
if (role == null || role.getModuleCode() != ModuleCode.GAO || !isRoleUsableForStore(role, storeId)) {
if (role == null || role.getModuleCode() != ModuleCode.GAO || (storeId == null && !isGlobalManagerRole(role)) || !isRoleUsableForStore(role, storeId)) {
throw invalidInvite();
}
return role;
@@ -274,7 +285,20 @@ public class GaoUserInviteServiceImplement implements GaoUserInviteService {
private boolean isRoleUsableForStore(Role role, String storeId) {
return role.getOwnerType() == null
|| role.getOwnerType() == AuthOwnerType.MODULE && (TimiJava.isEmpty(role.getOwnerId()) || ModuleCode.GAO.name().equals(role.getOwnerId()))
|| role.getOwnerType() == AuthOwnerType.STORE && storeId.equals(role.getOwnerId());
|| role.getOwnerType() == AuthOwnerType.STORE && storeId != null && storeId.equals(role.getOwnerId());
}
private boolean isGlobalManagerRole(Role role) {
return role != null
&& role.getModuleCode() == ModuleCode.GAO
&& GaoRoleCode.GLOBAL_MANAGER.name().equals(role.getCode());
}
private void validateInviteTarget(GaoUserInviteCache cache) {
if (cache.getStoreId() != null) {
requireActiveStore(cache.getStoreId());
}
requireValidRole(cache.getRoleId(), cache.getStoreId());
}
private void checkStoreScope(String userId, String storeId) {
@@ -10,7 +10,7 @@ import lombok.Data;
@Data
public class GaoUserInviteCreateRequest {
/// 门店管理场景的目标门店 ID,店长场景不使用
/// 门店管理场景的目标门店 ID,店长场景及 ADMIN 邀请 GLOBAL_MANAGER 时不使用
private String storeId;
/// 目标角色 ID
@@ -1,5 +1,6 @@
package com.imyeyu.api.modules.user.service;
import com.e2ins.ms.notify.vo.sms.CaptchaVerifyReq;
import com.imyeyu.api.modules.user.entity.User;
import com.imyeyu.api.modules.user.vo.LoginRequest;
import com.imyeyu.api.modules.user.vo.LoginResponse;
@@ -23,6 +24,8 @@ public interface UserLoginService {
LoginResponse login(String token, String userId);
LoginResponse loginBySms(CaptchaVerifyReq req);
/**
* 根据令牌获取用户
*
@@ -1,5 +1,8 @@
package com.imyeyu.api.modules.user.service.implement;
import com.e2ins.ms.notify.SmsNotifyService;
import com.e2ins.ms.notify.bean.NotifyDetail;
import com.e2ins.ms.notify.vo.sms.CaptchaVerifyReq;
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
import com.imyeyu.api.modules.common.entity.Attachment;
import com.imyeyu.api.modules.common.entity.Setting;
@@ -7,13 +10,13 @@ import com.imyeyu.api.modules.common.service.AttachmentService;
import com.imyeyu.api.modules.common.service.SettingService;
import com.imyeyu.api.modules.user.bean.BootstrapData;
import com.imyeyu.api.modules.user.entity.User;
import com.imyeyu.api.modules.user.service.RoleService;
import com.imyeyu.api.modules.user.service.UserLoginService;
import com.imyeyu.api.modules.user.service.UserRoleService;
import com.imyeyu.api.modules.user.service.UserService;
import com.imyeyu.api.modules.user.vo.LoginRequest;
import com.imyeyu.api.modules.user.vo.LoginResponse;
import com.imyeyu.java.TimiJava;
import com.imyeyu.java.bean.timi.TimiCode;
import com.imyeyu.java.bean.timi.TimiException;
import com.imyeyu.spring.TimiSpring;
import com.imyeyu.spring.util.Redis;
@@ -27,6 +30,7 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
@@ -44,9 +48,9 @@ public class UserLoginServiceImplement implements UserLoginService, TimiJava {
private static final long PHONE_VERIFY_CODE_TTL = Time.M * 5;
private final UserService userService;
private final RoleService roleService;
private final SettingService settingService;
private final UserRoleService userRoleService;
private final SmsNotifyService smsNotifyService;
private final AttachmentService attachmentService;
private final Redis<String, String> redisUserToken;
@@ -98,6 +102,24 @@ public class UserLoginServiceImplement implements UserLoginService, TimiJava {
return result;
}
@Override
public LoginResponse loginBySms(CaptchaVerifyReq req) {
try {
NotifyDetail detail = smsNotifyService.captchaVerify(req);
// 无报错即成功
User user = userService.getByPhoneNo(detail.getSendTo());
if (!user.isValidPhone()) {
user.setPhoneNoVerifyAt(Time.now());
userService.update(user);
}
return login(UUID.randomUUID().toString(), user.getId());
} catch (IOException e) {
log.error("login by sms error", e);
throw new TimiException(TimiCode.ERROR, "验证短信失败");
}
}
@Override
public User getLoginUser(String token) {
if (TimiJava.isEmpty(token)) {