Browse Source

-修改特种设备首页压力管道计算sql查询

jiangbiao 3 years ago
parent
commit
a8b6e5b983

+ 25 - 31
master/src/main/java/com/ruoyi/project/sems/controller/SpecHomeController.java

@@ -26,8 +26,6 @@ import org.springframework.web.bind.annotation.RestController;
 import java.math.BigDecimal;
 import java.text.DecimalFormat;
 import java.util.*;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
 
 /**
  * 特种设备申请Controller
@@ -207,46 +205,42 @@ public class SpecHomeController extends BaseController
     public AjaxResult sumYlgcLength(@RequestBody Map<String, Object> params){
         List plantIds = (List) params.get("plantIds");
 //        查询管道长度
-        List<TSpecdevYlgd> gdList = tSpecdevYlgdService.list(new QueryWrapper<TSpecdevYlgd>().select("length")
-                        .eq("STATUS" , 1)
-                        .eq("del_flag" , 0)
-                        .in("plant_code",plantIds)
-//                        .in("unit",unitIds)
-//                .eq(!StringUtils.isBlank((String)params.get("plantName")) , "plant_code" ,params.get("plantName"))
-//                        .and(unitIds.size()>0 ,i -> i.in("unit",unitIds).or().in("plant_code",unitIds).or().isNull("unit"))
-        );
-        double allLength = 0;
-        ExecutorService executorService = Executors.newFixedThreadPool(100);
-        for (int i = 0; i < gdList.size(); i++) {
-            executorService.execute(() -> {
-
-            });
-            double gdLength = 0;
-            if (!StringUtils.isBlank(gdList.get(i).getLength())) {
-                if (gdList.get(i).getLength().indexOf("\n") > -1) {
-                    String[] arr = gdList.get(i).getLength().split("\n");
+//        List<TSpecdevYlgd> gdList = tSpecdevYlgdService.list(new QueryWrapper<TSpecdevYlgd>()
+//                        .eq("STATUS" , 1)
+//                        .eq("del_flag" , 0)
+//                        .in("plant_code",plantIds)
+////                        .in("unit",unitIds)
+////                .eq(!StringUtils.isBlank((String)params.get("plantName")) , "plant_code" ,params.get("plantName"))
+////                        .and(unitIds.size()>0 ,i -> i.in("unit",unitIds).or().in("plant_code",unitIds).or().isNull("unit"))
+//        );
+        TSpecdevYlgd tSpecdevYlgd = new TSpecdevYlgd();
+        tSpecdevYlgd.setPlantCodes(plantIds);
+        List<TSpecdevYlgd> gdList = tSpecdevYlgdService.selectYlgdLengthList(tSpecdevYlgd);
+        ArrayList<Double> lengthList = new ArrayList<>();
+        for (TSpecdevYlgd ylgd : gdList) {
+            if (!StringUtils.isBlank(ylgd.getLength())) {
+                if (ylgd.getLength().indexOf("\n") > -1) {
+                    String[] arr = ylgd.getLength().split("\n");
                     for (int j = 0; j < arr.length; j++) {
                         try {
-                            gdLength += Double.parseDouble(arr[j]);
-                        }catch (NumberFormatException e) {
-                            logger.error(JSON.toJSONString(e));
-                            continue;
+                            lengthList.add(Double.valueOf(arr[j]));
+                        } catch (NumberFormatException e) {
+
                         }
                     }
                 }else {
                     try {
-                        gdLength = Double.parseDouble(gdList.get(i).getLength());
-                    }catch (NumberFormatException e) {
-                        logger.error(JSON.toJSONString(e));
+                        lengthList.add(Double.valueOf(ylgd.getLength()));
+                    } catch (NumberFormatException e) {
+
                     }
                 }
             }
-            allLength += gdLength;
         }
-        executorService.shutdown();
+        double sum = lengthList.stream().mapToDouble(x->x).sum();
         DecimalFormat df = new DecimalFormat("0.00#");
-        System.out.println(df.format(allLength));
-        return AjaxResult.success(df.format(allLength));
+        logger.info("==========sum:"+df.format(sum));
+        return AjaxResult.success(df.format(sum));
     }
 
     /**

+ 14 - 2
master/src/main/java/com/ruoyi/project/sems/domain/TSpecdevYlgd.java

@@ -1,7 +1,5 @@
 package com.ruoyi.project.sems.domain;
 
-import java.util.Date;
-
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
@@ -10,6 +8,9 @@ import com.ruoyi.framework.web.domain.BaseEntity;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
 
+import java.util.Date;
+import java.util.List;
+
 /**
  * 特种设备压力管道台账对象 t_specdev_ylgd
  *
@@ -258,6 +259,17 @@ public class TSpecdevYlgd extends BaseEntity
     @TableField(exist = false)
     private String checkYear;
 
+    @TableField(exist = false)
+    private List<String> plantCodes;
+
+    public List<String> getPlantCodes() {
+        return plantCodes;
+    }
+
+    public void setPlantCodes(List<String> plantCodes) {
+        this.plantCodes = plantCodes;
+    }
+
     public Long getHiFlag() {
         return hiFlag;
     }

+ 5 - 4
master/src/main/java/com/ruoyi/project/sems/mapper/TSpecdevYlgdMapper.java

@@ -1,14 +1,12 @@
 package com.ruoyi.project.sems.mapper;
 
-import java.util.List;
-
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.ruoyi.framework.aspectj.lang.annotation.DataScope;
 import com.ruoyi.framework.aspectj.lang.annotation.DataScopePlant;
-import com.ruoyi.project.sems.domain.TSpecdevGl;
 import com.ruoyi.project.sems.domain.TSpecdevYlgd;
 import com.ruoyi.project.sems.his.domain.TSpechiYlgd;
 
+import java.util.List;
+
 /**
  * 特种设备压力管道台账Mapper接口
  *
@@ -41,6 +39,9 @@ public interface TSpecdevYlgdMapper extends BaseMapper<TSpecdevYlgd> {
     @DataScopePlant(deptAlias = "d")
     public List<TSpecdevYlgd> selectTSpecdevYlgdList(TSpecdevYlgd tSpecdevYlgd);
 
+    @DataScopePlant(deptAlias = "d")
+    public List<TSpecdevYlgd> selectYlgdLengthList(TSpecdevYlgd tSpecdevYlgd);
+
     List<TSpecdevYlgd> selectTSpecdevYlgdListByYear(TSpecdevYlgd tSpecdevYlgd);
     /**
      * 新增特种设备压力管道台账

+ 3 - 3
master/src/main/java/com/ruoyi/project/sems/service/ITSpecdevYlgdService.java

@@ -1,12 +1,11 @@
 package com.ruoyi.project.sems.service;
 
-import java.util.List;
-
 import com.baomidou.mybatisplus.extension.service.IService;
-import com.ruoyi.project.sems.domain.TSpecdevGl;
 import com.ruoyi.project.sems.domain.TSpecdevYlgd;
 import com.ruoyi.project.sems.his.domain.TSpechiYlgd;
 
+import java.util.List;
+
 /**
  * 特种设备压力管道台账Service接口
  *
@@ -30,6 +29,7 @@ public interface ITSpecdevYlgdService extends IService<TSpecdevYlgd>
      * @return 特种设备压力管道台账集合
      */
     public List<TSpecdevYlgd> selectTSpecdevYlgdList(TSpecdevYlgd tSpecdevYlgd);
+    public List<TSpecdevYlgd> selectYlgdLengthList(TSpecdevYlgd tSpecdevYlgd);
     List<TSpecdevYlgd> selectTSpecdevYlgdListByYear(TSpecdevYlgd tSpecdevYlgd);
     /**
      * 新增特种设备压力管道台账

+ 11 - 7
master/src/main/java/com/ruoyi/project/sems/service/impl/TSpecdevYlgdServiceImpl.java

@@ -1,16 +1,14 @@
 package com.ruoyi.project.sems.service.impl;
 
-import java.util.List;
-
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.ruoyi.project.sems.domain.TSpecdevGl;
+import com.ruoyi.project.sems.domain.TSpecdevYlgd;
 import com.ruoyi.project.sems.his.domain.TSpechiYlgd;
-import com.ruoyi.project.sems.mapper.TSpecdevGlMapper;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
 import com.ruoyi.project.sems.mapper.TSpecdevYlgdMapper;
-import com.ruoyi.project.sems.domain.TSpecdevYlgd;
 import com.ruoyi.project.sems.service.ITSpecdevYlgdService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
 
 /**
  * 特种设备压力管道台账Service业务层处理
@@ -48,6 +46,12 @@ public class TSpecdevYlgdServiceImpl extends ServiceImpl<TSpecdevYlgdMapper, TSp
         return tSpecdevYlgdMapper.selectTSpecdevYlgdList(tSpecdevYlgd);
     }
 
+    @Override
+    public List<TSpecdevYlgd> selectYlgdLengthList(TSpecdevYlgd tSpecdevYlgd)
+    {
+        return tSpecdevYlgdMapper.selectYlgdLengthList(tSpecdevYlgd);
+    }
+
     @Override
     public List<TSpecdevYlgd> selectTSpecdevYlgdListByYear(TSpecdevYlgd tSpecdevYlgd) {
          return tSpecdevYlgdMapper.selectTSpecdevYlgdListByYear(tSpecdevYlgd);

+ 14 - 0
master/src/main/resources/mybatis/sems/TSpecdevYlgdMapper.xml

@@ -476,4 +476,18 @@
         )
     </update>
 
+    <select id="selectYlgdLengthList" fetchSize="1000" parameterType="TSpecdevYlgd" resultMap="TSpecdevYlgdResult">
+        SELECT *
+        FROM T_SPECDEV_YLGD
+        <where>
+            and del_flag=0
+            and status=1
+            and plant_code in
+            <foreach collection="plantCodes" item="item" open="(" separator="," close=")" index="index">
+                #{item}
+            </foreach>
+        </where>
+        --${params.dataScopePlant}
+    </select>
+
 </mapper>