Permalink
Browse files

完成了JPA演示

  • Loading branch information...
1 parent ce6dbf7 commit db0efd7963a1cd5debbd5df06110f702c7c45dc0 @henryyan committed Apr 17, 2014
View
@@ -8,3 +8,4 @@
*.iml
.idea
rebel.xml
+.settings
@@ -0,0 +1,29 @@
+package me.kafeitu.demo.activiti.dao;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.springframework.stereotype.Component;
+
+/**
+ * Activiti相关DAO操作
+ * @author: Henry Yan
+ */
+@Component
+public class ActivitiDao {
+
+ @PersistenceContext
+ private EntityManager entityManager;
+
+ /**
+ * 流程完成后清理detail表中的表单类型数据
+ * @param processInstanceId
+ * @return
+ */
+ public int deleteFormPropertyByProcessInstanceId(String processInstanceId) {
+ int i = entityManager.createNativeQuery("delete from act_hi_detail where proc_inst_id_ = ? and type_ = 'FormProperty' ")
+ .setParameter(1, processInstanceId).executeUpdate();
+ return i;
+ }
+
+}
@@ -30,6 +30,16 @@
private String leaveType;
private String reason;
+ /**
+ * 部门领导是否同意
+ */
+ private String deptLeaderApproved;
+
+ /**
+ * HR是否同意
+ */
+ private String hrApproved;
+
@Id
@Column(name="ID")
@GeneratedValue(strategy = GenerationType.AUTO)
@@ -131,6 +141,24 @@ public void setReportBackDate(Date reportBackDate) {
this.reportBackDate = reportBackDate;
}
+ @Column
+ public String getDeptLeaderApproved() {
+ return deptLeaderApproved;
+ }
+
+ public void setDeptLeaderApproved(String deptLeaderApproved) {
+ this.deptLeaderApproved = deptLeaderApproved;
+ }
+
+ @Column
+ public String getHrApproved() {
+ return hrApproved;
+ }
+
+ public void setHrApproved(String hrApproved) {
+ this.hrApproved = hrApproved;
+ }
+
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
@@ -10,6 +10,7 @@
import org.springframework.transaction.annotation.Transactional;
/**
+ * 请假实体JPA 实体管理器
* @author: Henry Yan
*/
@Service
@@ -32,8 +33,13 @@ public LeaveJpaEntity newLeave(DelegateExecution execution) {
return leave;
}
+ @Transactional
+ public void save(LeaveJpaEntity leave) {
+ entityManager.persist(leave);
+ }
+
public LeaveJpaEntity getLeave(Long id) {
return entityManager.find(LeaveJpaEntity.class, id);
}
-}
+}
@@ -0,0 +1,45 @@
+package me.kafeitu.demo.activiti.service.oa.leave;
+
+import me.kafeitu.demo.activiti.dao.ActivitiDao;
+import me.kafeitu.demo.activiti.entity.oa.LeaveJpaEntity;
+import org.activiti.engine.delegate.DelegateExecution;
+import org.activiti.engine.delegate.JavaDelegate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * 请假流程结束监听器
+ *
+ * @author: Henry Yan
+ */
+@Service
+@Transactional
+public class LeaveProcessEndListener implements JavaDelegate {
+
+ protected Logger logger = LoggerFactory.getLogger(getClass());
+
+ @Autowired
+ ActivitiDao activitiDao;
+
+ @Override
+ public void execute(DelegateExecution execution) throws Exception {
+ String processInstanceId = execution.getProcessInstanceId();
+
+ LeaveJpaEntity leave = (LeaveJpaEntity) execution.getVariable("leave");
+ Object deptLeaderApproved = execution.getVariable("deptLeaderApproved");
+ if (deptLeaderApproved != null) {
+ leave.setDeptLeaderApproved(deptLeaderApproved.toString());
+ }
+
+ Object hrApproved = execution.getVariable("hrApproved");
+ if (hrApproved != null) {
+ leave.setHrApproved(hrApproved.toString());
+ }
+
+ int i = activitiDao.deleteFormPropertyByProcessInstanceId(processInstanceId);
+ logger.debug("清理了 {} 条历史表单数据", i);
+ }
+}
@@ -0,0 +1,39 @@
+package me.kafeitu.demo.activiti.service.oa.leave;
+
+import org.activiti.engine.delegate.event.ActivitiEvent;
+import org.activiti.engine.delegate.event.ActivitiEventListener;
+import org.activiti.engine.delegate.event.ActivitiVariableEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * 引擎的全局监听器
+ * @author: Henry Yan
+ */
+@Service
+@Transactional
+public class VariableCreateListener implements ActivitiEventListener {
+
+ protected Logger logger = LoggerFactory.getLogger(getClass());
+
+ @Override
+ public void onEvent(ActivitiEvent event) {
+ switch (event.getType()) {
+
+ case VARIABLE_CREATED:
+ ActivitiVariableEvent variableEvent = (ActivitiVariableEvent) event;
+ System.out.println("创建了变量: " + variableEvent.getVariableName() + ", 值:" + variableEvent.getVariableValue());
+ break;
+
+ default:
+ System.out.println("Event received: " + event.getType());
+ }
+ }
+
+ @Override
+ public boolean isFailOnException() {
+ return false;
+ }
+}
@@ -76,7 +76,7 @@
<property name="transactionManager" ref="transactionManager"/>
<property name="databaseSchemaUpdate" value="true"/>
<property name="jobExecutorActivate" value="false"/>
- <property name="history" value="full"/>
+ <!--<property name="history" value="full"/>-->
<property name="processDefinitionCacheLimit" value="10"/>
<!-- UUID作为主键生成策略
@@ -110,6 +110,17 @@
<property name="jpaEntityManagerFactory" ref="entityManagerFactory" />
<property name="jpaHandleTransaction" value="false" />
<property name="jpaCloseEntityManager" value="false" />
+
+ <!-- 全局事件 -->
+ <property name="typedEventListeners">
+ <map>
+ <entry key="VARIABLE_CREATED" >
+ <list>
+ <ref bean="variableCreateListener"/>
+ </list>
+ </entry>
+ </map>
+ </property>
</bean>
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
@@ -4,24 +4,25 @@
<documentation>请假流程演示-JPA,把变量保存在独立的表中</documentation>
<extensionElements>
<activiti:executionListener event="start" expression="${execution.setVariable('leave', leaveEntityManager.newLeave(execution))}"></activiti:executionListener>
+ <activiti:executionListener event="end" delegateExpression="${leaveProcessEndListener}"></activiti:executionListener>
</extensionElements>
<startEvent id="startevent1" name="Start" activiti:initiator="applyUserId">
<extensionElements>
- <activiti:formProperty id="leaveType" name="请假类型" type="enum" required="true">
- <activiti:value id="公休" name="公休"></activiti:value>
- <activiti:value id="病假" name="病假"></activiti:value>
- <activiti:value id="调休" name="调休"></activiti:value>
- <activiti:value id="事假" name="事假"></activiti:value>
- <activiti:value id="婚假" name="婚假"></activiti:value>
- </activiti:formProperty>
+ <activiti:formProperty id="leaveType" name="请假类型" type="enum" required="true">
+ <activiti:value id="公休" name="公休"></activiti:value>
+ <activiti:value id="病假" name="病假"></activiti:value>
+ <activiti:value id="调休" name="调休"></activiti:value>
+ <activiti:value id="事假" name="事假"></activiti:value>
+ <activiti:value id="婚假" name="婚假"></activiti:value>
+ </activiti:formProperty>
<activiti:formProperty id="startTime" name="请假开始日期" type="date" datePattern="yyyy-MM-dd" required="true"></activiti:formProperty>
<activiti:formProperty id="endTime" name="请假结束日期" type="date" datePattern="yyyy-MM-dd" required="true"></activiti:formProperty>
<activiti:formProperty id="reason" name="请假原因" type="string" required="true"></activiti:formProperty>
</extensionElements>
</startEvent>
<userTask id="deptLeaderAudit" name="部门领导审批" activiti:candidateGroups="deptLeader">
<extensionElements>
- <activiti:formProperty id="leaveType" name="请假类型" expression="${leave.leaveType}" type="string" writable="false"></activiti:formProperty>
+ <activiti:formProperty id="leaveType" name="请假类型" type="string" expression="${leave.leaveType}" writable="false"></activiti:formProperty>
<activiti:formProperty id="startTime" name="请假开始日期" type="date" expression="${leave.startTime}" datePattern="yyyy-MM-dd" writable="false"></activiti:formProperty>
<activiti:formProperty id="endTime" name="请假结束日期" type="date" expression="${leave.endTime}" datePattern="yyyy-MM-dd" writable="false"></activiti:formProperty>
<activiti:formProperty id="reason" name="请假原因" type="string" expression="${leave.reason}" writable="false"></activiti:formProperty>
@@ -34,10 +35,10 @@
<exclusiveGateway id="exclusivegateway5" name="Exclusive Gateway"></exclusiveGateway>
<userTask id="modifyApply" name="调整申请" activiti:assignee="${leave.userId}">
<extensionElements>
- <activiti:formProperty id="leaveType" name="请假类型" expression="${leave.leaveType}" type="string" writable="false"></activiti:formProperty>
- <activiti:formProperty id="startTime" name="请假开始日期" type="date" expression="${leave.startTime}" datePattern="yyyy-MM-dd" writable="false"></activiti:formProperty>
- <activiti:formProperty id="endTime" name="请假结束日期" type="date" expression="${leave.endTime}" datePattern="yyyy-MM-dd" writable="false"></activiti:formProperty>
- <activiti:formProperty id="reason" name="请假原因" type="string" expression="${leave.reason}" writable="false"></activiti:formProperty>
+ <activiti:formProperty id="leaveType" name="请假类型" type="string" expression="${leave.leaveType}" writable="false"></activiti:formProperty>
+ <activiti:formProperty id="startTime" name="请假开始日期" type="date" expression="${leave.startTime}" datePattern="yyyy-MM-dd" writable="false"></activiti:formProperty>
+ <activiti:formProperty id="endTime" name="请假结束日期" type="date" expression="${leave.endTime}" datePattern="yyyy-MM-dd" writable="false"></activiti:formProperty>
+ <activiti:formProperty id="reason" name="请假原因" type="string" expression="${leave.reason}" writable="false"></activiti:formProperty>
<activiti:formProperty id="reApply" name="重新申请" type="enum" required="true">
<activiti:value id="true" name="重新申请"></activiti:value>
<activiti:value id="false" name="取消申请"></activiti:value>
@@ -46,10 +47,10 @@
</userTask>
<userTask id="hrAudit" name="人事审批" activiti:candidateGroups="hr">
<extensionElements>
- <activiti:formProperty id="leaveType" name="请假类型" expression="${leave.leaveType}" type="string" writable="false"></activiti:formProperty>
- <activiti:formProperty id="startTime" name="请假开始日期" type="date" expression="${leave.startTime}" datePattern="yyyy-MM-dd" writable="false"></activiti:formProperty>
- <activiti:formProperty id="endTime" name="请假结束日期" type="date" expression="${leave.endTime}" datePattern="yyyy-MM-dd" writable="false"></activiti:formProperty>
- <activiti:formProperty id="reason" name="请假原因" type="string" expression="${leave.reason}" writable="false"></activiti:formProperty>
+ <activiti:formProperty id="leaveType" name="请假类型" type="string" expression="${leave.leaveType}" writable="false"></activiti:formProperty>
+ <activiti:formProperty id="startTime" name="请假开始日期" type="date" expression="${leave.startTime}" datePattern="yyyy-MM-dd" writable="false"></activiti:formProperty>
+ <activiti:formProperty id="endTime" name="请假结束日期" type="date" expression="${leave.endTime}" datePattern="yyyy-MM-dd" writable="false"></activiti:formProperty>
+ <activiti:formProperty id="reason" name="请假原因" type="string" expression="${leave.reason}" writable="false"></activiti:formProperty>
<activiti:formProperty id="hrApproved" name="审批意见" type="enum" required="true">
<activiti:value id="true" name="同意"></activiti:value>
<activiti:value id="false" name="拒绝"></activiti:value>
@@ -59,10 +60,10 @@
<exclusiveGateway id="exclusivegateway6" name="Exclusive Gateway"></exclusiveGateway>
<userTask id="reportBack" name="销假" activiti:assignee="${leave.userId}">
<extensionElements>
- <activiti:formProperty id="leaveType" name="请假类型" expression="${leave.leaveType}" type="string" writable="false"></activiti:formProperty>
- <activiti:formProperty id="startTime" name="请假开始日期" type="date" expression="${leave.startTime}" datePattern="yyyy-MM-dd" writable="false"></activiti:formProperty>
- <activiti:formProperty id="endTime" name="请假结束日期" type="date" expression="${leave.endTime}" datePattern="yyyy-MM-dd" writable="false"></activiti:formProperty>
- <activiti:formProperty id="reason" name="请假原因" type="string" expression="${leave.reason}" writable="false"></activiti:formProperty>
+ <activiti:formProperty id="leaveType" name="请假类型" type="string" expression="${leave.leaveType}" writable="false"></activiti:formProperty>
+ <activiti:formProperty id="startTime" name="请假开始日期" type="date" expression="${leave.startTime}" datePattern="yyyy-MM-dd" writable="false"></activiti:formProperty>
+ <activiti:formProperty id="endTime" name="请假结束日期" type="date" expression="${leave.endTime}" datePattern="yyyy-MM-dd" writable="false"></activiti:formProperty>
+ <activiti:formProperty id="reason" name="请假原因" type="string" expression="${leave.reason}" writable="false"></activiti:formProperty>
<activiti:formProperty id="realityStartTime" name="(实际)请假开始日期" type="date" datePattern="yyyy-MM-dd" required="true"></activiti:formProperty>
<activiti:formProperty id="realityEndTime" name="(实际)请假结束日期" type="date" datePattern="yyyy-MM-dd" required="true"></activiti:formProperty>
<activiti:formProperty id="reportBackDate" name="销假日期" type="date" default="${leave.endTime}" datePattern="yyyy-MM-dd" required="true"></activiti:formProperty>
@@ -85,8 +86,8 @@
<sequenceFlow id="flow8" name="销假" sourceRef="reportBack" targetRef="endevent1">
<extensionElements>
<activiti:executionListener event="take" expression="${leave.setReportBackDate(reportBackDate)}"></activiti:executionListener>
- <activiti:executionListener event="take" expression="${leave.setRealityStartTime(realityStartTime)}"></activiti:executionListener>
- <activiti:executionListener event="take" expression="${leave.setRealityEndTime(realityEndTime)}"></activiti:executionListener>
+ <activiti:executionListener event="take" expression="${leave.setRealityStartTime(realityStartTime)}"></activiti:executionListener>
+ <activiti:executionListener event="take" expression="${leave.setRealityEndTime(realityEndTime)}"></activiti:executionListener>
</extensionElements>
</sequenceFlow>
<sequenceFlow id="flow9" name="拒绝" sourceRef="exclusivegateway6" targetRef="modifyApply">
@@ -151,14 +152,14 @@
<omgdi:waypoint x="270.0" y="67.0"></omgdi:waypoint>
<omgdi:waypoint x="270.0" y="108.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
- <omgdc:Bounds height="11.0" width="22.0" x="10.0" y="0.0"></omgdc:Bounds>
+ <omgdc:Bounds height="11.0" width="22.0" x="280.0" y="67.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
<omgdi:waypoint x="290.0" y="47.0"></omgdi:waypoint>
<omgdi:waypoint x="358.0" y="47.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
- <omgdc:Bounds height="11.0" width="22.0" x="-24.0" y="-17.0"></omgdc:Bounds>
+ <omgdc:Bounds height="11.0" width="22.0" x="300.0" y="30.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
@@ -169,30 +170,30 @@
<omgdi:waypoint x="535.0" y="47.0"></omgdi:waypoint>
<omgdi:waypoint x="590.0" y="47.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
- <omgdc:Bounds height="11.0" width="22.0" x="-27.0" y="-17.0"></omgdc:Bounds>
+ <omgdc:Bounds height="11.0" width="22.0" x="534.0" y="30.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8">
<omgdi:waypoint x="642.0" y="75.0"></omgdi:waypoint>
<omgdi:waypoint x="642.0" y="223.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
- <omgdc:Bounds height="11.0" width="22.0" x="10.0" y="0.0"></omgdc:Bounds>
+ <omgdc:Bounds height="11.0" width="22.0" x="652.0" y="75.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow9" id="BPMNEdge_flow9">
<omgdi:waypoint x="515.0" y="67.0"></omgdi:waypoint>
<omgdi:waypoint x="514.0" y="135.0"></omgdi:waypoint>
<omgdi:waypoint x="323.0" y="135.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
- <omgdc:Bounds height="11.0" width="22.0" x="10.0" y="0.0"></omgdc:Bounds>
+ <omgdc:Bounds height="11.0" width="22.0" x="525.0" y="67.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow10" id="BPMNEdge_flow10">
<omgdi:waypoint x="250.0" y="240.0"></omgdi:waypoint>
<omgdi:waypoint x="142.0" y="239.0"></omgdi:waypoint>
<omgdi:waypoint x="142.0" y="75.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
- <omgdc:Bounds height="11.0" width="44.0" x="10.0" y="0.0"></omgdc:Bounds>
+ <omgdc:Bounds height="11.0" width="44.0" x="186.0" y="221.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow11" id="BPMNEdge_flow11">
@@ -203,7 +204,7 @@
<omgdi:waypoint x="290.0" y="240.0"></omgdi:waypoint>
<omgdi:waypoint x="625.0" y="240.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
- <omgdc:Bounds height="11.0" width="44.0" x="10.0" y="0.0"></omgdc:Bounds>
+ <omgdc:Bounds height="11.0" width="44.0" x="300.0" y="223.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="association1" id="BPMNEdge_association1">
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -134,7 +134,6 @@
<td>
<div>运行SQL脚本文件:</div>
<ul>
- <li><code>resources/sql/h2/schema.sql</code></li>
<li><code>resources/sql/h2/data.sql</code></li>
</ul>
</td>
@@ -79,7 +79,7 @@ PropertyFileUtil.init();
<div id="bottomPane" class="ui-layout-south ui-widget ui-widget-content">
<div class="footer ui-state-default">
<a href="http://www.kafeitu.me" target="_blank">咖啡兔</a>
- <span class="copyright">©2008-2013</span>
+ <span class="copyright">©2008-2014</span>
<span class="version">Version:${prop['system.version']}</span>
</div>
</div>

0 comments on commit db0efd7

Please sign in to comment.