初始化

This commit is contained in:
2025-12-25 16:59:12 +08:00
commit 7bb6fbdeb5
9 changed files with 1459 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
package com.seeyon.utils.form;
public enum ClauseFactor {
EQ, //相等
GT, //大于
GE, //大于等于
LT, //小于
LE, //小于等于
NULL, //空
NOT_NULL, //非空
LIKE, //模糊
AND,
OR
;
public boolean isNullType() {
return this == NULL || this == NOT_NULL;
}
}

View File

@@ -0,0 +1,86 @@
package com.seeyon.utils.form;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.ctpenumnew.manager.EnumManager;
import com.seeyon.ctp.common.po.ctpenumnew.CtpEnumBean;
import com.seeyon.ctp.common.po.ctpenumnew.CtpEnumItem;
import com.seeyon.ctp.util.JDBCAgent;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
public class EnumMapUtils {
public static String getEnumItemValue(String rootPCode, String groupValue, String targetValue) {
if(targetValue == null || "null".equals(targetValue) || "".equals(targetValue)){
return "";
}
String queryIdSql = "SELECT ce.ID FROM ctp_enum ce inner join ctp_enum cei on ce.`PARENT_ID` = cei.ID where CEI.`PROGRAM_CODE` = ? and ce.`ENUMNAME` = ?";
Long enumId = null;
JDBCAgent agent = new JDBCAgent();
try {
agent.execute(queryIdSql, Arrays.asList(rootPCode,groupValue));
List<Map<String, Object>> list = (List<Map<String, Object>>) agent.resultSetToList();
if(list == null || list.size() == 0) {
return "";
}
Map map = list.get(0);
enumId = (Long)map.get("ID");
} catch (Exception e) {
return "";
}finally {
agent.close();
}
EnumManager enumManagerNew = (EnumManager) AppContext.getBean("enumManagerNew");
CtpEnumBean ctpEnumBean = enumManagerNew.getEnum(enumId);
if(ctpEnumBean == null) {
return "";
}
List<CtpEnumItem> ctpEnumItems = ctpEnumBean.getItems();
if(ctpEnumBean.getItems() == null) {
return "";
}
for (CtpEnumItem enumItem : ctpEnumItems) {
if(enumItem.getShowvalue().equals(targetValue)) {
return enumItem.getId() + "";
}
}
return "";
}
public static String getEnumItemValueByEnumId(String showValue,long enumId) {
EnumManager enumManagerNew = (EnumManager) AppContext.getBean("enumManagerNew");
CtpEnumBean ctpEnumBean = enumManagerNew.getEnum(enumId);
if(ctpEnumBean == null) {
return "";
}
List<CtpEnumItem> ctpEnumItems = ctpEnumBean.getItems();
if(ctpEnumBean.getItems() == null) {
return "";
}
for (CtpEnumItem enumItem : ctpEnumItems) {
if(enumItem.getShowvalue().equals(showValue)) {
return enumItem.getId() + "";
}
}
return "";
}
public static String getEnumItemValueByEnumIdAndEnumValue(String value,long enumId) {
EnumManager enumManagerNew = (EnumManager) AppContext.getBean("enumManagerNew");
CtpEnumBean ctpEnumBean = enumManagerNew.getEnum(enumId);
if(ctpEnumBean == null) {
return "";
}
List<CtpEnumItem> ctpEnumItems = ctpEnumBean.getItems();
if(ctpEnumBean.getItems() == null) {
return "";
}
for (CtpEnumItem enumItem : ctpEnumItems) {
if(enumItem.getValue().equals(value)) {
return enumItem.getId() + "";
}
}
return "";
}
}

View File

@@ -0,0 +1,24 @@
package com.seeyon.utils.form;
import java.util.List;
public class FormColumn {
private String id;
private List<FormFieldVo> vos;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public List<FormFieldVo> getVos() {
return vos;
}
public void setVos(List<FormFieldVo> vos) {
this.vos = vos;
}
}

View File

@@ -0,0 +1,629 @@
package com.seeyon.utils.form;
import com.alibaba.fastjson.JSONObject;
import com.seeyon.aicloud.common.JsonUtils;
import com.seeyon.cap4.form.api.FormApi4Cap4;
import com.seeyon.cap4.form.bean.FormBean;
import com.seeyon.cap4.form.bean.FormFieldBean;
import com.seeyon.cap4.form.bean.FormTableBean;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.exceptions.BusinessException;
import com.seeyon.ctp.util.JDBCAgent;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;
import org.apache.http.util.EntityUtils;
import www.seeyon.com.utils.StringUtil;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
public class FormDataOperator {
public void updateMasterForm(String formNo, List<FormUpdateField> updateFieldVos, List<FormWhereCondition> conditionVos) throws BusinessException {
FormApi4Cap4 formApi4Cap4 = (FormApi4Cap4) AppContext.getBean("formApi4Cap4");
FormBean cap4FormBean = formApi4Cap4.getFormByFormCode(formNo);
FormTableBean masterTableBean = cap4FormBean.getMasterTableBean();
if (updateFieldVos == null) {
throw new IllegalArgumentException("要修改的字段为空");
}
for (FormUpdateField fieldVo : updateFieldVos) {
FormFieldBean bean = masterTableBean.getFieldBeanByDisplay(fieldVo.getDisplay());
if (bean == null) {
continue;
}
if(bean.getInputType().equals("image") || bean.getInputType().equals("attachment")) {
}
fieldVo.fieldName(bean.getColumnName());
}
List<FormUpdateField> updateFields = updateFieldVos.stream().filter(u -> u.getFieldName() != null).collect(Collectors.toList());
for (FormWhereCondition conditionVo : conditionVos) {
FormFieldBean bean = masterTableBean.getFieldBeanByDisplay(conditionVo.getDisplay());
if (bean == null) {
if (conditionVo.getDisplay().equals("ID") || conditionVo.getDisplay().equals("id")) {
conditionVo.setFieldName(conditionVo.getDisplay());
}
continue;
}
conditionVo.setFieldName(bean.getColumnName());
}
List<FormWhereCondition> conditions = conditionVos.stream().filter(c -> c.getFieldName() != null).collect(Collectors.toList());
Map<String, Object> map = generateSql(updateFields, masterTableBean.getTableName(), conditions);
JDBCAgent agent = new JDBCAgent();
try {
agent.execute((String) map.get("sql"), (List<Object>) map.get("params"));
return;
} catch (Exception e) {
e.printStackTrace();
} finally {
agent.close();
}
}
public Long countCondition(String formNo,List<FormWhereCondition> conditionVos) throws BusinessException {
FormApi4Cap4 formApi4Cap4 = (FormApi4Cap4) AppContext.getBean("formApi4Cap4");
FormBean cap4FormBean = formApi4Cap4.getFormByFormCode(formNo);
FormTableBean masterTableBean = cap4FormBean.getMasterTableBean();
String tableName = masterTableBean.getTableName();
for (FormWhereCondition conditionVo : conditionVos) {
FormFieldBean fieldBeanByDisplay = masterTableBean.getFieldBeanByDisplay(conditionVo.getDisplay());
if (fieldBeanByDisplay == null) {
continue;
}
conditionVo.setFieldName(fieldBeanByDisplay.getColumnName());
}
Map<String, Object> generateSql = generateSql(conditionVos, tableName);
String sql = (String) generateSql.get("sql");
List<Object> params = (List<Object>) generateSql.get("params");
JDBCAgent jdbcAgent = new JDBCAgent();
try {
jdbcAgent.execute(sql, params);
return (Long) jdbcAgent.resultSetToMap().get("countsize");
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
jdbcAgent.close();
}
return null;
}
// public void refreshForm(String id, String formNo, String formLoginName, HttpFormRestApiConfig config) throws BusinessException, IOException {
// FormApi4Cap4 formApi4Cap4 = (FormApi4Cap4) AppContext.getBean("formApi4Cap4");
// FormBean cap4FormBean = formApi4Cap4.getFormByFormCode(formNo);
// FormTableBean masterTableBean = cap4FormBean.getMasterTableBean();
// List<Object> dataList = new ArrayList<>();
// Map<String,Object> temp1 = new HashMap<>();
// Map<String,Object> temp2 = new HashMap<>();
// temp1.put("masterTable",temp2);
// temp2.put("name",masterTableBean.getTableName());
// Map<String, Object> recordMap = new HashMap<>(3); // 容量=3 (2/0.75≈2.67)
// recordMap.put("id", id);
// recordMap.put("fields", new ArrayList<>());
// temp2.put("record", recordMap);
// temp2.put("changedFields",new ArrayList<>());
// dataList.add(temp1);
// String token = getToken(config.getTokenUrl(),config.getRestUserName(),config.getRestPwd(),formLoginName);
// Map beanMap = new HashMap();
// beanMap.put("formCode", formNo);
// beanMap.put("loginName", formLoginName);
// beanMap.put("doTrigger", "true");
// beanMap.put("rightId", config.getRightId());
// beanMap.put("dataList",dataList);
// Map<String, String> header = new HashMap<>();
// header.put("token", token);
// String url = config.getBaseUrl() + "/seeyon/rest/cap4/form/soap/batch-update";
// String response = HttpClient.httpPostRaw(url, JsonUtils.toJSONString(beanMap), header, "UTF-8");
// System.out.println(response);
// }
// private String getToken(String oatokenurl,String restName,String restPassword,String loginName) throws FileNotFoundException, IOException {
// String address = oatokenurl + restName + "/" + restPassword;
// if(StringUtil.isNotEmpty(loginName)){
// address = address +"?loginName="+loginName;
// }
// DefaultHttpClient client = new DefaultHttpClient();
// String result = "";
// HttpGet get = new HttpGet(address);
// // 添加 Headers 信息
// get.addHeader(new BasicHeader("Accept", "application/json"));
// try {
// HttpResponse res = client.execute(get);
// if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
// result = EntityUtils.toString(res.getEntity());
// }
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
// String token = "";
// if(result.contains("{")) {
// JSONObject jsObj = JSONObject.parseObject(result);
// token = jsObj.get("id").toString();
// }else {
// token = result;
// }
// return token;
// }
public List<FormColumn> queryFormDataCondition(String formNo, List<String> queryColumnVos, List<FormWhereCondition> conditionVos) throws BusinessException {
FormApi4Cap4 formApi4Cap4 = (FormApi4Cap4) AppContext.getBean("formApi4Cap4");
FormBean cap4FormBean = formApi4Cap4.getFormByFormCode(formNo);
List<String> queryColumns = new ArrayList<>();
FormTableBean masterTableBean = cap4FormBean.getMasterTableBean();
String tableName = masterTableBean.getTableName();
Map<String, FormFieldBean> fieldMap4Name = masterTableBean.getFieldMap4Name();
if (queryColumnVos != null) {
for (String queryColumnVo : queryColumnVos) {
FormFieldBean fieldBeanByDisplay = masterTableBean.getFieldBeanByDisplay(queryColumnVo);
if (fieldBeanByDisplay == null) {
continue;
}
queryColumns.add(fieldBeanByDisplay.getColumnName());
}
}
for (FormWhereCondition conditionVo : conditionVos) {
FormFieldBean fieldBeanByDisplay = masterTableBean.getFieldBeanByDisplay(conditionVo.getDisplay());
if (fieldBeanByDisplay == null) {
if (conditionVo.getDisplay().equals("ID") || conditionVo.getDisplay().equals("id")) {
conditionVo.setFieldName(conditionVo.getDisplay());
}
continue;
}
conditionVo.setFieldName(fieldBeanByDisplay.getColumnName());
}
Map<String, Object> generateSql = generateSql(queryColumns, conditionVos, tableName);
String sql = (String) generateSql.get("sql");
List<Object> params = (List<Object>) generateSql.get("params");
JDBCAgent jdbcAgent = new JDBCAgent();
List<FormColumn> columns = new ArrayList<>();
try {
jdbcAgent.execute(sql, params);
List list = jdbcAgent.resultSetToList();
for (Object o : list) {
FormColumn column = new FormColumn();
Map<String, Object> columnMap = (Map<String, Object>) o;
List<FormFieldVo> vos = new ArrayList<>();
for (String key : columnMap.keySet()) {
FormFieldVo fieldVo = new FormFieldVo();
if (fieldMap4Name.containsKey(key)) {
FormFieldBean fieldBean = fieldMap4Name.get(key);
fieldVo.setDisplayName(fieldBean.getDisplay());
fieldVo.setValue(columnMap.get(key));
vos.add(fieldVo);
}
}
column.setVos(vos);
if (columnMap.get("id") != null) {
column.setId(columnMap.get("id") + "");
}
columns.add(column);
}
return columns;
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
jdbcAgent.close();
}
return null;
}
private Map<String, Object> generateSql(List<FormWhereCondition> conditions, String tableName) {
if (tableName == null) {
throw new IllegalArgumentException("tableName cannot be null or empty");
}
StringBuilder sqlBuilder = new StringBuilder("SELECT count(*) as countSize ");
sqlBuilder.append(" from " + tableName);
List<Object> params = new ArrayList<>();
sqlBuilder.append(buildWhereClause(conditions,params));
Map<String, Object> result = new HashMap<>();
result.put("sql", sqlBuilder.toString());
result.put("params", params);
return result;
}
private Map<String, Object> generateSql(List<String> queryColumn, List<FormWhereCondition> conditions, String tableName) {
if (tableName == null) {
throw new IllegalArgumentException("tableName cannot be null or empty");
}
StringBuilder sqlBuilder = new StringBuilder("SELECT ");
if (queryColumn == null || queryColumn.isEmpty()) {
sqlBuilder.append("*");
}
for (int i = 0; i < queryColumn.size(); i++) {
sqlBuilder.append(queryColumn.get(i));
if (queryColumn.size() > 1 && i >= 0 && i < queryColumn.size() - 1) {
sqlBuilder.append(",");
}
}
if (queryColumn.size() > 0) {
sqlBuilder.append(",`ID`");
}
sqlBuilder.append(" from " + tableName);
List<Object> params = new ArrayList<>();
sqlBuilder.append(buildWhereClause(conditions,params));
Map<String, Object> result = new HashMap<>();
result.put("sql", sqlBuilder.toString());
result.put("params", params);
return result;
}
private Map<String, Object> generateSql(List<FormUpdateField> fieldValues, String tableName, List<FormWhereCondition> conditions) {
if (fieldValues == null || fieldValues.isEmpty()) {
throw new IllegalArgumentException("Field values cannot be null or empty");
}
if (tableName == null || tableName.trim().isEmpty()) {
throw new IllegalArgumentException("Table name cannot be null or empty");
}
StringBuilder sqlBuilder = new StringBuilder("UPDATE ").append(tableName).append(" SET ");
List<Object> params = new ArrayList<>();
// Build the SET clause
int fieldCount = 0;
for (FormUpdateField updateField : fieldValues) {
if (updateField.getValue() == null || "".equals(updateField.getValue()) || "null".equals(updateField.getValue())) {
continue;
}
if (fieldCount > 0) {
sqlBuilder.append(", ");
}
if (updateField.getValue() instanceof String && ((String) updateField.getValue()).startsWith("DATE>")) {
String oldValue = (String) updateField.getValue();
sqlBuilder.append(updateField.getFieldName()).append(" = TO_DATE( ?, 'YYYY-MM-DD')");
updateField.setValue(oldValue.substring(oldValue.indexOf(">") + 1));
} else {
sqlBuilder.append(updateField.getFieldName()).append(" = ?");
}
params.add(updateField.getValue());
fieldCount++;
}
String whereClauseStr = buildWhereClause(conditions,params);
// Append the WHERE clause
sqlBuilder.append(whereClauseStr);
// Create result map
Map<String, Object> result = new HashMap<>();
result.put("sql", sqlBuilder.toString());
result.put("params", params);
return result;
}
public Map<String,List<Object>> getMainFormTableAttachments(String formNo,Map<String,Object> sourceMap) throws BusinessException {
FormApi4Cap4 formApi4Cap4 = (FormApi4Cap4) AppContext.getBean("formApi4Cap4");
FormBean cap4FormBean = formApi4Cap4.getFormByFormCode(formNo);
FormTableBean masterTableBean = cap4FormBean.getMasterTableBean();
Map<String,List<Object>> attachmentTempMap = new HashMap<>();
Set<String> removeKey = new HashSet<>();
for (String key : sourceMap.keySet()) {
FormFieldBean fieldBeanByDisplay = masterTableBean.getFieldBeanByDisplay(key);
if(fieldBeanByDisplay == null ){
continue;
}
if(fieldBeanByDisplay.getInputType().equals("image") ||
fieldBeanByDisplay.getInputType().equals("attachment")) {
attachmentTempMap.put(fieldBeanByDisplay.getDisplay(),(List<Object>)sourceMap.get(key));
removeKey.add(key);
}
}
for (String key : removeKey) {
sourceMap.remove(key);
}
return attachmentTempMap;
}
public Map<String,List<Object>> getSubFormTableAttachments(String formNo,Map<String,Object> sourceMap) throws BusinessException {
FormApi4Cap4 formApi4Cap4 = (FormApi4Cap4) AppContext.getBean("formApi4Cap4");
FormBean cap4FormBean = formApi4Cap4.getFormByFormCode(formNo);
List<FormTableBean> subTableBean = cap4FormBean.getSubTableBean();
Map<String,List<Object>> attachmentTempMap = new HashMap<>();
String tableName = null;
for (String key : sourceMap.keySet()) {
tableName = key;
}
String finalTableName = tableName;
FormTableBean tableBean = subTableBean.stream().filter(s->s.getTableName().equals(finalTableName)).collect(Collectors.toList()).get(0);
List<Map<String,Object>> tableData = (List<Map<String,Object>>)sourceMap.get(tableName);
Set<String> removeKey = new HashSet<>();
for (Map<String, Object> rowData : tableData) {
for (String key : rowData.keySet()) {
FormFieldBean fieldBeanByDisplay = tableBean.getFieldBeanByDisplay(key);
if(fieldBeanByDisplay == null ){
continue;
}
if(fieldBeanByDisplay.getInputType().equals("image") ||
fieldBeanByDisplay.getInputType().equals("attachment")) {
attachmentTempMap.put(fieldBeanByDisplay.getDisplay(),(List<Object>)sourceMap.get(key));
removeKey.add(key);
}
}
for (String key : removeKey) {
rowData.remove(key);
}
removeKey.clear();
}
return attachmentTempMap;
}
public void addSubTableRecord(String subTableName,List<Object> data,String formNo,String formId) {
JDBCAgent agent = new JDBCAgent();
try {
FormApi4Cap4 formApi4Cap4 = (FormApi4Cap4) AppContext.getBean("formApi4Cap4");
FormBean cap4FormBean = formApi4Cap4.getFormByFormCode(formNo);
List<FormTableBean> tableBean = cap4FormBean.getSubTableBean();
for (FormTableBean bean : tableBean) {
if(!bean.getTableName().equals(subTableName)) {
continue;
}
for (Object column : data) {
Map<String,Object> map = (Map<String,Object>) column;
Map<String,Object> tempMap = new HashMap<>();
for (String key : map.keySet()) {
FormFieldBean fieldBeanByDisplay = bean.getFieldBeanByDisplay(key);
if(fieldBeanByDisplay == null) {
continue;
}
tempMap.put(fieldBeanByDisplay.getColumnName(),map.get(key));
}
tempMap.put("formmain_id",formId);
tempMap.put("sort",1);
tempMap.put("ID",Math.abs(UUID.randomUUID().getLeastSignificantBits()));
Map<String, Object> insertSql = generateInsertSql(tempMap, subTableName);
agent.execute((String)insertSql.get("sql"),(List<Object>)insertSql.get("params"));
}
}
} catch (Exception e) {
} finally {
agent.close();
}
}
public void rebuildSubTableRecord(String subTableName,List<Object> data,String formNo,String formId) {
String deleteSql = "delete from " + subTableName + " where formmain_id = ? ";
JDBCAgent agent = new JDBCAgent();
try {
agent.execute(deleteSql, Arrays.asList(formId));
FormApi4Cap4 formApi4Cap4 = (FormApi4Cap4) AppContext.getBean("formApi4Cap4");
FormBean cap4FormBean = formApi4Cap4.getFormByFormCode(formNo);
List<FormTableBean> tableBean = cap4FormBean.getSubTableBean();
for (FormTableBean bean : tableBean) {
if(!bean.getTableName().equals(subTableName)) {
continue;
}
for (Object column : data) {
Map<String,Object> map = (Map<String,Object>) column;
Map<String,Object> tempMap = new HashMap<>();
for (String key : map.keySet()) {
FormFieldBean fieldBeanByDisplay = bean.getFieldBeanByDisplay(key);
if(fieldBeanByDisplay == null) {
continue;
}
tempMap.put(fieldBeanByDisplay.getColumnName(),map.get(key));
}
tempMap.put("formmain_id",formId);
tempMap.put("sort",1);
tempMap.put("ID",Math.abs(UUID.randomUUID().getLeastSignificantBits()));
Map<String, Object> insertSql = generateInsertSql(tempMap, subTableName);
agent.execute((String)insertSql.get("sql"),(List<Object>)insertSql.get("params"));
}
}
} catch (Exception e) {
} finally {
agent.close();
}
}
public void handleEnumDeptEtc(Map<String,Object> map,String formNo) throws BusinessException {
FormApi4Cap4 formApi4Cap4 = (FormApi4Cap4) AppContext.getBean("formApi4Cap4");
FormBean cap4FormBean = formApi4Cap4.getFormByFormCode(formNo);
FormTableBean masterTableBean = cap4FormBean.getMasterTableBean();
for (String key : map.keySet()) {
FormFieldBean fieldBean = masterTableBean.getFieldBeanByDisplay(key);
if(fieldBean == null) {
continue;
}
switch (fieldBean.getInputType()) {
case "select": if(fieldBean.getEnumId() != 0l) {
String enumItemId = EnumMapUtils.getEnumItemValueByEnumId((String)map.get(key),fieldBean.getEnumId());
map.put(key,enumItemId);
} break;
case "image":break;
case "attachment": break;
case "account": break;
case "department": break;
case "radio": break;
case "member":break;
case "checkbox":
case "date":
case "text":break;
default: break;
}
}
}
public void handleSubTableEnumDeptEtc(Map<String,Object> map,String formNo) throws BusinessException {
FormApi4Cap4 formApi4Cap4 = (FormApi4Cap4) AppContext.getBean("formApi4Cap4");
FormBean cap4FormBean = formApi4Cap4.getFormByFormCode(formNo);
List<FormTableBean> subTableBean = cap4FormBean.getSubTableBean();
for (FormTableBean tableBean : subTableBean) {
String tableName = null;
for (String key : map.keySet()) {
tableName = key;
}
if(!tableBean.getTableName().equals(tableName)) {
continue;
}
List<Map<String,Object>> subDatas = (List<Map<String, Object>>) map.get(tableName);
for (Map<String, Object> subData : subDatas) {
for (String key : subData.keySet()) {
FormFieldBean fieldBean = tableBean.getFieldBeanByDisplay(key);
if(fieldBean == null) {
continue;
}
switch (fieldBean.getInputType()) {
case "select": if(fieldBean.getEnumId() != 0l) {
String enumItemId = EnumMapUtils.getEnumItemValueByEnumId((String)subData.get(key),fieldBean.getEnumId());
subData.put(key,enumItemId);
} break;
case "image":break;
case "attachment": break;
case "account": break;
case "department": break;
case "radio": break;
case "member":break;
case "checkbox":
case "date":
case "text":break;
default: break;
}
}
}
}
}
public boolean isMasterTableFile(String displayName,String formNo) {
FormApi4Cap4 formApi4Cap4 = (FormApi4Cap4) AppContext.getBean("formApi4Cap4");
try {
FormBean cap4FormBean = formApi4Cap4.getFormByFormCode(formNo);
FormTableBean masterTableBean = cap4FormBean.getMasterTableBean();
FormFieldBean fieldBeanByDisplay = masterTableBean.getFieldBeanByDisplay(displayName);
return fieldBeanByDisplay.getInputType().equals("image") || fieldBeanByDisplay.getInputType().equals("attachment");
} catch (BusinessException e) {
}
return false;
}
private Map<String, Object> generateInsertSql(Map<String, Object> data, String tableName) {
if (tableName == null || tableName.isEmpty()) {
throw new IllegalArgumentException("tableName cannot be null or empty");
}
if (data == null || data.isEmpty()) {
throw new IllegalArgumentException("data cannot be null or empty");
}
StringBuilder sqlBuilder = new StringBuilder("INSERT INTO " + tableName + " (");
List<Object> params = new ArrayList<>();
// 拼接字段名
StringBuilder columns = new StringBuilder();
// 拼接字段值
StringBuilder values = new StringBuilder();
for (Map.Entry<String, Object> entry : data.entrySet()) {
// 拼接字段名
if (columns.length() > 0) {
columns.append(", ");
}
columns.append(entry.getKey());
// 拼接值,使用占位符 ?
if (values.length() > 0) {
values.append(", ");
}
values.append("?");
// 将值加入 params 列表
params.add(entry.getValue());
}
// 完善 SQL 语句
sqlBuilder.append(columns).append(") VALUES (").append(values).append(");");
Map<String, Object> result = new HashMap<>();
result.put("sql", sqlBuilder.toString());
result.put("params", params);
return result;
}
/**
* 动态生成 WHERE 子句
* @param conditions 条件集合
* @param params 参数列表(引用传递)
* @return 拼接后的 WHERE 子句(包含 WHERE 关键字)
*/
private String buildWhereClause(List<FormWhereCondition> conditions, List<Object> params) {
if (conditions == null || conditions.isEmpty()) {
return "";
}
StringBuilder whereClause = new StringBuilder(" WHERE ");
int conditionIndex = 0;
for (FormWhereCondition condition : conditions) {
// 处理括号起始
if (condition.isStartWithBracket()) {
whereClause.append("(");
}
// 字段名校验
String fieldName = condition.getFieldName();
ClauseFactor factor = condition.getClauseFactor();
String operator = parseOperator(factor);
// 构建条件表达式
String conditionExpr;
if (factor != null && factor.isNullType()) {
// 处理 NULL/NOT NULL 条件(无需参数)
conditionExpr = String.format("%s %s", fieldName, operator);
} else {
// 处理普通条件(带占位符)
conditionExpr = String.format("%s %s ?", fieldName, operator);
// 处理函数模板(如 TO_DATE
if (condition.getIndex() != null) {
conditionExpr = conditionExpr.replace("?", condition.getIndex());
}
// 添加参数值
params.add(condition.getValue());
}
whereClause.append(conditionExpr);
// 处理括号闭合
if (condition.isEndWithBracket()) {
whereClause.append(")");
}
// 添加连接符AND/OR
if (conditionIndex < conditions.size() - 1) {
whereClause.append(" ").append(condition.getConcatFactor()).append(" ");
}
conditionIndex++;
}
return whereClause.toString();
}
/**
* 校验字段名合法性(防止 SQL 注入)
*/
private String validateFieldName(String fieldName) {
if (!fieldName.matches("^[a-zA-Z_][a-zA-Z0-9_]*$")) {
throw new IllegalArgumentException("非法字段名: " + fieldName);
}
return fieldName;
}
/**
* 解析运算符映射eq -> =, lt -> < 等)
*/
private String parseOperator(ClauseFactor factor) {
if(factor == null) {
return "=";
}
switch (factor) {
case EQ: return "=";
case GT: return ">";
case GE: return ">=";
case LT: return "<";
case LE: return "<=";
case LIKE: return "LIKE";
case NULL: return "IS NULL"; // 空值判断
case NOT_NULL: return "IS NOT NULL"; // 非空判断
default: throw new UnsupportedOperationException("不支持的运算符: " + factor);
}
}
}

View File

@@ -0,0 +1,84 @@
package com.seeyon.utils.form;
import com.seeyon.v3x.services.form.bean.RecordExport;
import com.seeyon.v3x.services.form.bean.SubordinateFormExport;
import com.seeyon.v3x.services.form.bean.ValueExport;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
//创建无流程表单数据处理工具类
public class FormExportUtil {
/**
* 设置主表信息
* @param map 设置主表字段。Map<主表显示名称,主表数据>
* @return
*/
public List<ValueExport> setFormValue(Map<String, Object> map ){
// 创建返回值对象
List<ValueExport> valueExports = new ArrayList<ValueExport>();
ValueExport valueExport ;
// 获取参数信息(显示名称)
Set<String> keys = map.keySet();
if(keys.size()>0) {
// 对控件赋值
for (String key : keys) {
if(map.get(key) != null ){
valueExport = new ValueExport();
valueExport.setDisplayName(key);
valueExport.setValue(map.get(key).toString());
valueExports.add(valueExport);
}
System.out.println(key+":"+map.get(key));
}
}
return valueExports;
}
/**
* 设置从表信息
* @param lists 设置主表字段。List<Map<显示名称,数据值>>
*/
public List<SubordinateFormExport> setSubordinateFormValue(List<Map<String, Object>> lists){
List<SubordinateFormExport> subordinateFormExports = new ArrayList<SubordinateFormExport>();
SubordinateFormExport subordinateFormExport = new SubordinateFormExport();
List<RecordExport> recordExports = new ArrayList<RecordExport>();
List<ValueExport> valueExports;
RecordExport recordExport;
for(int i = 0 ; i < lists.size() ; i++) {
recordExport = new RecordExport();
valueExports = setFormValue(lists.get(i));
recordExport.setRecord(valueExports);
recordExports.add(recordExport);
}
subordinateFormExport.setValues(recordExports);
subordinateFormExports.add(subordinateFormExport);
return subordinateFormExports;
}
public List<SubordinateFormExport> setAllSubordinateFormValue(List<Map<String,Object>> lists){
List<SubordinateFormExport> subordinateFormExports = new ArrayList<SubordinateFormExport>();
for (Map<String, Object> list : lists) {
SubordinateFormExport subordinateFormExport = new SubordinateFormExport();
List<RecordExport> recordExports = new ArrayList<RecordExport>();
for (String key : list.keySet()) {
List<Map<String,Object>> columns = (List<Map<String, Object>>) list.get(key);
for(int i = 0 ; i < columns.size() ; i++) {
List<ValueExport> valueExports = setFormValue(columns.get(i));
RecordExport recordExport = new RecordExport();
recordExport.setRecord(valueExports);
recordExports.add(recordExport);
}
}
subordinateFormExport.setValues(recordExports);
subordinateFormExports.add(subordinateFormExport);
}
return subordinateFormExports;
}
}

View File

@@ -0,0 +1,22 @@
package com.seeyon.utils.form;
public class FormFieldVo {
private String displayName;
private Object value;
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
}

View File

@@ -0,0 +1,57 @@
package com.seeyon.utils.form;
public class FormUpdateField {
private String display;
private String fieldName;
private Object value;
public FormUpdateField(Object value) {
this.value = value;
}
public FormUpdateField() {
}
public static FormUpdateField build() {
return new FormUpdateField();
}
public FormUpdateField display(String display) {
this.display = display;
return this;
}
public FormUpdateField value(String value) {
this.value = value;
return this;
}
public FormUpdateField fieldName(String fieldName) {
this.fieldName = fieldName;
return this;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
public String getDisplay() {
return display;
}
public void setDisplay(String display) {
this.display = display;
}
public String getFieldName() {
return fieldName;
}
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
}

View File

@@ -0,0 +1,121 @@
package com.seeyon.utils.form;
public class FormWhereCondition {
private String display;
private String fieldName; //字段名
private Object value; //值
private ClauseFactor clauseFactor; //条件因子 eq lt gt not_null null
private ClauseFactor concatFactor = ClauseFactor.AND; //拼接因子
private boolean startWithBracket = false; //是否以括号开头生成子条件
private boolean endWithBracket = false; //是否以括号结尾结束子条件
private String index;
public FormWhereCondition() {
}
public String getDisplay() {
return display;
}
public void setDisplay(String display) {
this.display = display;
}
public static FormWhereCondition build() {
return new FormWhereCondition();
}
public FormWhereCondition display(String display) {
this.display = display;
return this;
}
public FormWhereCondition value(Object value) {
this.value = value;
return this;
}
public FormWhereCondition clauseFactor(ClauseFactor clauseFactor) {
this.clauseFactor = clauseFactor;
return this;
}
public FormWhereCondition index(String index) {
this.index = index;
return this;
}
public FormWhereCondition startWithBracket(boolean startWithBracket) {
this.startWithBracket = startWithBracket;
return this;
}
public FormWhereCondition endWithBracket(boolean endWithBracket) {
this.endWithBracket = endWithBracket;
return this;
}
public FormWhereCondition concatFactor(ClauseFactor concatFactor) {
this.concatFactor = concatFactor;
return this;
}
public FormWhereCondition(Object value, ClauseFactor clauseFactor) {
this.value = value;
this.clauseFactor = clauseFactor;
}
public boolean isStartWithBracket() {
return startWithBracket;
}
public void setStartWithBracket(boolean startWithBracket) {
this.startWithBracket = startWithBracket;
}
public String getFieldName() {
return fieldName;
}
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
public ClauseFactor getClauseFactor() {
return clauseFactor;
}
public void setClauseFactor(ClauseFactor clauseFactor) {
this.clauseFactor = clauseFactor;
}
public ClauseFactor getConcatFactor() {
return concatFactor;
}
public void setConcatFactor(ClauseFactor concatFactor) {
this.concatFactor = concatFactor;
}
public String getIndex() {
return index;
}
public void setIndex(String index) {
this.index = index;
}
public boolean isEndWithBracket() {
return endWithBracket;
}
public void setEndWithBracket(boolean endWithBracket) {
this.endWithBracket = endWithBracket;
}
}

View File

@@ -0,0 +1,417 @@
package com.seeyon.utils.http;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.*;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import java.io.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @ClassName: HttpClient
* @Description: HTTP请求工具类
* @Author: GiikJc
* @Date: 2022/7/12 15:03
*/
/**
* 发送Get请求HttpResponse httpGet(String url,Map<String,String> headers,String encode)
*发送Post请求同表单Post提交HttpResponse httpPostForm(String url,Map<String,String> params, Map<String,String> headers,String encode)
*发送Post Raw请求HttpResponse httpPostRaw(String url,String stringJson,Map<String,String> headers, String encode)
*发送Put Raw请求HttpResponse httpPutRaw(String url,String stringJson,Map<String,String> headers, String encode)
*发送Delete请求HttpResponse httpDelete(String url,Map<String,String> headers,String encode)
*/
public class HttpClient {
/**
* 发送 HTTP GET 请求下载文件
* @param url 下载文件的 URL
* @param headers 请求头
* @param savePath 文件保存的路径
* @param encode 文件内容的编码
* @return 下载成功返回 true失败返回 false
*/
public static boolean httpDownloadFile(String url, Map<String, String> headers, String savePath, String encode) {
if (encode == null) {
encode = "utf-8"; // 默认字符编码
}
CloseableHttpClient httpClient = null;
CloseableHttpResponse httpResponse = null;
InputStream inputStream = null;
OutputStream outputStream = null;
try {
// 创建 HttpClient 实例
httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(url);
// 设置请求头
if (headers != null && headers.size() > 0) {
for (Map.Entry<String, String> entry : headers.entrySet()) {
httpGet.setHeader(entry.getKey(), entry.getValue());
}
}
// 执行请求
httpResponse = httpClient.execute(httpGet);
HttpEntity entity = httpResponse.getEntity();
// 检查响应状态码
if (httpResponse.getStatusLine().getStatusCode() == 200) {
inputStream = entity.getContent();
// 创建输出流,将文件保存到本地
outputStream = new FileOutputStream(savePath);
// 设置缓冲区
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
// 文件下载成功
return true;
} else {
System.out.println("Download failed, HTTP error code: " + httpResponse.getStatusLine().getStatusCode());
return false;
}
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
try {
if (inputStream != null) {
inputStream.close();
}
if (outputStream != null) {
outputStream.close();
}
if (httpResponse != null) {
httpResponse.close();
}
if (httpClient != null) {
httpClient.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 发送http get请求
*/
public static String httpGet(String url,Map<String,String> headers,String encode){
if(encode == null){
encode = "utf-8";
}
CloseableHttpResponse httpResponse = null;
CloseableHttpClient closeableHttpClient = null;
String content = null;
//since 4.3 不再使用 DefaultHttpClient
try {
closeableHttpClient = HttpClientBuilder.create().build();
HttpGet httpGet = new HttpGet(url);
//设置header
if (headers != null && headers.size() > 0) {
for (Map.Entry<String, String> entry : headers.entrySet()) {
httpGet.setHeader(entry.getKey(),entry.getValue());
}
}
httpResponse = closeableHttpClient.execute(httpGet);
HttpEntity entity = httpResponse.getEntity();
content = EntityUtils.toString(entity, encode);
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
httpResponse.close();
} catch (IOException e) {
e.printStackTrace();
}
}
try { //关闭连接、释放资源
closeableHttpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
return content;
}
/**
* 发送 http post 请求参数以form表单键值对的形式提交。
*/
public static String httpPostForm(String url,Map<String,String> params, Map<String,String> headers,String encode){
if(encode == null){
encode = "utf-8";
}
String content = null;
CloseableHttpResponse httpResponse = null;
CloseableHttpClient closeableHttpClient = null;
try {
closeableHttpClient = HttpClients.createDefault();
HttpPost httpost = new HttpPost(url);
//设置header
if (headers != null && headers.size() > 0) {
for (Map.Entry<String, String> entry : headers.entrySet()) {
httpost.setHeader(entry.getKey(),entry.getValue());
}
}
//组织请求参数
List<NameValuePair> paramList = new ArrayList <NameValuePair>();
if(params != null && params.size() > 0){
Set<String> keySet = params.keySet();
for(String key : keySet) {
paramList.add(new BasicNameValuePair(key, params.get(key)));
}
}
httpost.setEntity(new UrlEncodedFormEntity(paramList, encode));
httpResponse = closeableHttpClient.execute(httpost);
HttpEntity entity = httpResponse.getEntity();
content = EntityUtils.toString(entity, encode);
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
httpResponse.close();
} catch (IOException e) {
e.printStackTrace();
}
}
try { //关闭连接、释放资源
closeableHttpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
return content;
}
/**
* 发送 http post 请求,参数以原生字符串进行提交
* @param url
* @param encode
* @return
*/
public static String httpPostRaw(String url,String stringJson,Map<String,String> headers, String encode){
if(encode == null){
encode = "utf-8";
}
String content = null;
CloseableHttpResponse httpResponse = null;
CloseableHttpClient closeableHttpClient = null;
try {
//HttpClients.createDefault()等价于 HttpClientBuilder.create().build();
closeableHttpClient = HttpClients.createDefault();
HttpPost httpost = new HttpPost(url);
//设置header
httpost.setHeader("Content-type", "application/json");
if (headers != null && headers.size() > 0) {
for (Map.Entry<String, String> entry : headers.entrySet()) {
httpost.setHeader(entry.getKey(),entry.getValue());
}
}
//组织请求参数
StringEntity stringEntity = new StringEntity(stringJson, encode);
httpost.setEntity(stringEntity);
//响应信息
httpResponse = closeableHttpClient.execute(httpost);
HttpEntity entity = httpResponse.getEntity();
content = EntityUtils.toString(entity, encode);
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
httpResponse.close();
} catch (IOException e) {
e.printStackTrace();
}
}
try { //关闭连接、释放资源
closeableHttpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
return content;
}
/**
* 发送 http put 请求,参数以原生字符串进行提交
* @param url
* @param encode
* @return
*/
public static String httpPutRaw(String url,String stringJson,Map<String,String> headers, String encode){
if(encode == null){
encode = "utf-8";
}
CloseableHttpResponse httpResponse = null;
CloseableHttpClient closeableHttpClient = null;
String content = null;
//since 4.3 不再使用 DefaultHttpClient
try {
//HttpClients.createDefault()等价于 HttpClientBuilder.create().build();
closeableHttpClient = HttpClients.createDefault();
HttpPut httpput = new HttpPut(url);
//设置header
httpput.setHeader("Content-type", "application/json");
if (headers != null && headers.size() > 0) {
for (Map.Entry<String, String> entry : headers.entrySet()) {
httpput.setHeader(entry.getKey(),entry.getValue());
}
}
//组织请求参数
StringEntity stringEntity = new StringEntity(stringJson, encode);
httpput.setEntity(stringEntity);
//响应信息
httpResponse = closeableHttpClient.execute(httpput);
HttpEntity entity = httpResponse.getEntity();
content = EntityUtils.toString(entity, encode);
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
httpResponse.close();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
closeableHttpClient.close(); //关闭连接、释放资源
} catch (IOException e) {
e.printStackTrace();
}
return content;
}
/**
* 发送http delete请求
*/
public static String httpDelete(String url,Map<String,String> headers,String encode){
if(encode == null){
encode = "utf-8";
}
String content = null;
CloseableHttpResponse httpResponse = null;
CloseableHttpClient closeableHttpClient = null;
try {
//since 4.3 不再使用 DefaultHttpClient
closeableHttpClient = HttpClientBuilder.create().build();
HttpDelete httpdelete = new HttpDelete(url);
//设置header
if (headers != null && headers.size() > 0) {
for (Map.Entry<String, String> entry : headers.entrySet()) {
httpdelete.setHeader(entry.getKey(),entry.getValue());
}
}
httpResponse = closeableHttpClient.execute(httpdelete);
HttpEntity entity = httpResponse.getEntity();
content = EntityUtils.toString(entity, encode);
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
httpResponse.close();
} catch (IOException e) {
e.printStackTrace();
}
}
try { //关闭连接、释放资源
closeableHttpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
return content;
}
/**
* 发送 http post 请求,支持文件上传
*/
public static String httpPostFormMultipart(String url,Map<String,String> params, List<File> files,Map<String,String> headers,String encode){
if(encode == null){
encode = "utf-8";
}
CloseableHttpResponse httpResponse = null;
CloseableHttpClient closeableHttpClient = null;
String content = null;
//since 4.3 不再使用 DefaultHttpClient
try {
closeableHttpClient = HttpClients.createDefault();
HttpPost httpost = new HttpPost(url);
//设置header
if (headers != null && headers.size() > 0) {
for (Map.Entry<String, String> entry : headers.entrySet()) {
httpost.setHeader(entry.getKey(),entry.getValue());
}
}
MultipartEntityBuilder mEntityBuilder = MultipartEntityBuilder.create();
mEntityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
mEntityBuilder.setCharset(Charset.forName(encode));
// 普通参数
ContentType contentType = ContentType.create("text/plain",Charset.forName(encode));//解决中文乱码
if (params != null && params.size() > 0) {
Set<String> keySet = params.keySet();
for (String key : keySet) {
mEntityBuilder.addTextBody(key, params.get(key),contentType);
}
}
//二进制参数
if (files != null && files.size() > 0) {
for (File file : files) {
mEntityBuilder.addBinaryBody("file", file);
}
}
httpost.setEntity(mEntityBuilder.build());
httpResponse = closeableHttpClient.execute(httpost);
HttpEntity entity = httpResponse.getEntity();
content = EntityUtils.toString(entity, encode);
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
httpResponse.close();
} catch (IOException e) {
e.printStackTrace();
}
}
try { //关闭连接、释放资源
closeableHttpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
return content;
}
}