首页>代码>基于SSM实现的社区论坛系统(附PPT、设计文档)>/源代码/leek_bbs/src/main/java/com/lindong/controller/AdminDatumController.java
package com.lindong.controller;
import com.lindong.domain.Plate;
import com.lindong.domain.User;
import com.lindong.exception.ApiResult;
import com.lindong.exception.CustomException;
import com.lindong.exception.ResultCode;
import com.lindong.service.ILeadPostService;
import com.lindong.service.IPlateService;
import com.lindong.service.IUserService;
import com.lindong.utils.shiro.MD5;
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.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping("stair/datum")
public class AdminDatumController {
@Resource
private IUserService userService;
@Resource
private IPlateService plateService;
@Resource
private ILeadPostService iLeadPostService;
@RequestMapping("getUserInfo")
@ResponseBody
public User getUserInfo(String username){
return userService.findByName(username);
}
@RequestMapping("alterUser")
@ResponseBody
public ApiResult alterUser(@RequestBody Map map){
String old_password = (String) map.get("old_password");
if (old_password != null){ //密码更新
User user = userService.getPwdSalt((String) map.get("username"));
String oldPwd = MD5.getMd5String(old_password,user.getSalt());
if (!oldPwd.equals(user.getPassword())){ //与旧密码验证
throw new CustomException(ResultCode.PASSWORD_FAILED);
}
String new_salt = MD5.getSalt();
map.put("salt",new_salt);
String DBPassword = MD5.getMd5String((String) map.get("new_password"),new_salt);
map.put("password",DBPassword);
userService.updateUser(map);
}else { //基本资料更新
userService.updateUser(map);
}
return ApiResult.of(ResultCode.SUCCESS);
}
@RequestMapping("getCount")
@ResponseBody
public Map getCount(){
Map<String,Integer> map = new HashMap<>();
int userCount = userService.getUserCount(); //论坛用户总记录数
int browseNumber = iLeadPostService.getBrowseNumber();
int themeCount = 0; //论坛主题总记录数
int postsCount = 0; //论坛帖子总记录数
List<Plate> plates = plateService.findAll();
for (Plate plate : plates) {
themeCount = themeCount + plate.getTheme();
postsCount = postsCount + plate.getPosts();
}
map.put("userCount",userCount);
map.put("browseNumber",browseNumber);
map.put("themeCount",themeCount);
map.put("postsCount",postsCount);
return map;
}
}
最近下载更多
微信网友_7300424007897088 LV2
2024年12月17日
angaochong LV5
2024年10月15日
2636804923 LV6
2024年6月13日
sweetlove LV20
2024年6月13日
xiao1111 LV3
2024年5月15日
来一杯西瓜冰咩 LV6
2024年5月13日
JulyMagnolia LV5
2024年4月29日
getset LV8
2024年4月21日
微信网友_6444139264921600 LV8
2024年4月13日
xiaozhi丶 LV15
2024年3月28日
最近浏览更多
开开 LV4
11月26日
yigu123 LV6
11月8日
ma406805131 LV19
2024年12月18日
微信网友_7300424007897088 LV2
2024年12月17日
微信网友_7300409216405504
2024年12月17日
暂无贡献等级
微信网友_7300409508155392
2024年12月17日
暂无贡献等级
bankroll LV5
2024年12月16日
按市场洒出C LV1
2024年12月8日
krispeng LV15
2024年11月14日
yayacui LV2
2024年10月28日

