package com.iplatform.rectext.api; import com.iplatform.reccommon.ResponseValue; import com.iplatform.reccommon.config.TextSimilarProperties; import com.iplatform.rectext.pojo.SearchRequest; import com.iplatform.rectext.pojo.TextSimilar; import com.iplatform.rectext.pojo.UploadText; import com.walker.infrastructure.utils.JsonUtils; import com.walker.infrastructure.utils.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; import java.util.HashMap; import java.util.List; import java.util.Map; @RestController @RequestMapping("/api/text") public class TextResultApi { private final transient Logger logger = LoggerFactory.getLogger(this.getClass()); private RestTemplate restTemplate = null; private TextSimilarProperties textSimilarProperties = null; @Autowired public TextResultApi(RestTemplate restTemplate, TextSimilarProperties textSimilarProperties){ this.restTemplate = restTemplate; this.textSimilarProperties = textSimilarProperties; } /** * 业务上传课程文本分析数据。
* 1.请求参数格式:* { * "type":"kecheng", // 文本分类,业务设置标识字符串 * "title":["10","20","30"], // title为课程ID * "text":["课程描述1","课程描述2","课程描述3"] // text为课程描述等一个字符串 * } ** 2.响应格式:
* {"state":true, "code":1, "msg":"success"} // 1 成功,其他失败 ** @param json * @return * @author 时克英 * @date 2022-11-03 */ @RequestMapping("/upload") public ResponseValue uploadText(@RequestBody String json){ if(StringUtils.isEmpty(json)){ return ResponseValue.error("上传的课程分析数据为空"); } String url = this.textSimilarProperties.getAiService(); logger.info("upload text url = " + url); try { UploadText uploadText = JsonUtils.jsonStringToObject(json, UploadText.class); String error = this.postUploadText(url, uploadText); if(error != null){ return ResponseValue.error(error); } } catch (Exception e) { throw new RuntimeException(e); } return ResponseValue.success(); } /** * 给定一句话(或标签文本内容)检索出相似的课程列表,最多40个。
* {"query":"他是一个会计师", "type":"kecheng"} ** * 2.响应格式:
* { * "state": true, * "code": 1, * "msg": "success", * "data": [ * { * "dis": 0.3613262176513672, * "id": "9", * "text": "会计培训_会计全科班报名学费,零会计基础知识,欲全面学习会计专业技能,达到一般企业的熟练会计水平", * "type": "kecheng" * }, * { * "dis": 0.3019663691520691, * "id": "2", * "text": "初级会计师考试包含哪几门呢?初级会计师考试一直是考试两门,分别为《初级会计实务》和《经济法基础》。参加初级资格考试的人员,在一个考试年度内通过全部科目的考试,才可获得初级资格证书。", * "type": "kecheng" * }, * { * "dis": 0.29971787333488464, * "id": "8", * "text": "湖州市淘宝美工培训 淘宝电商培训报名热线,2022年湖州市春华职业培训学校开设电脑系列课程:办公、平面、美工、设计、制版、淘宝等;会计课程:基础会计,初中级会计考证,会计实务,会计全科班等,成人在职专科本科学历进修,淘宝美工爱好者、淘宝店铺经营者、平面设计爱好者。掌握网店主页美工设计、海报、焦点图、宝贝详情页的美工设计,图片空间,网站代码,实现视觉营销", * "type": "kecheng" * }, * { * "dis": 0.23417186737060547, * "id": "7", * "text": "2022年台州玉环县成人教育学历进修报名,学习形式有自考,函授与远程教育,学制短,文凭电子注册,国家教育部承认,高升本设置专业:会计,专升本设置专业:会计,机电一体化,工商管理", * "type": "kecheng" * }, * { * "dis": 0.22891874611377716, * "id": "10", * "text": "需要掌握财务知识的企业管理人员也可学习该课程。参加考试成绩合格颁发ATEP全国会计实务资格初级证书及会计从业资格证书", * "type": "kecheng" * }, * { * "dis": 0.11250658333301544, * "id": "11", * "text": "海宁市成人函授大学会计专科、本科学历招生,东北农业大学网络教育学院创建于2000年7月,是全国首批三十一所远程教育试点学校之一,也是全国第一所进行现代远程教育试点的高等农业院校", * "type": "kecheng" * }, * { * "dis": 0.10873384773731232, * "id": "13", * "text": "宁波杭州湾淘宝培训 电商运营推广班报名学费,春华淘宝开店培训班招收零基础学员、淘宝开店创业者、全职妈妈、打工仔、淘宝新手卖家,对有志于网络销售,淘宝开店等的社会各界人士,对网络零售和电子商务有更深入的理解,学习网店的建设;对网店的流程各方面都比较了解,能够独立运营网店,淘宝会员注册、支付宝实名认证、网上购物流程、淘宝店铺注册", * "type": "kecheng" * }, * { * "dis": 0.07954521477222443, * "id": "3", * "text": "一、二级消防师考试最新教,2022年版教材明确为一、二级注册消防工程师共用,同时按照考试大纲及考查范围对一级注册消防工程师和二级注册消防工程师学习", * "type": "kecheng" * } * ], * "total": 8 * } ** @param json * @return */ @RequestMapping("/search") public ResponseValue searchTextList(@RequestBody String json){ if(StringUtils.isEmpty(json)){ return ResponseValue.error("缺少查询条件:{'query':'demo'}"); } String url = this.textSimilarProperties.getAiService(); logger.info("upload text url = " + url); try { SearchRequest request = JsonUtils.jsonStringToObject(json, SearchRequest.class); List