package com.iflytek.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.iflytek.domain.CosEntity;
import com.iflytek.domain.UserEntity;
import com.iflytek.domain.es.EsTag;
import com.iflytek.domain.es.EsTagResult;
import com.iflytek.domain.es.MeMberTagEs;
import com.iflytek.mapper.es.EsMappingEtlMapper;
import com.iflytek.service.EsQueryService;
import com.iflytek.utils.RecommendCos;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
@Controller
public class EsMappingEtlController {
@Autowired
private EsQueryService esQueryService;
@Autowired
private EsMappingEtlMapper esMappingEtlMapper;
@RequestMapping("/genForeCast")
@ResponseBody
public List<EsTagResult> genForeCast(HttpServletResponse response, @RequestBody String data) throws IOException {
JSONObject obj = JSON.parseObject(data);
JSONArray tagsId = obj.getJSONArray("selectedTags");
List<EsTag> list = tagsId.toJavaList(EsTag.class);
System.out.println(list.toString());
String item = null;
for (EsTag tag :
list) {
if (tag.getName().equals("favGoods")){
item=tag.getValue();
System.out.println(item);
}else {
continue;
}
}
List<MeMberTagEs> tags = esQueryService.buildQuery(list);
//返回结果进行预测
List<UserEntity> userEntities = new ArrayList<>();
UserEntity userEntity;
for (MeMberTagEs tagEs:
tags) {
if (tagEs.getFavGoods()==null){
continue;
}
userEntity = new UserEntity();
userEntity.setId(tagEs.getMemberId());
userEntity.setPhone(tagEs.getPhone());
String str="";
for (Integer food:tagEs.getFavGoods()){
str+=String.valueOf(food)+"\t";
}
userEntity.setVFoods(str);
userEntities.add(userEntity);
}
CosEntity cosEntity = RecommendCos.itemUser(item, userEntities);
List<EsTagResult> esTagResults = new ArrayList<>();
EsTagResult esTagResult = null;
String esStr = null;
if (cosEntity.getItemId()==1){
esStr="卡布奇诺10元优惠卷一张";
}else if (cosEntity.getItemId()==2){
esStr="美式咖啡10元优惠卷一张";
}else if (cosEntity.getItemId()==3){
esStr="拿铁10元优惠卷一张";
}else if (cosEntity.getItemId()==4){
esStr="摩卡10元优惠卷一张";
}else if (cosEntity.getItemId()==5){
esStr="橙汁10元优惠卷一张";
}else if (cosEntity.getItemId()==6){
esStr="石榴汁10元优惠卷一张";
}else if (cosEntity.getItemId()==7){
esStr="西瓜汁10元优惠卷一张";
}else if (cosEntity.getItemId()==8){
esStr="芒果汁10元优惠卷一张";
}else if (cosEntity.getItemId()==9){
esStr="猕猴桃汁10元优惠卷一张";
}else if (cosEntity.getItemId()==10){
esStr="沙琪玛10元优惠卷一张";
}else if (cosEntity.getItemId()==11){
esStr="面包干10元优惠卷一张";
}else if (cosEntity.getItemId()==12){
esStr="酸奶10元优惠卷一张";
}else if (cosEntity.getItemId()==13){
esStr="火腿10元优惠卷一张";
}else if (cosEntity.getItemId()==14){
esStr="汉堡10元优惠卷一张";
}else if (cosEntity.getItemId()==15){
esStr="咖啡杯10元优惠卷一张";
}else if (cosEntity.getItemId()==16){
esStr="咖啡机10元优惠卷一张";
}else if (cosEntity.getItemId()==17){
esStr="果汁机10元优惠卷一张";
}else if (cosEntity.getItemId()==18){
esStr="咖啡物语10元优惠卷一张";
}else if (cosEntity.getItemId()==19){
esStr="钥匙扣10元优惠卷一张";
}
for (MeMberTagEs esTag:tags) {
esTagResult = new EsTagResult();
esTagResult.setUserId(esTag.getMemberId());
esTagResult.setPhone(esTag.getPhone());
esTagResult.setResult(esStr);
esTagResults.add(esTagResult);
}
System.out.println(esTagResults.toString());
return esTagResults;
}
@RequestMapping("/gen")
public void genAndDown(HttpServletResponse response, @RequestBody String data) throws IOException {
JSONObject object = JSON.parseObject(data);
JSONArray selectedTags = object.getJSONArray("selectedTags");
List<EsTag> list = selectedTags.toJavaList(EsTag.class);
System.out.println("list================"+list.toString());
List<MeMberTagEs> tags = esQueryService.buildQuery(list);
String content = toContent(tags);
String fileName = "member.txt";
response.setContentType("application/octet-stream");
try {
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
ServletOutputStream sos = null;
BufferedOutputStream bos = null;
try {
sos = response.getOutputStream();
bos = new BufferedOutputStream(sos);
bos.write(content.getBytes("UTF-8"));
bos.flush();
bos.close();
sos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
@RequestMapping("/down")
public void down(HttpServletResponse response) {
String fileName = "member.txt";
response.setContentType("text/plain");
try {
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
ServletOutputStream sos = null;
BufferedOutputStream bos = null;
try {
sos = response.getOutputStream();
bos = new BufferedOutputStream(sos);
bos.write("content".getBytes("UTF-8"));
bos.flush();
bos.close();
sos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private String toContent(List<MeMberTagEs> tags) {
StringBuilder sb = new StringBuilder();
for (MeMberTagEs tag : tags) {
sb.append("" + tag.getMemberId() + "\t" + tag.getPhone() + "\t" + tag.getFavGoods() + "\r\n");
}
return sb.toString();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 1、该资源内项目代码都是经过测试运行成功,功能正常的情况下才上传的,请放心下载使用。 2、适用人群:主要针对计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、数学、电子信息等)的同学或企业员工下载使用,具有较高的学习借鉴价值。 3、不仅适合小白学习实战练习,也可作为大作业、课程设计、毕设项目、初期项目立项演示等,欢迎下载,互相学习,共同进步!
资源推荐
资源详情
资源评论
收起资源包目录
基于SpringBoot+ElasticSearch+vue.js开发的大数据营销系统源码.zip (75个子文件)
code_30312
pom.xml 5KB
src
test
java
com
iflytek
tag.json 284KB
MemberEtlTest.java 595B
main
resources
logback.xml 2KB
application.properties 1KB
templates
user
tags.html 20KB
index.html 38KB
index.html 4KB
static
picture
weather.png 2KB
jt.png 72KB
lbx.png 81KB
loading.gif 701B
lbx-1.png 81KB
map.png 302KB
font
DS-DIGIT.TTF 25KB
js
tag-cloud.js 3KB
js.js 19B
china.js 117KB
echarts.min.js 727KB
area_echarts.js 15KB
index.html 9KB
vue.js 333KB
axios.min.js 13KB
jquery.js 82KB
css
bootstrap.min.css 141KB
tag-cloud.css 383B
comon0.css 7KB
bootstrap-grid.min.css 33KB
bootstrap-reboot.min.css 4KB
images
bg.jpg 252KB
line(1).png 4KB
head_bg.png 8KB
com
iflytek
mapper
WowEtlMapper.xml 1017B
MemberEtlMapper.xml 3KB
LineChartEtlMapper.xml 999B
UserMapper.xml 2KB
java
com
iflytek
mapper
LineChartEtlMapper.java 214B
UserMapper.java 329B
WowEtlMapper.java 361B
MemberEtlMapper.java 537B
RoleMapper.java 228B
PermissionMapper.java 246B
es
EsMappingEtlMapper.java 312B
controller
MemberEtlController.java 2KB
EsMappingEtlController.java 7KB
UserController.java 1KB
FunnelEtlController.java 986B
WowEtlController.java 930B
LineChartEtlController.java 752B
RemindEtlController.java 1KB
utils
ShiroConfig.java 2KB
UserRealm.java 2KB
CorsConfig.java 910B
service
EsQueryService.java 5KB
MarketingTagApplication.java 409B
domain
MemberTag.java 1024B
MemberHeat.java 281B
Permission.java 162B
Reg.java 150B
CouponReminder.java 158B
MemberChannel.java 178B
LineVo.java 391B
Order.java 154B
Role.java 248B
FreeReminder.java 163B
MemberMpSub.java 170B
User.java 245B
MemberSex.java 182B
es
MeMberTagEs.java 2KB
EsTag.java 158B
FunnelVo.java 381B
.mvn
wrapper
maven-wrapper.properties 218B
maven-wrapper.jar 50KB
MavenWrapperDownloader.java 5KB
marketing-tag.iml 18KB
共 75 条
- 1
资源评论
龙年行大运
- 粉丝: 1071
- 资源: 3853
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功