mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:59:20 +08:00
feat: 组织架构重构 - 公司成员与部门成员模块,登录逻辑及权限改造
- 新增 org_company_member 表及模块(公司成员:owner/member 角色) - 新增 org_department_member 表及模块(部门成员:一用户可属多部门) - 移除 sys_user 的 companyId/departmentId/positionId 字段 - 重构 UserMenuServiceImpl 权限逻辑:super→全系统 / owner→公司菜单 / member→职位菜单 - 修复 RoleAspect 中 role='company' 应为 'admin' 的 BUG - CurrentUserContext 注入 CompanyMemberService,新增 getCurrentMemberRole() - 登录时公司选择逻辑:优先 lastCompanyId,需状态可用且未过期 - 超管(super)登录跳过公司校验 - 创建公司时自动创建拥有者账号并写入 org_company_member(role=owner) - 联系人字段替换为拥有者姓名+拥有者电话 - org_company 表新增 owner_name/owner_phone 字段 - sys_user.phone 唯一约束修正 - 同步更新 SQL 设计文件(31张表 DDL)
This commit is contained in:
+1
-1
@@ -60,7 +60,7 @@ public class PermissionAspect {
|
||||
case "super":
|
||||
hasPermission = annotation.allowSuper();
|
||||
break;
|
||||
case "company":
|
||||
case "admin":
|
||||
hasPermission = annotation.allowCompany();
|
||||
break;
|
||||
case "user":
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ public class RoleAspect {
|
||||
case "super":
|
||||
hasPermission = annotation.allowSuper();
|
||||
break;
|
||||
case "company":
|
||||
case "admin":
|
||||
hasPermission = annotation.allowCompany();
|
||||
break;
|
||||
case "user":
|
||||
|
||||
+8
@@ -46,6 +46,14 @@ public interface PromotionFeeTypeService {
|
||||
*/
|
||||
void initPromotionFeeTypeForCompany(Long companyId);
|
||||
|
||||
/**
|
||||
* 初始化公司推广费类型数据(指定创建人)
|
||||
*
|
||||
* @param companyId 公司ID
|
||||
* @param creatorId 创建人ID
|
||||
*/
|
||||
void initPromotionFeeTypeForCompany(Long companyId, Long creatorId);
|
||||
|
||||
/**
|
||||
* 初始化当前公司推广费类型数据
|
||||
*/
|
||||
|
||||
+16
-11
@@ -208,6 +208,11 @@ public class PromotionFeeTypeServiceImpl implements PromotionFeeTypeService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void initPromotionFeeTypeForCompany(Long companyId) {
|
||||
initPromotionFeeTypeForCompany(companyId, 1L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initPromotionFeeTypeForCompany(Long companyId, Long creatorId) {
|
||||
// 检查是否已经初始化过
|
||||
LambdaQueryWrapper<PromotionFeeTypePO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PromotionFeeTypePO::getCompanyId, companyId);
|
||||
@@ -217,14 +222,14 @@ public class PromotionFeeTypeServiceImpl implements PromotionFeeTypeService {
|
||||
|
||||
// 初始化推广费类型数据
|
||||
List<PromotionFeeTypePO> initialTypes = List.of(
|
||||
createPromotionFeeTypePO(companyId, "直通车", "淘宝直通车推广费用", 3, 1),
|
||||
createPromotionFeeTypePO(companyId, "钻展", "钻石展位推广费用", 4, 2),
|
||||
createPromotionFeeTypePO(companyId, "超级推荐", "超级推荐推广费用", 3, 3),
|
||||
createPromotionFeeTypePO(companyId, "平台佣金", "平台交易佣金", 2, 4),
|
||||
createPromotionFeeTypePO(companyId, "分销佣金", "分销商佣金", 2, 5),
|
||||
createPromotionFeeTypePO(companyId, "活动费用", "平台活动参与费用", 1, 6),
|
||||
createPromotionFeeTypePO(companyId, "站外广告", "站外广告投放费用", 1, 7),
|
||||
createPromotionFeeTypePO(companyId, "直播推广", "直播推广费用", 1, 8)
|
||||
createPromotionFeeTypePO(companyId, "直通车", "淘宝直通车推广费用", 3, 1, creatorId),
|
||||
createPromotionFeeTypePO(companyId, "钻展", "钻石展位推广费用", 4, 2, creatorId),
|
||||
createPromotionFeeTypePO(companyId, "超级推荐", "超级推荐推广费用", 3, 3, creatorId),
|
||||
createPromotionFeeTypePO(companyId, "平台佣金", "平台交易佣金", 2, 4, creatorId),
|
||||
createPromotionFeeTypePO(companyId, "分销佣金", "分销商佣金", 2, 5, creatorId),
|
||||
createPromotionFeeTypePO(companyId, "活动费用", "平台活动参与费用", 1, 6, creatorId),
|
||||
createPromotionFeeTypePO(companyId, "站外广告", "站外广告投放费用", 1, 7, creatorId),
|
||||
createPromotionFeeTypePO(companyId, "直播推广", "直播推广费用", 1, 8, creatorId)
|
||||
);
|
||||
|
||||
// 批量插入
|
||||
@@ -255,7 +260,7 @@ public class PromotionFeeTypeServiceImpl implements PromotionFeeTypeService {
|
||||
* @param sortOrder 排序
|
||||
* @return 推广费类型PO对象
|
||||
*/
|
||||
private PromotionFeeTypePO createPromotionFeeTypePO(Long companyId, String typeName, String description, Integer calculationMethod, Integer sortOrder) {
|
||||
private PromotionFeeTypePO createPromotionFeeTypePO(Long companyId, String typeName, String description, Integer calculationMethod, Integer sortOrder, Long creatorId) {
|
||||
PromotionFeeTypePO po = new PromotionFeeTypePO();
|
||||
po.setCompanyId(companyId);
|
||||
po.setTypeName(typeName);
|
||||
@@ -263,8 +268,8 @@ public class PromotionFeeTypeServiceImpl implements PromotionFeeTypeService {
|
||||
po.setCalculationMethod(calculationMethod);
|
||||
po.setSortOrder(sortOrder);
|
||||
po.setIsActive(1);
|
||||
po.setCreateBy(1L); // 系统初始化
|
||||
po.setUpdateBy(1L);
|
||||
po.setCreateBy(creatorId != null ? creatorId : 1L);
|
||||
po.setUpdateBy(creatorId != null ? creatorId : 1L);
|
||||
return po;
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -28,6 +28,9 @@ public class AccountFilterDTO {
|
||||
@Schema(description = "岗位ID", example = "1")
|
||||
private Long positionId;
|
||||
|
||||
@Schema(description = "用户ID列表", example = "[1,2,3]")
|
||||
private java.util.List<Long> userIds;
|
||||
|
||||
@Schema(description = "角色", example = "user")
|
||||
private String role;
|
||||
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ public class AccountVO {
|
||||
@Schema(description = "部门ID", example = "1")
|
||||
private Long departmentId;
|
||||
|
||||
@Schema(description = "部门名称", example = "技术部")
|
||||
@Schema(description = "部门名称(多个用逗号分隔)", example = "技术部,研发部")
|
||||
private String departmentName;
|
||||
|
||||
@Schema(description = "岗位ID", example = "1")
|
||||
|
||||
+99
-29
@@ -19,8 +19,16 @@ import top.xyquan.ecomdmbbackend.modules.sys.user.model.po.UserPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.account.model.vo.AccountVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.account.service.AccountService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.company.service.CompanyService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.service.CompanyMemberService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.model.po.CompanyMemberPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.enums.CompanyMemberRole;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.model.vo.CompanyMemberVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.department.service.DepartmentService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.departmentmember.service.DepartmentMemberService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.departmentmember.model.po.DepartmentMemberPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.departmentmember.model.vo.DepartmentMemberVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.position.service.PositionService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.position.model.po.PositionPO;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@@ -35,14 +43,26 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
|
||||
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final CompanyService companyService;
|
||||
private final CompanyMemberService companyMemberService;
|
||||
private final DepartmentService departmentService;
|
||||
private final DepartmentMemberService departmentMemberService;
|
||||
private final PositionService positionService;
|
||||
|
||||
public AccountServiceImpl(PasswordEncoder passwordEncoder,
|
||||
CurrentUserContext currentUserContext,
|
||||
CompanyService companyService,
|
||||
CompanyMemberService companyMemberService,
|
||||
DepartmentService departmentService,
|
||||
DepartmentMemberService departmentMemberService,
|
||||
PositionService positionService) {
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.companyService = companyService;
|
||||
this.companyMemberService = companyMemberService;
|
||||
this.departmentService = departmentService;
|
||||
this.departmentMemberService = departmentMemberService;
|
||||
this.positionService = positionService;
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +100,6 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
|
||||
// 创建账户
|
||||
UserPO user = new UserPO();
|
||||
BeanUtils.copyProperties(createAccountDTO, user);
|
||||
user.setCompanyId(companyId); // 设置公司ID
|
||||
user.setPassword(passwordEncoder.encode(createAccountDTO.getPassword()));
|
||||
user.setRole("user"); // 默认角色
|
||||
user.setStatus(0); // 正常状态
|
||||
@@ -91,6 +110,14 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
|
||||
// 保存账户
|
||||
this.save(user);
|
||||
|
||||
// 创建公司成员关系
|
||||
companyMemberService.create(user.getId(), companyId, CompanyMemberRole.member, createAccountDTO.getPositionId());
|
||||
|
||||
// 如果有部门ID,创建部门成员关系
|
||||
if (createAccountDTO.getDepartmentId() != null) {
|
||||
departmentMemberService.addMember(createAccountDTO.getDepartmentId(), user.getId());
|
||||
}
|
||||
|
||||
// 转换为VO并返回
|
||||
return convertToVO(user);
|
||||
}
|
||||
@@ -145,15 +172,6 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
|
||||
if (updateAccountDTO.getAvatarImageId() != null) {
|
||||
user.setAvatarImageId(updateAccountDTO.getAvatarImageId());
|
||||
}
|
||||
if (updateAccountDTO.getDepartmentId() != null) {
|
||||
user.setDepartmentId(updateAccountDTO.getDepartmentId());
|
||||
}
|
||||
if (updateAccountDTO.getPositionId() != null) {
|
||||
user.setPositionId(updateAccountDTO.getPositionId());
|
||||
}
|
||||
if (updateAccountDTO.getStatus() != null) {
|
||||
user.setStatus(updateAccountDTO.getStatus());
|
||||
}
|
||||
if (StringUtils.hasText(updateAccountDTO.getRemark())) {
|
||||
user.setRemark(updateAccountDTO.getRemark());
|
||||
}
|
||||
@@ -163,6 +181,25 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
|
||||
// 保存更新
|
||||
this.updateById(user);
|
||||
|
||||
// 如果职位有更新,更新公司成员
|
||||
if (updateAccountDTO.getPositionId() != null) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
CompanyMemberPO member = companyMemberService.getByUserIdAndCompanyId(user.getId(), companyId);
|
||||
if (member != null) {
|
||||
companyMemberService.updatePosition(member.getId(), updateAccountDTO.getPositionId());
|
||||
}
|
||||
}
|
||||
|
||||
// 如果部门有更新,更新部门成员
|
||||
if (updateAccountDTO.getDepartmentId() != null) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
DepartmentMemberPO existingMember = departmentMemberService.getByUserIdAndDepartmentId(user.getId(), updateAccountDTO.getDepartmentId());
|
||||
if (existingMember == null) {
|
||||
// 添加新的部门成员关系
|
||||
departmentMemberService.addMember(updateAccountDTO.getDepartmentId(), user.getId());
|
||||
}
|
||||
}
|
||||
|
||||
// 转换为VO并返回
|
||||
return convertToVO(user);
|
||||
}
|
||||
@@ -183,6 +220,16 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
|
||||
user.setStatus(1); // 删除状态
|
||||
user.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
this.updateById(user);
|
||||
|
||||
// 删除公司成员关系
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
companyMemberService.removeByUserIdAndCompanyId(user.getId(), companyId);
|
||||
|
||||
// 删除所有部门成员关系
|
||||
List<DepartmentMemberVO> deptMembers = departmentMemberService.getByUserId(user.getId());
|
||||
for (DepartmentMemberVO dm : deptMembers) {
|
||||
departmentMemberService.removeMember(dm.getDepartmentId(), user.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,11 +285,15 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
|
||||
throw new BusinessException("无法获取公司信息");
|
||||
}
|
||||
|
||||
// 设置公司ID过滤条件
|
||||
// 获取公司所有成员的用户ID列表
|
||||
List<CompanyMemberVO> members = companyMemberService.getByCompanyId(companyId);
|
||||
List<Long> userIds = members.stream().map(CompanyMemberVO::getUserId).collect(Collectors.toList());
|
||||
|
||||
// 设置过滤条件:只查询公司成员
|
||||
if (pageQuery.getFilters() == null) {
|
||||
pageQuery.setFilters(new AccountFilterDTO());
|
||||
}
|
||||
pageQuery.getFilters().setCompanyId(companyId);
|
||||
pageQuery.getFilters().setUserIds(userIds);
|
||||
|
||||
// 调用通用分页查询方法
|
||||
return getAccountPage(pageQuery);
|
||||
@@ -278,21 +329,6 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
|
||||
wrapper.like(UserPO::getPhone, filterDTO.getPhone());
|
||||
}
|
||||
|
||||
// 公司ID
|
||||
if (filterDTO.getCompanyId() != null) {
|
||||
wrapper.eq(UserPO::getCompanyId, filterDTO.getCompanyId());
|
||||
}
|
||||
|
||||
// 部门ID
|
||||
if (filterDTO.getDepartmentId() != null) {
|
||||
wrapper.eq(UserPO::getDepartmentId, filterDTO.getDepartmentId());
|
||||
}
|
||||
|
||||
// 岗位ID
|
||||
if (filterDTO.getPositionId() != null) {
|
||||
wrapper.eq(UserPO::getPositionId, filterDTO.getPositionId());
|
||||
}
|
||||
|
||||
// 角色
|
||||
if (StringUtils.hasText(filterDTO.getRole())) {
|
||||
wrapper.eq(UserPO::getRole, filterDTO.getRole());
|
||||
@@ -303,6 +339,11 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
|
||||
wrapper.eq(UserPO::getStatus, filterDTO.getStatus());
|
||||
}
|
||||
|
||||
// 用户ID列表过滤
|
||||
if (filterDTO.getUserIds() != null && !filterDTO.getUserIds().isEmpty()) {
|
||||
wrapper.in(UserPO::getId, filterDTO.getUserIds());
|
||||
}
|
||||
|
||||
// 排除删除状态
|
||||
wrapper.ne(UserPO::getStatus, 1);
|
||||
|
||||
@@ -327,8 +368,37 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
|
||||
// 设置角色名称
|
||||
accountVO.setRoleName(getRoleName(user.getRole()));
|
||||
|
||||
// TODO: 设置公司名称、部门名称、岗位名称等关联信息
|
||||
// 这里可以根据需要查询关联表获取详细信息
|
||||
// 设置公司ID(从公司成员表获取)
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
CompanyMemberPO companyMember = companyMemberService.getByUserIdAndCompanyId(user.getId(), companyId);
|
||||
if (companyMember != null) {
|
||||
accountVO.setCompanyId(companyMember.getCompanyId());
|
||||
// 设置公司名称
|
||||
var company = companyService.getById(companyMember.getCompanyId());
|
||||
if (company != null) {
|
||||
accountVO.setCompanyName(company.getName());
|
||||
}
|
||||
// 设置职位ID和名称
|
||||
if (companyMember.getPositionId() != null) {
|
||||
accountVO.setPositionId(companyMember.getPositionId());
|
||||
PositionPO position = positionService.getById(companyMember.getPositionId());
|
||||
if (position != null) {
|
||||
accountVO.setPositionName(position.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 设置部门名称(逗号拼接所有部门)
|
||||
List<DepartmentMemberVO> deptMembers = departmentMemberService.getByUserId(user.getId());
|
||||
if (!deptMembers.isEmpty()) {
|
||||
String deptNames = deptMembers.stream()
|
||||
.map(DepartmentMemberVO::getDepartmentName)
|
||||
.filter(name -> name != null)
|
||||
.collect(Collectors.joining(","));
|
||||
accountVO.setDepartmentName(deptNames);
|
||||
// 设置第一个部门ID
|
||||
accountVO.setDepartmentId(deptMembers.get(0).getDepartmentId());
|
||||
}
|
||||
|
||||
return accountVO;
|
||||
}
|
||||
|
||||
+143
-15
@@ -18,6 +18,17 @@ import top.xyquan.ecomdmbbackend.modules.org.account.model.dto.SuperUpdateAccoun
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.user.model.po.UserPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.account.model.vo.AccountVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.account.service.SuperAccountService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.company.service.CompanyService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.service.CompanyMemberService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.model.po.CompanyMemberPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.enums.CompanyMemberRole;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.model.vo.CompanyMemberVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.departmentmember.model.po.DepartmentMemberPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.department.service.DepartmentService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.departmentmember.service.DepartmentMemberService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.departmentmember.model.vo.DepartmentMemberVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.position.service.PositionService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.position.model.po.PositionPO;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@@ -32,11 +43,26 @@ public class SuperAccountServiceImpl extends ServiceImpl<UserMapper, UserPO> imp
|
||||
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final CompanyService companyService;
|
||||
private final CompanyMemberService companyMemberService;
|
||||
private final DepartmentService departmentService;
|
||||
private final DepartmentMemberService departmentMemberService;
|
||||
private final PositionService positionService;
|
||||
|
||||
public SuperAccountServiceImpl(PasswordEncoder passwordEncoder,
|
||||
CurrentUserContext currentUserContext) {
|
||||
CurrentUserContext currentUserContext,
|
||||
CompanyService companyService,
|
||||
CompanyMemberService companyMemberService,
|
||||
DepartmentService departmentService,
|
||||
DepartmentMemberService departmentMemberService,
|
||||
PositionService positionService) {
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.companyService = companyService;
|
||||
this.companyMemberService = companyMemberService;
|
||||
this.departmentService = departmentService;
|
||||
this.departmentMemberService = departmentMemberService;
|
||||
this.positionService = positionService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,6 +102,17 @@ public class SuperAccountServiceImpl extends ServiceImpl<UserMapper, UserPO> imp
|
||||
// 保存账户
|
||||
this.save(user);
|
||||
|
||||
// 如果有公司ID,创建公司成员关系
|
||||
if (superCreateAccountDTO.getCompanyId() != null) {
|
||||
companyMemberService.create(user.getId(), superCreateAccountDTO.getCompanyId(),
|
||||
CompanyMemberRole.member, superCreateAccountDTO.getPositionId());
|
||||
}
|
||||
|
||||
// 如果有部门ID,创建部门成员关系
|
||||
if (superCreateAccountDTO.getDepartmentId() != null) {
|
||||
departmentMemberService.addMember(superCreateAccountDTO.getDepartmentId(), user.getId());
|
||||
}
|
||||
|
||||
// 转换为VO并返回
|
||||
return convertToVO(user);
|
||||
}
|
||||
@@ -129,15 +166,6 @@ public class SuperAccountServiceImpl extends ServiceImpl<UserMapper, UserPO> imp
|
||||
if (superUpdateAccountDTO.getAvatarImageId() != null) {
|
||||
user.setAvatarImageId(superUpdateAccountDTO.getAvatarImageId());
|
||||
}
|
||||
if (superUpdateAccountDTO.getCompanyId() != null) {
|
||||
user.setCompanyId(superUpdateAccountDTO.getCompanyId());
|
||||
}
|
||||
if (superUpdateAccountDTO.getDepartmentId() != null) {
|
||||
user.setDepartmentId(superUpdateAccountDTO.getDepartmentId());
|
||||
}
|
||||
if (superUpdateAccountDTO.getPositionId() != null) {
|
||||
user.setPositionId(superUpdateAccountDTO.getPositionId());
|
||||
}
|
||||
if (StringUtils.hasText(superUpdateAccountDTO.getRole())) {
|
||||
user.setRole(superUpdateAccountDTO.getRole());
|
||||
}
|
||||
@@ -153,6 +181,36 @@ public class SuperAccountServiceImpl extends ServiceImpl<UserMapper, UserPO> imp
|
||||
// 保存更新
|
||||
this.updateById(user);
|
||||
|
||||
// 如果公司ID有更新,更新公司成员关系
|
||||
if (superUpdateAccountDTO.getCompanyId() != null) {
|
||||
// 删除旧的公司成员关系
|
||||
List<CompanyMemberVO> oldMembers = companyMemberService.getByUserId(user.getId());
|
||||
for (CompanyMemberVO old : oldMembers) {
|
||||
companyMemberService.removeByUserIdAndCompanyId(user.getId(), old.getCompanyId());
|
||||
}
|
||||
// 创建新的公司成员关系
|
||||
companyMemberService.create(user.getId(), superUpdateAccountDTO.getCompanyId(),
|
||||
CompanyMemberRole.member, superUpdateAccountDTO.getPositionId());
|
||||
}
|
||||
|
||||
// 如果职位有更新,更新公司成员
|
||||
if (superUpdateAccountDTO.getPositionId() != null && superUpdateAccountDTO.getCompanyId() != null) {
|
||||
CompanyMemberPO member = companyMemberService.getByUserIdAndCompanyId(
|
||||
user.getId(), superUpdateAccountDTO.getCompanyId());
|
||||
if (member != null) {
|
||||
companyMemberService.updatePosition(member.getId(), superUpdateAccountDTO.getPositionId());
|
||||
}
|
||||
}
|
||||
|
||||
// 如果部门有更新,更新部门成员
|
||||
if (superUpdateAccountDTO.getDepartmentId() != null) {
|
||||
DepartmentMemberPO existingMember = departmentMemberService.getByUserIdAndDepartmentId(
|
||||
user.getId(), superUpdateAccountDTO.getDepartmentId());
|
||||
if (existingMember == null) {
|
||||
departmentMemberService.addMember(superUpdateAccountDTO.getDepartmentId(), user.getId());
|
||||
}
|
||||
}
|
||||
|
||||
// 转换为VO并返回
|
||||
return convertToVO(user);
|
||||
}
|
||||
@@ -173,6 +231,18 @@ public class SuperAccountServiceImpl extends ServiceImpl<UserMapper, UserPO> imp
|
||||
user.setStatus(1); // 删除状态
|
||||
user.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
this.updateById(user);
|
||||
|
||||
// 删除所有公司成员关系
|
||||
List<CompanyMemberVO> companyMembers = companyMemberService.getByUserId(user.getId());
|
||||
for (CompanyMemberVO member : companyMembers) {
|
||||
companyMemberService.removeByUserIdAndCompanyId(user.getId(), member.getCompanyId());
|
||||
}
|
||||
|
||||
// 删除所有部门成员关系
|
||||
List<DepartmentMemberVO> deptMembers = departmentMemberService.getByUserId(user.getId());
|
||||
for (DepartmentMemberVO dm : deptMembers) {
|
||||
departmentMemberService.removeMember(dm.getDepartmentId(), user.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -245,17 +315,41 @@ public class SuperAccountServiceImpl extends ServiceImpl<UserMapper, UserPO> imp
|
||||
|
||||
// 公司ID
|
||||
if (filterDTO.getCompanyId() != null) {
|
||||
wrapper.eq(UserPO::getCompanyId, filterDTO.getCompanyId());
|
||||
// 需要通过公司成员表查询该公司的所有用户ID
|
||||
List<CompanyMemberVO> members = companyMemberService.getByCompanyId(filterDTO.getCompanyId());
|
||||
List<Long> userIds = members.stream().map(CompanyMemberVO::getUserId).collect(Collectors.toList());
|
||||
if (!userIds.isEmpty()) {
|
||||
wrapper.in(UserPO::getId, userIds);
|
||||
} else {
|
||||
wrapper.eq(UserPO::getId, -1L); // 无结果
|
||||
}
|
||||
}
|
||||
|
||||
// 部门ID
|
||||
if (filterDTO.getDepartmentId() != null) {
|
||||
wrapper.eq(UserPO::getDepartmentId, filterDTO.getDepartmentId());
|
||||
// 需要通过部门成员表查询该部门的用户ID
|
||||
List<DepartmentMemberVO> members = departmentMemberService.getByDepartmentId(filterDTO.getDepartmentId());
|
||||
List<Long> userIds = members.stream().map(DepartmentMemberVO::getUserId).collect(Collectors.toList());
|
||||
if (!userIds.isEmpty()) {
|
||||
wrapper.in(UserPO::getId, userIds);
|
||||
} else {
|
||||
wrapper.eq(UserPO::getId, -1L); // 无结果
|
||||
}
|
||||
}
|
||||
|
||||
// 岗位ID
|
||||
if (filterDTO.getPositionId() != null) {
|
||||
wrapper.eq(UserPO::getPositionId, filterDTO.getPositionId());
|
||||
// 需要通过公司成员表查询该岗位的用户ID
|
||||
var allMembers = companyMemberService.getByPositionId(filterDTO.getPositionId());
|
||||
List<Long> userIds = allMembers.stream()
|
||||
.filter(m -> filterDTO.getPositionId().equals(m.getPositionId()))
|
||||
.map(CompanyMemberVO::getUserId)
|
||||
.collect(Collectors.toList());
|
||||
if (!userIds.isEmpty()) {
|
||||
wrapper.in(UserPO::getId, userIds);
|
||||
} else {
|
||||
wrapper.eq(UserPO::getId, -1L); // 无结果
|
||||
}
|
||||
}
|
||||
|
||||
// 角色
|
||||
@@ -268,6 +362,11 @@ public class SuperAccountServiceImpl extends ServiceImpl<UserMapper, UserPO> imp
|
||||
wrapper.eq(UserPO::getStatus, filterDTO.getStatus());
|
||||
}
|
||||
|
||||
// 用户ID列表过滤
|
||||
if (filterDTO.getUserIds() != null && !filterDTO.getUserIds().isEmpty()) {
|
||||
wrapper.in(UserPO::getId, filterDTO.getUserIds());
|
||||
}
|
||||
|
||||
// 排除删除状态
|
||||
wrapper.ne(UserPO::getStatus, 1);
|
||||
|
||||
@@ -290,8 +389,37 @@ public class SuperAccountServiceImpl extends ServiceImpl<UserMapper, UserPO> imp
|
||||
// 设置角色名称
|
||||
accountVO.setRoleName(getRoleName(user.getRole()));
|
||||
|
||||
// TODO: 设置公司名称、部门名称、岗位名称等关联信息
|
||||
// 这里可以根据需要查询关联表获取详细信息
|
||||
// 设置公司名称(从公司成员表获取)
|
||||
List<CompanyMemberVO> companyMembers = companyMemberService.getByUserId(user.getId());
|
||||
if (!companyMembers.isEmpty()) {
|
||||
// 取第一个公司成员
|
||||
CompanyMemberVO companyMember = companyMembers.get(0);
|
||||
accountVO.setCompanyId(companyMember.getCompanyId());
|
||||
var company = companyService.getById(companyMember.getCompanyId());
|
||||
if (company != null) {
|
||||
accountVO.setCompanyName(company.getName());
|
||||
}
|
||||
// 设置职位ID和名称
|
||||
if (companyMember.getPositionId() != null) {
|
||||
accountVO.setPositionId(companyMember.getPositionId());
|
||||
PositionPO position = positionService.getById(companyMember.getPositionId());
|
||||
if (position != null) {
|
||||
accountVO.setPositionName(position.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 设置部门名称(逗号拼接所有部门)
|
||||
List<DepartmentMemberVO> deptMembers = departmentMemberService.getByUserId(user.getId());
|
||||
if (!deptMembers.isEmpty()) {
|
||||
String deptNames = deptMembers.stream()
|
||||
.map(DepartmentMemberVO::getDepartmentName)
|
||||
.filter(name -> name != null)
|
||||
.collect(Collectors.joining(","));
|
||||
accountVO.setDepartmentName(deptNames);
|
||||
// 设置第一个部门ID
|
||||
accountVO.setDepartmentId(deptMembers.get(0).getDepartmentId());
|
||||
}
|
||||
|
||||
return accountVO;
|
||||
}
|
||||
|
||||
+2
-10
@@ -32,17 +32,9 @@ public class CompanyDTO {
|
||||
@Schema(description = "公司地址", example = "北京市朝阳区xxx街道xxx号")
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 联系人
|
||||
*/
|
||||
@Schema(description = "联系人", example = "张三")
|
||||
private String contactPerson;
|
||||
|
||||
/**
|
||||
* 联系电话
|
||||
*/
|
||||
@Schema(description = "联系电话", example = "13800138000")
|
||||
private String contactPhone;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
|
||||
+16
-10
@@ -26,17 +26,9 @@ public class CreateCompanyDTO {
|
||||
@Schema(description = "公司地址", example = "北京市朝阳区xxx街道xxx号")
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 联系人
|
||||
*/
|
||||
@Schema(description = "联系人", example = "张三")
|
||||
private String contactPerson;
|
||||
|
||||
/**
|
||||
* 联系电话
|
||||
*/
|
||||
@Schema(description = "联系电话", example = "13800138000")
|
||||
private String contactPhone;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
@@ -44,6 +36,20 @@ public class CreateCompanyDTO {
|
||||
@Schema(description = "邮箱", example = "contact@company.com")
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 公司拥有者姓名
|
||||
*/
|
||||
@Schema(description = "公司拥有者姓名", example = "张三", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "公司拥有者姓名不能为空")
|
||||
private String ownerName;
|
||||
|
||||
/**
|
||||
* 公司拥有者电话(作为登录账号)
|
||||
*/
|
||||
@Schema(description = "公司拥有者电话", example = "13800138000", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "公司拥有者电话不能为空")
|
||||
private String ownerPhone;
|
||||
|
||||
/**
|
||||
* logo图片ID
|
||||
*/
|
||||
|
||||
+2
-10
@@ -26,17 +26,9 @@ public class UpdateCompanyDTO {
|
||||
@Schema(description = "公司地址", example = "北京市朝阳区xxx街道xxx号")
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 联系人
|
||||
*/
|
||||
@Schema(description = "联系人", example = "张三")
|
||||
private String contactPerson;
|
||||
|
||||
/**
|
||||
* 联系电话
|
||||
*/
|
||||
@Schema(description = "联系电话", example = "13800138000")
|
||||
private String contactPhone;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
|
||||
+6
-6
@@ -39,16 +39,16 @@ public class CompanyPO {
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 联系人
|
||||
* 公司拥有者姓名
|
||||
*/
|
||||
@TableField("contact_person")
|
||||
private String contactPerson;
|
||||
@TableField("owner_name")
|
||||
private String ownerName;
|
||||
|
||||
/**
|
||||
* 联系电话
|
||||
* 公司拥有者电话
|
||||
*/
|
||||
@TableField("contact_phone")
|
||||
private String contactPhone;
|
||||
@TableField("owner_phone")
|
||||
private String ownerPhone;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
|
||||
+10
-6
@@ -37,16 +37,20 @@ public class CompanyVO {
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 联系人
|
||||
* 公司拥有者姓名
|
||||
*/
|
||||
@Schema(description = "联系人", example = "张三")
|
||||
private String contactPerson;
|
||||
@Schema(description = "公司拥有者姓名", example = "张三")
|
||||
private String ownerName;
|
||||
|
||||
/**
|
||||
* 联系电话
|
||||
* 公司拥有者电话
|
||||
*/
|
||||
@Schema(description = "联系电话", example = "13800138000")
|
||||
private String contactPhone;
|
||||
@Schema(description = "公司拥有者电话", example = "13800138000")
|
||||
private String ownerPhone;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
|
||||
+42
-10
@@ -30,9 +30,15 @@ import top.xyquan.ecomdmbbackend.modules.org.companymenu.model.po.CompanyMenuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymenu.model.vo.CompanyMenuVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.menu.model.po.MenuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.menu.service.MenuService;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.user.service.UserService;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.user.model.po.UserPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.service.CompanyMemberService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.enums.CompanyMemberRole;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
@@ -54,11 +60,16 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, CompanyPO> im
|
||||
private final DepartmentService departmentService;
|
||||
private final PositionService positionService;
|
||||
private final MenuService menuService;
|
||||
private final UserService userService;
|
||||
private final CompanyMemberService companyMemberService;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
public CompanyServiceImpl(CurrentUserContext currentUserContext, MediaImageService mediaImageService,
|
||||
public CompanyServiceImpl(@Lazy CurrentUserContext currentUserContext, MediaImageService mediaImageService,
|
||||
PromotionFeeTypeService promotionFeeTypeService,
|
||||
CompanyMenuService companyMenuService, DepartmentService departmentService,
|
||||
PositionService positionService, MenuService menuService) {
|
||||
PositionService positionService, MenuService menuService,
|
||||
@Lazy UserService userService, @Lazy CompanyMemberService companyMemberService,
|
||||
PasswordEncoder passwordEncoder) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.mediaImageService = mediaImageService;
|
||||
this.promotionFeeTypeService = promotionFeeTypeService;
|
||||
@@ -66,6 +77,9 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, CompanyPO> im
|
||||
this.departmentService = departmentService;
|
||||
this.positionService = positionService;
|
||||
this.menuService = menuService;
|
||||
this.userService = userService;
|
||||
this.companyMemberService = companyMemberService;
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,13 +116,37 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, CompanyPO> im
|
||||
}
|
||||
|
||||
// 设置创建人ID
|
||||
company.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
Long creatorId = currentUserContext.getCurrentUserId();
|
||||
company.setCreateBy(creatorId);
|
||||
|
||||
// 保存公司
|
||||
this.save(company);
|
||||
|
||||
// 创建公司拥有者用户
|
||||
UserPO ownerUser = null;
|
||||
LambdaQueryWrapper<UserPO> userWrapper = new LambdaQueryWrapper<>();
|
||||
userWrapper.eq(UserPO::getPhone, createCompanyDTO.getOwnerPhone());
|
||||
ownerUser = userService.getOne(userWrapper);
|
||||
if (ownerUser == null) {
|
||||
// 手机号未注册,创建新用户
|
||||
ownerUser = new UserPO();
|
||||
ownerUser.setLoginCode(createCompanyDTO.getOwnerPhone());
|
||||
ownerUser.setPhone(createCompanyDTO.getOwnerPhone());
|
||||
ownerUser.setRealName(createCompanyDTO.getOwnerName());
|
||||
ownerUser.setPassword(passwordEncoder.encode("123456")); // 默认密码
|
||||
ownerUser.setRole("user");
|
||||
ownerUser.setStatus(0);
|
||||
ownerUser.setPwdSecurityLevel(1);
|
||||
ownerUser.setPwdUpdateTime(LocalDateTime.now());
|
||||
ownerUser.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
userService.save(ownerUser);
|
||||
}
|
||||
|
||||
// 将拥有者加入公司成员(owner角色)
|
||||
companyMemberService.create(ownerUser.getId(), company.getId(), CompanyMemberRole.owner, null);
|
||||
|
||||
// 初始化推广费类型数据
|
||||
promotionFeeTypeService.initPromotionFeeTypeForCompany(company.getId());
|
||||
promotionFeeTypeService.initPromotionFeeTypeForCompany(company.getId(), creatorId);
|
||||
|
||||
// 初始化公司菜单(非超级菜单)
|
||||
initCompanyMenus(company.getId());
|
||||
@@ -203,12 +241,6 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, CompanyPO> im
|
||||
if (filterDTO.getName() != null && StringUtils.hasText(filterDTO.getName())) {
|
||||
wrapper.like(CompanyPO::getName, filterDTO.getName());
|
||||
}
|
||||
if (filterDTO.getContactPerson() != null && StringUtils.hasText(filterDTO.getContactPerson())) {
|
||||
wrapper.like(CompanyPO::getContactPerson, filterDTO.getContactPerson());
|
||||
}
|
||||
if (filterDTO.getContactPhone() != null && StringUtils.hasText(filterDTO.getContactPhone())) {
|
||||
wrapper.eq(CompanyPO::getContactPhone, filterDTO.getContactPhone());
|
||||
}
|
||||
if (filterDTO.getEmail() != null && StringUtils.hasText(filterDTO.getEmail())) {
|
||||
wrapper.eq(CompanyPO::getEmail, filterDTO.getEmail());
|
||||
}
|
||||
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.org.companymember.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.model.dto.CreateCompanyMemberDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.model.dto.UpdateCompanyMemberDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.model.vo.CompanyMemberVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.enums.CompanyMemberRole;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.service.CompanyMemberService;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequireRole;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 公司成员控制器
|
||||
*/
|
||||
@Tag(name = "组织-公司成员管理", description = "公司成员的增删改查接口")
|
||||
@RestController
|
||||
@RequestMapping("/company-member")
|
||||
public class CompanyMemberController {
|
||||
|
||||
private final CompanyMemberService companyMemberService;
|
||||
private final CurrentUserContext currentUserContext;
|
||||
|
||||
public CompanyMemberController(CompanyMemberService companyMemberService,
|
||||
CurrentUserContext currentUserContext) {
|
||||
this.companyMemberService = companyMemberService;
|
||||
this.currentUserContext = currentUserContext;
|
||||
}
|
||||
|
||||
@Operation(summary = "创建公司成员", description = "创建新的公司成员")
|
||||
@PostMapping("/create")
|
||||
@RequireRole(description = "创建公司成员", allowUser = false)
|
||||
public ApiResponse<CompanyMemberVO> create(@Valid @RequestBody CreateCompanyMemberDTO dto) {
|
||||
CompanyMemberVO vo = companyMemberService.create(dto);
|
||||
return ApiResponse.success(vo);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新成员职位", description = "更新成员的职位")
|
||||
@PutMapping("/update-position/{memberId}")
|
||||
@RequireRole(description = "更新成员职位", allowUser = false)
|
||||
public ApiResponse<CompanyMemberVO> updatePosition(
|
||||
@Parameter(description = "成员ID") @PathVariable Long memberId,
|
||||
@RequestParam Long positionId) {
|
||||
CompanyMemberVO vo = companyMemberService.updatePosition(memberId, positionId);
|
||||
return ApiResponse.success(vo);
|
||||
}
|
||||
|
||||
@Operation(summary = "变更成员角色", description = "变更成员的角色")
|
||||
@PutMapping("/change-role/{memberId}")
|
||||
@RequireRole(description = "变更成员角色", allowUser = false)
|
||||
public ApiResponse<CompanyMemberVO> changeRole(
|
||||
@Parameter(description = "成员ID") @PathVariable Long memberId,
|
||||
@RequestParam String role) {
|
||||
CompanyMemberVO vo = companyMemberService.changeRole(memberId, CompanyMemberRole.fromCode(role));
|
||||
return ApiResponse.success(vo);
|
||||
}
|
||||
|
||||
@Operation(summary = "移除成员", description = "移除公司成员")
|
||||
@DeleteMapping("/remove/{memberId}")
|
||||
@RequireRole(description = "移除成员", allowUser = false)
|
||||
public ApiResponse<Void> remove(@Parameter(description = "成员ID") @PathVariable Long memberId) {
|
||||
companyMemberService.remove(memberId);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "获取公司所有成员", description = "获取指定公司的所有成员(含用户信息、职位名称)")
|
||||
@GetMapping("/company/{companyId}")
|
||||
@RequireRole(description = "查询公司成员", allowUser = false)
|
||||
public ApiResponse<List<CompanyMemberVO>> getByCompanyId(
|
||||
@Parameter(description = "公司ID") @PathVariable Long companyId) {
|
||||
List<CompanyMemberVO> list = companyMemberService.getByCompanyId(companyId);
|
||||
return ApiResponse.success(list);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取用户所属公司列表", description = "获取当前用户所属的所有公司列表")
|
||||
@GetMapping("/user/{userId}")
|
||||
@RequireRole(description = "查询用户公司列表")
|
||||
public ApiResponse<List<CompanyMemberVO>> getByUserId(
|
||||
@Parameter(description = "用户ID") @PathVariable Long userId) {
|
||||
List<CompanyMemberVO> list = companyMemberService.getByUserId(userId);
|
||||
return ApiResponse.success(list);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取当前用户的公司成员信息", description = "获取当前用户在公司中的成员信息")
|
||||
@GetMapping("/current")
|
||||
public ApiResponse<CompanyMemberVO> getCurrentMember() {
|
||||
Long userId = currentUserContext.getCurrentUserId();
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
var member = companyMemberService.getByUserIdAndCompanyId(userId, companyId);
|
||||
if (member != null) {
|
||||
return ApiResponse.success(companyMemberService.convertToVO(member));
|
||||
}
|
||||
return ApiResponse.fail("用户不属于当前公司");
|
||||
}
|
||||
|
||||
@Operation(summary = "获取当前用户所有公司成员信息", description = "获取当前用户所有公司成员信息")
|
||||
@GetMapping("/current/all")
|
||||
public ApiResponse<List<CompanyMemberVO>> getCurrentUserAllMembers() {
|
||||
Long userId = currentUserContext.getCurrentUserId();
|
||||
List<CompanyMemberVO> list = companyMemberService.getByUserId(userId);
|
||||
return ApiResponse.success(list);
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.org.companymember.enums;
|
||||
|
||||
/**
|
||||
* 公司成员角色枚举
|
||||
*/
|
||||
public enum CompanyMemberRole {
|
||||
|
||||
owner("owner", "公司拥有者"),
|
||||
member("member", "成员");
|
||||
|
||||
private final String code;
|
||||
private final String description;
|
||||
|
||||
CompanyMemberRole(String code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public static CompanyMemberRole fromCode(String code) {
|
||||
if (code == null) {
|
||||
return member;
|
||||
}
|
||||
for (CompanyMemberRole role : values()) {
|
||||
if (role.code.equals(code)) {
|
||||
return role;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("无效的角色编码: " + code);
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.org.companymember.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.model.po.CompanyMemberPO;
|
||||
|
||||
/**
|
||||
* 公司成员Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface CompanyMemberMapper extends BaseMapper<CompanyMemberPO> {
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.org.companymember.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 创建公司成员DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "创建公司成员DTO")
|
||||
public class CreateCompanyMemberDTO {
|
||||
|
||||
@Schema(description = "用户ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "用户ID不能为空")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "公司ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "公司ID不能为空")
|
||||
private Long companyId;
|
||||
|
||||
@Schema(description = "角色: owner=公司拥有者, member=成员", example = "member")
|
||||
@Pattern(regexp = "^(owner|member)$", message = "角色必须是owner或member")
|
||||
private String role = "member";
|
||||
|
||||
@Schema(description = "职位ID", example = "1")
|
||||
private Long positionId;
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.org.companymember.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 更新公司成员DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "更新公司成员DTO")
|
||||
public class UpdateCompanyMemberDTO {
|
||||
|
||||
@Schema(description = "职位ID", example = "1")
|
||||
private Long positionId;
|
||||
|
||||
@Schema(description = "角色: owner=公司拥有者, member=成员", example = "member")
|
||||
@Pattern(regexp = "^(owner|member)$", message = "角色必须是owner或member")
|
||||
private String role;
|
||||
|
||||
@Schema(description = "状态: 0=禁用, 1=正常", example = "1")
|
||||
private Integer status;
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.org.companymember.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.enums.CompanyMemberRole;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 公司成员实体
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("org_company_member")
|
||||
public class CompanyMemberPO {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
@TableField("user_id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 公司ID
|
||||
*/
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
|
||||
/**
|
||||
* 角色: owner=公司拥有者, member=成员
|
||||
*/
|
||||
@TableField("role")
|
||||
private CompanyMemberRole role;
|
||||
|
||||
/**
|
||||
* 职位ID(可空)
|
||||
*/
|
||||
@TableField("position_id")
|
||||
private Long positionId;
|
||||
|
||||
/**
|
||||
* 状态: 0=禁用, 1=正常
|
||||
*/
|
||||
@TableField("status")
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
@TableField("update_by")
|
||||
private Long updateBy;
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.org.companymember.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 公司成员VO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "公司成员VO")
|
||||
public class CompanyMemberVO {
|
||||
|
||||
@Schema(description = "成员ID", example = "1")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "用户ID", example = "1")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "公司ID", example = "1")
|
||||
private Long companyId;
|
||||
|
||||
@Schema(description = "公司名称", example = "测试公司")
|
||||
private String companyName;
|
||||
|
||||
@Schema(description = "角色: owner=公司拥有者, member=成员", example = "owner")
|
||||
private String role;
|
||||
|
||||
@Schema(description = "角色名称", example = "公司拥有者")
|
||||
private String roleName;
|
||||
|
||||
@Schema(description = "职位ID", example = "1")
|
||||
private Long positionId;
|
||||
|
||||
@Schema(description = "职位名称", example = "技术总监")
|
||||
private String positionName;
|
||||
|
||||
@Schema(description = "状态: 0=禁用, 1=正常", example = "1")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "状态名称", example = "正常")
|
||||
private String statusName;
|
||||
|
||||
@Schema(description = "用户姓名", example = "张三")
|
||||
private String realName;
|
||||
|
||||
@Schema(description = "手机号码", example = "13800138000")
|
||||
private String phone;
|
||||
|
||||
@Schema(description = "登录账号", example = "admin001")
|
||||
private String loginCode;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.org.companymember.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.enums.CompanyMemberRole;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.model.dto.CreateCompanyMemberDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.model.dto.UpdateCompanyMemberDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.model.po.CompanyMemberPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.model.vo.CompanyMemberVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 公司成员服务接口
|
||||
*/
|
||||
public interface CompanyMemberService extends IService<CompanyMemberPO> {
|
||||
|
||||
/**
|
||||
* 创建成员
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param companyId 公司ID
|
||||
* @param role 角色: owner=公司拥有者, member=成员
|
||||
* @param positionId 职位ID(可空)
|
||||
* @return 成员VO
|
||||
*/
|
||||
CompanyMemberVO create(Long userId, Long companyId, CompanyMemberRole role, Long positionId);
|
||||
|
||||
/**
|
||||
* 创建成员(DTO)
|
||||
*
|
||||
* @param dto 创建DTO
|
||||
* @return 成员VO
|
||||
*/
|
||||
CompanyMemberVO create(CreateCompanyMemberDTO dto);
|
||||
|
||||
/**
|
||||
* 更新成员职位
|
||||
*
|
||||
* @param memberId 成员ID
|
||||
* @param positionId 职位ID
|
||||
* @return 成员VO
|
||||
*/
|
||||
CompanyMemberVO updatePosition(Long memberId, Long positionId);
|
||||
|
||||
/**
|
||||
* 变更成员角色
|
||||
*
|
||||
* @param memberId 成员ID
|
||||
* @param role 新角色: owner=公司拥有者, member=成员
|
||||
* @return 成员VO
|
||||
*/
|
||||
CompanyMemberVO changeRole(Long memberId, CompanyMemberRole role);
|
||||
|
||||
/**
|
||||
* 移除成员
|
||||
*
|
||||
* @param memberId 成员ID
|
||||
*/
|
||||
void remove(Long memberId);
|
||||
|
||||
/**
|
||||
* 获取公司所有成员(含用户信息、职位名称)
|
||||
*
|
||||
* @param companyId 公司ID
|
||||
* @return 成员列表
|
||||
*/
|
||||
List<CompanyMemberVO> getByCompanyId(Long companyId);
|
||||
|
||||
/**
|
||||
* 获取用户所属公司列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 公司列表
|
||||
*/
|
||||
List<CompanyMemberVO> getByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 获取用户所属公司列表(按加入时间倒序,用于登录时选择公司)
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 公司列表(按createTime倒序)
|
||||
*/
|
||||
List<CompanyMemberVO> getByUserIdOrderByCreateTime(Long userId);
|
||||
|
||||
/**
|
||||
* 根据职位ID查询成员列表
|
||||
*
|
||||
* @param positionId 职位ID
|
||||
* @return 成员列表
|
||||
*/
|
||||
List<CompanyMemberVO> getByPositionId(Long positionId);
|
||||
|
||||
/**
|
||||
* 根据用户ID和公司ID获取成员
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param companyId 公司ID
|
||||
* @return 成员PO
|
||||
*/
|
||||
CompanyMemberPO getByUserIdAndCompanyId(Long userId, Long companyId);
|
||||
|
||||
/**
|
||||
* 根据用户ID和公司ID删除成员
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param companyId 公司ID
|
||||
*/
|
||||
void removeByUserIdAndCompanyId(Long userId, Long companyId);
|
||||
|
||||
/**
|
||||
* 判断用户是否为该公司拥有者
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param companyId 公司ID
|
||||
* @return 是否为拥有者
|
||||
*/
|
||||
boolean isOwner(Long userId, Long companyId);
|
||||
|
||||
/**
|
||||
* 将成员PO转换为VO
|
||||
*
|
||||
* @param member 成员PO
|
||||
* @return 成员VO
|
||||
*/
|
||||
CompanyMemberVO convertToVO(CompanyMemberPO member);
|
||||
}
|
||||
+248
@@ -0,0 +1,248 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.org.companymember.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.enums.CompanyMemberRole;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.mapper.CompanyMemberMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.model.dto.CreateCompanyMemberDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.model.po.CompanyMemberPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.model.vo.CompanyMemberVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.service.CompanyMemberService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.company.model.po.CompanyPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.company.service.CompanyService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.position.model.po.PositionPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.position.service.PositionService;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.user.mapper.UserMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.user.model.po.UserPO;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 公司成员服务实现类
|
||||
*/
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class CompanyMemberServiceImpl extends ServiceImpl<CompanyMemberMapper, CompanyMemberPO> implements CompanyMemberService {
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final CompanyService companyService;
|
||||
private final PositionService positionService;
|
||||
private final UserMapper userMapper;
|
||||
|
||||
public CompanyMemberServiceImpl(@Lazy CurrentUserContext currentUserContext,
|
||||
@Lazy CompanyService companyService,
|
||||
PositionService positionService,
|
||||
UserMapper userMapper) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.companyService = companyService;
|
||||
this.positionService = positionService;
|
||||
this.userMapper = userMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompanyMemberVO create(Long userId, Long companyId, CompanyMemberRole role, Long positionId) {
|
||||
CreateCompanyMemberDTO dto = new CreateCompanyMemberDTO();
|
||||
dto.setUserId(userId);
|
||||
dto.setCompanyId(companyId);
|
||||
dto.setRole(role != null ? role.getCode() : CompanyMemberRole.member.getCode());
|
||||
dto.setPositionId(positionId);
|
||||
return create(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompanyMemberVO create(CreateCompanyMemberDTO dto) {
|
||||
// 检查是否已存在
|
||||
LambdaQueryWrapper<CompanyMemberPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(CompanyMemberPO::getUserId, dto.getUserId())
|
||||
.eq(CompanyMemberPO::getCompanyId, dto.getCompanyId());
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("该用户已是公司成员");
|
||||
}
|
||||
|
||||
CompanyMemberPO member = new CompanyMemberPO();
|
||||
BeanUtils.copyProperties(dto, member);
|
||||
member.setStatus(1);
|
||||
member.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
this.save(member);
|
||||
return convertToVO(member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompanyMemberVO updatePosition(Long memberId, Long positionId) {
|
||||
CompanyMemberPO member = super.getById(memberId);
|
||||
if (member == null) {
|
||||
throw new BusinessException("成员不存在");
|
||||
}
|
||||
|
||||
member.setPositionId(positionId);
|
||||
member.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
this.updateById(member);
|
||||
|
||||
return convertToVO(member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompanyMemberVO changeRole(Long memberId, CompanyMemberRole role) {
|
||||
CompanyMemberPO member = super.getById(memberId);
|
||||
if (member == null) {
|
||||
throw new BusinessException("成员不存在");
|
||||
}
|
||||
|
||||
member.setRole(role);
|
||||
member.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
this.updateById(member);
|
||||
|
||||
return convertToVO(member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Long memberId) {
|
||||
CompanyMemberPO member = super.getById(memberId);
|
||||
if (member == null) {
|
||||
throw new BusinessException("成员不存在");
|
||||
}
|
||||
|
||||
// 不允许删除唯一的owner
|
||||
if (member.getRole() == CompanyMemberRole.owner) {
|
||||
LambdaQueryWrapper<CompanyMemberPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(CompanyMemberPO::getCompanyId, member.getCompanyId())
|
||||
.eq(CompanyMemberPO::getRole, CompanyMemberRole.owner)
|
||||
.eq(CompanyMemberPO::getStatus, 1);
|
||||
long ownerCount = this.count(wrapper);
|
||||
if (ownerCount <= 1) {
|
||||
throw new BusinessException("不能删除公司唯一的拥有者");
|
||||
}
|
||||
}
|
||||
|
||||
// 逻辑删除
|
||||
member.setStatus(0);
|
||||
member.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
this.updateById(member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CompanyMemberVO> getByCompanyId(Long companyId) {
|
||||
LambdaQueryWrapper<CompanyMemberPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(CompanyMemberPO::getCompanyId, companyId)
|
||||
.eq(CompanyMemberPO::getStatus, 1);
|
||||
List<CompanyMemberPO> members = this.list(wrapper);
|
||||
|
||||
return members.stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CompanyMemberVO> getByUserId(Long userId) {
|
||||
LambdaQueryWrapper<CompanyMemberPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(CompanyMemberPO::getUserId, userId)
|
||||
.eq(CompanyMemberPO::getStatus, 1);
|
||||
List<CompanyMemberPO> members = this.list(wrapper);
|
||||
|
||||
return members.stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CompanyMemberVO> getByUserIdOrderByCreateTime(Long userId) {
|
||||
LambdaQueryWrapper<CompanyMemberPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(CompanyMemberPO::getUserId, userId)
|
||||
.eq(CompanyMemberPO::getStatus, 1)
|
||||
.orderByDesc(CompanyMemberPO::getCreateTime);
|
||||
List<CompanyMemberPO> members = this.list(wrapper);
|
||||
|
||||
return members.stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CompanyMemberVO> getByPositionId(Long positionId) {
|
||||
if (positionId == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
LambdaQueryWrapper<CompanyMemberPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(CompanyMemberPO::getPositionId, positionId)
|
||||
.eq(CompanyMemberPO::getStatus, 1);
|
||||
List<CompanyMemberPO> members = this.list(wrapper);
|
||||
|
||||
return members.stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompanyMemberPO getByUserIdAndCompanyId(Long userId, Long companyId) {
|
||||
LambdaQueryWrapper<CompanyMemberPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(CompanyMemberPO::getUserId, userId)
|
||||
.eq(CompanyMemberPO::getCompanyId, companyId)
|
||||
.eq(CompanyMemberPO::getStatus, 1);
|
||||
return this.getOne(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeByUserIdAndCompanyId(Long userId, Long companyId) {
|
||||
CompanyMemberPO member = getByUserIdAndCompanyId(userId, companyId);
|
||||
if (member != null) {
|
||||
member.setStatus(0);
|
||||
member.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
this.updateById(member);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOwner(Long userId, Long companyId) {
|
||||
CompanyMemberPO member = getByUserIdAndCompanyId(userId, companyId);
|
||||
return member != null && member.getRole() == CompanyMemberRole.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompanyMemberVO convertToVO(CompanyMemberPO member) {
|
||||
CompanyMemberVO vo = new CompanyMemberVO();
|
||||
BeanUtils.copyProperties(member, vo);
|
||||
|
||||
// 设置状态名称
|
||||
vo.setStatusName(member.getStatus() != null && member.getStatus() == 1 ? "正常" : "禁用");
|
||||
|
||||
// 设置角色名称
|
||||
vo.setRole(member.getRole() != null ? member.getRole().getDescription() : "成员");
|
||||
|
||||
// 设置公司名称
|
||||
if (member.getCompanyId() != null) {
|
||||
CompanyPO company = companyService.getById(member.getCompanyId());
|
||||
if (company != null) {
|
||||
vo.setCompanyName(company.getName());
|
||||
}
|
||||
}
|
||||
|
||||
// 设置职位名称
|
||||
if (member.getPositionId() != null) {
|
||||
PositionPO position = positionService.getById(member.getPositionId());
|
||||
if (position != null) {
|
||||
vo.setPositionName(position.getName());
|
||||
}
|
||||
}
|
||||
|
||||
// 设置用户信息
|
||||
if (member.getUserId() != null) {
|
||||
UserPO user = userMapper.selectById(member.getUserId());
|
||||
if (user != null) {
|
||||
vo.setRealName(user.getRealName());
|
||||
vo.setPhone(user.getPhone());
|
||||
vo.setLoginCode(user.getLoginCode());
|
||||
}
|
||||
}
|
||||
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.org.departmentmember.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.departmentmember.model.dto.AddDepartmentMemberDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.departmentmember.model.dto.RemoveDepartmentMemberDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.departmentmember.model.vo.DepartmentMemberVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.departmentmember.service.DepartmentMemberService;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequireRole;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 部门成员控制器
|
||||
*/
|
||||
@Tag(name = "组织-部门成员管理", description = "部门成员的增删改查接口")
|
||||
@RestController
|
||||
@RequestMapping("/department-member")
|
||||
public class DepartmentMemberController {
|
||||
|
||||
private final DepartmentMemberService departmentMemberService;
|
||||
|
||||
public DepartmentMemberController(DepartmentMemberService departmentMemberService) {
|
||||
this.departmentMemberService = departmentMemberService;
|
||||
}
|
||||
|
||||
@Operation(summary = "添加部门成员", description = "添加成员到部门")
|
||||
@PostMapping("/add")
|
||||
@RequireRole(description = "添加部门成员", allowUser = false)
|
||||
public ApiResponse<DepartmentMemberVO> addMember(@Valid @RequestBody AddDepartmentMemberDTO dto) {
|
||||
DepartmentMemberVO vo = departmentMemberService.addMember(dto);
|
||||
return ApiResponse.success(vo);
|
||||
}
|
||||
|
||||
@Operation(summary = "移除部门成员", description = "从部门移除成员")
|
||||
@PostMapping("/remove")
|
||||
@RequireRole(description = "移除部门成员", allowUser = false)
|
||||
public ApiResponse<Void> removeMember(@Valid @RequestBody RemoveDepartmentMemberDTO dto) {
|
||||
departmentMemberService.removeMember(dto.getDepartmentId(), dto.getUserId());
|
||||
return ApiResponse.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "获取部门所有成员", description = "获取指定部门的所有成员(含用户信息)")
|
||||
@GetMapping("/department/{departmentId}")
|
||||
@RequireRole(description = "查询部门成员", allowUser = false)
|
||||
public ApiResponse<List<DepartmentMemberVO>> getByDepartmentId(
|
||||
@Parameter(description = "部门ID") @PathVariable Long departmentId) {
|
||||
List<DepartmentMemberVO> list = departmentMemberService.getByDepartmentId(departmentId);
|
||||
return ApiResponse.success(list);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取用户所属部门列表", description = "获取用户所属的所有部门列表")
|
||||
@GetMapping("/user/{userId}")
|
||||
@RequireRole(description = "查询用户部门列表")
|
||||
public ApiResponse<List<DepartmentMemberVO>> getByUserId(
|
||||
@Parameter(description = "用户ID") @PathVariable Long userId) {
|
||||
List<DepartmentMemberVO> list = departmentMemberService.getByUserId(userId);
|
||||
return ApiResponse.success(list);
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.org.departmentmember.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.departmentmember.model.po.DepartmentMemberPO;
|
||||
|
||||
/**
|
||||
* 部门成员Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface DepartmentMemberMapper extends BaseMapper<DepartmentMemberPO> {
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.org.departmentmember.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 添加部门成员DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "添加部门成员DTO")
|
||||
public class AddDepartmentMemberDTO {
|
||||
|
||||
@Schema(description = "部门ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "部门ID不能为空")
|
||||
private Long departmentId;
|
||||
|
||||
@Schema(description = "用户ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "用户ID不能为空")
|
||||
private Long userId;
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.org.departmentmember.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 移除部门成员DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "移除部门成员DTO")
|
||||
public class RemoveDepartmentMemberDTO {
|
||||
|
||||
@Schema(description = "部门ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "部门ID不能为空")
|
||||
private Long departmentId;
|
||||
|
||||
@Schema(description = "用户ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "用户ID不能为空")
|
||||
private Long userId;
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.org.departmentmember.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 部门成员实体
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("org_department_member")
|
||||
public class DepartmentMemberPO {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
@TableField("user_id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 部门ID
|
||||
*/
|
||||
@TableField("department_id")
|
||||
private Long departmentId;
|
||||
|
||||
/**
|
||||
* 状态: 0=禁用, 1=正常
|
||||
*/
|
||||
@TableField("status")
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
@TableField("update_by")
|
||||
private Long updateBy;
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.org.departmentmember.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 部门成员VO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "部门成员VO")
|
||||
public class DepartmentMemberVO {
|
||||
|
||||
@Schema(description = "成员ID", example = "1")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "用户ID", example = "1")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "部门ID", example = "1")
|
||||
private Long departmentId;
|
||||
|
||||
@Schema(description = "部门名称", example = "技术部")
|
||||
private String departmentName;
|
||||
|
||||
@Schema(description = "状态: 0=禁用, 1=正常", example = "1")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "状态名称", example = "正常")
|
||||
private String statusName;
|
||||
|
||||
@Schema(description = "用户姓名", example = "张三")
|
||||
private String realName;
|
||||
|
||||
@Schema(description = "手机号码", example = "13800138000")
|
||||
private String phone;
|
||||
|
||||
@Schema(description = "登录账号", example = "admin001")
|
||||
private String loginCode;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.org.departmentmember.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.departmentmember.model.dto.AddDepartmentMemberDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.departmentmember.model.po.DepartmentMemberPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.departmentmember.model.vo.DepartmentMemberVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 部门成员服务接口
|
||||
*/
|
||||
public interface DepartmentMemberService extends IService<DepartmentMemberPO> {
|
||||
|
||||
/**
|
||||
* 添加成员到部门
|
||||
*
|
||||
* @param departmentId 部门ID
|
||||
* @param userId 用户ID
|
||||
* @return 成员VO
|
||||
*/
|
||||
DepartmentMemberVO addMember(Long departmentId, Long userId);
|
||||
|
||||
/**
|
||||
* 添加成员(DTO方式)
|
||||
*
|
||||
* @param dto 添加DTO
|
||||
* @return 成员VO
|
||||
*/
|
||||
DepartmentMemberVO addMember(AddDepartmentMemberDTO dto);
|
||||
|
||||
/**
|
||||
* 从部门移除成员
|
||||
*
|
||||
* @param departmentId 部门ID
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
void removeMember(Long departmentId, Long userId);
|
||||
|
||||
/**
|
||||
* 获取部门所有成员(含用户信息)
|
||||
*
|
||||
* @param departmentId 部门ID
|
||||
* @return 成员列表
|
||||
*/
|
||||
List<DepartmentMemberVO> getByDepartmentId(Long departmentId);
|
||||
|
||||
/**
|
||||
* 获取用户所属部门列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 部门列表
|
||||
*/
|
||||
List<DepartmentMemberVO> getByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户ID和部门ID获取成员
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param departmentId 部门ID
|
||||
* @return 成员PO
|
||||
*/
|
||||
DepartmentMemberPO getByUserIdAndDepartmentId(Long userId, Long departmentId);
|
||||
|
||||
/**
|
||||
* 检查用户是否属于指定部门
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param departmentId 部门ID
|
||||
* @return 是否属于
|
||||
*/
|
||||
boolean isMember(Long userId, Long departmentId);
|
||||
|
||||
/**
|
||||
* 将成员PO转换为VO
|
||||
*
|
||||
* @param member 成员PO
|
||||
* @return 成员VO
|
||||
*/
|
||||
DepartmentMemberVO convertToVO(DepartmentMemberPO member);
|
||||
}
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.org.departmentmember.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.departmentmember.mapper.DepartmentMemberMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.departmentmember.model.dto.AddDepartmentMemberDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.departmentmember.model.po.DepartmentMemberPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.departmentmember.model.vo.DepartmentMemberVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.departmentmember.service.DepartmentMemberService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.department.model.po.DepartmentPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.department.service.DepartmentService;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.user.mapper.UserMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.user.model.po.UserPO;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 部门成员服务实现类
|
||||
*/
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class DepartmentMemberServiceImpl extends ServiceImpl<DepartmentMemberMapper, DepartmentMemberPO> implements DepartmentMemberService {
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final DepartmentService departmentService;
|
||||
private final UserMapper userMapper;
|
||||
|
||||
public DepartmentMemberServiceImpl(@Lazy CurrentUserContext currentUserContext,
|
||||
DepartmentService departmentService,
|
||||
UserMapper userMapper) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.departmentService = departmentService;
|
||||
this.userMapper = userMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DepartmentMemberVO addMember(Long departmentId, Long userId) {
|
||||
AddDepartmentMemberDTO dto = new AddDepartmentMemberDTO();
|
||||
dto.setDepartmentId(departmentId);
|
||||
dto.setUserId(userId);
|
||||
return addMember(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DepartmentMemberVO addMember(AddDepartmentMemberDTO dto) {
|
||||
// 检查是否已存在
|
||||
LambdaQueryWrapper<DepartmentMemberPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(DepartmentMemberPO::getUserId, dto.getUserId())
|
||||
.eq(DepartmentMemberPO::getDepartmentId, dto.getDepartmentId());
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("该用户已是部门成员");
|
||||
}
|
||||
|
||||
DepartmentMemberPO member = new DepartmentMemberPO();
|
||||
member.setUserId(dto.getUserId());
|
||||
member.setDepartmentId(dto.getDepartmentId());
|
||||
member.setStatus(1);
|
||||
member.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
this.save(member);
|
||||
return convertToVO(member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeMember(Long departmentId, Long userId) {
|
||||
DepartmentMemberPO member = getByUserIdAndDepartmentId(userId, departmentId);
|
||||
if (member == null) {
|
||||
throw new BusinessException("成员不存在");
|
||||
}
|
||||
|
||||
// 逻辑删除
|
||||
member.setStatus(0);
|
||||
member.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
this.updateById(member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DepartmentMemberVO> getByDepartmentId(Long departmentId) {
|
||||
LambdaQueryWrapper<DepartmentMemberPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(DepartmentMemberPO::getDepartmentId, departmentId)
|
||||
.eq(DepartmentMemberPO::getStatus, 1);
|
||||
List<DepartmentMemberPO> members = this.list(wrapper);
|
||||
|
||||
return members.stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DepartmentMemberVO> getByUserId(Long userId) {
|
||||
LambdaQueryWrapper<DepartmentMemberPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(DepartmentMemberPO::getUserId, userId)
|
||||
.eq(DepartmentMemberPO::getStatus, 1);
|
||||
List<DepartmentMemberPO> members = this.list(wrapper);
|
||||
|
||||
return members.stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DepartmentMemberPO getByUserIdAndDepartmentId(Long userId, Long departmentId) {
|
||||
LambdaQueryWrapper<DepartmentMemberPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(DepartmentMemberPO::getUserId, userId)
|
||||
.eq(DepartmentMemberPO::getDepartmentId, departmentId)
|
||||
.eq(DepartmentMemberPO::getStatus, 1);
|
||||
return this.getOne(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMember(Long userId, Long departmentId) {
|
||||
return getByUserIdAndDepartmentId(userId, departmentId) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DepartmentMemberVO convertToVO(DepartmentMemberPO member) {
|
||||
DepartmentMemberVO vo = new DepartmentMemberVO();
|
||||
BeanUtils.copyProperties(member, vo);
|
||||
|
||||
// 设置状态名称
|
||||
vo.setStatusName(member.getStatus() != null && member.getStatus() == 1 ? "正常" : "禁用");
|
||||
|
||||
// 设置部门名称
|
||||
if (member.getDepartmentId() != null) {
|
||||
DepartmentPO department = departmentService.getById(member.getDepartmentId());
|
||||
if (department != null) {
|
||||
vo.setDepartmentName(department.getName());
|
||||
}
|
||||
}
|
||||
|
||||
// 设置用户信息
|
||||
if (member.getUserId() != null) {
|
||||
UserPO user = userMapper.selectById(member.getUserId());
|
||||
if (user != null) {
|
||||
vo.setRealName(user.getRealName());
|
||||
vo.setPhone(user.getPhone());
|
||||
vo.setLoginCode(user.getLoginCode());
|
||||
}
|
||||
}
|
||||
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
+27
-9
@@ -1,6 +1,9 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.menu.service.impl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.enums.CompanyMemberRole;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.service.CompanyMemberService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.model.po.CompanyMemberPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymenu.service.CompanyMenuService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.position.service.PositionCompanyMenuService;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.user.model.po.UserPO;
|
||||
@@ -9,7 +12,7 @@ import top.xyquan.ecomdmbbackend.modules.sys.menu.model.vo.UserMenuVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.menu.service.MenuService;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.menu.service.UserMenuService;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.user.service.UserService;
|
||||
import top.xyquan.ecomdmbbackend.utils.SecurityUtils;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -26,15 +29,21 @@ public class UserMenuServiceImpl implements UserMenuService {
|
||||
private final CompanyMenuService companyMenuService;
|
||||
private final PositionCompanyMenuService positionCompanyMenuService;
|
||||
private final UserService userService;
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final CompanyMemberService companyMemberService;
|
||||
|
||||
public UserMenuServiceImpl(MenuService menuService,
|
||||
CompanyMenuService companyMenuService,
|
||||
PositionCompanyMenuService positionCompanyMenuService,
|
||||
UserService userService) {
|
||||
UserService userService,
|
||||
CurrentUserContext currentUserContext,
|
||||
CompanyMemberService companyMemberService) {
|
||||
this.menuService = menuService;
|
||||
this.companyMenuService = companyMenuService;
|
||||
this.positionCompanyMenuService = positionCompanyMenuService;
|
||||
this.userService = userService;
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.companyMemberService = companyMemberService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,7 +53,7 @@ public class UserMenuServiceImpl implements UserMenuService {
|
||||
@Override
|
||||
public List<UserMenuVO> getUserMenus() {
|
||||
// 从Security上下文获取用户ID
|
||||
Long userId = SecurityUtils.getCurrentUserId();
|
||||
Long userId = currentUserContext.getCurrentUserId();
|
||||
if (userId == null) {
|
||||
throw new RuntimeException("用户未登录");
|
||||
}
|
||||
@@ -60,10 +69,10 @@ public class UserMenuServiceImpl implements UserMenuService {
|
||||
throw new RuntimeException("用户状态异常");
|
||||
}
|
||||
|
||||
// 获取用户角色和其他信息
|
||||
// 获取用户角色
|
||||
String userRole = user.getRole();
|
||||
Long companyId = user.getCompanyId();
|
||||
Long positionId = user.getPositionId();
|
||||
// 获取公司ID
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
List<MenuVO> menus;
|
||||
|
||||
@@ -81,11 +90,20 @@ public class UserMenuServiceImpl implements UserMenuService {
|
||||
}
|
||||
break;
|
||||
case "user":
|
||||
// 普通用户根据职位获取菜单
|
||||
if (positionId == null) {
|
||||
// 普通用户,根据公司成员角色判断
|
||||
CompanyMemberPO member = companyMemberService.getByUserIdAndCompanyId(userId, companyId);
|
||||
if (member == null) {
|
||||
menus = List.of();
|
||||
} else if (member.getRole() == CompanyMemberRole.owner) {
|
||||
// owner 角色获取公司所有菜单
|
||||
menus = companyMenuService.getCompanyMenusForRoute(companyId);
|
||||
} else {
|
||||
menus = positionCompanyMenuService.getPositionMenusForRoute(positionId);
|
||||
// member 角色根据职位获取菜单
|
||||
if (member.getPositionId() == null) {
|
||||
menus = List.of();
|
||||
} else {
|
||||
menus = positionCompanyMenuService.getPositionMenusForRoute(member.getPositionId());
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
+3
-18
@@ -20,24 +20,6 @@ public class UserPO {
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 公司id
|
||||
*/
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
|
||||
/**
|
||||
* 部门id
|
||||
*/
|
||||
@TableField("department_id")
|
||||
private Long departmentId;
|
||||
|
||||
/**
|
||||
* 岗位id
|
||||
*/
|
||||
@TableField("position_id")
|
||||
private Long positionId;
|
||||
|
||||
/**
|
||||
* 登录账号
|
||||
*/
|
||||
@@ -95,6 +77,9 @@ public class UserPO {
|
||||
/**
|
||||
* 最后登录ip
|
||||
*/
|
||||
@TableField("last_company_id")
|
||||
private Long lastCompanyId;
|
||||
|
||||
@TableField("last_login_ip")
|
||||
private String lastLoginIp;
|
||||
|
||||
|
||||
+132
-15
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.util.StringUtils;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.user.mapper.UserMapper;
|
||||
@@ -17,6 +18,7 @@ import top.xyquan.ecomdmbbackend.modules.sys.auth.model.dto.RegisterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.user.model.dto.UpdateUserInfoDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.user.model.dto.UserFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.user.model.po.UserPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.company.model.po.CompanyPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.auth.model.vo.LoginVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.user.model.vo.UserVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.user.service.UserService;
|
||||
@@ -41,11 +43,20 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
private final JwtUtils jwtUtils;
|
||||
private final MediaImageService mediaImageService;
|
||||
private final top.xyquan.ecomdmbbackend.modules.org.companymember.service.CompanyMemberService companyMemberService;
|
||||
private final top.xyquan.ecomdmbbackend.modules.org.departmentmember.service.DepartmentMemberService departmentMemberService;
|
||||
private final top.xyquan.ecomdmbbackend.modules.org.company.service.CompanyService companyService;
|
||||
|
||||
public UserServiceImpl(PasswordEncoder passwordEncoder, JwtUtils jwtUtils, MediaImageService mediaImageService) {
|
||||
public UserServiceImpl(PasswordEncoder passwordEncoder, JwtUtils jwtUtils, MediaImageService mediaImageService,
|
||||
@Lazy top.xyquan.ecomdmbbackend.modules.org.companymember.service.CompanyMemberService companyMemberService,
|
||||
top.xyquan.ecomdmbbackend.modules.org.departmentmember.service.DepartmentMemberService departmentMemberService,
|
||||
top.xyquan.ecomdmbbackend.modules.org.company.service.CompanyService companyService) {
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
this.jwtUtils = jwtUtils;
|
||||
this.mediaImageService = mediaImageService;
|
||||
this.companyMemberService = companyMemberService;
|
||||
this.departmentMemberService = departmentMemberService;
|
||||
this.companyService = companyService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,7 +135,13 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements
|
||||
this.updateById(user);
|
||||
|
||||
// 生成登录响应
|
||||
return generateLoginResponse(user);
|
||||
try {
|
||||
return generateLoginResponse(user);
|
||||
} catch (Exception e) {
|
||||
System.out.println("DEBUG generateLoginResponse ERROR: " + e.getClass().getName() + ": " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -381,19 +398,37 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements
|
||||
queryWrapper.eq(UserPO::getRole, filter.getRole());
|
||||
}
|
||||
|
||||
// 公司ID查询
|
||||
// 公司ID查询(通过公司成员表)
|
||||
if (filter.getCompanyId() != null) {
|
||||
queryWrapper.eq(UserPO::getCompanyId, filter.getCompanyId());
|
||||
var members = companyMemberService.getByCompanyId(filter.getCompanyId());
|
||||
List<Long> userIds = members.stream().map(top.xyquan.ecomdmbbackend.modules.org.companymember.model.vo.CompanyMemberVO::getUserId).collect(Collectors.toList());
|
||||
if (!userIds.isEmpty()) {
|
||||
queryWrapper.in(UserPO::getId, userIds);
|
||||
} else {
|
||||
queryWrapper.eq(UserPO::getId, -1L); // 无结果
|
||||
}
|
||||
}
|
||||
|
||||
// 部门ID查询
|
||||
|
||||
// 部门ID查询(通过部门成员表)
|
||||
if (filter.getDepartmentId() != null) {
|
||||
queryWrapper.eq(UserPO::getDepartmentId, filter.getDepartmentId());
|
||||
var deptMembers = departmentMemberService.getByDepartmentId(filter.getDepartmentId());
|
||||
List<Long> userIds = deptMembers.stream().map(top.xyquan.ecomdmbbackend.modules.org.departmentmember.model.vo.DepartmentMemberVO::getUserId).collect(Collectors.toList());
|
||||
if (!userIds.isEmpty()) {
|
||||
queryWrapper.in(UserPO::getId, userIds);
|
||||
} else {
|
||||
queryWrapper.eq(UserPO::getId, -1L); // 无结果
|
||||
}
|
||||
}
|
||||
|
||||
// 岗位ID查询
|
||||
|
||||
// 岗位ID查询(通过公司成员表)
|
||||
if (filter.getPositionId() != null) {
|
||||
queryWrapper.eq(UserPO::getPositionId, filter.getPositionId());
|
||||
var positionMembers = companyMemberService.getByPositionId(filter.getPositionId());
|
||||
List<Long> userIds = positionMembers.stream().map(top.xyquan.ecomdmbbackend.modules.org.companymember.model.vo.CompanyMemberVO::getUserId).collect(Collectors.toList());
|
||||
if (!userIds.isEmpty()) {
|
||||
queryWrapper.in(UserPO::getId, userIds);
|
||||
} else {
|
||||
queryWrapper.eq(UserPO::getId, -1L); // 无结果
|
||||
}
|
||||
}
|
||||
|
||||
// 状态查询
|
||||
@@ -433,6 +468,22 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements
|
||||
/**
|
||||
* 生成登录响应
|
||||
*/
|
||||
/**
|
||||
* 检查公司是否可用(状态正常且未过期)
|
||||
*/
|
||||
private boolean isCompanyAvailable(CompanyPO company) {
|
||||
if (company == null) {
|
||||
return false;
|
||||
}
|
||||
if (company.getStatus() != 1) {
|
||||
return false;
|
||||
}
|
||||
if (company.getExpiration() != null && company.getExpiration().isBefore(LocalDateTime.now())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private LoginVO generateLoginResponse(UserPO user) {
|
||||
return generateLoginResponseWithRole(user, user.getRole());
|
||||
}
|
||||
@@ -443,15 +494,81 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements
|
||||
private LoginVO generateLoginResponseWithRole(UserPO user, String role) {
|
||||
LoginVO loginVO = new LoginVO();
|
||||
|
||||
// 生成访问令牌负载信息(包含完整用户信息)
|
||||
// 超管(super)不需要公司上下文,直接生成令牌
|
||||
if ("super".equals(role)) {
|
||||
AccessTokenPayload accessPayload = AccessTokenPayload.builder()
|
||||
.userId(user.getId().toString())
|
||||
.companyId(null)
|
||||
.role("super")
|
||||
.positionId(null)
|
||||
.build();
|
||||
RefreshTokenPayload refreshPayload = RefreshTokenPayload.builder()
|
||||
.userId(user.getId().toString())
|
||||
.role("super")
|
||||
.build();
|
||||
String accessToken = jwtUtils.generateAccessToken(accessPayload);
|
||||
String refreshToken = jwtUtils.generateRefreshToken(refreshPayload);
|
||||
loginVO.setAccessToken(accessToken);
|
||||
loginVO.setRefreshToken(refreshToken);
|
||||
loginVO.setAccessTokenExpiresAt(jwtUtils.getAccessTokenExpiresAt());
|
||||
loginVO.setRefreshTokenExpiresAt(jwtUtils.getRefreshTokenExpiresAt());
|
||||
return loginVO;
|
||||
}
|
||||
|
||||
// 选择登录公司:优先使用 lastCompanyId(上次登录的公司),前提是该公司状态可用
|
||||
// 否则取用户加入时间最早的一个可用公司
|
||||
Long companyIdForToken = null;
|
||||
Long positionIdForToken = null;
|
||||
|
||||
var memberships = companyMemberService.getByUserIdOrderByCreateTime(user.getId());
|
||||
if (memberships.isEmpty()) {
|
||||
throw new BusinessException("无可用公司,无法登录");
|
||||
}
|
||||
|
||||
// 优先使用 lastCompanyId(需公司状态可用且未过期)
|
||||
if (user.getLastCompanyId() != null) {
|
||||
var lastCompany = companyService.getById(user.getLastCompanyId());
|
||||
if (isCompanyAvailable(lastCompany)) {
|
||||
companyIdForToken = user.getLastCompanyId();
|
||||
}
|
||||
}
|
||||
|
||||
// 如果 lastCompanyId 无效,从已按加入时间排序的成员列表中找第一个可用公司
|
||||
if (companyIdForToken == null) {
|
||||
for (var member : memberships) {
|
||||
var company = companyService.getById(member.getCompanyId());
|
||||
if (isCompanyAvailable(company)) {
|
||||
companyIdForToken = member.getCompanyId();
|
||||
positionIdForToken = member.getPositionId();
|
||||
// 更新 lastCompanyId
|
||||
user.setLastCompanyId(companyIdForToken);
|
||||
this.updateById(user);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// lastCompanyId 有效,直接从成员列表找对应的 positionId
|
||||
for (var member : memberships) {
|
||||
if (member.getCompanyId().equals(companyIdForToken)) {
|
||||
positionIdForToken = member.getPositionId();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (companyIdForToken == null) {
|
||||
throw new BusinessException("无可用公司,无法登录");
|
||||
}
|
||||
|
||||
// 生成访问令牌负载信息
|
||||
AccessTokenPayload accessPayload = AccessTokenPayload.builder()
|
||||
.userId(user.getId().toString())
|
||||
.companyId(user.getCompanyId())
|
||||
.companyId(companyIdForToken)
|
||||
.role(role != null ? role : user.getRole())
|
||||
.positionId(user.getPositionId())
|
||||
.positionId(positionIdForToken)
|
||||
.build();
|
||||
|
||||
// 生成刷新令牌负载信息(包含用户ID和角色)
|
||||
// 生成刷新令牌负载信息
|
||||
RefreshTokenPayload refreshPayload = RefreshTokenPayload.builder()
|
||||
.userId(user.getId().toString())
|
||||
.role(role != null ? role : user.getRole())
|
||||
@@ -460,7 +577,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements
|
||||
// 生成访问令牌和刷新令牌
|
||||
String accessToken = jwtUtils.generateAccessToken(accessPayload);
|
||||
String refreshToken = jwtUtils.generateRefreshToken(refreshPayload);
|
||||
|
||||
|
||||
// 设置令牌信息
|
||||
loginVO.setAccessToken(accessToken);
|
||||
loginVO.setRefreshToken(refreshToken);
|
||||
|
||||
@@ -1,239 +1,68 @@
|
||||
-- 店铺表
|
||||
CREATE TABLE `ec_shop` (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '店铺ID',
|
||||
`company_id` BIGINT UNSIGNED NOT NULL COMMENT '所属公司ID',
|
||||
`name` VARCHAR(200) NOT NULL COMMENT '店铺名称',
|
||||
`logo_image_id` BIGINT UNSIGNED DEFAULT NULL COMMENT 'logo图片ID',
|
||||
`platform` VARCHAR(50) DEFAULT NULL COMMENT '平台(如淘宝、京东、拼多多)',
|
||||
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
|
||||
-- ========================================
|
||||
-- 电商数据中台数据库设计
|
||||
-- 生成时间:2026-03-29
|
||||
-- ========================================
|
||||
|
||||
-- ========================================
|
||||
-- EC_BRUSH_ORDER
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `ec_brush_order`;
|
||||
CREATE TABLE `ec_brush_order` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '刷单记录ID',
|
||||
`company_id` bigint unsigned NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint unsigned NOT NULL COMMENT '店铺ID',
|
||||
`product_id` bigint unsigned DEFAULT NULL COMMENT '商品ID(可选)',
|
||||
`product_spec_id` bigint unsigned DEFAULT NULL COMMENT '商品规格ID(可选)',
|
||||
`brush_amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '刷单金额',
|
||||
`brush_time` timestamp NOT NULL COMMENT '刷单时间',
|
||||
`platform_order_no` varchar(100) DEFAULT NULL COMMENT '平台订单号(可选)',
|
||||
`quantity` int DEFAULT '1' COMMENT '刷单数量',
|
||||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_company_id` (`company_id`),
|
||||
KEY `fk_ec_shop_logo_image` (`logo_image_id`),
|
||||
KEY `fk_ec_shop_creator` (`create_by`),
|
||||
KEY `fk_ec_shop_updater` (`update_by`),
|
||||
CONSTRAINT `fk_ec_shop_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_logo_image` FOREIGN KEY (`logo_image_id`) REFERENCES `sys_file` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-店铺表';
|
||||
|
||||
-- 商品表
|
||||
CREATE TABLE `ec_product` (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '商品ID',
|
||||
`company_id` BIGINT UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`name` VARCHAR(255) NOT NULL COMMENT '商品名称',
|
||||
`product_code` VARCHAR(100) DEFAULT NULL COMMENT '商品编码',
|
||||
`main_image_id` BIGINT UNSIGNED DEFAULT NULL COMMENT '主图图片ID',
|
||||
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_company_id` (`company_id`),
|
||||
UNIQUE KEY `uk_product_code` (`product_code`),
|
||||
KEY `fk_ec_product_main_image` (`main_image_id`),
|
||||
KEY `fk_ec_product_creator` (`create_by`),
|
||||
KEY `fk_ec_product_updater` (`update_by`),
|
||||
CONSTRAINT `fk_ec_product_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_product_main_image` FOREIGN KEY (`main_image_id`) REFERENCES `sys_file` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_product_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_product_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-商品表(含成本价)';
|
||||
|
||||
-- 商品规格表
|
||||
CREATE TABLE `ec_product_spec` (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '规格ID',
|
||||
`company_id` BIGINT UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`product_id` BIGINT UNSIGNED NOT NULL COMMENT '商品ID',
|
||||
`name` VARCHAR(200) NOT NULL COMMENT '规格名称',
|
||||
`spec_code` VARCHAR(100) DEFAULT NULL COMMENT '规格编码',
|
||||
`product_cost` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '商品成本',
|
||||
`shipping_cost` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '运费成本',
|
||||
`other_cost` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '其他成本',
|
||||
`remark` VARCHAR(500) DEFAULT NULL COMMENT '备注',
|
||||
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_company_id` (`company_id`),
|
||||
KEY `idx_product_id` (`product_id`),
|
||||
KEY `idx_spec_code` (`spec_code`),
|
||||
KEY `fk_ec_spec_creator` (`create_by`),
|
||||
KEY `fk_ec_spec_updater` (`update_by`),
|
||||
CONSTRAINT `fk_ec_spec_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_spec_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_spec_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_spec_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-规格表';
|
||||
|
||||
-- 订单状态表
|
||||
CREATE TABLE `ec_order_status` (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '订单状态ID',
|
||||
`company_id` BIGINT UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`status_name` VARCHAR(100) NOT NULL COMMENT '状态名称(中文)',
|
||||
`description` VARCHAR(200) DEFAULT NULL COMMENT '状态描述',
|
||||
`sort_order` INT NOT NULL DEFAULT 0 COMMENT '排序',
|
||||
`auto_statistics` TINYINT NOT NULL DEFAULT 1 COMMENT '是否自动参与统计 0不参与 1参与',
|
||||
`is_refund` TINYINT NOT NULL DEFAULT 0 COMMENT '是否为退款状态 0否 1是',
|
||||
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_company_id` (`company_id`),
|
||||
UNIQUE KEY `uk_company_status_name` (`company_id`, `status_name`),
|
||||
KEY `idx_sort_order` (`sort_order`),
|
||||
KEY `idx_auto_statistics` (`auto_statistics`),
|
||||
KEY `idx_is_refund` (`is_refund`),
|
||||
KEY `fk_ec_order_status_creator` (`create_by`),
|
||||
KEY `fk_ec_order_status_updater` (`update_by`),
|
||||
CONSTRAINT `fk_ec_order_status_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_status_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_status_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-订单状态表';
|
||||
|
||||
-- 订单表
|
||||
CREATE TABLE `ec_order` (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '订单ID',
|
||||
`company_id` BIGINT UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` BIGINT UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`product_id` BIGINT UNSIGNED NOT NULL COMMENT '商品ID',
|
||||
`product_spec_id` BIGINT UNSIGNED DEFAULT NULL COMMENT '商品规格ID',
|
||||
`status_id` BIGINT UNSIGNED NOT NULL COMMENT '订单状态ID',
|
||||
`platform_order_no` VARCHAR(100) DEFAULT NULL COMMENT '平台订单号',
|
||||
`link_product_name` VARCHAR(255) NOT NULL COMMENT '链接商品名称',
|
||||
`link_spec_name` VARCHAR(200) DEFAULT NULL COMMENT '链接规格名称',
|
||||
`received_amount` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '商家实收金额',
|
||||
`quantity` INT NOT NULL DEFAULT 1 COMMENT '数量',
|
||||
`unit_price` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '销售单价',
|
||||
`product_cost` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '单件商品成本(下单时快照)',
|
||||
`shipping_cost` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '单件运费成本(下单时快照)',
|
||||
`other_cost` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '单件其他成本(下单时快照)',
|
||||
`remark` VARCHAR(500) DEFAULT NULL COMMENT '备注',
|
||||
`import_task_id` BIGINT UNSIGNED DEFAULT NULL COMMENT '导入任务ID',
|
||||
`confirm` TINYINT NOT NULL DEFAULT 1 COMMENT '确认(0-否 1-是)',
|
||||
`order_time` TIMESTAMP NOT NULL COMMENT '下单时间',
|
||||
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_company_shop_time` (`company_id`, `shop_id`, `order_time`),
|
||||
KEY `idx_status_id` (`status_id`),
|
||||
KEY `idx_platform_order_no` (`platform_order_no`),
|
||||
KEY `idx_shop_id` (`shop_id`),
|
||||
KEY `idx_product_id` (`product_id`),
|
||||
KEY `idx_product_spec_id` (`product_spec_id`),
|
||||
KEY `idx_import_task_id` (`import_task_id`),
|
||||
KEY `idx_confirm` (`confirm`),
|
||||
KEY `fk_ec_order_creator` (`create_by`),
|
||||
KEY `fk_ec_order_updater` (`update_by`),
|
||||
CONSTRAINT `fk_ec_order_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_product_spec` FOREIGN KEY (`product_spec_id`) REFERENCES `ec_product_spec` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_status` FOREIGN KEY (`status_id`) REFERENCES `ec_order_status` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_import_task` FOREIGN KEY (`import_task_id`) REFERENCES `ec_import_tasks` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-订单表(含商品明细)';
|
||||
KEY `idx_brush_time` (`brush_time`),
|
||||
KEY `idx_platform_order_no` (`platform_order_no`),
|
||||
KEY `idx_company_shop_time` (`company_id`,`shop_id`,`brush_time`),
|
||||
KEY `fk_ec_brush_order_creator` (`create_by`),
|
||||
KEY `fk_ec_brush_order_updater` (`update_by`),
|
||||
CONSTRAINT `fk_ec_brush_order_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_brush_order_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_brush_order_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_brush_order_product_spec` FOREIGN KEY (`product_spec_id`) REFERENCES `ec_product_spec` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_brush_order_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_brush_order_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-刷单记录表'
|
||||
|
||||
-- 推广费类型表
|
||||
CREATE TABLE `ec_promotion_fee_type` (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '推广费类型ID',
|
||||
`company_id` BIGINT UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`type_name` VARCHAR(100) NOT NULL COMMENT '类型名称',
|
||||
`description` VARCHAR(200) DEFAULT NULL COMMENT '类型描述',
|
||||
`calculation_method` TINYINT NOT NULL DEFAULT 1 COMMENT '计算方式 1固定金额 2按比例 3按点击 4按展示',
|
||||
`sort_order` INT NOT NULL DEFAULT 0 COMMENT '排序',
|
||||
`is_active` TINYINT NOT NULL DEFAULT 1 COMMENT '是否启用 0禁用 1启用',
|
||||
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_company_id` (`company_id`),
|
||||
UNIQUE KEY `uk_company_type_name` (`company_id`, `type_name`),
|
||||
KEY `idx_sort_order` (`sort_order`),
|
||||
KEY `idx_is_active` (`is_active`),
|
||||
KEY `fk_ec_promotion_fee_type_creator` (`create_by`),
|
||||
KEY `fk_ec_promotion_fee_type_updater` (`update_by`),
|
||||
CONSTRAINT `fk_ec_promotion_fee_type_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_promotion_fee_type_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_promotion_fee_type_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-推广费类型表';
|
||||
|
||||
-- 推广费记录表
|
||||
CREATE TABLE `ec_promotion_fee` (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '推广费记录ID',
|
||||
`company_id` BIGINT UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` BIGINT UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`fee_type_id` BIGINT UNSIGNED NOT NULL COMMENT '推广费类型ID',
|
||||
`fee_name` VARCHAR(200) NOT NULL COMMENT '推广费名称',
|
||||
`platform` VARCHAR(50) DEFAULT NULL COMMENT '平台(淘宝、京东、拼多多等)',
|
||||
`campaign_name` VARCHAR(200) DEFAULT NULL COMMENT '推广活动名称',
|
||||
`fee_amount` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '推广费金额',
|
||||
`base_amount` DECIMAL(10,2) DEFAULT NULL COMMENT '基础金额(用于按比例计算)',
|
||||
`fee_rate` DECIMAL(5,4) DEFAULT NULL COMMENT '费率(用于按比例计算)',
|
||||
`click_count` INT DEFAULT NULL COMMENT '点击次数',
|
||||
`impression_count` INT DEFAULT NULL COMMENT '展示次数',
|
||||
`conversion_count` INT DEFAULT NULL COMMENT '转化次数',
|
||||
`fee_date` DATE NOT NULL COMMENT '推广费发生日期',
|
||||
`remark` VARCHAR(500) DEFAULT NULL COMMENT '备注',
|
||||
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_company_id` (`company_id`),
|
||||
KEY `idx_shop_id` (`shop_id`),
|
||||
KEY `idx_fee_type_id` (`fee_type_id`),
|
||||
KEY `idx_fee_date` (`fee_date`),
|
||||
KEY `idx_platform` (`platform`),
|
||||
KEY `fk_ec_promotion_fee_creator` (`create_by`),
|
||||
KEY `fk_ec_promotion_fee_updater` (`update_by`),
|
||||
CONSTRAINT `fk_ec_promotion_fee_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_promotion_fee_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_promotion_fee_type` FOREIGN KEY (`fee_type_id`) REFERENCES `ec_promotion_fee_type` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_promotion_fee_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_promotion_fee_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-推广费记录表';
|
||||
|
||||
-- 导入任务表
|
||||
CREATE TABLE `ec_import_tasks` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`company_id` bigint unsigned NOT NULL COMMENT '所属公司ID',
|
||||
`shop_id` bigint unsigned NOT NULL COMMENT '所属店铺ID',
|
||||
-- ========================================
|
||||
-- EC_IMPORT_FIELD_DEFS
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `ec_import_field_defs`;
|
||||
CREATE TABLE `ec_import_field_defs` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '字段定义ID',
|
||||
`type` enum('product','order') NOT NULL COMMENT '导入类型(product-商品 order-订单)',
|
||||
`task_name` varchar(100) DEFAULT NULL COMMENT '任务名称',
|
||||
`file_name` varchar(255) NOT NULL COMMENT '原始文件名',
|
||||
`file_path` varchar(500) NOT NULL COMMENT '存储路径',
|
||||
`status` enum('pending','processing','success','failed') DEFAULT 'pending' NOT NULL COMMENT '任务状态(pending-待处理 processing-处理中 success-成功 failed-失败)',
|
||||
`total_count` int unsigned DEFAULT 0 COMMENT '总行数',
|
||||
`success_count` int unsigned DEFAULT 0 COMMENT '成功行数',
|
||||
`fail_count` int unsigned DEFAULT 0 COMMENT '失败行数',
|
||||
`mapping` json DEFAULT NULL COMMENT '字段映射记录',
|
||||
`message` text DEFAULT NULL COMMENT '错误信息或备注',
|
||||
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
|
||||
|
||||
`field_name` varchar(100) NOT NULL COMMENT '数据库字段名,如 name',
|
||||
`field_label` varchar(100) NOT NULL COMMENT '中文字段名,如 商品名称',
|
||||
`file_field_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '文件字段名,如 商品名称',
|
||||
`required` tinyint(1) DEFAULT '0' COMMENT '是否必填',
|
||||
`sort` int unsigned DEFAULT '0' COMMENT '排序',
|
||||
`data_type` varchar(50) DEFAULT 'string' COMMENT 'string, number, date等',
|
||||
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_company_id` (`company_id`),
|
||||
KEY `idx_shop_id` (`shop_id`),
|
||||
KEY `idx_create_by` (`create_by`),
|
||||
KEY `idx_update_by` (`update_by`),
|
||||
CONSTRAINT `fk_import_task_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_import_task_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_import_task_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_import_task_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-导入任务表';
|
||||
UNIQUE KEY `uniq_type_field` (`type`,`field_name`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-导入字段定义表'
|
||||
|
||||
-- 导入映射表
|
||||
-- ========================================
|
||||
-- EC_IMPORT_MAPPINGS
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `ec_import_mappings`;
|
||||
CREATE TABLE `ec_import_mappings` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '映射ID',
|
||||
`company_id` bigint unsigned NOT NULL COMMENT '所属公司ID',
|
||||
@@ -244,44 +73,319 @@ CREATE TABLE `ec_import_mappings` (
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
|
||||
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uniq_company_type_name` (`company_id`, `type`, `name`),
|
||||
UNIQUE KEY `uniq_company_type_name` (`company_id`,`type`,`name`),
|
||||
KEY `fk_import_mapping_creator` (`create_by`),
|
||||
KEY `fk_import_mapping_updater` (`update_by`),
|
||||
CONSTRAINT `fk_import_mapping_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_import_mapping_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_import_mapping_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-导入映射表';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-导入映射表'
|
||||
|
||||
-- 导入字段定义表
|
||||
CREATE TABLE `ec_import_field_defs` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '字段定义ID',
|
||||
-- ========================================
|
||||
-- EC_IMPORT_TASKS
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `ec_import_tasks`;
|
||||
CREATE TABLE `ec_import_tasks` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`company_id` bigint unsigned NOT NULL COMMENT '所属公司ID',
|
||||
`shop_id` bigint unsigned DEFAULT NULL COMMENT '所属店铺ID',
|
||||
`type` enum('product','order') NOT NULL COMMENT '导入类型(product-商品 order-订单)',
|
||||
`field_name` varchar(100) NOT NULL COMMENT '数据库字段名,如 name',
|
||||
`field_label` varchar(100) NOT NULL COMMENT '中文字段名,如 商品名称',
|
||||
`file_field_name` varchar(100) DEFAULT NULL COMMENT '文件字段名,如 商品名称',
|
||||
`required` tinyint(1) DEFAULT 0 COMMENT '是否必填',
|
||||
`sort` int unsigned DEFAULT 0 COMMENT '排序',
|
||||
`data_type` varchar(50) DEFAULT 'string' COMMENT 'string, number, date等',
|
||||
`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
|
||||
`task_name` varchar(100) DEFAULT NULL COMMENT '任务名称',
|
||||
`file_name` varchar(255) NOT NULL COMMENT '原始文件名',
|
||||
`file_path` varchar(500) NOT NULL COMMENT '存储路径',
|
||||
`status` enum('pending','processing','success','failed') NOT NULL DEFAULT 'pending' COMMENT '任务状态(pending-待处理 processing-处理中 success-成功 failed-失败)',
|
||||
`total_count` int unsigned DEFAULT '0' COMMENT '总行数',
|
||||
`success_count` int unsigned DEFAULT '0' COMMENT '成功行数',
|
||||
`fail_count` int unsigned DEFAULT '0' COMMENT '失败行数',
|
||||
`mapping` json DEFAULT NULL COMMENT '字段映射记录',
|
||||
`message` text COMMENT '错误信息或备注',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uniq_type_field` (`type`,`field_name`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-导入字段定义表';
|
||||
KEY `idx_company_id` (`company_id`),
|
||||
KEY `idx_create_by` (`create_by`),
|
||||
KEY `idx_update_by` (`update_by`),
|
||||
CONSTRAINT `fk_import_task_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_import_task_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_import_task_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=174 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-导入任务表'
|
||||
|
||||
-- 店铺商品关联表(中间表)
|
||||
-- ========================================
|
||||
-- EC_ORDER
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `ec_order`;
|
||||
CREATE TABLE `ec_order` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '订单ID',
|
||||
`company_id` bigint unsigned NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint unsigned NOT NULL COMMENT '店铺ID',
|
||||
`product_id` bigint unsigned NOT NULL COMMENT '商品ID',
|
||||
`product_spec_id` bigint unsigned DEFAULT NULL COMMENT '商品规格ID',
|
||||
`status_id` bigint unsigned NOT NULL COMMENT '订单状态ID',
|
||||
`platform_order_no` varchar(100) DEFAULT NULL COMMENT '平台订单号',
|
||||
`link_product_name` varchar(255) NOT NULL COMMENT '链接商品名称',
|
||||
`link_spec_name` varchar(200) DEFAULT NULL COMMENT '链接规格名称',
|
||||
`received_amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '商家实收金额',
|
||||
`quantity` int NOT NULL DEFAULT '1' COMMENT '数量',
|
||||
`unit_price` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '销售单价',
|
||||
`product_cost` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '单件商品成本(下单时快照)',
|
||||
`shipping_cost` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '单件运费成本(下单时快照)',
|
||||
`other_cost` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '单件其他成本(下单时快照)',
|
||||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
||||
`import_task_id` bigint unsigned DEFAULT NULL COMMENT '导入任务ID',
|
||||
`confirm` tinyint NOT NULL DEFAULT '1' COMMENT '确认(0-否 1-是)',
|
||||
`order_time` timestamp NOT NULL COMMENT '下单时间',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_company_shop_time` (`company_id`,`shop_id`,`order_time`),
|
||||
KEY `idx_status_id` (`status_id`),
|
||||
KEY `idx_platform_order_no` (`platform_order_no`),
|
||||
KEY `idx_product_id` (`product_id`),
|
||||
KEY `idx_product_spec_id` (`product_spec_id`),
|
||||
KEY `idx_import_task_id` (`import_task_id`),
|
||||
KEY `idx_confirm` (`confirm`),
|
||||
KEY `fk_ec_order_creator` (`create_by`),
|
||||
KEY `fk_ec_order_updater` (`update_by`),
|
||||
KEY `fk_ec_order_shop` (`shop_id`),
|
||||
CONSTRAINT `fk_ec_order_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_import_task` FOREIGN KEY (`import_task_id`) REFERENCES `ec_import_tasks` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_product_spec` FOREIGN KEY (`product_spec_id`) REFERENCES `ec_product_spec` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_status` FOREIGN KEY (`status_id`) REFERENCES `ec_order_status` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1351 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-订单表(含商品明细)'
|
||||
|
||||
-- ========================================
|
||||
-- EC_ORDER_STATUS
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `ec_order_status`;
|
||||
CREATE TABLE `ec_order_status` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '订单状态ID',
|
||||
`company_id` bigint unsigned NOT NULL COMMENT '公司ID',
|
||||
`status_name` varchar(100) NOT NULL COMMENT '状态名称(中文)',
|
||||
`description` varchar(200) DEFAULT NULL COMMENT '状态描述',
|
||||
`color` varchar(20) DEFAULT NULL COMMENT '状态颜色(十六进制)',
|
||||
`sort_order` int NOT NULL DEFAULT '0' COMMENT '排序',
|
||||
`auto_statistics` tinyint NOT NULL DEFAULT '1' COMMENT '是否自动参与统计 0不参与 1参与',
|
||||
`is_refund` tinyint NOT NULL DEFAULT '0' COMMENT '是否为退款状态 0否 1是',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_company_status_name` (`company_id`,`status_name`),
|
||||
KEY `idx_company_id` (`company_id`),
|
||||
KEY `idx_sort_order` (`sort_order`),
|
||||
KEY `idx_auto_statistics` (`auto_statistics`),
|
||||
KEY `fk_ec_order_status_creator` (`create_by`),
|
||||
KEY `fk_ec_order_status_updater` (`update_by`),
|
||||
KEY `idx_is_refund` (`is_refund`),
|
||||
CONSTRAINT `fk_ec_order_status_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_status_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_status_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-订单状态表'
|
||||
|
||||
-- ========================================
|
||||
-- EC_PRODUCT
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `ec_product`;
|
||||
CREATE TABLE `ec_product` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '商品ID',
|
||||
`company_id` bigint unsigned NOT NULL COMMENT '公司ID',
|
||||
`name` varchar(255) NOT NULL COMMENT '商品名称',
|
||||
`product_code` varchar(100) DEFAULT NULL COMMENT '商品编码',
|
||||
`main_image_id` bigint unsigned DEFAULT NULL COMMENT '主图图片ID',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_product_code` (`product_code`),
|
||||
KEY `idx_company_id` (`company_id`),
|
||||
KEY `fk_ec_product_main_image` (`main_image_id`),
|
||||
KEY `fk_ec_product_creator` (`create_by`),
|
||||
KEY `fk_ec_product_updater` (`update_by`),
|
||||
CONSTRAINT `fk_ec_product_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_product_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_product_main_image` FOREIGN KEY (`main_image_id`) REFERENCES `sys_file` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_product_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-商品表(含成本价)'
|
||||
|
||||
-- ========================================
|
||||
-- EC_PRODUCT_SPEC
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `ec_product_spec`;
|
||||
CREATE TABLE `ec_product_spec` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '规格ID',
|
||||
`company_id` bigint unsigned NOT NULL COMMENT '公司ID',
|
||||
`product_id` bigint unsigned NOT NULL COMMENT '商品ID',
|
||||
`name` varchar(200) NOT NULL COMMENT '规格名称',
|
||||
`spec_code` varchar(100) DEFAULT NULL COMMENT '规格编码',
|
||||
`product_cost` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '商品成本',
|
||||
`shipping_cost` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '运费成本',
|
||||
`other_cost` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '其他成本',
|
||||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_company_id` (`company_id`),
|
||||
KEY `idx_product_id` (`product_id`),
|
||||
KEY `idx_spec_code` (`spec_code`),
|
||||
KEY `fk_ec_spec_creator` (`create_by`),
|
||||
KEY `fk_ec_spec_updater` (`update_by`),
|
||||
CONSTRAINT `fk_ec_spec_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_spec_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_spec_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_spec_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=107 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-规格表'
|
||||
|
||||
-- ========================================
|
||||
-- EC_PROMOTION_FEE
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `ec_promotion_fee`;
|
||||
CREATE TABLE `ec_promotion_fee` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '推广费记录ID',
|
||||
`company_id` bigint unsigned NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint unsigned NOT NULL COMMENT '店铺ID',
|
||||
`fee_type_id` bigint unsigned NOT NULL COMMENT '推广费类型ID',
|
||||
`fee_name` varchar(200) NOT NULL COMMENT '推广费名称',
|
||||
`platform` varchar(50) DEFAULT NULL COMMENT '平台(淘宝、京东、拼多多等)',
|
||||
`campaign_name` varchar(200) DEFAULT NULL COMMENT '推广活动名称',
|
||||
`fee_amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '推广费金额',
|
||||
`base_amount` decimal(10,2) DEFAULT NULL COMMENT '基础金额(用于按比例计算)',
|
||||
`fee_rate` decimal(5,4) DEFAULT NULL COMMENT '费率(用于按比例计算)',
|
||||
`click_count` int DEFAULT NULL COMMENT '点击次数',
|
||||
`impression_count` int DEFAULT NULL COMMENT '展示次数',
|
||||
`conversion_count` int DEFAULT NULL COMMENT '转化次数',
|
||||
`fee_date` date NOT NULL COMMENT '推广费发生日期',
|
||||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_company_id` (`company_id`),
|
||||
KEY `idx_shop_id` (`shop_id`),
|
||||
KEY `idx_fee_type_id` (`fee_type_id`),
|
||||
KEY `idx_fee_date` (`fee_date`),
|
||||
KEY `idx_platform` (`platform`),
|
||||
KEY `fk_ec_promotion_fee_creator` (`create_by`),
|
||||
KEY `fk_ec_promotion_fee_updater` (`update_by`),
|
||||
CONSTRAINT `fk_ec_promotion_fee_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_promotion_fee_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_promotion_fee_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_promotion_fee_type` FOREIGN KEY (`fee_type_id`) REFERENCES `ec_promotion_fee_type` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_promotion_fee_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-推广费记录表'
|
||||
|
||||
-- ========================================
|
||||
-- EC_PROMOTION_FEE_TYPE
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `ec_promotion_fee_type`;
|
||||
CREATE TABLE `ec_promotion_fee_type` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '推广费类型ID',
|
||||
`company_id` bigint unsigned NOT NULL COMMENT '公司ID',
|
||||
`type_name` varchar(100) NOT NULL COMMENT '类型名称',
|
||||
`description` varchar(200) DEFAULT NULL COMMENT '类型描述',
|
||||
`calculation_method` tinyint NOT NULL DEFAULT '1' COMMENT '计算方式 1固定金额 2按比例 3按点击 4按展示',
|
||||
`sort_order` int NOT NULL DEFAULT '0' COMMENT '排序',
|
||||
`is_active` tinyint NOT NULL DEFAULT '1' COMMENT '是否启用 0禁用 1启用',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_company_type_name` (`company_id`,`type_name`),
|
||||
KEY `idx_company_id` (`company_id`),
|
||||
KEY `idx_sort_order` (`sort_order`),
|
||||
KEY `idx_is_active` (`is_active`),
|
||||
KEY `fk_ec_promotion_fee_type_creator` (`create_by`),
|
||||
KEY `fk_ec_promotion_fee_type_updater` (`update_by`),
|
||||
CONSTRAINT `fk_ec_promotion_fee_type_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_promotion_fee_type_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_promotion_fee_type_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-推广费类型表'
|
||||
|
||||
-- ========================================
|
||||
-- EC_SHOP
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `ec_shop`;
|
||||
CREATE TABLE `ec_shop` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '店铺ID',
|
||||
`company_id` bigint unsigned NOT NULL COMMENT '所属公司ID',
|
||||
`name` varchar(200) NOT NULL COMMENT '店铺名称',
|
||||
`logo_image_id` bigint unsigned DEFAULT NULL COMMENT 'logo图片ID',
|
||||
`platform` varchar(50) DEFAULT NULL COMMENT '平台(如淘宝、京东、拼多多)',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_company_id` (`company_id`),
|
||||
KEY `fk_ec_shop_logo_image` (`logo_image_id`),
|
||||
KEY `fk_ec_shop_creator` (`create_by`),
|
||||
KEY `fk_ec_shop_updater` (`update_by`),
|
||||
CONSTRAINT `fk_ec_shop_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_logo_image` FOREIGN KEY (`logo_image_id`) REFERENCES `sys_file` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-店铺表'
|
||||
|
||||
-- ========================================
|
||||
-- EC_SHOP_MONTHLY_TARGET
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `ec_shop_monthly_target`;
|
||||
CREATE TABLE `ec_shop_monthly_target` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '目标ID',
|
||||
`company_id` bigint unsigned NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint unsigned NOT NULL COMMENT '店铺ID',
|
||||
`target_month` date NOT NULL COMMENT '目标月份(格式:YYYY-MM-01)',
|
||||
`target_amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '目标销售额',
|
||||
`target_order_count` int NOT NULL DEFAULT '0' COMMENT '目标订单数',
|
||||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_shop_month` (`shop_id`,`target_month`),
|
||||
KEY `idx_company_id` (`company_id`),
|
||||
KEY `idx_shop_id` (`shop_id`),
|
||||
KEY `idx_target_month` (`target_month`),
|
||||
KEY `idx_company_shop_month` (`company_id`,`shop_id`,`target_month`),
|
||||
KEY `fk_ec_shop_monthly_target_creator` (`create_by`),
|
||||
KEY `fk_ec_shop_monthly_target_updater` (`update_by`),
|
||||
CONSTRAINT `fk_ec_shop_monthly_target_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_monthly_target_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_monthly_target_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_monthly_target_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-店铺月销量目标表'
|
||||
|
||||
-- ========================================
|
||||
-- EC_SHOP_PRODUCT_RELATION
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `ec_shop_product_relation`;
|
||||
CREATE TABLE `ec_shop_product_relation` (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '关联ID',
|
||||
`company_id` BIGINT UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` BIGINT UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`product_id` BIGINT UNSIGNED NOT NULL COMMENT '商品ID',
|
||||
`sort_order` INT NOT NULL DEFAULT 0 COMMENT '排序',
|
||||
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '关联ID',
|
||||
`company_id` bigint unsigned NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint unsigned NOT NULL COMMENT '店铺ID',
|
||||
`product_id` bigint unsigned NOT NULL COMMENT '商品ID',
|
||||
`sort_order` int NOT NULL DEFAULT '0' COMMENT '排序',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint unsigned DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_shop_product` (`shop_id`, `product_id`),
|
||||
UNIQUE KEY `uk_shop_product` (`shop_id`,`product_id`),
|
||||
KEY `idx_company_id` (`company_id`),
|
||||
KEY `idx_shop_id` (`shop_id`),
|
||||
KEY `idx_product_id` (`product_id`),
|
||||
@@ -289,69 +393,9 @@ CREATE TABLE `ec_shop_product_relation` (
|
||||
KEY `fk_ec_shop_product_creator` (`create_by`),
|
||||
KEY `fk_ec_shop_product_updater` (`update_by`),
|
||||
CONSTRAINT `fk_ec_shop_product_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_product_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_product_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_product_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_product_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_product_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_product_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-店铺商品关联表';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=129 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='电商-店铺商品关联表'
|
||||
|
||||
-- 刷单记录表
|
||||
CREATE TABLE `ec_brush_order` (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '刷单记录ID',
|
||||
`company_id` BIGINT UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` BIGINT UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`product_id` BIGINT UNSIGNED DEFAULT NULL COMMENT '商品ID(可选)',
|
||||
`product_spec_id` BIGINT UNSIGNED DEFAULT NULL COMMENT '商品规格ID(可选)',
|
||||
`brush_amount` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '刷单金额',
|
||||
`brush_time` TIMESTAMP NOT NULL COMMENT '刷单时间',
|
||||
`platform_order_no` VARCHAR(100) DEFAULT NULL COMMENT '平台订单号(可选)',
|
||||
`quantity` INT DEFAULT 1 COMMENT '刷单数量',
|
||||
`remark` VARCHAR(500) DEFAULT NULL COMMENT '备注',
|
||||
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_company_id` (`company_id`),
|
||||
KEY `idx_shop_id` (`shop_id`),
|
||||
KEY `idx_product_id` (`product_id`),
|
||||
KEY `idx_product_spec_id` (`product_spec_id`),
|
||||
KEY `idx_brush_time` (`brush_time`),
|
||||
KEY `idx_platform_order_no` (`platform_order_no`),
|
||||
KEY `idx_company_shop_time` (`company_id`, `shop_id`, `brush_time`),
|
||||
KEY `fk_ec_brush_order_creator` (`create_by`),
|
||||
KEY `fk_ec_brush_order_updater` (`update_by`),
|
||||
CONSTRAINT `fk_ec_brush_order_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_brush_order_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_brush_order_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_brush_order_product_spec` FOREIGN KEY (`product_spec_id`) REFERENCES `ec_product_spec` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_brush_order_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_brush_order_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-刷单记录表';
|
||||
|
||||
-- 店铺月销量目标表
|
||||
CREATE TABLE `ec_shop_monthly_target` (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '目标ID',
|
||||
`company_id` BIGINT UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` BIGINT UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`target_month` DATE NOT NULL COMMENT '目标月份(格式:YYYY-MM-01)',
|
||||
`target_amount` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '目标销售额',
|
||||
`target_order_count` INT NOT NULL DEFAULT 0 COMMENT '目标订单数',
|
||||
`remark` VARCHAR(500) DEFAULT NULL COMMENT '备注',
|
||||
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_company_id` (`company_id`),
|
||||
KEY `idx_shop_id` (`shop_id`),
|
||||
KEY `idx_target_month` (`target_month`),
|
||||
KEY `idx_company_shop_month` (`company_id`, `shop_id`, `target_month`),
|
||||
KEY `fk_ec_shop_monthly_target_creator` (`create_by`),
|
||||
KEY `fk_ec_shop_monthly_target_updater` (`update_by`),
|
||||
UNIQUE KEY `uk_shop_month` (`shop_id`, `target_month`),
|
||||
CONSTRAINT `fk_ec_shop_monthly_target_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_monthly_target_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_monthly_target_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_monthly_target_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-店铺月销量目标表';
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
-- ========================================
|
||||
-- 电商数据中台数据库设计
|
||||
-- 生成时间:2026-03-29
|
||||
-- ========================================
|
||||
|
||||
-- ========================================
|
||||
-- MEDIA_FILE
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `media_file`;
|
||||
CREATE TABLE `media_file` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
`company_id` bigint unsigned NOT NULL,
|
||||
@@ -20,8 +29,12 @@ CREATE TABLE `media_file` (
|
||||
KEY `idx_media_file_format` (`file_format`) USING BTREE COMMENT '文件格式索引',
|
||||
CONSTRAINT `fk_media_file_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_media_file_uploader` FOREIGN KEY (`upload_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='文件资源池表';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='文件资源池表'
|
||||
|
||||
-- ========================================
|
||||
-- MEDIA_IMAGE
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `media_image`;
|
||||
CREATE TABLE `media_image` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
`company_id` bigint unsigned NOT NULL,
|
||||
@@ -46,4 +59,5 @@ CREATE TABLE `media_image` (
|
||||
KEY `idx_media_image_format` (`image_format`) USING BTREE COMMENT '图片格式索引',
|
||||
CONSTRAINT `fk_media_image_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_media_image_uploader` FOREIGN KEY (`upload_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='图片资源池表';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='图片资源池表'
|
||||
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
-- ========================================
|
||||
-- 电商数据中台数据库设计
|
||||
-- 生成时间:2026-03-29
|
||||
-- ========================================
|
||||
|
||||
-- ========================================
|
||||
-- ORG_COMPANY
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `org_company`;
|
||||
CREATE TABLE `org_company` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '公司 id',
|
||||
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '公司名称',
|
||||
`expiration` datetime DEFAULT NULL COMMENT '订阅到期时间',
|
||||
`address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '公司地址',
|
||||
`contact_person` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '联系人',
|
||||
`contact_phone` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '联系电话',
|
||||
`owner_name` varchar(100) DEFAULT NULL COMMENT '公司拥有者姓名',
|
||||
`owner_phone` varchar(20) DEFAULT NULL COMMENT '公司拥有者电话',
|
||||
`email` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '邮箱',
|
||||
`logo` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT 'logo URL(冗余字段)',
|
||||
`logo_image_id` bigint unsigned DEFAULT NULL COMMENT 'logo图片ID',
|
||||
@@ -19,10 +28,38 @@ CREATE TABLE `org_company` (
|
||||
KEY `fk_org_company_updater` (`update_by`) USING BTREE,
|
||||
KEY `fk_org_company_logo_image` (`logo_image_id`) USING BTREE,
|
||||
CONSTRAINT `fk_org_company_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_org_company_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_org_company_logo_image` FOREIGN KEY (`logo_image_id`) REFERENCES `media_image` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='系统模块-公司表';
|
||||
CONSTRAINT `fk_org_company_logo_image` FOREIGN KEY (`logo_image_id`) REFERENCES `media_image` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_org_company_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='系统模块-公司表'
|
||||
|
||||
-- ========================================
|
||||
-- ORG_COMPANY_MEMBER
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `org_company_member`;
|
||||
CREATE TABLE `org_company_member` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`user_id` bigint unsigned NOT NULL,
|
||||
`company_id` bigint unsigned NOT NULL,
|
||||
`role` enum('owner','member') NOT NULL DEFAULT 'member',
|
||||
`position_id` bigint unsigned DEFAULT NULL,
|
||||
`status` tinyint NOT NULL DEFAULT '1' COMMENT '状态: 0=禁用, 1=正常',
|
||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP,
|
||||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`create_by` bigint unsigned DEFAULT NULL,
|
||||
`update_by` bigint unsigned DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_user_company` (`user_id`,`company_id`),
|
||||
KEY `idx_company` (`company_id`),
|
||||
KEY `idx_position` (`position_id`),
|
||||
CONSTRAINT `fk_cm_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `fk_cm_position` FOREIGN KEY (`position_id`) REFERENCES `org_position` (`id`) ON DELETE SET NULL,
|
||||
CONSTRAINT `fk_cm_user` FOREIGN KEY (`user_id`) REFERENCES `sys_user` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='公司成员表'
|
||||
|
||||
-- ========================================
|
||||
-- ORG_COMPANY_MENU
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `org_company_menu`;
|
||||
CREATE TABLE `org_company_menu` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '关联ID',
|
||||
`company_id` bigint unsigned NOT NULL COMMENT '公司ID',
|
||||
@@ -48,8 +85,12 @@ CREATE TABLE `org_company_menu` (
|
||||
CONSTRAINT `fk_org_company_menu_menu` FOREIGN KEY (`menu_id`) REFERENCES `sys_menu` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_org_company_menu_parent` FOREIGN KEY (`parent_id`) REFERENCES `org_company_menu` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_org_company_menu_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='公司菜单权限关联表';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=127 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='公司菜单权限关联表'
|
||||
|
||||
-- ========================================
|
||||
-- ORG_DEPARTMENT
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `org_department`;
|
||||
CREATE TABLE `org_department` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '部门 id',
|
||||
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '部门名称',
|
||||
@@ -70,8 +111,33 @@ CREATE TABLE `org_department` (
|
||||
CONSTRAINT `fk_org_department_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_org_department_parent` FOREIGN KEY (`parent_id`) REFERENCES `org_department` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_org_department_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='系统模块-部门表';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='系统模块-部门表'
|
||||
|
||||
-- ========================================
|
||||
-- ORG_DEPARTMENT_MEMBER
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `org_department_member`;
|
||||
CREATE TABLE `org_department_member` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`user_id` bigint unsigned NOT NULL,
|
||||
`department_id` bigint unsigned NOT NULL,
|
||||
`status` tinyint NOT NULL DEFAULT '1' COMMENT '状态: 0=禁用, 1=正常',
|
||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP,
|
||||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`create_by` bigint unsigned DEFAULT NULL,
|
||||
`update_by` bigint unsigned DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_user_department` (`user_id`,`department_id`),
|
||||
KEY `idx_department` (`department_id`),
|
||||
KEY `idx_user` (`user_id`),
|
||||
CONSTRAINT `fk_dm_department` FOREIGN KEY (`department_id`) REFERENCES `org_department` (`id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `fk_dm_user` FOREIGN KEY (`user_id`) REFERENCES `sys_user` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='部门成员表'
|
||||
|
||||
-- ========================================
|
||||
-- ORG_POSITION
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `org_position`;
|
||||
CREATE TABLE `org_position` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '岗位ID',
|
||||
`name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '岗位名称',
|
||||
@@ -90,8 +156,12 @@ CREATE TABLE `org_position` (
|
||||
CONSTRAINT `fk_org_position_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_org_position_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_org_position_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='岗位表';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='岗位表'
|
||||
|
||||
-- ========================================
|
||||
-- ORG_POSITION_COMPANY_MENU_MAP
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `org_position_company_menu_map`;
|
||||
CREATE TABLE `org_position_company_menu_map` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`position_id` bigint unsigned NOT NULL COMMENT '岗位ID',
|
||||
@@ -106,4 +176,5 @@ CREATE TABLE `org_position_company_menu_map` (
|
||||
CONSTRAINT `fk_rel_position_company_menu_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_rel_position_company_menu_menu` FOREIGN KEY (`company_menu_id`) REFERENCES `org_company_menu` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_rel_position_company_menu_position` FOREIGN KEY (`position_id`) REFERENCES `org_position` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='岗位与公司菜单权限中间表';
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='岗位与公司菜单权限中间表'
|
||||
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
-- ========================================
|
||||
-- 电商数据中台数据库设计
|
||||
-- 生成时间:2026-03-29
|
||||
-- ========================================
|
||||
|
||||
-- ========================================
|
||||
-- SUB_PLAN
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `sub_plan`;
|
||||
CREATE TABLE `sub_plan` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '套餐ID',
|
||||
`name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '套餐名称',
|
||||
@@ -15,8 +24,12 @@ CREATE TABLE `sub_plan` (
|
||||
KEY `fk_sub_plan_updater` (`update_by`) USING BTREE,
|
||||
CONSTRAINT `fk_sub_plan_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sub_plan_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='订阅套餐定义表';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='订阅套餐定义表'
|
||||
|
||||
-- ========================================
|
||||
-- SUB_PLAN_PRICING
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `sub_plan_pricing`;
|
||||
CREATE TABLE `sub_plan_pricing` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '定价ID',
|
||||
`plan_id` bigint unsigned NOT NULL COMMENT '对应套餐ID',
|
||||
@@ -34,8 +47,12 @@ CREATE TABLE `sub_plan_pricing` (
|
||||
CONSTRAINT `fk_sub_plan_pricing_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sub_plan_pricing_plan` FOREIGN KEY (`plan_id`) REFERENCES `sub_plan` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sub_plan_pricing_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='订阅套餐定价表';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='订阅套餐定价表'
|
||||
|
||||
-- ========================================
|
||||
-- SUB_SUBSCRIPTION
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `sub_subscription`;
|
||||
CREATE TABLE `sub_subscription` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '记录ID',
|
||||
`company_id` bigint unsigned NOT NULL COMMENT '公司ID(关联sys_company)',
|
||||
@@ -65,4 +82,5 @@ CREATE TABLE `sub_subscription` (
|
||||
CONSTRAINT `fk_sub_subscription_deleter` FOREIGN KEY (`delete_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sub_subscription_plan` FOREIGN KEY (`plan_id`) REFERENCES `sub_plan` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sub_subscription_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='订阅记录表中间表';
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='订阅记录表中间表'
|
||||
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
-- ========================================
|
||||
-- 电商数据中台数据库设计
|
||||
-- 生成时间:2026-03-29
|
||||
-- ========================================
|
||||
|
||||
-- ========================================
|
||||
-- SYS_USER
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `sys_user`;
|
||||
CREATE TABLE `sys_user` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '用户ID',
|
||||
`company_id` bigint unsigned DEFAULT NULL COMMENT '公司 id',
|
||||
`department_id` bigint unsigned DEFAULT NULL COMMENT '部门 id',
|
||||
`position_id` bigint unsigned DEFAULT NULL COMMENT '岗位 id',
|
||||
`login_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '登录账号',
|
||||
`password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '登录密码',
|
||||
`phone` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '手机号码',
|
||||
@@ -14,6 +20,7 @@ CREATE TABLE `sys_user` (
|
||||
`pwd_update_time` timestamp NULL DEFAULT NULL COMMENT '密码最后更新时间',
|
||||
`last_login_ip` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '最后登录 ip',
|
||||
`last_login_date` timestamp NULL DEFAULT NULL COMMENT '最后登录时间',
|
||||
`last_company_id` bigint unsigned DEFAULT NULL COMMENT '最后登录公司ID',
|
||||
`freeze_date` timestamp NULL DEFAULT NULL COMMENT '冻结时间',
|
||||
`freeze_cause` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '冻结原因',
|
||||
`status` tinyint unsigned DEFAULT NULL COMMENT '状态(0-正常 1-删除 2-停用 3-冻结)',
|
||||
@@ -24,19 +31,19 @@ CREATE TABLE `sys_user` (
|
||||
`update_by` bigint unsigned DEFAULT NULL COMMENT '更新者',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `uk_login_code` (`login_code`) USING BTREE,
|
||||
UNIQUE KEY `uk_phone` (`login_code`) USING BTREE,
|
||||
UNIQUE KEY `uk_phone` (`phone`),
|
||||
KEY `idx_role` (`role`) USING BTREE,
|
||||
KEY `idx_status` (`status`) USING BTREE,
|
||||
KEY `fk_user_company` (`company_id`) USING BTREE,
|
||||
KEY `fk_user_department` (`department_id`) USING BTREE,
|
||||
KEY `fk_user_position` (`position_id`) USING BTREE,
|
||||
KEY `fk_user_avatar_image` (`avatar_image_id`) USING BTREE,
|
||||
CONSTRAINT `fk_user_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_user_department` FOREIGN KEY (`department_id`) REFERENCES `org_department` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_user_position` FOREIGN KEY (`position_id`) REFERENCES `org_position` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_user_avatar_image` FOREIGN KEY (`avatar_image_id`) REFERENCES `media_image` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='系统模块-用户表';
|
||||
KEY `fk_user_last_company` (`last_company_id`),
|
||||
CONSTRAINT `fk_user_avatar_image` FOREIGN KEY (`avatar_image_id`) REFERENCES `media_image` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_user_last_company` FOREIGN KEY (`last_company_id`) REFERENCES `org_company` (`id`) ON DELETE SET NULL
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='系统模块-用户表'
|
||||
|
||||
-- ========================================
|
||||
-- SYS_MENU
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `sys_menu`;
|
||||
CREATE TABLE `sys_menu` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '菜单 id',
|
||||
`parent_id` bigint unsigned DEFAULT NULL COMMENT '父菜单 id',
|
||||
@@ -63,8 +70,12 @@ CREATE TABLE `sys_menu` (
|
||||
CONSTRAINT `fk_nemu_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_nemu_parent` FOREIGN KEY (`parent_id`) REFERENCES `sys_menu` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_nemu_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='系统模块-菜单权限表';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='系统模块-菜单权限表'
|
||||
|
||||
-- ========================================
|
||||
-- SYS_PERMISSION
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `sys_permission`;
|
||||
CREATE TABLE `sys_permission` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '权限ID',
|
||||
`code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '权限码(唯一标识,如 user:add, order:approve)',
|
||||
@@ -82,8 +93,12 @@ CREATE TABLE `sys_permission` (
|
||||
KEY `fk_permission_updater` (`update_by`) USING BTREE,
|
||||
CONSTRAINT `fk_permission_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_permission_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='系统模块-权限定义表';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='系统模块-权限定义表'
|
||||
|
||||
-- ========================================
|
||||
-- SYS_MENU_PERMISSION_MAP
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `sys_menu_permission_map`;
|
||||
CREATE TABLE `sys_menu_permission_map` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`menu_id` bigint unsigned NOT NULL COMMENT '菜单ID',
|
||||
@@ -98,9 +113,12 @@ CREATE TABLE `sys_menu_permission_map` (
|
||||
CONSTRAINT `fk_menu_permission_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_menu_permission_menu` FOREIGN KEY (`menu_id`) REFERENCES `sys_menu` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_menu_permission_permission` FOREIGN KEY (`permission_id`) REFERENCES `sys_permission` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='菜单与权限关联表';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='菜单与权限关联表'
|
||||
|
||||
-- 统一文件资源表(替代 media_file 和 media_image)
|
||||
-- ========================================
|
||||
-- SYS_FILE
|
||||
-- ========================================
|
||||
DROP TABLE IF EXISTS `sys_file`;
|
||||
CREATE TABLE `sys_file` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '文件ID',
|
||||
`company_id` bigint unsigned NOT NULL COMMENT '公司ID',
|
||||
@@ -128,8 +146,11 @@ CREATE TABLE `sys_file` (
|
||||
KEY `idx_sys_file_category` (`category`) USING BTREE COMMENT '文件分类索引',
|
||||
KEY `idx_sys_file_storage_type` (`storage_type`) USING BTREE COMMENT '存储类型索引',
|
||||
KEY `idx_sys_file_delete_time` (`delete_time`) USING BTREE COMMENT '删除时间索引,用于软删除查询',
|
||||
KEY `fk_sys_file_updater` (`update_by`),
|
||||
KEY `fk_sys_file_deleter` (`delete_by`),
|
||||
CONSTRAINT `fk_sys_file_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_file_uploader` FOREIGN KEY (`upload_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_file_deleter` FOREIGN KEY (`delete_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_file_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_sys_file_deleter` FOREIGN KEY (`delete_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='系统模块-统一文件资源表(支持本地存储和对象存储)';
|
||||
CONSTRAINT `fk_sys_file_uploader` FOREIGN KEY (`upload_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='系统模块-统一文件资源表(支持本地存储和对象存储)'
|
||||
|
||||
|
||||
+34
-1
@@ -1,9 +1,12 @@
|
||||
package top.xyquan.ecomdmbbackend.utils;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.model.po.CompanyMemberPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.companymember.service.CompanyMemberService;
|
||||
|
||||
/**
|
||||
* 当前用户上下文工具类
|
||||
@@ -13,9 +16,11 @@ import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
public class CurrentUserContext {
|
||||
|
||||
private final JwtUtils jwtUtils;
|
||||
private final CompanyMemberService companyMemberService;
|
||||
|
||||
public CurrentUserContext(JwtUtils jwtUtils) {
|
||||
public CurrentUserContext(JwtUtils jwtUtils, @Lazy CompanyMemberService companyMemberService) {
|
||||
this.jwtUtils = jwtUtils;
|
||||
this.companyMemberService = companyMemberService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,6 +45,7 @@ public class CurrentUserContext {
|
||||
|
||||
/**
|
||||
* 获取当前用户公司ID
|
||||
* 改为从 org_company_member 表查(用当前 userId + 当前 token 中的 companyId)
|
||||
*
|
||||
* @return 公司ID
|
||||
* @throws BusinessException 如果无法获取公司信息
|
||||
@@ -103,4 +109,31 @@ public class CurrentUserContext {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
return authentication != null && authentication.isAuthenticated();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户在公司中的成员信息
|
||||
*
|
||||
* @return CompanyMemberPO
|
||||
* @throws BusinessException 如果无法获取成员信息
|
||||
*/
|
||||
public CompanyMemberPO getCurrentMember() {
|
||||
Long userId = getCurrentUserId();
|
||||
Long companyId = getCurrentCompanyId();
|
||||
CompanyMemberPO member = companyMemberService.getByUserIdAndCompanyId(userId, companyId);
|
||||
if (member == null) {
|
||||
throw new BusinessException("用户不属于当前公司");
|
||||
}
|
||||
return member;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户在公司中的成员角色
|
||||
*
|
||||
* @return "owner" 或 "member"
|
||||
* @throws BusinessException 如果无法获取成员信息
|
||||
*/
|
||||
public String getCurrentMemberRole() {
|
||||
CompanyMemberPO member = getCurrentMember();
|
||||
return member.getRole().getCode();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user