瀏覽代碼

Merge branch 'test' of jishutao/kede-server into prod

anderx 2 年之前
父節點
當前提交
008f920b35

+ 30 - 9
src/main/java/com/goafanti/RD/service/impl/RDServiceImpl.java

@@ -6,6 +6,7 @@ import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.AFTConstants;
 import com.goafanti.common.dao.RdDetailsMapper;
 import com.goafanti.common.model.RdDetails;
+import com.goafanti.common.utils.StringUtils;
 import com.goafanti.common.utils.excel.NewExcelUtil;
 import com.goafanti.common.utils.pdf.PDFUtils;
 import com.goafanti.common.utils.word.WordUtils;
@@ -114,18 +115,38 @@ public class RDServiceImpl extends BaseMybatisDao<RdDetailsMapper> implements RD
         String aid=TokenManager.getAdminId();
         Date date =new Date();
         Map<String,Object> map=new HashMap<>();
-        List<InputExcelRdDetails> relust= new ArrayList<>();
+        int OkCount=0;
+        int RdCount=0;
+        int erCount=0;
         List<String>errors=new ArrayList<>();
         for (InputExcelRdDetails in : list) {
-            relust.add(in);
-        }
-        for (InputExcelRdDetails in : relust) {
-            in.setStatus(1);
-            in.setAid(aid);
-            in.setCreateTime(date);
+            if (StringUtils.isNotEmpty(in.getRdName())){
+                RdCount++;
+                OkCount++;
+                int i = rdDetailsMapper.selectByRDName(in.getRdName());
+                if (i==0){
+                    try {
+                        in.setStatus(1);
+                        in.setAid(aid);
+                        in.setCreateTime(date);
+                        rdDetailsMapper.insertSelective(in);
+                    }catch (Exception e ){
+                        int errorsCount=RdCount+3;
+                        erCount++;
+                        OkCount--;
+                        errors.add(String.format("%s.数据第%s行,项目名称[%s]数据异常!",erCount,errorsCount,in.getRdName()));
+                    }
+                }else {
+                    OkCount--;
+                    erCount++;
+                    int errorsCount=RdCount+3;
+                    errors.add(String.format("%s.数据第%s行,名称[%s]导入失败,名称已存在!",erCount,errorsCount,in.getRdName()));
+                }
+            }
         }
-        if (relust.size()>0)insertBatch(relust);
-        map.put("OK",relust.size());
+
+//        if (relust.size()>0)insertBatch(relust);
+        map.put("OK",OkCount);
         map.put("ERROR",errors);
         return map;
     }

+ 2 - 0
src/main/java/com/goafanti/common/dao/RdDetailsMapper.java

@@ -33,4 +33,6 @@ public interface RdDetailsMapper {
      * @return
      */
     int updateBrowseOrDownload(@Param("id")Long id, @Param("type")Integer type);
+
+    int selectByRDName(String rdName);
 }

+ 1 - 1
src/main/java/com/goafanti/common/error/SystemExceptionResolver.java

@@ -88,7 +88,7 @@ public class SystemExceptionResolver extends SimpleMappingExceptionResolver{
 			error = new Error((String) message);
 		}else {
 			error = new Error((String) errorResource.getProperty(ex.getClass().getName()));
-			LoggerUtils.fmtError(getClass(), ex, "系统异常。",ex.getClass().getName());
+			LoggerUtils.fmtError(getClass(), ex, "数据异常。",ex.getClass().getName());
 		}
 		if (StringUtils.isEmpty(error.getMessage())) {
 			error.setMessage("系统异常,请联系管理员。");

+ 7 - 1
src/main/java/com/goafanti/common/mapper/RdDetailsMapper.xml

@@ -341,7 +341,8 @@
       and a.aid =#{aid}
     </if>
   </select>
-  <insert id="insertBatch">
+
+    <insert id="insertBatch">
     insert into rd_details (user_name, rd_no, ip_no,
                             rd_name, rd_start, rd_end,
                             technical_field, technology_source, total_amount,
@@ -373,4 +374,9 @@
     </set>
   </update>
 
+  <select id="selectByRDName" parameterType="java.lang.String" resultType="java.lang.Integer">
+    select count(*) from rd_details
+    where rd_name= #{rdName}
+  </select>
+
 </mapper>

+ 1 - 1
src/main/resources/props/error.properties

@@ -4,7 +4,7 @@ org.apache.shiro.authc.LockedAccountException=\u8BE5\u8D26\u53F7\u5DF2\u51BB\u7E
 org.apache.shiro.authc.DisabledAccountException=\u8BE5\u8D26\u53F7\u5DF2\u51BB\u7ED3\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u3002
 org.apache.shiro.authc.ExcessiveAttemptsException=\u5C1D\u8BD5\u6B21\u6570\u8FC7\u591A\uFF0C\u8D26\u53F7\u6682\u65F6\u88AB\u9501\u5B9A\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5\u3002
 org.apache.shiro.session.ExpiredSessionException=\u767B\u5F55\u4FE1\u606F\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55\u3002
-org.springframework.dao.DataIntegrityViolationException=\u6570\u636E\u5F02\u5E38\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u6216\u7A0D\u540E\u518D\u8BD5\u3002
+org.springframework.dao.DataIntegrityViolationException=\u6570\u636E\u5F02\u5E38\uFF0C\u8BF7\u4FEE\u6539\u8868\u683C\u5185\u5BB9\u786E\u4FDD\u5185\u5BB9\u6B63\u786E\u3002
 org.springframework.jdbc.BadSqlGrammarException=\u6570\u636E\u5F02\u5E38\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u6216\u7A0D\u540E\u518D\u8BD5\u3002
 org.springframework.web.multipart.MaxUploadSizeExceededException=\u4E0A\u4F20\u9644\u4EF6\u8D85\u51FA\u9650\u5236\u3002
 java.text.ParseException=\u53C2\u6570\u683C\u5F0F\u9519\u8BEF\uFF0C\u8BF7\u6838\u5BF9\u8F93\u5165\u6570\u636E\u540E\u518D\u8BD5\u3002