|
|
@@ -1396,9 +1396,117 @@ public class CompanyUserServiceImpl implements ICompanyUserService
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 生成基础邀请码
|
|
|
- */
|
|
|
+ @Override
|
|
|
+ public int updateUserParentId(Long userId, Long parentId) {
|
|
|
+ CompanyUser user = new CompanyUser();
|
|
|
+ user.setUserId(userId);
|
|
|
+ user.setParentId(parentId);
|
|
|
+ return companyUserMapper.updateCompanyUser(user);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int batchUpdateUserParentId(List<Long> userIds, Long parentId) {
|
|
|
+ int count = 0;
|
|
|
+ for (Long userId : userIds) {
|
|
|
+ count += updateUserParentId(userId, parentId);
|
|
|
+ }
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R initUserHierarchy(Long companyId) {
|
|
|
+ try {
|
|
|
+ List<CompanyRole> roles = roleMapper.selectRoleListByCompanyId(companyId);
|
|
|
+ Long adminRoleId = null;
|
|
|
+ Long leaderRoleId = null;
|
|
|
+ Long managerRoleId = null;
|
|
|
+ Long memberRoleId = null;
|
|
|
+
|
|
|
+ for (CompanyRole role : roles) {
|
|
|
+ String roleKey = role.getRoleKey();
|
|
|
+ String roleName = role.getRoleName();
|
|
|
+ if ("admin".equals(roleKey) || "general_manager".equals(roleKey) || "logistics_manager".equals(roleKey) ||
|
|
|
+ (roleName != null && (roleName.contains("管理员") || roleName.contains("总经理") || roleName.contains("物流经理")))) {
|
|
|
+ adminRoleId = role.getRoleId();
|
|
|
+ } else if ("leader".equals(roleKey) || "zuzhang".equals(roleKey) ||
|
|
|
+ (roleName != null && roleName.contains("组长"))) {
|
|
|
+ leaderRoleId = role.getRoleId();
|
|
|
+ } else if ("sales_manager".equals(roleKey) || "xiaoshoujingli".equals(roleKey) ||
|
|
|
+ (roleName != null && roleName.contains("销售经理"))) {
|
|
|
+ managerRoleId = role.getRoleId();
|
|
|
+ } else if ("member".equals(roleKey) || "zuyuan".equals(roleKey) ||
|
|
|
+ (roleName != null && roleName.contains("组员"))) {
|
|
|
+ memberRoleId = role.getRoleId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ int initCount = 0;
|
|
|
+ StringBuilder msg = new StringBuilder();
|
|
|
+
|
|
|
+ if (leaderRoleId != null && memberRoleId != null) {
|
|
|
+ int count = companyUserMapper.initMemberParentId(companyId, leaderRoleId, memberRoleId);
|
|
|
+ initCount += count;
|
|
|
+ msg.append("组员→组长:").append(count).append("条; ");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (managerRoleId != null && leaderRoleId != null) {
|
|
|
+ int count = companyUserMapper.initLeaderParentId(companyId, managerRoleId, leaderRoleId);
|
|
|
+ initCount += count;
|
|
|
+ msg.append("组长→销售经理:").append(count).append("条; ");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (adminRoleId != null && managerRoleId != null) {
|
|
|
+ int count = companyUserMapper.initManagerParentId(companyId, adminRoleId, managerRoleId);
|
|
|
+ initCount += count;
|
|
|
+ msg.append("销售经理→管理员:").append(count).append("条; ");
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok("初始化完成,共更新 " + initCount + " 条记录。" + msg.toString());
|
|
|
+ } catch (Exception e) {
|
|
|
+ return R.error("初始化失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R initAllCompanyUserHierarchy() {
|
|
|
+ try {
|
|
|
+ List<Long> companyIds = companyService.selectCompanyIds();
|
|
|
+ if (companyIds == null || companyIds.isEmpty()) {
|
|
|
+ return R.ok("没有需要初始化的公司");
|
|
|
+ }
|
|
|
+
|
|
|
+ int totalCount = 0;
|
|
|
+ int successCount = 0;
|
|
|
+ int failCount = 0;
|
|
|
+ StringBuilder failMsg = new StringBuilder();
|
|
|
+
|
|
|
+ for (Long companyId : companyIds) {
|
|
|
+ totalCount++;
|
|
|
+ try {
|
|
|
+ R result = initUserHierarchy(companyId);
|
|
|
+ if (result.get("code") != null && (int) result.get("code") == 200) {
|
|
|
+ successCount++;
|
|
|
+ } else {
|
|
|
+ failCount++;
|
|
|
+ failMsg.append("公司ID:").append(companyId).append(" 初始化失败; ");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ failCount++;
|
|
|
+ failMsg.append("公司ID:").append(companyId).append(" 异常:").append(e.getMessage()).append("; ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok("批量初始化完成,共处理 " + totalCount + " 个公司,成功 " + successCount + " 个,失败 " + failCount + " 个。" + failMsg.toString());
|
|
|
+ } catch (Exception e) {
|
|
|
+ return R.error("批量初始化失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CompanyUser> selectSubordinateList(Long userId) {
|
|
|
+ return companyUserMapper.selectSubordinateList(userId);
|
|
|
+ }
|
|
|
+
|
|
|
private static String generateBaseCode(Long salesId) {
|
|
|
// 简单的算法:销售ID经过简单变换
|
|
|
long transformed = (salesId * 31L + 12345L) % 1000000L;
|