From 930c5ec490066dfaf66674ada8ea197d39a2d443 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 31 Dec 2021 22:12:08 +0800 Subject: [PATCH] =?UTF-8?q?BPM=20Form=20=E8=A1=A8=E5=8D=95=E7=9A=84?= =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/form/BpmFormController.java | 13 +- .../bpm/controller/form/vo/BpmFormBaseVO.java | 11 +- .../form/vo/BpmFormCreateReqVO.java | 11 ++ .../controller/form/vo/BpmFormExcelVO.java | 34 ----- .../form/vo/BpmFormExportReqVO.java | 14 -- .../controller/form/vo/BpmFormPageReqVO.java | 2 +- .../bpm/controller/form/vo/BpmFormRespVO.java | 21 ++- .../form/vo/BpmFormUpdateReqVO.java | 11 +- .../bpm/convert/form/BpmFormConvert.java | 15 +-- .../form/{BpmForm.java => BpmFormDO.java} | 12 +- .../{BpmFormData.java => BpmFormDataDO.java} | 6 +- .../bpm/dal/mysql/form/BpmFormMapper.java | 11 +- .../bpm/service/form/BpmFormService.java | 8 +- .../form/{ => impl}/BpmFormServiceImpl.java | 16 +-- .../bpm/service/form/BpmFormServiceTest.java | 122 ++++++++++++++++++ .../modules/bpm/service/package-info.java | 1 + .../src/test/resources/sql/clean.sql | 3 + .../src/test/resources/sql/create_tables.sql | 16 +++ .../src/utils/generator/drawingDefalut.js | 50 +++---- .../src/views/bpm/form/formEditor.vue | 90 +++++++++++-- yudao-admin-ui/src/views/bpm/form/index.vue | 94 ++------------ .../framework/test/core/util/RandomUtils.java | 8 ++ 22 files changed, 340 insertions(+), 229 deletions(-) delete mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormExcelVO.java delete mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormExportReqVO.java rename yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/form/{BpmForm.java => BpmFormDO.java} (90%) rename yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/form/{BpmFormData.java => BpmFormDataDO.java} (90%) rename yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/form/{ => impl}/BpmFormServiceImpl.java (81%) create mode 100644 yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/bpm/service/form/BpmFormServiceTest.java create mode 100644 yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/bpm/service/package-info.java diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/BpmFormController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/BpmFormController.java index 65d9a578f..270dbfaf6 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/BpmFormController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/BpmFormController.java @@ -1,13 +1,11 @@ package cn.iocoder.yudao.adminserver.modules.bpm.controller.form; import cn.iocoder.yudao.adminserver.modules.bpm.convert.form.BpmFormConvert; -import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmForm; +import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO; import cn.iocoder.yudao.adminserver.modules.bpm.service.form.BpmFormService; import cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo.*; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; @@ -16,14 +14,11 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; -import java.io.IOException; import java.util.Collection; import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; @Api(tags = "动态表单") @RestController @@ -63,7 +58,7 @@ public class BpmFormController { @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) @PreAuthorize("@ss.hasPermission('bpm:form:query')") public CommonResult getForm(@RequestParam("id") Long id) { - BpmForm form = formService.getForm(id); + BpmFormDO form = formService.getForm(id); return success(BpmFormConvert.INSTANCE.convert(form)); } @@ -72,7 +67,7 @@ public class BpmFormController { @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) @PreAuthorize("@ss.hasPermission('bpm:form:query')") public CommonResult> getFormList(@RequestParam("ids") Collection ids) { - List list = formService.getFormList(ids); + List list = formService.getFormList(ids); return success(BpmFormConvert.INSTANCE.convertList(list)); } @@ -80,7 +75,7 @@ public class BpmFormController { @ApiOperation("获得动态表单分页") @PreAuthorize("@ss.hasPermission('bpm:form:query')") public CommonResult> getFormPage(@Valid BpmFormPageReqVO pageVO) { - PageResult pageResult = formService.getFormPage(pageVO); + PageResult pageResult = formService.getFormPage(pageVO); return success(BpmFormConvert.INSTANCE.convertPage(pageResult)); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormBaseVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormBaseVO.java index 56674a412..21e10b7c6 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormBaseVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormBaseVO.java @@ -11,18 +11,15 @@ import javax.validation.constraints.*; @Data public class BpmFormBaseVO { - @ApiModelProperty(value = "表单名称", required = true) + @ApiModelProperty(value = "表单名称", required = true, example = "芋道") @NotNull(message = "表单名称不能为空") private String name; - @ApiModelProperty(value = "商户状态", required = true) - @NotNull(message = "商户状态不能为空") + @ApiModelProperty(value = "表单状态", required = true, notes = "参见 CommonStatusEnum 枚举", example = "1") + @NotNull(message = "表单状态不能为空") private Integer status; - @ApiModelProperty(value = "表单JSON") - private String formJson; - - @ApiModelProperty(value = "备注") + @ApiModelProperty(value = "备注", example = "我是备注") private String remark; } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormCreateReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormCreateReqVO.java index 79e9ee55d..e10519e47 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormCreateReqVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormCreateReqVO.java @@ -3,10 +3,21 @@ package cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo; import lombok.*; import io.swagger.annotations.*; +import javax.validation.constraints.NotNull; +import java.util.List; + @ApiModel("动态表单创建 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class BpmFormCreateReqVO extends BpmFormBaseVO { + @ApiModelProperty(value = "表单的配置", required = true, notes = "JSON 字符串") + @NotNull(message = "表单的配置不能为空") + private String conf; + + @ApiModelProperty(value = "表单项的数组", required = true, notes = "JSON 字符串的数组") + @NotNull(message = "表单项的数组不能为空") + private List fields; + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormExcelVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormExcelVO.java deleted file mode 100644 index 542758677..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormExcelVO.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo; - -import com.alibaba.excel.annotation.ExcelProperty; -import lombok.Data; - -import java.util.Date; - -/** - * 动态表单 Excel VO - * - * @author 芋艿 - */ -@Data -public class BpmFormExcelVO { - - @ExcelProperty("表单编号") - private Long id; - - @ExcelProperty("表单名称") - private String name; - - @ExcelProperty("商户状态") - private Integer status; - - @ExcelProperty("表单JSON") - private String formJson; - - @ExcelProperty("备注") - private String remark; - - @ExcelProperty("创建时间") - private Date createTime; - -} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormExportReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormExportReqVO.java deleted file mode 100644 index 5accb8e6b..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormExportReqVO.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -@ApiModel(value = "动态表单 Excel 导出 Request VO", description = "参数和 BpmFormPageReqVO 是一致的") -@Data -public class BpmFormExportReqVO { - - @ApiModelProperty(value = "表单名称") - private String name; - -} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormPageReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormPageReqVO.java index 503cbe82e..559b88f2c 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormPageReqVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormPageReqVO.java @@ -13,7 +13,7 @@ import lombok.ToString; @ToString(callSuper = true) public class BpmFormPageReqVO extends PageParam { - @ApiModelProperty(value = "表单名称") + @ApiModelProperty(value = "表单名称", example = "芋道") private String name; } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormRespVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormRespVO.java index e0424dbe2..2393a6157 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormRespVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormRespVO.java @@ -1,8 +1,14 @@ package cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo; -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import javax.validation.constraints.NotNull; +import java.util.Date; +import java.util.List; @ApiModel("动态表单 Response VO") @Data @@ -10,8 +16,15 @@ import io.swagger.annotations.*; @ToString(callSuper = true) public class BpmFormRespVO extends BpmFormBaseVO { - @ApiModelProperty(value = "表单编号", required = true) + @ApiModelProperty(value = "表单编号", required = true, example = "1024") private Long id; + @ApiModelProperty(value = "表单的配置", required = true, notes = "JSON 字符串") + @NotNull(message = "表单的配置不能为空") + private String conf; + + @ApiModelProperty(value = "表单项的数组", required = true, notes = "JSON 字符串的数组") + @NotNull(message = "表单项的数组不能为空") + private List fields; @ApiModelProperty(value = "创建时间", required = true) private Date createTime; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormUpdateReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormUpdateReqVO.java index 89bb759ee..81fdd869d 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormUpdateReqVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/form/vo/BpmFormUpdateReqVO.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo; import lombok.*; import io.swagger.annotations.*; import javax.validation.constraints.*; +import java.util.List; @ApiModel("动态表单更新 Request VO") @Data @@ -10,8 +11,16 @@ import javax.validation.constraints.*; @ToString(callSuper = true) public class BpmFormUpdateReqVO extends BpmFormBaseVO { - @ApiModelProperty(value = "表单编号", required = true) + @ApiModelProperty(value = "表单编号", required = true, example = "1024") @NotNull(message = "表单编号不能为空") private Long id; + @ApiModelProperty(value = "表单的配置", required = true, notes = "JSON 字符串") + @NotNull(message = "表单的配置不能为空") + private String conf; + + @ApiModelProperty(value = "表单项的数组", required = true, notes = "JSON 字符串的数组") + @NotNull(message = "表单项的数组不能为空") + private List fields; + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/form/BpmFormConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/form/BpmFormConvert.java index a7764dc04..97df03ebb 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/form/BpmFormConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/form/BpmFormConvert.java @@ -1,10 +1,9 @@ package cn.iocoder.yudao.adminserver.modules.bpm.convert.form; import cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo.BpmFormCreateReqVO; -import cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo.BpmFormExcelVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo.BpmFormRespVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo.BpmFormUpdateReqVO; -import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmForm; +import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -21,16 +20,14 @@ public interface BpmFormConvert { BpmFormConvert INSTANCE = Mappers.getMapper(BpmFormConvert.class); - BpmForm convert(BpmFormCreateReqVO bean); + BpmFormDO convert(BpmFormCreateReqVO bean); - BpmForm convert(BpmFormUpdateReqVO bean); + BpmFormDO convert(BpmFormUpdateReqVO bean); - BpmFormRespVO convert(BpmForm bean); + BpmFormRespVO convert(BpmFormDO bean); - List convertList(List list); + List convertList(List list); - PageResult convertPage(PageResult page); - - List convertList02(List list); + PageResult convertPage(PageResult page); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/form/BpmForm.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/form/BpmFormDO.java similarity index 90% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/form/BpmForm.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/form/BpmFormDO.java index c3435c15b..c74f60ceb 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/form/BpmForm.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/form/BpmFormDO.java @@ -22,7 +22,7 @@ import java.util.List; @Builder @NoArgsConstructor @AllArgsConstructor -public class BpmForm extends BaseDO { +public class BpmFormDO extends BaseDO { /** * 编号 @@ -37,12 +37,12 @@ public class BpmForm extends BaseDO { * 状态 */ private Integer status; -// /** -// * 表单JSON -// */ -// private String formJson; /** - * 表单配置 + * 表单的配置 + */ + private String conf; + /** + * 表单项的数组 * * 目前直接将 https://github.com/JakHuang/form-generator 生成的 JSON 串,直接保存 * 定义:https://github.com/JakHuang/form-generator/issues/46 diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/form/BpmFormData.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/form/BpmFormDataDO.java similarity index 90% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/form/BpmFormData.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/form/BpmFormDataDO.java index 59daa510c..dc437ae04 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/form/BpmFormData.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/form/BpmFormDataDO.java @@ -22,7 +22,7 @@ import java.util.Map; @Builder @NoArgsConstructor @AllArgsConstructor -public class BpmFormData extends BaseDO { +public class BpmFormDataDO extends BaseDO { /** * 编号 @@ -31,7 +31,7 @@ public class BpmFormData extends BaseDO { /** * 表单编号 * - * 关联 {@link BpmForm#getId()} + * 关联 {@link BpmFormDO#getId()} */ private Long formId; /** @@ -41,7 +41,7 @@ public class BpmFormData extends BaseDO { /** * 表单配置 * - * 冗余 {@link BpmForm#getFields()} + * 冗余 {@link BpmFormDO#getFields()} * 主要考虑,表单是可以修改的 */ @TableField(typeHandler = JacksonTypeHandler.class) diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/form/BpmFormMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/form/BpmFormMapper.java index ab21094f3..a68d84782 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/form/BpmFormMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/form/BpmFormMapper.java @@ -1,26 +1,23 @@ package cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.form; -import cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo.BpmFormExportReqVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo.BpmFormPageReqVO; -import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmForm; +import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import org.apache.ibatis.annotations.Mapper; -import java.util.List; - /** * 动态表单 Mapper * * @author 风里雾里 */ @Mapper -public interface BpmFormMapper extends BaseMapperX { +public interface BpmFormMapper extends BaseMapperX { - default PageResult selectPage(BpmFormPageReqVO reqVO) { - return selectPage(reqVO, new QueryWrapperX() + default PageResult selectPage(BpmFormPageReqVO reqVO) { + return selectPage(reqVO, new QueryWrapperX() .likeIfPresent("name", reqVO.getName()) .orderByDesc("id")); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/form/BpmFormService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/form/BpmFormService.java index b37ea0e50..a69e7d4f9 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/form/BpmFormService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/form/BpmFormService.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.form; 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; -import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmForm; +import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import javax.validation.Valid; @@ -46,7 +46,7 @@ public interface BpmFormService { * @param id 编号 * @return 动态表单 */ - BpmForm getForm(Long id); + BpmFormDO getForm(Long id); /** * 获得动态表单列表 @@ -54,7 +54,7 @@ public interface BpmFormService { * @param ids 编号 * @return 动态表单列表 */ - List getFormList(Collection ids); + List getFormList(Collection ids); /** * 获得动态表单分页 @@ -62,6 +62,6 @@ public interface BpmFormService { * @param pageReqVO 分页查询 * @return 动态表单分页 */ - PageResult getFormPage(BpmFormPageReqVO pageReqVO); + PageResult getFormPage(BpmFormPageReqVO pageReqVO); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/form/BpmFormServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/form/impl/BpmFormServiceImpl.java similarity index 81% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/form/BpmFormServiceImpl.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/form/impl/BpmFormServiceImpl.java index deebe697c..1fd917654 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/form/BpmFormServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/form/impl/BpmFormServiceImpl.java @@ -1,12 +1,12 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.service.form; +package cn.iocoder.yudao.adminserver.modules.bpm.service.form.impl; import cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo.BpmFormCreateReqVO; -import cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo.BpmFormExportReqVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo.BpmFormPageReqVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.form.vo.BpmFormUpdateReqVO; import cn.iocoder.yudao.adminserver.modules.bpm.convert.form.BpmFormConvert; -import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmForm; +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.framework.common.pojo.PageResult; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -33,7 +33,7 @@ public class BpmFormServiceImpl implements BpmFormService { @Override public Long createForm(BpmFormCreateReqVO createReqVO) { // 插入 - BpmForm form = BpmFormConvert.INSTANCE.convert(createReqVO); + BpmFormDO form = BpmFormConvert.INSTANCE.convert(createReqVO); formMapper.insert(form); // 返回 return form.getId(); @@ -44,7 +44,7 @@ public class BpmFormServiceImpl implements BpmFormService { // 校验存在 this.validateFormExists(updateReqVO.getId()); // 更新 - BpmForm updateObj = BpmFormConvert.INSTANCE.convert(updateReqVO); + BpmFormDO updateObj = BpmFormConvert.INSTANCE.convert(updateReqVO); formMapper.updateById(updateObj); } @@ -63,17 +63,17 @@ public class BpmFormServiceImpl implements BpmFormService { } @Override - public BpmForm getForm(Long id) { + public BpmFormDO getForm(Long id) { return formMapper.selectById(id); } @Override - public List getFormList(Collection ids) { + public List getFormList(Collection ids) { return formMapper.selectBatchIds(ids); } @Override - public PageResult getFormPage(BpmFormPageReqVO pageReqVO) { + public PageResult getFormPage(BpmFormPageReqVO pageReqVO) { return formMapper.selectPage(pageReqVO); } diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/bpm/service/form/BpmFormServiceTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/bpm/service/form/BpmFormServiceTest.java new file mode 100644 index 000000000..704178e75 --- /dev/null +++ b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/bpm/service/form/BpmFormServiceTest.java @@ -0,0 +1,122 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.service.form; + +import cn.iocoder.yudao.adminserver.BaseDbUnitTest; +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; +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.impl.BpmFormServiceImpl; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; + +import javax.annotation.Resource; + +import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.BPM_FORM_NOT_EXISTS; +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; +import static org.junit.jupiter.api.Assertions.*; + +/** + * {@link BpmFormServiceImpl} 的单元测试类 + * + * @author 芋道源码 + */ +@Import(BpmFormServiceImpl.class) +public class BpmFormServiceTest extends BaseDbUnitTest { + + @Resource + private BpmFormServiceImpl formService; + + @Resource + private BpmFormMapper formMapper; + + @Test + public void testCreateForm_success() { + // 准备参数 + BpmFormCreateReqVO reqVO = randomPojo(BpmFormCreateReqVO.class); + + // 调用 + Long formId = formService.createForm(reqVO); + // 断言 + assertNotNull(formId); + // 校验记录的属性是否正确 + BpmFormDO form = formMapper.selectById(formId); + assertPojoEquals(reqVO, form); + } + + @Test + public void testUpdateForm_success() { + // mock 数据 + BpmFormDO dbForm = randomPojo(BpmFormDO.class); + formMapper.insert(dbForm);// @Sql: 先插入出一条存在的数据 + // 准备参数 + BpmFormUpdateReqVO reqVO = randomPojo(BpmFormUpdateReqVO.class, o -> { + o.setId(dbForm.getId()); // 设置更新的 ID + }); + + // 调用 + formService.updateForm(reqVO); + // 校验是否更新正确 + BpmFormDO form = formMapper.selectById(reqVO.getId()); // 获取最新的 + assertPojoEquals(reqVO, form); + } + + @Test + public void testUpdateForm_notExists() { + // 准备参数 + BpmFormUpdateReqVO reqVO = randomPojo(BpmFormUpdateReqVO.class); + + // 调用, 并断言异常 + assertServiceException(() -> formService.updateForm(reqVO), BPM_FORM_NOT_EXISTS); + } + + @Test + public void testDeleteForm_success() { + // mock 数据 + BpmFormDO dbForm = randomPojo(BpmFormDO.class); + formMapper.insert(dbForm);// @Sql: 先插入出一条存在的数据 + // 准备参数 + Long id = dbForm.getId(); + + // 调用 + formService.deleteForm(id); + // 校验数据不存在了 + assertNull(formMapper.selectById(id)); + } + + @Test + public void testDeleteForm_notExists() { + // 准备参数 + Long id = randomLongId(); + + // 调用, 并断言异常 + assertServiceException(() -> formService.deleteForm(id), BPM_FORM_NOT_EXISTS); + } + + @Test + public void testGetFormPage() { + // mock 数据 + BpmFormDO dbForm = randomPojo(BpmFormDO.class, o -> { // 等会查询到 + o.setName("芋道源码"); + }); + formMapper.insert(dbForm); + // 测试 name 不匹配 + formMapper.insert(cloneIgnoreId(dbForm, o -> o.setName("源码"))); + // 准备参数 + BpmFormPageReqVO reqVO = new BpmFormPageReqVO(); + reqVO.setName("芋道"); + + // 调用 + PageResult pageResult = formService.getFormPage(reqVO); + // 断言 + assertEquals(1, pageResult.getTotal()); + assertEquals(1, pageResult.getList().size()); + assertPojoEquals(dbForm, pageResult.getList().get(0)); + } + +} diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/bpm/service/package-info.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/bpm/service/package-info.java new file mode 100644 index 000000000..cdde7ccc4 --- /dev/null +++ b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/bpm/service/package-info.java @@ -0,0 +1 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.service; diff --git a/yudao-admin-server/src/test/resources/sql/clean.sql b/yudao-admin-server/src/test/resources/sql/clean.sql index d89c5552e..e5b362062 100644 --- a/yudao-admin-server/src/test/resources/sql/clean.sql +++ b/yudao-admin-server/src/test/resources/sql/clean.sql @@ -25,3 +25,6 @@ DELETE FROM "sys_sms_log"; DELETE FROM "sys_error_code"; DELETE FROM "sys_social_user"; DELETE FROM "sys_tenant"; + +-- bpm 开头的 DB +DELETE FROM "bpm_form"; diff --git a/yudao-admin-server/src/test/resources/sql/create_tables.sql b/yudao-admin-server/src/test/resources/sql/create_tables.sql index 93bfd5587..b6623a5e7 100644 --- a/yudao-admin-server/src/test/resources/sql/create_tables.sql +++ b/yudao-admin-server/src/test/resources/sql/create_tables.sql @@ -472,3 +472,19 @@ CREATE TABLE IF NOT EXISTS "sys_tenant" ( "deleted" bit NOT NULL DEFAULT FALSE, PRIMARY KEY ("id") ) COMMENT '租户'; + + +CREATE TABLE IF NOT EXISTS "bpm_form" ( + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "name" varchar(63) NOT NULL, + "status" tinyint NOT NULL, + "fields" varchar(255) NOT NULL, + "conf" varchar(255) NOT NULL, + "remark" varchar(255), + "creator" varchar(64) DEFAULT '', + "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updater" varchar(64) DEFAULT '', + "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + "deleted" bit NOT NULL DEFAULT FALSE, + PRIMARY KEY ("id") +) COMMENT '动态表单'; diff --git a/yudao-admin-ui/src/utils/generator/drawingDefalut.js b/yudao-admin-ui/src/utils/generator/drawingDefalut.js index c1469c694..09f133ca1 100644 --- a/yudao-admin-ui/src/utils/generator/drawingDefalut.js +++ b/yudao-admin-ui/src/utils/generator/drawingDefalut.js @@ -1,29 +1,29 @@ export default [ { - // layout: 'colFormItem', - // tagIcon: 'input', - // label: '手机号', - // vModel: 'mobile', - // formId: 6, - // tag: 'el-input', - // placeholder: '请输入手机号', - // defaultValue: '', - // span: 24, - // style: { width: '100%' }, - // clearable: true, - // prepend: '', - // append: '', - // 'prefix-icon': 'el-icon-mobile', - // 'suffix-icon': '', - // maxlength: 11, - // 'show-word-limit': true, - // readonly: false, - // disabled: false, - // required: true, - // changeTag: true, - // regList: [{ - // pattern: '/^1(3|4|5|7|8|9)\\d{9}$/', - // message: '手机号格式错误' - // }] + layout: 'colFormItem', + tagIcon: 'input', + label: '手机号', + vModel: 'mobile', + formId: 6, + tag: 'el-input', + placeholder: '请输入手机号', + defaultValue: '', + span: 24, + style: { width: '100%' }, + clearable: true, + prepend: '', + append: '', + 'prefix-icon': 'el-icon-mobile', + 'suffix-icon': '', + maxlength: 11, + 'show-word-limit': true, + readonly: false, + disabled: false, + required: true, + changeTag: true, + regList: [{ + pattern: '/^1(3|4|5|7|8|9)\\d{9}$/', + message: '手机号格式错误' + }] } ] diff --git a/yudao-admin-ui/src/views/bpm/form/formEditor.vue b/yudao-admin-ui/src/views/bpm/form/formEditor.vue index 308296aec..e4c13ce55 100644 --- a/yudao-admin-ui/src/views/bpm/form/formEditor.vue +++ b/yudao-admin-ui/src/views/bpm/form/formEditor.vue @@ -32,7 +32,7 @@
- 布局型组件 + 布局型组件
@@ -66,11 +66,10 @@
- - 清空 - + 保存 + 清空
- + { + const data = response.data + this.form = { + id: data.id, + name: data.name, + status: data.status, + remark: data.remark + } + this.formConf = JSON.parse(data.conf) + this.drawingList = this.decodeFields(data.fields) + }); + } + }, methods: { activeFormItem(element) { this.activeData = element @@ -202,6 +223,53 @@ export default { ...this.formConf } }, + save() { + // this.AssembleFormData() + // console.log(this.formData) + this.$refs["form"].validate(valid => { + if (!valid) { + return; + } + const form = { + conf: JSON.stringify(this.formConf), // 表单配置 + // fields: JSON.stringify(this.drawingList), // 表单项的数组 + fields: this.encodeFields(), // 表单项的数组 + ...this.form // 表单名等 + } + // 修改的提交 + if (this.form.id != null) { + updateForm(form).then(response => { + this.msgSuccess("修改成功"); + this.close() + }); + return; + } + // 添加的提交 + createForm(form).then(response => { + this.msgSuccess("新增成功"); + this.close() + }); + }); + }, + /** 关闭按钮 */ + close() { + this.$store.dispatch("tagsView/delView", this.$route); + this.$router.push({ path: "/bpm/manager/form", query: { t: Date.now()}}) + }, + encodeFields() { + const fields = [] + this.drawingList.forEach(item => { + fields.push(JSON.stringify(item)) + }) + return fields + }, + decodeFields(fields) { + const drawingList = [] + fields.forEach(item => { + drawingList.push(JSON.parse(item)) + }) + return drawingList + }, empty() { this.$confirm('确定要清空所有组件吗?', '提示', { type: 'warning' }).then( () => { diff --git a/yudao-admin-ui/src/views/bpm/form/index.vue b/yudao-admin-ui/src/views/bpm/form/index.vue index c9af34559..9abb7cef3 100644 --- a/yudao-admin-ui/src/views/bpm/form/index.vue +++ b/yudao-admin-ui/src/views/bpm/form/index.vue @@ -30,7 +30,6 @@ {{ getDictDataLabel(DICT_TYPE.SYS_COMMON_STATUS, scope.row.status) }} -