Compare commits
3 Commits
2435926edb
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| a59d3c076c | |||
| cabf83391f | |||
| 6652165e86 |
@@ -1,6 +1,7 @@
|
||||
package com.seeyon.utils.form;
|
||||
|
||||
public enum ClauseFactor {
|
||||
NEQ,//不相等
|
||||
EQ, //相等
|
||||
GT, //大于
|
||||
GE, //大于等于
|
||||
@@ -10,10 +11,16 @@ public enum ClauseFactor {
|
||||
NOT_NULL, //非空
|
||||
LIKE, //模糊
|
||||
AND,
|
||||
OR
|
||||
OR,
|
||||
IN,
|
||||
NOT_IN
|
||||
;
|
||||
|
||||
|
||||
public boolean isNullType() {
|
||||
return this == NULL || this == NOT_NULL;
|
||||
}
|
||||
public boolean isInType() {
|
||||
return this == IN || this == NOT_IN;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.seeyon.utils.form;
|
||||
|
||||
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;
|
||||
@@ -12,34 +10,29 @@ import com.seeyon.ctp.common.po.ctpenumnew.CtpEnumItem;
|
||||
import com.seeyon.ctp.util.JDBCAgent;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class EnumMapUtils {
|
||||
|
||||
public static String getMasterTableEnumItemValue(String formNo,String fieldDisplay, String targetValue) {
|
||||
public static String getEnumItemValueByDisplayValue(FormTableBean formTableBean,String fieldDisplay, String targetValue) {
|
||||
if(targetValue == null || "null".equals(targetValue) || "".equals(targetValue)){
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
FormApi4Cap4 formApi4Cap4 = (FormApi4Cap4) AppContext.getBean("formApi4Cap4");
|
||||
FormBean cap4FormBean = formApi4Cap4.getFormByFormCode(formNo);
|
||||
FormTableBean masterTableBean = cap4FormBean.getMasterTableBean();
|
||||
FormFieldBean beanByDisplay = masterTableBean.getFieldBeanByDisplay(fieldDisplay);
|
||||
FormFieldBean beanByDisplay = formTableBean.getFieldBeanByDisplay(fieldDisplay);
|
||||
if(beanByDisplay == null || beanByDisplay.getEnumId() == 0l) {
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
return getEnumItemValueByEnumId(targetValue, beanByDisplay.getEnumId());
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getEnumItemIdByGroupNameAndItemShowValue(String enumGroupName, String targetValue) {
|
||||
String sql = "SELECT * FROM ctp_enum ce let join ctp_enum_item cei on ce.`ID` = cei.REF_ENUMID where ce.`ENUMNAME` = ? and CEI.`SHOWVALUE` = ?";
|
||||
if(StringUtils.isAnyBlank(enumGroupName, targetValue)){
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
Long enumId = null;
|
||||
JDBCAgent agent = new JDBCAgent();
|
||||
@@ -47,7 +40,7 @@ public class EnumMapUtils {
|
||||
agent.execute(sql, Arrays.asList(enumGroupName,targetValue));
|
||||
List<Map<String, Object>> list = (List<Map<String, Object>>) agent.resultSetToList();
|
||||
if(list == null || list.size() == 0) {
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
Map map = list.get(0);
|
||||
enumId = (Long)map.get("ID");
|
||||
@@ -57,13 +50,13 @@ public class EnumMapUtils {
|
||||
}finally {
|
||||
agent.close();
|
||||
}
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static String getEnumItemValue(String rootPCode, String groupValue, String targetValue) {
|
||||
public static String getEnumItemValueByRootPCode(String rootPCode, String groupValue, String targetValue) {
|
||||
if(targetValue == null || "null".equals(targetValue) || "".equals(targetValue)){
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
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;
|
||||
@@ -72,62 +65,88 @@ public class EnumMapUtils {
|
||||
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 "";
|
||||
return null;
|
||||
}
|
||||
Map map = list.get(0);
|
||||
enumId = (Long)map.get("ID");
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
return null;
|
||||
}finally {
|
||||
agent.close();
|
||||
}
|
||||
EnumManager enumManagerNew = (EnumManager) AppContext.getBean("enumManagerNew");
|
||||
CtpEnumBean ctpEnumBean = enumManagerNew.getEnum(enumId);
|
||||
if(ctpEnumBean == null) {
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
List<CtpEnumItem> ctpEnumItems = ctpEnumBean.getItems();
|
||||
if(ctpEnumBean.getItems() == null) {
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
for (CtpEnumItem enumItem : ctpEnumItems) {
|
||||
if(enumItem.getShowvalue().equals(targetValue)) {
|
||||
return enumItem.getId() + "";
|
||||
}
|
||||
}
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Set<String> getEnumItemValues(FormTableBean formTableBean, String fieldDisplay) {
|
||||
Set<String> set = new HashSet<>();
|
||||
try {
|
||||
FormFieldBean beanByDisplay = formTableBean.getFieldBeanByDisplay(fieldDisplay);
|
||||
if(beanByDisplay == null || beanByDisplay.getEnumId() == 0l) {
|
||||
return set;
|
||||
}
|
||||
EnumManager enumManagerNew = (EnumManager) AppContext.getBean("enumManagerNew");
|
||||
CtpEnumBean ctpEnumBean = enumManagerNew.getEnum(beanByDisplay.getEnumId());
|
||||
|
||||
if(ctpEnumBean == null) {
|
||||
return set;
|
||||
}
|
||||
List<CtpEnumItem> ctpEnumItems = ctpEnumBean.getItems();
|
||||
if(ctpEnumBean.getItems() == null) {
|
||||
return set;
|
||||
}
|
||||
for (CtpEnumItem enumItem : ctpEnumItems) {
|
||||
set.add(enumItem.getShowvalue());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
public static String getEnumItemValueByEnumId(String showValue,long enumId) {
|
||||
EnumManager enumManagerNew = (EnumManager) AppContext.getBean("enumManagerNew");
|
||||
CtpEnumBean ctpEnumBean = enumManagerNew.getEnum(enumId);
|
||||
if(ctpEnumBean == null) {
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
List<CtpEnumItem> ctpEnumItems = ctpEnumBean.getItems();
|
||||
if(ctpEnumBean.getItems() == null) {
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
for (CtpEnumItem enumItem : ctpEnumItems) {
|
||||
if(enumItem.getShowvalue().equals(showValue)) {
|
||||
return enumItem.getId() + "";
|
||||
}
|
||||
}
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getEnumShowValue(Object enumItemId) throws BusinessException {
|
||||
if(enumItemId == null) {
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
Long temp = enumItemId instanceof Long ? (Long)enumItemId : (enumItemId instanceof String ? Long.parseLong((String)enumItemId) : null);
|
||||
if(temp == null) {
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
EnumManager enumManagerNew = (EnumManager) AppContext.getBean("enumManagerNew");
|
||||
CtpEnumItem ctpEnumItem = enumManagerNew.getCtpEnumItem(temp);
|
||||
if(ctpEnumItem == null) {
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
return ctpEnumItem.getShowvalue();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.seeyon.utils.form;
|
||||
|
||||
import com.seeyon.ctp.services.ServiceException;
|
||||
import com.seeyon.v3x.services.form.FormFactory;
|
||||
import com.seeyon.v3x.services.form.bean.FormExport;
|
||||
import com.seeyon.v3x.services.form.bean.RecordExport;
|
||||
import com.seeyon.v3x.services.form.bean.SubordinateFormExport;
|
||||
import com.seeyon.v3x.services.form.bean.ValueExport;
|
||||
@@ -10,14 +13,14 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
//创建无流程表单数据处理工具类
|
||||
public class FormExportUtil {
|
||||
public class FormSaveUtil {
|
||||
|
||||
/**
|
||||
* 设置主表信息
|
||||
* @param map 设置主表字段。Map<主表显示名称,主表数据>
|
||||
* @return
|
||||
*/
|
||||
public List<ValueExport> setFormValue(Map<String, Object> map ){
|
||||
public static List<ValueExport> setFormValue(Map<String, Object> map ){
|
||||
// 创建返回值对象
|
||||
List<ValueExport> valueExports = new ArrayList<ValueExport>();
|
||||
ValueExport valueExport ;
|
||||
@@ -32,7 +35,6 @@ public class FormExportUtil {
|
||||
valueExport.setValue(map.get(key).toString());
|
||||
valueExports.add(valueExport);
|
||||
}
|
||||
System.out.println(key+":"+map.get(key));
|
||||
}
|
||||
}
|
||||
return valueExports;
|
||||
@@ -42,7 +44,7 @@ public class FormExportUtil {
|
||||
* 设置从表信息
|
||||
* @param lists 设置主表字段。List<Map<显示名称,数据值>>
|
||||
*/
|
||||
public List<SubordinateFormExport> setSubordinateFormValue(List<Map<String, Object>> lists){
|
||||
public static List<SubordinateFormExport> setSubordinateFormValue(List<Map<String, Object>> lists){
|
||||
List<SubordinateFormExport> subordinateFormExports = new ArrayList<SubordinateFormExport>();
|
||||
SubordinateFormExport subordinateFormExport = new SubordinateFormExport();
|
||||
List<RecordExport> recordExports = new ArrayList<RecordExport>();
|
||||
@@ -60,7 +62,7 @@ public class FormExportUtil {
|
||||
return subordinateFormExports;
|
||||
}
|
||||
|
||||
public List<SubordinateFormExport> setAllSubordinateFormValue(List<Map<String,Object>> lists){
|
||||
public static List<SubordinateFormExport> setAllSubordinateFormValue(List<Map<String,Object>> lists){
|
||||
List<SubordinateFormExport> subordinateFormExports = new ArrayList<SubordinateFormExport>();
|
||||
for (Map<String, Object> list : lists) {
|
||||
SubordinateFormExport subordinateFormExport = new SubordinateFormExport();
|
||||
@@ -80,5 +82,15 @@ public class FormExportUtil {
|
||||
return subordinateFormExports;
|
||||
}
|
||||
|
||||
|
||||
public static void formSave(String loginName, String formNo, FormFactory formFactory, Map<String,Object> mainFormData, List<Map<String,Object>> subFormDatas) throws ServiceException {
|
||||
FormExport formExport = new FormExport();
|
||||
FormSaveUtil formExportUtil = new FormSaveUtil();
|
||||
List<ValueExport> valueExport = formExportUtil.setFormValue(mainFormData);
|
||||
formExport.setValues(valueExport);
|
||||
if(subFormDatas != null) {
|
||||
formExport.setSubordinateForms(formExportUtil.setAllSubordinateFormValue(subFormDatas));
|
||||
}
|
||||
formFactory.importBusinessFormData(loginName, formNo,
|
||||
formExport, new String[] {});
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ 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;
|
||||
@@ -16,18 +15,16 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class FormTableExecutor {
|
||||
|
||||
/* ========== 表定位 ========== */
|
||||
|
||||
private static final Log log = LogFactory.getLog(FormTableExecutor.class);
|
||||
|
||||
/* ========== 表定位 ========== */
|
||||
|
||||
public TableContext master(String formNo) throws BusinessException {
|
||||
/*获取主表定义bean对象*/
|
||||
public static TableContext master(String formNo) throws BusinessException {
|
||||
FormBean form = getForm(formNo);
|
||||
return new TableContext(form.getMasterTableBean());
|
||||
}
|
||||
|
||||
public TableContext sub(String formNo, String subTable) throws BusinessException {
|
||||
/*获取从表定义bean对象*/
|
||||
public static TableContext sub(String formNo, String subTable) throws BusinessException {
|
||||
FormBean form = getForm(formNo);
|
||||
return form.getSubTableBean().stream()
|
||||
.filter(t -> t.getTableName().equals(subTable) || t.getDisplay().equals(subTable))
|
||||
@@ -36,12 +33,13 @@ public class FormTableExecutor {
|
||||
.orElseThrow(() -> new BusinessException("未找到子表:" + subTable));
|
||||
}
|
||||
|
||||
private FormBean getForm(String formNo) throws BusinessException {
|
||||
private static FormBean getForm(String formNo) throws BusinessException {
|
||||
FormApi4Cap4 api = (FormApi4Cap4) AppContext.getBean("formApi4Cap4");
|
||||
return api.getFormByFormCode(formNo);
|
||||
}
|
||||
|
||||
private void fillUpdateFields(TableContext ctx, List<FormUpdateField> updateFields) {
|
||||
/*填充update字段fieldName*/
|
||||
private static void fillUpdateFields(TableContext ctx, List<FormUpdateField> updateFields) {
|
||||
if (updateFields == null) return;
|
||||
|
||||
for (FormUpdateField c : updateFields) {
|
||||
@@ -52,7 +50,8 @@ public class FormTableExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
private void fillConditionFields(TableContext ctx, List<FormWhereCondition> conditions) {
|
||||
/*填充condition字段fieldName*/
|
||||
private static void fillConditionFields(TableContext ctx, List<FormWhereCondition> conditions) {
|
||||
if (conditions == null) return;
|
||||
|
||||
for (FormWhereCondition c : conditions) {
|
||||
@@ -67,7 +66,8 @@ public class FormTableExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> resolveQueryColumns(TableContext ctx, List<String> displays) {
|
||||
/*将查询列display转换为fieldName*/
|
||||
private static List<String> resolveQueryColumns(TableContext ctx, List<String> displays) {
|
||||
if (displays == null) return Collections.emptyList();
|
||||
return displays.stream()
|
||||
.map(ctx.getTableBean()::getFieldBeanByDisplay)
|
||||
@@ -78,7 +78,7 @@ public class FormTableExecutor {
|
||||
|
||||
/* ========== 查询方法 ========== */
|
||||
|
||||
public List<FormColumn> query(TableContext ctx,
|
||||
public static List<FormColumn> query(TableContext ctx,
|
||||
List<String> queryDisplays,
|
||||
List<FormWhereCondition> conditions,
|
||||
boolean changeEnum) {
|
||||
@@ -110,7 +110,8 @@ public class FormTableExecutor {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public FormColumn queryOne(TableContext ctx,
|
||||
/*查询单条记录*/
|
||||
public static FormColumn queryOne(TableContext ctx,
|
||||
List<FormWhereCondition> conditions,
|
||||
boolean changeEnum) {
|
||||
|
||||
@@ -138,7 +139,8 @@ public class FormTableExecutor {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<FormColumn> pageQuery(TableContext ctx,
|
||||
/*分页查询*/
|
||||
public static List<FormColumn> pageQuery(TableContext ctx,
|
||||
List<String> displays,
|
||||
List<FormWhereCondition> conditions,
|
||||
int pageNo,
|
||||
@@ -174,7 +176,8 @@ public class FormTableExecutor {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public long count(TableContext ctx,List<String> countField,List<FormWhereCondition> conditions) {
|
||||
/*统计数量*/
|
||||
public static long count(TableContext ctx,List<String> countField,List<FormWhereCondition> conditions) {
|
||||
fillConditionFields(ctx, conditions);
|
||||
List<String> countColumn = resolveQueryColumns(ctx,countField);
|
||||
SqlBuildParam param = new SqlBuildParam();
|
||||
@@ -199,8 +202,8 @@ public class FormTableExecutor {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int update(TableContext ctx, List<FormUpdateField> fields, List<FormWhereCondition> conditions) {
|
||||
/*更新操作*/
|
||||
public static int update(TableContext ctx, List<FormUpdateField> fields, List<FormWhereCondition> conditions) {
|
||||
if (fields == null || fields.isEmpty()) throw new IllegalArgumentException("更新字段不能为空");
|
||||
if (conditions == null || conditions.isEmpty()) throw new IllegalArgumentException("UPDATE必须带条件");
|
||||
fillConditionFields(ctx, conditions);
|
||||
@@ -224,7 +227,30 @@ public class FormTableExecutor {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int delete(TableContext ctx, List<FormWhereCondition> conditions) {
|
||||
public static int update(String tableName, List<FormUpdateField> fields, List<FormWhereCondition> conditions) {
|
||||
if (fields == null || fields.isEmpty()) throw new IllegalArgumentException("更新字段不能为空");
|
||||
if (conditions == null || conditions.isEmpty()) throw new IllegalArgumentException("UPDATE必须带条件");
|
||||
SqlBuildParam param = new SqlBuildParam();
|
||||
param.setSqlType(SqlType.UPDATE);
|
||||
param.setTableName(tableName);
|
||||
param.setConditions(conditions);
|
||||
param.setUpdateFields(fields);
|
||||
Map<String, Object> sqlMap = generateSql(param);
|
||||
JDBCAgent agent = new JDBCAgent();
|
||||
try {
|
||||
return agent.execute((String) sqlMap.get("sql"), (List<Object>) sqlMap.get("params"));
|
||||
} catch (Exception e){
|
||||
log.error("执行sql为: " + sqlMap.get("sql"));
|
||||
log.error("执行sql参数为: " + JsonUtils.toJSONString(sqlMap.get("params")));
|
||||
log.error(e.getMessage(),e);
|
||||
}finally {
|
||||
agent.close();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*删除操作*/
|
||||
public static int delete(TableContext ctx, List<FormWhereCondition> conditions) {
|
||||
if (conditions == null || conditions.isEmpty()) throw new IllegalArgumentException("DELETE必须带条件");
|
||||
fillConditionFields(ctx, conditions);
|
||||
SqlBuildParam param = new SqlBuildParam();
|
||||
@@ -247,7 +273,8 @@ public class FormTableExecutor {
|
||||
}
|
||||
/* ========== 构建 FormColumn ========== */
|
||||
|
||||
private FormColumn buildFormColumn(Map<String, Object> row,
|
||||
/*填充结果字段*/
|
||||
private static FormColumn buildFormColumn(Map<String, Object> row,
|
||||
TableContext ctx,
|
||||
boolean changeEnum) {
|
||||
FormColumn column = new FormColumn();
|
||||
@@ -262,10 +289,8 @@ public class FormTableExecutor {
|
||||
if (changeEnum && field.isEnumField()) {
|
||||
value = EnumMapUtils.getEnumShowValue(value);
|
||||
}
|
||||
|
||||
// 枚举、部门、成员等特殊字段处理
|
||||
value = handleFieldSpecialType(field, value);
|
||||
|
||||
// value = handleFieldSpecialType(field, value);
|
||||
FormFieldVo vo = new FormFieldVo();
|
||||
vo.setDisplayName(field.getDisplay());
|
||||
vo.setValue(value);
|
||||
@@ -284,13 +309,13 @@ public class FormTableExecutor {
|
||||
return column;
|
||||
}
|
||||
|
||||
private Object handleFieldSpecialType(FormFieldBean field, Object value) throws BusinessException {
|
||||
private static Object handleFieldSpecialType(FormFieldBean field, Object value) throws BusinessException {
|
||||
if (value == null) return null;
|
||||
|
||||
switch (field.getInputType()) {
|
||||
case "select":
|
||||
if (field.getEnumId() != 0L) {
|
||||
return EnumMapUtils.getEnumItemValueByEnumId(String.valueOf(value), field.getEnumId());
|
||||
if (field.isEnumField()) {
|
||||
return EnumMapUtils.getEnumShowValue(value);
|
||||
}
|
||||
break;
|
||||
case "department":
|
||||
@@ -308,22 +333,7 @@ public class FormTableExecutor {
|
||||
return value;
|
||||
}
|
||||
|
||||
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 != null &&
|
||||
("image".equals(fieldBeanByDisplay.getInputType()) ||
|
||||
"attachment".equals(fieldBeanByDisplay.getInputType()));
|
||||
} catch (BusinessException e) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Map<String, Object> buildCountSql(
|
||||
private static Map<String, Object> buildCountSql(
|
||||
String countField,
|
||||
String tableName,
|
||||
List<FormWhereCondition> conditions) {
|
||||
@@ -337,7 +347,7 @@ public class FormTableExecutor {
|
||||
return buildResult(sql, params);
|
||||
}
|
||||
|
||||
private Map<String, Object> buildSelectSql(
|
||||
private static Map<String, Object> buildSelectSql(
|
||||
String tableName,
|
||||
List<String> queryColumns,
|
||||
List<FormWhereCondition> conditions,
|
||||
@@ -368,13 +378,13 @@ public class FormTableExecutor {
|
||||
sql.append(" order by "+ orderField +" desc");
|
||||
}
|
||||
if(limit != null && offset != null) {
|
||||
sql.append(" "+ offset + "," + limit);
|
||||
sql.append(" LIMIT "+ offset + "," + limit);
|
||||
}
|
||||
sql.append(";");
|
||||
return buildResult(sql, params);
|
||||
}
|
||||
|
||||
private Map<String, Object> buildUpdateSql(
|
||||
private static Map<String, Object> buildUpdateSql(
|
||||
String tableName,
|
||||
List<FormUpdateField> fields,
|
||||
List<FormWhereCondition> conditions) {
|
||||
@@ -417,7 +427,7 @@ public class FormTableExecutor {
|
||||
return buildResult(sql, params);
|
||||
}
|
||||
|
||||
private Map<String, Object> buildDeleteSql(
|
||||
private static Map<String, Object> buildDeleteSql(
|
||||
String tableName,
|
||||
List<FormWhereCondition> conditions) {
|
||||
|
||||
@@ -435,7 +445,7 @@ public class FormTableExecutor {
|
||||
return buildResult(sql, params);
|
||||
}
|
||||
|
||||
private Map<String, Object> buildInsertSql(
|
||||
private static Map<String, Object> buildInsertSql(
|
||||
String tableName,
|
||||
Map<String, Object> data) {
|
||||
|
||||
@@ -474,63 +484,82 @@ public class FormTableExecutor {
|
||||
* @param params 参数列表(引用传递)
|
||||
* @return 拼接后的 WHERE 子句(包含 WHERE 关键字)
|
||||
*/
|
||||
private String buildWhereClause(List<FormWhereCondition> conditions, List<Object> params) {
|
||||
private static 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("(");
|
||||
StringBuilder whereCause = new StringBuilder(" WHERE ");
|
||||
for (int i = 0; i < conditions.size(); i++) {
|
||||
FormWhereCondition c = conditions.get(i);
|
||||
// 左括号
|
||||
if (c.isStartWithBracket()) {
|
||||
whereCause.append("(");
|
||||
}
|
||||
|
||||
// 字段名校验
|
||||
String fieldName = condition.getFieldName();
|
||||
ClauseFactor factor = condition.getClauseFactor();
|
||||
String field = c.getFieldName();
|
||||
ClauseFactor factor = c.getClauseFactor();
|
||||
String operator = parseOperator(factor);
|
||||
|
||||
// 构建条件表达式
|
||||
String conditionExpr;
|
||||
if (factor != null && factor.isNullType()) {
|
||||
// 处理 NULL/NOT NULL 条件(无需参数)
|
||||
conditionExpr = String.format("%s %s", fieldName, operator);
|
||||
// NULL / NOT NULL
|
||||
if (factor.isNullType()) {
|
||||
whereCause.append(field).append(" ").append(operator);
|
||||
} else if (factor.isInType()) {
|
||||
appendInClause(whereCause, field, operator, c.getValue(), params);
|
||||
} else {
|
||||
// 处理普通条件(带占位符)
|
||||
conditionExpr = String.format("%s %s ?", fieldName, operator);
|
||||
// 处理函数模板(如 TO_DATE)
|
||||
if (condition.getIndex() != null) {
|
||||
conditionExpr = conditionExpr.replace("?", condition.getIndex());
|
||||
String placeholder = "?";
|
||||
// 函数模板(如 TO_DATE(?))
|
||||
if (c.getIndex() != null) {
|
||||
placeholder = c.getIndex();
|
||||
}
|
||||
whereCause.append(field).append(" ").append(operator).append(" ").append(placeholder);
|
||||
if (ClauseFactor.LIKE.equals(factor)) {
|
||||
params.add("%" + c.getValue() + "%");
|
||||
} else {
|
||||
params.add(c.getValue());
|
||||
}
|
||||
// 添加参数值
|
||||
params.add(condition.getValue());
|
||||
}
|
||||
|
||||
whereClause.append(conditionExpr);
|
||||
|
||||
// 处理括号闭合
|
||||
if (condition.isEndWithBracket()) {
|
||||
whereClause.append(")");
|
||||
// 右括号
|
||||
if (c.isEndWithBracket()) {
|
||||
whereCause.append(")");
|
||||
}
|
||||
|
||||
// 添加连接符(AND/OR)
|
||||
if (conditionIndex < conditions.size() - 1) {
|
||||
whereClause.append(" ").append(condition.getConcatFactor()).append(" ");
|
||||
// AND / OR
|
||||
if (i < conditions.size() - 1) {
|
||||
whereCause.append(" ").append(c.getConcatFactor()).append(" ");
|
||||
}
|
||||
conditionIndex++;
|
||||
}
|
||||
|
||||
return whereClause.toString();
|
||||
return whereCause.toString();
|
||||
}
|
||||
|
||||
private static void appendInClause(
|
||||
StringBuilder sql,
|
||||
String field,
|
||||
String operator,
|
||||
Object value,
|
||||
List<Object> params) {
|
||||
if (!(value instanceof Collection)) {
|
||||
throw new IllegalArgumentException("IN 条件的值必须是 Collection");
|
||||
}
|
||||
Collection<?> values = (Collection<?>) value;
|
||||
if (values.isEmpty()) {
|
||||
// 防止 SQL 语法错误
|
||||
sql.append("1 = 0");
|
||||
return;
|
||||
}
|
||||
sql.append(field).append(" ").append(operator).append(" (");
|
||||
int index = 0;
|
||||
for (Object v : values) {
|
||||
if (index > 0) {
|
||||
sql.append(", ");
|
||||
}
|
||||
sql.append("?");
|
||||
params.add(v);
|
||||
index++;
|
||||
}
|
||||
sql.append(")");
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析运算符映射(eq -> =, lt -> < 等)
|
||||
*/
|
||||
private String parseOperator(ClauseFactor factor) {
|
||||
private static String parseOperator(ClauseFactor factor) {
|
||||
if(factor == null) {
|
||||
return "=";
|
||||
}
|
||||
@@ -547,14 +576,14 @@ public class FormTableExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> buildResult(StringBuilder sql, List<Object> params) {
|
||||
private static Map<String, Object> buildResult(StringBuilder sql, List<Object> params) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("sql", sql.toString());
|
||||
result.put("params", params);
|
||||
return result;
|
||||
}
|
||||
|
||||
private Map<String, Object> generateSql(SqlBuildParam param) {
|
||||
private static Map<String, Object> generateSql(SqlBuildParam param) {
|
||||
|
||||
if (param == null || param.getSqlType() == null) {
|
||||
throw new IllegalArgumentException("SqlBuildParam or SqlType cannot be null");
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
package com.seeyon.utils.form;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FormWhereCondition {
|
||||
private String display;
|
||||
private String fieldName; //字段名
|
||||
private Object value; //值
|
||||
private ClauseFactor clauseFactor; //条件因子 eq lt gt not_null null
|
||||
private List<Object> values; //值
|
||||
private ClauseFactor clauseFactor = ClauseFactor.EQ; //条件因子 eq lt gt not_null null
|
||||
private ClauseFactor concatFactor = ClauseFactor.AND; //拼接因子
|
||||
private boolean startWithBracket = false; //是否以括号开头生成子条件
|
||||
private boolean endWithBracket = false; //是否以括号结尾结束子条件
|
||||
private String index;
|
||||
|
||||
public FormWhereCondition() {
|
||||
this.values = new ArrayList<>();
|
||||
}
|
||||
|
||||
public String getDisplay() {
|
||||
@@ -52,6 +57,11 @@ public class FormWhereCondition {
|
||||
return this;
|
||||
}
|
||||
|
||||
public FormWhereCondition fieldName(String fieldName) {
|
||||
this.fieldName = fieldName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FormWhereCondition concatFactor(ClauseFactor concatFactor) {
|
||||
this.concatFactor = concatFactor;
|
||||
return this;
|
||||
@@ -118,4 +128,15 @@ public class FormWhereCondition {
|
||||
public void setEndWithBracket(boolean endWithBracket) {
|
||||
this.endWithBracket = endWithBracket;
|
||||
}
|
||||
|
||||
public List<Object> getValues() {
|
||||
return values;
|
||||
}
|
||||
public FormWhereCondition addValue(Object value) {
|
||||
this.values.add(value);
|
||||
return this;
|
||||
}
|
||||
public void setValues(List<Object> values) {
|
||||
this.values = values;
|
||||
}
|
||||
}
|
||||
|
||||
503
src/main/java/com/seeyon/utils/http/FileUtil.java
Normal file
503
src/main/java/com/seeyon/utils/http/FileUtil.java
Normal file
@@ -0,0 +1,503 @@
|
||||
package com.seeyon.utils.http;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.seeyon.ctp.common.AppContext;
|
||||
import com.seeyon.ctp.common.SystemEnvironment;
|
||||
import com.seeyon.ctp.common.exceptions.BusinessException;
|
||||
import com.seeyon.ctp.common.filemanager.manager.AttachmentManager;
|
||||
import com.seeyon.ctp.common.filemanager.manager.FileManager;
|
||||
import com.seeyon.ctp.common.po.filemanager.Attachment;
|
||||
import com.seeyon.ctp.organization.bo.V3xOrgAccount;
|
||||
import com.seeyon.ctp.organization.bo.V3xOrgMember;
|
||||
import com.seeyon.ctp.organization.manager.OrgManager;
|
||||
import com.seeyon.ctp.services.FileUploadExporter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import www.seeyon.com.utils.StringUtil;
|
||||
import www.seeyon.com.utils.UUIDUtil;
|
||||
|
||||
import java.io.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class FileUtil {
|
||||
|
||||
private static final long MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
|
||||
private static final String TEMP_DIR = System.getProperty("java.io.tmpdir") + File.separator + "seeyontempfile";
|
||||
private static final String DEFAULT_FILENAME_PREFIX = "没有文件名_";
|
||||
private static final String CATEGORY_CODE = "66";
|
||||
private FileManager fileManager;
|
||||
|
||||
public void setFileManager(FileManager fileManager) {
|
||||
this.fileManager = fileManager;
|
||||
}
|
||||
|
||||
public FileManager getFileManager() {
|
||||
if (fileManager == null) {
|
||||
fileManager = (FileManager) AppContext.getBean("fileManager");
|
||||
}
|
||||
return fileManager;
|
||||
}
|
||||
|
||||
private AttachmentManager attachmentManager;
|
||||
|
||||
public void setAttachmentManager(AttachmentManager attachmentManager) {
|
||||
this.attachmentManager = attachmentManager;
|
||||
}
|
||||
|
||||
public AttachmentManager getAttachmentManager() {
|
||||
if (attachmentManager == null) {
|
||||
attachmentManager = (AttachmentManager) AppContext.getBean("attachmentManager");
|
||||
}
|
||||
return attachmentManager;
|
||||
}
|
||||
|
||||
public void isFilePath(String filePath) {
|
||||
File directory = new File(filePath);
|
||||
if (!directory.exists()) {
|
||||
directory.mkdirs();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传附件
|
||||
*
|
||||
* @param fileNames
|
||||
* @throws Exception
|
||||
* @throws NumberFormatException
|
||||
*/
|
||||
public List<Attachment> fileUpload(List<String> fileNames, String summaryId, Long memberId, Long accountId) throws NumberFormatException, Exception {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
FileUploadExporter fileUpload = new FileUploadExporter();
|
||||
List<Attachment> attachments = new ArrayList<Attachment>();
|
||||
File f = null;
|
||||
long l = UUIDUtil.getUUIDLong();
|
||||
for (int i = 0; i < fileNames.size(); i++) {
|
||||
String fileName = fileNames.get(i);
|
||||
if (StringUtils.isNotEmpty(fileName)) {
|
||||
f = new File(fileName);
|
||||
if (!f.exists()) {
|
||||
return null;
|
||||
}
|
||||
if (f.length() > 102400000) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
String[] strs = new String[]{f.getAbsolutePath()};
|
||||
String s = fileUpload.processUpload(strs);
|
||||
Map<String, String> map = new HashMap();
|
||||
String attachName = f.getName();
|
||||
String[] suffixNames = attachName.split("\\.");
|
||||
map.put("type", "0");
|
||||
map.put("fileUrl", s);
|
||||
map.put("mimeType", "application/" + suffixNames[suffixNames.length - 1].toLowerCase());
|
||||
map.put("size", f.length() + "");
|
||||
map.put("subReference", l + "");
|
||||
map.put("category", "66");
|
||||
map.put("createdate", sdf.format(new Date()));
|
||||
map.put("filename", f.getName());
|
||||
map.put("reference", summaryId);
|
||||
Attachment attachment = new Attachment(map);
|
||||
attachments.add(attachment);
|
||||
}
|
||||
String str = getAttachmentManager().create(attachments, memberId, accountId);
|
||||
return attachments;
|
||||
}
|
||||
|
||||
|
||||
public List<String> fieldFileDownload(Long refId, String path) throws BusinessException {
|
||||
// 判断路径是否存在
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
List<Long> fileUrls = getAttachmentManager().getBySubReference(refId);
|
||||
System.out.println(fileUrls.size());
|
||||
List<String> filepaths = new ArrayList<>();
|
||||
for (Long fileUrl : fileUrls) {
|
||||
Attachment attachment = getAttachmentManager().getAttachmentByFileURL(fileUrl);
|
||||
InputStream inputStream = getFileManager().getFileInputStream(attachment.getFileUrl());
|
||||
String filepath = path + attachment.getFilename();
|
||||
try (OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(filepath))) {
|
||||
byte[] buffer = new byte[1024];
|
||||
int bytesRead;
|
||||
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||
outputStream.write(buffer, 0, bytesRead);
|
||||
}
|
||||
outputStream.flush();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
filepaths.add(filepath);
|
||||
}
|
||||
return filepaths;
|
||||
}
|
||||
|
||||
|
||||
public JSONArray getFileContent(String filePath) throws IOException {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
String houzhui = filePath.substring(filePath.lastIndexOf(".") + 1);
|
||||
// 创建文件输入流
|
||||
FileInputStream file = new FileInputStream(new File(filePath));
|
||||
// 创建工作簿对象
|
||||
Workbook workbook;
|
||||
System.out.println("当前文件为"+houzhui+"后缀");
|
||||
if ("xlsx".equals(houzhui) || "XLSX".equals(houzhui)) {
|
||||
workbook = new XSSFWorkbook(file);
|
||||
} else {
|
||||
workbook = new HSSFWorkbook(file);
|
||||
}
|
||||
// 获取第一个工作表
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
// 迭代行
|
||||
Iterator<Row> rowIterator = sheet.iterator();
|
||||
// 根据行跳过设置
|
||||
row : while (rowIterator.hasNext()) {
|
||||
Row row = rowIterator.next();
|
||||
if (row.getRowNum() < 2) {
|
||||
continue;
|
||||
}
|
||||
int num = 0;
|
||||
int bj = 0;
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
JSONArray SPS = new JSONArray();
|
||||
JSONObject SP = new JSONObject();
|
||||
boolean isddh = false;
|
||||
|
||||
// 迭代单元格
|
||||
Iterator<Cell> cellIterator = row.cellIterator();
|
||||
cell : while (cellIterator.hasNext()) {
|
||||
// 获取单元格对象
|
||||
Cell cell = cellIterator.next();
|
||||
// 单元格索引为1的数据(订单号)
|
||||
if (cell.getColumnIndex() == 1) {
|
||||
String ddh = "";
|
||||
switch (cell.getCellType()) {
|
||||
case STRING:
|
||||
ddh = cell.getStringCellValue();
|
||||
break;
|
||||
case NUMERIC:
|
||||
ddh = cell.getNumericCellValue()+"";
|
||||
break;
|
||||
default:
|
||||
ddh = "";
|
||||
}
|
||||
// 如果当前订单号为空,则跳过当前行数据
|
||||
// 查询当前订单号是否已经存在
|
||||
for (int i = 0; i < jsonArray.size(); i++) {
|
||||
JSONObject json = jsonArray.getJSONObject(i);
|
||||
if (ddh.equals(json.getString("DDH"))) {
|
||||
// 订单号已经存在
|
||||
bj = i;
|
||||
isddh = true;
|
||||
jsonObject = json;
|
||||
SPS = jsonObject.getJSONArray("SPS");
|
||||
} else {
|
||||
num++;
|
||||
}
|
||||
}
|
||||
if (num == jsonArray.size()) {
|
||||
// switch (cell.getCellType()) {
|
||||
// case STRING:
|
||||
jsonObject.put("DDH",ddh);
|
||||
// break;
|
||||
// case NUMERIC:
|
||||
// jsonObject.put("DDH", cell.getNumericCellValue());
|
||||
// break;
|
||||
// default:
|
||||
// jsonObject.put("DDH", "");
|
||||
// }
|
||||
//// jsonObject.put("DDH", cell.getStringCellValue());
|
||||
}
|
||||
}
|
||||
switch (cell.getColumnIndex()) {
|
||||
case 3:
|
||||
if (!isddh) {
|
||||
switch (cell.getCellType()) {
|
||||
case STRING:
|
||||
jsonObject.put("GMFMC", cell.getStringCellValue());
|
||||
break;
|
||||
case NUMERIC:
|
||||
jsonObject.put("GMFMC", cell.getNumericCellValue());
|
||||
break;
|
||||
default:
|
||||
jsonObject.put("GMFMC", "");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (!isddh) {
|
||||
switch (cell.getCellType()) {
|
||||
case STRING:
|
||||
jsonObject.put("GMFNSRSBH", cell.getStringCellValue());
|
||||
break;
|
||||
case NUMERIC:
|
||||
jsonObject.put("GMFNSRSBH", cell.getNumericCellValue());
|
||||
break;
|
||||
default:
|
||||
jsonObject.put("GMFNSRSBH", "");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
if (!isddh) {
|
||||
switch (cell.getCellType()) {
|
||||
case STRING:
|
||||
jsonObject.put("GMFYX", cell.getStringCellValue());
|
||||
break;
|
||||
case NUMERIC:
|
||||
jsonObject.put("GMFYX", cell.getNumericCellValue());
|
||||
break;
|
||||
default:
|
||||
jsonObject.put("GMFYX", "");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
if (!isddh) {
|
||||
switch (cell.getCellType()) {
|
||||
case STRING:
|
||||
jsonObject.put("GMFSJ", cell.getStringCellValue());
|
||||
break;
|
||||
case NUMERIC:
|
||||
jsonObject.put("GMFSJ", cell.getNumericCellValue());
|
||||
break;
|
||||
default:
|
||||
jsonObject.put("GMFSJ", "");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 17:
|
||||
if (!isddh) {
|
||||
switch (cell.getCellType()) {
|
||||
case STRING:
|
||||
jsonObject.put("BZ", cell.getStringCellValue());
|
||||
break;
|
||||
case NUMERIC:
|
||||
jsonObject.put("BZ", cell.getNumericCellValue());
|
||||
break;
|
||||
default:
|
||||
jsonObject.put("BZ", "");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
switch (cell.getCellType()) {
|
||||
case STRING:
|
||||
SP.put("FXHXZ", cell.getStringCellValue());
|
||||
break;
|
||||
case NUMERIC:
|
||||
SP.put("FXHXZ", cell.getNumericCellValue());
|
||||
break;
|
||||
default:
|
||||
SP.put("FXHXZ", "");
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
switch (cell.getCellType()) {
|
||||
case STRING:
|
||||
SP.put("XMMC", cell.getStringCellValue());
|
||||
break;
|
||||
case NUMERIC:
|
||||
SP.put("XMMC", cell.getNumericCellValue());
|
||||
break;
|
||||
default:
|
||||
SP.put("XMMC", "");
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
switch (cell.getCellType()) {
|
||||
case STRING:
|
||||
SP.put("SPBM", cell.getStringCellValue());
|
||||
break;
|
||||
case NUMERIC:
|
||||
SP.put("SPBM", cell.getNumericCellValue());
|
||||
break;
|
||||
default:
|
||||
SP.put("SPBM", "");
|
||||
}
|
||||
break;
|
||||
case 9:
|
||||
switch (cell.getCellType()) {
|
||||
case STRING:
|
||||
SP.put("GGXH", cell.getStringCellValue());
|
||||
break;
|
||||
case NUMERIC:
|
||||
SP.put("GGXH", cell.getNumericCellValue());
|
||||
break;
|
||||
default:
|
||||
SP.put("GGXH", "");
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
switch (cell.getCellType()) {
|
||||
case STRING:
|
||||
SP.put("DW", cell.getStringCellValue());
|
||||
break;
|
||||
case NUMERIC:
|
||||
SP.put("DW", cell.getNumericCellValue());
|
||||
break;
|
||||
default:
|
||||
SP.put("DW", "");
|
||||
}
|
||||
break;
|
||||
case 11:
|
||||
switch (cell.getCellType()) {
|
||||
case STRING:
|
||||
SP.put("NUM", cell.getStringCellValue());
|
||||
break;
|
||||
case NUMERIC:
|
||||
SP.put("NUM", cell.getNumericCellValue());
|
||||
break;
|
||||
default:
|
||||
SP.put("NUM", "");
|
||||
}
|
||||
break;
|
||||
case 12:
|
||||
switch (cell.getCellType()) {
|
||||
case STRING:
|
||||
SP.put("SPDJ", cell.getStringCellValue());
|
||||
break;
|
||||
case NUMERIC:
|
||||
SP.put("SPDJ", cell.getNumericCellValue());
|
||||
break;
|
||||
default:
|
||||
SP.put("SPDJ", "");
|
||||
}
|
||||
break;
|
||||
case 13:
|
||||
switch (cell.getCellType()) {
|
||||
case STRING:
|
||||
SP.put("JE", cell.getStringCellValue());
|
||||
break;
|
||||
case NUMERIC:
|
||||
SP.put("JE", cell.getNumericCellValue());
|
||||
break;
|
||||
default:
|
||||
SP.put("JE", "");
|
||||
}
|
||||
break;
|
||||
case 14:
|
||||
switch (cell.getCellType()) {
|
||||
case STRING:
|
||||
SP.put("SL", cell.getStringCellValue());
|
||||
break;
|
||||
case NUMERIC:
|
||||
SP.put("SL", cell.getNumericCellValue());
|
||||
break;
|
||||
default:
|
||||
SP.put("SL", "");
|
||||
}
|
||||
break;
|
||||
case 15:
|
||||
switch (cell.getCellType()) {
|
||||
case STRING:
|
||||
SP.put("ZKJE", cell.getStringCellValue());
|
||||
break;
|
||||
case NUMERIC:
|
||||
SP.put("ZKJE", cell.getNumericCellValue());
|
||||
break;
|
||||
default:
|
||||
SP.put("ZKJE", "");
|
||||
}
|
||||
break;
|
||||
case 16:
|
||||
switch (cell.getCellType()) {
|
||||
case STRING:
|
||||
SP.put("YHZCBS", cell.getStringCellValue());
|
||||
break;
|
||||
case NUMERIC:
|
||||
SP.put("YHZCBS", cell.getNumericCellValue());
|
||||
break;
|
||||
default:
|
||||
SP.put("YHZCBS", "");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(StringUtil.isEmpty(jsonObject.getString("DDH"))){
|
||||
continue row;
|
||||
}
|
||||
SPS.add(SP);
|
||||
jsonObject.put("SPS", SPS);
|
||||
if (num == jsonArray.size()) {
|
||||
jsonArray.add(jsonObject);
|
||||
} else {
|
||||
jsonArray.set(bj, jsonObject);
|
||||
}
|
||||
}
|
||||
// 关闭工作簿
|
||||
workbook.close();
|
||||
file.close();
|
||||
return jsonArray;
|
||||
}
|
||||
|
||||
public JSONArray getFileContent(long fileId) throws IOException {
|
||||
System.out.println("获取参数附件ID"+fileId);
|
||||
// 附件路径
|
||||
String path = SystemEnvironment.getApplicationFolder()+"/hxinvoiceFile/"+fileId+"/";
|
||||
System.out.println("文件下载路径"+path);
|
||||
List<Long> fileUrls = getAttachmentManager().getBySubReference(fileId);
|
||||
Attachment attachment = getAttachmentManager().getAttachmentByFileURL(fileUrls.get(0));
|
||||
String filePath = path+attachment.getFilename();
|
||||
JSONArray jsonArray = getFileContent(filePath);
|
||||
return jsonArray;
|
||||
}
|
||||
|
||||
|
||||
public static String uploadContractToOA(Object[] fileInfos, String formId, String loginName, String updateAccountName) throws Exception {
|
||||
|
||||
OrgManager orgManager = (OrgManager) AppContext.getBean("orgManager");
|
||||
V3xOrgMember member = orgManager.getMemberByLoginName(loginName);
|
||||
V3xOrgAccount account = orgManager.getAccountByName(updateAccountName);
|
||||
String refId = String.valueOf(Math.abs(UUID.randomUUID().getLeastSignificantBits()));
|
||||
List<Attachment> attachments = new ArrayList<>();
|
||||
File tempDir = new File(TEMP_DIR);
|
||||
if (!tempDir.exists()) {
|
||||
tempDir.mkdirs();
|
||||
}
|
||||
for (Object fileInfo : fileInfos) {
|
||||
Map<String, Object> fileInfoMap = (Map<String, Object>) fileInfo;
|
||||
String fileName = (String) fileInfoMap.get("fileName");
|
||||
String url = (String) fileInfoMap.get("downloadUrl");
|
||||
String savePath = TEMP_DIR + File.separator + fileName;
|
||||
HttpClient.httpDownloadFile(url, null,savePath,"ITF-8");
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
FileUploadExporter fileUpload = new FileUploadExporter();
|
||||
File file = new File(savePath);
|
||||
if (file.exists() && file.length() <= MAX_FILE_SIZE) {
|
||||
String uploadedPath = fileUpload.processUpload(new String[]{file.getAbsolutePath()});
|
||||
Map<String, String> attachMeta = new HashMap<>();
|
||||
attachMeta.put("type", "0");
|
||||
attachMeta.put("fileUrl", uploadedPath);
|
||||
attachMeta.put("size", String.valueOf(file.length()));
|
||||
attachMeta.put("subReference", refId);
|
||||
attachMeta.put("category", CATEGORY_CODE);
|
||||
attachMeta.put("createdate", sdf.format(new Date()));
|
||||
attachMeta.put("filename", fileName);
|
||||
attachMeta.put("reference", formId);
|
||||
attachMeta.put("mimeType", "application/" + "pdf");
|
||||
attachments.add(new Attachment(attachMeta));
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
if (attachments.isEmpty()) return null;
|
||||
AttachmentManager attachmentManager = (AttachmentManager) AppContext.getBean("attachmentManager");
|
||||
attachmentManager.create(attachments, member.getId(), account.getId());
|
||||
return refId;
|
||||
}
|
||||
|
||||
private static boolean isBlank(String str) {
|
||||
return str == null || str.trim().isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -246,18 +246,18 @@ public class HttpClient {
|
||||
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;
|
||||
}
|
||||
|
||||
32
src/main/java/com/seeyon/utils/http/OaResp.java
Normal file
32
src/main/java/com/seeyon/utils/http/OaResp.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package com.seeyon.utils.http;
|
||||
|
||||
public class OaResp {
|
||||
|
||||
private Integer code;
|
||||
private String message;
|
||||
private Object data;
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Object getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(Object data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
114
src/main/java/com/seeyon/utils/http/OaRestClient.java
Normal file
114
src/main/java/com/seeyon/utils/http/OaRestClient.java
Normal file
@@ -0,0 +1,114 @@
|
||||
package com.seeyon.utils.http;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.seeyon.aicloud.common.JsonUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
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 org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class OaRestClient {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(OaRestClient.class);
|
||||
private String oaHost;
|
||||
private String restName;
|
||||
private String restPwd;
|
||||
private Boolean cacheToken = false;
|
||||
private ConcurrentHashMap<String, String> tokenCache = new ConcurrentHashMap<>();
|
||||
|
||||
public OaRestClient(String oaHost, String restName, String restPwd, Boolean cacheToken) {
|
||||
this.oaHost = oaHost;
|
||||
this.restName = restName;
|
||||
this.restPwd = restPwd;
|
||||
this.cacheToken = cacheToken;
|
||||
}
|
||||
|
||||
public OaResp sendGet(String bizName, String url) throws Exception {
|
||||
Map<String,String> headers = new HashMap<>();
|
||||
headers.put("token",getToken());
|
||||
log.info(bizName + "请求链接为:" + url);
|
||||
String respStr = HttpClient.httpGet(oaHost + "/seeyon/rest" + url,headers,null);
|
||||
log.info(bizName + "响应结果为:" + respStr);
|
||||
return resovleResp(respStr);
|
||||
}
|
||||
|
||||
public OaResp sendPost(String bizName,String url,Map<String,Object> params) throws Exception {
|
||||
Map<String,String> headers = new HashMap<>();
|
||||
headers.put("token",getToken());
|
||||
String paramStr = JsonUtils.toJSONString(params);
|
||||
log.info(bizName + "请求参数为:" + paramStr);
|
||||
String respStr = HttpClient.httpPostRaw(oaHost + "/seeyon/rest" + url,paramStr,headers,null);
|
||||
log.info(bizName + "响应结果为:" + respStr);
|
||||
return resovleResp(respStr);
|
||||
}
|
||||
|
||||
OaResp resovleResp(String respStr){
|
||||
return JsonUtils.parseObject(respStr,OaResp.class);
|
||||
}
|
||||
|
||||
private String applyToken() {
|
||||
String url = oaHost +"/seeyon/rest/token/" + restName + "/" + restPwd + "?loginName=" + restName;
|
||||
DefaultHttpClient client = new DefaultHttpClient();
|
||||
String result = "";
|
||||
HttpGet get = new HttpGet(url);
|
||||
// 添加 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 = null;
|
||||
if(result.contains("{")) {
|
||||
JSONObject jsObj = JSONObject.parseObject(result);
|
||||
token = jsObj.get("id").toString();
|
||||
}else {
|
||||
token = result;
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
private String getToken(){
|
||||
if(cacheToken) {
|
||||
String token = tokenCache.get(restName);
|
||||
if(token != null && !checkExpire(token)) {
|
||||
return token;
|
||||
}else {
|
||||
String tokenStr = applyToken();
|
||||
tokenCache.put(restName, tokenStr);
|
||||
return tokenStr;
|
||||
}
|
||||
}
|
||||
return applyToken();
|
||||
}
|
||||
|
||||
private boolean checkExpire(String token) {
|
||||
String url = oaHost + "/seeyon/rest/cap4/batch/refresh";
|
||||
try{
|
||||
Map<String,String> headers = new HashMap<>();
|
||||
headers.put("token",token);
|
||||
headers.put("loginName",restName);
|
||||
String respStr = HttpClient.httpPostRaw(url, null, headers,null);
|
||||
Map map = JsonUtils.parseObject(respStr, Map.class);
|
||||
if("0".equals(map.get("code"))) {
|
||||
return false;
|
||||
}else {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
5
src/test/OaRestClientTest.java
Normal file
5
src/test/OaRestClientTest.java
Normal file
@@ -0,0 +1,5 @@
|
||||
public class OaRestClientTest {
|
||||
public static void main(String[] args) {
|
||||
OaRestClientTest oaRestClientTest = new OaRestClientTest();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user