【Activiti】從入門到放棄——專案實戰之辦理任務
阿新 • • 發佈:2018-12-07
前面,我們已經完成每個任務的動態表單實現,能看到任務詳情,接下來就要根據它是否符合條件進行任務辦理。
審批報備辦理者動態指定
1.寫一個類繼承TaskListener
public class ManagerSettingListener implements TaskListener{
@Autowired
private IEmployeeService employeeService;
}
2.把這個類繫結對應的任務節點
3.在這個類中實現設定辦理者的邏輯
public class ManagerSettingListener implements TaskListener { @Autowired private IEmployeeService employeeService; @Override public void notify(DelegateTask delegateTask) { //獲取審批人員 獲取營銷人員---部門----部門經理 String sellerNickName = delegateTask.getVariable("seller", String.class); System.out.println(sellerNickName); System.out.println(employeeService); //寫死"超級管理員"-超級管理員就可以獲取審批任務 delegateTask.setAssignee("超級管理員"); } }
注意:要配置spring對listener的註解掃描:
<!-- listener的註解掃描 -->
<context:component-scan base-package="cn.itsource.crm.listener"></context:component-scan>
流程辦理完成狀態修改
- 寫一個類繼承ExecutionListener
@Component public class EndListener implements ExecutionListener { @Autowired private ICustomerService customerService; }
2.繫結到結束節點
3.實現邏輯
@Component public class EndListener implements ExecutionListener{ @Autowired private ICustomerService customerService; @Override public void notify(DelegateExecution execution) throws Exception { //流程結束的時候修改status的狀態值: //通過流程變數獲取業務id Long businessObjId = execution.getVariable("businessObjId", Long.class); //查詢業務物件 Customer customer = customerService.get(businessObjId); //設定狀態值 customer.setStatus(2); //跟新資料庫 customerService.update(customer); } }