Browse Source

修复解析报文的bug

lgs 11 months ago
parent
commit
c863aab16e

+ 8 - 0
src/main/java/com/kexun/mapper/ReportInfoMapper.java

@@ -3,6 +3,7 @@ package com.kexun.mapper;
 import com.kexun.entity.ReportInfo;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.kexun.model.dto.ReportInfoDTO;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * <p>
@@ -20,4 +21,11 @@ public interface ReportInfoMapper extends BaseMapper<ReportInfo> {
      */
     void updateReportInfo(ReportInfoDTO reportInfoDTO);
 
+    /**
+     * 修改报文信息状态
+     * @param status 状态
+     * @param id 主键
+     */
+    void updateReportInfoStatus(@Param("status") String status,@Param("id") Long id);
+
 }

+ 6 - 0
src/main/java/com/kexun/service/ReportInfoService.java

@@ -30,6 +30,12 @@ public interface ReportInfoService extends IService<ReportInfo> {
      */
     void updateReportInfo(ReportInfoDTO reportInfoDTO);
 
+    /**
+     * 修改报文信息
+     * @param status
+     * @param id
+     */
+    void updateReportInfoStatus(String status,Long id);
 
     /**
      * 根据条件获取报文信息

+ 41 - 17
src/main/java/com/kexun/service/atomic/BaseFieldAtomicService.java

@@ -234,10 +234,13 @@ public class BaseFieldAtomicService {
                         .filter(e -> e.getEndMonth() != null &&
                                 DateUtils.getSpaceByUnit(DateUtils.convertStrToDate(e.getEndMonth(), DateUtils.YYYY_MM), currtDate, DateUtils.UNIT_MOUTHS) <= 12)
                         .collect(Collectors.toList());
-                BigDecimal last1YearHousingFundAvg = last1YearHousingList.stream()
+                BigDecimal last1YearHousingFund = last1YearHousingList.stream()
                         .map(e -> e.getMonthMoney() == null ? BigDecimal.ZERO : e.getMonthMoney())
-                        .reduce(BigDecimal.ZERO, BigDecimal::add)
-                        .divide(BigDecimal.valueOf(last1YearHousingList.size()), 2, BigDecimal.ROUND_HALF_UP);
+                        .reduce(BigDecimal.ZERO, BigDecimal::add);
+                BigDecimal last1YearHousingFundAvg = new BigDecimal("0.00");
+                if (last1YearHousingFund.compareTo(BigDecimal.ZERO) > 0) {
+                    last1YearHousingFundAvg = last1YearHousingFund.divide(BigDecimal.valueOf(last1YearHousingList.size()), 2, BigDecimal.ROUND_HALF_UP);
+                }
                 jsonResultMap.put(last1YearHousingFundAvgKey, last1YearHousingFundAvg);
                 //住房公积金-最近3年公积金平均值
                 String last3YearHousingFundAvgKey = fieldDefineCount.stream()
@@ -249,10 +252,14 @@ public class BaseFieldAtomicService {
                         .filter(e -> e.getEndMonth() != null &&
                                 DateUtils.getSpaceByUnit(DateUtils.convertStrToDate(e.getEndMonth(), DateUtils.YYYY_MM), currtDate, DateUtils.UNIT_MOUTHS) <= 36)
                         .collect(Collectors.toList());
-                BigDecimal last3YearHousingFundAvg = last3YearHousingList.stream()
+                BigDecimal last3YearHousingFund = last3YearHousingList.stream()
                         .map(e -> e.getMonthMoney() == null ? BigDecimal.ZERO : e.getMonthMoney())
-                        .reduce(BigDecimal.ZERO, BigDecimal::add)
-                        .divide(BigDecimal.valueOf(last3YearHousingList.size()), 2, BigDecimal.ROUND_HALF_UP);
+                        .reduce(BigDecimal.ZERO, BigDecimal::add);
+                BigDecimal last3YearHousingFundAvg = new BigDecimal("0.00");
+
+                if (last3YearHousingFund.compareTo(BigDecimal.ZERO) > 0) {
+                    last3YearHousingFundAvg = last3YearHousingFund.divide(BigDecimal.valueOf(last3YearHousingList.size()), 2, BigDecimal.ROUND_HALF_UP);
+                }
                 jsonResultMap.put(last3YearHousingFundAvgKey, last3YearHousingFundAvg);
 
                 List<Map> trsInfoList = new ArrayList<>();
@@ -1176,19 +1183,30 @@ public class BaseFieldAtomicService {
     public Map<String, String> relRepayInfoCalculate(JSONObject jsonObject, List<FieldDefineEntity> defineEntityList) {
         Map<String, String> jsonResultMap = new HashMap<>();
         SmryRepay smryRepay = jsonObject.toJavaObject(SmryRepay.class);
-        List<SmryRepayInfo> smryRepayInfoList = smryRepay.getSmryRepayInfoList();
+        List<SmryRepayInfo> smryRepayInfoList = Optional.ofNullable(smryRepay.getSmryRepayInfoList()).orElse(new ArrayList<SmryRepayInfo>());
         //按照借款人身份类别进行分组
-        Map<String, List<SmryRepayInfo>> repayInfoMap = smryRepayInfoList.stream().collect(Collectors.groupingBy(e -> e.getBoTypeCode()));
-
-        Map<String, List<FieldDefineEntity>> fieldDefineMap = defineEntityList.stream().collect(Collectors.groupingBy(e -> e.getParam()));
+        Map<String, List<SmryRepayInfo>> repayInfoMap = smryRepayInfoList.
+                stream()
+                .filter((e) -> e.getBoTypeCode() != null)
+                .collect(Collectors.groupingBy(e -> e.getBoTypeCode()));
+
+        Map<String, List<FieldDefineEntity>> fieldDefineMap = defineEntityList.stream()
+                .filter((e) -> e.getParam() != null)
+                .collect(Collectors.groupingBy(e -> e.getParam()));
         //个人
         List<FieldDefineEntity> perFieldDefineEntities = fieldDefineMap.get("1");
         //个人
         List<SmryRepayInfo> perSmryRepayInfos = repayInfoMap.get("1");
-        //按类别进行分组
-        Map<String, List<SmryRepayInfo>> perRespCodeMap = perSmryRepayInfos.stream().collect(Collectors.groupingBy(e -> e.getRelPayRespDesc()));
-        List<SmryRepayInfo> perGuaranteeList = perRespCodeMap.get("担保责任");
-        List<SmryRepayInfo> perOtherList = perRespCodeMap.get("其他相关还款责任");
+        List<SmryRepayInfo> perGuaranteeList = null;
+        List<SmryRepayInfo> perOtherList = null;
+        if (perSmryRepayInfos != null) {
+            //按类别进行分组
+            Map<String, List<SmryRepayInfo>> perRespCodeMap = perSmryRepayInfos.stream()
+                    .filter((e) -> e.getRelPayRespDesc() != null)
+                    .collect(Collectors.groupingBy(e -> e.getRelPayRespDesc()));
+            perGuaranteeList = perRespCodeMap.get("担保责任");
+            perOtherList = perRespCodeMap.get("其他相关还款责任");
+        }
         for (FieldDefineEntity perFieldDefineEntity : perFieldDefineEntities) {
             String path = perFieldDefineEntity.getPath();
             String name = perFieldDefineEntity.getName();
@@ -1207,9 +1225,15 @@ public class BaseFieldAtomicService {
         }
         //企业
         List<SmryRepayInfo> entSmryRepayInfos = repayInfoMap.get("2");
-        Map<String, List<SmryRepayInfo>> entRespCodeMap = entSmryRepayInfos.stream().collect(Collectors.groupingBy(e -> e.getRelPayRespDesc()));
-        List<SmryRepayInfo> entGuaranteeList = entRespCodeMap.get("担保责任");
-        List<SmryRepayInfo> entOtherList = entRespCodeMap.get("其他相关还款责任");
+        List<SmryRepayInfo> entGuaranteeList = null;
+        List<SmryRepayInfo> entOtherList = null;
+        if (entSmryRepayInfos != null) {
+            Map<String, List<SmryRepayInfo>> entRespCodeMap = entSmryRepayInfos.stream()
+                    .filter((e) -> e.getRelPayRespDesc() != null)
+                    .collect(Collectors.groupingBy(e -> e.getRelPayRespDesc()));
+            entGuaranteeList = entRespCodeMap.get("担保责任");
+            entOtherList = entRespCodeMap.get("其他相关还款责任");
+        }
         List<FieldDefineEntity> entFieldDefineEntities = fieldDefineMap.get("2");
         for (FieldDefineEntity entFieldDefineEntity : entFieldDefineEntities) {
             String path = entFieldDefineEntity.getPath();

+ 8 - 1
src/main/java/com/kexun/service/field/BaseFieldPackageJsonService.java

@@ -125,7 +125,14 @@ public class BaseFieldPackageJsonService implements IBaseFieldPackageJsonService
             Object object = SpringContextUtil.getBean(formulaClass);
             Class<?> aClass = object.getClass();
             Method method = aClass.getMethod(formulaMethod, JSONObject.class, List.class);
-            Object invoke = method.invoke(object, jsonObject, fieldDefineEntities);
+            Object invoke = null;
+            try {
+                invoke = method.invoke(object, jsonObject, fieldDefineEntities);
+            }catch (Exception e){
+                e.printStackTrace();
+                log.error("调用衍生字段处理类={},方法为={}",formulaClass,formulaMethod);
+                throw new Exception(e.getMessage());
+            }
             handleBaseField(invoke,infoMap,jsonMap,jsonKey,subJsonMap,infoList);
             //计算和产品关联的信息
             if(fieldDefineEntityList!=null && fieldDefineEntityList.size()>0){

+ 6 - 1
src/main/java/com/kexun/service/impl/FileServiceImpl.java

@@ -32,6 +32,11 @@ public class FileServiceImpl {
      */
     @Value("${report.file.jsonTargetPath}")
     private String jsonTargetPath;
+    /**
+     * 解析出来的json文件
+     */
+    @Value("${report.file.xmlTargetPath}")
+    private String xmlTargetPath;
 
     /**
      * 上传文件
@@ -66,7 +71,7 @@ public class FileServiceImpl {
         reportFileService.saveOrUpdate(reportFileEntity);
         //上传文件到服务器的目录
         //xml文件
-        writeFile(xmlContext,fileName+".xml",xmlSourcePath);
+        writeFile(xmlContext,fileName+".xml",xmlTargetPath);
         //json文件
         writeFile(jsonContext,fileName+".txt",jsonTargetPath);
     }

+ 10 - 0
src/main/java/com/kexun/service/impl/ReportInfoServiceImpl.java

@@ -56,6 +56,16 @@ public class ReportInfoServiceImpl extends ServiceImpl<ReportInfoMapper, ReportI
         reportInfoMapper.updateReportInfo(reportInfoDTO);
     }
 
+    /**
+     * 修改状态
+     * @param status
+     * @param id
+     */
+    @Override
+    public void updateReportInfoStatus(String status, Long id) {
+        reportInfoMapper.updateReportInfoStatus(status,id);
+    }
+
     /**
      * 按条件查询报文信息
      *

+ 0 - 1
src/main/java/com/kexun/service/impl/XmlFileHandlerServiceImpl.java

@@ -55,7 +55,6 @@ public class XmlFileHandlerServiceImpl implements XmlFileHandlerService {
                 File[] fileLists = files.listFiles();
                 if (fileLists != null) {
                     //创建目录文件路径
-
                     for (File fileList : fileLists) {
                         //只处理xml文件
                         if (fileList.isFile() && fileList.getName().endsWith(".xml")) {

+ 1 - 2
src/main/java/com/kexun/task/ReportParseJobHandler.java

@@ -98,11 +98,10 @@ public class ReportParseJobHandler {
                 } catch (Exception e) {
                     e.printStackTrace();
                     //解析失败,状态修改成失败
-                    reportInfo.setStatus(ReportStatusEnum.QUERY_FAIL.getValue());
+                    reportInfoService.updateReportInfoStatus(ReportStatusEnum.QUERY_FAIL.getValue(),reportInfo.getId());
                     log.error("解析出现异常,异常信息如下:{}", e.getStackTrace());
                     new RRException("解析出现异常,异常信息:" + e.getMessage(), -1);
                 }
-
             } else {
                 log.info("获取到的解析内容为空,不做处理");
             }

+ 2 - 0
src/main/resources/application-dev.yml

@@ -73,6 +73,8 @@ report:
     # 解析出来的json文件
     #jsonTargetPath: "/home/credit/file/json/"
     jsonTargetPath: "/Users/lgs/work/json/"
+    # 解析出来的xml文件
+    xmlTargetPath: "/Users/lgs/work/xml/"
     # 存放的model文件
     #modelTargetPath: "/home/credit/file/model/"
     modelTargetPath: "/Users/lgs/work/model/"

+ 2 - 0
src/main/resources/application-prod.yml

@@ -73,6 +73,8 @@ report:
     # 解析出来的json文件
     jsonTargetPath: "/home/credit/file/json/"
     #jsonTargetPath: "/Users/lgs/work/json/"
+    # 解析出来的xml文件
+    xmlTargetPath: "/home/credit/file/xml/"
     # 存放的model文件
     modelTargetPath: "/home/credit/file/model/"
     #modelTargetPath: "/Users/lgs/work/model/"

+ 2 - 0
src/main/resources/application-test.yml

@@ -73,6 +73,8 @@ report:
     # 解析出来的json文件
     jsonTargetPath: "/home/credit/file/json/"
     #jsonTargetPath: "/Users/lgs/work/json/"
+    # 解析出来的xml文件
+    xmlTargetPath: "/home/credit/file/xml/"
     # 存放的model文件
     modelTargetPath: "/home/credit/file/model/"
     #modelTargetPath: "/Users/lgs/work/model/"

+ 3 - 1
src/main/resources/application.yml

@@ -89,7 +89,9 @@ report:
     xmlBackPath: "/home/credit/file/back/"
     #xmlBackPath: "/Users/lgs/work/back/"
     # 解析出来的json文件
-    jsonTargetPath: "/home/credit/file/json/"
+    jsonTargetPath: "/home/credit/file/txt/"
+    # 解析出来的xml文件
+    xmlTargetPath: "/home/credit/file/xml/"
     #jsonTargetPath: "/Users/lgs/work/json/"
     # 存放的model文件
     modelTargetPath: "/home/credit/file/model/"

+ 6 - 0
src/main/resources/mapper/ReportInfoMapper.xml

@@ -38,4 +38,10 @@
         where id = #{id}
     </update>
 
+    <update id="updateReportInfoStatus">
+        update report_info
+        set status = #{status}
+        where id = #{id}
+    </update>
+
 </mapper>