瀏覽代碼

指标配置导入和导出接口

wukai 8 月之前
父節點
當前提交
2ec53de6d3

+ 85 - 85
jjt-admin/pom.xml

@@ -76,78 +76,13 @@
 
     <build>
         <plugins>
-<!--            <plugin>-->
-<!--                <groupId>org.springframework.boot</groupId>-->
-<!--                <artifactId>spring-boot-maven-plugin</artifactId>-->
-<!--                <version>2.5.15</version>-->
-<!--                <configuration>-->
-<!--                    <fork>true</fork> &lt;!&ndash; 如果没有该配置,devtools不会生效 &ndash;&gt;-->
-<!--                </configuration>-->
-<!--                <executions>-->
-<!--                    <execution>-->
-<!--                        <goals>-->
-<!--                            <goal>repackage</goal>-->
-<!--                        </goals>-->
-<!--                    </execution>-->
-<!--                </executions>-->
-<!--            </plugin>-->
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-war-plugin</artifactId>
-                <version>3.1.0</version>
-                <configuration>
-                    <failOnMissingWebXml>false</failOnMissingWebXml>
-                    <warName>${project.artifactId}</warName>
-                </configuration>
-            </plugin>
-
-            <!--下面这段是分离打包-->
-
             <plugin>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
                 <version>2.5.15</version>
                 <configuration>
                     <fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
-                    <executable>true</executable>
-                    <layout>ZIP</layout>
-                    <!--这里是填写需要包含进去的jar,
-                         必须项目中的某些模块,会经常变动,那么就应该将其坐标写进来
-                         如果没有则nothing ,表示不打包依赖 -->
-                    <includes>
-                        <!-- 定时任务-->
-                        <include>
-                            <groupId>com.jjt</groupId>
-                            <artifactId>jjt-quartz</artifactId>
-                        </include>
-                        <!-- 代码生成-->
-                        <include>
-                            <groupId>com.jjt</groupId>
-                            <artifactId>jjt-generator</artifactId>
-                        </include>
-                        <!-- 核心模块-->
-                        <include>
-                            <groupId>com.jjt</groupId>
-                            <artifactId>jjt-framework</artifactId>
-                        </include>
-                        <!-- 系统模块-->
-                        <include>
-                            <groupId>com.jjt</groupId>
-                            <artifactId>jjt-system</artifactId>
-                        </include>
-                        <!-- 通用工具-->
-                        <include>
-                            <groupId>com.jjt</groupId>
-                            <artifactId>jjt-common</artifactId>
-                        </include>
-                        <!-- 业务模块-->
-                        <include>
-                            <groupId>com.jjt</groupId>
-                            <artifactId>jjt-biz</artifactId>
-                        </include>
-                    </includes>
                 </configuration>
-
                 <executions>
                     <execution>
                         <goals>
@@ -155,30 +90,95 @@
                         </goals>
                     </execution>
                 </executions>
-
             </plugin>
-
-            <!--拷贝依赖到jar外面的lib目录-->
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-dependency-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <id>copy</id>
-                        <phase>package</phase>
-                        <goals>
-                            <goal>copy-dependencies</goal>
-                        </goals>
-                        <configuration>
-                            <!--指定的依赖路径-->
-                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
-                            <!--排除的ArtifactId-->
-                            <excludeArtifactIds>jjt-framework,jjt-system,jjt-quartz,jjt-generator,jjt-common,jjt-biz
-                            </excludeArtifactIds>
-                        </configuration>
-                    </execution>
-                </executions>
+                <artifactId>maven-war-plugin</artifactId>
+                <version>3.1.0</version>
+                <configuration>
+                    <failOnMissingWebXml>false</failOnMissingWebXml>
+                    <warName>${project.artifactId}</warName>
+                </configuration>
             </plugin>
+
+            <!--下面这段是分离打包-->
+
+<!--            <plugin>-->
+<!--                <groupId>org.springframework.boot</groupId>-->
+<!--                <artifactId>spring-boot-maven-plugin</artifactId>-->
+<!--                <version>2.5.15</version>-->
+<!--                <configuration>-->
+<!--                    <fork>true</fork> &lt;!&ndash; 如果没有该配置,devtools不会生效 &ndash;&gt;-->
+<!--                    <executable>true</executable>-->
+<!--                    <layout>ZIP</layout>-->
+<!--                    &lt;!&ndash;这里是填写需要包含进去的jar,-->
+<!--                         必须项目中的某些模块,会经常变动,那么就应该将其坐标写进来-->
+<!--                         如果没有则nothing ,表示不打包依赖 &ndash;&gt;-->
+<!--                    <includes>-->
+<!--                        &lt;!&ndash; 定时任务&ndash;&gt;-->
+<!--                        <include>-->
+<!--                            <groupId>com.jjt</groupId>-->
+<!--                            <artifactId>jjt-quartz</artifactId>-->
+<!--                        </include>-->
+<!--                        &lt;!&ndash; 代码生成&ndash;&gt;-->
+<!--                        <include>-->
+<!--                            <groupId>com.jjt</groupId>-->
+<!--                            <artifactId>jjt-generator</artifactId>-->
+<!--                        </include>-->
+<!--                        &lt;!&ndash; 核心模块&ndash;&gt;-->
+<!--                        <include>-->
+<!--                            <groupId>com.jjt</groupId>-->
+<!--                            <artifactId>jjt-framework</artifactId>-->
+<!--                        </include>-->
+<!--                        &lt;!&ndash; 系统模块&ndash;&gt;-->
+<!--                        <include>-->
+<!--                            <groupId>com.jjt</groupId>-->
+<!--                            <artifactId>jjt-system</artifactId>-->
+<!--                        </include>-->
+<!--                        &lt;!&ndash; 通用工具&ndash;&gt;-->
+<!--                        <include>-->
+<!--                            <groupId>com.jjt</groupId>-->
+<!--                            <artifactId>jjt-common</artifactId>-->
+<!--                        </include>-->
+<!--                        &lt;!&ndash; 业务模块&ndash;&gt;-->
+<!--                        <include>-->
+<!--                            <groupId>com.jjt</groupId>-->
+<!--                            <artifactId>jjt-biz</artifactId>-->
+<!--                        </include>-->
+<!--                    </includes>-->
+<!--                </configuration>-->
+
+<!--                <executions>-->
+<!--                    <execution>-->
+<!--                        <goals>-->
+<!--                            <goal>repackage</goal>-->
+<!--                        </goals>-->
+<!--                    </execution>-->
+<!--                </executions>-->
+
+<!--            </plugin>-->
+
+<!--            &lt;!&ndash;拷贝依赖到jar外面的lib目录&ndash;&gt;-->
+<!--            <plugin>-->
+<!--                <groupId>org.apache.maven.plugins</groupId>-->
+<!--                <artifactId>maven-dependency-plugin</artifactId>-->
+<!--                <executions>-->
+<!--                    <execution>-->
+<!--                        <id>copy</id>-->
+<!--                        <phase>package</phase>-->
+<!--                        <goals>-->
+<!--                            <goal>copy-dependencies</goal>-->
+<!--                        </goals>-->
+<!--                        <configuration>-->
+<!--                            &lt;!&ndash;指定的依赖路径&ndash;&gt;-->
+<!--                            <outputDirectory>${project.build.directory}/lib</outputDirectory>-->
+<!--                            &lt;!&ndash;排除的ArtifactId&ndash;&gt;-->
+<!--                            <excludeArtifactIds>jjt-framework,jjt-system,jjt-quartz,jjt-generator,jjt-common,jjt-biz-->
+<!--                            </excludeArtifactIds>-->
+<!--                        </configuration>-->
+<!--                    </execution>-->
+<!--                </executions>-->
+<!--            </plugin>-->
         </plugins>
         <finalName>jy2024</finalName>
     </build>

+ 16 - 1
jjt-biz/src/main/java/com/jjt/biz/controller/BizObjMetricsController.java

@@ -16,6 +16,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
@@ -58,11 +59,25 @@ public class BizObjMetricsController extends BaseController {
     @Log(title = "业务对象指标", businessType = BusinessType.EXPORT)
     @PostMapping("/export")
     public void export(HttpServletResponse response, BizObjMetrics bizObjMetrics) {
+        Map<String, Object> params = new HashMap<>(2);
+        params.put("type", "2");
+        bizObjMetrics.setParams(params);
         List<BizObjMetrics> list = bizObjMetricsService.selectBizObjMetricsList(bizObjMetrics);
-        ExcelUtil<BizObjMetrics> util = new ExcelUtil<BizObjMetrics>(BizObjMetrics.class);
+        ExcelUtil<BizObjMetrics> util = new ExcelUtil<>(BizObjMetrics.class);
         util.exportExcel(response, list, "业务对象指标数据");
     }
 
+    @ApiOperation("导入业务对象指标列表")
+    @Log(title = "业务对象指标", businessType = BusinessType.IMPORT)
+    @PostMapping("/importData")
+    public AjaxResult importData(MultipartFile file) throws Exception {
+        ExcelUtil<BizObjMetrics> util = new ExcelUtil<>(BizObjMetrics.class);
+        List<BizObjMetrics> metricsList = util.importExcel(file.getInputStream());
+        String userName = getUsername();
+        String message = bizObjMetricsService.importMetrics(metricsList,userName);
+        return success(message);
+    }
+
     /**
      * 获取业务对象指标详细信息
      */

+ 3 - 4
jjt-biz/src/main/java/com/jjt/biz/domain/BizObjMetrics.java

@@ -25,18 +25,19 @@ public class BizObjMetrics extends BaseEntity {
      */
     @ApiModelProperty("指标对象ID")
     @TableId
+    @Excel(name = "指标对象ID")
     private Long objMetricsId;
 
     /**
      * 业务对象ID
      */
     @ApiModelProperty("业务对象ID")
-    @Excel(name = "业务对象ID")
     private Long objId;
     /**
      * 业务对象ID
      */
     @ApiModelProperty("对象名称")
+    @Excel(name = "对象名称")
     private String objName;
 
     @ApiModelProperty("对象业务类型")
@@ -45,14 +46,12 @@ public class BizObjMetrics extends BaseEntity {
      * 模板ID
      */
     @ApiModelProperty("模板ID")
-    @Excel(name = "模板ID")
     private Long tplId;
 
     /**
      * 指标ID
      */
     @ApiModelProperty("指标ID")
-    @Excel(name = "指标ID")
     private Long metricsId;
 
     /**
@@ -66,7 +65,6 @@ public class BizObjMetrics extends BaseEntity {
      * 指标编码
      */
     @ApiModelProperty("指标编码")
-    @Excel(name = "指标编码")
     private String metricsCode;
 
     @ApiModelProperty("告警-低")
@@ -83,6 +81,7 @@ public class BizObjMetrics extends BaseEntity {
     @ApiModelProperty("指标当前值")
     private BigDecimal dValue;
     @ApiModelProperty("数据接口")
+    @Excel(name = "数据接口")
     private String dataExp;
 
 

+ 9 - 0
jjt-biz/src/main/java/com/jjt/biz/service/IBizObjMetricsService.java

@@ -140,4 +140,13 @@ public interface IBizObjMetricsService {
      * @param date  数据时间
      */
     void imitate(Long objId, Date date);
+
+    /**
+     * 更新公式
+     *
+     * @param metricsList 指标列表
+     * @param userName    用户名
+     * @return 列表
+     */
+    String importMetrics(List<BizObjMetrics> metricsList, String userName);
 }

+ 43 - 0
jjt-biz/src/main/java/com/jjt/biz/service/impl/BizObjMetricsServiceImpl.java

@@ -8,12 +8,15 @@ import com.jjt.biz.mapper.AlarmRecordMapper;
 import com.jjt.biz.mapper.BizObjMetricsDataMapper;
 import com.jjt.biz.mapper.BizObjMetricsMapper;
 import com.jjt.biz.service.*;
+import com.jjt.common.exception.ServiceException;
 import com.jjt.common.utils.DateUtils;
 import com.jjt.common.utils.StringUtils;
+import com.jjt.common.utils.bean.BeanValidators;
 import com.jjt.hl.domain.HlEvent;
 import com.jjt.hl.mapper.HlEventMapper;
 import com.jjt.hl.service.IHlEventService;
 import com.jjt.system.service.ISysConfigService;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.ibatis.session.ExecutorType;
 import org.apache.ibatis.session.SqlSession;
 import org.apache.ibatis.session.SqlSessionFactory;
@@ -33,6 +36,7 @@ import java.util.stream.Collectors;
  * @date 2024-08-09
  */
 @Service
+@Slf4j
 public class BizObjMetricsServiceImpl implements IBizObjMetricsService {
     @Resource
     private BizObjMetricsMapper bizObjMetricsMapper;
@@ -487,6 +491,45 @@ public class BizObjMetricsServiceImpl implements IBizObjMetricsService {
     }
 
     /**
+     * 更新公式
+     *
+     * @param metricsList 指标列表
+     * @param userName    用户名
+     * @return 列表
+     */
+    @Override
+    public String importMetrics(List<BizObjMetrics> metricsList, String userName) {
+        if (StringUtils.isNull(metricsList) || metricsList.size() == 0) {
+            throw new ServiceException("导入指标不能为空!");
+        }
+        int successNum = 0;
+        int failureNum = 0;
+        StringBuilder successMsg = new StringBuilder();
+        StringBuilder failureMsg = new StringBuilder();
+        for (BizObjMetrics om : metricsList) {
+            String metricsName = om.getMetricsName();
+            try {
+                om.setUpdateBy(userName);
+                updateBizObjMetrics(om);
+                successNum++;
+                successMsg.append("<br/>" + successNum + "、 " + om.getMetricsName() + " 更新成功");
+            } catch (Exception e) {
+                failureNum++;
+                String msg = "<br/>" + failureNum + "、 " + om.getMetricsName() + " 导入失败:";
+                failureMsg.append(msg + e.getMessage());
+                log.error(msg, e);
+            }
+        }
+        if (failureNum > 0) {
+            failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
+            throw new ServiceException(failureMsg.toString());
+        } else {
+            successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
+        }
+        return successMsg.toString();
+    }
+
+    /**
      * 更新BIZ_OBJ_PP
      *
      * @param objId          对象ID

+ 5 - 1
jjt-biz/src/main/java/com/jjt/hl/service/impl/HlScoreServiceImpl.java

@@ -436,7 +436,11 @@ public class HlScoreServiceImpl implements IHlScoreService {
 
                 //(告警组件数量/总数量 )*细项分
                 if (lostNum > 0) {
-                    lost = BigDecimal.valueOf(lostNum).divide(BigDecimal.valueOf(total), RoundingMode.HALF_UP).multiply(hlMetrics.getHlScore());
+                    if (total == 0) {
+                        lost = BigDecimal.ZERO;
+                    } else {
+                       lost = BigDecimal.valueOf(lostNum).divide(BigDecimal.valueOf(total), RoundingMode.HALF_UP).multiply(hlMetrics.getHlScore());
+                    }
                 }
                 //最终得分 = 分数-扣分
                 BigDecimal score2 = BigDecimal.ZERO;

+ 3 - 0
jjt-biz/src/main/resources/mapper/obj/BizObjMetricsMapper.xml

@@ -117,6 +117,9 @@
             <if test="updateTime != null ">
                 and UPDATE_TIME = #{updateTime}
             </if>
+            <if test="params.type != null and params.type != ''">
+                and METRICS_TYPE = #{params.type}
+            </if>
             <if test="remark != null  and remark != ''">
                 and REMARK = #{remark}
             </if>