Commit 86f44b37 by chenxi

优加门店上架导入改动提交,新增产品分类、组织返回值

1 parent 0e270a24
......@@ -37,7 +37,9 @@ import com.youjia.store.vo.HeaderGroupVO;
import com.youjia.store.vo.StoreImportCheckVO;
import com.youjia.store.vo.StoreImportFailVO;
import com.youjia.store.vo.StoreImportSpecVO;
import com.youjia.system.entity.SysOrg;
import com.youjia.system.entity.SysRole;
import com.youjia.system.mapper.SysOrgMapper;
import com.youjia.system.mapper.SysRoleMapper;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
......@@ -63,6 +65,7 @@ import java.util.ArrayList;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
......@@ -100,6 +103,7 @@ public class StoreImportServiceImpl implements StoreImportService {
private final StoreImportValidator storeImportValidator;
private final StoreImportRemoteValidator storeImportRemoteValidator;
private final SysRoleMapper sysRoleMapper;
private final SysOrgMapper sysOrgMapper;
private final OssTemplate ossTemplate;
private final TransactionTemplate transactionTemplate;
private final StoreImportIdempotentGuard idempotentGuard;
......@@ -214,6 +218,9 @@ public class StoreImportServiceImpl implements StoreImportService {
vo.setDistinctProductCategoryCount(result.getDistinctProductCategoryCount());
vo.setDistinctBusinessSceneCount(result.getDistinctBusinessSceneCount());
vo.setProductCategoryRowCount(result.getProductCategoryRowCount());
// 产品分类(表格中去重后的全部分类,按出现顺序)+ 操作用户组织链
vo.setProductCategories(result.getProductCategories());
vo.setOrgPath(resolveOrgPath(CurrentUserHolder.getOrgId()));
// 表头 / 无数据行等文件级问题已在校验器中直接抛 STORE_IMPORT_FILE_INVALID
......@@ -329,16 +336,18 @@ public class StoreImportServiceImpl implements StoreImportService {
private StoreListing saveOrUpdateDraft(String sceneCode, List<StoreImportRowDTO> rows,
String remark, String level1RoleCode) {
StoreImportRowDTO first = rows.get(0);
// ⚠️ 查询条件必须用 business_scene_code(编码列):business_scene 存的是文本,
// 拿编码去比文本永远不相等 → 永远查不到已有草稿 → 每次导入都插重复记录
StoreListing existing = storeListingMapper.selectOne(new LambdaQueryWrapper<StoreListing>()
.eq(StoreListing::getMerchantNo, first.getMerchantNo())
.eq(StoreListing::getBusinessScene, sceneCode)
.eq(StoreListing::getBusinessSceneCode, sceneCode)
.eq(StoreListing::getStatus, StoreStatusEnum.DRAFT.getCode())
.last("limit 1"));
// 已有待审批记录 → 整表拦截
Long pendingCount = storeListingMapper.selectCount(new LambdaQueryWrapper<StoreListing>()
.eq(StoreListing::getMerchantNo, first.getMerchantNo())
.eq(StoreListing::getBusinessScene, sceneCode)
.eq(StoreListing::getBusinessSceneCode, sceneCode)
.eq(StoreListing::getStatus, StoreStatusEnum.PENDING.getCode()));
if (pendingCount != null && pendingCount > 0) {
throw new BusinessException(ResultCode.STORE_DUPLICATE_LISTING,
......@@ -375,7 +384,7 @@ public class StoreImportServiceImpl implements StoreImportService {
listing.setCostLabor(labor);
listing.setCostTotal(decoration.add(monthly).add(labor));
listing.setOrgId(CurrentUserHolder.getOrgId());
// 登录链路的全局处理未完成,提交人先留空
// 提交人由 submit(DRAFT → PENDING)时写入,草稿态保持为空
listing.setSubmitUserId(null);
listing.setSubmitUserName(null);
listing.setSubmitTime(LocalDateTime.now());
......@@ -475,6 +484,9 @@ public class StoreImportServiceImpl implements StoreImportService {
update.setVersion(listing.getVersion());
update.setStatus(StoreStatusEnum.PENDING.getCode());
update.setSubmitTime(LocalDateTime.now());
// 提交人 = 当前登录用户(与审批路径的 approveUserId / approveUserName 对称)
update.setSubmitUserId(CurrentUserHolder.getUserId());
update.setSubmitUserName(CurrentUserHolder.getName());
if (storeListingMapper.updateById(update) != 1) {
throw new BusinessException(ResultCode.OPERATION_NOT_ALLOWED, "记录已被他人处置,请刷新后重试");
}
......@@ -543,6 +555,33 @@ public class StoreImportServiceImpl implements StoreImportService {
/**
* 第 1 级审批角色编码:按 `sys_role.role_name = '优加商务经理'` 查。
*/
/**
* 解析操作用户的组织链(从所在组织向上追溯到根),名称以「 / 」分割。
*
* @param orgId 当前登录用户的主属组织 ID
* @return 如「优加主体 / 线上运营部」;查不到组织时返回 null
*/
private String resolveOrgPath(Long orgId) {
if (orgId == null) {
return null;
}
LinkedList<String> names = new LinkedList<>();
Long current = orgId;
int guard = 0;
while (current != null && current > 0 && guard++ < 20) {
SysOrg org = sysOrgMapper.selectById(current);
if (org == null) {
break;
}
names.addFirst(org.getOrgName());
current = org.getParentId();
}
return names.isEmpty() ? null : String.join(" / ", names);
}
/**
* 第 1 级审批角色编码:按 `sys_role.role_name = '优加商务经理'` 查。
*/
private String resolveLevel1RoleCode() {
SysRole role = sysRoleMapper.selectOne(new LambdaQueryWrapper<SysRole>()
.eq(SysRole::getRoleName, CommonConstants.ROLE_NAME_YJ_BIZ_MGR)
......
......@@ -29,6 +29,9 @@ public class StoreImportCheckResult {
/** 业务场景(去重后以「/」分隔,展示用 label) */
private String businessSceneSummary;
/** 产品分类(表格中去重后的全部分类,按出现顺序,以「 / 」分隔) */
private String productCategories;
/** 通过行数 */
private int passRows;
......
......@@ -77,6 +77,7 @@ public class StoreImportValidator {
Set<String> sceneCodes = new LinkedHashSet<>();
Set<String> sceneLabels = new LinkedHashSet<>();
Set<String> categoryTexts = new LinkedHashSet<>();
Set<String> categoryKeys = new LinkedHashSet<>();
Map<String, String> uniqueRowKeys = new LinkedHashMap<>();
int passRows = 0;
......@@ -148,6 +149,8 @@ public class StoreImportValidator {
if (!StringUtils.hasText(categoryText)) {
l3.add("产品分类不能为空");
} else {
// 返回值用:表格中出现的全部分类(去重、按出现顺序)
categoryTexts.add(categoryText);
MatchOutcome outcome = matchCategory(categoryText, categories);
if (outcome.type == MatchType.NOT_FOUND) {
l4.add("产品分类不存在:" + categoryText);
......@@ -189,6 +192,7 @@ public class StoreImportValidator {
result.setDistinctBusinessSceneCount(sceneCodes.size());
result.setProductCategoryRowCount(rows.size());
result.setBusinessSceneSummary(String.join("/", sceneLabels));
result.setProductCategories(String.join(" / ", categoryTexts));
return result;
}
......
......@@ -81,4 +81,12 @@ public class StoreImportCheckVO {
@Schema(description = "是否已落库(导入成功为 true;仅校验失败为 false)")
private Boolean submitted = Boolean.FALSE;
@Schema(description = "产品分类(表格中去重后的全部分类,按出现顺序,多个以「 / 」分割,"
+ "如「太阳膜-原厂 / 车衣-原厂 / 精品-小桌板」)")
private String productCategories;
@Schema(description = "所属组织(操作用户所在组织链,多层级以「 / 」分割,"
+ "如「优加主体 / 线上运营部」)")
private String orgPath;
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!