From 8b9b29dbf196b16e722ab7c9ac5a1b01802cc35d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E9=B8=BF=E5=B1=95?= <18031053041@163.com> Date: Thu, 30 Jul 2026 10:04:03 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=8F=91=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mhd-user-center/src/main/resources/bootstrap.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mhd-user-center/src/main/resources/bootstrap.yml b/mhd-user-center/src/main/resources/bootstrap.yml index dd13bfba5..7b6baaea4 100644 --- a/mhd-user-center/src/main/resources/bootstrap.yml +++ b/mhd-user-center/src/main/resources/bootstrap.yml @@ -20,15 +20,15 @@ spring: discovery: # server-addr: 127.0.0.1:8848 # 线上测试环境配置 容器名+端口号 -# server-addr: 10.33.0.129:6010 - server-addr: 10.102.192.31:6848 + server-addr: 10.33.0.129:6010 +# server-addr: 10.102.192.30:6848 username: nacos password: manhuoda@2023 config: # server-addr: 127.0.0.1:8848 # 线上测试环境配置 容器名+端口号 -# server-addr: 10.33.0.129:6010 - server-addr: 10.102.192.31:6848 + server-addr: 10.33.0.129:6010 +# server-addr: 10.102.192.30:6848 username: nacos password: manhuoda@2023 group: DEFAULT_GROUP # 默认分组就是DEFAULT_GROUP,如果使用默认分组可以不配置 From 2bd4d5bb638742573689c9d8791f180f90d1eb2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E9=B8=BF=E5=B1=95?= <18031053041@163.com> Date: Thu, 30 Jul 2026 10:08:24 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=8F=91=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UserShipperApplicationService.java | 164 ++++++++++++++++-- 1 file changed, 145 insertions(+), 19 deletions(-) diff --git a/mhd-user-center/src/main/java/com/mhd/user/application/service/UserShipperApplicationService.java b/mhd-user-center/src/main/java/com/mhd/user/application/service/UserShipperApplicationService.java index 98ee09ca5..5ec35096a 100644 --- a/mhd-user-center/src/main/java/com/mhd/user/application/service/UserShipperApplicationService.java +++ b/mhd-user-center/src/main/java/com/mhd/user/application/service/UserShipperApplicationService.java @@ -23,7 +23,10 @@ import com.mhd.common.core.enums.MessageTypeEnum; import com.mhd.common.core.enums.WebsocketTypeEnum; import com.mhd.common.core.feign.ThirdPartyServiceFeign; import com.mhd.common.core.service.jPush.AsyncJPushApplicationService; +import com.mhd.common.core.utils.AESUtil; +import com.mhd.common.core.utils.OConvertUtils; import com.mhd.common.core.utils.StringUtils; +import com.mhd.common.security.utils.password.PasswordUtil; import com.mhd.system.api.FinanceServiceFeign; import com.mhd.system.api.WlhyServiceFeign; import com.mhd.system.api.domain.UserShipperEntityFeign; @@ -361,7 +364,7 @@ public class UserShipperApplicationService { /** * 从 Excel 导入委托方 - * 模版列:登录账号、公司名称、联系人、联系电话、地址、详细地址、备注、结算币种 + * 模版列:登录账号、公司名称、联系人、联系电话、地址、详细地址、备注、结算币种、NC客户编码 */ public com.mhd.common.core.web.domain.AjaxResult importShipperFromExcel(org.springframework.web.multipart.MultipartFile file) { if (file == null || file.isEmpty()) { @@ -372,6 +375,12 @@ public class UserShipperApplicationService { org.apache.poi.ss.usermodel.Sheet sheet = workbook.getSheetAt(0); int total = 0, success = 0, failed = 0; java.util.List errors = new java.util.ArrayList<>(); + LoginUser loginUser = SecurityUtils.getLoginUser(); + if (loginUser == null || loginUser.getUserPo() == null) { + return com.mhd.common.core.web.domain.AjaxResult.error("登录信息失效"); + } + Long currentOrgId = loginUser.getUserPo().getOrganizationId(); + String currentOrgName = loginUser.getUserPo().getOrganizationName(); for (int i = 1; i <= sheet.getLastRowNum(); i++) { org.apache.poi.ss.usermodel.Row row = sheet.getRow(i); if (row == null) continue; @@ -380,14 +389,21 @@ public class UserShipperApplicationService { if (org.springframework.util.StringUtils.isEmpty(companyName)) continue; total++; try { + String contactName = getCellStr(row.getCell(2)); + String contactPhone = getCellStr(row.getCell(3)); + String address = getCellStr(row.getCell(4)); + String detailedAddress = getCellStr(row.getCell(5)); + String remark = getCellStr(row.getCell(6)); + String settlementCurrency = getCellStr(row.getCell(7)); + String ncCustomerCode = getCellStr(row.getCell(8)); + // 先按公司名称查是否已存在委托方 UserShipperEntity existingShipper = findFirstByShipperEnterpriseNameAcrossOrgs(companyName); if (existingShipper != null && existingShipper.getShipperId() != null) { - // 已存在:只更新NC客户编码和org_code - appendOrganizationToExistingShipper(existingShipper, - SecurityUtils.getLoginUser().getUserPo().getOrganizationId(), - SecurityUtils.getLoginUser().getUserPo().getOrganizationName(), - userAccount, SecurityUtils.getLoginUser()); + // 已存在:按模板更新指定字段 + updateShipperFromExcel(existingShipper, userAccount, companyName, + contactName, contactPhone, address, detailedAddress, + remark, settlementCurrency, ncCustomerCode, loginUser, currentOrgId); success++; } else { UserShipperDO shipperDO = new UserShipperDO(); @@ -395,28 +411,27 @@ public class UserShipperApplicationService { shipperDO.setDataSource(2); shipperDO.setUserAccount(userAccount); shipperDO.setShipperEnterpriseName(companyName); - // 登录账号同时作为NC客户编码 - shipperDO.setCustomerNcCode(userAccount); - String contactName = getCellStr(row.getCell(2)); - String contactPhone = getCellStr(row.getCell(3)); + // NC客户编码使用模板中的独立字段,不再复用登录账号 + shipperDO.setCustomerNcCode(ncCustomerCode); // 联系人 -> user表 user_name + user_shipper表 user_name_shipper shipperDO.setUserName(contactName); shipperDO.setUserNameShipper(contactName); // 联系电话 -> user表 user_phone shipperDO.setUserPhone(contactPhone); // 地址 -> user表 user_area_name,详细地址 -> user表 user_area_address - shipperDO.setUserAreaName(getCellStr(row.getCell(4))); - shipperDO.setUserAreaAddress(getCellStr(row.getCell(5))); - shipperDO.setRemark(getCellStr(row.getCell(6))); - shipperDO.setSettlementCurrency(getCellStr(row.getCell(7))); + shipperDO.setUserAreaName(address); + shipperDO.setUserAreaAddress(detailedAddress); + shipperDO.setRemark(remark); + shipperDO.setSettlementCurrency(settlementCurrency); + // 新导入账号默认密码 Aa123456(按前端加密约定先 AES 加密) + shipperDO.setUserPassword(AESUtil.encrypt("Aa123456")); // 初始化 orgCode:记录当前组织信息和NC客户编码 com.alibaba.fastjson.JSONArray orgCodeArray = new com.alibaba.fastjson.JSONArray(); com.alibaba.fastjson.JSONObject orgItem = new com.alibaba.fastjson.JSONObject(); - LoginUser loginUser = SecurityUtils.getLoginUser(); - orgItem.put("name", loginUser.getUserPo().getOrganizationName()); - orgItem.put("code", loginUser.getUserPo().getOrganizationId()); - orgItem.put("ncCustomer", userAccount); - orgItem.put("names", loginUser.getUserPo().getOrganizationId()); + orgItem.put("name", currentOrgName); + orgItem.put("code", currentOrgId); + orgItem.put("ncCustomer", ncCustomerCode); + orgItem.put("names", currentOrgId); orgCodeArray.add(orgItem); shipperDO.setOrgCode(orgCodeArray.toJSONString()); addShipper(shipperDO); @@ -441,6 +456,117 @@ public class UserShipperApplicationService { } } + /** + * 按Excel模板更新已存在的委托方(只更新模板中的字段) + */ + private void updateShipperFromExcel(UserShipperEntity existingShipper, String userAccount, + String companyName, String contactName, String contactPhone, + String address, String detailedAddress, String remark, + String settlementCurrency, String ncCustomerCode, + LoginUser loginUser, Long currentOrgId) { + Long userId = existingShipper.getUserId(); + // 从 user 主表读取当前登录账号(user_shipper 表无 user_account 字段) + UserPo existingUser = null; + String existingUserAccount = null; + if (userId != null) { + existingUser = userDomainService.selectByUserId(userId); + if (existingUser != null) { + existingUserAccount = existingUser.getUserAccount(); + } + } + if (StringUtils.isBlank(existingUserAccount) && StringUtils.isBlank(userAccount)) { + throw new ServiceException("登录账号不能为空"); + } + // 登录账号变更时校验唯一性 + if (StringUtils.isNotBlank(userAccount) && !userAccount.equals(existingUserAccount)) { + UserDO checkDO = new UserDO(); + checkDO.setUserAccount(userAccount); + checkDO.setTopOrganizationId(existingShipper.getTopOrganizationId()); + UserPo existedUser = userDomainService.findByTopOrganizationIdAndUserAccount(checkDO); + if (existedUser != null && !existedUser.getUserId().equals(userId)) { + throw new ServiceException("登录账号已存在:" + userAccount); + } + } + Date now = new Date(); + Long updateBy = loginUser.getUserPo().getUserId(); + String updateByName = loginUser.getUserPo().getUserName(); + + // 1. 更新 user_shipper 表指定字段 + // 注意:user_shipper 表没有 user_account 字段,登录账号在 user 主表维护 + UserShipperEntity shipperUpdate = new UserShipperEntity(); + shipperUpdate.setShipperId(existingShipper.getShipperId()); + shipperUpdate.setShipperEnterpriseName(companyName); + shipperUpdate.setUserNameShipper(contactName); + shipperUpdate.setUserAreaName(address); + shipperUpdate.setUserAreaAddress(detailedAddress); + shipperUpdate.setRemark(remark); + shipperUpdate.setSettlementCurrency(settlementCurrency); + shipperUpdate.setCustomerNcCode(ncCustomerCode); + shipperUpdate.setUpdateBy(updateBy); + shipperUpdate.setUpdateByName(updateByName); + shipperUpdate.setUpdateTime(now); + userShipperMapper.updateById(shipperUpdate); + + // 2. 同步更新 user 表指定字段 + if (userId != null) { + UserDO userDO = new UserDO(); + userDO.setUserId(userId); + if (StringUtils.isNotBlank(userAccount)) { + userDO.setUserAccount(userAccount); + } + userDO.setUserName(contactName); + userDO.setUserPhone(contactPhone); + userDO.setUserAreaName(address); + userDO.setUserAreaAddress(detailedAddress); + userDO.setUpdateBy(updateBy); + userDO.setUpdateByName(updateByName); + userDO.setUpdateTime(now); + // 如果现有账号没有密码,设置默认密码 Aa123456(与 addUserInfoShipper 一致的加密流程) + if (existingUser != null && StringUtils.isBlank(existingUser.getUserPassword())) { + String finalAccount = StringUtils.isNotBlank(userAccount) ? userAccount : existingUser.getUserAccount(); + String salt = OConvertUtils.randomGen(8); + String passwordEncode = PasswordUtil.encrypt(finalAccount, "Aa123456", salt); + userDO.setUserPassword(passwordEncode); + userDO.setUserSalt(salt); + } + userDomainService.updateUser(userDO); + } + + // 3. 更新 orgCode 中当前组织的 ncCustomer + String existingOrgCode = existingShipper.getOrgCode(); + com.alibaba.fastjson.JSONArray orgCodeArray = new com.alibaba.fastjson.JSONArray(); + boolean hasOrg = false; + if (StringUtils.isNotEmpty(existingOrgCode)) { + try { + orgCodeArray = com.alibaba.fastjson.JSONArray.parseArray(existingOrgCode); + for (int i = 0; i < orgCodeArray.size(); i++) { + com.alibaba.fastjson.JSONObject orgItem = orgCodeArray.getJSONObject(i); + if (currentOrgId != null && currentOrgId.equals(orgItem.getLong("code"))) { + orgItem.put("ncCustomer", ncCustomerCode); + hasOrg = true; + } + } + } catch (Exception e) { + log.error("解析orgCode失败,shipperId={}", existingShipper.getShipperId(), e); + } + } + if (!hasOrg) { + com.alibaba.fastjson.JSONObject newOrgItem = new com.alibaba.fastjson.JSONObject(); + newOrgItem.put("name", loginUser.getUserPo().getOrganizationName()); + newOrgItem.put("code", currentOrgId); + newOrgItem.put("ncCustomer", ncCustomerCode); + newOrgItem.put("names", currentOrgId); + orgCodeArray.add(newOrgItem); + } + UserShipperEntity orgCodeUpdate = new UserShipperEntity(); + orgCodeUpdate.setShipperId(existingShipper.getShipperId()); + orgCodeUpdate.setOrgCode(orgCodeArray.toJSONString()); + orgCodeUpdate.setUpdateBy(updateBy); + orgCodeUpdate.setUpdateByName(updateByName); + orgCodeUpdate.setUpdateTime(now); + userShipperMapper.updateById(orgCodeUpdate); + } + private String getCellStr(org.apache.poi.ss.usermodel.Cell cell) { if (cell == null) return null; cell.setCellType(org.apache.poi.ss.usermodel.CellType.STRING); From 69412f7293a5919c8793d2afaf05d0e34fdfa68d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E9=B8=BF=E5=B1=95?= <18031053041@163.com> Date: Thu, 30 Jul 2026 11:43:06 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=8F=91=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mhd/system/api/BmsServiceFeign.java | 2 +- .../com/mhd/system/api/OmsServiceFeign.java | 2 +- .../com/mhd/system/api/WlhyServiceFeign.java | 2 +- .../com/mhd/system/api/WmsServiceFeign.java | 2 +- .../com/mhd/system/api/YmsServiceFeign.java | 2 +- .../UserShipperApplicationService.java | 38 ++++++++++++++++++- 6 files changed, 42 insertions(+), 6 deletions(-) diff --git a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/BmsServiceFeign.java b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/BmsServiceFeign.java index e18484e8d..91f2f8a11 100644 --- a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/BmsServiceFeign.java +++ b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/BmsServiceFeign.java @@ -18,7 +18,7 @@ import java.util.Set; /** * bms财务结算系统feign调用接口 */ -@FeignClient(contextId = "BmsService", value = ServiceNameConstants.BMS_SERVICE, url = "http://10.102.192.3:8019",fallbackFactory = RemoteBmsFeignFallbackFactory.class, configuration = FeignAutoConfiguration.class) +@FeignClient(contextId = "BmsService", value = ServiceNameConstants.BMS_SERVICE, url = "http://10.33.0.109:8019",fallbackFactory = RemoteBmsFeignFallbackFactory.class, configuration = FeignAutoConfiguration.class) public interface BmsServiceFeign { diff --git a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/OmsServiceFeign.java b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/OmsServiceFeign.java index e34bb9cd4..03d48d2f4 100644 --- a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/OmsServiceFeign.java +++ b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/OmsServiceFeign.java @@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.RequestBody; import java.util.List; import java.util.concurrent.CompletableFuture; -@FeignClient(contextId = "OmsService", value = ServiceNameConstants.OMS_SERVICE,url = "http://10.102.192.4:8017", fallbackFactory = RemoteOmsFeignFallbackFactory.class, configuration = FeignAutoConfiguration.class) +@FeignClient(contextId = "OmsService", value = ServiceNameConstants.OMS_SERVICE,url = "http://10.33.0.99:8017", fallbackFactory = RemoteOmsFeignFallbackFactory.class, configuration = FeignAutoConfiguration.class) public interface OmsServiceFeign { diff --git a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/WlhyServiceFeign.java b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/WlhyServiceFeign.java index e4a817238..ba9a45148 100644 --- a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/WlhyServiceFeign.java +++ b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/WlhyServiceFeign.java @@ -26,7 +26,7 @@ import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.Map; -@FeignClient(contextId = "commonWlhyServiceFeign",value = ServiceNameConstants.WLHY_SERVICE,url = "http://10.102.192.30:8014",configuration = FeignAutoConfiguration.class) +@FeignClient(contextId = "commonWlhyServiceFeign",value = ServiceNameConstants.WLHY_SERVICE,url = "http://10.33.0.129:8014",configuration = FeignAutoConfiguration.class) public interface WlhyServiceFeign { /** diff --git a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/WmsServiceFeign.java b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/WmsServiceFeign.java index 743be7c29..688e5ea7c 100644 --- a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/WmsServiceFeign.java +++ b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/WmsServiceFeign.java @@ -21,7 +21,7 @@ import java.util.Map; * @description: TODO * @date 2024/5/10 8:58 **/ -@FeignClient(contextId = "remoteWmsServiceFeign",value = ServiceNameConstants.WMS_SERVICE, url = "http://10.102.192.3:8016", fallbackFactory = RemoteWmsFallbackFactory.class, configuration = FeignAutoConfiguration.class) +@FeignClient(contextId = "remoteWmsServiceFeign",value = ServiceNameConstants.WMS_SERVICE, url = "http://10.33.0.109:8016", fallbackFactory = RemoteWmsFallbackFactory.class, configuration = FeignAutoConfiguration.class) public interface WmsServiceFeign { /** diff --git a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/YmsServiceFeign.java b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/YmsServiceFeign.java index dfac7337f..48d76d01e 100644 --- a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/YmsServiceFeign.java +++ b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/YmsServiceFeign.java @@ -9,7 +9,7 @@ import com.mhd.system.api.feign.FeignAutoConfiguration; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.*; -@FeignClient(contextId = "YmsService", value = ServiceNameConstants.YMS_SERVICE,fallbackFactory = RemoteBmsFeignFallbackFactory.class,url = "http://10.102.192.4:8018", configuration = FeignAutoConfiguration.class) +@FeignClient(contextId = "YmsService", value = ServiceNameConstants.YMS_SERVICE,fallbackFactory = RemoteBmsFeignFallbackFactory.class,url = "http://10.33.0.99:8018", configuration = FeignAutoConfiguration.class) public interface YmsServiceFeign { /** diff --git a/mhd-user-center/src/main/java/com/mhd/user/application/service/UserShipperApplicationService.java b/mhd-user-center/src/main/java/com/mhd/user/application/service/UserShipperApplicationService.java index 5ec35096a..a73ad76d5 100644 --- a/mhd-user-center/src/main/java/com/mhd/user/application/service/UserShipperApplicationService.java +++ b/mhd-user-center/src/main/java/com/mhd/user/application/service/UserShipperApplicationService.java @@ -434,7 +434,11 @@ public class UserShipperApplicationService { orgItem.put("names", currentOrgId); orgCodeArray.add(orgItem); shipperDO.setOrgCode(orgCodeArray.toJSONString()); - addShipper(shipperDO); + Map addResult = addShipper(shipperDO); + Object newUserIdObj = addResult.get("userId"); + if (newUserIdObj instanceof Long) { + assignCompanyRoleIfMissing((Long) newUserIdObj, currentOrgId); + } success++; } } catch (Exception e) { @@ -456,6 +460,36 @@ public class UserShipperApplicationService { } } + /** + * 导入时若账号没有任何角色,则补分配企业货主角色 + */ + private void assignCompanyRoleIfMissing(Long userId, Long organizationId) { + if (userId == null || organizationId == null) { + return; + } + List existingRoles = userRoleDomainService.selectRolesByUserId(userId); + if (CollUtil.isNotEmpty(existingRoles)) { + return; + } + // 按 role_code + organization_id 精确匹配角色(selectByOrganizationIdAndRoleCode 的 common_where 不含 roleCode 过滤,不适用) + RolePO rolePO = roleDomainService.selectByRoleCodeAndOrganizationId(RoleEnum.COMPANY.getCode(), organizationId); + if (rolePO == null) { + log.warn("组织{}下未找到{}角色,无法为导入用户{}分配角色", organizationId, RoleEnum.COMPANY.getCode(), userId); + return; + } + // 1. 写入 user_role 表 + UserRoleDo userRoleDo = new UserRoleDo(); + userRoleDo.setUserId(userId); + userRoleDo.setRoleId(rolePO.getRoleId()); + userRoleDomainService.addUserRole(userRoleDo); + // 2. 同步更新 user 表的 role_code / role_name + UserDO userDO = new UserDO(); + userDO.setUserId(userId); + userDO.setRoleCode(RoleEnum.COMPANY.getCode()); + userDO.setRoleName(RoleEnum.COMPANY.getName()); + userDomainService.updateUser(userDO); + } + /** * 按Excel模板更新已存在的委托方(只更新模板中的字段) */ @@ -530,6 +564,8 @@ public class UserShipperApplicationService { userDO.setUserSalt(salt); } userDomainService.updateUser(userDO); + // 如果该账号没有任何角色,补分配企业货主角色,避免登录报“账号未授权角色信息” + assignCompanyRoleIfMissing(userId, existingShipper.getOrganizationId()); } // 3. 更新 orgCode 中当前组织的 ncCustomer