fix(缺陷管理): 缺陷内置字段展示国际化问题

--bug=1049213 --user=宋昌昌 【缺陷管理】LOCAL平台-新建缺陷-处理人、状态展示为英文 https://www.tapd.cn/55049933/s/1615277
This commit is contained in:
song-cc-rock 2024-11-22 14:32:53 +08:00 committed by 刘瑞斌
parent a355557115
commit 8d8c568503
4 changed files with 45 additions and 28 deletions

View File

@ -133,7 +133,7 @@ public class BugController {
@Operation(summary = "缺陷管理-列表-查看缺陷(详情&&编辑&&复制)") @Operation(summary = "缺陷管理-列表-查看缺陷(详情&&编辑&&复制)")
@RequiresPermissions(PermissionConstants.PROJECT_BUG_READ) @RequiresPermissions(PermissionConstants.PROJECT_BUG_READ)
public BugDetailDTO get(@PathVariable String id) { public BugDetailDTO get(@PathVariable String id) {
return bugService.get(id, SessionUtils.getUserId()); return bugService.get(id, SessionUtils.getUserId(), Objects.requireNonNull(SessionUtils.getUser()).getLanguage());
} }
@GetMapping("/delete/{id}") @GetMapping("/delete/{id}")
@ -229,7 +229,7 @@ public class BugController {
@RequiresPermissions(PermissionConstants.PROJECT_BUG_READ) @RequiresPermissions(PermissionConstants.PROJECT_BUG_READ)
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
public TemplateDTO getTemplateDetail(@RequestBody BugTemplateRequest request) { public TemplateDTO getTemplateDetail(@RequestBody BugTemplateRequest request) {
return bugService.getTemplate(request.getId(), request.getProjectId(), request.getFromStatusId(), request.getPlatformBugKey(), request.getShowLocal()); return bugService.getTemplate(request.getId(), request.getProjectId(), request.getFromStatusId(), request.getPlatformBugKey(), request.getShowLocal(), Objects.requireNonNull(SessionUtils.getUser()).getLanguage());
} }
@GetMapping("/follow/{id}") @GetMapping("/follow/{id}")

View File

@ -3,19 +3,19 @@ package io.metersphere.bug.enums;
import io.metersphere.sdk.util.Translator; import io.metersphere.sdk.util.Translator;
import lombok.Getter; import lombok.Getter;
@Getter
public enum BugTemplateCustomField { public enum BugTemplateCustomField {
/** /**
* 处理人 * 处理人
*/ */
HANDLE_USER("handleUser", Translator.get("bug.handle_user")), HANDLE_USER("handleUser", "bug.handle_user"),
/** /**
* 状态 * 状态
*/ */
STATUS("status", Translator.get("bug.status")); STATUS("status", "bug.status");
@Getter
private final String id; private final String id;
private final String name; private final String name;
@ -24,4 +24,8 @@ public enum BugTemplateCustomField {
this.id = id; this.id = id;
this.name = name; this.name = name;
} }
public String getName(String language) {
return Translator.get(name, language);
}
} }

View File

@ -252,9 +252,9 @@ public class BugService {
* @param id 缺陷ID * @param id 缺陷ID
* @return 缺陷详情 * @return 缺陷详情
*/ */
public BugDetailDTO get(String id, String currentUser) { public BugDetailDTO get(String id, String currentUser, String language) {
Bug bug = checkBugExist(id); Bug bug = checkBugExist(id);
TemplateDTO template = getTemplate(bug.getTemplateId(), bug.getProjectId(), null, null, StringUtils.equals(bug.getPlatform(), BugPlatform.LOCAL.getName())); TemplateDTO template = getTemplate(bug.getTemplateId(), bug.getProjectId(), null, null, StringUtils.equals(bug.getPlatform(), BugPlatform.LOCAL.getName()), language);
List<BugCustomFieldDTO> allCustomFields = extBugCustomFieldMapper.getBugAllCustomFields(List.of(id), bug.getProjectId()); List<BugCustomFieldDTO> allCustomFields = extBugCustomFieldMapper.getBugAllCustomFields(List.of(id), bug.getProjectId());
BugDetailDTO detail = new BugDetailDTO(); BugDetailDTO detail = new BugDetailDTO();
detail.setId(id); detail.setId(id);
@ -381,21 +381,21 @@ public class BugService {
* @param platformBugKey 平台缺陷key * @param platformBugKey 平台缺陷key
* @return 模板详情 * @return 模板详情
*/ */
public TemplateDTO getTemplate(String templateId, String projectId, String fromStatusId, String platformBugKey, Boolean showLocal) { public TemplateDTO getTemplate(String templateId, String projectId, String fromStatusId, String platformBugKey, Boolean showLocal, String language) {
Template template = templateMapper.selectByPrimaryKey(templateId); Template template = templateMapper.selectByPrimaryKey(templateId);
if (template != null) { if (template != null) {
// 属于系统模板 // 属于系统模板
return injectPlatformTemplateBugField(baseTemplateService.getTemplateDTO(template), projectId, fromStatusId, platformBugKey, showLocal); return injectPlatformTemplateBugField(baseTemplateService.getTemplateDTO(template), projectId, fromStatusId, platformBugKey, showLocal, language);
} else { } else {
// 不属于系统模板 // 不属于系统模板
List<ProjectTemplateOptionDTO> option = projectTemplateService.getOption(projectId, TemplateScene.BUG.name()); List<ProjectTemplateOptionDTO> option = projectTemplateService.getOption(projectId, TemplateScene.BUG.name());
Optional<ProjectTemplateOptionDTO> isThirdPartyDefaultTemplate = option.stream().filter(projectTemplateOptionDTO -> StringUtils.equals(projectTemplateOptionDTO.getId(), templateId)).findFirst(); Optional<ProjectTemplateOptionDTO> isThirdPartyDefaultTemplate = option.stream().filter(projectTemplateOptionDTO -> StringUtils.equals(projectTemplateOptionDTO.getId(), templateId)).findFirst();
if (isThirdPartyDefaultTemplate.isPresent()) { if (isThirdPartyDefaultTemplate.isPresent()) {
// 属于第三方平台默认模板(平台生成的默认模板无需注入配置中的字段) // 属于第三方平台默认模板(平台生成的默认模板无需注入配置中的字段)
return attachTemplateStatusField(getPluginBugDefaultTemplate(projectId, true), projectId, fromStatusId, platformBugKey, false); return attachTemplateStatusField(getPluginBugDefaultTemplate(projectId, true), projectId, fromStatusId, platformBugKey, false, language);
} else { } else {
// 不属于系统模板&&不属于第三方平台默认模板, 则该模板已被删除 // 不属于系统模板&&不属于第三方平台默认模板, 则该模板已被删除
return injectPlatformTemplateBugField(projectTemplateService.getDefaultTemplateDTO(projectId, TemplateScene.BUG.name()), projectId, fromStatusId, platformBugKey, showLocal); return injectPlatformTemplateBugField(projectTemplateService.getDefaultTemplateDTO(projectId, TemplateScene.BUG.name()), projectId, fromStatusId, platformBugKey, showLocal, language);
} }
} }
} }
@ -883,20 +883,21 @@ public class BugService {
* @param platformBugKey 平台缺陷key * @param platformBugKey 平台缺陷key
* @return 模板 * @return 模板
*/ */
private TemplateDTO injectPlatformTemplateBugField(TemplateDTO templateDTO, String projectId, String fromStatusId, String platformBugKey, Boolean showLocal) { private TemplateDTO injectPlatformTemplateBugField(TemplateDTO templateDTO, String projectId, String fromStatusId, String platformBugKey,
Boolean showLocal, String language) {
// 来自平台模板 // 来自平台模板
templateDTO.setPlatformDefault(false); templateDTO.setPlatformDefault(false);
String platformName = projectApplicationService.getPlatformName(projectId); String platformName = projectApplicationService.getPlatformName(projectId);
// 状态字段 // 状态字段
attachTemplateStatusField(templateDTO, projectId, fromStatusId, platformBugKey, showLocal); attachTemplateStatusField(templateDTO, projectId, fromStatusId, platformBugKey, showLocal, language);
// 内置字段(处理人字段) // 内置字段(处理人字段)
if (StringUtils.equals(platformName, BugPlatform.LOCAL.getName()) || BooleanUtils.isTrue(showLocal)) { if (StringUtils.equals(platformName, BugPlatform.LOCAL.getName()) || BooleanUtils.isTrue(showLocal)) {
// Local(处理人) // Local(处理人)
TemplateCustomFieldDTO handleUserField = new TemplateCustomFieldDTO(); TemplateCustomFieldDTO handleUserField = new TemplateCustomFieldDTO();
handleUserField.setFieldId(BugTemplateCustomField.HANDLE_USER.getId()); handleUserField.setFieldId(BugTemplateCustomField.HANDLE_USER.getId());
handleUserField.setFieldName(BugTemplateCustomField.HANDLE_USER.getName()); handleUserField.setFieldName(BugTemplateCustomField.HANDLE_USER.getName(language));
handleUserField.setFieldKey(BugTemplateCustomField.HANDLE_USER.getId()); handleUserField.setFieldKey(BugTemplateCustomField.HANDLE_USER.getId());
handleUserField.setType(CustomFieldType.SELECT.name()); handleUserField.setType(CustomFieldType.SELECT.name());
handleUserField.setOptions(getMemberOption(projectId)); handleUserField.setOptions(getMemberOption(projectId));
@ -952,13 +953,14 @@ public class BugService {
* @param platformBugKey 平台缺陷key * @param platformBugKey 平台缺陷key
* @return 模板 * @return 模板
*/ */
public TemplateDTO attachTemplateStatusField(TemplateDTO templateDTO, String projectId, String fromStatusId, String platformBugKey, Boolean showLocal) { public TemplateDTO attachTemplateStatusField(TemplateDTO templateDTO, String projectId, String fromStatusId, String platformBugKey,
Boolean showLocal, String language) {
if (templateDTO == null) { if (templateDTO == null) {
return null; return null;
} }
TemplateCustomFieldDTO statusField = new TemplateCustomFieldDTO(); TemplateCustomFieldDTO statusField = new TemplateCustomFieldDTO();
statusField.setFieldId(BugTemplateCustomField.STATUS.getId()); statusField.setFieldId(BugTemplateCustomField.STATUS.getId());
statusField.setFieldName(BugTemplateCustomField.STATUS.getName()); statusField.setFieldName(BugTemplateCustomField.STATUS.getName(language));
statusField.setFieldKey(BugTemplateCustomField.STATUS.getId()); statusField.setFieldKey(BugTemplateCustomField.STATUS.getId());
statusField.setType(CustomFieldType.SELECT.name()); statusField.setType(CustomFieldType.SELECT.name());
List<SelectOption> statusOption = bugStatusService.getToStatusItemOption(projectId, fromStatusId, platformBugKey, showLocal); List<SelectOption> statusOption = bugStatusService.getToStatusItemOption(projectId, fromStatusId, platformBugKey, showLocal);

View File

@ -960,17 +960,19 @@ export interface CascaderOption {
/** /**
* *
* @param value * @param arr
* @param options (2) * @param options (2)
*/ */
export function cascaderValueToLabel(value: string, options: CascaderOption[]) { export function cascaderValueToLabel(arr: string[], options: CascaderOption[]) {
if (!value || !options) return ''; if (!arr || !options || arr.length === 0) return '';
let targetLabel = ''; let targetLabel = '';
options.forEach((option) => { options.forEach((option) => {
if (option.children) { if (option.value === arr[0]) {
option.children.forEach((child) => { targetLabel += option.text;
if (child.value === value) { if (arr.length === 1) return;
targetLabel = child.text; option.children?.forEach((child) => {
if (child.value === arr[1]) {
targetLabel += `/${child.text}`;
} }
}); });
} }
@ -1009,11 +1011,20 @@ export function customFieldDataToTableData(customFieldData: Record<string, any>[
.map((val: string) => field.options.find((option: { value: string }) => option.value === val)?.text) .map((val: string) => field.options.find((option: { value: string }) => option.value === val)?.text)
.join(','); .join(',');
} catch (e) { } catch (e) {
console.log('自定义字段值不是数组'); // eslint-disable-next-line no-console
console.error('multiple field value is not array!');
} }
} else if (field.type === 'CASCADER') { } else if (field.type === 'CASCADER' && field.value) {
try {
const arr = JSON.parse(field.value);
if (arr.length > 1) {
// 特殊的三方字段-级联选择器 // 特殊的三方字段-级联选择器
tableData[field.id] = cascaderValueToLabel(JSON.parse(field.value)[1], field.options); tableData[field.id] = cascaderValueToLabel(arr, field.options);
}
} catch (e) {
// eslint-disable-next-line no-console
console.error('cascader field value is nor array!');
}
} else { } else {
tableData[field.id] = field.value; tableData[field.id] = field.value;
} }