随着企业数字化转型的需求日益增长,低代码平台作为一种快速开发和部署业务应用的方法,正在获得更多关注。领域驱动设计(DDD)是一种软件架构风格,旨在更好地满足复杂业务需求。结合这两者可以创建灵活且可维护的应用程序。
在本应用中,我们将利用低代码平台的灵活性和DDD的架构优势来构建一个可持续的解决方案。
本文将以一个最常见的实例来展开分析。
模型构建,主要是根据数据库表,将结构化数据关系(1:1,1:N,N:N)对应完成ormaping映射。实例中采用使用了一个单表模型做演示。同时将在资源库这一层抽象出的接口信息,通过注解完成在DDD领域模型中的注册,使得持久层的操作可见可用。具体的操作办法如下:
资源库是领域模型仓储库的一个具体事项方式,主要管理数据库资源以及已经完成映射的,DAO类库以及其相应的接口操作库。
完成数据连接导入后可以动态获取库表及业务视图,完成库表导入后由资源库完成相应的代码构建工作。
代码构建主要是基于已经建立的持久化模型,根据模版管理库构建对应的代码结构。
添加图片注释,不超过 140 字(可选)
完成构建后就可以在线查看生成代码了。
完成代码构建后,可以自动或手工完成相关的代码编译工作,编译完成后相应类库信息会同步到领域模型库中,方便领域模型根据模版构建相应的聚合应用体系。
相关代码示例如下:
贫血模型接口(I**Class)
package com.ds.test.repository.leaveapplication.module;
import com.ds.enums.db.*;
import com.ds.enums.*;
import com.ds.esd.tool.ui.enums.*;
import java.util.*;
import com.ds.esd.custom.form.enums.*;
import com.ds.esd.custom.nav.enums.*;
import com.ds.esd.custom.grid.enums.*;
import com.ds.esd.custom.gallery.enums.*;
import com.ds.test.repository.leaveapplication.module.*;
import com.ds.test.repository.leaveapplication.service.*;
@DBTable(configKey="fdt",cname="请假审批单表",primaryKey="uuid",tableName="leaveapplication")
@RepositoryAnnotation
@Entity
public interface ILeaveapplication {
@Uid
@DBField(cnName="主键",length=36,dbFieldName="uuid")
public String getUuid();
public void setUuid(String uuid);
@CustomAnnotation(caption="学号")
@DBField(cnName="学号",length=10,dbFieldName="studentid")
public String getStudentid();
public void setStudentid(String studentid);
@CustomAnnotation(caption="姓名")
@DBField(cnName="姓名",length=50,dbFieldName="studentname")
public String getStudentname();
public void setStudentname(String studentname);
@CustomAnnotation(caption="专业/方向")
@DBField(cnName="专业/方向",length=50,dbFieldName="major")
public String getMajor();
public void setMajor(String major);
@CustomAnnotation(caption="导师")
@DBField(cnName="导师",length=50,dbFieldName="advisor")
public String getAdvisor();
public void setAdvisor(String advisor);
@CustomAnnotation(caption="请假日期")
@ComboInputAnnotation(inputType=ComboInputType.date)
@FieldAnnotation(componentType=ComponentType.ComboInput)
@DBField(cnName="请假日期",length=0,dbType=ColType.DATE,dbFieldName="leavedate")
public Date getLeavedate();
public void setLeavedate(Date leavedate);
@CustomAnnotation(caption="请假时间")
@ComboInputAnnotation(inputType=ComboInputType.time)
@FieldAnnotation(componentType=ComponentType.ComboInput)
@DBField(cnName="请假时间",length=0,dbType=ColType.TIME,dbFieldName="leavetime")
public Date getLeavetime();
public void setLeavetime(Date leavetime);
@CustomAnnotation(caption="请假课程")
@DBField(cnName="请假课程",length=50,dbFieldName="coursename")
public String getCoursename();
public void setCoursename(String coursename);
@CustomAnnotation(caption="任课老师")
@DBField(cnName="任课老师",length=50,dbFieldName="instructor")
public String getInstructor();
public void setInstructor(String instructor);
@CustomAnnotation(caption="请假事由")
@FieldAnnotation(componentType=ComponentType.MultiLines,colSpan=-1,manualHeight=200)
@DBField(cnName="请假事由",length=0,dbType=ColType.TEXT,dbFieldName="reason")
public String getReason();
public void setReason(String reason);
@CustomAnnotation(caption="审批状态")
@DBField(cnName="审批状态",length=10,dbFieldName="approvalstatus")
public String getApprovalstatus();
public void setApprovalstatus(String approvalstatus);
@CustomAnnotation(caption="审批人")
@DBField(cnName="审批人",length=50,dbFieldName="approvalperson")
public String getApprovalperson();
public void setApprovalperson(String approvalperson);
@CustomAnnotation(caption="审批单位")
@DBField(cnName="审批单位",length=50,dbFieldName="approvalunit")
public String getApprovalunit();
public void setApprovalunit(String approvalunit);
@CustomAnnotation(caption="userId")
@DBField(cnName="userId",dbFieldName="userid")
public String getUserid();
public void setUserid(String userid);
}
数据映射(实体Bean)
package com.ds.test.repository.leaveapplication.module;
import com.ds.enums.db.*;
import com.ds.enums.*;
import com.ds.esd.tool.ui.enums.*;
import java.util.*;
import com.ds.esd.custom.api.annotation.*;
import com.ds.esd.annotation.*;
import com.ds.esd.custom.enums.*;
import com.ds.esd.custom.api.enums.*;
import com.ds.esd.custom.titleblock.enums.*;
import com.ds.esd.custom.tree.enums.*;
import com.ds.esd.custom.form.enums.*;
import com.ds.esd.custom.nav.enums.*;
import com.ds.esd.custom.grid.enums.*;
import com.ds.esd.custom.gallery.enums.*;
import com.ds.test.repository.leaveapplication.module.*;
import com.ds.test.repository.leaveapplication.service.*;
@DBTable(configKey="fdt",cname="请假审批单表",primaryKey="uuid",tableName="leaveapplication")
@RepositoryAnnotation
@Entity
public class Leaveapplication {
@Uid
@DBField(cnName="主键",length=36,dbFieldName="uuid")
public String uuid;
@CustomAnnotation(caption="学号")
@DBField(cnName="学号",length=10,dbFieldName="studentid")
public String studentid;
@CustomAnnotation(caption="姓名")
@DBField(cnName="姓名",length=50,dbFieldName="studentname")
public String studentname;
@CustomAnnotation(caption="专业/方向")
@DBField(cnName="专业/方向",length=50,dbFieldName="major")
public String major;
@CustomAnnotation(caption="导师")
@DBField(cnName="导师",length=50,dbFieldName="advisor")
public String advisor;
@CustomAnnotation(caption="请假日期")
@ComboInputAnnotation(inputType=ComboInputType.date)
@FieldAnnotation(componentType=ComponentType.ComboInput)
@DBField(cnName="请假日期",length=0,dbType=ColType.DATE,dbFieldName="leavedate")
public Date leavedate;
@CustomAnnotation(caption="请假时间")
@ComboInputAnnotation(inputType=ComboInputType.time)
@FieldAnnotation(componentType=ComponentType.ComboInput)
@DBField(cnName="请假时间",length=0,dbType=ColType.TIME,dbFieldName="leavetime")
public Date leavetime;
@CustomAnnotation(caption="请假课程")
@DBField(cnName="请假课程",length=50,dbFieldName="coursename")
public String coursename;
@CustomAnnotation(caption="任课老师")
@DBField(cnName="任课老师",length=50,dbFieldName="instructor")
public String instructor;
@CustomAnnotation(caption="请假事由")
@FieldAnnotation(componentType=ComponentType.MultiLines,colSpan=-1,manualHeight=200)
@DBField(cnName="请假事由",length=0,dbType=ColType.TEXT,dbFieldName="reason")
public String reason;
@CustomAnnotation(caption="审批状态")
@DBField(cnName="审批状态",length=10,dbFieldName="approvalstatus")
public String approvalstatus;
@CustomAnnotation(caption="审批人")
@DBField(cnName="审批人",length=50,dbFieldName="approvalperson")
public String approvalperson;
@CustomAnnotation(caption="审批单位")
@DBField(cnName="审批单位",length=50,dbFieldName="approvalunit")
public String approvalunit;
@CustomAnnotation(caption="activityHist")
@DBField(cnName="activityHist",dbFieldName="activityhistoryid")
public String activityhistoryid;
@CustomAnnotation(caption="activityInst")
@DBField(cnName="activityInst",dbFieldName="activityinstid")
public String activityinstid;
@CustomAnnotation(caption="userId")
@DBField(cnName="userId",dbFieldName="userid")
public String userid;
@CustomAnnotation(caption="processInstI")
@DBField(cnName="processInstI",dbFieldName="processinstid")
public String processinstid
}
数据接口(定义)
package com.ds.test.repository.leaveapplication.service;
import com.ds.enums.db.*;
import com.ds.enums.*;
import com.ds.esd.tool.ui.enums.*;
import java.util.*;
import com.ds.esd.custom.tree.enums.*;
import com.ds.esd.custom.form.enums.*;
import com.ds.esd.custom.nav.enums.*;
import com.ds.esd.custom.grid.enums.*;
import com.ds.esd.custom.gallery.enums.*;
import com.ds.test.repository.leaveapplication.module.*;
import com.ds.test.repository.leaveapplication.service.*;
@Aggregation(type = AggregationType.aggregationEntity,
entityClass=Leaveapplication.class,rootClass= LeaveapplicationService.class)
public interface LeaveapplicationService{
@ModuleAnnotation(moduleViewType = ModuleViewType.GridConfig)
@APIEventAnnotation(bindMenu = {CustomMenuItem.reload}, autoRun = true, customRequestData = RequestPathEnum.ctx)
public List<Leaveapplication> findAll()throws JDSException;
public List<Leaveapplication> findByWhere(String where)throws JDSException;
@APIEventAnnotation(bindMenu = {CustomMenuItem.search})
public List<Leaveapplication> find(Leaveapplication leaveapplication)throws JDSException;
@ModuleAnnotation(moduleViewType = ModuleViewType.FormConfig)
@APIEventAnnotation(bindFormEvent = CustomFormEvent.formLoad,
bindGridEvent = {CustomGridEvent.editor}, autoRun = true,
customRequestData = RequestPathEnum.ctx, customResponseData = ResponsePathEnum.form)
public Leaveapplication getLeaveapplicationInfo(String uuid) throws JDSException;
@APIEventAnnotation(bindMenu = {CustomMenuItem.save}, callback = {CustomCallBack.ReloadParent, CustomCallBack.Close})
public Leaveapplication update( Leaveapplication leaveapplication) throws JDSException ;
@APIEventAnnotation(bindMenu = {CustomMenuItem.delete}, callback = CustomCallBack.Reload)
public Boolean delete(String uuid) throws JDSException ;
}
数据接口(实现)
package com.ds.test.repository.leaveapplication.service;
import com.ds.enums.db.*;
import com.ds.enums.*;
import com.ds.esd.tool.ui.enums.*;
import com.ds.test.repository.leaveapplication.module.*;
import com.ds.test.repository.leaveapplication.service.*;
@EsbBeanAnnotation
public class LeaveapplicationServiceImpl implements LeaveapplicationService{
public List<Leaveapplication> findAll()throws JDSException{
List<Leaveapplication> leaveapplicationList = new ArrayList<>();
DAO dao = null;
try {
DAOFactory factory = new DAOFactory(Leaveapplication.class);
dao = factory.getDAO();
leaveapplicationList = dao.findAll();
} catch (Exception e) {
e.printStackTrace();
throw new JDSException(e);
} finally {
if (dao != null) {
dao.close();
}
}
return leaveapplicationList;
}
public List<Leaveapplication> findByWhere(String where)throws JDSException{
List<Leaveapplication> leaveapplicationList = new ArrayList<>();
DAO dao =null;
try {
DAOFactory factory = new DAOFactory(Leaveapplication.class);
dao = factory.getDAO();
leaveapplicationList = dao.find(where);
} catch (Exception e) {
e.printStackTrace();
throw new JDSException(e);
} finally {
if (dao != null) {
dao.close();
}
}
return leaveapplicationList;
}
public List<Leaveapplication> find(Leaveapplication leaveapplication)throws JDSException{
List<Leaveapplication> leaveapplicationList = new ArrayList<>();
DAO dao = null;
try {
DAOFactory factory = new DAOFactory(Leaveapplication.class);
dao = factory.getDAO();
leaveapplicationList = dao.find(leaveapplication);
} catch (Exception e) {
e.printStackTrace();
throw new JDSException(e);
} finally {
if (dao != null) {
dao.close();
}
}
return leaveapplicationList;
}
public Leaveapplication getLeaveapplicationInfo(String uuid) throws JDSException {
Leaveapplication leaveapplication = null;
DAO<Leaveapplication> dao =null;
try {
DAOFactory factory = new DAOFactory(Leaveapplication.class);
dao = factory.getDAO();
if (uuid==null||uuid.equals("")){
leaveapplication= dao.createBean();
}else{
leaveapplication= dao.findByPrimaryKey(uuid);
}
} catch (Exception e) {
e.printStackTrace();
throw new JDSException(e);
} finally {
if (dao != null) {
dao.close();
}
}
return leaveapplication;
}
public Leaveapplication update( Leaveapplication leaveapplication) throws JDSException {
DAO<Leaveapplication> dao = null;
try {
DAOFactory factory = new DAOFactory(Leaveapplication.class);
dao = factory.getDAO();
dao.update(leaveapplication);
} catch (Exception e) {
e.printStackTrace();
throw new JDSException(e);
} finally {
if (dao != null) {
dao.close();
}
}
return leaveapplication;
}
public Boolean delete(String uuid) throws JDSException {
DAO<Leaveapplication> dao =null;
try {
DAOFactory factory = new DAOFactory(Leaveapplication.class);
dao = factory.getDAO();
if (uuid.indexOf(";") > -1) {
for (String uid : uuid.split(";")) {
dao.delete(uid);
}
} else {
dao.delete(uuid);
}
} catch (Exception e) {
e.printStackTrace();
throw new JDSException(e);
} finally {
if (dao != null) {
dao.close();
}
}
return true;
}
}
聚合应用是领域模型建模中最为重要的一个环节,这个环节的重点是将,资源库相应的操作接口转换为领域模型应用,通过web聚合器输出位web 引用发布,同时将实体操作转换为领域事件供DDD内部完成调度处理。而聚合应用则是将视图与模型有机结合实现聚合实体以及聚合根应用。同时抽取相应的数据字典以及应用域作为上层的支撑。
package com.ds.test.domain.leaveapplication.api;
import org.springframework.stereotype.*;
import org.springframework.core.annotation.*;
import com.ds.esd.custom.action.module.*;
import com.ds.esd.custom.titleblock.enums.*;
import com.ds.esd.custom.tree.enums.*;
import com.ds.esd.custom.form.enums.*;
import com.ds.esd.custom.nav.enums.*;
import com.ds.esd.custom.grid.enums.*;
import com.ds.esd.custom.gallery.enums.*;
import com.ds.esd.custom.annotation.toolbar.*;
import com.ds.test.domain.leaveapplication.*;
import com.ds.test.domain.leaveapplication.api.*;
import test.leaveapplication.*;
@Aggregation(rootClass=LeaveapplicationService.class,
entityClass=Leaveapplication.class,type=AggregationType.aggregationEntity)
@RequestMapping(value="/test/leaveapplication")
@Controller
public interface LeaveapplicationServiceAPI {
@APIEventAnnotation(bindMenu=CustomMenuItem.reload,customRequestData=RequestPathEnum.ctx,autoRun=true)
@ModuleAnnotation(moduleViewType=ModuleViewType.GridConfig)
@GridViewAnnotation
@CustomAnnotation
@RequestMapping(value="FindAll")
@ResponseBody
public ListResultModel<List<FindAll>> findAll ();
@APIEventAnnotation(bindFormEvent=CustomFormEvent.formLoad,
customRequestData=RequestPathEnum.ctx,autoRun=true,
bindGridEvent=CustomGridEvent.editor,customResponseData=ResponsePathEnum.form)
@ModuleAnnotation(moduleViewType=ModuleViewType.FormConfig)
@FormViewAnnotation
@RequestMapping(value="LeaveapplicationInfo")
@ResponseBody
public ResultModel<LeaveapplicationInfo> getLeaveapplicationInfo (String uuid);
@APIEventAnnotation(bindMenu=CustomMenuItem.save,callback={CustomCallBack.ReloadParent,CustomCallBack.Close})
public ResultModel<Leaveapplication> update (@RequestBody Leaveapplication leaveapplication);
@APIEventAnnotation(bindMenu=CustomMenuItem.search)
public ListResultModel<List<Leaveapplication>> find (Leaveapplication leaveapplication);
@APIEventAnnotation(bindMenu=CustomMenuItem.delete,callback=CustomCallBack.Reload)
@RequestMapping(value="delete")
@ResponseBody
public ResultModel<Boolean> delete (String uuid);
@RequestMapping(value="findByWhere")
@ResponseBody
public ListResultModel<List<Leaveapplication>> findByWhere (String where);
}
视图域是在完成初步聚合实体建模后,根据具体的模型来构建视图体系,这些体系中根据实体的结构来构建视图的结构,最终通过,代码的方式展现处理。
视图模版种类:
视图模版具体化后工程结构:
(2)视图配置
为列表增加菜单
为列表增加分页栏
为表单字段子域配置
配置 模块编译输出
添加图片注释,不超过 140 字(可选)
package test.leaveapplication;
import com.ds.config.*;
import java.util.*;
import com.ds.esd.custom.action.module.*;
import com.ds.esd.custom.annotation.*;
import com.ds.esd.custom.bean.enums.*;
import com.ds.esd.custom.annotation.toolbar.*;
import org.springframework.web.bind.annotation.*;
@PageBar
@GridRowCmd
@MenuBarMenu(domainId="test")
@RowHead
@GridAnnotation(uidColumn="uuid",customMenu={GridMenu.Delete,GridMenu.Reload,GridMenu.Add})
public interface FindAll {
@CustomAnnotation(caption="请假事由")
@GridColItemAnnotation(width="8.0em")
public String getReason();
public void setReason(String reason);
@CustomAnnotation(caption="专业/方向")
@GridColItemAnnotation(width="8.0em")
public String getMajor();
public void setMajor(String major);
@CustomAnnotation(caption="userId")
@GridColItemAnnotation(width="8.0em")
public String getUserid();
public void setUserid(String userid);
@CustomAnnotation(caption="学号")
@GridColItemAnnotation(width="8.0em")
public String getStudentid();
public void setStudentid(String studentid);
@CustomAnnotation(caption="姓名")
@GridColItemAnnotation(width="8.0em")
public String getStudentname();
public void setStudentname(String studentname);
@CustomAnnotation(caption="请假日期")
@GridColItemAnnotation(width="8.0em",inputType=ComboInputType.date)
public Date getLeavedate();
public void setLeavedate(Date leavedate);
@CustomAnnotation(caption="任课老师")
@GridColItemAnnotation(width="8.0em")
public String getInstructor();
public void setInstructor(String instructor);
@CustomAnnotation(caption="请假时间")
@GridColItemAnnotation(width="8.0em",inputType=ComboInputType.time)
public Date getLeavetime();
public void setLeavetime(Date leavetime);
@CustomAnnotation(caption="请假课程")
@GridColItemAnnotation(width="8.0em")
public String getCoursename();
public void setCoursename(String coursename);
@CustomAnnotation(caption="processInstI")
@GridColItemAnnotation(width="8.0em")
public String getProcessinstid();
public void setProcessinstid(String processinstid);
@CustomAnnotation(caption="导师")
@GridColItemAnnotation(width="8.0em")
public String getAdvisor();
public void setAdvisor(String advisor);
@CustomAnnotation(caption="审批单位")
@GridColItemAnnotation(width="8.0em")
public String getApprovalunit();
public void setApprovalunit(String approvalunit);
@CustomAnnotation(caption="审批状态")
@GridColItemAnnotation(width="8.0em")
public String getApprovalstatus();
public void setApprovalstatus(String approvalstatus);
@CustomAnnotation(caption="审批人")
@GridColItemAnnotation(width="8.0em")
public String getApprovalperson();
public void setApprovalperson(String approvalperson);
@CustomAnnotation(uid=true,hidden=true,index=1)
@GridColItemAnnotation(width="8.0em")
public String getUuid();
public void setUuid(String uuid);
@CustomAnnotation(index=17)
@GridColItemAnnotation(width="8.0em",flexSize=true)
public String getFormTitle();
public void setFormTitle(String formTitle);
}
package test.leaveapplication;
import com.ds.config.*;
import java.util.*;
import com.ds.esd.tool.ui.component.navigation.*;
import com.ds.esd.tool.ui.component.form.*;
import com.ds.web.*;
import com.ds.esd.custom.enums.*;
import com.ds.esd.dsm.aggregation.*;
import com.ds.esd.custom.field.*;
import com.ds.esd.custom.field.combo.*;
@FormAnnotation
public interface LeaveapplicationInfo {
@FieldAnnotation(componentType=ComponentType.Label,colSpan=-1,manualHeight=60)
@CustomAnnotation(index=30,caption="LeaveapplicationInfo")
@LabelAnnotation(hAlign=HAlignType.center,fontSize="3em")
public String getFormTitle();
public void setFormTitle(String formTitle);
@FieldAnnotation(componentType=ComponentType.ComboInput,colSpan=-1)
@CustomAnnotation(index=1,caption="请假事由")
public String getReason();
public void setReason(String reason);
@CustomAnnotation(index=2,caption="专业/方向")
@InputAnnotation
public String getMajor();
public void setMajor(String major);
@FieldAnnotation(componentType=ComponentType.ComboInput)
@CustomAnnotation(index=3,caption="请假时间")
@ComboDateAnnotation
public Date getLeavetime();
public void setLeavetime(Date leavetime);
@CustomAnnotation(index=4,caption="导师")
@InputAnnotation
public String getAdvisor();
public void setAdvisor(String advisor);
@FieldAnnotation(componentType=ComponentType.ComboInput)
@CustomAnnotation(index=5,caption="请假日期")
@ComboDateAnnotation
public Date getLeavedate();
public void setLeavedate(Date leavedate);
@FieldAnnotation(componentType=ComponentType.HiddenInput)
@CustomAnnotation(index=6,caption="processInstI")
@InputAnnotation
public String getProcessinstid();
public void setProcessinstid(String processinstid);
@CustomAnnotation(index=7,caption="学号")
@InputAnnotation
public String getStudentid();
public void setStudentid(String studentid);
@CustomAnnotation(index=8,caption="姓名")
@InputAnnotation
public String getStudentname();
public void setStudentname(String studentname);
@CustomAnnotation(index=9,caption="审批单位")
@InputAnnotation
public String getApprovalunit();
public void setApprovalunit(String approvalunit);
@CustomAnnotation(index=10,caption="请假课程")
@InputAnnotation
public String getCoursename();
public void setCoursename(String coursename);
@CustomAnnotation(index=11,caption="任课老师")
@InputAnnotation
public String getInstructor();
public void setInstructor(String instructor);
@FieldAnnotation(componentType=ComponentType.HiddenInput)
@CustomAnnotation(index=12,caption="userId")
@InputAnnotation
public String getUserid();
public void setUserid(String userid);
@FieldAnnotation(componentType=ComponentType.HiddenInput)
@CustomAnnotation(index=13,caption="activityHist")
@InputAnnotation
public String getActivityhistoryid();
public void setActivityhistoryid(String activityhistoryid);
@CustomAnnotation(index=14,caption="审批状态")
@InputAnnotation
public String getApprovalstatus();
public void setApprovalstatus(String approvalstatus);
@CustomAnnotation(index=15,caption="审批人")
@InputAnnotation
public String getApprovalperson();
public void setApprovalperson(String approvalperson);
@FieldAnnotation(componentType=ComponentType.HiddenInput)
@CustomAnnotation(index=16,caption="activityInst")
@InputAnnotation
public String getActivityinstid();
public void setActivityinstid(String activityinstid);
@FieldAnnotation(componentType=ComponentType.HiddenInput)
@CustomAnnotation(uid=true,hidden=true,index=17)
public String getUuid();
public void setUuid(String uuid);
}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。