Kaynağa Gözat

数据统计-通过项目名称模糊查询

黄远 5 yıl önce
ebeveyn
işleme
ef6d6c33ab

+ 4 - 0
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/dao/model/request/AnnualInspectionDataRequest.java

@@ -9,4 +9,8 @@ import lombok.Data;
  */
 @Data
 public class AnnualInspectionDataRequest extends CommonRequest {
+    /**
+     * 项目名称
+     */
+    private String projectName;
 }

+ 1 - 1
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/dao/model/response/RegionPaymentResponse.java

@@ -20,7 +20,7 @@ public class RegionPaymentResponse {
     private Double planMoney;
 
     /**
-     * 时间收款
+     * 实际收款
      */
     private Double workMoney;
 

+ 25 - 15
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/service/AnnualInspectionDataService.java

@@ -8,6 +8,7 @@ import cn.com.ty.lift.batch.applet.dao.model.request.CommonRequest;
 import cn.com.ty.lift.batch.applet.util.DataStatisticsUtil;
 import cn.com.ty.lift.common.constants.ApiConstants;
 import cn.com.xwy.boot.web.dto.RestResponse;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
@@ -84,7 +85,7 @@ public class AnnualInspectionDataService {
         List<AnnualInspectionDataModel> annualInspectionDataModelList = getAnnualInspectionDataListFromRedis(
                 annualInspectionDataRequest);
         Map<Integer, Long> annualStatusToNum = DataStatisticsConstants.ANNUAL_STATUS_TO_NUM;
-            if(annualInspectionDataModelList != null && annualInspectionDataModelList.size() > 0){
+        if (annualInspectionDataModelList != null && annualInspectionDataModelList.size() > 0) {
             //设置计划年检条数
             annualStatusToNum.put(1, annualInspectionDataModelList.stream().count());
             //设置完成年检条数
@@ -106,7 +107,7 @@ public class AnnualInspectionDataService {
      * @date 2020/2/5 4:11 下午
      */
     public RestResponse annualProgress(AnnualInspectionDataRequest annualInspectionDataRequest) {
-        List<AnnualInspectionDataModel> annualInspectionDataModelList  = getProjectAnnualProgress(
+        List<AnnualInspectionDataModel> annualInspectionDataModelList = getProjectAnnualProgress(
                 annualInspectionDataRequest, "top5");
         return RestResponse.success(annualInspectionDataModelList, ApiConstants.RESULT_SUCCESS, "获取统计数据成功");
     }
@@ -118,7 +119,7 @@ public class AnnualInspectionDataService {
      * @date 2020/2/5 4:14 下午
      */
     public RestResponse allProjectAnnualProgress(AnnualInspectionDataRequest annualInspectionDataRequest) {
-        List<AnnualInspectionDataModel> annualInspectionDataModelList  = getProjectAnnualProgress(
+        List<AnnualInspectionDataModel> annualInspectionDataModelList = getProjectAnnualProgress(
                 annualInspectionDataRequest, "all");
         return RestResponse.success(annualInspectionDataModelList, ApiConstants.RESULT_SUCCESS, "获取统计数据成功");
     }
@@ -134,19 +135,28 @@ public class AnnualInspectionDataService {
         //从redis中获取当前公司年检数据
         List<AnnualInspectionDataModel> annualInspectionDataModelList = getAnnualInspectionDataListFromRedis(
                 annualInspectionDataRequest);
-        //获取全部项目的年检进度
-        if ("all".equals(countFlag)) {
-            //获取所有项目的年检进度,按照计划年检时间顺序排列
-            annualInspectionDataModelList = annualInspectionDataModelList.stream()
-                    .sorted(Comparator.comparing(AnnualInspectionDataModel::getPlanDate))
-                    .collect(Collectors.toList());
-        } else {
-            //获取计划年检时间前五的项目的年检进度,按照计划年检时间顺序排列
-            annualInspectionDataModelList = annualInspectionDataModelList.stream()
-                    .sorted(Comparator.comparing(AnnualInspectionDataModel::getPlanDate)).limit(5)
-                    .collect(Collectors.toList());
+        if (annualInspectionDataModelList != null && annualInspectionDataModelList.size() > 0) {
+            //获取全部项目的年检进度
+            if ("all".equals(countFlag)) {
+                if (StringUtils.isNotBlank(annualInspectionDataRequest.getProjectName())) {
+                    //通过项目名称模糊查询
+                    annualInspectionDataModelList = annualInspectionDataModelList.stream()
+                            //通过名称模糊匹配
+                            .filter(a -> DataStatisticsUtil.strMatch(
+                                    annualInspectionDataRequest.getProjectName(), a.getProjectName()))
+                            .collect(Collectors.toList());
+                }
+                //获取所有项目的年检进度,按照计划年检时间顺序排列
+                annualInspectionDataModelList = annualInspectionDataModelList.stream()
+                        .sorted(Comparator.comparing(AnnualInspectionDataModel::getPlanDate))
+                        .collect(Collectors.toList());
+            } else {
+                //获取计划年检时间前五的项目的年检进度,按照计划年检时间顺序排列
+                annualInspectionDataModelList = annualInspectionDataModelList.stream()
+                        .sorted(Comparator.comparing(AnnualInspectionDataModel::getPlanDate)).limit(5)
+                        .collect(Collectors.toList());
+            }
         }
         return annualInspectionDataModelList;
-
     }
 }

+ 17 - 0
lift-batch-service/src/main/java/cn/com/ty/lift/batch/applet/util/DataStatisticsUtil.java

@@ -4,6 +4,7 @@ import cn.com.ty.lift.batch.applet.constants.DataStatisticsConstants;
 import cn.com.ty.lift.batch.applet.dao.model.BaseDataModel;
 import cn.com.ty.lift.batch.applet.dao.model.request.CommonRequest;
 import com.google.common.collect.Maps;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.data.redis.core.RedisTemplate;
 
 import java.math.BigDecimal;
@@ -13,6 +14,7 @@ import java.time.format.DateTimeFormatter;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 /**
@@ -186,6 +188,21 @@ public class DataStatisticsUtil {
         return result;
     }
 
+    /**
+     * @param subField 模糊查询字段
+     * @param field 字段
+     * @return
+     * @description 查看字符串是否包含子字符串
+     * @date 2020/2/10 6:43 下午
+     */
+    public static boolean strMatch(String subField, String field) {
+        if(StringUtils.isNotBlank(subField) && StringUtils.isNotBlank(field)){
+           Pattern pattern = Pattern.compile(".*" + subField + ".*");
+           return pattern.matcher(field).find();
+        }
+        return false;
+    }
+
     /**
      * @param yearInterval 年份间隔 正值:之后的年份 负值:之前的年份
      * @return