mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-14 02:55:07 +08:00
增加 Bpm Field 的 vModel 重复的问题
This commit is contained in:
@ -30,6 +30,7 @@ public interface BpmErrorCodeConstants {
|
||||
ErrorCode BPMN_PROCESS_DEFINITION_NOT_EXISTS = new ErrorCode(1004001004, "流程定义不存在");
|
||||
|
||||
// ========== 动态表单模块 1-003-003-000 ==========
|
||||
ErrorCode BPM_FORM_NOT_EXISTS = new ErrorCode(1003001002, "动态表单不存在");
|
||||
ErrorCode BPM_FORM_NOT_EXISTS = new ErrorCode(1003003000, "动态表单不存在");
|
||||
ErrorCode BPM_FORM_FIELD_REPEAT = new ErrorCode(1003003000, "表单项({}) 和 ({}) 使用了相同的字段名({})");
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.bpm.service.form.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Bpm 表单的 Field 表单项 Response DTO
|
||||
* 字段的定义,可见 https://github.com/JakHuang/form-generator/issues/46 文档
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Data
|
||||
public class BpmFormFieldRespDTO {
|
||||
|
||||
/**
|
||||
* 表单标题
|
||||
*/
|
||||
private String label;
|
||||
/**
|
||||
* 表单字段的属性名,可自定义
|
||||
*/
|
||||
@JsonProperty(value = "vModel")
|
||||
private String vModel;
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.bpm.service.form.impl;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo.BpmFormCreateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo.BpmFormPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo.BpmFormUpdateReqVO;
|
||||
@ -7,14 +8,19 @@ import cn.iocoder.yudao.adminserver.modules.bpm.convert.form.BpmFormConvert;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.form.BpmFormMapper;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.form.BpmFormService;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.form.dto.BpmFormFieldRespDTO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.BPM_FORM_FIELD_REPEAT;
|
||||
import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.BPM_FORM_NOT_EXISTS;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
|
||||
@ -32,6 +38,7 @@ public class BpmFormServiceImpl implements BpmFormService {
|
||||
|
||||
@Override
|
||||
public Long createForm(BpmFormCreateReqVO createReqVO) {
|
||||
this.checkFields(createReqVO.getFields());
|
||||
// 插入
|
||||
BpmFormDO form = BpmFormConvert.INSTANCE.convert(createReqVO);
|
||||
formMapper.insert(form);
|
||||
@ -41,6 +48,7 @@ public class BpmFormServiceImpl implements BpmFormService {
|
||||
|
||||
@Override
|
||||
public void updateForm(BpmFormUpdateReqVO updateReqVO) {
|
||||
this.checkFields(updateReqVO.getFields());
|
||||
// 校验存在
|
||||
this.validateFormExists(updateReqVO.getId());
|
||||
// 更新
|
||||
@ -77,4 +85,24 @@ public class BpmFormServiceImpl implements BpmFormService {
|
||||
return formMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验 Field,避免 field 重复
|
||||
*
|
||||
* @param fields field 数组
|
||||
*/
|
||||
private void checkFields(List<String> fields) {
|
||||
Map<String, String> fieldMap = new HashMap<>(); // key 是 vModel,value 是 label
|
||||
for (String field : fields) {
|
||||
BpmFormFieldRespDTO fieldDTO = JsonUtils.parseObject(field, BpmFormFieldRespDTO.class);
|
||||
Assert.notNull(fieldDTO);
|
||||
String oldLabel = fieldMap.put(fieldDTO.getVModel(), fieldDTO.getLabel());
|
||||
// 如果不存在,则直接返回
|
||||
if (oldLabel == null) {
|
||||
continue;
|
||||
}
|
||||
// 如果存在,则报错
|
||||
throw exception(BPM_FORM_FIELD_REPEAT, oldLabel, fieldDTO.getLabel(), fieldDTO.getVModel());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user