Browse Source

导入完善

guq 7 years ago
parent
commit
e82169ef1b

+ 24 - 23
applications/commons/commons-server/src/main/java/com/usoftchina/saas/commons/service/impl/ExcelServiceImpl.java

@@ -12,6 +12,7 @@ import com.usoftchina.saas.commons.service.ExcelService;
 import com.usoftchina.saas.context.BaseContextHolder;
 import com.usoftchina.saas.exception.BizException;
 import com.usoftchina.saas.utils.CollectionUtils;
+import com.usoftchina.saas.utils.DateUtils;
 import com.usoftchina.saas.utils.StringUtils;
 import org.apache.poi.hssf.util.HSSFColor;
 import org.apache.poi.ss.usermodel.*;
@@ -138,7 +139,6 @@ public class ExcelServiceImpl implements ExcelService{
             StringBuilder err = new StringBuilder();
             JSONArray mains = new JSONArray();
             JSONArray details = new JSONArray();
-            boolean flag = false;
             //数据行循环
             for (int i = 0; i < datas.size(); i++) {
                 Map<String,String> data = datas.get(i);
@@ -179,25 +179,21 @@ public class ExcelServiceImpl implements ExcelService{
                            if (difference) {
                                dd.setDd_codevalue(codeValue);
                                if ("true".equals(set.getNecessary()) && data.get("*" + set.getDescription()).equals("")) {
-                                   err.append("第" + (i + 2) + "行 " + set.getDescription() + " 必填字段未填写! ");
+                                   err.append("第" + (i + 3) + "行 " + set.getDescription() + " 必填字段未填写!<br/> ");
                                    break;
                                }
                            }
                            //检测日期类型是否规范
                            if ("date".equals(set.getType()) && !StringUtils.isEmpty(value)) {
-                               flag = validateDateFormat(value);
-                               if (!flag) {
-                                   err.append("第" + (i + 2) + "行 " + set.getDescription() + " 日期格式不正确! ");
+                               value = praseDate(value);
+                               if (null == value) {
+                                   err.append("第" + (i + 3) + "行 " + set.getDescription() + " 日期格式不正确!<br/> ");
                                    break;
                                }
                            }
                            //插入主表数据
                            if (null != mainData) {
-                               if ("true".equals(set.getNecessary())) {
-                                   mainData.put(set.getField(), value);
-                               } else {
-                                   mainData.put(set.getField(), value);
-                               }
+                               mainData.put(set.getField(), value);
                            }
                        }
                        //所有主表数据进行分类
@@ -216,24 +212,20 @@ public class ExcelServiceImpl implements ExcelService{
                            } else {
                                value = data.get(set.getDescription());
                            }
-                           //拼从表数据
-                           if ("true".equals(set.getNecessary())) {
-                               detailData.put(set.getField(), data.get("*" + set.getDescription()));
-                           } else {
-                               detailData.put(set.getField(), data.get(set.getDescription()));
-                           }
-                           if ("true".equals(set.getNecessary()) && data.get("*" + set.getDescription()).equals("")) {
-                               err.append("第" + (i + 2) + "行 " + set.getDescription() + " 必填字段未填写! ");
+                           if ("true".equals(set.getNecessary()) && value.equals("")) {
+                               err.append("第" + (i + 3) + "行 " + set.getDescription() + " 必填字段未填写!<br/> ");
                                break;
                            }
                            //检测日期类型是否规范
-                           if ("date".equals(set.getType())) {
-                               flag = validateDateFormat(value);
-                               if (!flag) {
-                                   err.append("第" + (i + 2) + "行 " + set.getDescription() + " 日期格式不正确! ");
+                           if ("date".equals(set.getType()) && !StringUtils.isEmpty(value)) {
+                               value = praseDate(value);
+                               if (null == value) {
+                                   err.append("第" + (i + 3) + "行 " + set.getDescription() + " 日期格式不正确!<br/> ");
                                    break;
                                }
                            }
+                           //拼从表数据
+                           detailData.put(set.getField(), value);
                        }
                        if (detailData.size() > 0) {
                            dd.setDd_codevalue(codeValue);
@@ -273,6 +265,15 @@ public class ExcelServiceImpl implements ExcelService{
         return flag;
     }
 
+    private String praseDate(String num) {
+        try {
+            Integer days = Integer.valueOf(num);
+            return DateUtils.plusDay(days, "1899-12-30");
+        }catch (Exception e) {
+            return null;
+        }
+    }
+
     //保证先遍历主表
     private List<String> SetToList(Set<String> sets) {
         List<String> list = new ArrayList<>();
@@ -294,7 +295,7 @@ public class ExcelServiceImpl implements ExcelService{
                     cellValue = String.valueOf(cell.getNumericCellValue());
                     //判断是否为INT类型
                     if (Double.valueOf(cellValue.toString()).intValue() - Double.valueOf(cellValue.toString()) == 0) {
-                        return Double.valueOf(cellValue.toString()).intValue();
+                        return cellValue.toString().substring(0, cellValue.toString().indexOf("."));
                     }
                     break;
                 }

+ 1 - 1
applications/document/document-server/src/main/java/com/usoftchina/saas/document/service/impl/CustomerServiceImpl.java

@@ -516,7 +516,7 @@ public class CustomerServiceImpl extends CommonBaseServiceImpl<CustomerMapper, C
                 //验证业务员
                 if (!StringUtils.isEmpty(customerDTO.getCu_sellername())) {
                     List<Employee> employees = employeeMapper.selectByName(customerDTO.getCu_sellername(), companyId);
-                    if (null == employees || StringUtils.isEmpty(employees.get(0))) {
+                    if (null == employees || employees.size() == 0 || StringUtils.isEmpty(employees.get(0))) {
                         err.append("客户编号为: " + customerDTO.getCu_code() + " 的业务员: "+ customerDTO.getCu_sellername() +" 在系统中不存在,请确认数据是否正确");
                         break;
                     }

+ 11 - 1
framework/core/src/main/java/com/usoftchina/saas/utils/DateUtils.java

@@ -543,9 +543,19 @@ public class DateUtils {
     //获取期间
     public static int getYm(Date date){
         String dates = date2String(date, "yyyyMM");
-//        dates = dates + "01";
         int d = Integer.parseInt(dates);
         return d;
     }
 
+    public static String plusDay(int num,String newDate) throws ParseException{
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+        Date currdate = format.parse(newDate);
+        Calendar ca = Calendar.getInstance();
+        ca.setTime(currdate);
+        ca.add(Calendar.DATE, num);// num为增加的天数,可以改变的
+        Date next = ca.getTime();
+        String enddate = format.format(next);
+        return enddate;
+    }
+
 }