first commit
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package com.sqx.modules.search.Response;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SearchResponse implements Serializable {
|
||||
|
||||
//用户的搜索记录
|
||||
List<String> userSearchName = new ArrayList<>();
|
||||
//所有搜索记录前几名
|
||||
List<String> AllSerchName = new ArrayList<>();
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.sqx.modules.search.controller;
|
||||
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.search.entity.Search;
|
||||
import com.sqx.modules.search.service.SearchService;
|
||||
import com.sqx.modules.sys.controller.AbstractController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@Api(value = "搜索记录", tags = {"搜索记录"})
|
||||
@RequestMapping(value = "/search")
|
||||
public class SearchController extends AbstractController {
|
||||
@Autowired
|
||||
private SearchService searchService;
|
||||
@PostMapping("/insertSearch")
|
||||
@ApiOperation("记录搜索信息")
|
||||
public Result insertSearch(@RequestBody Search search){
|
||||
return searchService.insertSearch(search);
|
||||
}
|
||||
@GetMapping("/selectByUserId")
|
||||
@ApiOperation("查看搜索信息")
|
||||
public Result selectByUserId(Long userId){
|
||||
return searchService.selectByUserId(userId);
|
||||
}
|
||||
|
||||
@GetMapping("/deleteById")
|
||||
@ApiOperation("删除搜索信息")
|
||||
public Result deleteById(Long id){
|
||||
return searchService.deleteById(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.sqx.modules.search.controller.app;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.annotation.Login;
|
||||
import com.sqx.modules.app.entity.App;
|
||||
import com.sqx.modules.search.entity.Search;
|
||||
import com.sqx.modules.search.service.AppSearchService;
|
||||
import com.sqx.modules.search.service.SearchService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 搜索记录
|
||||
*
|
||||
* @author liyuan
|
||||
* @since 2021-07-17
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("app/appSearchController")
|
||||
@AllArgsConstructor
|
||||
@Slf4j
|
||||
public class AppSearchController {
|
||||
|
||||
private AppSearchService appSearchService;
|
||||
/**
|
||||
* 查询搜索记录
|
||||
*/
|
||||
@Login
|
||||
@RequestMapping(value = "/selectAppSearchNum", method = RequestMethod.GET)
|
||||
public Result selectAppSearchNum(@RequestAttribute Long userId) {
|
||||
return appSearchService.selectAppSearchNum(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户的搜索记录
|
||||
*/
|
||||
@Login
|
||||
@RequestMapping(value = "/deleteAppSearch", method = RequestMethod.GET)
|
||||
public Result deleteAppSearch(@RequestAttribute Long userId) {
|
||||
return appSearchService.deleteAppSearch(userId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
26
src/main/java/com/sqx/modules/search/dao/AppSearchDao.java
Normal file
26
src/main/java/com/sqx/modules/search/dao/AppSearchDao.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package com.sqx.modules.search.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.search.entity.Search;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface AppSearchDao extends BaseMapper<Search> {
|
||||
|
||||
/**
|
||||
* 经常搜索的名称
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<String> selectAppSearchNum();
|
||||
|
||||
/**
|
||||
* 删除用户的搜索记录
|
||||
*/
|
||||
int deleteAppSearch(Long userId);
|
||||
}
|
||||
9
src/main/java/com/sqx/modules/search/dao/SearchDao.java
Normal file
9
src/main/java/com/sqx/modules/search/dao/SearchDao.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.sqx.modules.search.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.sqx.modules.search.entity.Search;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface SearchDao extends BaseMapper<Search> {
|
||||
}
|
||||
35
src/main/java/com/sqx/modules/search/entity/Search.java
Normal file
35
src/main/java/com/sqx/modules/search/entity/Search.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.sqx.modules.search.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
@Data
|
||||
@TableName("search")
|
||||
public class Search implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
/**
|
||||
* 搜索id
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long searchId;
|
||||
/**
|
||||
* 搜索名称
|
||||
*/
|
||||
private String searchName;
|
||||
/**
|
||||
* 用户
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField("update_time")
|
||||
private String updateTime;
|
||||
|
||||
public Search() {}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.sqx.modules.search.service;
|
||||
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.search.entity.Search;
|
||||
import org.springframework.web.bind.annotation.RequestAttribute;
|
||||
|
||||
/**
|
||||
* app搜索
|
||||
*/
|
||||
public interface AppSearchService {
|
||||
|
||||
Result insetAppSearch(String searchName, Long userId);
|
||||
|
||||
Result selectAppSearchNum(Long userId);
|
||||
|
||||
Result deleteAppSearch( Long userId);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.sqx.modules.search.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.search.entity.Search;
|
||||
|
||||
public interface SearchService extends IService<Search> {
|
||||
Result insertSearch(Search search);
|
||||
Result selectByUserId(Long userId);
|
||||
Result deleteById(Long id);
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.sqx.modules.search.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.search.Response.SearchResponse;
|
||||
import com.sqx.modules.search.dao.AppSearchDao;
|
||||
import com.sqx.modules.search.entity.Search;
|
||||
import com.sqx.modules.search.service.AppSearchService;
|
||||
import com.sqx.modules.search.service.SearchService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class AppSearchServiceImpl extends ServiceImpl<AppSearchDao, Search> implements AppSearchService {
|
||||
private AppSearchDao appSearchDao;
|
||||
private SearchService searchService;
|
||||
|
||||
/**
|
||||
* 记录用户搜索的内容
|
||||
*
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Result insetAppSearch(String searchName, Long userId) {
|
||||
//判断传过来的搜索信息不为空
|
||||
if (searchName != null) {
|
||||
//去查询用户搜索内容是否有重复
|
||||
QueryWrapper<Search> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("search_name", searchName);
|
||||
queryWrapper.eq("user_id", userId);
|
||||
Search search1 = baseMapper.selectOne(queryWrapper);
|
||||
//有重复则更新改变时间
|
||||
if (search1 != null) {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
search1.setUpdateTime(simpleDateFormat.format(new Date()));
|
||||
int i = baseMapper.updateById(search1);
|
||||
if (i > 0) {
|
||||
return Result.success("更新成功!");
|
||||
} else {
|
||||
return Result.error("更新失败!");
|
||||
}
|
||||
} else {
|
||||
//没有则记录
|
||||
Search search=new Search();
|
||||
search.setUserId(userId);
|
||||
search.setSearchName(searchName);
|
||||
int count = baseMapper.insert(search);
|
||||
if (count > 0) {
|
||||
return Result.success("记录成功!");
|
||||
} else {
|
||||
return Result.error("记录失败!");
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
return Result.error("搜索信息为空!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 经常搜索的名称
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Result selectAppSearchNum(Long userId) {
|
||||
//经常搜索的名称
|
||||
List<String> list = appSearchDao.selectAppSearchNum();
|
||||
//用户经常搜索的名称
|
||||
Result result = searchService.selectByUserId(userId);
|
||||
//创建返回对象
|
||||
SearchResponse searchResponse = new SearchResponse();
|
||||
searchResponse.setAllSerchName(list);
|
||||
List<Search> searches = (List<Search>) result.get("data");
|
||||
for (Search search : searches) {
|
||||
searchResponse.getUserSearchName().add(search.getSearchName());
|
||||
}
|
||||
|
||||
return Result.success().put("data", searchResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户的搜索记录
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Result deleteAppSearch(Long userId) {
|
||||
int count = appSearchDao.deleteAppSearch(userId);
|
||||
if (count > 0) {
|
||||
return Result.success("删除成功!");
|
||||
} else {
|
||||
return Result.error("删除失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.sqx.modules.search.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.search.dao.SearchDao;
|
||||
import com.sqx.modules.search.entity.Search;
|
||||
import com.sqx.modules.search.service.SearchService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class SearchServiceImpl extends ServiceImpl<SearchDao, Search> implements SearchService {
|
||||
@Override
|
||||
public Result insertSearch(Search search) {
|
||||
baseMapper.insert(search);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result selectByUserId(Long userId) {
|
||||
QueryWrapper<Search> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("user_id",userId);
|
||||
return Result.success().put("data",baseMapper.selectList(queryWrapper));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result deleteById(Long id) {
|
||||
baseMapper.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user