Skip to content

Commit 4da1606

Browse files
author
xiaowei
committed
add hotsearch
1 parent e1b1cec commit 4da1606

14 files changed

Lines changed: 848 additions & 28 deletions

File tree

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
package com.changyu.foryou.controller;
2+
3+
import java.util.Date;
4+
import java.util.HashMap;
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
import javax.annotation.Resource;
9+
10+
import org.springframework.stereotype.Controller;
11+
import org.springframework.validation.BindingResult;
12+
import org.springframework.web.bind.annotation.RequestMapping;
13+
import org.springframework.web.bind.annotation.RequestParam;
14+
import org.springframework.web.bind.annotation.ResponseBody;
15+
16+
import com.changyu.foryou.model.HotSearch;
17+
import com.changyu.foryou.service.HotSearchService;
18+
import com.changyu.foryou.tools.Constants;
19+
20+
@Controller
21+
@RequestMapping("/hotSearch")
22+
public class HotSearchController {
23+
@Resource private HotSearchService hotSearchService;
24+
25+
/**
26+
* 获取所有的热门搜索标签
27+
* @param campusId 校区id
28+
* @return
29+
*/
30+
@RequestMapping("/getHotSearchs")
31+
public @ResponseBody List<HotSearch> getHotSearchs(@RequestParam Integer campusId){
32+
Map<String,Object> paramMap=new HashMap<String,Object>();
33+
paramMap.put("campusId",campusId);
34+
List<HotSearch> searchs=hotSearchService.getHotSearchs(paramMap);
35+
36+
return searchs;
37+
}
38+
39+
/**
40+
* 将标签设为不显示
41+
* @param campusId //校区id
42+
* @param hotId 搜索标签id
43+
* @return
44+
*/
45+
@RequestMapping("/setNot2Display")
46+
public @ResponseBody Map<String,Object> setNot2Display(@RequestParam Integer hotId){
47+
Map<String,Object> resultMap=new HashMap<>();
48+
49+
try {
50+
Map<String,Object> paramMap=new HashMap<String,Object>();
51+
//paramMap.put("campusId",campusId);
52+
paramMap.put("hotId",hotId);
53+
int flag=hotSearchService.setNot2Display(paramMap);
54+
if(flag!=-1){
55+
resultMap.put(Constants.STATUS,Constants.SUCCESS);
56+
resultMap.put(Constants.MESSAGE, "修改成功");
57+
}else{
58+
resultMap.put(Constants.STATUS,Constants.FAILURE);
59+
resultMap.put(Constants.MESSAGE, "修改失败");
60+
}
61+
} catch (Exception e) {
62+
resultMap.put(Constants.STATUS,Constants.FAILURE);
63+
resultMap.put(Constants.MESSAGE, "修改失败");
64+
}
65+
66+
return resultMap;
67+
}
68+
69+
/**
70+
* 将标签设为显示
71+
* @param campusId
72+
* @param hotId
73+
* @return
74+
*/
75+
@RequestMapping("/set2Display")
76+
public @ResponseBody Map<String,Object> set2Display(@RequestParam Integer hotId){
77+
Map<String,Object> resultMap=new HashMap<>();
78+
try {
79+
Map<String,Object> paramMap=new HashMap<String,Object>();
80+
//paramMap.put("campusId",campusId);
81+
paramMap.put("hotId",hotId);
82+
int flag=hotSearchService.set2Display(paramMap);
83+
if(flag!=-1){
84+
resultMap.put(Constants.STATUS,Constants.SUCCESS);
85+
resultMap.put(Constants.MESSAGE, "修改成功");
86+
}else{
87+
resultMap.put(Constants.STATUS,Constants.FAILURE);
88+
resultMap.put(Constants.MESSAGE, "修改失败");
89+
}
90+
} catch (Exception e) {
91+
resultMap.put(Constants.STATUS,Constants.FAILURE);
92+
resultMap.put(Constants.MESSAGE, "修改失败");
93+
}
94+
95+
96+
return resultMap;
97+
}
98+
99+
/**
100+
* 删除标签
101+
* @param hotIds
102+
* @return
103+
*/
104+
@RequestMapping("/deleteHotSearchs")
105+
public @ResponseBody Map<String,Object> deleteHotSearchs(@RequestParam String hotIds){
106+
Map<String,Object> resultMap=new HashMap<>();
107+
108+
try {
109+
Map<String,Object> paramMap=new HashMap<>();
110+
111+
String[] hotIdsStrings=hotIds.split(",");
112+
paramMap.put("hotIds",hotIdsStrings);
113+
int flag= hotSearchService.deleteHotSearchs(paramMap);
114+
if(flag!=-1){
115+
resultMap.put(Constants.STATUS,Constants.SUCCESS);
116+
resultMap.put(Constants.MESSAGE, "修改成功");
117+
}else{
118+
resultMap.put(Constants.STATUS,Constants.FAILURE);
119+
resultMap.put(Constants.MESSAGE, "修改失败");
120+
}
121+
} catch (Exception e) {
122+
e.getStackTrace();
123+
resultMap.put(Constants.STATUS,Constants.FAILURE);
124+
resultMap.put(Constants.MESSAGE, "修改失败");
125+
}
126+
127+
return resultMap;
128+
}
129+
130+
@RequestMapping("/updateHotSearch")
131+
public @ResponseBody Map<String,Object> updateHotSearch(Integer hotId,String displayName,Integer campusId,String searchTag){
132+
Map<String,Object> resultMap=new HashMap<String,Object>();
133+
134+
try {
135+
HotSearch hotSearch=new HotSearch();
136+
hotSearch.setSearchTag(searchTag);
137+
hotSearch.setDisplayName(displayName);
138+
139+
int flag=-1;
140+
if(hotId==0||hotId==null){
141+
//新增
142+
hotSearch.setCampusId(campusId);
143+
hotSearch.setCreateTime(new Date().getTime());
144+
flag=hotSearchService.insert(hotSearch); //添加
145+
}else{
146+
hotSearch.setHotId(hotId);
147+
flag=hotSearchService.update(hotSearch); //更新
148+
}
149+
150+
if(flag!=-1){
151+
resultMap.put(Constants.STATUS,Constants.SUCCESS);
152+
resultMap.put(Constants.MESSAGE, "修改成功");
153+
}else{
154+
resultMap.put(Constants.STATUS,Constants.FAILURE);
155+
resultMap.put(Constants.MESSAGE, "修改失败");
156+
}
157+
} catch (Exception e) {
158+
e.getStackTrace();
159+
resultMap.put(Constants.STATUS,Constants.FAILURE);
160+
resultMap.put(Constants.MESSAGE, "修改失败");
161+
}
162+
163+
return resultMap;
164+
}
165+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.changyu.foryou.mapper;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
6+
import com.changyu.foryou.model.HotSearch;
7+
8+
public interface HotSearchMapper {
9+
int deleteByPrimaryKey(Integer hotId);
10+
11+
int insert(HotSearch record);
12+
13+
int insertSelective(HotSearch record);
14+
15+
HotSearch selectByPrimaryKey(Integer hotId);
16+
17+
int updateByPrimaryKeySelective(HotSearch record);
18+
19+
int updateByPrimaryKey(HotSearch record);
20+
21+
List<HotSearch> getHotSearchs(Map<String, Object> paramMap); //获取校区的所有热搜标签
22+
23+
int setNot2Display(Map<String, Object> paramMap); //将标签拿下来
24+
25+
int set2Dispaly(Map<String, Object> paramMap); //显示标签
26+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
3+
<mapper namespace="com.changyu.foryou.mapper.HotSearchMapper" >
4+
<resultMap id="BaseResultMap" type="com.changyu.foryou.model.HotSearch" >
5+
<id column="hot_id" property="hotId" jdbcType="INTEGER" />
6+
<result column="display_name" property="displayName" jdbcType="VARCHAR" />
7+
<result column="search_tag" property="searchTag" jdbcType="VARCHAR" />
8+
<result column="create_time" property="createTime" jdbcType="BIGINT" />
9+
<result column="is_display" property="isDisplay" jdbcType="TINYINT" />
10+
<result column="campus_id" property="campusId" jdbcType="INTEGER" />
11+
</resultMap>
12+
<sql id="Base_Column_List" >
13+
hot_id, display_name, search_tag, create_time, is_display, campus_id
14+
</sql>
15+
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Short" >
16+
select
17+
<include refid="Base_Column_List" />
18+
from hot_search
19+
where hot_id = #{hotId,jdbcType=INTEGER}
20+
</select>
21+
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
22+
delete from hot_search
23+
where hot_id = #{hotId,jdbcType=INTEGER}
24+
</delete>
25+
<insert id="insert" parameterType="com.changyu.foryou.model.HotSearch" >
26+
insert into hot_search (hot_id, display_name, search_tag,
27+
create_time, is_display, campus_id
28+
)
29+
values (#{hotId,jdbcType=INTEGER}, #{displayName,jdbcType=VARCHAR}, #{searchTag,jdbcType=VARCHAR},
30+
#{createTime,jdbcType=BIGINT}, #{isDisplay,jdbcType=TINYINT}, #{campusId,jdbcType=INTEGER}
31+
)
32+
</insert>
33+
<insert id="insertSelective" parameterType="com.changyu.foryou.model.HotSearch" >
34+
insert into hot_search
35+
<trim prefix="(" suffix=")" suffixOverrides="," >
36+
<if test="hotId != null" >
37+
hot_id,
38+
</if>
39+
<if test="displayName != null" >
40+
display_name,
41+
</if>
42+
<if test="searchTag != null" >
43+
search_tag,
44+
</if>
45+
<if test="createTime != null" >
46+
create_time,
47+
</if>
48+
<if test="isDisplay != null" >
49+
is_display,
50+
</if>
51+
<if test="campusId != null" >
52+
campus_id,
53+
</if>
54+
</trim>
55+
<trim prefix="values (" suffix=")" suffixOverrides="," >
56+
<if test="hotId != null" >
57+
#{hotId,jdbcType=INTEGER},
58+
</if>
59+
<if test="displayName != null" >
60+
#{displayName,jdbcType=VARCHAR},
61+
</if>
62+
<if test="searchTag != null" >
63+
#{searchTag,jdbcType=VARCHAR},
64+
</if>
65+
<if test="createTime != null" >
66+
#{createTime,jdbcType=BIGINT},
67+
</if>
68+
<if test="isDisplay != null" >
69+
#{isDisplay,jdbcType=TINYINT},
70+
</if>
71+
<if test="campusId != null" >
72+
#{campusId,jdbcType=INTEGER},
73+
</if>
74+
</trim>
75+
</insert>
76+
<update id="updateByPrimaryKeySelective" parameterType="com.changyu.foryou.model.HotSearch" >
77+
update hot_search
78+
<set >
79+
<if test="displayName != null" >
80+
display_name = #{displayName,jdbcType=VARCHAR},
81+
</if>
82+
<if test="searchTag != null" >
83+
search_tag = #{searchTag,jdbcType=VARCHAR},
84+
</if>
85+
<if test="createTime != null" >
86+
create_time = #{createTime,jdbcType=BIGINT},
87+
</if>
88+
<if test="isDisplay != null" >
89+
is_display = #{isDisplay,jdbcType=TINYINT},
90+
</if>
91+
<if test="campusId != null" >
92+
campus_id = #{campusId,jdbcType=INTEGER},
93+
</if>
94+
</set>
95+
where hot_id = #{hotId,jdbcType=INTEGER}
96+
</update>
97+
<update id="updateByPrimaryKey" parameterType="com.changyu.foryou.model.HotSearch" >
98+
update hot_search
99+
set display_name = #{displayName,jdbcType=VARCHAR},
100+
search_tag = #{searchTag,jdbcType=VARCHAR},
101+
create_time = #{createTime,jdbcType=BIGINT},
102+
is_display = #{isDisplay,jdbcType=TINYINT},
103+
campus_id = #{campusId,jdbcType=INTEGER}
104+
where hot_id = #{hotId,jdbcType=INTEGER}
105+
</update>
106+
107+
<!-- 获取热搜标签 -->
108+
<select id="getHotSearchs" resultMap="BaseResultMap">
109+
select
110+
search_tag,hot_id,display_name,is_display
111+
from hot_search
112+
where campus_id=#{campusId,jdbcType=INTEGER}
113+
order by create_time DESC
114+
</select>
115+
116+
<update id="setNot2Display">
117+
update
118+
hot_search
119+
set
120+
is_display=0
121+
where hot_id=#{hotId,jdbcType=INTEGER}
122+
</update>
123+
124+
<update id="set2Dispaly">
125+
update
126+
hot_search
127+
set
128+
is_display=1
129+
where hot_id=#{hotId,jdbcType=INTEGER}
130+
</update>
131+
</mapper>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.changyu.foryou.model;
2+
3+
public class HotSearch {
4+
private Integer hotId;
5+
6+
private String displayName;
7+
8+
private String searchTag;
9+
10+
private Long createTime;
11+
12+
private Byte isDisplay;
13+
14+
private Integer campusId;
15+
16+
17+
18+
public String getDisplayName() {
19+
return displayName;
20+
}
21+
22+
public void setDisplayName(String displayName) {
23+
this.displayName = displayName == null ? null : displayName.trim();
24+
}
25+
26+
public String getSearchTag() {
27+
return searchTag;
28+
}
29+
30+
public void setSearchTag(String searchTag) {
31+
this.searchTag = searchTag == null ? null : searchTag.trim();
32+
}
33+
34+
public Long getCreateTime() {
35+
return createTime;
36+
}
37+
38+
public void setCreateTime(Long createTime) {
39+
this.createTime = createTime;
40+
}
41+
42+
public Byte getIsDisplay() {
43+
return isDisplay;
44+
}
45+
46+
public void setIsDisplay(Byte isDisplay) {
47+
this.isDisplay = isDisplay;
48+
}
49+
50+
public Integer getCampusId() {
51+
return campusId;
52+
}
53+
54+
public void setCampusId(Integer campusId) {
55+
this.campusId = campusId;
56+
}
57+
58+
public Integer getHotId() {
59+
return hotId;
60+
}
61+
62+
public void setHotId(Integer hotId) {
63+
this.hotId = hotId;
64+
}
65+
}

0 commit comments

Comments
 (0)