package fine;
|
|
import java.io.File;
|
import java.math.BigDecimal;
|
import java.util.ArrayList;
|
import java.util.List;
|
import org.activiti.engine.task.Task;
|
|
import process.service.IServiceCaller;
|
import process.service.IdentityService;
|
import process.service.TaskService;
|
import process.service.HistoryService;
|
import foundation.callable.Callable;
|
import foundation.config.Configer;
|
import foundation.data.Entity;
|
import foundation.data.EntitySet;
|
import foundation.data.Variant;
|
import foundation.file.download.ClientAction;
|
import foundation.file.download.HttpResponseWriter;
|
import foundation.persist.DataHandler;
|
import foundation.persist.sql.NamedSQL;
|
import foundation.persist.sql.SQLRunner;
|
|
public class BusinessConsole extends Callable implements IServiceCaller {
|
|
private TaskService taskService;
|
private HistoryService historyService;
|
private IdentityService identityService;
|
|
|
public BusinessConsole() throws Exception {
|
taskService = new TaskService(this);
|
historyService = new HistoryService(this);
|
identityService = new IdentityService(this);
|
}
|
|
@Override
|
protected void publishMethod() {
|
addMethod("getTodoAgreement");
|
addMethod("newAgreementVersion");
|
addMethod("approveAgreement");
|
addMethod("preview");
|
addMethod("getMyHistotyApprove");
|
addMethod("startProcess");
|
}
|
|
protected void startProcess() throws Exception {
|
Variant dataId = getParameter("id");
|
// type = tablename e.g. agreement
|
String tableName = getParameter("type").getStringValue();
|
Entity entity = DataHandler.getLine(tableName, dataId.getStringValue());
|
String typecode = entity.getString("typecode");
|
dataPool.addParameter("typecode", typecode);
|
|
if (tableName.equalsIgnoreCase("feeslit")) {
|
//1. update salesflow_month qty
|
EntitySet dataSet = DataHandler.getDataSet(tableName+"detail", "parentid="+dataId.getStringValue());
|
for (Entity feesLitDetail: dataSet) {
|
String flowId = feesLitDetail.getString("flowid");
|
BigDecimal qty = feesLitDetail.getBigDecimal("qty");
|
Entity salesflowMonth = DataHandler.getLine("salesflow_month", flowId);
|
BigDecimal qty_examine = salesflowMonth.getBigDecimal("qty_examine");
|
BigDecimal qty_available = qty_examine.subtract(qty) ;
|
salesflowMonth.set("qty_book", qty);
|
salesflowMonth.set("qty_available", qty_available);
|
DataHandler.updateLine(salesflowMonth);
|
}
|
|
//2. calculate rebate
|
calculateRebate();
|
}
|
String processInstanceId = identityService.startProcess();
|
|
NamedSQL updateNamedSQL = NamedSQL.getInstance("updateById");
|
String fieldNameValues = "workflowId = '" + processInstanceId + "',statuscode='commit'";
|
updateNamedSQL.setParam("tablename", tableName);
|
updateNamedSQL.setParam("fieldNameId", "id");
|
updateNamedSQL.setParam("id", "'"+dataId+"'");
|
updateNamedSQL.setParam("fieldNameValues", fieldNameValues);
|
updateNamedSQL.exec();
|
}
|
|
|
|
protected void getMyHistotyApprove() throws Exception {
|
|
ArrayList<Entity> result = new ArrayList<Entity>();
|
EntitySet entitySet = DataHandler.getDataSet("agreement", "1=1");
|
List<String> myHistotyApprove = historyService.getMyHistotyApprove();
|
|
for (Entity entity : entitySet) {
|
String id = entity.getString("workflowid");
|
if (myHistotyApprove.contains(id)) {
|
result.add(entity);
|
}
|
}
|
resultPool.addValue(result);
|
}
|
|
protected void getTodoAgreement() throws Exception {
|
|
ArrayList<Entity> result = new ArrayList<Entity>();
|
String filter = getParameter("filter").getStringValue();
|
EntitySet entitySet = DataHandler.getDataSet("agreement", filter);
|
List<String> todoTaskId = taskService.getTodoTask();
|
|
for (Entity entity : entitySet) {
|
String id = entity.getString("id");
|
if (todoTaskId.contains(id)) {
|
result.add(entity);
|
}
|
}
|
resultPool.addValue(result);
|
}
|
|
protected void newAgreementVersion() throws Exception {
|
identityService.startProcess();
|
}
|
|
protected void approveAgreement() throws Exception {
|
Variant dataId = getParameter("id");
|
Variant isReset = getParameter("isReset");
|
String tableName = getParameter("type").getStringValue();
|
|
|
//1.claim
|
String taskid = taskService.claimTask();
|
if (taskid == null) {
|
return;
|
}
|
|
dataPool.addParameter("taskid", taskid);
|
|
//2.complete
|
boolean success = taskService.completeTask();
|
if (!success) {
|
return;
|
}
|
|
if (isReset.getBooleanValue()) {
|
NamedSQL namedSQL = NamedSQL.getInstance("updateTableStatusCodeById");
|
namedSQL.setParam("statuscode", "commit");
|
namedSQL.setParam("id", dataId.getStringValue());
|
namedSQL.setParam("tablename", tableName);
|
namedSQL.exec();
|
}
|
|
Task task = taskService.geTask();
|
if(task != null && task.getTaskDefinitionKey().equalsIgnoreCase("modifyApply")) {
|
NamedSQL namedSQL = NamedSQL.getInstance("updateTableStatusCodeById");
|
namedSQL.setParam("id", dataId.getStringValue());
|
namedSQL.setParam("tablename", tableName);
|
namedSQL.setParam("statuscode", "isReset");
|
namedSQL.exec();
|
}
|
|
|
//3.update status
|
if (historyService.isTaskFinished()) {
|
NamedSQL namedSQL = NamedSQL.getInstance("updateTableStatusCodeById");
|
namedSQL.setParam("id", dataId.getStringValue());
|
namedSQL.setParam("tablename", tableName);
|
if (getParameter("passFlag").getStringValue().equalsIgnoreCase("false")) {
|
namedSQL.setParam("statuscode", "close");
|
}else {
|
namedSQL.setParam("statuscode", "open");
|
}
|
namedSQL.exec();
|
}
|
|
resultPool.success();
|
}
|
|
protected void preview() throws Exception {
|
Variant code = dataPool.getParameter("code");
|
|
NamedSQL namedSQL = NamedSQL.getInstance("getApplicationTemplatePath");
|
namedSQL.setParam("code", code.getStringValue());
|
String path = SQLRunner.getString(namedSQL);
|
String root = Configer.getParam("applicationTemplateRoot");
|
|
File file = new File(root, path);
|
|
if (!file.exists()) {
|
resultPool.error("file not exists: " + file);
|
return;
|
}
|
|
HttpResponseWriter writer = new HttpResponseWriter(response);
|
writer.write(file, ClientAction.AsPDF);
|
}
|
|
@Override
|
public void error(String error) {
|
resultPool.error(error);
|
}
|
|
@Override
|
public Variant getParameter(String name) {
|
return dataPool.getParameter(name);
|
}
|
|
private void calculateRebate() {
|
|
}
|
|
}
|