|
@@ -1,14 +1,16 @@
|
|
package org.hsweb.web.service.impl.form;
|
|
package org.hsweb.web.service.impl.form;
|
|
|
|
|
|
-import org.hsweb.web.bean.common.PagerResult;
|
|
|
|
-import org.hsweb.web.bean.common.QueryParam;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import org.hsweb.web.bean.common.*;
|
|
import org.hsweb.web.bean.po.form.Form;
|
|
import org.hsweb.web.bean.po.form.Form;
|
|
|
|
+import org.hsweb.web.bean.po.history.History;
|
|
import org.hsweb.web.service.form.DynamicFormService;
|
|
import org.hsweb.web.service.form.DynamicFormService;
|
|
import org.hsweb.web.service.form.FormService;
|
|
import org.hsweb.web.service.form.FormService;
|
|
|
|
+import org.hsweb.web.service.history.HistoryService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
-import org.webbuilder.sql.DataBase;
|
|
|
|
-import org.webbuilder.sql.TableMetaData;
|
|
|
|
|
|
+import org.springframework.util.Assert;
|
|
|
|
+import org.webbuilder.sql.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -33,19 +35,27 @@ public class DynamicFormServiceImpl implements DynamicFormService {
|
|
@Resource
|
|
@Resource
|
|
protected FormService formService;
|
|
protected FormService formService;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ protected HistoryService historyService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void deploy(Form form) throws Exception {
|
|
public void deploy(Form form) throws Exception {
|
|
Lock writeLock = lock.writeLock();
|
|
Lock writeLock = lock.writeLock();
|
|
try {
|
|
try {
|
|
writeLock.lock();
|
|
writeLock.lock();
|
|
TableMetaData metaData = formParser.parse(form);
|
|
TableMetaData metaData = formParser.parse(form);
|
|
- List<Form> oldList = formService.select(new QueryParam().where("name", form.getName()).where("version", form.getVersion() - 1));
|
|
|
|
- Form old = null;
|
|
|
|
- if (oldList.size() > 0) old = oldList.get(0);
|
|
|
|
- if (old != null)
|
|
|
|
- dataBase.updateTable(metaData);
|
|
|
|
- else
|
|
|
|
|
|
+ History history = historyService.selectLastHistoryByType("form.deploy." + form.getName());
|
|
|
|
+ //首次部署
|
|
|
|
+ if (history == null) {
|
|
dataBase.createTable(metaData);
|
|
dataBase.createTable(metaData);
|
|
|
|
+ } else {
|
|
|
|
+ Form lastDeploy = JSON.parseObject(history.getChange_after(), Form.class);
|
|
|
|
+ TableMetaData lastDeployMetaData = formParser.parse(lastDeploy);
|
|
|
|
+ //向上发布
|
|
|
|
+ dataBase.updateTable(lastDeployMetaData);//先放入旧的结构
|
|
|
|
+ //更新结构
|
|
|
|
+ dataBase.alterTable(metaData);
|
|
|
|
+ }
|
|
} finally {
|
|
} finally {
|
|
writeLock.unlock();
|
|
writeLock.unlock();
|
|
}
|
|
}
|
|
@@ -56,53 +66,167 @@ public class DynamicFormServiceImpl implements DynamicFormService {
|
|
Lock writeLock = lock.writeLock();
|
|
Lock writeLock = lock.writeLock();
|
|
try {
|
|
try {
|
|
writeLock.lock();
|
|
writeLock.lock();
|
|
|
|
+ dataBase.removeTable(form.getName());
|
|
} finally {
|
|
} finally {
|
|
writeLock.unlock();
|
|
writeLock.unlock();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public Table getTableByName(String name) throws Exception {
|
|
|
|
+ Table table = dataBase.getTable(name.toUpperCase());
|
|
|
|
+ if (table == null)
|
|
|
|
+ table = dataBase.getTable(name.toLowerCase());
|
|
|
|
+ Assert.notNull(table, "表单[" + name + "]不存在");
|
|
|
|
+ return table;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public <T> PagerResult<T> selectPager(String name, QueryParam param) throws Exception {
|
|
public <T> PagerResult<T> selectPager(String name, QueryParam param) throws Exception {
|
|
Lock readLock = lock.readLock();
|
|
Lock readLock = lock.readLock();
|
|
|
|
+ PagerResult<T> result = new PagerResult<>();
|
|
try {
|
|
try {
|
|
readLock.lock();
|
|
readLock.lock();
|
|
- System.out.println("执行");
|
|
|
|
- Thread.sleep(1000);
|
|
|
|
|
|
+ Table table = getTableByName(name);
|
|
|
|
+ Query query = table.createQuery();
|
|
|
|
+ QueryParamProxy proxy = QueryParamProxy.build(param);
|
|
|
|
+ int total = query.total(proxy);
|
|
|
|
+ result.setTotal(total);
|
|
|
|
+ param.rePaging(total);
|
|
|
|
+ proxy = QueryParamProxy.build(param);
|
|
|
|
+ result.setData(query.list(proxy));
|
|
} finally {
|
|
} finally {
|
|
readLock.unlock();
|
|
readLock.unlock();
|
|
}
|
|
}
|
|
- return null;
|
|
|
|
|
|
+ return result;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public <T> List<T> select(String name, QueryParam param) throws Exception {
|
|
public <T> List<T> select(String name, QueryParam param) throws Exception {
|
|
- return null;
|
|
|
|
|
|
+ Lock readLock = lock.readLock();
|
|
|
|
+ try {
|
|
|
|
+ readLock.lock();
|
|
|
|
+ Table table = getTableByName(name);
|
|
|
|
+ Query query = table.createQuery();
|
|
|
|
+ param.setPaging(false);
|
|
|
|
+ QueryParamProxy proxy = QueryParamProxy.build(param);
|
|
|
|
+ return query.list(proxy);
|
|
|
|
+ } finally {
|
|
|
|
+ readLock.unlock();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public int total(String name, QueryParam param) throws Exception {
|
|
public int total(String name, QueryParam param) throws Exception {
|
|
- return 0;
|
|
|
|
|
|
+ Lock readLock = lock.readLock();
|
|
|
|
+ try {
|
|
|
|
+ readLock.lock();
|
|
|
|
+ Table table = getTableByName(name);
|
|
|
|
+ Query query = table.createQuery();
|
|
|
|
+ param.setPaging(false);
|
|
|
|
+ QueryParamProxy proxy = QueryParamProxy.build(param);
|
|
|
|
+ return query.total(proxy);
|
|
|
|
+ } finally {
|
|
|
|
+ readLock.unlock();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public int insert(String name, Map<String, Object> data) throws Exception {
|
|
|
|
- return 0;
|
|
|
|
|
|
+ public int insert(String name, InsertParam<Map<String, Object>> param) throws Exception {
|
|
|
|
+ Lock readLock = lock.readLock();
|
|
|
|
+ try {
|
|
|
|
+ readLock.lock();
|
|
|
|
+ Table table = getTableByName(name);
|
|
|
|
+ Insert insert = table.createInsert();
|
|
|
|
+ boolean success = insert.insert(InsertParamProxy.build(param));
|
|
|
|
+ return success ? 1 : 0;
|
|
|
|
+ } finally {
|
|
|
|
+ readLock.unlock();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public int delete(String name, Map<String, Object> data) throws Exception {
|
|
|
|
- return 0;
|
|
|
|
|
|
+ public int delete(String name, DeleteParam where) throws Exception {
|
|
|
|
+ Lock readLock = lock.readLock();
|
|
|
|
+ try {
|
|
|
|
+ readLock.lock();
|
|
|
|
+ Table table = getTableByName(name);
|
|
|
|
+ Delete delete = table.createDelete();
|
|
|
|
+ return delete.delete(DeleteParamProxy.build(where));
|
|
|
|
+ } finally {
|
|
|
|
+ readLock.unlock();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public int update(String name, Map<String, Object> data) throws Exception {
|
|
|
|
- return 0;
|
|
|
|
|
|
+ public int update(String name, UpdateParam<Map<String, Object>> param) throws Exception {
|
|
|
|
+ Lock readLock = lock.readLock();
|
|
|
|
+ try {
|
|
|
|
+ readLock.lock();
|
|
|
|
+ Table table = getTableByName(name);
|
|
|
|
+ Update update = table.createUpdate();
|
|
|
|
+ UpdateParamProxy paramProxy = UpdateParamProxy.build(param);
|
|
|
|
+ return update.update(paramProxy);
|
|
|
|
+ } finally {
|
|
|
|
+ readLock.unlock();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public <T> T selectByPk(String name, Object pk) throws Exception {
|
|
public <T> T selectByPk(String name, Object pk) throws Exception {
|
|
- return null;
|
|
|
|
|
|
+ Lock readLock = lock.readLock();
|
|
|
|
+ try {
|
|
|
|
+ readLock.lock();
|
|
|
|
+ Table table = getTableByName(name);
|
|
|
|
+ Object pk_name = table.getMetaData().attr("primaryKey");
|
|
|
|
+ if (pk_name == null) {
|
|
|
|
+ pk_name = "u_id";
|
|
|
|
+ }
|
|
|
|
+ Query query = table.createQuery();
|
|
|
|
+ QueryParamProxy proxy = new QueryParamProxy();
|
|
|
|
+ proxy.where(String.valueOf(pk_name), pk);
|
|
|
|
+ return query.single(proxy);
|
|
|
|
+ } finally {
|
|
|
|
+ readLock.unlock();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static class QueryParamProxy extends org.webbuilder.sql.param.query.QueryParam {
|
|
|
|
+ public static QueryParamProxy build(QueryParam param) {
|
|
|
|
+ QueryParamProxy proxy = new QueryParamProxy();
|
|
|
|
+ proxy.where(param.getTerm());
|
|
|
|
+ proxy.exclude(param.getExcludes());
|
|
|
|
+ proxy.include(param.getIncludes());
|
|
|
|
+ proxy.orderBy("desc".equals(param.getSortOrder()), param.getSortField());
|
|
|
|
+ proxy.doPaging(param.getPageIndex(), param.getPageSize());
|
|
|
|
+ proxy.setPaging(param.isPaging());
|
|
|
|
+ return proxy;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static class UpdateParamProxy extends org.webbuilder.sql.param.update.UpdateParam {
|
|
|
|
+ public static UpdateParamProxy build(UpdateParam<Map<String, Object>> param) {
|
|
|
|
+ UpdateParamProxy proxy = new UpdateParamProxy();
|
|
|
|
+ proxy.where(param.getTerm());
|
|
|
|
+ proxy.exclude(param.getExcludes());
|
|
|
|
+ proxy.include(param.getIncludes());
|
|
|
|
+ proxy.set(param.getData());
|
|
|
|
+ return proxy;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static class InsertParamProxy extends org.webbuilder.sql.param.insert.InsertParam {
|
|
|
|
+ public static InsertParamProxy build(InsertParam<Map<String, Object>> param) {
|
|
|
|
+ InsertParamProxy proxy = new InsertParamProxy();
|
|
|
|
+ proxy.values(param.getData());
|
|
|
|
+ return proxy;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ public static class DeleteParamProxy extends org.webbuilder.sql.param.delete.DeleteParam {
|
|
|
|
+ public static DeleteParamProxy build(DeleteParam param) {
|
|
|
|
+ DeleteParamProxy proxy = new DeleteParamProxy();
|
|
|
|
+ proxy.where(param.getTerm());
|
|
|
|
+ return proxy;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|