Browse Source

导入功能优化

guq 7 years ago
parent
commit
56b8044c03

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

@@ -165,17 +165,13 @@ public class ExcelServiceImpl implements ExcelService{
                        for (TempletSet set : main) {
                        for (TempletSet set : main) {
                            //取excel值
                            //取excel值
                            value = data.get(set.getDescription());
                            value = data.get(set.getDescription());
-                          /* if ("true".equals(set.getNecessary())) {
-                               value = data.get("*" + set.getDescription());
-                           } else {
-                               value = data.get(set.getDescription());
-                           }*/
                            //取编号字段
                            //取编号字段
                            if (set.isCodefield() && !"".equals(value)) {
                            if (set.isCodefield() && !"".equals(value)) {
                                mainData = new JSONObject();
                                mainData = new JSONObject();
                                codeValue = value;
                                codeValue = value;
                                difference = true;
                                difference = true;
                                validateCode.add(codeValue);
                                validateCode.add(codeValue);
+                               dd.setDd_codevalue(codeValue);
                            }
                            }
                            //检查是否是同一单
                            //检查是否是同一单
                            if (set.isCodefield() && "".equals(value)) {
                            if (set.isCodefield() && "".equals(value)) {
@@ -184,7 +180,6 @@ public class ExcelServiceImpl implements ExcelService{
                            }
                            }
                            //检查主表必填字段是否完整
                            //检查主表必填字段是否完整
                            if (difference) {
                            if (difference) {
-                               dd.setDd_codevalue(codeValue);
                                if ("true".equals(set.getNecessary()) && "".equals(value)) {
                                if ("true".equals(set.getNecessary()) && "".equals(value)) {
                                    err.append("第" + (i + 3) + "行 " + set.getDescription() + " 必填字段未填写!<br/> ");
                                    err.append("第" + (i + 3) + "行 " + set.getDescription() + " 必填字段未填写!<br/> ");
                                    break;
                                    break;
@@ -227,11 +222,6 @@ public class ExcelServiceImpl implements ExcelService{
                        for (TempletSet set : detail) {
                        for (TempletSet set : detail) {
                            //取excel值
                            //取excel值
                            value = data.get(set.getDescription());
                            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("")) {
                            if ("true".equals(set.getNecessary()) && value.equals("")) {
                                detailData = null;
                                detailData = null;
                                //err.append("第" + (i + 3) + "行 " + set.getDescription() + " 必填字段未填写!<br/> ");
                                //err.append("第" + (i + 3) + "行 " + set.getDescription() + " 必填字段未填写!<br/> ");
@@ -245,9 +235,17 @@ public class ExcelServiceImpl implements ExcelService{
                                    break;
                                    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;
+                                   }
+                               }
                            }
                            }
                            //拼从表数据
                            //拼从表数据
                            detailData.put(set.getField(), value);
                            detailData.put(set.getField(), value);
@@ -258,8 +256,8 @@ public class ExcelServiceImpl implements ExcelService{
                        }
                        }
                    }
                    }
                 }
                 }
-                //排除编号未填写但是其他字段填写的情况
-                if (StringUtils.hasText(codeValue)) {
+                //排除编号未填写但是其他字段填写的情况 主表不为空且从表也不为空
+                if (StringUtils.hasText(codeValue) && StringUtils.hasText(dd.getDd_codevalue())) {
                     dataImportDetailMapper.insertSelective(dd);
                     dataImportDetailMapper.insertSelective(dd);
                 }
                 }
             }
             }
@@ -315,8 +313,8 @@ public class ExcelServiceImpl implements ExcelService{
         if (StringUtils.isEmpty(date)) {
         if (StringUtils.isEmpty(date)) {
             return false;
             return false;
         }
         }
-        String regEx1 = "[0-9]{4}/[0-9]{2}/[0-9]{2}";
-        String regEX2 = "[0-9]{4}-[0-9]{2}-[0-9]{2}";
+        String regEx1 = "[0-9]{4}/[0-1][0-9]/[0-3][0-9]";
+        String regEX2 = "[0-9]{4}-[0-1][0-9]-[0-3][0-9]";
         // 编译正则表达式
         // 编译正则表达式
         Pattern pattern1 = Pattern.compile(regEx1);
         Pattern pattern1 = Pattern.compile(regEx1);
         Pattern pattern2 = Pattern.compile(regEX2);
         Pattern pattern2 = Pattern.compile(regEX2);
@@ -334,7 +332,7 @@ public class ExcelServiceImpl implements ExcelService{
             Integer days = Integer.valueOf(num);
             Integer days = Integer.valueOf(num);
             return DateUtils.plusDay(days, "1899-12-30");
             return DateUtils.plusDay(days, "1899-12-30");
         }catch (Exception e) {
         }catch (Exception e) {
-            return null;
+            return validateDateFormat(num) ? num : null;
         }
         }
     }
     }
 
 

+ 2 - 0
applications/document/document-server/src/main/java/com/usoftchina/saas/document/mapper/VendorkindMapper.java

@@ -28,4 +28,6 @@ public interface VendorkindMapper extends CommonBaseMapper<Vendorkind> {
     List<Vendorkind> selectAll(@Param("companyId") Long companyId);
     List<Vendorkind> selectAll(@Param("companyId") Long companyId);
 
 
     int getCountFromVendor(@Param("id") Long id, @Param("companyId") Long companyId);
     int getCountFromVendor(@Param("id") Long id, @Param("companyId") Long companyId);
+
+    Vendorkind getTypeByname(@Param("name") String name, @Param("companyId") Long companyId);
 }
 }

+ 2 - 0
applications/document/document-server/src/main/java/com/usoftchina/saas/document/service/VendorkindService.java

@@ -15,4 +15,6 @@ public interface VendorkindService extends CommonBaseService<VendorkindMapper, V
     List<Vendorkind> selectAll();
     List<Vendorkind> selectAll();
 
 
     DocBaseDTO saveData(Vendorkind vendorkind);
     DocBaseDTO saveData(Vendorkind vendorkind);
+
+    Vendorkind getTypeByname(String name);
 }
 }

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

@@ -16,7 +16,6 @@ import com.usoftchina.saas.commons.po.DataImportDetail;
 import com.usoftchina.saas.commons.po.Operation;
 import com.usoftchina.saas.commons.po.Operation;
 import com.usoftchina.saas.commons.po.Status;
 import com.usoftchina.saas.commons.po.Status;
 import com.usoftchina.saas.context.BaseContextHolder;
 import com.usoftchina.saas.context.BaseContextHolder;
-import com.usoftchina.saas.document.dto.ProductListDTO;
 import com.usoftchina.saas.document.dto.VendorDTO;
 import com.usoftchina.saas.document.dto.VendorDTO;
 import com.usoftchina.saas.document.dto.VendorListDTO;
 import com.usoftchina.saas.document.dto.VendorListDTO;
 import com.usoftchina.saas.document.entities.*;
 import com.usoftchina.saas.document.entities.*;
@@ -25,6 +24,7 @@ import com.usoftchina.saas.document.mapper.SubledgerMapper;
 import com.usoftchina.saas.document.mapper.VendorMapper;
 import com.usoftchina.saas.document.mapper.VendorMapper;
 import com.usoftchina.saas.document.mapper.VendorcontactMapper;
 import com.usoftchina.saas.document.mapper.VendorcontactMapper;
 import com.usoftchina.saas.document.service.VendorService;
 import com.usoftchina.saas.document.service.VendorService;
+import com.usoftchina.saas.document.service.VendorkindService;
 import com.usoftchina.saas.exception.BizException;
 import com.usoftchina.saas.exception.BizException;
 import com.usoftchina.saas.page.PageRequest;
 import com.usoftchina.saas.page.PageRequest;
 import com.usoftchina.saas.utils.CollectionUtils;
 import com.usoftchina.saas.utils.CollectionUtils;
@@ -57,6 +57,8 @@ public class VendorServiceImpl extends CommonBaseServiceImpl<VendorMapper, Vendo
     private VendorMapper vendorMapper;
     private VendorMapper vendorMapper;
     @Autowired
     @Autowired
     private DataImportMapper dataImportMapper;
     private DataImportMapper dataImportMapper;
+    @Autowired
+    private VendorkindService vendorkindService;
 
 
     @Override
     @Override
     public PageInfo<VendorDTO> getVendorsByCondition(PageRequest page, ListReqDTO listReqDTO) {
     public PageInfo<VendorDTO> getVendorsByCondition(PageRequest page, ListReqDTO listReqDTO) {
@@ -462,6 +464,12 @@ public class VendorServiceImpl extends CommonBaseServiceImpl<VendorMapper, Vendo
                 Vendor vendor = JSONObject.parseObject(main.getDd_maindata(), Vendor.class);
                 Vendor vendor = JSONObject.parseObject(main.getDd_maindata(), Vendor.class);
                 vendor.setVe_status(Status.ENABLE.getDisplay());
                 vendor.setVe_status(Status.ENABLE.getDisplay());
                 vendor.setVe_statuscode(Status.ENABLE.name());
                 vendor.setVe_statuscode(Status.ENABLE.name());
+                if (!StringUtils.isEmpty(vendor.getVe_type())) {
+                    Vendorkind type = vendorkindService.getTypeByname(vendor.getVe_type());
+                    if (null == type) {
+                        throw new BizException(70110581,"供应商: " + vendor.getVe_name() + " 类型: " + vendor.getVe_type() + " 在系统中不存在");
+                    }
+                }
                 //编号不存在
                 //编号不存在
                 if (i == 0) {
                 if (i == 0) {
                     vendor.setId(0l);
                     vendor.setId(0l);
@@ -476,15 +484,25 @@ public class VendorServiceImpl extends CommonBaseServiceImpl<VendorMapper, Vendo
                 //添加从表
                 //添加从表
                 if (data.size() > 0) {
                 if (data.size() > 0) {
                     detno = 1;
                     detno = 1;
+                    int count = 0;
                     for (DataImportDetail productDetail : data) {
                     for (DataImportDetail productDetail : data) {
                         Vendorcontact detail = JSONObject.parseObject(productDetail.getDd_detaildata(), Vendorcontact.class);
                         Vendorcontact detail = JSONObject.parseObject(productDetail.getDd_detaildata(), Vendorcontact.class);
                         if (null != detail) {
                         if (null != detail) {
                             detail.setVc_veid(vendor.getId());
                             detail.setVc_veid(vendor.getId());
                             detail.setVc_detno(detno);
                             detail.setVc_detno(detno);
                             detno++;
                             detno++;
+                            if ("是".equals(detail.getVc_default())) {
+                                detail.setVc_default("1");
+                                count++;
+                            } else {
+                                detail.setVc_default("0");
+                            }
                             details_.add(detail);
                             details_.add(detail);
                         }
                         }
                     }
                     }
+                    if (count > 1) {
+                        throw new BizException(70110582,"供应商: " + vendor.getVe_name() + " 存在多个默认联系人");
+                    }
                 }
                 }
                 listDTO.setMain(vendor);
                 listDTO.setMain(vendor);
                 listDTO.setItems(details_);
                 listDTO.setItems(details_);

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

@@ -10,10 +10,10 @@ import com.usoftchina.saas.document.entities.Vendorkind;
 import com.usoftchina.saas.document.mapper.VendorkindMapper;
 import com.usoftchina.saas.document.mapper.VendorkindMapper;
 import com.usoftchina.saas.document.service.VendorkindService;
 import com.usoftchina.saas.document.service.VendorkindService;
 import com.usoftchina.saas.exception.BizException;
 import com.usoftchina.saas.exception.BizException;
+import com.usoftchina.saas.utils.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
-import javax.print.Doc;
 import java.util.Date;
 import java.util.Date;
 import java.util.List;
 import java.util.List;
 
 
@@ -52,6 +52,15 @@ public class VendorkindServiceImpl extends CommonBaseServiceImpl<VendorkindMappe
         return docBaseDTO;
         return docBaseDTO;
     }
     }
 
 
+    @Override
+    public Vendorkind getTypeByname(String name) {
+        if (StringUtils.isEmpty(name)) {
+            return null;
+        }
+        Vendorkind kind = vendorkindMapper.getTypeByname(name, BaseContextHolder.getCompanyId());
+        return kind;
+    }
+
     @Override
     @Override
     public boolean removeByPrimaryKey(Long id){
     public boolean removeByPrimaryKey(Long id){
         if(id != null && id > 0){
         if(id != null && id > 0){

+ 1 - 1
applications/document/document-server/src/main/resources/mapper/DataImportMapper.xml

@@ -93,7 +93,7 @@
 
 
   <select id="selectMainBycode" resultMap="DetailMap">
   <select id="selectMainBycode" resultMap="DetailMap">
     select * from  data_importdetail
     select * from  data_importdetail
-    where dd_codevalue = #{code} and dd_diid=#{id} and ifnull(dd_success,0)=0 and dd_maindata is not null and companyid=#{companyid}
+    where dd_codevalue = #{code} and dd_diid=#{id} and ifnull(dd_success,0)=0 and ifnull(dd_maindata,'')!='' and companyid=#{companyid}
   </select>
   </select>
 
 
   <update id="updateDataImport" parameterType="integer">
   <update id="updateDataImport" parameterType="integer">

+ 3 - 0
applications/document/document-server/src/main/resources/mapper/VendorkindMapper.xml

@@ -133,4 +133,7 @@
     <select id="getCountFromVendor" resultType="int">
     <select id="getCountFromVendor" resultType="int">
         SELECT COUNT(*) FROM VENDOR WHERE VE_TYPE = (SELECT VK_NAME FROM VENDORKIND WHERE VK_ID = #{id}) AND companyId = #{companyId}
         SELECT COUNT(*) FROM VENDOR WHERE VE_TYPE = (SELECT VK_NAME FROM VENDORKIND WHERE VK_ID = #{id}) AND companyId = #{companyId}
     </select>
     </select>
+  <select id="getTypeByname" resultMap="BaseResultMap">
+    select * from vendorkind where vk_name=#{name} and companyId=#{companyId}
+  </select>
 </mapper>
 </mapper>

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

@@ -78,7 +78,7 @@ public class RegexpUtils {
             return "";
             return "";
         }
         }
         Pattern p = Pattern.compile(SPECIALCHARACTER_EXP);
         Pattern p = Pattern.compile(SPECIALCHARACTER_EXP);
-        Matcher m = p.matcher(obj.toString());
+        Matcher m = p.matcher(obj.toString().trim());
         return m.replaceAll("");
         return m.replaceAll("");
     }
     }
 }
 }