| | |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.Set; |
| | | |
| | | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.QC_NO_TEMPLATE; |
| | |
| | | private Map<String, Long> supplierNameMap; |
| | | /** 客户名称 -> 编号 */ |
| | | private Map<String, Long> customerNameMap; |
| | | /** 当前登录用户可见的客户编号;null 表示不限制 */ |
| | | private Set<Long> permittedClientIds; |
| | | private boolean clientPermissionLoaded; |
| | | |
| | | /** |
| | | * 开始一次导入:清空上一次导入的缓存,保证新建的供应商/客户/方案本次即可命中 |
| | |
| | | templateNameMap = null; |
| | | supplierNameMap = null; |
| | | customerNameMap = null; |
| | | permittedClientIds = null; |
| | | clientPermissionLoaded = false; |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 解析客户编号,基于客户名称 |
| | | * 解析客户编号,基于客户名称;留空表示不关联客户 |
| | | */ |
| | | public Long resolveClientId(String clientName) { |
| | | if (StrUtil.isBlank(clientName)) { |
| | | throw new IllegalArgumentException("客户名称不能为空:请填写模板中该行的「客户名称」列"); |
| | | return null; |
| | | } |
| | | if (customerNameMap == null) { |
| | | customerNameMap = new HashMap<>(); |
| | |
| | | return clientId; |
| | | } |
| | | |
| | | /** |
| | | * 校验客户在当前登录用户的可见范围内 |
| | | * |
| | | * 出货检验单列表按客户数据权限过滤,权限外的客户导入后本人在列表中看不到该单据,因此提前拦截。 |
| | | */ |
| | | /** MES 业务模块对所有 CRM 客户开放访问,不应用营销管理的客户团队权限。 */ |
| | | public void validateClientPermission(Long clientId, String clientName) { |
| | | if (!clientPermissionLoaded) { |
| | | List<Long> permittedIds = crmCustomerApi.getPermittedCustomerIds(); |
| | | permittedClientIds = permittedIds == null ? null : new HashSet<>(permittedIds); |
| | | clientPermissionLoaded = true; |
| | | } |
| | | if (permittedClientIds == null || permittedClientIds.contains(clientId)) { |
| | | return; |
| | | } |
| | | throw new IllegalArgumentException("客户[" + clientName + "]不在您的数据权限范围内:" |
| | | + "导入后您将无法在「出货检验」列表中看到该检验单。请改用您负责的客户(可在「CRM 客户管理-我负责的」中查看)," |
| | | + "或联系管理员为您开通该客户的权限后重新导入"); |
| | | // 客户是否存在仍由 resolveClientId 校验;负责人和团队权限只约束 CRM 营销管理。 |
| | | } |
| | | |
| | | /** |