| | |
| | | package com.product.module.data.service; |
| | | |
| | | |
| | | import cn.hutool.core.util.NumberUtil; |
| | | import cn.hutool.core.util.ReflectUtil; |
| | | import cn.hutool.extra.spring.SpringUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.google.common.collect.Lists; |
| | | import com.google.common.collect.Maps; |
| | |
| | | import com.product.core.service.support.QueryFilterService; |
| | | import com.product.core.spring.context.SpringMVCContextHolder; |
| | | import com.product.core.transfer.Transactional; |
| | | import com.product.core.util.ReflectUtil; |
| | | import com.product.file.service.FileManagerService; |
| | | import com.product.module.data.config.CmnCode; |
| | | import com.product.module.data.config.CmnConst; |
| | |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.lang.reflect.Method; |
| | | import java.lang.reflect.ParameterizedType; |
| | | import java.lang.reflect.Type; |
| | | import java.util.*; |
| | | |
| | | @Service |
| | |
| | | } |
| | | subDte = new DataTableEntity(); |
| | | mainFse = null; |
| | | for (String excelHeader : list.get(0)) { |
| | | for (String excelHeader : list.get(list.size() - 1)) { |
| | | if (StringUtils.isEmpty(excelHeader)) { |
| | | throw new BaseException(CmnCode.UPLOAD_TEMPLATE_EXISTS_EMPTY_COL.getValue(), CmnCode.UPLOAD_TEMPLATE_EXISTS_EMPTY_COL.getText()); |
| | | } |
| | |
| | | } else { |
| | | mainFse.removeSubData(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB); |
| | | } |
| | | mainFse.setValue("start_row_index", list.size() - 1); |
| | | mainFse.addSubDataTable(subDte); |
| | | index++; |
| | | } |
| | |
| | | int index = 0; |
| | | FieldSetEntity curTemplateFse; |
| | | Map<String, FieldSetEntity> curSubMap; |
| | | List<List<List<String>>> headerDataList = Lists.newArrayList(); |
| | | List<Map<String, FieldSetEntity>> fieldInfoList = Lists.newArrayList(); |
| | | FieldSetEntity curFieldFse; |
| | | FieldSetEntity recordFse;// 业务表fse |
| | |
| | | curTemplateFse = templateDte.getFieldSetEntity(index); |
| | | curSubMap = dte2Map(curTemplateFse.getSubDataTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB), CmnConst.FIELD_EXCEL_HEADER); |
| | | fieldInfoList.add(curSubMap); |
| | | titleList = dataList.get(0); |
| | | // 字段对应的excel 表头索引 |
| | | Map<String, String> fieldIndex = Maps.newHashMap(); |
| | | for (int i = 1; i < dataList.size(); i++) { |
| | | //表头开始行 cheng update 2023年6月30日15:48:22 多行头时,表头开始行不一定是第一行 |
| | | int startRowIndex = 1; |
| | | if (!StringUtils.isEmpty(curTemplateFse.getString("start_row_index")) && NumberUtil.isNumber(curTemplateFse.getString("start_row_index"))) { |
| | | startRowIndex = Integer.parseInt(curTemplateFse.getString("start_row_index")) + 1; |
| | | if (startRowIndex < 1) { |
| | | startRowIndex = 1; |
| | | } |
| | | } |
| | | |
| | | titleList = dataList.get(startRowIndex); |
| | | if (startRowIndex > 0) { |
| | | headerDataList.add(dataList.subList(0, startRowIndex)); |
| | | } else { |
| | | headerDataList.add(new ArrayList<>()); |
| | | } |
| | | for (int i = startRowIndex; i < dataList.size(); i++) { |
| | | rowList = dataList.get(i); |
| | | recordFse = new FieldSetEntity(); |
| | | recordFse.setTableName(curTemplateFse.getString(CmnConst.FIELD_TABLE_NAME)); |
| | |
| | | |
| | | // 保存前处理 |
| | | try { |
| | | tempDte = spDeal(templateDte.getFieldSetEntity(i).getString(CmnConst.FIELD_BEFORE_FUNC), tempDte); |
| | | tempDte = spDeal(templateDte.getFieldSetEntity(i).getString(CmnConst.FIELD_BEFORE_FUNC), tempDte, headerDataList.get(i)); |
| | | if (BaseUtil.dataTableIsEmpty(tempDte)) { |
| | | throw new BaseException(CmnCode.UPLOAD_TEMPLATE_BEFORE_FUNC_EXEC_NO_DATA.getValue(), CmnCode.UPLOAD_TEMPLATE_BEFORE_FUNC_EXEC_NO_DATA.getText()); |
| | | } |
| | |
| | | |
| | | // 保存后处理 |
| | | try { |
| | | spDeal(templateDte.getFieldSetEntity(i).getString(CmnConst.FIELD_AFTER_FUNC), tempDte); |
| | | spDeal(templateDte.getFieldSetEntity(i).getString(CmnConst.FIELD_AFTER_FUNC), tempDte, headerDataList.get(i)); |
| | | } catch (BaseException e) { |
| | | SpringMVCContextHolder.getSystemLogger().error(e); |
| | | } catch (Exception e) { |
| | |
| | | * |
| | | * @param functionContent |
| | | * @param dte |
| | | * @param headerDataList |
| | | * @return |
| | | */ |
| | | private DataTableEntity spDeal(String functionContent, DataTableEntity dte) throws BaseException { |
| | | private DataTableEntity spDeal(String functionContent, DataTableEntity dte, List<List<String>> headerDataList) throws BaseException { |
| | | if (functionContent == null) { |
| | | return dte; |
| | | } |
| | |
| | | } |
| | | String className = functionContent.substring(0, functionContent.indexOf(".")); |
| | | String methodName = functionContent.substring(functionContent.indexOf(".") + 1, functionContent.indexOf("(")); |
| | | Object resultObj = ReflectUtil.invoke(className, methodName, new Object[]{dte}); |
| | | return (DataTableEntity) resultObj; |
| | | //根据className获取类 |
| | | Object bean = SpringUtil.getBean(className); |
| | | //使用huTool的反射工具类获取方法,方法的参数类型为DataTableEntity、List<List<String>> |
| | | Method method = ReflectUtil.getMethod(bean.getClass(), methodName, DataTableEntity.class, List.class); |
| | | if (method != null) { |
| | | //判断method返回值为DataTableEntity |
| | | boolean isBackDataTable = !method.getReturnType().equals(DataTableEntity.class); |
| | | //判断第二个参数的泛型类型 |
| | | Type[] types = method.getGenericParameterTypes(); |
| | | Type type = types[1]; |
| | | //判断类型是否为List<List<String>>,如果是则调用方法 |
| | | if (isBackDataTable && type.getTypeName().equals("java.util.List<java.util.List<java.lang.String>>")) { |
| | | return ReflectUtil.invoke(bean, methodName, dte, headerDataList); |
| | | } |
| | | } |
| | | |
| | | return ReflectUtil.invoke(bean, methodName, dte); |
| | | } |
| | | |
| | | /** |