增加政策协议接口 / 个人中心接口 / 热搜接口

This commit is contained in:
TinyAnts 2022-09-07 16:19:54 +08:00
parent 18eb788ac9
commit fcb356e17e
9 changed files with 279 additions and 7 deletions

View File

@ -13,6 +13,7 @@ public class FrontConfig {
"/api/login",
"/api/index",
"/api/config",
"/api/policy",
"/api/decorate",
"/api/sms/send",

View File

@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@RestController
@ -56,4 +57,29 @@ public class IndexController {
return AjaxResult.success(map);
}
/**
* 协议
*
* @author fzr
* @param type 类型 service=服务协议,privacy=隐私协议
* @return Object
*/
@GetMapping("/policy")
public Object policy(@RequestParam String type) {
Map<String, String> map = iIndexService.policy(type);
return AjaxResult.success(map);
}
/**
* 热搜
*
* @author fzr
* @return Object
*/
@GetMapping("/search")
public Object search() {
List<String> list = iIndexService.search();
return AjaxResult.success(list);
}
}

View File

@ -1,24 +1,53 @@
package com.mdd.front.controller;
import com.mdd.common.core.AjaxResult;
import com.mdd.front.LikeFrontThreadLocal;
import com.mdd.front.service.IUserService;
import com.mdd.front.vo.user.UserCenterVo;
import com.mdd.front.vo.user.UserInfoVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RestController
@RequestMapping("api/user")
public class UserController {
@Resource
IUserService iUserService;
/**
* 个人中心
*
* @author fzr
* @return Object
*/
@GetMapping("/center")
public Object center() {
return AjaxResult.success();
UserCenterVo vo = iUserService.center(LikeFrontThreadLocal.getUserId());
return AjaxResult.success(vo);
}
/**
* 个人信息
*
* @author fzr
* @return Object
*/
@GetMapping("/info")
public Object info() {
return AjaxResult.success();
UserInfoVo vo = iUserService.info(LikeFrontThreadLocal.getUserId());
return AjaxResult.success(vo);
}
/**
* 政策协议
*
* @author fzr
* @return Object
*/
@GetMapping("/agreement")
public Object agreement() {
return AjaxResult.success();

View File

@ -1,5 +1,6 @@
package com.mdd.front.service;
import java.util.List;
import java.util.Map;
/**
@ -31,4 +32,21 @@ public interface IIndexService {
*/
Map<String, Object> config();
/**
* 政策
*
* @author fzr
* @param type 类型 service=服务协议,privacy=隐私协议
* @return Map<String, Object>
*/
Map<String, String> policy(String type);
/**
* 热搜
*
* @author fzr
* @return List<String>
*/
List<String> search();
}

View File

@ -1,4 +1,11 @@
package com.mdd.front.service;
import com.mdd.front.vo.user.UserCenterVo;
import com.mdd.front.vo.user.UserInfoVo;
public interface IUserService {
UserCenterVo center(Integer userId);
UserInfoVo info(Integer userId);
}

View File

@ -4,8 +4,10 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.mdd.common.entity.decorate.DecoratePage;
import com.mdd.common.entity.decorate.DecorateTabbar;
import com.mdd.common.entity.setting.HotSearch;
import com.mdd.common.mapper.decorate.DecoratePageMapper;
import com.mdd.common.mapper.decorate.DecorateTabbarMapper;
import com.mdd.common.mapper.setting.HotSearchMapper;
import com.mdd.common.utils.ConfigUtil;
import com.mdd.common.utils.ToolsUtil;
import com.mdd.common.utils.UrlUtil;
@ -13,10 +15,7 @@ import com.mdd.front.service.IIndexService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* 首页服务实现类
@ -30,6 +29,9 @@ public class IndexServiceImpl implements IIndexService {
@Resource
DecorateTabbarMapper decorateTabbarMapper;
@Resource
HotSearchMapper hotSearchMapper;
/**
* 首页
*
@ -100,4 +102,47 @@ public class IndexServiceImpl implements IIndexService {
return response;
}
/**
* 政策
*
* @author fzr
* @param type 类型 service=服务协议,privacy=隐私协议
* @return Map<String, Object>
*/
@Override
public Map<String, String> policy(String type) {
Map<String, String> map = ConfigUtil.getMap("protocol", type);
if (map == null) {
Map<String, String> m = new LinkedHashMap<>();
m.put("name", "");
m.put("content", "");
return m;
}
return map;
}
/**
* 热搜
*
* @author fzr
* @return List<String>
*/
@Override
public List<String> search() {
String isHotSearch = ConfigUtil.get("search", "isHotSearch", "0");
List<String> list = new LinkedList<>();
if (Integer.parseInt(isHotSearch) == 1) {
List<HotSearch> hotSearches = hotSearchMapper.selectList(
new QueryWrapper<HotSearch>()
.orderByDesc(Arrays.asList("sort", "id")));
for (HotSearch hotSearch : hotSearches) {
list.add(hotSearch.getName());
}
}
return list;
}
}

View File

@ -1,7 +1,88 @@
package com.mdd.front.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mdd.common.config.GlobalConfig;
import com.mdd.common.entity.user.User;
import com.mdd.common.entity.user.UserAuth;
import com.mdd.common.enums.ClientEnum;
import com.mdd.common.mapper.user.UserAuthMapper;
import com.mdd.common.mapper.user.UserMapper;
import com.mdd.common.utils.ConfigUtil;
import com.mdd.common.utils.TimeUtil;
import com.mdd.common.utils.UrlUtil;
import com.mdd.front.service.IUserService;
import com.mdd.front.vo.user.UserCenterVo;
import com.mdd.front.vo.user.UserInfoVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
@Service
public class UserServiceImpl {
public class UserServiceImpl implements IUserService {
@Resource
UserMapper userMapper;
@Resource
UserAuthMapper userAuthMapper;
/**
* 个人中心
*
* @author fzr
* @param userId 用户ID
* @return UserCenterVo
*/
@Override
public UserCenterVo center(Integer userId) {
User user = userMapper.selectOne(new QueryWrapper<User>()
.select("id,sn,avatar,real_name,nickname,username,mobile")
.eq("id", userId)
.last("limit 1"));
UserCenterVo vo = new UserCenterVo();
BeanUtils.copyProperties(user, vo);
if (user.getAvatar().equals("")) {
String avatar = ConfigUtil.get("user", "defaultAvatar", "");
vo.setAvatar(UrlUtil.toAbsoluteUrl(avatar));
} else {
vo.setAvatar(UrlUtil.toAbsoluteUrl(user.getAvatar()));
}
return vo;
}
@Override
public UserInfoVo info(Integer userId) {
User user = userMapper.selectOne(new QueryWrapper<User>()
.select("id,sn,avatar,real_name,nickname,username,mobile,password,sex,create_time")
.eq("id", userId)
.last("limit 1"));
UserAuth userAuth = userAuthMapper.selectOne(new QueryWrapper<UserAuth>()
.select("id,openid")
.eq("user_id", userId)
.eq("client", ClientEnum.MNP.getCode())
.last("limit 1"));
UserInfoVo vo = new UserInfoVo();
BeanUtils.copyProperties(user, vo);
vo.setIsPassword(!user.getPassword().equals(""));
vo.setIsBindMnp(userAuth != null);
vo.setVersion(GlobalConfig.version);
vo.setSex(user.getSex());
vo.setCreateTime(TimeUtil.timestampToDate(user.getCreateTime()));
if (!user.getAvatar().equals("")) {
vo.setAvatar(UrlUtil.toAbsoluteUrl(user.getAvatar()));
} else {
String avatar = ConfigUtil.get("user", "defaultAvatar", "");
vo.setAvatar(UrlUtil.toAbsoluteUrl(avatar));
}
return vo;
}
}

View File

@ -0,0 +1,23 @@
package com.mdd.front.vo.user;
import lombok.Data;
import java.io.Serializable;
/**
* 用户个人中心Vo
*/
@Data
public class UserCenterVo implements Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
private Integer sn;
private String avatar;
private String realName;
private String nickname;
private String username;
private String mobile;
}

View File

@ -0,0 +1,42 @@
package com.mdd.front.vo.user;
import lombok.Data;
import java.io.Serializable;
/**
* 用户个人中心Vo
*/
@Data
public class UserInfoVo implements Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
private Integer sn;
private String avatar;
private String realName;
private String nickname;
private String username;
private String mobile;
private String sex;
private Boolean isPassword;
private Boolean isBindMnp;
private String version;
private String createTime;
public void setSex(Integer sex) {
switch (sex) {
case 0:
this.sex = "未知";
break;
case 1:
this.sex = "";
break;
case 2:
this.sex = "";
break;
}
}
}