摘 要
现如今人们在努力工作和改善生活的同时,也开始关心起自己是否拥有一个健康的体魄,因此去健身房锻炼的人越来越多。面对不断激增的用户数量,飞羽健身房还是以传统人工操作的方式管理用户,执行效率很低。故开发基于微信小程序的飞羽健身管理系统,可帮助健身房经营者从繁杂的事务中解脱出来,以致于可以精确、便利、直观地获取信息。
为了解决上面的问题,对现有的一些健身房的管理系统的执行效率进行调查和询问,进而分析其目的和意义;利用互联网查询和分析时下比较热门和实用的软件开发工具和数据库,在此基础上提出了使用Java语言技术、基于Springboot+MyBatis框架和采用MySQL数据库、使用微信开发者工具完成飞羽健身小程序的开发方案;最后,在对飞羽健身系统进行总体需求分析、系统功能设计、数据库表设计和数据关系模型设计等工作,实现了基于微信小程序的飞羽健身管理系统。小程序学员端主要有首页、查看课程、添加到购物车等功能、教练端主要有课程管理、查看近期课程和创建课程等功能,后台主要有用户管理、课程管理、请假管理等功能。
该系统可以高效地管理健身学员用户信息和教练信息以及相关数据,解决了人手操作时的工作量大的问题,而且提高工作效率,使得飞羽健身房的管理者能集中精力于经营方面的内容。
关键词:健身 微信小程序 SpringBoot MySQL
【java毕业设计】基于微信小程序前端springboot的健身管理系统源码和论文
- package cn.com.itcast.sport.controller;
-
- import cn.com.itcast.sport.entry.*;
- import cn.com.itcast.sport.service.ApiService;
- import com.alibaba.fastjson.JSON;
- import com.github.pagehelper.Page;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import io.swagger.annotations.ApiOperation;
- import org.apache.ibatis.annotations.Param;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.ResponseBody;
-
- import java.math.BigDecimal;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- import java.util.stream.Collectors;
-
-
- @Controller
- @RequestMapping("/api")
- public class ApiController {
- @Autowired
- private ApiService apiService;
- public static String DATA_HM = "yyyy-MM-dd HH:mm";
- public static String DATA_DAY = "yyyy-MM-dd";
- public Date changeData(String date,String dataType) {
- if(dataType.equals(DATA_HM) ){
- date = date+":00";
- dataType = dataType+":ss";
- }
- SimpleDateFormat dateFormat = new SimpleDateFormat(dataType);
- Date parse = null;
- try {
- parse = dateFormat.parse(date);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- return parse;
- }
-
- @RequestMapping(path = "/login")
- @ApiOperation("登录校验账号密码")
-
- @ResponseBody
- public Result login(@Param("userName") String userName, @Param("password") String password){
- return apiService.checkLogin(userName,password);
- }
- @RequestMapping(path = "/getPic")
- @ApiOperation("获取轮播图")
- @ResponseBody
- public Result getPic(){
- List
pic = new ArrayList<>(); - pic.add("https://qq2118119173.oss-cn-beijing.aliyuncs.com/pics/logo1.jpg");
- pic.add("https://qq2118119173.oss-cn-beijing.aliyuncs.com/pics/logo2.jpg");
- pic.add("https://qq2118119173.oss-cn-beijing.aliyuncs.com/pics/logo3.jpg");
- return Result.success(pic);
- }
-
-
- @RequestMapping(path = "/course/queryCourses")
- @ApiOperation("查询全部课程,带参数则返回相应条件的数据,不带则返回全部")
- @ResponseBody
- public String queryCourses(@Param("courseName") String courseName, @Param("typeCode")String typeCode,
- @RequestParam(required=false,defaultValue="1") int page,
- @RequestParam(required=false,defaultValue="10") int limit){
- PageHelper.startPage(page, limit);
- List
courseMains = apiService.queryCourses(courseName, typeCode); - //用PageInfo对结果进行包装,传入连续显示的页数
- PageInfo pageInfo = new PageInfo(courseMains,limit);
- Map
map = new HashMap(); - map.put("code","200");
- map.put("msg", "操作成功!");
- map.put("maxPage",pageInfo.getPages());
- map.put("data",pageInfo.getList());
- String json= JSON.toJSONString(map);
- //将map转换为json格式
- return json;
- }
- @RequestMapping(path = "/course/queryTeacherCourses")
- @ApiOperation("查询教练个人的课程,必须带userCode参数")
- @ResponseBody
- public String queryTeacherCourses(@Param("courseName") String courseName, @Param("typeCode")String typeCode,
- @Param("userCode")String userCode,
- @RequestParam(required=false,defaultValue="1") int page,
- @RequestParam(required=false,defaultValue="10") int limit){
- PageHelper.startPage(page, limit);
- List
courseMains = apiService.queryTeacherCourses(courseName, typeCode,userCode); - //用PageInfo对结果进行包装,传入连续显示的页数
- PageInfo pageInfo = new PageInfo(courseMains,limit);
- Map
map = new HashMap(); - map.put("code","200");
- map.put("msg", "操作成功!");
- map.put("maxPage",pageInfo.getPages());
- map.put("data",pageInfo.getList());
- String json= JSON.toJSONString(map);
- //将map转换为json格式
- return json;
- }
-
- @RequestMapping(path = "/course/queryRecommendedCourses")
- @ApiOperation("查询推荐课程,带参数则返回相应条件的数据,不带则返回全部")
- @ResponseBody
- public Result queryRecommendedCourses(@Param("courseName") String courseName){
- List
courseMains = apiService.queryRecommendedCourses(courseName); - return Result.success(courseMains);
- }
-
- @RequestMapping(path = "/course/queryCourse")
- @ApiOperation("查看具体课程,必须带参数courseCode")
- @ResponseBody
- public Result queryCourse(@Param("userCode") String userCode,@Param("courseCode") String courseCode){
- CourseMain courseMain = apiService.queryCourse(userCode,courseCode);
- return Result.success(courseMain);
- }
-
- @RequestMapping(path = "/course/addCourse")
- @ApiOperation("添加课程,必须带参数")
- @ResponseBody
- public Result addCourse(@Param("courseName") String courseName, @Param("coursePic") String coursePic,
- @Param("courseVideo") String courseVideo,@Param("courseDesc") String courseDesc, @Param("coursePrice") BigDecimal coursePrice,
- @Param("startTime") String startTime, @Param("endTime") String endTime,
- @Param("coueseTypeName") String coueseTypeName, @Param("courseTypeCode") String courseTypeCode,
- @Param("userCode") String userCode, @Param("userName") String userName){
-
- CourseMain courseMain = new CourseMain();
- courseMain.setCourseName(courseName);
- courseMain.setCoursePic(coursePic);
- courseMain.setCourseVideo(courseVideo);
- courseMain.setCourseDesc(courseDesc);
- courseMain.setCoursePrice(coursePrice);
- courseMain.setCourseName(courseName);
- if(startTime !=null){
- courseMain.setStartTime(changeData(startTime, DATA_DAY));
- }
- if(endTime !=null){
- courseMain.setEndTime(changeData(endTime, DATA_DAY));
- }
- courseMain.setCoueseTypeName(coueseTypeName);
- courseMain.setCourseTypeCode(courseTypeCode);
- courseMain.setUserCode(userCode);
- courseMain.setUserName(userName);
- int addCourse = apiService.addCourse(courseMain);
- if(addCourse == -1){
- return Result.error(new CodeMsg(500,"插入失败"));
- }
- return Result.success("操作成功!");
- }
-
- @RequestMapping(path = "/course/editCourse")
- @ApiOperation("修改课程,必须带courseCode,只修改参数不为空的,状态status:'0未开课,1正在开课,2结束,3下架(教练离职)")
- @ResponseBody
- public Result editCourse(@Param("courseName") String courseName, @Param("courseCode") String courseCode,
- @Param("coursePic") String coursePic,@Param("courseVideo") String courseVideo,
- @Param("coursePrice") BigDecimal coursePrice,
- @Param("startTime") String startTime, @Param("endTime") String endTime,
- @Param("coueseTypeName") String coueseTypeName, @Param("courseTypeCode") String courseTypeCode,
- @Param("status") String status,
- @Param("userCode") String userCode, @Param("userName") String userName){
- CourseMain courseMain = new CourseMain();
- if(startTime !=null && !"''".equals(startTime)){
- courseMain.setStartTime(changeData(startTime, DATA_DAY));
- }
- if(endTime !=null&& !"''".equals(endTime)){
- courseMain.setEndTime(changeData(endTime, DATA_DAY));
- }
- courseMain.setCourseName(courseName);
- courseMain.setCourseCode(courseCode);
- courseMain.setCoursePic(coursePic);
- courseMain.setCourseVideo(courseVideo);
- courseMain.setCoursePrice(coursePrice);
- courseMain.setStatus(status);
- courseMain.setCoueseTypeName(coueseTypeName);
- courseMain.setCourseTypeCode(courseTypeCode);
- courseMain.setUserCode(userCode);
- courseMain.setUserName(userName);
- int editCourse = apiService.editCourse(courseMain);
- if(editCourse == -1){
- return Result.error(new CodeMsg(500,"更新失败"));
- }
- return Result.success("操作成功!");
- }
- @RequestMapping(path = "/course/openOrEndCourse")
- @ApiOperation("教练课程开课或下课,必须带courseCode和状态status:'0未开课,1正在开课,2结束,3下架(教练离职) ")
- @ResponseBody
- public Result openOrEndCourse( @Param("courseCode") String courseCode,@Param("status") String status){
-
- int editCourse = apiService.openOrEndCourse(courseCode,status);
- if(editCourse == -1){
- return Result.error(new CodeMsg(500,"操作失败"));
- }
- return Result.success("操作成功!");
- }
- @RequestMapping(path = "/course/applyEnd")
- @ApiOperation("教练课程申请下架,必须带courseCode")
- @ResponseBody
- public Result applyEnd( @Param("courseCode") String courseCode){
-
- int editCourse = apiService.applyEnd(courseCode);
- if(editCourse == -1){
- return Result.error(new CodeMsg(500,"操作失败"));
- }
- return Result.success("操作成功!");
- }
-
- @RequestMapping(path = "/course/courseCommend")
- @ApiOperation("学生课程评价,必须带用户userCode,课程courseCode,评价courseComment")
- @ResponseBody
- public Result courseCommend( @Param("userCode") String userCode,
- @Param("courseCode") String courseCode,
- @Param("courseComment") String courseComment){
-
- int commend = apiService.courseCommend(userCode, courseCode, courseComment);
- if(commend == -1){
- return Result.error(new CodeMsg(500,"参数不能为空"));
- }else if(commend == -0){
- return Result.error(new CodeMsg(500,"该学生没有此课程,不能评价!"));
- }
- return Result.success("操作成功!");
- }
-
- @RequestMapping(path = "/course/addClickNum")
- @ApiOperation("添加点击人数,必须带参数")
- @ResponseBody
- public Result addClickNum(@Param("courseCode") String courseCode){
- int clickNum = apiService.addClickNum(courseCode);
- if(clickNum == -1){
- return Result.error(new CodeMsg(500,"操作失败"));
- }
- return Result.success("操作成功");
- }
- @RequestMapping(path = "/course/queryCourseTypes")
- @ApiOperation("查看课程分类")
- @ResponseBody
- public Result queryCourseTypes(){
- List
courseTypes = apiService.queryCourseTypes(); - return Result.success(courseTypes);
- }
- @RequestMapping(path = "/course/queryCourseTypeByCode")
- @ApiOperation("查看某一课程分类信息,必须带参数")
- @ResponseBody
- public Result queryCourseTypeByCode(@Param("typeCode") String typeCode){
- CourseType courseType = apiService.queryCourseTypeByCode(typeCode);
- return Result.success(courseType);
- }
-
- @RequestMapping(path = "/course/queryPackages")
- @ApiOperation("查询课程全部小节,必须带参数")
- @ResponseBody
- public Result queryPackages(@Param("courseCode") String courseCode){
- List
coursePackages = apiService.queryPackages(courseCode); - return Result.success(coursePackages);
- }
- @RequestMapping(path = "/course/queryNearPackages")
- @ApiOperation("查询教练近期课程小节,必须带参数")
- @ResponseBody
- public String queryNearPackages(@Param("userCode") String userCode,@RequestParam(required=false,defaultValue="1") int page,
- @RequestParam(required=false,defaultValue="10") int limit){
- Page
- List
coursePackages = apiService.queryNearPackages(userCode); - PageInfo pageInfo = new PageInfo(coursePackages,limit);
- pageInfo.setPages(page1.getPages());//总页数
- pageInfo.setTotal(page1.getTotal());//总条数
- Map
map = new HashMap(); - map.put("code","200");
- map.put("msg", "操作成功!");
- map.put("maxPage",pageInfo.getPages());
- map.put("data",pageInfo.getList());
- String json= JSON.toJSONString(map);
- //将map转换为json格式
- return json;
- }
- @RequestMapping(path = "/course/queryPackage")
- @ApiOperation("查询具体小节的信息,必须带参数")
- @ResponseBody
- public Result queryPackage(@Param("packageCode") String packageCode){
- CoursePackage coursePackage = apiService.queryPackage(packageCode);
- return Result.success(coursePackage);
- }
- @RequestMapping(path = "/course/addPackage")
- @ApiOperation("添加小节,必须带参数")
- @ResponseBody
- public Result addPackage(@Param("packageNum") String packageNum,@Param("packageName") String packageName,
- @Param("timeLong") String timeLong,@Param("startTime") String startTime,
- @Param("endTime") String endTime, @Param("courseCode") String courseCode){
- CoursePackage coursePackage = new CoursePackage();
- coursePackage.setPackageName(packageName);
- coursePackage.setPackageNum(packageNum);
- coursePackage.setTimeLong(timeLong);
- coursePackage.setCourseCode(courseCode);
- if(startTime !=null){
- coursePackage.setStartTime(changeData(startTime, DATA_HM));
- }
- if(endTime !=null){
- coursePackage.setEndTime(changeData(endTime, DATA_HM));
- }
-
- int i = apiService.addPackage(coursePackage);
- if(i == -1){
- return Result.error(new CodeMsg(500,"操作失败"));
- }
- return Result.success("操作成功");
- }
- @RequestMapping(path = "/course/editPackage")
- @ApiOperation("修改小节,必须带packageCode参数,其他参数带则修改")
- @ResponseBody
- public Result editPackage(@Param("packageNum") String packageNum,@Param("packageName") String packageName,
- @Param("timeLong") String timeLong,@Param("startTime") String startTime,
- @Param("endTime") String endTime, @Param("courseCode") String courseCode,
- @Param("packageCode") String packageCode,@Param("status") String status){
- CoursePackage coursePackage = new CoursePackage();
- coursePackage.setPackageName(packageName);
- coursePackage.setPackageNum(packageNum);
- coursePackage.setTimeLong(timeLong);
- if(startTime !=null && !"''".equals(startTime)){
- coursePackage.setStartTime(changeData(startTime, DATA_HM));
- }
- if(endTime !=null && !"''".equals(endTime)){
- coursePackage.setEndTime(changeData(endTime, DATA_HM));
- }
- coursePackage.setCourseCode(courseCode);
- coursePackage.setStatus(status);
- int i = apiService.editPackage(coursePackage);
- if(i == -1){
- return Result.error(new CodeMsg(500,"操作失败"));
- }
- return Result.success("操作成功");
- }
- //detail
- @RequestMapping(path = "/course/openOrEndPackage")
- @ApiOperation("教练小节开课或下课,必须带packageCode和状态status:'0未解锁,1正在进行已解锁,2已完成")
- @ResponseBody
- public Result openOrEndPackage( @Param("packageCode") String packageCode,@Param("status") String status){
- int editPackage = apiService.openOrEndPackage(packageCode,status);
- if(editPackage == -1){
- return Result.error(new CodeMsg(500,"操作失败"));
- }
- return Result.success("操作成功!");
- }
- @RequestMapping(path = "/course/delPackage")
- @ApiOperation("教练删除小节,必须带packageCode")
- @ResponseBody
- public Result delPackage( @Param("packageCode") String packageCode){
-
- int delPackage = apiService.delPackage(packageCode);
- if(delPackage == -1){
- return Result.error(new CodeMsg(500,"操作失败"));
- }
- return Result.success("操作成功!");
- }
-
- @RequestMapping(path = "/course/queryShopChart")
- @ApiOperation("查看购物车,必须带参数")
- @ResponseBody
- public String queryShopChart(@Param("userCode") String userCode,
- @RequestParam(required=false,defaultValue="1") int page,
- @RequestParam(required=false,defaultValue="10") int limit){
- PageHelper.startPage(page, limit);
- List
shopCarts = apiService.queryShopChart(userCode); - PageInfo pageInfo = new PageInfo(shopCarts,limit);
- Map
map = new HashMap(); - map.put("code","200");
- map.put("msg", "操作成功!");
- map.put("maxPage",pageInfo.getPages());
- map.put("data",pageInfo.getList());
- String json= JSON.toJSONString(map);
- //将map转换为json格式
- return json;
- }
-
- @RequestMapping(path = "/course/addShopChart")
- @ApiOperation("添加购物车,必须带参数")
- @ResponseBody
- public Result addShopChart(@Param("userCode") String userCode,@Param("courseName") String courseName,
- @Param("courseCode") String courseCode){
- ShopCart shopCart = new ShopCart();
- shopCart.setCourseName(courseName);
- shopCart.setCourseCode(courseCode);
- shopCart.setUserCode(userCode);
- int i = apiService.addShopChart(shopCart);
- if(i == -1){
- return Result.error(new CodeMsg(500,"操作失败"));
- }
- return Result.success("操作成功");
- }
-
- @RequestMapping(path = "/course/editShopChart")
- @ApiOperation("批量删除购物车,必须带数组ids")
- @ResponseBody
- public Result delShopChart(Integer[] ids){
- int i = apiService.delShopChart(ids);
- if(i == -1){
- return Result.error(new CodeMsg(500,"操作失败"));
- }
- return Result.success("操作成功");
- }
- @RequestMapping(path = "/course/createOrderByShopChartIds")
- @ApiOperation("通过购物车创建订单,必须带购物车的数组ids")
- @ResponseBody
- public Result createOrderByShopChartIds(Integer[] ids){
- Map
order = apiService.createOrderByShopChartIds(ids); - if(order == null || order.size() == 0){
- return Result.error(new CodeMsg(500,"操作失败"));
- }
- return Result.success(order);
- }
- @RequestMapping(path = "/course/payOrder")
- @ApiOperation("支付或者取消订单,必须带参数orderCode和status,其中状态:-1,已取消,0未付款,1已付款,")
- @ResponseBody
- public Result payOrder(String orderCode,String status){
- int i = apiService.payOrder(orderCode, status);
- if(i == -1){
- return Result.error(new CodeMsg(500,"操作失败"));
- }
- return Result.success("操作成功!");
- }
-
- @RequestMapping(path = "/course/queryShopOrders")
- @ApiOperation("查看个人所有订单,必须带参数userCode")
- @ResponseBody
- public String queryShopOrders(String userCode,
- @RequestParam(required=false,defaultValue="1") int page,
- @RequestParam(required=false,defaultValue="10") int limit){
- Page
- List
- PageInfo pageInfo = new PageInfo(maps,limit);
- pageInfo.setPages(page1.getPages());//总页数
- pageInfo.setTotal(page1.getTotal());//总条数
- Map
map = new HashMap(); - map.put("code","200");
- map.put("msg", "操作成功!");
- map.put("maxPage",pageInfo.getPages());
- map.put("data",pageInfo.getList());
- String json= JSON.toJSONString(map);
- //将map转换为json格式
- return json;
- }
-
- @RequestMapping(path = "/course/queryUserCourse")
- @ApiOperation("查看学员个人课程,必须带参数userCode")
- @ResponseBody
- public String queryUserCourse(String userCode,
- @RequestParam(required=false,defaultValue="1") int page,
- @RequestParam(required=false,defaultValue="10") int limit){
- PageHelper.startPage(page, limit);
- List
courseMains = apiService.queryUserCourse(userCode); - PageInfo pageInfo = new PageInfo(courseMains,limit);
- Map
map = new HashMap(); - map.put("code","200");
- map.put("msg", "操作成功!");
- map.put("maxPage",pageInfo.getPages());
- map.put("data",pageInfo.getList());
- String json= JSON.toJSONString(map);
- //将map转换为json格式
- return json;
- }
-
- @RequestMapping(path = "/course/putCard")
- @ApiOperation("学员小节打卡,必须带参数packageCode和userCode")
- @ResponseBody
- public Result putCard(String packageCode,String userCode){
- int i = apiService.putCard(packageCode, userCode);
- if(i == -1){
- return Result.error(new CodeMsg(500,"操作失败"));
- }
- return Result.success("操作成功!");
- }
-
- @RequestMapping(path = "/course/queryUserInfo")
- @ApiOperation("查看个人信息,必须带参数userCode")
- @ResponseBody
- public Result queryUserInfo(String userCode){
- User user = apiService.queryUserInfo(userCode);
- if(user == null){
- return Result.error(new CodeMsg(500,"个人信息为空!"));
- }
- return Result.success(user);
- }
-
- @RequestMapping(path = "/course/querySalarys")
- @ApiOperation("查看个人工资,必须带参数userCode")
- @ResponseBody
- public Result querySalarys(String userCode){
- List
salaryMonths = apiService.querySalarys(userCode); - return Result.success(salaryMonths);
- }
-
- @RequestMapping(path = "/course/queryLeaveMains")
- @ApiOperation("查看教练请假列表,必须带参数")
- @ResponseBody
- public String queryLeaveMains(String userCode,
- @RequestParam(required=false,defaultValue="1") int page,
- @RequestParam(required=false,defaultValue="10") int limit){
- PageHelper.startPage(page, limit);
- List
leaveMains = apiService.queryLeaveMains(userCode); - PageInfo pageInfo = new PageInfo(leaveMains,limit);
- Map
map = new HashMap(); - map.put("code","200");
- map.put("msg", "操作成功!");
- map.put("maxPage",pageInfo.getPages());
- map.put("data",pageInfo.getList());
- String json= JSON.toJSONString(map);
- //将map转换为json格式
- return json;
- }
-
- @RequestMapping(path = "/course/addLeaveMain")
- @ApiOperation("教练请假,必须带参数")
- @ResponseBody
- public Result addLeaveMain(String packageCode,String packageAdjustStartTime,String packageAdjustEndTime,
- String startUserName,String startUserCode){
- LeaveMain leaveMain = new LeaveMain();
- if(packageAdjustStartTime !=null){
- leaveMain.setPackageAdjustStartTime(changeData(packageAdjustStartTime, DATA_HM));
- }
- if(packageAdjustEndTime !=null){
- leaveMain.setPackageAdjustEndTime(changeData(packageAdjustEndTime, DATA_HM));
- }
- leaveMain.setPackageCode(packageCode);
- leaveMain.setStartUserName(startUserName);
- leaveMain.setStartUserCode(startUserCode);
- int i = apiService.addLeaveMain(leaveMain);
- if(i == -1){
- return Result.error(new CodeMsg(500,"操作失败,参数异常!"));
- }else if(i == -2){
- return Result.error(new CodeMsg(500,"课程已开始,不能请假!"));
- }
- return Result.success("操作成功!");
- }
-
- @RequestMapping(path = "/course/cancelLeaveMain")
- @ApiOperation("教练撤销请假,必须带小节的code参数")
- @ResponseBody
- public Result cancelLeaveMain(String packageCode){
- int i = apiService.cancelLeaveMain(packageCode);
- if(i == -1){
- return Result.error(new CodeMsg(500,"操作失败"));
- }
- return Result.success("操作成功!");
- }
- @RequestMapping(path = "/course/querySiteMsgs")
- @ApiOperation("查询站内消息,必须带接收人code参数")
- @ResponseBody
- public String querySiteMsgs(String acceptCode,
- @RequestParam(required=false,defaultValue="1") int page,
- @RequestParam(required=false,defaultValue="10") int limit){
- PageHelper.startPage(page, limit);
- List
siteMsgs = apiService.querySiteMsgs(acceptCode); - PageInfo pageInfo = new PageInfo(siteMsgs,limit);
- Map
map = new HashMap(); - map.put("code","200");
- map.put("msg", "操作成功!");
- map.put("maxPage",pageInfo.getPages());
- map.put("data",pageInfo.getList());
- String json= JSON.toJSONString(map);
- //将map转换为json格式
- return json;
- }
- @RequestMapping(path = "/course/querySiteMsgNum")
- @ApiOperation("查询站内消息数量,必须带接收人code参数")
- @ResponseBody
- public Result querySiteMsgNum(String acceptCode){
- List
siteMsgs = apiService.querySiteMsgs(acceptCode); - int msgNum = 0;
- if(siteMsgs!=null &&siteMsgs.size() > 0){
- List
collect = siteMsgs.stream().filter(siteMsg -> siteMsg.getIsRead() != null && "0".equals(siteMsg.getIsRead())).collect(Collectors.toList()); - msgNum = collect == null ? 0: collect.size();
- }
- Map
map = new HashMap(); - map.put("msgNum",msgNum);
- return Result.success(map);
- }
- @RequestMapping(path = "/course/readSiteMsg")
- @ApiOperation("站内消息变为已读,必须带消息id")
- @ResponseBody
- public Result readSiteMsg(Integer id){
- int i = apiService.readSiteMsg(id);
- if(i == -1){
- return Result.error(new CodeMsg(500,"操作失败"));
- }
- return Result.success("操作成功!");
- }
-
-
- }
- package cn.com.itcast.sport.controller;
-
- import cn.com.itcast.sport.entry.*;
- import cn.com.itcast.sport.service.UserService;
- import com.alibaba.fastjson.JSON;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.ResponseBody;
-
- import javax.servlet.http.HttpSession;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
-
-
- @Controller
- public class UserController {
-
- @Autowired
- private UserService userService;
- /*学员管理*/
- @RequestMapping("/student/init")
- public String studentInit() {
- return "web/user-manage/studentManage";
- }
- @RequestMapping("/student/findAll")
- @ResponseBody
- public String studentManage(String name, @RequestParam(required=false,defaultValue="1") int page,
- @RequestParam(required=false,defaultValue="10") int limit) {
- //分页初始化
- PageHelper.startPage(page, limit);
- List<User> users = userService.findUsers(name,"0");
- //用PageInfo对结果进行包装,传入连续显示的页数
- PageInfo pageInfo = new PageInfo(users,limit);
- Map<String,Object> map = new HashMap<String, Object>();
- map.put("code","0");
- map.put("msg", "");
- map.put("count",pageInfo.getTotal());
- map.put("data",pageInfo.getList());
- String json= JSON.toJSONString(map);
- //将map转换为json格式
- // return JsonConversion.writeMapJSON(map);
- return json;
- }
- /*教师管理*/
- @RequestMapping("/teacher/init")
- public String teacherInit() {
- return "web/user-manage/teacherManage";
- }
- @RequestMapping("/teacher/findAll")
- @ResponseBody
- public String teacherManage(String name, @RequestParam(required=false,defaultValue="1") int page,
- @RequestParam(required=false,defaultValue="10") int limit) {
- PageHelper.startPage(page, limit);
- List<User> users = userService.findUsers(name,"1");
- //用PageInfo对结果进行包装,传入连续显示的页数
- PageInfo pageInfo = new PageInfo(users,limit);
- String msg = null;
- Map<String,Object> map = new HashMap<String, Object>();
- map.put("code","0");
- map.put("msg", msg);
- map.put("count",pageInfo.getTotal());
- map.put("data",pageInfo.getList());
- String json= JSON.toJSONString(map);
- //将map转换为json格式
- // return JsonConversion.writeMapJSON(map);
- return json;
- }
- /*添加教练,学员*/
- @RequestMapping("/user/addInit")
- public String userAddInit(Model model ,String type) {
- model.addAttribute("type",type);
- return "web/user-manage/addUser";
- }
- @RequestMapping("/user/addUser")
- @ResponseBody
- public Result addUser(User user){
- CodeMsg codeMsg = userService.addUser(user);
- Result<CodeMsg> success = Result.success(codeMsg);
- return success;
- }
- @RequestMapping("/user/editInit")
- public String
- userEditInit(Model model ,Integer id){
- User user = userService.findUserById(id);
- model.addAttribute("user",user);
- return "web/user-manage/editUser";
- }
-
- @RequestMapping("/user/editUser")
- @ResponseBody
- public Result editUser(User user){
- CodeMsg codeMsg = userService.editUser(user);
- Result<CodeMsg> success = Result.success(codeMsg);
- return success;
- }
- /*账号管理*/
- @RequestMapping("/account/init")
- public String accountInit(Model model, HttpSession httpSession) {
- return "web/user-manage/accountManage";
- }
- @RequestMapping("/account/findAll")
- @ResponseBody
- public String accountManage(String userName, @RequestParam(required=false,defaultValue="1") int page,
- @RequestParam(required=false,defaultValue="10") int limit) {
- PageHelper.startPage(page, limit);
- List<UserAndAccountAndRole> allUserInfo = userService.findAllUserInfo(userName);
- //用PageInfo对结果进行包装,传入连续显示的页数
- PageInfo pageInfo = new PageInfo(allUserInfo,limit);
-
- Map<String,Object> map = new HashMap<String, Object>();
- map.put("code","0");
- map.put("msg", "");
- map.put("count",pageInfo.getTotal());
- map.put("data",pageInfo.getList());
- String json= JSON.toJSONString(map);
- //将map转换为json格式
- // return JsonConversion.writeMapJSON(map);
- return json;
- }
- /*添加账号*/
- @RequestMapping("/account/addInit")
- public String accountAddInit(Model model) {
- List<User> users = userService.findHasNoAccountUsers();
- List<Role> roles = userService.findRoles(null);
- List<Account> accounts = userService.findAccounts(null);
- model.addAttribute("users",users);
- model.addAttribute("roles",roles);
- return "web/user-manage/addAccount";
- }
- @RequestMapping("/account/addAccount")
- @ResponseBody
- public Result addAccount(Account account){
- CodeMsg codeMsg = userService.addAccounts(account);
- Result<CodeMsg> success = Result.success(codeMsg);
- return success;
- }
- /*修改账号*/
- @RequestMapping("/account/editInit")
- public String accountEditInit(Model model,Integer id) {
- Account account = userService.findAccountById(id);
- List<Role> roles = userService.findRoles(null);
- model.addAttribute("account",account);
- model.addAttribute("roles",roles);
- return "web/user-manage/editAccount";
- }
-
- @RequestMapping("/account/editAccount")
- @ResponseBody
- public Result editAccount(Account account){
- CodeMsg codeMsg = userService.editAccount(account);
- Result<CodeMsg> success = Result.success(codeMsg);
- return success;
- }
-
- @RequestMapping("/role/findAll")
- @ResponseBody
- public String roleManage(String roleName, @RequestParam(required=false,defaultValue="1") int page,
- @RequestParam(required=false,defaultValue="10") int limit) {
- PageHelper.startPage(page, limit);
- List<Role> roles = userService.findRoles(roleName);
- //用PageInfo对结果进行包装,传入连续显示的页数
- PageInfo pageInfo = new PageInfo(roles,limit);
-
- Map<String,Object> map = new HashMap<String, Object>();
- map.put("code","0");
- map.put("msg", "");
- map.put("count",pageInfo.getTotal());
- map.put("data",pageInfo.getList());
- String json= JSON.toJSONString(map);
- //将map转换为json格式
- // return JsonConversion.writeMapJSON(map);
- return json;
- }
- /*添加账号*/
- @RequestMapping("/role/addInit")
- public String roleAddInit(Model model) {
- return "web/user-manage/addRole";
- }
- @RequestMapping("/role/addRole")
- @ResponseBody
- public Result addRole(Role role){
- CodeMsg codeMsg = userService.addRole(role);
- Result<CodeMsg> success = Result.success(codeMsg);
- return success;
- }
- @RequestMapping("/role/editInit")
- public String editRoleInit(Model model,Integer id){
- Role role = userService.findRoleById(id);
- model.addAttribute("role",role);
- return "web/user-manage/editRole";
- }
- @RequestMapping("/role/editRole")
- @ResponseBody
- public Result editRole(Role role){
- CodeMsg codeMsg = userService.editRole(role);
- Result<CodeMsg> success = Result.success(codeMsg);
- return success;
- }
-
- /*更改密码页面*/
- @RequestMapping("/editAccountPwd")
- public String editAccountPwd(Model model, HttpSession httpSession){
- Account account = userService.findUserInfo(httpSession);
- model.addAttribute("account",account);
- return "web/login/editAccountPwd";
- }
- /*更改密码*/
- @RequestMapping("/submitAccountPwd")
- @ResponseBody
- public Result submitAccountPwd(EditAccountPwd editAccount){
- CodeMsg codeMsg = userService.editAccountPwd(editAccount);
- Result<CodeMsg> success = Result.success(codeMsg);
- return success;
- }
-
- }