package com.hpe.findlover.contoller.front;
import com.alibaba.fastjson.JSONObject;
import com.hpe.findlover.anno.MyParam;
import com.hpe.findlover.model.*;
import com.hpe.findlover.service.*;
import com.hpe.findlover.util.Constant;
import com.hpe.findlover.util.LoverUtil;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.*;
/**
* 用户中心控制类
*
* @author hgh
*/
@Controller
@RequestMapping("/usercenter")
@CacheConfig(cacheNames = "user-cache")
public class UserCenterController {
private Logger logger = LoggerFactory.getLogger(UserCenterController.class);
private final UserService userService;
private final UserDetailService userDetailService;
private final UserLifeService userLifeService;
private final UserStatusService userStatusService;
private final UserPickService userPickService;
private final UserAssetService userAssetService;
private final UploadService uploadService;
private final UserPhotoService userPhotoService;
@Autowired
public UserCenterController(UserService userService, UserDetailService userDetailService, UserLifeService userLifeService, UserStatusService userStatusService, UserPickService userPickService, UserAssetService userAssetService, UploadService uploadService, UserPhotoService userPhotoService) {
this.userService = userService;
this.userDetailService = userDetailService;
this.userLifeService = userLifeService;
this.userStatusService = userStatusService;
this.userPickService = userPickService;
this.userAssetService = userAssetService;
this.uploadService = uploadService;
this.userPhotoService = userPhotoService;
}
/**
* 跳转到用户中心界面
*/
@GetMapping
public String userCenter(Model model, HttpSession session,@RequestParam(required = false) String type) {
//跳转前查询用资产
UserBasic user = (UserBasic) session.getAttribute("user");
userService.userAttrHandler(user);
UserAsset userAsset = userAssetService.selectByPrimaryKey(user.getId());
UserPhoto userPhoto = new UserPhoto();
userPhoto.setUserId(user.getId());
//获取用户所有照片
List<UserPhoto> photos = userPhotoService.select(userPhoto);
//获取用户头像
UserPhoto userBasicPhoto = new UserPhoto();
userBasicPhoto.setId(0);
userBasicPhoto.setPhoto(user.getPhoto());
userBasicPhoto.setUserId(user.getId());
photos.add(0, userBasicPhoto);
session.setAttribute("user", user);
logger.info("userAsset:" + userAsset);
logger.info("userAuth:" + user.isAuthenticated());
//剩余时间计算
int vipDate = 0, starDate = 0, asset = 0;
if (userAsset != null) {
if (userAsset.getVipDeadline() != null) {
vipDate = LoverUtil.getDiffOfDays(userAsset.getVipDeadline());
}
if (userAsset.getStarDeadline() != null) {
starDate = LoverUtil.getDiffOfDays(userAsset.getStarDeadline());
}
if (userAsset.getAsset() != null) {
asset = userAsset.getAsset();
}
}
logger.info("vipDate=" + vipDate + "....starDate=" + starDate + ".....asset=" + asset);
model.addAttribute("photos", photos);
model.addAttribute("vipDate", Math.max(0, vipDate));
model.addAttribute("starDate", Math.max(0, starDate));
model.addAttribute("asset", asset);
model.addAttribute("type", type);
return "front/user_center";
}
/**
* 用户图片上传
*
* @param request
* @return 严格返回JSON格式
*/
@RequestMapping(value = "upload", method = RequestMethod.POST)
@ResponseBody
public Object upload(HttpServletRequest request, HttpSession session) throws Exception {
//先检查图片数量是否已经上传至最大,即8张
UserBasic userBasic = (UserBasic) session.getAttribute("user");
UserPhoto checkPhoto = new UserPhoto();
checkPhoto.setUserId(userBasic.getId());
List<UserPhoto> validatPhotos = userPhotoService.select(checkPhoto);
if (validatPhotos.size() >= 8) {
return "{\"result\":\"false\"}";
}
Map<String, Object> resultMap = null;
//如果符合以上条件就给予上传
if (request instanceof MultipartHttpServletRequest) {
MultipartHttpServletRequest mrequest = (MultipartHttpServletRequest) request;
List<MultipartFile> photos = mrequest.getFiles("photos");
logger.debug("上传总数====>" + photos.size());
logger.debug("上传总数====>" + (validatPhotos.size() + photos.size()));
if ((validatPhotos.size() + photos.size()) > 8) {
return "{\"result\":\"false\"}";
}
resultMap = new HashMap<>();
List<UserPhoto> paths = new ArrayList<>();
Iterator<MultipartFile> iterator = photos.iterator();
while (iterator.hasNext()) {
MultipartFile photo = iterator.next();
if (photo != null) {
logger.debug("文件名称====>" + photo.getName());
logger.debug("文件类型====>" + photo.getContentType());
logger.debug("文件大小====>" + photo.getSize());
String photoPath = uploadService.uploadFile(photo);
UserPhoto userPhoto = new UserPhoto();
userPhoto.setUserId(userBasic.getId());
userPhoto.setPhoto(photoPath);
userPhotoService.insertUseGeneratedKeys(userPhoto);
paths.add(userPhoto);
logger.debug("上传完成!");
logger.debug("==================================");
}
}
//查询出所有的照片
resultMap.put("photos", paths);
}
resultMap.put("result", "true");
return resultMap;
}
/**
* 在相册中选择
*
* @param id 要删除照片的id
* @return
*/
@RequestMapping(value = "photo/head/{id}", method = RequestMethod.PUT)
@ResponseBody
@CachePut(key = "'photo-'+#id")
public Object updateUserPhoto(@PathVariable Integer id, HttpSession session) {
boolean result = false;
if (id != null) {
UserPhoto photo = userPhotoService.selectByPrimaryKey(id);
UserBasic user = (UserBasic) session.getAttribute("user");
result = userService.updatePhoto(photo, user);
session.setAttribute("user", user);
}
return result;
}
/**
* 删除照片
*
* @param id 要删除照片的id
* @return
*/
@RequestMapping(value = "photo/{id}", method = RequestMethod.DELETE)
@ResponseBody
public Object uploadPhoto(@PathVariable Integer id) {
boolean result = false;
if (id != null) {
logger.debug("删除的图片id为:" + id);
result = userPhotoService.deletePhotoByUserPhotoId(id);
}
return result;
}
/**
* 用户头像上传
*
* @param photo
* @return 严格返回JSON格式
*/
@RequestMapping(value = "photo", method = RequestMethod.POST)
@ResponseBody
public Object uploadPhoto(MultipartFile photo, HttpSession session) {
if (photo == null) {
return "{\"result\":\"false\"}";
}
String uploadPhotoPath = null;
UserBasic userBasic = (UserBasic) session.getAttribute("user");
UserPhoto userPhoto = null;
try {
//上传之前删除原来头像
if (userBasic.getPhoto() != null
&& !Constant.MALE_PHOTO.equals(userBasic.getPhoto())
&& !Constant.FEMALE_PHOTO.equals(userBasic.getPhoto())) {
uploadService.deleteFile(userBasic.getPhoto());
}
//获取用户头像
logger.debug("文件名称====>" + photo.getName());
logger.debug("文件类型====>" + photo.getContentType());
logger.debug("文件大小====>" + photo.getSize());
uploadPhotoPath = uploadService.uploadFile(photo);
userBasic.setPhoto(uploadPhotoPath);
logger.debug(uploadPhotoPath);
//更新sesion中图片路径
session.setAttribute("user", userBasic);
userService.updateByPrimaryKeySelective(userBa
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 1755 条
- 1
- 2
- 3
- 4
- 5
- 6
- 18
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
- qq_230177692020-05-06不要下载,资源不全,运行不起来,而且加微信以后就是要钱wx:fulltilt82021-04-19竞争对手
- qq_345528612019-12-26没有数据库wx:fulltilt82019-12-30有啊,加我吧,头像
![avatar](https://profile-avatar.csdnimg.cn/0b9fc0da0a9b425faf57e833245e3be7_u014191624.jpg!1)
wx:fulltilt8
- 粉丝: 94
- 资源: 25
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)