chengqiang 3 anos atrás
pai
commit
9dbb5d68ed

+ 151 - 0
src/main/java/com/jeeplus/common/utils/excel/ImportExcel.java

@@ -402,6 +402,157 @@ public class ImportExcel {
 		return dataList;
 		return dataList;
 	}
 	}
 
 
+	/**
+	 * 获取导入数据列表,470行小于号改为小于等于,用于处理读取行数问题
+	 * @param cls 导入对象类型
+	 * @param groups 导入分组
+	 */
+	public <E> List<E> getDataListNew(Class<E> cls, int... groups) throws InstantiationException, IllegalAccessException{
+		List<Object[]> annotationList = Lists.newArrayList();
+		// Get annotation field
+		Field[] fs = cls.getDeclaredFields();
+		for (Field f : fs){
+			ExcelField ef = f.getAnnotation(ExcelField.class);
+			if (ef != null && (ef.type()==0 || ef.type()==2)){
+				if (groups!=null && groups.length>0){
+					boolean inGroup = false;
+					for (int g : groups){
+						if (inGroup){
+							break;
+						}
+						for (int efg : ef.groups()){
+							if (g == efg){
+								inGroup = true;
+								annotationList.add(new Object[]{ef, f});
+								break;
+							}
+						}
+					}
+				}else{
+					annotationList.add(new Object[]{ef, f});
+				}
+			}
+		}
+		// Get annotation method
+		Method[] ms = cls.getDeclaredMethods();
+		for (Method m : ms){
+			ExcelField ef = m.getAnnotation(ExcelField.class);
+			if (ef != null && (ef.type()==0 || ef.type()==2)){
+				if (groups!=null && groups.length>0){
+					boolean inGroup = false;
+					for (int g : groups){
+						if (inGroup){
+							break;
+						}
+						for (int efg : ef.groups()){
+							if (g == efg){
+								inGroup = true;
+								annotationList.add(new Object[]{ef, m});
+								break;
+							}
+						}
+					}
+				}else{
+					annotationList.add(new Object[]{ef, m});
+				}
+			}
+		}
+		// Field sorting
+		Collections.sort(annotationList, new Comparator<Object[]>() {
+			public int compare(Object[] o1, Object[] o2) {
+				return new Integer(((ExcelField)o1[0]).sort()).compareTo(
+						new Integer(((ExcelField)o2[0]).sort()));
+			};
+		});
+		//log.debug("Import column count:"+annotationList.size());
+		// Get excel data
+		List<E> dataList = Lists.newArrayList();
+		int a = this.getDataRowNum();
+		int b = this.getLastDataRowNum();
+		for (int i = this.getDataRowNum(); i <= this.sheet.getLastRowNum(); i++) {
+			E e = (E)cls.newInstance();
+			int column = 0;
+			Row row = this.getRow(i);
+			StringBuilder sb = new StringBuilder();
+			for (Object[] os : annotationList){
+				Object val = this.getCellValue(row, column++);
+				if (val != null){
+					ExcelField ef = (ExcelField)os[0];
+					// If is dict type, get dict value
+					if (StringUtils.isNotBlank(ef.dictType())){
+						val = DictUtils.getDictValue(val.toString(), ef.dictType(), "");
+						//log.debug("Dictionary type value: ["+i+","+colunm+"] " + val);
+					}
+					// Get param type and type cast
+					Class<?> valType = Class.class;
+					if (os[1] instanceof Field){
+						valType = ((Field)os[1]).getType();
+					}else if (os[1] instanceof Method){
+						Method method = ((Method)os[1]);
+						if ("get".equals(method.getName().substring(0, 3))){
+							valType = method.getReturnType();
+						}else if("set".equals(method.getName().substring(0, 3))){
+							valType = ((Method)os[1]).getParameterTypes()[0];
+						}
+					}
+					//log.debug("Import value type: ["+i+","+column+"] " + valType);
+					try {
+						//如果导入的java对象,需要在这里自己进行变换。
+						if (valType == String.class){
+							String s = String.valueOf(val.toString());
+							if(StringUtils.endsWith(s, ".0")){
+								val = StringUtils.substringBefore(s, ".0");
+							}else{
+								val = String.valueOf(val.toString());
+							}
+						}else if (valType == Integer.class){
+							val = Double.valueOf(val.toString()).intValue();
+						}else if (valType == Long.class){
+							val = Double.valueOf(val.toString()).longValue();
+						}else if (valType == Double.class){
+							val = Double.valueOf(val.toString());
+						}else if (valType == Float.class){
+							val = Float.valueOf(val.toString());
+						}else if (valType == Date.class){
+							SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
+							val=sdf.parse(val.toString());
+						}else if (valType == User.class){
+							val = UserUtils.getByUserName(val.toString());
+						}else if (valType == Office.class){
+							val = UserUtils.getByOfficeName(val.toString());
+						}else if (valType == Area.class){
+							val = UserUtils.getByAreaName(val.toString());
+						}else{
+							if (ef.fieldType() != Class.class){
+								val = ef.fieldType().getMethod("getValue", String.class).invoke(null, val.toString());
+							}else{
+								val = Class.forName(this.getClass().getName().replaceAll(this.getClass().getSimpleName(),
+										"fieldtype."+valType.getSimpleName()+"Type")).getMethod("getValue", String.class).invoke(null, val.toString());
+							}
+						}
+					} catch (Exception ex) {
+						log.info("Get cell value ["+i+","+column+"] error: " + ex.toString());
+						val = null;
+					}
+					// set entity value
+					if (os[1] instanceof Field){
+						Reflections.invokeSetter(e, ((Field)os[1]).getName(), val);
+					}else if (os[1] instanceof Method){
+						String mthodName = ((Method)os[1]).getName();
+						if ("get".equals(mthodName.substring(0, 3))){
+							mthodName = "set"+StringUtils.substringAfter(mthodName, "get");
+						}
+						Reflections.invokeMethod(e, mthodName, new Class[] {valType}, new Object[] {val});
+					}
+				}
+				sb.append(val+", ");
+			}
+			dataList.add(e);
+			log.debug("Read success: ["+i+"] "+sb.toString());
+		}
+		return dataList;
+	}
+
 //	/**
 //	/**
 //	 * 导入测试
 //	 * 导入测试
 //	 */
 //	 */

+ 1 - 1
src/main/java/com/jeeplus/modules/sg/balancedlibrary/liKuResourcePool/utils/OptimalUtil.java

@@ -123,7 +123,7 @@ public class OptimalUtil {
             List newCurr = new ArrayList(curr);
             List newCurr = new ArrayList(curr);
             newCurr.add(next);
             newCurr.add(next);
             solve(index,sum+nextNeed,newCurr,total,elements);
             solve(index,sum+nextNeed,newCurr,total,elements);
-            solve(index,sum,curr,total,elements);
+//            solve(index,sum,curr,total,elements);
         }
         }
     }
     }
 
 

+ 4 - 4
src/main/java/com/jeeplus/modules/sg/budgetSpectaculars/web/ProjectBasicsController.java

@@ -95,7 +95,7 @@ public class ProjectBasicsController extends BaseController {
         AjaxJson j = new AjaxJson();
         AjaxJson j = new AjaxJson();
         try {
         try {
             ImportExcel ei = new ImportExcel(file, 0, 0);
             ImportExcel ei = new ImportExcel(file, 0, 0);
-            List<BudgetExecuteInfo> budgetExecuteList = ei.getDataList(BudgetExecuteInfo.class);
+            List<BudgetExecuteInfo> budgetExecuteList = ei.getDataListNew(BudgetExecuteInfo.class);
             //数据处理
             //数据处理
             service.disposeBudgetExecuteInfo(budgetExecuteList,year);
             service.disposeBudgetExecuteInfo(budgetExecuteList,year);
             j.setSuccess(true);
             j.setSuccess(true);
@@ -117,7 +117,7 @@ public class ProjectBasicsController extends BaseController {
         AjaxJson j = new AjaxJson();
         AjaxJson j = new AjaxJson();
         try {
         try {
             ImportExcel ei = new ImportExcel(file, 0, 0);
             ImportExcel ei = new ImportExcel(file, 0, 0);
-            List<ProjectDetailInfo> projectDetailList = ei.getDataList(ProjectDetailInfo.class);
+            List<ProjectDetailInfo> projectDetailList = ei.getDataListNew(ProjectDetailInfo.class);
             //数据处理
             //数据处理
             service.disposeProjectDetailInfo(projectDetailList);
             service.disposeProjectDetailInfo(projectDetailList);
             j.setSuccess(true);
             j.setSuccess(true);
@@ -140,7 +140,7 @@ public class ProjectBasicsController extends BaseController {
         AjaxJson j = new AjaxJson();
         AjaxJson j = new AjaxJson();
         try {
         try {
             ImportExcel ei = new ImportExcel(file, 1, 0);
             ImportExcel ei = new ImportExcel(file, 1, 0);
-            List<ProjectSettlementInfo> budgetExecuteList = ei.getDataList(ProjectSettlementInfo.class);
+            List<ProjectSettlementInfo> budgetExecuteList = ei.getDataListNew(ProjectSettlementInfo.class);
             //数据处理
             //数据处理
             service.disposeProjectSettlementInfo(budgetExecuteList);
             service.disposeProjectSettlementInfo(budgetExecuteList);
             j.setSuccess(true);
             j.setSuccess(true);
@@ -162,7 +162,7 @@ public class ProjectBasicsController extends BaseController {
         AjaxJson j = new AjaxJson();
         AjaxJson j = new AjaxJson();
         try {
         try {
             ImportExcel ei = new ImportExcel(file, 0, 0);
             ImportExcel ei = new ImportExcel(file, 0, 0);
-            List<WhichMaterialInfo> projectDetailList = ei.getDataList(WhichMaterialInfo.class);
+            List<WhichMaterialInfo> projectDetailList = ei.getDataListNew(WhichMaterialInfo.class);
             //数据处理
             //数据处理
             service.disposeWhichMaterialInfo(projectDetailList);
             service.disposeWhichMaterialInfo(projectDetailList);
             j.setSuccess(true);
             j.setSuccess(true);

+ 3 - 0
src/main/java/com/jeeplus/modules/sg/financial/erpcredit/service/ErpCreditService.java

@@ -306,6 +306,9 @@ public class ErpCreditService extends CrudService<ErpCreditMapper,ErpCredit> {
                 if (null != inputStream) {
                 if (null != inputStream) {
                     inputStream.close();
                     inputStream.close();
                 }
                 }
+                if(newFile.exists()){
+                    newFile.delete();
+                }
             } catch (Exception e) {
             } catch (Exception e) {
                 e.printStackTrace();
                 e.printStackTrace();
             }
             }

+ 5 - 4
src/main/java/com/jeeplus/modules/sg/financial/settlement/service/DonorMaterialService.java

@@ -171,10 +171,11 @@ public class DonorMaterialService extends CrudService<DonorMaterialMapper, Donor
             if (null != row) {
             if (null != row) {
                 String cellOne = this.getCellValue(row.getCell(1));
                 String cellOne = this.getCellValue(row.getCell(1));
                 Cell cell=row.getCell(2);
                 Cell cell=row.getCell(2);
-                if (cell.getCellType()!=1){
-                    cell.setCellType(1);
-                }
-                String cellTwo = cell.getStringCellValue();
+//                if (cell.getCellType()!=1){
+//                    cell.setCellType(1);
+//                }
+//                String cellTwo = cell.getStringCellValue();
+                String cellTwo = this.getCellValue(cell);
                 if (null!=cellTwo  && !"".equals(cellTwo) && !"无".equals(cellTwo)  && !"0".equals(cellTwo)) {
                 if (null!=cellTwo  && !"".equals(cellTwo) && !"无".equals(cellTwo)  && !"0".equals(cellTwo)) {
                     donorMaterial.setProjectName(projectName);
                     donorMaterial.setProjectName(projectName);
                     donorMaterial.setProjectId(projectId);
                     donorMaterial.setProjectId(projectId);