基本完成实验报告上传

master
hujunbo 3 years ago
parent 5f9156ff4d
commit 62c1be6187

@ -81,3 +81,9 @@ sso:
password: admin123
secretKey: 4ce36bf549d64d44b6cbc48e926abb05
appId: cb00a3e26b963b25e28cae6e046f1190
report:
uploadUrl: http://test.vsp.cqooc.com/open/api/v2/upload/data
refreshUrl: http://test.vsp.cqooc.com/open/api/v2/oauth/refresh?token=TOKEN&appid=APPID&signature=SIGNATURE
validateUrl: http://vsp.cqooc.com/open/api/v2/oauth/validate?username=USERNAME&password=PASSWORD&nonce=NONCE&cnonce=CNONCE&appid=APPID&signature=SIGNATURE
uploadAttachmentUrl: http://test.vsp.cqooc.com/open/api/v2/upload/attachment?access_token=ACCESS_TOKEN&appid=APPID&originId=ORIGINID&filename=FILENAME&title=TITLE&remarks=REMARKS
getReportListUrl: http://test.vsp.cqooc.com/open/api/v2/query/data?appId=APPID&accessToken=ACCESS_TOKEN&signature=SIGNATURE

@ -35,10 +35,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>

@ -4,14 +4,17 @@ import com.ruoyi.biemo.business.domain.Report;
import com.ruoyi.biemo.business.service.ReportService;
import com.ruoyi.biemo.core.page.Page;
import com.ruoyi.biemo.core.page.PageFactory;
import com.ruoyi.biemo.nlp.SentimentAnalysisUtils;
import com.ruoyi.biemo.nlp.WordVectorModelUtils;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
@ -73,8 +76,8 @@ public class ReportController
@RequestMapping
public AjaxResult add(@RequestBody Report report)
{
reportService.insertOrUpdateReport(report);
return AjaxResult.success();
//reportService.insertOrUpdateReport(report);
return reportService.uploadReport(report, SecurityUtils.getUsername());
}
@ -102,4 +105,19 @@ public class ReportController
return AjaxResult.success(WordVectorModelUtils.similarCount(text1,text2));
}
@PostMapping("/sentiment")
public AjaxResult sentiment(String text){
return AjaxResult.success("查询成功",SentimentAnalysisUtils.analysis(text));
}
@PostMapping("/sentiment/import")
public AjaxResult sentimentImport(MultipartFile[] files,String sentimentName){
return AjaxResult.success("模型训练成功",SentimentAnalysisUtils.analysisImport(files,sentimentName));
}
@GetMapping("/sentiment/getCurrSentiments")
public AjaxResult getCurrSentiments(){
return AjaxResult.success("查询成功",SentimentAnalysisUtils.getCurrSentiments());
}
}

@ -10,6 +10,8 @@ import com.ruoyi.common.core.domain.BaseEntity;
import org.springframework.data.elasticsearch.annotations.Document;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
* report
@ -20,28 +22,41 @@ import java.io.Serializable;
@Data
@Document(indexName = "report")
@org.springframework.data.mongodb.core.mapping.Document("report")
public class Report extends BiemoEntity
{
private static final long serialVersionUID = 1L;
/** 主键 */
public class Report extends BiemoEntity {
/**
*
*/
@EsId
private String id;
/** 报告名称 */
/**
*
*/
@FieldInfo(type = "string", participle = 3)
private String name;
/** 状态 */
private String title;
/**
*
*/
@FieldInfo(type = "keyword", participle = 0)
private Long status;
/** 报告编号 */
/**
*
*/
@FieldInfo(type = "keyword", participle = 0)
private String reportNo;
private String accessToken;
private String appId;
private Long endTime;
private Map extData;
private String groupId;
private String groupMembers;
private String groupName;
private String openId;
private String originId;
private String roleInGroup;
private Long score;
private String signature;
private Long startTime;
private Long timeUsed;
private List<ReportStep> steps;
}

@ -0,0 +1,21 @@
package com.ruoyi.biemo.business.domain;
import lombok.Data;
@Data
public class ReportStep {
private String title;
private String evaluation;
private Long expectTime;
private Long maxScore;
private Long repeatCount;
private Long score;
private Long seq;
private Long startTime;
private Long endTime;
private Long timeUsed;
private String remarks;
private String scoringModel;
}

@ -10,13 +10,16 @@ import com.ruoyi.biemo.business.domain.event.CategoryDeleteEvent;
import com.ruoyi.biemo.business.domain.event.CategorySaveEvent;
import com.ruoyi.biemo.business.domain.event.ReportDeleteEvent;
import com.ruoyi.biemo.business.domain.event.ReportSaveEvent;
import com.ruoyi.biemo.core.MyConstants;
import com.ruoyi.biemo.core.page.Page;
import com.ruoyi.biemo.core.response.MyResponseResult;
import com.ruoyi.biemo.elasticsearch.util.EsService;
import com.ruoyi.biemo.mongodb.utils.CriteriaAndWrapper;
import com.ruoyi.biemo.mongodb.utils.MongoHelper;
import com.ruoyi.biemo.utils.MyObjects;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.SecurityUtils;
@ -192,6 +195,21 @@ public class ReportService extends EsService<Report> {
private String appId = "cb00a3e26b963b25e28cae6e046f1190";
@Value("${sso.secretKey}")
private String secretKey = "4ce36bf549d64d44b6cbc48e926abb05";
@Value("${report.uploadUrl}")
private String reportUploadUrl = "http://test.vsp.cqooc.com/open/api/v2/upload/data";
@Value("${report.refreshUrl}")
private String refreshUrl = "http://test.vsp.cqooc.com/open/api/v2/oauth/refresh?token=TOKEN&appid=APPID&signature=SIGNATURE";
@Value("${report.validateUrl}")
private String validateUrl = "http://test.vsp.cqooc.com/open/api/v2/oauth/validate?username=USERNAME&password=PASSWORD&nonce=NONCE&cnonce=CNONCE&appid=APPID&signature=SIGNATURE";
@Value("${report.uploadAttachmentUrl}")
private String uploadAttachmentUrl = "http://test.vsp.cqooc.com/open/api/v2/upload/attachment?access_token=ACCESS_TOKEN&appid=APPID&originId=ORIGINID&filename=FILENAME&title=TITLE&remarks=REMARKS";
@Value("${report.getReportListUrl}")
private String getReportListUrl = "http://test.vsp.cqooc.com/open/api/v2/query/data?appId=APPID&accessToken=ACCESS_TOKEN&signature=SIGNATURE&&originId=ORIGINID";
@Autowired
private RedisCache redisCache;
@ -213,10 +231,16 @@ public class ReportService extends EsService<Report> {
userName = data.getString("userName");
String openId = data.getString("openId");
String accessToken = data.getString("accessToken");
MyResponseResult myResponseResult = new MyResponseResult();
myResponseResult.setAccessToken(accessToken);
myResponseResult.setOpenId(openId);
Long createTime = data.getLong("createTime");
Long expiresTime = data.getLong("expiresTime");
Long expiresLong = expiresTime-createTime;
redisCache.setCacheObject(ticket, accessToken, expiresLong.intValue(), TimeUnit.MILLISECONDS);
Long expiresLong = expiresTime-System.currentTimeMillis();
redisCache.setCacheObject(MyConstants.TOKEN_PREFIX+userName, myResponseResult, expiresLong.intValue(), TimeUnit.MILLISECONDS);
if(expiresLong<=0){
refreshToken(accessToken,userName,myResponseResult);
}
//用户名不存在就新建
SysUser sysUser = new SysUser();
if(UserConstants.UNIQUE.equals(userService.checkUserNameUnique(userName))){
@ -250,6 +274,93 @@ public class ReportService extends EsService<Report> {
return null;
}
//验证用户信息
//上报实验结果
public AjaxResult uploadReport(Report report,String username){
if(report==null||StringUtils.isBlank(username)){
return AjaxResult.error("参数不能为空!");
}
MyResponseResult myResponseResult = redisCache.getCacheObject(MyConstants.TOKEN_PREFIX+username);
if(myResponseResult!=null&&myResponseResult.getAccessToken()!=null){
report.setAccessToken(myResponseResult.getAccessToken());
String signature = report.getSignature();
signature = Md5Utils.hash(appId+secretKey+report.getAccessToken()).toUpperCase();
report.setSignature(signature);
report.setOpenId(myResponseResult.getOpenId());
report.setOriginId(username);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<Map> uploadResponseEntity = restTemplate.postForEntity(reportUploadUrl, report, Map.class);
Map result = uploadResponseEntity.getBody();
if (result != null && (Integer) result.get("code") == 0) {
return AjaxResult.success(result.get("data"));
}else{
return AjaxResult.error(result.get("message").toString());
}
}
return AjaxResult.error("没有授权或授权到期!");
}
//获取实验结果
public Page<Report> getReportList(String username){
RestTemplate restTemplate = new RestTemplate();
Map<String,Object> map = new HashMap<>();
MyResponseResult myResponseResult = redisCache.getCacheObject(MyConstants.TOKEN_PREFIX+username);
if(myResponseResult!=null&&StringUtils.isNotBlank(myResponseResult.getAccessToken())){
String accessToken = myResponseResult.getAccessToken();
String signature = Md5Utils.hash(appId+secretKey+accessToken).toUpperCase();
map.put("APPID",appId);
map.put("ACCESS_TOKEN",accessToken);
map.put("SIGNATURE",signature);
map.put("ORIGINID",username);
ResponseEntity<Map> responseEntity = restTemplate.getForEntity(getReportListUrl,Map.class,map);
Map body = responseEntity.getBody();
if(body!=null&&(Integer)body.get("code")==0){
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(body);
JSONObject data = jsonObject.getObject("data",JSONObject.class);
JSONObject meta = jsonObject.getObject("meta",JSONObject.class);
String total = meta.getString("total");
String start = meta.getString("start");
String size = meta.getString("size");
List<Report> reportList = JSONObject.parseArray(data.getString("data"),Report.class);
Page<Report> page = new Page<>();
page.setRows(reportList);
page.setPageNum(Integer.parseInt(start));
page.setPageSize(Integer.parseInt(size));
page.setTotal(Long.valueOf(total));
return page;
}
}
return new Page<Report>();
}
//刷新token方法
public String refreshToken(String oldToken,String username,MyResponseResult myResponseResult){
String newToken = "";
String signature = Md5Utils.hash(appId+secretKey+oldToken).toUpperCase();
RestTemplate restTemplate = new RestTemplate();
Map<String,Object> map = new HashMap<>();
map.put("APPID",appId);
map.put("TOKEN",oldToken);
map.put("SIGNATURE",signature);
ResponseEntity<Map> responseEntity = restTemplate.getForEntity(refreshUrl,Map.class,map);
Map responseMap = responseEntity.getBody();
if(responseMap!=null&&(Integer)responseMap.get("code")==0){
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(responseMap);
JSONObject data = jsonObject.getObject("data",JSONObject.class);
newToken = data.getString("accessToken");
Long createTime = data.getLong("createTime");
Long expiresTime = data.getLong("expiresTime");
Long expiresLong = expiresTime-System.currentTimeMillis();
myResponseResult.setAccessToken(newToken);
redisCache.setCacheObject(MyConstants.TOKEN_PREFIX+username,myResponseResult,expiresLong.intValue(),TimeUnit.MILLISECONDS);
}
return newToken;
}
/**
* "success": true,
* "code": 0,

@ -0,0 +1,7 @@
package com.ruoyi.biemo.core;
public class MyConstants {
public static final String TOKEN_PREFIX = "makesoft:";
}

@ -0,0 +1,14 @@
package com.ruoyi.biemo.core.response;
import lombok.Data;
import java.io.Serializable;
@Data
public class MyResponseResult implements Serializable {
private String accessToken;
private String openId;
}

@ -3,8 +3,12 @@ package com.ruoyi.biemo.nlp;
import com.hankcs.hanlp.classification.classifiers.IClassifier;
import com.hankcs.hanlp.classification.classifiers.NaiveBayesClassifier;
import com.ruoyi.biemo.utils.TestUtility;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
*
@ -13,7 +17,7 @@ public class SentimentAnalysisUtils {
public static final String CORPUS_FOLDER = TestUtility.ensureTestData("ChnSentiCorp情感分析酒店评论", "http://hanlp.linrunsoft.com/release/corpus/ChnSentiCorp.zip");
public static String analysis(String text){
String result = "";
IClassifier classifier = new NaiveBayesClassifier(); //
IClassifier classifier = new NaiveBayesClassifier();
try {
classifier.train(CORPUS_FOLDER);
result = classifier.classify(text);
@ -22,4 +26,46 @@ public class SentimentAnalysisUtils {
}
return result;
}
public static Object analysisImport(MultipartFile[] files, String name) {
if(files!=null&&files.length>0){
File file1 = new File(CORPUS_FOLDER+"/"+name);
if(!file1.getParentFile().exists()){
file1.mkdirs();
}
if(!file1.exists()){
file1.mkdirs();
}
for(int i=0;i<files.length;i++){
MultipartFile file = files[i];
try {
File file2 = new File(file1.getCanonicalPath()+"/"+ file.getOriginalFilename());
file.transferTo(file2);
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
IClassifier classifier = new NaiveBayesClassifier();
try {
classifier.train(CORPUS_FOLDER);
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
return "ok";
}
public static List<String> getCurrSentiments(){
File file = new File(CORPUS_FOLDER);
File[] dirs = file.listFiles();
List<String> result = new ArrayList<>();
if(dirs!=null&&dirs.length>0){
for(int i=0;i<dirs.length;i++){
if(dirs[i].isDirectory()){
result.add(dirs[i].getName());
}
}
}
return result;
}
}

@ -0,0 +1,45 @@
package com.ruoyi.biemo.utils;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class SHA256Util {
public static String getSHA256String(String str){
MessageDigest messageDigest;
String sha256Str = "";
try {
messageDigest = MessageDigest.getInstance("SHA-256");
messageDigest.update(str.getBytes("UTF-8"));
sha256Str=byte2Hex(messageDigest.digest());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return sha256Str;
}
/**
* byte16
* @param bytes
* @return
*/
private static String byte2Hex(byte[]bytes){
StringBuffer stringBuffer = new StringBuffer();
String temp = null;
for (int i=0;i<bytes.length;i++){
temp = Integer.toHexString(bytes[i] & 0xFF);
if (temp.length()==1){
stringBuffer.append("0");
}
stringBuffer.append(temp);
}
return stringBuffer.toString();
}
public static void main(String[] args) {
System.out.println(getSHA256String("makesoft"));
}
}

@ -52,3 +52,28 @@ export function similar(query) {
params: query
})
}
// 情感分析
export function sentiment(query) {
return request({
url: '/makesoft/report/sentiment',
method: 'post',
params: query
})
}
// 情感分析训练
export function sentimentImport(data) {
return request({
url: '/makesoft/report/sentiment/import',
method: 'post',
data: data
})
}
// 获取当前情感词
export function getCurrSentiments() {
return request({
url: '/makesoft/report/sentiment/getCurrSentiments',
method: 'get',
})
}

@ -90,6 +90,7 @@
<el-form-item label="排序" prop="orderNum">
<el-input v-model="form.orderNum" placeholder="请输入排序" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>

@ -299,9 +299,7 @@ export default {
}
}
</script>
<style scoped>
@import "../../assets/styles/typo.css";
<style rel="stylesheet/scss" lang="scss" scoped>
@import "./css/google.css";
h1, h2, button {
font-weight: 300 !important;
@ -421,3 +419,7 @@ input {
}
</style>

@ -112,12 +112,105 @@
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改报告提交对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="报告名称" prop="name">
<el-input v-model="form.name" placeholder="请输入报告名称" />
<el-form-item label="报告名称" prop="title">
<el-input v-model="form.title" placeholder="请输入实验报告名称" />
</el-form-item>
<el-form-item label="开始时间" prop="startTime">
<el-date-picker
v-model="form.startTime"
style="width: 240px"
type="date"
value-format="timestamp"
></el-date-picker>
</el-form-item>
<el-form-item label="结束时间" prop="endTime">
<el-date-picker
v-model="form.endTime"
style="width: 240px"
type="date"
value-format="timestamp"
></el-date-picker>
</el-form-item>
<el-form-item label="实验状态" prop="status">
<el-select v-model="form.status">
<el-option value="1" label="未完成"/>
<el-option value="2" label="已完成"/>
</el-select>
</el-form-item>
<el-form-item label="合理用时" prop="timeUsed">
<el-input v-model="form.timeUsed" placeholder="请输入合理用时" />
</el-form-item>
<el-form-item label="得分" prop="score">
<el-input v-model="form.score" placeholder="请输入得分" />
</el-form-item>
<el-form-item label="添加步骤">
<el-row>
<el-col :span="3">
<el-button type="primary" @click="addform"></el-button>
</el-col>
</el-row>
<!-- 动态表单 -->
<el-form :model="form_1" ref="form_1" label-width="120px" style="width:83%; margin-bottom: 8%;">
<div v-for="(item,index) in domains" :key="item.key">
<el-row>
<el-col :span="1">
<i class="el-icon-delete-solid" style="color:red;" @click.prevent="removeDomain(item)"></i>
<span>步骤:{{index+1}}</span>
</el-col>
<el-col :span="7">
<el-form-item><el-input v-model="form_1[index].seq" value="index+1" hidden></el-input></el-form-item>
<el-form-item label="标题" style="margin-bottom: 2%;">
<el-input v-model="form_1[index].title" style="width:300px"></el-input>
</el-form-item>
<el-form-item label="评价" style="margin-bottom: 2%;">
<el-input v-model="form_1[index].evaluation" style="width:300px"></el-input>
</el-form-item>
<el-form-item label="重复次数" style="margin-bottom: 2%;">
<el-input v-model="form_1[index].repeatCount" style="width:300px"></el-input>
</el-form-item>
<el-form-item label="满分" style="margin-bottom: 2%;">
<el-input v-model="form_1[index].maxScore" style="width:300px"></el-input>
</el-form-item>
<el-form-item label="得分" style="margin-bottom: 2%;">
<el-input v-model="form_1[index].score" style="width:300px"></el-input>
</el-form-item>
<el-form-item label="开始时间" prop="startTime">
<el-date-picker
v-model="form_1[index].startTime"
style="width: 240px"
type="date"
value-format="timestamp"
></el-date-picker>
</el-form-item>
<el-form-item label="结束时间" prop="endTime">
<el-date-picker
v-model="form_1[index].endTime"
style="width: 240px"
type="date"
value-format="timestamp"
></el-date-picker>
</el-form-item>
<el-form-item label="合理用时" style="margin-bottom: 2%;">
<el-input v-model="form_1[index].expectTime" style="width:300px"></el-input>
</el-form-item>
<el-form-item label="实验用时" style="margin-bottom: 2%;">
<el-input v-model="form_1[index].timeUsed" style="width:300px"></el-input>
</el-form-item>
<el-form-item label="赋分模型" style="margin-bottom: 2%;">
<el-input v-model="form_1[index].scoringModel" style="width:300px"></el-input>
</el-form-item>
<el-form-item label="备注" style="margin-bottom: 2%;">
<el-input v-model="form_1[index].remarks" style="width:300px"></el-input>
</el-form-item>
</el-col>
</el-row>
</div>
</el-form>
</el-form-item>
</el-form>
@ -168,9 +261,12 @@ export default {
},
//
form: {},
form_1:[],
//
rules: {
}
},
domains: [],
fromList:[]
};
},
created() {
@ -196,7 +292,7 @@ export default {
this.form = {
id: null,
name: null,
status: 0,
status: 1,
createdBy: null,
updatedBy: null,
createTime: null,
@ -239,6 +335,7 @@ export default {
},
/** 提交按钮 */
submitForm() {
this.form.steps = this.form_1;
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.id != null) {
@ -272,6 +369,33 @@ export default {
this.download('report/report/export', {
...this.queryParams
}, `report_${new Date().getTime()}.xlsx`)
},
//
addform() {
this.domains.push({
formName: this.form.appUrl, //
key: Date.now()
})
this.form_1.push({
evaluation:null,
title:null,
maxScore:null,
expectTime:null,
timeUsed:null,
scoringModel:null,
remarks:null,
seq:null,
startTime:null,
endTime:null,
repeatCount:null
})
},
//
removeDomain(item) {
var index = this.domains.indexOf(item)
if (index !== -1) {
this.domains.splice(index, 1)
}
}
}
};

@ -0,0 +1,186 @@
<template>
<div>
<el-form :model="queryParams" :rules="rules" ref="queryForm">
<el-form-item prop="text">
<el-input
type="textarea"
:autosize="{ minRows: 10, maxRows: 20}"
placeholder="情感分析即文本倾向性分析,就是计算机判断人们的看法或评论是属于对事物的积极、消极或中性意见。"
v-model="queryParams.text">
</el-input>
</el-form-item>
<div style="margin: 20px 0;">
当前情感词:<span v-for="item in this.sentimentNames">{{item}},</span><br>
<el-button @click="addSentiment()"></el-button>
</div>
<el-form-item style="text-align: center;margin-left:-100px;margin-top:10px;">
<el-button type="primary" @click="submitForm('queryForm')"></el-button>
<el-button @click="resetForm('queryForm')"></el-button>
</el-form-item>
</el-form>
<el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
<el-upload
ref="upload"
multiple
:file-list = "upload.fileList"
accept=".txt"
:headers="upload.headers"
action="#"
:disabled="upload.isUploading"
:on-progress="handleFileUploadProgress"
:on-success="handleFileSuccess"
:auto-upload="false"
:before-remove="beforeRemove"
:before-upload="beforeUpload"
:on-change="uploadChange"
drag
>
<div class="el-upload__tip text-center" slot="tip">
<div class="el-upload__text">将文件拖到此处<em>点击上传</em></div>
</div>
<i class="el-icon-upload"></i>
<div class="el-upload__text">将文件拖到此处<em>点击上传</em></div>
<div class="el-upload__tip text-center" slot="tip">
<div class="el-upload__tip" slot="tip">
<el-input v-model="upload.sentimentName" placeholder="请输入情感词"/>
</div>
<span>仅允许导入txt格式文件</span>
</div>
</el-upload>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitFileForm"></el-button>
<el-button @click="upload.open = false"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import {sentiment,sentimentImport,getCurrSentiments} from "@/api/biemo/report"
import {getToken} from "@/utils/auth";
export default {
data() {
return {
open: false,
result:null,
queryParams:{
text: '',
},
//
upload: {
//
open: false,
//
title: "",
//
isUploading: false,
//
sentimentName: '',
//
headers: { Authorization: "Bearer " + getToken() },
//
url: '',
fileList: []
},
sentimentNames:[],
rules: {
text: [
{required: true, message: '请输入文本', trigger: 'blur'}
]
}
}
},
created(){
this.getSentiments();
},
methods:{
getSentiments(){
getCurrSentiments().then(response =>{
this.sentimentNames = response.data;
})
},
/** 导入按钮操作 */
addSentiment() {
this.upload.title = "新增情感词";
this.upload.open = true;
},
beforeUpload(file) {
//
const imgSize = Number(file.size / 1024 / 1024);
if (imgSize > 10) {
this.$msgbox({
title: '',
message: '文件大小不能超过10MB请重新上传。',
type: 'warning',
});
return false;
}
return true;
},
beforeRemove(file, fileList) {
const index = fileList.indexOf(file);
this.delIndex = index;
this.fileIds.splice(this.delIndex, 1);
},
uploadChange(file, fileList) { //
this.upload.fileList = fileList;
},
/** 下载模板操作 */
importTemplate() {
this.download('system/user/importTemplate', {
}, `user_template_${new Date().getTime()}.xlsx`)
},
//
handleFileUploadProgress(event, file, fileList) {
this.upload.isUploading = true;
},
//
handleFileSuccess(response, file, fileList) {
this.upload.open = false;
this.upload.isUploading = false;
this.$refs.upload.clearFiles();
this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
this.getSentiments();
},
//
submitFileForm() {
if (this.upload.fileList.length) { //
const formData = new FormData();
this.upload.fileList.forEach((item) => {
formData.append('files', item.raw); // append file.rawfiles
});
formData.append("sentimentName",this.upload.sentimentName)
sentimentImport(formData).then(response =>{
this.handleFileSuccess(response)
})
// this.$refs.upload.submit();
}
},
submitForm(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
this.$modal.loading("正在拼命分析中,请稍候!");
sentiment(this.queryParams).then(response =>{
this.$modal.closeLoading();
if(response.data){
alert("情感分析结果为:"+response.data);
}
}).catch(()=>{
alert("计算出错了!");
})
} else {
console.log('error submit!!');
return false;
}
});
},
resetForm(formName) {
this.$refs[formName].resetFields();
}
}
}
</script>

@ -27,7 +27,6 @@
</template>
<script>
import {similar} from "@/api/biemo/report"
import { Loading } from 'element-ui';
export default {
data() {

Loading…
Cancel
Save