Explorar el Código

Merge branch 'dev' of ssh://10.10.100.21/source/saas-platform into dev

hy hace 7 años
padre
commit
87825eca70

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

@@ -14,6 +14,7 @@ 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.RegexpUtils;
 import com.usoftchina.saas.utils.StringUtils;
 import org.apache.poi.hssf.util.HSSFColor;
 import org.apache.poi.ss.usermodel.*;
@@ -163,27 +164,28 @@ public class ExcelServiceImpl implements ExcelService{
                        List<TempletSet> main = columns.get(position);
                        for (TempletSet set : main) {
                            //取excel值
-                           if ("true".equals(set.getNecessary())) {
+                           value = data.get(set.getDescription());
+                          /* if ("true".equals(set.getNecessary())) {
                                value = data.get("*" + set.getDescription());
                            } else {
                                value = data.get(set.getDescription());
-                           }
+                           }*/
                            //取编号字段
-                           if (set.isCodefield() && !data.get("*" + set.getDescription()).equals("")) {
+                           if (set.isCodefield() && !"".equals(value)) {
                                mainData = new JSONObject();
                                codeValue = value;
                                difference = true;
                                validateCode.add(codeValue);
                            }
                            //检查是否是同一单
-                           if (set.isCodefield() && data.get("*" + set.getDescription()).equals("")) {
+                           if (set.isCodefield() && "".equals(value)) {
                                difference = false;
                                break;
                            }
                            //检查主表必填字段是否完整
                            if (difference) {
                                dd.setDd_codevalue(codeValue);
-                               if ("true".equals(set.getNecessary()) && data.get("*" + set.getDescription()).equals("")) {
+                               if ("true".equals(set.getNecessary()) && "".equals(value)) {
                                    err.append("第" + (i + 3) + "行 " + set.getDescription() + " 必填字段未填写!<br/> ");
                                    break;
                                }
@@ -196,9 +198,18 @@ public class ExcelServiceImpl implements ExcelService{
                                    break;
                                }
                            }
-                           //如果为数字类型且为空默认赋值0
-                           if ("number".equals(set.getType()) && StringUtils.isEmpty(value)) {
-                                value = "0";
+                           //如果为数字类型且为空默认赋值0,检测是否为数字类型
+                           if ("number".equals(set.getType())) {
+                               if (StringUtils.isEmpty(value)) {
+                                   value = "0";
+                               } else {
+                                   Boolean numner = isNumner(value);
+                                   if (!numner) {
+                                       err.append("第" + (i + 3) + "行 " + set.getDescription() + " 数字格式不正确!<br/> ");
+                                       break;
+                                   }
+                               }
+
                            }
                            //插入主表数据
                            if (null != mainData) {
@@ -216,11 +227,12 @@ public class ExcelServiceImpl implements ExcelService{
                        detailData = new JSONObject();
                        for (TempletSet set : detail) {
                            //取excel值
-                           if ("true".equals(set.getNecessary())) {
+                           value = data.get(set.getDescription());
+                          /* if ("true".equals(set.getNecessary())) {
                                value = data.get("*" + set.getDescription());
                            } else {
                                value = data.get(set.getDescription());
-                           }
+                           }*/
                            if ("true".equals(set.getNecessary()) && value.equals("")) {
                                detailData = null;
                                //err.append("第" + (i + 3) + "行 " + set.getDescription() + " 必填字段未填写!<br/> ");
@@ -284,6 +296,19 @@ public class ExcelServiceImpl implements ExcelService{
     }
 
 
+    private Boolean isNumner(String str) {
+        for(int i=str.length() - 1; i>=0; i--){
+            int chr=str.charAt(i);
+            if(chr < 48 || chr >  57) {
+                if (chr == 46) {
+                    continue;
+                }
+                return false;
+            }
+
+        }
+        return true;
+    }
 
 
     private boolean validateDateFormat(String date) {
@@ -333,6 +358,7 @@ public class ExcelServiceImpl implements ExcelService{
             switch(cell.getCellType()){
                 case Cell.CELL_TYPE_NUMERIC:{
                     cellValue = String.valueOf(cell.getNumericCellValue());
+                    cellValue = RegexpUtils.replaceSpecialCharacter(cellValue);
                     //判断是否为INT类型
                     if (Double.valueOf(cellValue.toString()).intValue() - Double.valueOf(cellValue.toString()) == 0) {
                         return cellValue.toString().substring(0, cellValue.toString().indexOf("."));
@@ -344,14 +370,17 @@ public class ExcelServiceImpl implements ExcelService{
                     if(DateUtil.isCellDateFormatted(cell)){
                         //转换为日期格式YYYY-mm-dd
                         cellValue = cell.getDateCellValue();
+                        cellValue = RegexpUtils.replaceSpecialCharacter(cellValue);
                     }else{
                         //数字
                         cellValue = String.valueOf(cell.getNumericCellValue());
+                        cellValue = RegexpUtils.replaceSpecialCharacter(cellValue);
                     }
                     break;
                 }
                 case Cell.CELL_TYPE_STRING:{
                     cellValue = cell.getRichStringCellValue().getString();
+                    cellValue = RegexpUtils.replaceSpecialCharacter(cellValue);
                     break;
                 }
                 default:
@@ -464,16 +493,15 @@ public class ExcelServiceImpl implements ExcelService{
 
     private CellStyle getCellStyle(SXSSFWorkbook workbook, boolean main) {
         CellStyle style = workbook.createCellStyle();
-        style.setFillBackgroundColor((short) 18);
-        style.setFillPattern(FillPatternType.LEAST_DOTS);
         Font font = workbook.createFont();
         font.setFontName("仿宋_GB2312");// 字体
         font.setFontHeightInPoints((short) 12);// 字号
+        font.setBold(true);
         font.setColor((short)64);// 颜色
         style.setFont(font);
+        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
         style.setAlignment(HorizontalAlignment.CENTER);
-        style.setFillForegroundColor(HSSFColor.GREEN.index);
-        style.setFillBackgroundColor(main ? HSSFColor.LIGHT_YELLOW.index : HSSFColor.PALE_BLUE.index);
+        style.setFillForegroundColor(main ? HSSFColor.LIGHT_YELLOW.index : HSSFColor.PALE_BLUE.index);
         style.setBorderBottom(BorderStyle.MEDIUM);
         style.setBorderLeft(BorderStyle.MEDIUM);
         style.setBorderRight(BorderStyle.MEDIUM);

+ 17 - 2
framework/core/src/main/java/com/usoftchina/saas/utils/RegexpUtils.java

@@ -12,7 +12,7 @@ public class RegexpUtils {
     private static final String HK_MOBILE_EXP = "^(5|6|8|9)\\d{7}$";
     private static final String EMAIL_EXP = "^\\w+([-.]\\w+)*@\\w+([-]\\w+)*\\.(\\w+([-]\\w+)*\\.)*[a-z]{2,4}$";
     private static final String SPECCHARACTER_EXP = "[\\\\s~·`!!@#¥$%^……&*(())\\\\-——\\\\-_=+【\\\\[\\\\]】{{}}\\\\|、\\\\\\\\;;::‘'“”\\\",,《<。.》>、/??]";
-
+    private static final String SPECIALCHARACTER_EXP = "[`~!@#$%^&*()+=|{}':;',\\[\\]<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]";
     /**
      * 匹配手机号码
      *
@@ -57,7 +57,7 @@ public class RegexpUtils {
     }
 
     /**
-     * 特殊字符替换
+     * 特殊字符替换含小写字母
      * @param str
      * @return
      */
@@ -66,4 +66,19 @@ public class RegexpUtils {
         Matcher m = p.matcher(str);
         return m.replaceAll("");
     }
+
+
+    /**
+     * 特殊字符替换
+     * @param obj
+     * @return
+     */
+    public static String replaceSpecialCharacter(Object obj){
+        if (StringUtils.isEmpty(obj)) {
+            return "";
+        }
+        Pattern p = Pattern.compile(SPECIALCHARACTER_EXP);
+        Matcher m = p.matcher(obj.toString());
+        return m.replaceAll("");
+    }
 }