跟著湯陽光同志做一個OA專案(十四):審批流轉約定與總流程和一些重要程式碼及最終的實體設計
阿新 • • 發佈:2019-02-18
@Controller
@Scope("prototype")
public class FlowAction extends BaseAction {
private File upload; // 上傳的檔案
private Long applicationTemplateId;
private Long applicationId;
private String taskId;
private String comment;
private boolean approval;
private String outcome;
private String applicationStatus;
// ================================== 申請人有關
/** 起草申請(模板列表) */
public String templateList() throws Exception {
List<ApplicationTemplate> applicationTemplateList = applicationTemplateService.findAll();
ActionContext.getContext().put("applicationTemplateList", applicationTemplateList);
return "applicationTemplateList";
}
/** 提交申請頁面 */
public String submitUI() throws Exception {
return "submitUI";
}
/** 提交申請 */
public String submit() throws Exception {
// 封裝申請資訊
Application application = new Application();
application.setApplicant(getCurrentUser()); // 申請人,當前使用者
application.setPath(saveUploadFile(upload)); // 儲存上傳的檔案並設定路徑
application.setApplicationTemplate(applicationTemplateService.getById(applicationTemplateId));
// 呼叫業務方法(儲存申請資訊,並啟動流程開始流轉)
applicationService.submit(application);
return "toMyApplicationList"; // 成功後轉到"我的申請查詢"
}
/** 我的申請查詢 */
public String myApplicationList() throws Exception {
// 構建查詢條件並準備分頁資訊
new QueryHelper(Application.class, "a")//
.addCondition("a.applicant=?", getCurrentUser())//
.addCondition(applicationTemplateId != null, "a.applicationTemplate.id=?", applicationTemplateId)//
.addCondition(StringUtils.isNotBlank(applicationStatus), "a.status=?", applicationStatus)//
.addOrderProperty("a.applyTime", false)
.preparePageBean(applicationService, pageNum, pageSize);
// 準備資料
List<ApplicationTemplate> applicationTemplateList = applicationTemplateService.findAll();
ActionContext.getContext().put("applicationTemplateList", applicationTemplateList);
return "myApplicationList";
}
// ================================== 審批人有關
/** 待我審批(我的任務列表) */
public String myTaskList() throws Exception {
List<TaskView> taskViewList = applicationService.getMyTaskViewList(getCurrentUser());
ActionContext.getContext().put("taskViewList", taskViewList);
return "myTaskList";
}
/** 審批處理頁面 */
public String approveUI() throws Exception {
Set<String> outcomes = applicationService.getOutcomesByTaskId(taskId);
ActionContext.getContext().put("outcomes", outcomes);
return "approveUI";
}
/** 審批處理 */
public String approve() throws Exception {
// 封裝
ApproveInfo approveInfo = new ApproveInfo();
approveInfo.setComment(comment);
approveInfo.setApproval(approval);
approveInfo.setApplication(applicationService.getById(applicationId));
approveInfo.setApprover(getCurrentUser()); // 審批人,當前登入使用者
approveInfo.setApproveTime(new Date()); // 當前時間
// 呼叫用業務方法(儲存本次審批資訊,並辦理完任務,並維護申請的狀態)
applicationService.approve(approveInfo, taskId, outcome);
return "toMyTaskList"; // 成功後轉到待我審批頁面
}
/** 檢視流轉記錄 */
public String approveHistory() throws Exception {
Application application = applicationService.getById(applicationId);
ActionContext.getContext().put("approveInfos", application.getApproveInfos());
return "approveHistory";
}
// --------
public File getUpload() {
return upload;
}
public Long getApplicationTemplateId() {
return applicationTemplateId;
}
public void setApplicationTemplateId(Long applicationTemplateId) {
this.applicationTemplateId = applicationTemplateId;
}
public void setUpload(File upload) {
this.upload = upload;
}
public Long getApplicationId() {
return applicationId;
}
public void setApplicationId(Long applicationId) {
this.applicationId = applicationId;
}
public String getTaskId() {
return taskId;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public boolean isApproval() {
return approval;
}
public void setApproval(boolean approval) {
this.approval = approval;
}
public String getOutcome() {
return outcome;
}
public void setOutcome(String outcome) {
this.outcome = outcome;
}
public String getApplicationStatus() {
return applicationStatus;
}
public void setApplicationStatus(String applicationStatus) {
this.applicationStatus = applicationStatus;
}
}
@Scope("prototype")
public class FlowAction extends BaseAction {
private File upload; // 上傳的檔案
private Long applicationTemplateId;
private Long applicationId;
private String taskId;
private String comment;
private boolean approval;
private String outcome;
private String applicationStatus;
// ================================== 申請人有關
/** 起草申請(模板列表) */
public String templateList() throws Exception {
List<ApplicationTemplate> applicationTemplateList = applicationTemplateService.findAll();
ActionContext.getContext().put("applicationTemplateList", applicationTemplateList);
return "applicationTemplateList";
}
/** 提交申請頁面 */
public String submitUI() throws Exception {
return "submitUI";
}
/** 提交申請 */
public String submit() throws Exception {
// 封裝申請資訊
Application application = new Application();
application.setApplicant(getCurrentUser()); // 申請人,當前使用者
application.setPath(saveUploadFile(upload)); // 儲存上傳的檔案並設定路徑
application.setApplicationTemplate(applicationTemplateService.getById(applicationTemplateId));
// 呼叫業務方法(儲存申請資訊,並啟動流程開始流轉)
applicationService.submit(application);
return "toMyApplicationList"; // 成功後轉到"我的申請查詢"
}
/** 我的申請查詢 */
public String myApplicationList() throws Exception {
// 構建查詢條件並準備分頁資訊
new QueryHelper(Application.class, "a")//
.addCondition("a.applicant=?", getCurrentUser())//
.addCondition(applicationTemplateId != null, "a.applicationTemplate.id=?", applicationTemplateId)//
.addCondition(StringUtils.isNotBlank(applicationStatus), "a.status=?", applicationStatus)//
.addOrderProperty("a.applyTime", false)
.preparePageBean(applicationService, pageNum, pageSize);
// 準備資料
List<ApplicationTemplate> applicationTemplateList = applicationTemplateService.findAll();
ActionContext.getContext().put("applicationTemplateList", applicationTemplateList);
return "myApplicationList";
}
// ================================== 審批人有關
/** 待我審批(我的任務列表) */
public String myTaskList() throws Exception {
List<TaskView> taskViewList = applicationService.getMyTaskViewList(getCurrentUser());
ActionContext.getContext().put("taskViewList", taskViewList);
return "myTaskList";
}
/** 審批處理頁面 */
public String approveUI() throws Exception {
Set<String> outcomes = applicationService.getOutcomesByTaskId(taskId);
ActionContext.getContext().put("outcomes", outcomes);
return "approveUI";
}
/** 審批處理 */
public String approve() throws Exception {
// 封裝
ApproveInfo approveInfo = new ApproveInfo();
approveInfo.setComment(comment);
approveInfo.setApproval(approval);
approveInfo.setApplication(applicationService.getById(applicationId));
approveInfo.setApprover(getCurrentUser()); // 審批人,當前登入使用者
approveInfo.setApproveTime(new Date()); // 當前時間
// 呼叫用業務方法(儲存本次審批資訊,並辦理完任務,並維護申請的狀態)
applicationService.approve(approveInfo, taskId, outcome);
return "toMyTaskList"; // 成功後轉到待我審批頁面
}
/** 檢視流轉記錄 */
public String approveHistory() throws Exception {
Application application = applicationService.getById(applicationId);
ActionContext.getContext().put("approveInfos", application.getApproveInfos());
return "approveHistory";
}
// --------
public File getUpload() {
return upload;
}
public Long getApplicationTemplateId() {
return applicationTemplateId;
}
public void setApplicationTemplateId(Long applicationTemplateId) {
this.applicationTemplateId = applicationTemplateId;
}
public void setUpload(File upload) {
this.upload = upload;
}
public Long getApplicationId() {
return applicationId;
}
public void setApplicationId(Long applicationId) {
this.applicationId = applicationId;
}
public String getTaskId() {
return taskId;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public boolean isApproval() {
return approval;
}
public void setApproval(boolean approval) {
this.approval = approval;
}
public String getOutcome() {
return outcome;
}
public void setOutcome(String outcome) {
this.outcome = outcome;
}
public String getApplicationStatus() {
return applicationStatus;
}
public void setApplicationStatus(String applicationStatus) {
this.applicationStatus = applicationStatus;
}
}