Browse Source

fix recommend

allen 1 year ago
parent
commit
500c026fff

+ 40 - 0
cirs-biz/src/main/java/com/cirs/biz/DTO/ResponseDTO.java

@@ -0,0 +1,40 @@
+package com.cirs.biz.DTO;
+
+public class ResponseDTO<T> {
+    private Integer code;
+    private String msg;
+    private T data;
+
+    public Integer getCode() {
+        return code;
+    }
+
+    public void setCode(Integer code) {
+        this.code = code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+
+    public T getData() {
+        return data;
+    }
+
+    public void setData(T data) {
+        this.data = data;
+    }
+
+    @Override
+    public String toString() {
+        return "ResponseDTO{" +
+                "code='" + code + '\'' +
+                ", msg='" + msg + '\'' +
+                ", data=" + data +
+                '}';
+    }
+}

+ 64 - 27
cirs-biz/src/main/java/com/cirs/biz/controller/SysTrainController.java

@@ -1,26 +1,22 @@
 package com.cirs.biz.controller;
 
-import com.cirs.biz.domain.VerificationData;
+import com.cirs.biz.DTO.ResponseDTO;
+import com.cirs.biz.service.ITElectronComponentService;
 import com.cirs.common.utils.DictUtils;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import org.springframework.http.HttpMethod;
+import org.springframework.core.ParameterizedTypeReference;
 
 
-import java.io.File;
-import java.sql.Timestamp;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.stream.Collectors;
 import javax.servlet.http.HttpServletResponse;
 
 import com.alibaba.fastjson2.JSON;
-import com.alibaba.fastjson2.JSONObject;
 import com.cirs.biz.domain.TElectronComponent;
 import com.cirs.biz.domain.TrainReturn;
-import org.apache.commons.io.FileUtils;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.autoconfigure.web.reactive.function.client.WebClientAutoConfiguration;
+import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -33,7 +29,6 @@ import com.cirs.biz.service.ISysTrainService;
 import com.cirs.common.utils.poi.ExcelUtil;
 import com.cirs.common.core.page.TableDataInfo;
 import org.springframework.web.multipart.MultipartFile;
-import org.springframework.web.reactive.function.BodyInserters;
 import org.springframework.web.reactive.function.client.WebClient;
 import reactor.core.publisher.Mono;
 
@@ -51,6 +46,9 @@ public class SysTrainController extends BaseController
     @Autowired
     private ISysTrainService sysTrainService;
 
+    @Autowired
+    ITElectronComponentService electronComponentService;
+
     // 创建 WebClient 对象
     private WebClient webClient = WebClient.builder()
 //            .baseUrl("http://jsonplaceholder.typicode.com")
@@ -227,10 +225,8 @@ public class SysTrainController extends BaseController
         try {
 
             String recommend_uri = DictUtils.getDictValue("biz_algorithm_config","recommend_uri");
-
             String model_path = DictUtils.getDictValue("biz_algorithm_config","model_path");
-
-            Map<String, Object> objectMap=new HashMap<>();
+            Map<String, Object> objectMap = new HashMap<>();
             objectMap.put("useScene", recommend_args.getUseScene());
             objectMap.put("searchCondition",recommend_args.getSearchCondition());
             objectMap.put("modelPath", model_path);
@@ -241,20 +237,61 @@ public class SysTrainController extends BaseController
             objectMap.put("result5Id",recommend_args.getResult5Id());
             logger.info("request payload: {}",JSON.toJSONString(objectMap));
             //接下来就传入算法
-            Mono<String> mono = webClient
-                    .post() // POST 请求
-                    .uri(recommend_uri)  // 请求路径
+
+            // 使用 ParameterizedTypeReference 定义泛型类型
+            ParameterizedTypeReference<ResponseDTO<SysTrain>> responseType = new ParameterizedTypeReference<ResponseDTO<SysTrain>>() {};
+
+            // 发起 GET 请求,并解析为带有泛型的 ResponseEntity 返回值
+            ResponseEntity<ResponseDTO<SysTrain>> responseEntity = webClient
+                    .post()
+                    .uri(recommend_uri)
                     .contentType(MediaType.APPLICATION_JSON_UTF8)
                     .syncBody(objectMap)
-                    .retrieve() // 获取响应体
-                    .bodyToMono(String.class); //响应数据类型转换
-
-                String res = mono.block();
-                logger.info(res);
-            AjaxResult result = new AjaxResult();
-            result.put("data",res);
-            result.put("code",200);
-            return result;
+                    .retrieve()
+                    .toEntity(responseType)
+                    .block();
+            logger.info("response: {}",responseEntity);
+            if(responseEntity != null && responseEntity.getStatusCode() == HttpStatus.OK && responseEntity.getBody().getCode() == 200 && responseEntity.getBody().getData() != null) {
+                SysTrain data = responseEntity.getBody().getData();
+                List<Long> ids = new ArrayList<>();
+                if (data.getResult1Id() != null) {
+                    ids.add(data.getResult1Id());
+                }
+                if (data.getResult2Id() != null) {
+                    ids.add(data.getResult2Id());
+                }
+                if (data.getResult3Id() != null) {
+                    ids.add(data.getResult3Id());
+                }
+                if (data.getResult4Id() != null) {
+                    ids.add(data.getResult4Id());
+                }
+                if (data.getResult5Id() != null) {
+                    ids.add(data.getResult5Id());
+                }
+                if (!ids.isEmpty()) {
+                    // 查询元器件详情列表
+                    List<TElectronComponent> list = electronComponentService.getByIds(ids);
+                    List<TElectronComponent> resultList = new ArrayList<>(ids.size());
+                    // 根据python的返回值顺序排序
+                    if (list != null && !list.isEmpty()){
+                        Map<Long, TElectronComponent> idToCompMap = list.stream().collect(Collectors.toMap(TElectronComponent::getId, obj -> obj));
+                        HashSet idSet = new HashSet();
+                        for (Long id : ids) {
+                            // 放入有数据的并且未添加的数据
+                            if(idToCompMap.get(id) != null && !idSet.contains(id)){
+                                idSet.add(id);
+                                resultList.add(idToCompMap.get(id));
+                            }
+                        }
+                    }
+                    return success(resultList);
+                } else {
+                    return error("推荐元器件结果为空");
+                }
+            } else {
+                return error("推荐元器件失败");
+            }
         } catch (Exception e) {
             logger.error("推荐元器件失败", e);
             return error("推荐元器件失败");

+ 2 - 0
cirs-biz/src/main/java/com/cirs/biz/mapper/TElectronComponentMapper.java

@@ -65,4 +65,6 @@ public interface TElectronComponentMapper
     public List<TElectronComponent> getAll();
 
     public ElectronComponent getDetailById(@Param("id") Long id);
+
+    List<TElectronComponent> getByIds(@Param("ids") List<Long> ids);
 }

+ 2 - 0
cirs-biz/src/main/java/com/cirs/biz/service/ITElectronComponentService.java

@@ -64,4 +64,6 @@ public interface ITElectronComponentService
     public String importComponent(List<TElectronComponent> componentList, boolean updateSupport, String operName);
 
     public String getDetailById(Long id);
+
+    public List<TElectronComponent> getByIds(List<Long> ids);
 }

+ 5 - 2
cirs-biz/src/main/java/com/cirs/biz/service/impl/TElectronComponentServiceImpl.java

@@ -3,8 +3,6 @@ package com.cirs.biz.service.impl;
 import java.util.List;
 
 import com.cirs.biz.domain.ElectronComponent;
-import com.cirs.biz.domain.TVerificationTask;
-import com.cirs.biz.mapper.TVerificationTaskMapper;
 import com.cirs.common.exception.ServiceException;
 import com.cirs.common.utils.DateUtils;
 import com.cirs.common.utils.StringUtils;
@@ -162,4 +160,9 @@ public class TElectronComponentServiceImpl implements ITElectronComponentService
         ElectronComponent detail = tElectronComponentMapper.getDetailById(id);
         return detail.getComponent_model()+"-"+detail.getQuality_grade()+"-"+detail.getComponent_name();
     }
+
+    @Override
+    public List<TElectronComponent> getByIds(List<Long> ids){
+        return tElectronComponentMapper.getByIds(ids);
+    }
 }

+ 8 - 0
cirs-biz/src/main/resources/mapper/biz/TElectronComponentMapper.xml

@@ -281,4 +281,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{id}
         </foreach>
     </delete>
+
+    <select id="getByIds" resultMap="TElectronComponentResult">
+        <include refid="selectTElectronComponentVo"/>
+        WHERE id IN
+        <foreach collection="ids" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </select>
 </mapper>

+ 179 - 202
cirs-ui/src/views/biz/recommend/index.vue

@@ -1,42 +1,52 @@
 <template>
   <div class="app-container">
     <div style="padding-bottom: 8px">
-    <el-select v-model="use_scene" placeholder="请选择使用场景" style="padding-right: 14px">
-      <el-option
-        v-for="item in options"
-        :key="item.value"
-        :label="item.label"
-        :value="item.value">
-      </el-option>
-    </el-select>
-    <span>
-      <el-input placeholder="请输入查询条件" v-model="searchCondition" style="width:250px"/>
-      <el-button type="primary" @click="recommend" style="margin-left: 20px">推荐</el-button>
-    </span>
+      <el-select v-model="use_scene" placeholder="请选择使用场景" style="padding-right: 14px">
+        <el-option
+          v-for="item in options"
+          :key="item.value"
+          :label="item.label"
+          :value="item.value"
+        />
+      </el-select>
+      <span>
+        <el-input v-model="searchCondition" placeholder="请输入查询条件" style="width:250px" />
+        <el-button type="primary" style="margin-left: 20px" @click="recommend">推荐</el-button>
+      </span>
     </div>
-    <el-table v-loading="loading" :data="componentList" >
-      <el-table-column label="元器件名称" align="center" prop="componentName" :show-overflow-tooltip="true"/>
-      <el-table-column label="型号规格" align="center" prop="componentModel" :show-overflow-tooltip="true"/>
-      <el-table-column label="质量等级" align="center" prop="qualityGrade" :show-overflow-tooltip="true"/>
-      <el-table-column label="国产替代型号" align="center" prop="replaceDomesticModel" :show-overflow-tooltip="true"/>
-<!--      <el-table-column label="元器件应用" align="center" prop="applications"/>-->
+    <el-table v-loading="loading" :data="componentList">
+      <el-table-column label="元器件名称" align="center" prop="componentName" :show-overflow-tooltip="true" />
+      <el-table-column label="型号规格" align="center" prop="componentModel" :show-overflow-tooltip="true" />
+      <el-table-column label="质量等级" align="center" prop="qualityGrade" :show-overflow-tooltip="true" />
+      <el-table-column label="国产替代型号" align="center" prop="replaceDomesticModel" :show-overflow-tooltip="true" />
+      <!--      <el-table-column label="元器件应用" align="center" prop="applications"/>-->
       <el-table-column label="元器件应用" align="center" :show-overflow-tooltip="true">
         <template slot-scope="scope">
           {{ scope.row.applications }}
         </template>
       </el-table-column>
-<!--      <el-table-column label="相关推荐" align="center" :show-overflow-tooltip="true">-->
-<!--        <span>1,2,3...</span>-->
-<!--      </el-table-column>-->
+      <el-table-column label="相关推荐" align="center" :show-overflow-tooltip="true">
+        <template slot-scope="scope">
+          <el-button
+            v-hasPermi="['biz:component:query']"
+            size="mini"
+            type="text"
+            @click="showRelation(scope.row.id)"
+          >相关推荐</el-button>
+        </template>
+      </el-table-column>
+      <!--      <el-table-column label="相关推荐" align="center" :show-overflow-tooltip="true">-->
+      <!--        <span>1,2,3...</span>-->
+      <!--      </el-table-column>-->
 
       <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
         <template slot-scope="scope">
           <el-button
+            v-hasPermi="['biz:component:query']"
             size="mini"
             type="text"
             @click="handleDetail(scope.row)"
-            v-hasPermi="['biz:component:query']"
-          >查看详情<i class="el-icon-more"></i></el-button>
+          >查看详情<i class="el-icon-more" /></el-button>
 
           <el-button
             size="mini"
@@ -61,14 +71,13 @@
         v-model="escore"
         :show-score="true"
         text-color="#ff9900"
-        >
-      </el-rate>
+      />
       <el-input
+        v-model="eremark"
         type="textarea"
         :rows="2"
         placeholder="请输入备注"
-        v-model="eremark">
-      </el-input>
+      />
       <div slot="footer" class="dialog-footer">
         <el-button @click="showevalatedialog = false">取 消</el-button>
         <el-button type="primary" @click="evaluate">确 定</el-button>
@@ -77,7 +86,7 @@
 
     <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body @close="closedialog">
 
-      <el-form  style="border:1px solid #C0C0C0;padding: 5px;margin: auto" ref="form" :model="form" :rules="rules" label-width="200px">
+      <el-form ref="form" style="border:1px solid #C0C0C0;padding: 5px;margin: auto" :model="form" :rules="rules" label-width="200px">
         <h2><b>元器件基本信息</b></h2>
         <el-form-item label="元器件名称" prop="componentName">
           <el-input v-model="form.componentName" readonly />
@@ -110,86 +119,87 @@
           <el-input v-model="form.inPreference" readonly />
         </el-form-item>
         <el-form-item label="停产断档日期" prop="shutdownDate">
-          <el-date-picker clearable
-                          v-model="form.shutdownDate"
-                          type="date"
-                          value-format="yyyy-MM-dd"
-                          readonly>
-          </el-date-picker>
-        </el-form-item>
-        <el-form-item label="阻值" prop="resistanceValue" v-if="form.resistanceValue!==null && form.resistanceValue!==''">
+          <el-date-picker
+            v-model="form.shutdownDate"
+            clearable
+            type="date"
+            value-format="yyyy-MM-dd"
+            readonly
+          />
+        </el-form-item>
+        <el-form-item v-if="form.resistanceValue!==null && form.resistanceValue!==''" label="阻值" prop="resistanceValue">
           <el-input v-model="form.resistanceValue" readonly />
         </el-form-item>
-        <el-form-item label="精度" prop="resistancePrecision" v-if="form.resistancePrecision!==null && form.resistancePrecision!==''">
+        <el-form-item v-if="form.resistancePrecision!==null && form.resistancePrecision!==''" label="精度" prop="resistancePrecision">
           <el-input v-model="form.resistancePrecision" readonly />
         </el-form-item>
-        <el-form-item label="电阻温度特性" prop="resistanceTemperature" v-if="form.resistanceTemperature!==null && form.resistanceTemperature!==''">
+        <el-form-item v-if="form.resistanceTemperature!==null && form.resistanceTemperature!==''" label="电阻温度特性" prop="resistanceTemperature">
           <el-input v-model="form.resistanceTemperature" readonly />
         </el-form-item>
-        <el-form-item label="功耗" prop="resistancePower" v-if="form.resistancePower!==null && form.resistancePower!==''">
+        <el-form-item v-if="form.resistancePower!==null && form.resistancePower!==''" label="功耗" prop="resistancePower">
           <el-input v-model="form.resistancePower" readonly />
         </el-form-item>
-        <el-form-item label="封装形式" prop="encapsulationMode" v-if="form.encapsulationMode!==null && form.encapsulationMode!==''">
+        <el-form-item v-if="form.encapsulationMode!==null && form.encapsulationMode!==''" label="封装形式" prop="encapsulationMode">
           <el-input v-model="form.encapsulationMode" readonly />
         </el-form-item>
-        <el-form-item label="电容量Cp" prop="capacitanceValue" v-if="form.capacitanceValue!==null && form.capacitanceValue!==''">
+        <el-form-item v-if="form.capacitanceValue!==null && form.capacitanceValue!==''" label="电容量Cp" prop="capacitanceValue">
           <el-input v-model="form.capacitanceValue" readonly />
         </el-form-item>
-        <el-form-item label="损耗DF" prop="capacitanceLoss" v-if="form.capacitanceLoss!==null && form.capacitanceLoss!==''">
+        <el-form-item v-if="form.capacitanceLoss!==null && form.capacitanceLoss!==''" label="损耗DF" prop="capacitanceLoss">
           <el-input v-model="form.capacitanceLoss" readonly />
         </el-form-item>
-        <el-form-item label="温度系数" prop="temperatureCoefficient" v-if="form.temperatureCoefficient!==null && form.temperatureCoefficient!==''">
+        <el-form-item v-if="form.temperatureCoefficient!==null && form.temperatureCoefficient!==''" label="温度系数" prop="temperatureCoefficient">
           <el-input v-model="form.temperatureCoefficient" readonly />
         </el-form-item>
-        <el-form-item label="额定电压WVDC" prop="ratedVoltage" v-if="form.ratedVoltage!==null && form.ratedVoltage!==''">
+        <el-form-item v-if="form.ratedVoltage!==null && form.ratedVoltage!==''" label="额定电压WVDC" prop="ratedVoltage">
           <el-input v-model="form.ratedVoltage" readonly />
         </el-form-item>
-        <el-form-item label="电感量" prop="inductance" v-if="form.inductance!==null && form.inductance!==''">
+        <el-form-item v-if="form.inductance!==null && form.inductance!==''" label="电感量" prop="inductance">
           <el-input v-model="form.inductance" readonly />
         </el-form-item>
-        <el-form-item label="品质因数Qmin" prop="qualityFactor" v-if="form.qualityFactor!==null && form.qualityFactor!==''">
+        <el-form-item v-if="form.qualityFactor!==null && form.qualityFactor!==''" label="品质因数Qmin" prop="qualityFactor">
           <el-input v-model="form.qualityFactor" readonly />
         </el-form-item>
-        <el-form-item label="直流电阻" prop="dcResistance" v-if="form.dcResistance!==null && form.dcResistance!==''">
+        <el-form-item v-if="form.dcResistance!==null && form.dcResistance!==''" label="直流电阻" prop="dcResistance">
           <el-input v-model="form.dcResistance" readonly />
         </el-form-item>
-        <el-form-item label="额定电流" prop="ratedCurrent" v-if="form.ratedCurrent!==null && form.ratedCurrent!==''">
+        <el-form-item v-if="form.ratedCurrent!==null && form.ratedCurrent!==''" label="额定电流" prop="ratedCurrent">
           <el-input v-model="form.ratedCurrent" readonly />
         </el-form-item>
-        <el-form-item label="最大正向电流IFM" prop="paramIfm" v-if="form.paramIfm!==null && form.paramIfm!==''">
+        <el-form-item v-if="form.paramIfm!==null && form.paramIfm!==''" label="最大正向电流IFM" prop="paramIfm">
           <el-input v-model="form.paramIfm" readonly />
         </el-form-item>
-        <el-form-item label="最大反向工作电压VRRM" prop="paramVrrm" v-if="form.paramVrrm!==null && form.paramVrrm!==''">
+        <el-form-item v-if="form.paramVrrm!==null && form.paramVrrm!==''" label="最大反向工作电压VRRM" prop="paramVrrm">
           <el-input v-model="form.paramVrrm" readonly />
         </el-form-item>
-        <el-form-item label="最大浪涌电流IFSM" prop="paramIfsm" v-if="form.paramIfsm!==null && form.paramIfsm!==''">
+        <el-form-item v-if="form.paramIfsm!==null && form.paramIfsm!==''" label="最大浪涌电流IFSM" prop="paramIfsm">
           <el-input v-model="form.paramIfsm" readonly />
         </el-form-item>
-        <el-form-item label="稳压状态下的动态电阻ZZ" prop="paramZz" v-if="form.paramZz!==null && form.paramZz!==''">
+        <el-form-item v-if="form.paramZz!==null && form.paramZz!==''" label="稳压状态下的动态电阻ZZ" prop="paramZz">
           <el-input v-model="form.paramZz" readonly />
         </el-form-item>
-        <el-form-item label="最大额定功率PCM" prop="paramPcm" v-if="form.paramPcm!==null && form.paramPcm!==''">
+        <el-form-item v-if="form.paramPcm!==null && form.paramPcm!==''" label="最大额定功率PCM" prop="paramPcm">
           <el-input v-model="form.paramPcm" readonly />
         </el-form-item>
-        <el-form-item label="最大集电极电流ICM" prop="paramIcm" v-if="form.paramIcm!==null && form.paramIcm!==''">
+        <el-form-item v-if="form.paramIcm!==null && form.paramIcm!==''" label="最大集电极电流ICM" prop="paramIcm">
           <el-input v-model="form.paramIcm" readonly />
         </el-form-item>
-        <el-form-item label="最大集电极-基极电压VCBO" prop="paramVcbo" v-if="form.paramVcbo!==null && form.paramVcbo!==''">
+        <el-form-item v-if="form.paramVcbo!==null && form.paramVcbo!==''" label="最大集电极-基极电压VCBO" prop="paramVcbo">
           <el-input v-model="form.paramVcbo" readonly />
         </el-form-item>
-        <el-form-item label="集电极-发射极电压VCEO" prop="paramVceo" v-if="form.paramVceo!==null && form.paramVceo!==''">
+        <el-form-item v-if="form.paramVceo!==null && form.paramVceo!==''" label="集电极-发射极电压VCEO" prop="paramVceo">
           <el-input v-model="form.paramVceo" readonly />
         </el-form-item>
-        <el-form-item label="发射极-基极电压VEBO" prop="paramVebo" v-if="form.paramVebo!==null && form.paramVebo!==''">
+        <el-form-item v-if="form.paramVebo!==null && form.paramVebo!==''" label="发射极-基极电压VEBO" prop="paramVebo">
           <el-input v-model="form.paramVebo" readonly />
         </el-form-item>
-        <el-form-item label="漏源电压VDSS" prop="paramVdss" v-if="form.paramVdss!==null && form.paramVdss!==''">
+        <el-form-item v-if="form.paramVdss!==null && form.paramVdss!==''" label="漏源电压VDSS" prop="paramVdss">
           <el-input v-model="form.paramVdss" readonly />
         </el-form-item>
-        <el-form-item label="漏极直流电流ID" prop="paramId" v-if="form.paramId!==null && form.paramId!==''">
+        <el-form-item v-if="form.paramId!==null && form.paramId!==''" label="漏极直流电流ID" prop="paramId">
           <el-input v-model="form.paramId" readonly />
         </el-form-item>
-        <el-form-item label="漏-源通态电阻RDS(on)" prop="paramRdsOn" v-if="form.paramRdsOn!==null && form.paramRdsOn!==''">
+        <el-form-item v-if="form.paramRdsOn!==null && form.paramRdsOn!==''" label="漏-源通态电阻RDS(on)" prop="paramRdsOn">
           <el-input v-model="form.paramRdsOn" readonly />
         </el-form-item>
         <el-form-item label="抗静电能力" prop="antistaticCapacity">
@@ -199,7 +209,7 @@
           <el-input v-model="form.radiationResistance" readonly />
         </el-form-item>
         <el-form-item label="材料" prop="materials">
-          <el-input v-model="form.materials" type="textarea" readonly/>
+          <el-input v-model="form.materials" type="textarea" readonly />
         </el-form-item>
         <el-form-item label="工艺" prop="craft">
           <el-input v-model="form.craft" type="textarea" readonly />
@@ -211,8 +221,6 @@
           <el-input v-model="form.remark" type="textarea" readonly />
         </el-form-item>
       </el-form>
-
-
       <el-table style="margin-top: 20px" :header-cell-style="{background:'#87CEEB',color:'#606266'}" :data="useInfoList">
         <el-table-column label="应用场景" align="center" prop="usedBy" />
         <el-table-column label="应用时间" align="center" prop="usedDate" />
@@ -220,35 +228,34 @@
 
     </el-dialog>
 
-<!--    <el-dialog-->
-<!--      title="推荐"-->
-<!--      :visible.sync="dialogVisible"-->
-<!--      width="20%"-->
-<!--      style="top:225px"-->
-
-<!--    >-->
-<!--      <div  align="center">-->
-<!--        <el-progress-->
-<!--          type="circle"-->
-<!--          :percentage="Progress"-->
-<!--          width="80"-->
-<!--          :status="progressStatus"-->
-<!--        ></el-progress>-->
-<!--      </div>-->
-<!--    </el-dialog>-->
+    <el-dialog title="相关推荐" :visible.sync="dialogShowRelation">
+      <el-table :data="relation">
+        <el-table-column property="componentModel" label="元器件型号" width="150" />
+        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
+          <template slot-scope="scope">
+            <el-button
+              v-hasPermi="['biz:component:query']"
+              size="mini"
+              type="text"
+              @click="handleDetail(scope.row)"
+            >查看详情</el-button>
+          </template>
+        </el-table-column>
+      </el-table>
+    </el-dialog>
   </div>
 </template>
 
 <script>
-import { RecommendlistComponent,getComponent,getBycomponentId,addEvaluation,addTime,getscore } from "@/api/biz/recommend";
-import { recommend } from "@/api/biz/train";
+import { RecommendlistComponent, getComponent, getBycomponentId, addEvaluation, addTime, getscore } from '@/api/biz/recommend'
+import { recommend } from '@/api/biz/train'
 export default {
-  name: "recommend",
+  name: 'Recommend',
   data() {
     return {
-      Progress:0,
-      useInfoList:[],
-      eremark:'',//评分的备注
+      Progress: 0,
+      useInfoList: [],
+      eremark: '', // 评分的备注
       // 遮罩层
       loading: false,
       // 选中数组
@@ -265,26 +272,25 @@ export default {
       componentList: [
       ],
       // 弹出层标题
-      title: "",
+      title: '',
       // 是否显示弹出层
       open: false,
-      searchCondition:'',
+      searchCondition: '',
       // 查询参数  元器件规格 元器件名称 国产替代型号 元器件应用 操作
       queryParams: {
         pageNum: 1,
         pageSize: 10,
 
-          useScene: '',
-          searchCondition: '',
-          result1Id: null,
-          result2Id: null,
-          result3Id: null,
-          result4Id: null,
-          result5Id: null,
-
+        useScene: '',
+        searchCondition: '',
+        result1Id: null,
+        result2Id: null,
+        result3Id: null,
+        result4Id: null,
+        result5Id: null
 
       },
-      use_scene:'',
+      use_scene: '',
       evaluation: {
         id: null,
         searchCondition: null,
@@ -297,14 +303,14 @@ export default {
         updateTime: null,
         remark: null
       },
-      escore:0,
+      escore: 0,
       showevalatedialog: false,
       // 表单参数
       form: {},
       // 表单校验
       rules: {
       },
-      options:[
+      options: [
         {
           value: '质量最优',
           label: '质量最优'
@@ -319,135 +325,97 @@ export default {
           label: '供货量最优'
         }
       ],
-      currentTime:0,
-      startTime:0,
-      pageviewTime:{},
-
-      recommmend_args:{
+      currentTime: 0,
+      startTime: 0,
+      pageviewTime: {},
 
+      recommmend_args: {
         useScene: '',
         searchCondition: '',
         result1Id: null,
         result2Id: null,
         result3Id: null,
         result4Id: null,
-        result5Id: null,
+        result5Id: null
       },
-      dialogVisible:false,
-    };
+      dialogVisible: false,
+      dialogShowRelation: false,
+      relation: []
+    }
   },
   computed: {
     progressStatus() {
-      return this.Progress === 100 ? 'success' : '';
-    },
+      return this.Progress === 100 ? 'success' : ''
+    }
   },
   methods: {
     // 得到evaluation
-    getevaluationdata(row){
-
-      getscore(row.id.toString()).then(score=>{
+    getevaluationdata(row) {
+      getscore(row.id.toString()).then(score => {
         console.log(score)
         this.escore = score.data
-        this.showevalatedialog=true
+        this.showevalatedialog = true
         this.evaluation.componentId = row.id
-
         this.evaluation.usedBy = row.applications.toString()
       })
-
-
-
     },
 
-
-    //调用推荐算法
+    // 调用推荐算法
     recommend() {
       this.recommmend_args.useScene = this.use_scene
       this.recommmend_args.searchCondition = this.searchCondition
 
-      recommend(this.recommmend_args).then(res=>{
-        // console.log(res.code)
-        if(res.code===200&&JSON.parse(res.data).code===200) {
-          this.recommmend_args = JSON.parse(res.data).data
-          console.log(this.recommmend_args)
-          // this.queryParams.result1Id = 53
-          this.queryParams.result1Id = this.recommmend_args.result1Id
-          this.queryParams.result2Id = this.recommmend_args.result2Id
-          this.queryParams.result3Id = this.recommmend_args.result3Id
-          this.queryParams.result4Id = this.recommmend_args.result4Id
-          this.queryParams.result5Id = this.recommmend_args.result5Id
-          this.getList()
-          this.$modal.msgSuccess("调用推荐算法成功")
-
+      recommend(this.recommmend_args).then(res => {
+        if (res.code === 200) {
+          this.componentList = res.data
+          const clist = res.data
+          for (let i = 0; i < clist.length; i++) {
+            getBycomponentId(clist[i].id).then(res => {
+              const apps = []
+              for (const one of res.data) {
+                apps.push(one.usedBy)
+              }
 
+              if (apps && apps.length > 3) {
+                this.$set(this.componentList[i], 'applications', apps.slice(0, 3).join(', ') + '...')
+              } else {
+                this.$set(this.componentList[i], 'applications', apps.join(', '))
+              }
+            })
+          }
         } else {
-          this.$modal.msgError("调用推荐算法失败,输入因素不能为空!")
+          this.$modal.msgError('调用推荐算法失败,输入因素不能为空!')
         }
-
       })
-
-      // // 模拟进度变化,每0.0.5秒更新一次,共更新100次
-      // this.dialogVisible = true
-      //
-      // const intervalId = setInterval(() => {
-      //
-      //   this.Progress++;
-      //   // 如果进度达到100%,清除定时器
-      //   if (this.Progress >= 100) {
-      //     this.Progress = 0
-      //     clearInterval(intervalId);
-      //     this.dialogVisible = false
-      //
-      //     if(result.code===200){
-      //       this.getList()
-      //       this.$modal.msgSuccess("调用推荐算法成功")
-      //     }
-      //
-      //     else {
-      //       this.$modal.msgError(result.msg);
-      //     }
-      //   }
-      // }, 50);
-
     },
     /** 查询元器件列表 */
     getList() {
       // console.log(this.queryParams)
-      this.loading = true;
+      this.loading = true
       this.evaluation.searchCondition = this.searchCondition
-      RecommendlistComponent(this.queryParams).then(response => {//queryParams中分页的信息应该是在session中保存,在请求的时候通过session封装到了pagedomain中了
-
-        this.componentList = response.rows;
-
-        let clist = response.rows;
-        for(let i=0; i< clist.length;i++){
-
-          getBycomponentId(clist[i].id).then(res=>{
-            // console.log(res.data)
-            let apps = []
-            for(let one of res.data){
-
+      RecommendlistComponent(this.queryParams).then(response => { // queryParams中分页的信息应该是在session中保存,在请求的时候通过session封装到了pagedomain中了
+        this.componentList = response.rows
+
+        const clist = response.rows
+        for (let i = 0; i < clist.length; i++) {
+          getBycomponentId(clist[i].id).then(res => {
+            const apps = []
+            for (const one of res.data) {
               apps.push(one.usedBy)
             }
-            // console.log("apps:")
-
-              if (apps && apps.length > 3) {
-                this.$set(this.componentList[i], 'applications', apps.slice(0, 3).join(', ') + '...');
-
-              } else {
-                this.$set(this.componentList[i], 'applications', apps.join(', '));
-              }
-
-
-            // this.componentList[i].applications = apps
-
+            if (apps && apps.length > 3) {
+              this.$set(this.componentList[i], 'applications', apps.slice(0, 3).join(', ') + '...')
+            } else {
+              this.$set(this.componentList[i], 'applications', apps.join(', '))
+            }
           })
         }
-        this.total = response.total;
-        this.loading = false;
-      });
+        this.total = response.total
+        this.loading = false
+      })
     },
-    //评分
-    evaluate(){
+    // 评分
+    evaluate() {
       this.evaluation.mark = this.escore
       this.evaluation.remark = this.eremark
       this.evaluation.useScene = this.use_scene
@@ -456,41 +424,50 @@ export default {
         // this.$modal.msgSuccess("评分成功");
 
         this.showevalatedialog = false
-      });
+      })
     },
 
     /** 搜索按钮操作 */
     handleDetail(row) {
       const id = row.id || this.ids
       getComponent(id).then(response => {
-        this.form = response.data;
-        this.title = "元器件详情";
-
-      });
-      getBycomponentId(id).then(res=>{
+        this.form = response.data
+        this.title = '元器件详情'
+      })
+      getBycomponentId(id).then(res => {
         this.useInfoList = res.data
       })
-      this.open = true;
+      this.open = true
       this.startTime = Date.now()
       this.pageviewTime.componentId = row.id
-
     },
 
-    //监听元器件详情dialog关闭
-    closedialog(){
+    // 监听元器件详情dialog关闭
+    closedialog() {
       this.currentTime = Date.now()
       this.pageviewTime.viewTime = this.currentTime - this.startTime
       this.pageviewTime.useScene = this.use_scene
       console.log(this.use_scene)
       this.pageviewTime.searchCondition = this.searchCondition
-      addTime(this.pageviewTime).then(res=>{
+      addTime(this.pageviewTime).then(res => {
         // this.$modal.msgSuccess("详情浏览时间成功")
       })
-      console.log("详情关闭")
-      this.open=false
+      console.log('详情关闭')
+      this.reset()
+      this.open = false
+    },
+    showRelation(id) {
+      this.reset()
+      this.dialogShowRelation = true
+      this.relation = []
+      debugger
+      this.relation = this.componentList.filter(comp => comp.id !== id)
+    },
+    reset() {
+      this.resetForm('form')
     }
   }
-};
+}
 </script>
 <style>