You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
134 lines
6.3 KiB
134 lines
6.3 KiB
2 years ago
|
package com.fr.plugin.db.procedure.stableKey;
|
||
|
|
||
|
import com.fr.json.JSONObject;
|
||
|
import com.fr.log.FineLoggerFactory;
|
||
|
import com.fr.plugin.db.procedure.entity.TPDBAccessProvider;
|
||
|
import com.fr.plugin.db.procedure.entity.TemplateProcedureDAO;
|
||
|
import com.fr.plugin.db.procedure.entity.TemplateProcedureEntity;
|
||
|
import com.fr.stable.db.action.DBAction;
|
||
|
import com.fr.stable.db.dao.DAOContext;
|
||
|
|
||
|
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.List;
|
||
|
|
||
|
public class DBAcessActionImpl implements IDBAcessAction{
|
||
|
@Override
|
||
|
public String operate(String jsonData) {
|
||
|
FineLoggerFactory.getLogger().info("远程收到:"+jsonData);
|
||
|
JSONObject result = new JSONObject();
|
||
|
try {
|
||
|
result.put("result",new ArrayList());
|
||
|
|
||
|
JSONObject jsonObject = new JSONObject(jsonData);
|
||
|
String action = jsonObject.get("action").toString();
|
||
|
if(action.equals("getAll")){
|
||
|
List<TemplateProcedureEntity> entities = null;
|
||
|
try {
|
||
|
entities = TPDBAccessProvider.dbAccessor.runQueryAction(new DBAction<List<TemplateProcedureEntity>>() {
|
||
|
@Override
|
||
|
public List<TemplateProcedureEntity> run(DAOContext daoContext) throws Exception {
|
||
|
return daoContext.getDAO(TemplateProcedureDAO.class).getAll();
|
||
|
}
|
||
|
});
|
||
|
} catch (Exception e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
|
||
|
result.put("result",entities);
|
||
|
}
|
||
|
if("getEntityByprocedureId".equals(action)){
|
||
|
String procedureId = jsonObject.get("procedureId").toString();
|
||
|
FineLoggerFactory.getLogger().info("远程根据procedureId查询实体");
|
||
|
try {
|
||
|
TemplateProcedureEntity entity = TPDBAccessProvider.dbAccessor.runQueryAction(new DBAction<TemplateProcedureEntity>() {
|
||
|
@Override
|
||
|
public TemplateProcedureEntity run(DAOContext daoContext) throws Exception {
|
||
|
return daoContext.getDAO(TemplateProcedureDAO.class).getEntityByprocedureId(procedureId);
|
||
|
}
|
||
|
});
|
||
|
List<TemplateProcedureEntity> entities = new ArrayList<>();
|
||
|
if(entity != null){
|
||
|
entities.add(entity);
|
||
|
}
|
||
|
result.put("result",entity);
|
||
|
} catch (Exception e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
}
|
||
|
if("updateEntity".equals(action)){
|
||
|
TemplateProcedureEntity entity = new TemplateProcedureEntity();
|
||
|
entity.setId(jsonObject.get("id").toString());
|
||
|
entity.setConnectionId(jsonObject.get("connectionId").toString());
|
||
|
entity.setConnectionName(jsonObject.get("connectionName").toString());
|
||
|
entity.setProcedureName(jsonObject.get("procedureName").toString());
|
||
|
entity.setProcedureId(jsonObject.get("procedureId").toString());
|
||
|
entity.setReportPath(jsonObject.get("reportPath").toString());
|
||
|
try {
|
||
|
TPDBAccessProvider.dbAccessor.runDMLAction(new DBAction<TemplateProcedureEntity>() {
|
||
|
@Override
|
||
|
public TemplateProcedureEntity run(DAOContext daoContext) throws Exception {
|
||
|
daoContext.getDAO(TemplateProcedureDAO.class).updateEntity(entity);
|
||
|
return entity;
|
||
|
}
|
||
|
});
|
||
|
} catch (Exception e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
}
|
||
|
if("addEntity".equals(action)){
|
||
|
TemplateProcedureEntity entity = new TemplateProcedureEntity();
|
||
|
entity.setId(jsonObject.get("id").toString());
|
||
|
entity.setConnectionId(jsonObject.get("connectionId").toString());
|
||
|
entity.setConnectionName(jsonObject.get("connectionName").toString());
|
||
|
entity.setProcedureName(jsonObject.get("procedureName").toString());
|
||
|
entity.setProcedureId(jsonObject.get("procedureId").toString());
|
||
|
entity.setReportPath(jsonObject.get("reportPath").toString());
|
||
|
try {
|
||
|
TPDBAccessProvider.dbAccessor.runDMLAction(new DBAction<TemplateProcedureEntity>() {
|
||
|
@Override
|
||
|
public TemplateProcedureEntity run(DAOContext daoContext) throws Exception {
|
||
|
daoContext.getDAO(TemplateProcedureDAO.class).addEntity(entity);
|
||
|
FineLoggerFactory.getLogger().info("远程增加实体完成:"+entity.getId());
|
||
|
return entity;
|
||
|
}
|
||
|
});
|
||
|
} catch (Exception e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
}
|
||
|
if("removeAll".equals(action)){
|
||
|
try {
|
||
|
TPDBAccessProvider.dbAccessor.runDMLAction(new DBAction<TemplateProcedureEntity>() {
|
||
|
@Override
|
||
|
public TemplateProcedureEntity run(DAOContext daoContext) throws Exception {
|
||
|
daoContext.getDAO(TemplateProcedureDAO.class).removeAll();
|
||
|
return null;
|
||
|
}
|
||
|
});
|
||
|
} catch (Exception e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
}
|
||
|
if("removeById".equals(action)){
|
||
|
String id = jsonObject.get("id").toString();
|
||
|
try {
|
||
|
TPDBAccessProvider.dbAccessor.runDMLAction(new DBAction<TemplateProcedureEntity>() {
|
||
|
@Override
|
||
|
public TemplateProcedureEntity run(DAOContext daoContext) throws Exception {
|
||
|
daoContext.getDAO(TemplateProcedureDAO.class).removeById(id);
|
||
|
return null;
|
||
|
}
|
||
|
});
|
||
|
} catch (Exception e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
}
|
||
|
} catch (Exception e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
|
||
|
return result.toString();
|
||
|
}
|
||
|
}
|