Quellcode durchsuchen

产业产值、补贴、产能三个模块:优化查询功能

zhuoning vor 2 Jahren
Ursprung
Commit
7cce1d2cf5

+ 11 - 6
huimv-cattle/src/main/java/com/huimv/cattle/service/impl/IndustryOutputServiceImpl.java

@@ -43,13 +43,18 @@ public class IndustryOutputServiceImpl extends ServiceImpl<IndustryOutputMapper,
             farmCode = TokenSign.getFarmCode(request);
         }
         String yearNum = paramsMap.get("yearNum");
-        if (StringUtils.isBlank(yearNum)){
-            yearNum = "0";
+//        if (StringUtils.isBlank(yearNum)){
+//            yearNum = "0";
+//        }
+        QueryWrapper<IndustryOutput> queryWrapper = new QueryWrapper<IndustryOutput>();
+//        queryWrapper.between("year", Integer.valueOf(dateUtil.getThisYear()) - Integer.valueOf(yearNum), Integer.valueOf(dateUtil.getThisYear()));
+        if(StringUtils.isNotBlank(yearNum)) {
+            queryWrapper.between("year", Integer.valueOf(dateUtil.getThisYear()) - Integer.valueOf(yearNum), Integer.valueOf(dateUtil.getThisYear()));
         }
-        List<IndustryOutput> industryOutputs = industryOutputMapper.selectList(new QueryWrapper<IndustryOutput>()
-//                .between("year", Integer.valueOf(dateUtil.getThisYear()) - Integer.valueOf(yearNum), Integer.valueOf(dateUtil.getThisYear()))
-                .eq("farm_code",farmCode)
-                .orderByDesc("year"));
+        queryWrapper.eq("farm_code",farmCode);
+        queryWrapper.orderByDesc("year");
+//        queryWrapper.last("LIMIT "+yearNum);
+        List<IndustryOutput> industryOutputs = industryOutputMapper.selectList(queryWrapper);
         if (industryOutputs.isEmpty()) {
             IndustryOutput industryOutput = new IndustryOutput();
             industryOutput.setYear(dateUtil.getThisYear());

+ 20 - 17
huimv-cattle/src/main/java/com/huimv/cattle/service/impl/ProductionCapacityServiceImpl.java

@@ -23,7 +23,7 @@ import java.util.*;
 
 /**
  * <p>
- *  服务实现类
+ * 服务实现类
  * </p>
  *
  * @author zn
@@ -40,42 +40,45 @@ public class ProductionCapacityServiceImpl extends ServiceImpl<ProductionCapacit
     @Override
     public Result getProductionCapacity(HttpServletRequest request, Map<String, String> paramsMap) {
         String farmCode = paramsMap.get("farmCode");
-        if (StringUtils.isBlank(farmCode)){
+        if (StringUtils.isBlank(farmCode)) {
             farmCode = TokenSign.getFarmCode(request);
         }
         String yearNum = paramsMap.get("yearNum");
-        if (StringUtils.isBlank(yearNum)){
-            yearNum = "0";
+//        if (StringUtils.isBlank(yearNum)){
+//            yearNum = "0";
+//        }
+        QueryWrapper<ProductionCapacity> queryWrapper = new QueryWrapper<>();
+        if (StringUtils.isNotBlank(yearNum)) {
+            queryWrapper.between("year", Integer.valueOf(dateUtil.getThisYear()) - Integer.valueOf(yearNum), Integer.valueOf(dateUtil.getThisYear()));
         }
-        List<ProductionCapacity> productionCapacities = productionCapacityMapper.selectList(new QueryWrapper<ProductionCapacity>()
-//                .between("year", Integer.valueOf(dateUtil.getThisYear()) - Integer.valueOf(yearNum), Integer.valueOf(dateUtil.getThisYear()))
-                .eq("farm_code",farmCode)
-                .orderByDesc("year"));
-        if (ObjectUtil.isEmpty(productionCapacities)){
+        queryWrapper.eq("farm_code", farmCode);
+        queryWrapper.orderByDesc("year");
+        List<ProductionCapacity> productionCapacities = productionCapacityMapper.selectList(queryWrapper);
+        if (ObjectUtil.isEmpty(productionCapacities)) {
             ProductionCapacity productionCapacity1 = new ProductionCapacity();
             productionCapacity1.setYear(Integer.valueOf(dateUtil.getThisYear()));
             productionCapacity1.setFarmCode(farmCode);
             productionCapacities.add(productionCapacity1);
             productionCapacityMapper.insert(productionCapacity1);
         }
-        return new Result(ResultCode.SUCCESS,productionCapacities);
+        return new Result(ResultCode.SUCCESS, productionCapacities);
     }
 
     @Override
     public Result saveProductionCapacity(HttpServletRequest request, Map<String, String> paramsMap) {
         String farmCode = paramsMap.get("farmCode");
-        if (StringUtils.isBlank(farmCode)){
+        if (StringUtils.isBlank(farmCode)) {
             farmCode = TokenSign.getFarmCode(request);
         }
         String list = paramsMap.get("list");
         JSONArray listJa = JSONArray.parseArray(list);
         List<ProductionCapacity> productionCapacityList = listJa.toJavaList(ProductionCapacity.class);
         if (checkRepeat(productionCapacityList)) {
-            return new Result(10001,"有重复年份",false);
-        }else {
+            return new Result(10001, "有重复年份", false);
+        } else {
             productionCapacityMapper.deleteAll(farmCode);
         }
-        for (int a = listJa.size()-1; a >= 0 ; a--){
+        for (int a = listJa.size() - 1; a >= 0; a--) {
             JSONObject jsonObject = listJa.getJSONObject(a);
             Integer year = jsonObject.getInteger("year");
             ProductionCapacity productionCapacity = new ProductionCapacity();
@@ -87,12 +90,12 @@ public class ProductionCapacityServiceImpl extends ServiceImpl<ProductionCapacit
         return new Result(ResultCode.SUCCESS);
     }
 
-    private Boolean checkRepeat(List<ProductionCapacity> list){
+    private Boolean checkRepeat(List<ProductionCapacity> list) {
         List<Integer> collectionOptionList = new ArrayList<>();
-        for (ProductionCapacity a : list){
+        for (ProductionCapacity a : list) {
             collectionOptionList.add(a.getYear());
         }
         Set<Integer> set = new HashSet<>(collectionOptionList);
-        return collectionOptionList.size()!= set.size();
+        return collectionOptionList.size() != set.size();
     }
 }

+ 21 - 17
huimv-cattle/src/main/java/com/huimv/cattle/service/impl/SubsidyCountServiceImpl.java

@@ -23,7 +23,7 @@ import java.util.*;
 
 /**
  * <p>
- *  服务实现类
+ * 服务实现类
  * </p>
  *
  * @author zn
@@ -40,42 +40,46 @@ public class SubsidyCountServiceImpl extends ServiceImpl<SubsidyCountMapper, Sub
     @Override
     public Result getSubsidyCount(HttpServletRequest request, Map<String, String> paramsMap) {
         String farmCode = paramsMap.get("farmCode");
-        if (StringUtils.isBlank(farmCode)){
+        if (StringUtils.isBlank(farmCode)) {
             farmCode = TokenSign.getFarmCode(request);
         }
         String yearNum = paramsMap.get("yearNum");
-        if (StringUtils.isBlank(yearNum)){
-            yearNum = "0";
+//        if (StringUtils.isBlank(yearNum)){
+//            yearNum = "0";
+//        }
+        QueryWrapper<SubsidyCount> queryWrapper = new QueryWrapper<SubsidyCount>();
+        if(StringUtils.isNotBlank(yearNum)) {
+            queryWrapper.between("year", Integer.valueOf(dateUtil.getThisYear()) - Integer.valueOf(yearNum), Integer.valueOf(dateUtil.getThisYear()));
         }
-        List<SubsidyCount> subsidyCounts = subsidyCountMapper.selectList(new QueryWrapper<SubsidyCount>()
-//                .between("year", Integer.valueOf(dateUtil.getThisYear()) - Integer.valueOf(yearNum), Integer.valueOf(dateUtil.getThisYear()))
-                .eq("farm_code",farmCode)
-                .orderByDesc("year"));
-        if (ObjectUtil.isEmpty(subsidyCounts)){
+        queryWrapper.eq("farm_code", farmCode);
+        queryWrapper.orderByDesc("year");
+
+        List<SubsidyCount> subsidyCounts = subsidyCountMapper.selectList(queryWrapper);
+        if (ObjectUtil.isEmpty(subsidyCounts)) {
             SubsidyCount subsidyCount1 = new SubsidyCount();
             subsidyCount1.setYear(Integer.valueOf(dateUtil.getThisYear()));
             subsidyCount1.setFarmCode(farmCode);
             subsidyCounts.add(subsidyCount1);
             subsidyCountMapper.insert(subsidyCount1);
         }
-        return new Result(ResultCode.SUCCESS,subsidyCounts);
+        return new Result(ResultCode.SUCCESS, subsidyCounts);
     }
 
     @Override
     public Result saveSubsidyCount(HttpServletRequest request, Map<String, String> paramsMap) {
         String farmCode = paramsMap.get("farmCode");
-        if (StringUtils.isBlank(farmCode)){
+        if (StringUtils.isBlank(farmCode)) {
             farmCode = TokenSign.getFarmCode(request);
         }
         String list = paramsMap.get("list");
         JSONArray listJa = JSONArray.parseArray(list);
         List<SubsidyCount> SubsidyCountList = listJa.toJavaList(SubsidyCount.class);
         if (checkRepeat(SubsidyCountList)) {
-            return new Result(10001,"有重复年份",false);
-        }else {
+            return new Result(10001, "有重复年份", false);
+        } else {
             subsidyCountMapper.deleteAll(farmCode);
         }
-        for (int a = listJa.size()-1; a >= 0 ; a--){
+        for (int a = listJa.size() - 1; a >= 0; a--) {
             JSONObject jsonObject = listJa.getJSONObject(a);
             Integer year = jsonObject.getInteger("year");
             SubsidyCount subsidyCount = new SubsidyCount();
@@ -87,12 +91,12 @@ public class SubsidyCountServiceImpl extends ServiceImpl<SubsidyCountMapper, Sub
         return new Result(ResultCode.SUCCESS);
     }
 
-    private Boolean checkRepeat(List<SubsidyCount> list){
+    private Boolean checkRepeat(List<SubsidyCount> list) {
         List<Integer> collectionOptionList = new ArrayList<>();
-        for (SubsidyCount a : list){
+        for (SubsidyCount a : list) {
             collectionOptionList.add(a.getYear());
         }
         Set<Integer> set = new HashSet<>(collectionOptionList);
-        return collectionOptionList.size()!= set.size();
+        return collectionOptionList.size() != set.size();
     }
 }