├── classspirit.iml ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── jinhui │ │ └── classspirit │ │ ├── ClassSpiritApplication.java │ │ ├── ServletInitializer.java │ │ ├── controller │ │ ├── ActivityController.java │ │ ├── BaseController.java │ │ ├── ClassController.java │ │ ├── LoginController.java │ │ └── UserController.java │ │ ├── mapper │ │ ├── ActivityMapper.java │ │ ├── ApplyMapper.java │ │ ├── ClassMapper.java │ │ ├── StudentMapper.java │ │ └── UserMapper.java │ │ ├── service │ │ ├── ActivityService.java │ │ ├── ApplyService.java │ │ ├── ClassService.java │ │ ├── StudentService.java │ │ └── UserService.java │ │ ├── util │ │ ├── HttpRequest.java │ │ ├── JsonMapper.java │ │ ├── RequestTime.java │ │ └── TypeConversion.java │ │ └── vo │ │ ├── Activity.java │ │ ├── ActivityApply.java │ │ ├── Apply.java │ │ ├── Classes.java │ │ ├── Student.java │ │ └── User.java └── resources │ ├── application.yml │ ├── classspirit.sql │ ├── log4j2.xml │ ├── mapper │ ├── activityMapper.xml │ ├── applyMapper.xml │ ├── classMapper.xml │ ├── studentMapper.xml │ └── userMapper.xml │ ├── mybatis-conf.xml │ └── templates │ └── index.html └── test └── java └── com └── jinhui └── classspirit └── ClassSpiritApplicationTests.java /classspirit.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | com.jinhui 6 | classspirit 7 | 1.0.1.Beta 8 | jar 9 | classspirit 10 | 微信小程序——班务精灵 11 | 12 | 13 | org.springframework.boot 14 | spring-boot-starter-parent 15 | 2.0.7.RELEASE 16 | 17 | 18 | 19 | 20 | UTF-8 21 | UTF-8 22 | 1.8 23 | 24 | 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-logging 33 | 34 | 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-web 40 | 41 | 42 | 43 | org.mybatis.spring.boot 44 | mybatis-spring-boot-starter 45 | 1.3.2 46 | 47 | 48 | 49 | mysql 50 | mysql-connector-java 51 | compile 52 | 53 | 54 | 55 | org.springframework.boot 56 | spring-boot-starter-tomcat 57 | provided 58 | 59 | 60 | 61 | org.springframework.boot 62 | spring-boot-starter-log4j2 63 | 64 | 65 | 66 | org.springframework.boot 67 | spring-boot-starter-test 68 | test 69 | 70 | 71 | 72 | org.apache.commons 73 | commons-lang3 74 | 75 | 76 | 77 | com.alibaba 78 | fastjson 79 | 80 | 81 | org.apache.shiro 82 | shiro-core 83 | 1.2.3 84 | 85 | 86 | com.fasterxml.jackson.module 87 | jackson-module-jaxb-annotations 88 | 2.9.5 89 | 90 | 91 | org.activiti 92 | activiti-engine 93 | 5.21.0 94 | 95 | 96 | commons-io 97 | commons-io 98 | 2.5 99 | 100 | 101 | 102 | 103 | 104 | classspirit 105 | 106 | 107 | org.springframework.boot 108 | spring-boot-maven-plugin 109 | 110 | 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/ClassSpiritApplication.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ClassSpiritApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ClassSpiritApplication.class, args); 11 | } 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/ServletInitializer.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit; 2 | 3 | import org.springframework.boot.builder.SpringApplicationBuilder; 4 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 5 | 6 | public class ServletInitializer extends SpringBootServletInitializer { 7 | 8 | @Override 9 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 10 | return application.sources(ClassSpiritApplication.class); 11 | } 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/controller/ActivityController.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.controller; 2 | 3 | import com.jinhui.classspirit.service.ActivityService; 4 | import com.jinhui.classspirit.service.ApplyService; 5 | import com.jinhui.classspirit.service.UserService; 6 | import com.jinhui.classspirit.util.RequestTime; 7 | import com.jinhui.classspirit.vo.Activity; 8 | import com.jinhui.classspirit.vo.ActivityApply; 9 | import com.jinhui.classspirit.vo.Apply; 10 | import com.jinhui.classspirit.vo.User; 11 | import org.apache.commons.logging.Log; 12 | import org.apache.commons.logging.LogFactory; 13 | import org.apache.ibatis.annotations.Param; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.stereotype.Controller; 16 | import org.springframework.web.bind.annotation.RequestMapping; 17 | import org.springframework.web.bind.annotation.RequestMethod; 18 | import org.springframework.web.bind.annotation.RequestParam; 19 | import org.springframework.web.bind.annotation.ResponseBody; 20 | import org.springframework.web.multipart.MultipartFile; 21 | 22 | import javax.servlet.http.HttpServletRequest; 23 | import javax.servlet.http.HttpServletResponse; 24 | import java.io.File; 25 | import java.util.ArrayList; 26 | import java.util.HashMap; 27 | import java.util.List; 28 | import java.util.Map; 29 | 30 | @Controller 31 | @RequestMapping("/activity") 32 | public class ActivityController extends BaseController { 33 | 34 | private static Log log = LogFactory.getLog(ActivityController.class); 35 | 36 | @Autowired 37 | private ActivityService activityService; 38 | @Autowired 39 | private ApplyService applyService; 40 | @Autowired 41 | private UserService userService; 42 | 43 | /** 44 | * 活动列表(含详情) 45 | * 46 | * @param response 47 | * @return 48 | */ 49 | @RequestMapping(value = "list", method = RequestMethod.POST) 50 | @ResponseBody 51 | public String List(@RequestParam(defaultValue = "0") Integer currentPage, @RequestParam(defaultValue = "5") Integer pageSize, @Param("requestTime") String requestTime, 52 | @Param("classId") String classId, @Param("userId") String userId, @Param("type") Integer type, @Param("sort") Integer sort, HttpServletResponse response) { 53 | Map map = new HashMap(); 54 | List> list = new ArrayList>(); 55 | 56 | //查询活动列表 57 | List activitiesList = activityService.getActivitiesList(currentPage, pageSize, classId, userId, type, requestTime, sort); 58 | if (activitiesList != null) { 59 | for (ActivityApply activities : activitiesList) { 60 | //判断活动是或否截至报名 61 | int i = activities.getStartTime().compareTo(RequestTime.getStringDates()); 62 | if (i > 0) { 63 | activities.setActivityState(0); 64 | } else { 65 | activities.setActivityState(1); 66 | } 67 | Map maps = new HashMap(); 68 | List> lists = new ArrayList>(); 69 | //查询报名人数 70 | ActivityApply personCounts = applyService.getApplyCountByActivityId(activities.getActivityId()); 71 | 72 | maps.put("activityId", activities.getActivityId()); 73 | maps.put("activityName", activities.getActivityName()); 74 | maps.put("activityImage", serverUrl + activityImageUrl + activities.getActivityImage()); 75 | maps.put("activityContent", activities.getActivityContent()); 76 | maps.put("activityState", activities.getActivityState()); 77 | maps.put("classId", activities.getClassId()); 78 | maps.put("className", activities.getClassName()); 79 | maps.put("userName", activities.getUserName()); 80 | maps.put("startTime", activities.getStartTime()); 81 | maps.put("pubTime", activities.getPubTime()); 82 | maps.put("personCount", personCounts.getPersonCount()); 83 | 84 | //查询报名人信息列表 85 | List appliesList = applyService.getAppliesListByActivityId(activities.getActivityId()); 86 | for (ActivityApply applies : appliesList) { 87 | Map mapss = new HashMap(); 88 | mapss.put("userName", applies.getUserName()); 89 | mapss.put("userPhone", applies.getUserPhone()); 90 | mapss.put("userId", applies.getUserId()); 91 | mapss.put("userImage", serverUrl + userImageUrl + applies.getUserImage()); 92 | mapss.put("image", serverUrl + applyImageUrl + applies.getImage()); 93 | mapss.put("punchTime", applies.getPunchTime()); 94 | lists.add(mapss); 95 | } 96 | maps.put("personList", lists); 97 | list.add(maps); 98 | } 99 | map.put("activityList", list); 100 | map.put("result", 1); 101 | } else { 102 | map.put("result", 101); 103 | } 104 | 105 | return renderString(response, map); 106 | } 107 | 108 | /** 109 | * 活动详情 110 | * @param activityId 111 | * @param response 112 | * @return 113 | */ 114 | @RequestMapping(value = "details", method = RequestMethod.POST) 115 | @ResponseBody 116 | public String Details(@Param("activityId") Integer activityId, HttpServletResponse response) { 117 | Map map = new HashMap(); 118 | List> list = new ArrayList>(); 119 | 120 | ActivityApply activityInfo = activityService.getActivityByActivityId(activityId); 121 | if (activityInfo != null){ 122 | User us = userService.getUserName(activityInfo.getUserId()); 123 | map.put("activityId", activityInfo.getActivityId()); 124 | map.put("activityName", activityInfo.getActivityName()); 125 | map.put("activityImage", serverUrl + activityImageUrl + activityInfo.getActivityImage()); 126 | map.put("activityContent", activityInfo.getActivityContent()); 127 | 128 | int i = activityInfo.getStartTime().compareTo(RequestTime.getStringDates()); 129 | if (i > 0) { 130 | activityInfo.setActivityState(0); 131 | } else { 132 | activityInfo.setActivityState(1); 133 | } 134 | map.put("activityState", activityInfo.getActivityState()); 135 | map.put("classId", activityInfo.getClassId()); 136 | map.put("className", activityInfo.getClassName()); 137 | map.put("userName", us.getUserName()); 138 | map.put("startTime", activityInfo.getStartTime()); 139 | map.put("pubTime", activityInfo.getPubTime()); 140 | map.put("personCount", activityInfo.getPersonCount()); 141 | 142 | List applyInfo = applyService.getAppliesListByActivityId(activityId); 143 | for (ActivityApply a : applyInfo){ 144 | Map maps = new HashMap(); 145 | maps.put("userName", a.getUserName()); 146 | maps.put("userPhone", a.getUserPhone()); 147 | maps.put("userId", a.getUserId()); 148 | maps.put("userImage", serverUrl + userImageUrl + a.getUserImage()); 149 | maps.put("image", serverUrl + applyImageUrl + a.getImage()); 150 | maps.put("punchTime", a.getPunchTime()); 151 | list.add(maps); 152 | } 153 | map.put("personList", list); 154 | map.put("result", 1); 155 | }else { 156 | map.put("result", 0); 157 | } 158 | return renderString(response, map); 159 | } 160 | 161 | /** 162 | * 发布活动 163 | * 164 | * @param activityName 165 | * @param activityContent 166 | * @param classId 167 | * @param userId 168 | * @param startTime 169 | * @param activityImage 170 | * @param request 171 | * @param response 172 | * @return 173 | */ 174 | @RequestMapping(value = "add", method = RequestMethod.POST) 175 | @ResponseBody 176 | public String Add(@Param("activityName") String activityName, @Param("activityContent") String activityContent, 177 | @Param("classId") String classId, @Param("userId") String userId, 178 | @Param("startTime") String startTime, @Param("activityImage") MultipartFile activityImage, 179 | HttpServletRequest request, HttpServletResponse response) { 180 | Map map = new HashMap(); 181 | 182 | Activity a = new Activity(); 183 | a.setActivityName(activityName); 184 | a.setActivityContent(activityContent); 185 | a.setUserId(userId); 186 | a.setClassId(classId); 187 | a.setStartTime(startTime); 188 | a.setPubTime(RequestTime.getStringDates()); 189 | 190 | //获取文件名 191 | String imageName = null; 192 | imageName = activityImage.getOriginalFilename(); 193 | //保存地址 194 | String path = request.getSession().getServletContext().getRealPath("upload/images/activity/"); 195 | // 获取原文件名 196 | int startIndex = imageName.lastIndexOf("."); 197 | //文件类型 198 | String suffix = imageName.substring(startIndex); 199 | //重构文件名时间戳+类型 200 | imageName = System.currentTimeMillis() + suffix; 201 | //上传文件 202 | File targetFile = new File(path + File.separator + imageName); 203 | //若文件夹不存在,则创建目录 204 | if (!targetFile.exists()) { 205 | targetFile.mkdirs(); 206 | } 207 | try { 208 | activityImage.transferTo(targetFile); 209 | } catch (Exception e) { 210 | //e.printStackTrace(); 211 | map.put("result", "101"); 212 | } 213 | a.setActivityImage(imageName); 214 | //发布活动 215 | activityService.insertActivity(a); 216 | 217 | map.put("result", "1"); 218 | return renderString(response, map); 219 | } 220 | 221 | /** 222 | * 报名活动 223 | * @param activityId 224 | * @param userId 225 | * @param image 226 | * @param request 227 | * @param response 228 | * @return 229 | */ 230 | @RequestMapping(value = "apply", method = RequestMethod.POST) 231 | @ResponseBody 232 | public String Apply(@Param("activityId") Integer activityId, @Param("userId") String userId, 233 | @Param("image") MultipartFile image, HttpServletRequest request, HttpServletResponse response) { 234 | Map map = new HashMap(); 235 | //验证报名时间 236 | Activity verifyTime = activityService.verifyTime(activityId); 237 | //判断活动是或否截至报名 238 | int i = verifyTime.getStartTime().compareTo(RequestTime.getStringDates()); 239 | if (i > 0) { 240 | //验证是否报名 241 | Apply verifyApply = applyService.verifyApply(activityId, userId); 242 | if (verifyApply == null) { 243 | Apply a = new Apply(); 244 | a.setActivityId(activityId); 245 | a.setUserId(userId); 246 | a.setPunchTime(RequestTime.getStringDates()); 247 | 248 | //获取文件名 249 | String imageName = null; 250 | imageName = image.getOriginalFilename(); 251 | //保存地址 252 | String path = request.getSession().getServletContext().getRealPath("upload/images/apply/"); 253 | // 获取原文件名 254 | int startIndex = imageName.lastIndexOf("."); 255 | //文件类型 256 | String suffix = imageName.substring(startIndex); 257 | //重构文件名时间戳+类型 258 | imageName = System.currentTimeMillis() + suffix; 259 | //上传文件 260 | File targetFile = new File(path + File.separator + imageName); 261 | //若文件夹不存在,则创建目录 262 | if (!targetFile.exists()) { 263 | targetFile.mkdirs(); 264 | } 265 | try { 266 | image.transferTo(targetFile); 267 | } catch (Exception e) { 268 | //e.printStackTrace(); 269 | map.put("result", "101"); 270 | map.put("msg", "上传图片失败"); 271 | } 272 | a.setImage(imageName); 273 | //报名 274 | applyService.insertApply(a); 275 | map.put("result", "1"); 276 | } else { 277 | map.put("result", "3"); 278 | } 279 | } else { 280 | map.put("result", "2"); 281 | } 282 | return renderString(response, map); 283 | } 284 | 285 | 286 | } 287 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/controller/BaseController.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.controller; 2 | 3 | import com.jinhui.classspirit.util.JsonMapper; 4 | import org.apache.commons.lang3.StringEscapeUtils; 5 | import org.apache.commons.lang3.time.DateUtils; 6 | import org.apache.shiro.authc.AuthenticationException; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.ui.Model; 10 | import org.springframework.validation.BindException; 11 | import org.springframework.web.bind.WebDataBinder; 12 | import org.springframework.web.bind.annotation.ExceptionHandler; 13 | import org.springframework.web.bind.annotation.InitBinder; 14 | import org.springframework.web.servlet.mvc.support.RedirectAttributes; 15 | 16 | import javax.servlet.http.HttpServletResponse; 17 | import javax.validation.ConstraintViolationException; 18 | import javax.validation.ValidationException; 19 | import java.beans.PropertyEditorSupport; 20 | import java.io.File; 21 | import java.io.IOException; 22 | import java.text.ParseException; 23 | import java.util.Date; 24 | 25 | /** 26 | * 控制器支持类 27 | */ 28 | public abstract class BaseController { 29 | /** 30 | * 日志对象 31 | */ 32 | protected Logger logger = LoggerFactory.getLogger(getClass()); 33 | 34 | /** 35 | * 定义头像图片返回地址 36 | */ 37 | //String serverUrl = "http://192.168.92.52:8080/classspirit"; 38 | String serverUrl = "https://smartpark.iego.cn:60443/classspirit"; 39 | String activityImageUrl = "/upload/images/activity/"; 40 | String userImageUrl = "/upload/images/user/"; 41 | String applyImageUrl = "/upload/images/apply/"; 42 | String studentImageUrl = "/upload/images/student/"; 43 | 44 | 45 | /** 46 | * 删除服务器文件 47 | * @param filePath 48 | * @return 49 | */ 50 | public static boolean deleteServerFile(String filePath){ 51 | boolean deleteFlag = false; 52 | File file = new File(filePath); 53 | if (file.exists() && file.isFile() && file.delete()){ 54 | deleteFlag = true;} 55 | else{ 56 | deleteFlag = false;} 57 | return deleteFlag; 58 | } 59 | 60 | /** 61 | * 客户端返回JSON字符串 62 | * 63 | * @param response 64 | * @param object 65 | * @return 66 | */ 67 | protected String renderString(HttpServletResponse response, Object object) { 68 | return renderString(response, JsonMapper.toJsonString(object), "application/json"); 69 | } 70 | 71 | /** 72 | * 客户端返回字符串 73 | * 74 | * @param response 75 | * @param string 76 | * @return 77 | */ 78 | protected String renderString(HttpServletResponse response, String string, String type) { 79 | try { 80 | response.reset(); 81 | response.setContentType(type); 82 | response.setCharacterEncoding("utf-8"); 83 | response.getWriter().print(string); 84 | return null; 85 | } catch (IOException e) { 86 | return null; 87 | } 88 | } 89 | 90 | /** 91 | * 添加Model消息 92 | * 93 | * @param messages 94 | */ 95 | protected void addMessage(Model model, String... messages) { 96 | StringBuilder sb = new StringBuilder(); 97 | for (String message : messages) { 98 | sb.append(message).append(messages.length > 1 ? "
" : ""); 99 | } 100 | model.addAttribute("message", sb.toString()); 101 | } 102 | 103 | /** 104 | * 添加Flash消息 105 | * 106 | * @param messages 107 | */ 108 | protected void addMessage(RedirectAttributes redirectAttributes, String... messages) { 109 | StringBuilder sb = new StringBuilder(); 110 | for (String message : messages) { 111 | sb.append(message).append(messages.length > 1 ? "
" : ""); 112 | } 113 | redirectAttributes.addFlashAttribute("message", sb.toString()); 114 | } 115 | 116 | /** 117 | * 参数绑定异常 118 | */ 119 | @ExceptionHandler({BindException.class, ConstraintViolationException.class, ValidationException.class}) 120 | public String bindException() { 121 | return "error/400"; 122 | } 123 | 124 | /** 125 | * 授权登录异常 126 | */ 127 | @ExceptionHandler({AuthenticationException.class}) 128 | public String authenticationException() { 129 | return "error/403"; 130 | } 131 | 132 | /** 133 | * 初始化数据绑定 134 | * 1. 将所有传递进来的String进行HTML编码,防止XSS攻击 135 | * 2. 将字段中Date类型转换为String类型 136 | */ 137 | @InitBinder 138 | protected void initBinder(WebDataBinder binder) { 139 | // String类型转换,将所有传递进来的String进行HTML编码,防止XSS攻击 140 | binder.registerCustomEditor(String.class, new PropertyEditorSupport() { 141 | @Override 142 | public void setAsText(String text) { 143 | setValue(text == null ? null : StringEscapeUtils.escapeHtml4(text.trim())); 144 | } 145 | 146 | @Override 147 | public String getAsText() { 148 | Object value = getValue(); 149 | return value != null ? value.toString() : ""; 150 | } 151 | }); 152 | // Date 类型转换 153 | binder.registerCustomEditor(Date.class, new PropertyEditorSupport() { 154 | @Override 155 | public void setAsText(String text) { 156 | try { 157 | setValue(DateUtils.parseDate(text)); 158 | } catch (ParseException e) { 159 | e.printStackTrace(); 160 | } 161 | } 162 | // @Override 163 | // public String getAsText() { 164 | // Object value = getValue(); 165 | // return value != null ? DateUtils.formatDateTime((Date)value) : ""; 166 | // } 167 | }); 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/controller/ClassController.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.controller; 2 | 3 | import com.jinhui.classspirit.service.ClassService; 4 | import com.jinhui.classspirit.service.StudentService; 5 | import com.jinhui.classspirit.service.UserService; 6 | import com.jinhui.classspirit.vo.Classes; 7 | import com.jinhui.classspirit.vo.Student; 8 | import com.jinhui.classspirit.vo.User; 9 | import org.apache.commons.logging.Log; 10 | import org.apache.commons.logging.LogFactory; 11 | import org.apache.ibatis.annotations.Param; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.stereotype.Controller; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.bind.annotation.RequestMethod; 16 | import org.springframework.web.bind.annotation.ResponseBody; 17 | 18 | import javax.servlet.http.HttpServletResponse; 19 | import java.util.ArrayList; 20 | import java.util.HashMap; 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | @Controller 25 | @RequestMapping("/class") 26 | public class ClassController extends BaseController { 27 | 28 | private static Log log = LogFactory.getLog(ClassController.class); 29 | 30 | @Autowired 31 | ClassService classService; 32 | @Autowired 33 | UserService userService; 34 | @Autowired 35 | StudentService studentService; 36 | 37 | /** 38 | * 班级列表 39 | * @param response 40 | * @return 41 | */ 42 | @RequestMapping(value = "list",method = RequestMethod.POST) 43 | @ResponseBody 44 | public String List(HttpServletResponse response) { 45 | Map map = new HashMap(); 46 | 47 | try { 48 | List> lists = new ArrayList>(); 49 | List list = classService.getClassList(); 50 | if (list != null){ 51 | for (Classes classes : list){ 52 | Map maps = new HashMap(); 53 | maps.put("classId", classes.getClassId()); 54 | maps.put("className", classes.getClassName()); 55 | lists.add(maps); 56 | } 57 | map.put("classList", lists); 58 | map.put("result", 1); 59 | }else { 60 | map.put("result", 101); 61 | } 62 | } catch (Exception e) { 63 | map.put("result", 0); 64 | //e.printStackTrace(); 65 | } 66 | 67 | return renderString(response,map); 68 | } 69 | 70 | /** 71 | * 班级详情 72 | * @param classId 班级Id 73 | * @param response 74 | * @return 75 | */ 76 | @RequestMapping(value = "details",method = RequestMethod.POST) 77 | @ResponseBody 78 | public String Details(@Param("classId") String classId, HttpServletResponse response) { 79 | Map map = new HashMap(); //一级 80 | Map maps = new HashMap(); //二级 81 | 82 | try { 83 | if (classId != null) { 84 | //获取班级信息 85 | Classes classes = classService.getClassById(classId); 86 | maps.put("classId", classes.getClassId()); 87 | maps.put("className", classes.getClassName()); 88 | 89 | //获取教师信息 90 | List> teacherList = new ArrayList>(); 91 | List teachers = userService.getTeacherByClassId(classId); 92 | for (User teacher : teachers){ 93 | Map teacherMap = new HashMap(); 94 | teacherMap.put("userName", teacher.getUserName()); 95 | teacherMap.put("userPhone", teacher.getUserPhone()); 96 | teacherMap.put("userType", teacher.getUserType()); 97 | teacherMap.put("userImage", serverUrl + userImageUrl + teacher.getUserImage()); 98 | teacherList.add(teacherMap); 99 | } 100 | maps.put("teacherList", teacherList); 101 | 102 | //获取学生信息 103 | List> studentList = new ArrayList>(); 104 | List students = studentService.getStudentByClassId(classId); 105 | for (Student student : students){ 106 | Map studentMap = new HashMap(); 107 | studentMap.put("studentId", student.getStudentId()); 108 | studentMap.put("studentName", student.getStudentName()); 109 | studentMap.put("studentClass", student.getStudentClass()); 110 | studentMap.put("studentImage", serverUrl + studentImageUrl + student.getStudentImage()); 111 | studentList.add(studentMap); 112 | } 113 | maps.put("studentList", studentList); 114 | 115 | map.put("classDetail", maps); 116 | map.put("result", 1); 117 | } else { 118 | map.put("result", 101); 119 | } 120 | } catch (Exception e) { 121 | map.put("result", 0); 122 | //e.printStackTrace(); 123 | } 124 | 125 | return renderString(response, map); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/controller/LoginController.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.controller; 2 | 3 | import com.jinhui.classspirit.service.UserService; 4 | import com.jinhui.classspirit.util.HttpRequest; 5 | import com.jinhui.classspirit.vo.User; 6 | import org.activiti.engine.impl.util.json.JSONObject; 7 | import org.apache.commons.io.FileUtils; 8 | import org.apache.commons.logging.Log; 9 | import org.apache.commons.logging.LogFactory; 10 | import org.apache.ibatis.annotations.Param; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Controller; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.bind.annotation.RequestMethod; 15 | import org.springframework.web.bind.annotation.ResponseBody; 16 | 17 | import javax.servlet.http.HttpServletRequest; 18 | import javax.servlet.http.HttpServletResponse; 19 | import java.io.File; 20 | import java.net.HttpURLConnection; 21 | import java.net.URL; 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | 25 | @Controller 26 | public class LoginController extends BaseController { 27 | 28 | private static Log log = LogFactory.getLog(LoginController.class); 29 | 30 | @Autowired 31 | UserService userService; 32 | 33 | /** 34 | * 通过code获取openId 35 | * @param code 客户端上传的code参数 36 | * @param response 37 | * @return 38 | * @throws Exception 39 | */ 40 | @RequestMapping(value = "getOpenId", method = RequestMethod.POST) 41 | @ResponseBody 42 | public String getOpenId(String code, HttpServletResponse response) throws Exception{ 43 | 44 | Map map = new HashMap(); 45 | 46 | // 登录凭证不能为空 47 | if (code == null || code.length() == 0) { 48 | map.put("status", 0); 49 | map.put("msg", "code 不能为空"); 50 | return renderString(response, map); 51 | } 52 | 53 | // 小程序唯一标识 (在微信小程序管理后台获取) 54 | String appid = "wxcf3f24b6252bc5c1"; 55 | // 小程序的 app secret (在微信小程序管理后台获取) 56 | String secret = "3b2aedd5e69e3f1577f667ab79e6d994"; 57 | // 授权(必填) 58 | String grant_type = "authorization_code"; 59 | 60 | //////////////// 1、向微信服务器 使用登录凭证 code 获取 session_key 和 openid //////////////// 61 | // 请求参数 62 | String params = "appid=" + appid + "&secret=" + secret + "&js_code=" + code + "&grant_type=" 63 | + grant_type; 64 | // 发送请求 65 | String sr = HttpRequest.sendGet("https://api.weixin.qq.com/sns/jscode2session", params); 66 | 67 | // 解析相应内容(转换成json对象) 68 | JSONObject json = new JSONObject(sr); 69 | String session_key = null; 70 | String openid = null; 71 | String errcode = null; 72 | 73 | //判断json对象中是否存在"openid"字段 74 | if (json.has("openid")) { 75 | // 用户的唯一标识(openid) 76 | openid = (String) json.get("openid"); 77 | map.put("result", 1); 78 | map.put("openid", openid); 79 | } else { 80 | // 获取错误码(errcode) 81 | errcode = json.get("errcode").toString(); 82 | map.put("result", errcode); 83 | } 84 | //判断json对象中是否存在"session_key"字段 85 | if (json.has("session_key")) { 86 | // 获取会话密钥(session_key) 87 | session_key = json.get("session_key").toString(); 88 | } 89 | return renderString(response, map); 90 | } 91 | 92 | /** 93 | * 登录 94 | * @return 95 | */ 96 | @RequestMapping(value = "login", method = RequestMethod.POST) 97 | @ResponseBody 98 | public String Login(@Param("userId") String userId, @Param("userName") String userName, 99 | @Param("userType") Integer userType, @Param("userImage") String userImage, 100 | HttpServletRequest request, HttpServletResponse response){ 101 | Map map = new HashMap(); 102 | User user = new User(); 103 | User verify = userService.verifyUser(userId); 104 | if (verify == null){ 105 | user.setUserId(userId); 106 | user.setUserName(userName); 107 | if (userType == null){ 108 | user.setUserType(-1); 109 | }else if (userType.equals(0)){ 110 | user.setUserType(0); 111 | }else if (userType.equals(1)){ 112 | user.setUserType(1); 113 | }else if (userType.equals(2)){ 114 | user.setUserType(2); 115 | } 116 | 117 | //根据userImage地址下载图片到服务器,将保存路径存入数据库 118 | String imageName = System.currentTimeMillis()+".png"; //定义图片保存名称 119 | String savePath = request.getSession().getServletContext().getRealPath("upload/images/user/"); //保存路径 120 | try { 121 | URL httpUrl = new URL(userImage); 122 | HttpURLConnection conn = (HttpURLConnection)httpUrl.openConnection(); 123 | //设置超时间为3秒 124 | conn.setConnectTimeout(3*1000); 125 | //防止屏蔽程序抓取而返回403错误 126 | conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); 127 | 128 | //文件保存位置 129 | File saveDir = new File(savePath); 130 | if(!saveDir.exists()){ 131 | saveDir.mkdirs(); 132 | } 133 | File file = new File(saveDir+ File.separator+imageName); 134 | //拷贝url到文件 135 | FileUtils.copyURLToFile(httpUrl, file); 136 | } catch (Exception e) { 137 | //e.printStackTrace(); 138 | map.put("result","101"); 139 | map.put("msg","没有获取到微信头像地址!"); 140 | } 141 | user.setUserImage(imageName); 142 | userService.insertUser(user); 143 | map.put("result", 1); 144 | }else { 145 | map.put("result", 0); 146 | } 147 | return renderString(response, map); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.controller; 2 | 3 | import com.jinhui.classspirit.service.UserService; 4 | import com.jinhui.classspirit.vo.User; 5 | import org.apache.commons.logging.Log; 6 | import org.apache.commons.logging.LogFactory; 7 | import org.apache.ibatis.annotations.Param; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RequestMethod; 12 | import org.springframework.web.bind.annotation.ResponseBody; 13 | import org.springframework.web.multipart.MultipartFile; 14 | 15 | import javax.servlet.http.HttpServletRequest; 16 | import javax.servlet.http.HttpServletResponse; 17 | import java.io.File; 18 | import java.util.HashMap; 19 | import java.util.Map; 20 | 21 | @Controller 22 | @RequestMapping("/user") 23 | public class UserController extends BaseController { 24 | 25 | private static Log log = LogFactory.getLog(UserController.class); 26 | 27 | @Autowired 28 | UserService userService; 29 | 30 | /** 31 | * 获取用户信息 32 | * 33 | * @param userId 34 | * @param response 35 | * @return 36 | */ 37 | @RequestMapping(value = "getInfo", method = RequestMethod.POST) 38 | @ResponseBody 39 | public String GetInfo(@Param("userId") String userId, HttpServletResponse response) { 40 | Map map = new HashMap(); 41 | 42 | 43 | if (userId != null) { 44 | User user = userService.getUserInfoByUserId(userId); 45 | if (user != null) { 46 | map.put("userId", user.getUserId()); 47 | map.put("userPhone", user.getUserPhone()); 48 | map.put("userImage", serverUrl + userImageUrl + user.getUserImage()); 49 | map.put("userType", user.getUserType()); 50 | map.put("userName", user.getUserName()); 51 | map.put("studentName", user.getStudentName()); 52 | map.put("className", user.getClassName()); 53 | 54 | map.put("result", 1); 55 | } else { 56 | map.put("result", 999); 57 | } 58 | } else { 59 | map.put("result", 101); 60 | } 61 | 62 | 63 | return renderString(response, map); 64 | } 65 | 66 | /** 67 | * 用户信息修改 68 | * 69 | * @param response 70 | * @return 71 | */ 72 | @RequestMapping(value = "updateInfo", method = RequestMethod.POST) 73 | @ResponseBody 74 | public String UpdateInfo(@Param("userId") String userId, @Param("userPhone") String userPhone, 75 | @Param("userImage") MultipartFile userImage, @Param("userType") Integer userType, 76 | @Param("userName") String userName, @Param("studentId") String studentId, 77 | @Param("classId") String classId, 78 | HttpServletRequest request, HttpServletResponse response) { 79 | Map map = new HashMap(); 80 | 81 | 82 | //验证用户类型 83 | User verifyType = userService.verifyUser(userId); 84 | 85 | User user = new User(); 86 | user.setUserId(userId); 87 | user.setUserPhone(userPhone); 88 | if (userImage != null) { 89 | 90 | //获取文件名 91 | String imageName = null; 92 | imageName = userImage.getOriginalFilename(); 93 | //保存地址 94 | String path = request.getSession().getServletContext().getRealPath("upload/images/user/"); 95 | // 获取原文件名 96 | int startIndex = imageName.lastIndexOf("."); 97 | //文件类型 98 | String suffix = imageName.substring(startIndex); 99 | //重构文件名时间戳+类型 100 | imageName = System.currentTimeMillis() + suffix; 101 | //上传文件 102 | File targetFile = new File(path + File.separator + imageName); 103 | //若文件夹不存在,则创建目录 104 | if (!targetFile.exists()) { 105 | targetFile.mkdirs(); 106 | } 107 | try { 108 | userImage.transferTo(targetFile); 109 | } catch (Exception e) { 110 | //e.printStackTrace(); 111 | map.put("result", "101"); 112 | } 113 | 114 | user.setUserImage(imageName); 115 | 116 | //删除修改前保存的图片 117 | deleteServerFile(path + File.separator + verifyType.getUserImage()); 118 | } 119 | if (verifyType.getUserType() == -1) { 120 | user.setUserType(userType); 121 | } 122 | user.setUserName(userName); 123 | if (userType == 2) { 124 | user.setStudentId(studentId); 125 | } 126 | if (userType == 0 || userType == 1) { 127 | user.setClassId(classId); 128 | } 129 | //更新用户信息 130 | userService.updateUserInfo(user); 131 | 132 | map.put("result", 1); 133 | 134 | 135 | return renderString(response, map); 136 | } 137 | 138 | 139 | } 140 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/mapper/ActivityMapper.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.mapper; 2 | 3 | import com.jinhui.classspirit.vo.Activity; 4 | import com.jinhui.classspirit.vo.ActivityApply; 5 | import org.apache.ibatis.annotations.Mapper; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | import java.util.List; 9 | 10 | @Mapper 11 | public interface ActivityMapper { 12 | List getActivitiesList(@Param("offset") int offset, @Param("pageSize") Integer pageSize, @Param("classId") String classId, @Param("userId") String userId, @Param("type") Integer type, @Param("requestTime") String requestTime, @Param("sort") Integer sort); 13 | 14 | List getActivitiesLists(@Param("offset") int offset, @Param("pageSize") Integer pageSize, @Param("classId") String classId, @Param("userId") String userId, @Param("type") Integer type, @Param("requestTime") String requestTime, @Param("sort") Integer sort); 15 | 16 | void insertActivity(Activity a); 17 | 18 | Activity verifyTime(Integer activityId); 19 | 20 | ActivityApply getActivityByActivityId(Integer activityId); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/mapper/ApplyMapper.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.mapper; 2 | 3 | import com.jinhui.classspirit.vo.ActivityApply; 4 | import com.jinhui.classspirit.vo.Apply; 5 | import org.apache.ibatis.annotations.Mapper; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | import java.util.List; 9 | 10 | @Mapper 11 | public interface ApplyMapper { 12 | 13 | ActivityApply getApplyCountByActivityId(long activityId); 14 | 15 | List getAppliesListByActivityId(long activityId); 16 | 17 | Apply verifyApply(@Param("activityId") Integer activityId, @Param("userId") String userId); 18 | 19 | void insertApply(Apply a); 20 | 21 | Apply verifyTime(String activityId); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/mapper/ClassMapper.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.mapper; 2 | 3 | import com.jinhui.classspirit.vo.Classes; 4 | import org.apache.ibatis.annotations.Mapper; 5 | 6 | import java.util.List; 7 | 8 | @Mapper 9 | public interface ClassMapper { 10 | List getClassList(); 11 | 12 | Classes getClassById(String classId); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/mapper/StudentMapper.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.mapper; 2 | 3 | import com.jinhui.classspirit.vo.Student; 4 | import org.apache.ibatis.annotations.Mapper; 5 | 6 | import java.util.List; 7 | 8 | @Mapper 9 | public interface StudentMapper { 10 | List getStudentByClassId(String classId); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.mapper; 2 | 3 | import com.jinhui.classspirit.vo.User; 4 | import org.apache.ibatis.annotations.Mapper; 5 | 6 | import java.util.List; 7 | 8 | @Mapper 9 | public interface UserMapper { 10 | List getTeacherByClassId(String classId); 11 | 12 | User getUserInfoByUserId(String userId); 13 | 14 | void updateUserInfo(User user); 15 | 16 | User verifyUser(String userId); 17 | 18 | void insertUser(User user); 19 | 20 | User getUserName(String userId); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/service/ActivityService.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.service; 2 | 3 | import com.jinhui.classspirit.mapper.ActivityMapper; 4 | import com.jinhui.classspirit.vo.Activity; 5 | import com.jinhui.classspirit.vo.ActivityApply; 6 | import org.apache.ibatis.annotations.Param; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | import java.util.List; 11 | 12 | @Service 13 | public class ActivityService { 14 | @Autowired 15 | private ActivityMapper activityMapper; 16 | 17 | /** 18 | * 获取活动列表 19 | * @param currentPage 当前页 20 | * @param pageSize 页码 21 | * @param classId 班级Id 22 | * @param userId 用户Id 23 | * @param type 类型 24 | * @return 25 | */ 26 | public List getActivitiesList(@Param("currentPage")Integer currentPage, @Param("pageSize")Integer pageSize, @Param("classId")String classId, @Param("userId")String userId, @Param("type")Integer type, @Param("requestTime")String requestTime, @Param("sort") Integer sort) { 27 | int offset = (currentPage) * pageSize; 28 | if (type != null && type == 2){ 29 | return activityMapper.getActivitiesLists(offset,pageSize,classId,userId,type,requestTime,sort); 30 | } 31 | return activityMapper.getActivitiesList(offset,pageSize,classId,userId,type,requestTime,sort); 32 | } 33 | 34 | /** 35 | * 发布活动 36 | * @param a 活动实体类 37 | */ 38 | public void insertActivity(Activity a) { 39 | activityMapper.insertActivity(a); 40 | } 41 | 42 | /** 43 | * 验证活动报名是否过期 44 | * @param activityId 45 | * @return 46 | */ 47 | public Activity verifyTime(Integer activityId) { 48 | return activityMapper.verifyTime(activityId); 49 | } 50 | 51 | /** 52 | * 活动信息 53 | * @param activityId 54 | * @return 55 | */ 56 | public ActivityApply getActivityByActivityId(Integer activityId) { 57 | return activityMapper.getActivityByActivityId(activityId); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/service/ApplyService.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.service; 2 | 3 | import com.jinhui.classspirit.mapper.ApplyMapper; 4 | import com.jinhui.classspirit.vo.ActivityApply; 5 | import com.jinhui.classspirit.vo.Apply; 6 | import org.apache.ibatis.annotations.Param; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | import java.util.List; 11 | 12 | @Service 13 | public class ApplyService { 14 | @Autowired 15 | private ApplyMapper applyMapper; 16 | 17 | /** 18 | * 根据活动Id查询报名人数 19 | * @param activityId 20 | * @return 21 | */ 22 | public ActivityApply getApplyCountByActivityId(long activityId) { 23 | return applyMapper.getApplyCountByActivityId(activityId); 24 | } 25 | 26 | /** 27 | * 根据活动Id查询报名人信息列表 28 | * @param activityId 29 | * @return 30 | */ 31 | public List getAppliesListByActivityId(long activityId) { 32 | return applyMapper.getAppliesListByActivityId(activityId); 33 | } 34 | 35 | /** 36 | * 验证是否已报名 37 | * @param activityId 38 | * @param userId 39 | * @return 40 | */ 41 | public Apply verifyApply(@Param("activityId") Integer activityId, @Param("userId") String userId) { 42 | return applyMapper.verifyApply(activityId,userId); 43 | } 44 | 45 | /** 46 | * 报名参加活动 47 | * @param a 48 | */ 49 | public void insertApply(Apply a) { 50 | applyMapper.insertApply(a); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/service/ClassService.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.service; 2 | 3 | import com.jinhui.classspirit.mapper.ClassMapper; 4 | import com.jinhui.classspirit.vo.Classes; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | 10 | @Service 11 | public class ClassService { 12 | @Autowired 13 | private ClassMapper classMapper; 14 | 15 | /** 16 | * 获取班级列表 17 | * @return 18 | */ 19 | public List getClassList() { 20 | return classMapper.getClassList(); 21 | } 22 | 23 | /** 24 | * 根据班级Id获取班级详情 25 | * @param classId 26 | * @return 27 | */ 28 | public Classes getClassById(String classId) { 29 | return classMapper.getClassById(classId); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/service/StudentService.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.service; 2 | 3 | import com.jinhui.classspirit.mapper.StudentMapper; 4 | import com.jinhui.classspirit.vo.Student; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | 10 | @Service 11 | public class StudentService { 12 | @Autowired 13 | private StudentMapper studentMapper; 14 | 15 | /** 16 | * 根据班级Id获取学生信息 17 | * @param classId 班级Id 18 | * @return 19 | */ 20 | public List getStudentByClassId(String classId) { 21 | return studentMapper.getStudentByClassId(classId); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.service; 2 | 3 | import com.jinhui.classspirit.mapper.UserMapper; 4 | import com.jinhui.classspirit.vo.User; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | 10 | @Service 11 | public class UserService { 12 | @Autowired 13 | private UserMapper userMapper; 14 | 15 | /** 16 | * 根据班级Id获取教师信息 17 | * @param classId 18 | * @return 19 | */ 20 | public List getTeacherByClassId(String classId) { 21 | return userMapper.getTeacherByClassId(classId); 22 | } 23 | 24 | /** 25 | * 获取用户信息(根据userId) 26 | * @param userId 27 | * @return 28 | */ 29 | public User getUserInfoByUserId(String userId) { 30 | return userMapper.getUserInfoByUserId(userId); 31 | } 32 | 33 | /** 34 | * 用户信息修改 35 | * @param user 36 | * @return 37 | */ 38 | public void updateUserInfo(User user) { 39 | userMapper.updateUserInfo(user); 40 | } 41 | 42 | /** 43 | * 验证用户是否存在 44 | * @param userId 45 | * @return 46 | */ 47 | public User verifyUser(String userId) { 48 | return userMapper.verifyUser(userId); 49 | } 50 | 51 | /** 52 | * 添加用户信息 53 | * @param user 54 | */ 55 | public void insertUser(User user) { 56 | userMapper.insertUser(user); 57 | } 58 | 59 | public User getUserName(String userId) { 60 | return userMapper.getUserName(userId); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/util/HttpRequest.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.util; 2 | 3 | 4 | import java.io.BufferedReader; 5 | import java.io.IOException; 6 | import java.io.InputStreamReader; 7 | import java.io.PrintWriter; 8 | import java.net.URL; 9 | import java.net.URLConnection; 10 | import java.util.List; 11 | import java.util.Map; 12 | 13 | public class HttpRequest { 14 | /** 15 | * 向指定URL发送GET方法的请求 16 | * 17 | * @param url 发送请求的URL 18 | * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。 19 | * @return result 所代表远程资源的响应结果 20 | */ 21 | public static String sendGet(String url, String param)throws IOException { 22 | String result = ""; 23 | BufferedReader in = null; 24 | try { 25 | String urlNameString = url + "?" + param; 26 | URL realUrl = new URL(urlNameString); 27 | // 打开和URL之间的连接 28 | URLConnection connection = realUrl.openConnection(); 29 | // 设置通用的请求属性 30 | connection.setRequestProperty("accept", "*/*"); 31 | connection.setRequestProperty("connection", "Keep-Alive"); 32 | connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); 33 | // 建立实际的连接 34 | connection.connect(); 35 | // 获取所有响应头字段 36 | Map> map = connection.getHeaderFields(); 37 | // 遍历所有的响应头字段 38 | for (String key : map.keySet()) { 39 | System.out.println(key + "--->" + map.get(key)); 40 | } 41 | // 定义 BufferedReader输入流来读取URL的响应 42 | in = new BufferedReader(new InputStreamReader(connection.getInputStream())); 43 | String line; 44 | while ((line = in.readLine()) != null) { 45 | result += line; 46 | } 47 | } catch (Exception e) { 48 | System.out.println("发送GET请求出现异常!" + e); 49 | e.printStackTrace(); 50 | } 51 | // 使用finally块来关闭输入流 52 | finally { 53 | try { 54 | if (in != null) { 55 | in.close(); 56 | } 57 | } catch (Exception e2) { 58 | e2.printStackTrace(); 59 | } 60 | } 61 | return result; 62 | } 63 | 64 | /** 65 | * 向指定 URL 发送POST方法的请求 66 | * @param url 发送请求的 URL 67 | * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。 68 | * @return result 所代表远程资源的响应结果 69 | */ 70 | public static String sendPost(String url, String param)throws IOException { 71 | PrintWriter out = null; 72 | BufferedReader in = null; 73 | String result = ""; 74 | try { 75 | URL realUrl = new URL(url); 76 | // 打开和URL之间的连接 77 | URLConnection conn = realUrl.openConnection(); 78 | // 设置通用的请求属性 79 | conn.setRequestProperty("accept", "*/*"); 80 | conn.setRequestProperty("connection", "Keep-Alive"); 81 | conn.setRequestProperty("user-agent", 82 | "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); 83 | // 发送POST请求必须设置如下两行 84 | conn.setDoOutput(true); 85 | conn.setDoInput(true); 86 | // 获取URLConnection对象对应的输出流 87 | out = new PrintWriter(conn.getOutputStream()); 88 | // 发送请求参数 89 | out.print(param); 90 | // flush输出流的缓冲 91 | out.flush(); 92 | // 定义BufferedReader输入流来读取URL的响应 93 | in = new BufferedReader(new InputStreamReader(conn.getInputStream())); 94 | String line; 95 | while ((line = in.readLine()) != null) { 96 | result += line; 97 | } 98 | } catch (Exception e) { 99 | System.out.println("发送 POST 请求出现异常!" + e); 100 | e.printStackTrace(); 101 | } 102 | //使用finally块来关闭输出流、输入流 103 | finally { 104 | try { 105 | if (out != null) { 106 | out.close(); 107 | } 108 | if (in != null) { 109 | in.close(); 110 | } 111 | } catch (IOException ex) { 112 | ex.printStackTrace(); 113 | } 114 | } 115 | return result; 116 | } 117 | } -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/util/JsonMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2012-2016 jee All rights reserved. 3 | */ 4 | package com.jinhui.classspirit.util; 5 | 6 | import com.fasterxml.jackson.annotation.JsonInclude.Include; 7 | import com.fasterxml.jackson.core.JsonGenerator; 8 | import com.fasterxml.jackson.core.JsonParser.Feature; 9 | import com.fasterxml.jackson.core.JsonProcessingException; 10 | import com.fasterxml.jackson.databind.*; 11 | import com.fasterxml.jackson.databind.module.SimpleModule; 12 | import com.fasterxml.jackson.databind.util.JSONPObject; 13 | import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule; 14 | import org.apache.commons.lang3.StringEscapeUtils; 15 | import org.apache.commons.lang3.StringUtils; 16 | import org.slf4j.Logger; 17 | import org.slf4j.LoggerFactory; 18 | 19 | import java.io.IOException; 20 | import java.util.Map; 21 | import java.util.TimeZone; 22 | 23 | /** 24 | * 简单封装Jackson,实现JSON String<->Java Object的Mapper. 25 | * 封装不同的输出风格, 使用不同的builder函数创建实例. 26 | * @author ThinkGem 27 | * @version 2013-11-15 28 | */ 29 | public class JsonMapper extends ObjectMapper { 30 | 31 | private static final long serialVersionUID = 1L; 32 | 33 | private static Logger logger = LoggerFactory.getLogger(JsonMapper.class); 34 | 35 | private static JsonMapper mapper; 36 | 37 | public JsonMapper() { 38 | this(Include.NON_EMPTY); 39 | } 40 | 41 | public JsonMapper(Include include) { 42 | // 设置输出时包含属性的风格 43 | if (include != null) { 44 | this.setSerializationInclusion(include); 45 | } 46 | // 允许单引号、允许不带引号的字段名称 47 | this.enableSimple(); 48 | // 设置输入时忽略在JSON字符串中存在但Java对象实际没有的属性 49 | this.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); 50 | // 空值处理为空串 51 | this.getSerializerProvider().setNullValueSerializer(new JsonSerializer(){ 52 | @Override 53 | public void serialize(Object value, JsonGenerator jgen, 54 | SerializerProvider provider) throws IOException, 55 | JsonProcessingException { 56 | jgen.writeString(""); 57 | } 58 | }); 59 | // 进行HTML解码。 60 | this.registerModule(new SimpleModule().addSerializer(String.class, new JsonSerializer(){ 61 | @Override 62 | public void serialize(String value, JsonGenerator jgen, 63 | SerializerProvider provider) throws IOException, 64 | JsonProcessingException { 65 | jgen.writeString(StringEscapeUtils.unescapeHtml4(value)); 66 | } 67 | })); 68 | // 设置时区 69 | this.setTimeZone(TimeZone.getDefault());//getTimeZone("GMT+8:00") 70 | } 71 | 72 | /** 73 | * 创建只输出非Null且非Empty(如List.isEmpty)的属性到Json字符串的Mapper,建议在外部接口中使用. 74 | */ 75 | public static JsonMapper getInstance() { 76 | if (mapper == null){ 77 | mapper = new JsonMapper().enableSimple(); 78 | } 79 | return mapper; 80 | } 81 | 82 | /** 83 | * 创建只输出初始值被改变的属性到Json字符串的Mapper, 最节约的存储方式,建议在内部接口中使用。 84 | */ 85 | public static JsonMapper nonDefaultMapper() { 86 | if (mapper == null){ 87 | mapper = new JsonMapper(Include.NON_DEFAULT); 88 | } 89 | return mapper; 90 | } 91 | 92 | /** 93 | * Object可以是POJO,也可以是Collection或数组。 94 | * 如果对象为Null, 返回"null". 95 | * 如果集合为空集合, 返回"[]". 96 | */ 97 | public String toJson(Object object) { 98 | try { 99 | return this.writeValueAsString(object); 100 | } catch (IOException e) { 101 | logger.warn("write to json string error:" + object, e); 102 | return null; 103 | } 104 | } 105 | 106 | /** 107 | * 反序列化POJO或简单Collection如List. 108 | * 109 | * 如果JSON字符串为Null或"null"字符串, 返回Null. 110 | * 如果JSON字符串为"[]", 返回空集合. 111 | * 112 | * 如需反序列化复杂Collection如List, 请使用fromJson(String,JavaType) 113 | * @see #fromJson(String, JavaType) 114 | */ 115 | public T fromJson(String jsonString, Class clazz) { 116 | if (StringUtils.isEmpty(jsonString)) { 117 | return null; 118 | } 119 | try { 120 | return this.readValue(jsonString, clazz); 121 | } catch (IOException e) { 122 | logger.warn("parse json string error:" + jsonString, e); 123 | return null; 124 | } 125 | } 126 | 127 | /** 128 | * 反序列化复杂Collection如List, 先使用函數createCollectionType构造类型,然后调用本函数. 129 | * @see #createCollectionType(Class, Class...) 130 | */ 131 | @SuppressWarnings("unchecked") 132 | public T fromJson(String jsonString, JavaType javaType) { 133 | if (StringUtils.isEmpty(jsonString)) { 134 | return null; 135 | } 136 | try { 137 | return (T) this.readValue(jsonString, javaType); 138 | } catch (IOException e) { 139 | logger.warn("parse json string error:" + jsonString, e); 140 | return null; 141 | } 142 | } 143 | 144 | /** 145 | * 構造泛型的Collection Type如: 146 | * ArrayList, 则调用constructCollectionType(ArrayList.class,MyBean.class) 147 | * HashMap, 则调用(HashMap.class,String.class, MyBean.class) 148 | */ 149 | public JavaType createCollectionType(Class collectionClass, Class... elementClasses) { 150 | return this.getTypeFactory().constructParametricType(collectionClass, elementClasses); 151 | } 152 | 153 | /** 154 | * 當JSON裡只含有Bean的部分屬性時,更新一個已存在Bean,只覆蓋該部分的屬性. 155 | */ 156 | @SuppressWarnings("unchecked") 157 | public T update(String jsonString, T object) { 158 | try { 159 | return (T) this.readerForUpdating(object).readValue(jsonString); 160 | } catch (JsonProcessingException e) { 161 | logger.warn("update json string:" + jsonString + " to object:" + object + " error.", e); 162 | } catch (IOException e) { 163 | logger.warn("update json string:" + jsonString + " to object:" + object + " error.", e); 164 | } 165 | return null; 166 | } 167 | 168 | /** 169 | * 輸出JSONP格式數據. 170 | */ 171 | public String toJsonP(String functionName, Object object) { 172 | return toJson(new JSONPObject(functionName, object)); 173 | } 174 | 175 | /** 176 | * 設定是否使用Enum的toString函數來讀寫Enum, 177 | * 為False時時使用Enum的name()函數來讀寫Enum, 默認為False. 178 | * 注意本函數一定要在Mapper創建後, 所有的讀寫動作之前調用. 179 | */ 180 | public JsonMapper enableEnumUseToString() { 181 | this.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); 182 | this.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING); 183 | return this; 184 | } 185 | 186 | /** 187 | * 支持使用Jaxb的Annotation,使得POJO上的annotation不用与Jackson耦合。 188 | * 默认会先查找jaxb的annotation,如果找不到再找jackson的。 189 | */ 190 | public JsonMapper enableJaxbAnnotation() { 191 | JaxbAnnotationModule module = new JaxbAnnotationModule(); 192 | this.registerModule(module); 193 | return this; 194 | } 195 | 196 | /** 197 | * 允许单引号 198 | * 允许不带引号的字段名称 199 | */ 200 | public JsonMapper enableSimple() { 201 | this.configure(Feature.ALLOW_SINGLE_QUOTES, true); 202 | this.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); 203 | return this; 204 | } 205 | 206 | /** 207 | * 取出Mapper做进一步的设置或使用其他序列化API. 208 | */ 209 | public ObjectMapper getMapper() { 210 | return this; 211 | } 212 | 213 | /** 214 | * 对象转换为JSON字符串 215 | * @param object 216 | * @return 217 | */ 218 | public static String toJsonString(Object object){ 219 | return JsonMapper.getInstance().toJson(object); 220 | } 221 | 222 | /** 223 | * JSON字符串转换为对象 224 | * @param jsonString 225 | * @param clazz 226 | * @return 227 | */ 228 | public static Object fromJsonString(String jsonString, Class clazz){ 229 | return JsonMapper.getInstance().fromJson(jsonString, clazz); 230 | } 231 | 232 | /** 233 | * 测试 234 | */ 235 | public static void main(String[] args) { 236 | // List> list = Lists.newArrayList(); 237 | // Map map = Maps.newHashMap(); 238 | // map.put("id", 1); 239 | // map.put("pId", -1); 240 | // map.put("name", "根节点"); 241 | // list.add(map); 242 | // map = Maps.newHashMap(); 243 | // map.put("id", 2); 244 | // map.put("pId", 1); 245 | // map.put("name", "你好"); 246 | // map.put("open", true); 247 | // list.add(map); 248 | // String json = JsonMapper.getInstance().toJson(list); 249 | // System.out.println(json); 250 | 251 | Map m = (Map) JsonMapper.fromJsonString("{'a':'1','b':'2'}", Map.class); 252 | System.out.println(m); 253 | } 254 | 255 | } 256 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/util/RequestTime.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.util; 2 | 3 | import java.text.ParseException; 4 | import java.text.SimpleDateFormat; 5 | import java.util.Date; 6 | 7 | /** 8 | * 获取时间 9 | */ 10 | public class RequestTime { 11 | 12 | /** 13 | * 获取当前时间 14 | * @return 时间类型 yyyy-MM-dd HH:mm:ss 15 | */ 16 | public static Date getNowDate() throws ParseException { 17 | //设置日期格式 18 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 19 | Date currentTime = new Date(); 20 | String date = sdf.format(currentTime); 21 | return sdf.parse(date); 22 | } 23 | 24 | /** 25 | * 获取当前时间 26 | * @return 时间类型 yyyy-MM-dd HH:mm 27 | */ 28 | public static Date getNowDates() throws ParseException { 29 | //设置日期格式 30 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); 31 | Date currentTime = new Date(); 32 | String date = sdf.format(currentTime); 33 | return sdf.parse(date); 34 | } 35 | 36 | /** 37 | * 获取当前时间 38 | * @return 时间类型 yyyy-MM-dd 39 | * @throws ParseException 40 | */ 41 | public static Date getNowDateShort() throws ParseException { 42 | //设置日期格式 43 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 44 | Date currentTime = new Date(); 45 | String date = sdf.format(currentTime); 46 | return sdf.parse(date); 47 | } 48 | 49 | /** 50 | * 获取当前时间(时:分:秒) 51 | * @return 时间类型 HH:mm:ss 52 | */ 53 | public static Date getDateTime() throws ParseException { 54 | SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); 55 | Date currentTime = new Date(); 56 | String date = sdf.format(currentTime); 57 | return sdf.parse(date); 58 | } 59 | /** 60 | * 获取当前时间 61 | * @return 字符串格式 yyyy-MM-dd HH:mm:ss 62 | */ 63 | public static String getStringDate() { 64 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 65 | Date currentTime = new Date(); 66 | return sdf.format(currentTime); 67 | } 68 | 69 | /** 70 | * 获取当前时间 71 | * @return 字符串格式 yyyy-MM-dd HH:mm 72 | */ 73 | public static String getStringDates() { 74 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); 75 | Date currentTime = new Date(); 76 | return sdf.format(currentTime); 77 | } 78 | 79 | /** 80 | * 获取当前时间 81 | * @return 字符串格式 yyyy-MM-dd 82 | */ 83 | public static String getStringDateShort() { 84 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 85 | Date currentTime = new Date(); 86 | return sdf.format(currentTime); 87 | } 88 | 89 | /** 90 | * 获取当前时间(时:分:秒) 91 | * @return 字符串格式 HH:mm:ss 92 | */ 93 | public static String getStringTime() { 94 | SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); 95 | Date currentTime = new Date(); 96 | return sdf.format(currentTime); 97 | } 98 | 99 | /** 100 | * 获取当前时间 101 | * @return 时间类型 102 | */ 103 | public static Date getNow() { 104 | return new Date(); 105 | } 106 | 107 | /** 108 | * 提取一个月中的最后一天 109 | * @param day 110 | * @return 111 | */ 112 | public static Date getLastDate(long day) { 113 | Date date = new Date(); 114 | long date_last = date.getTime() - 3600000 * 34 * day; 115 | return new Date(date_last); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/util/TypeConversion.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.util; 2 | 3 | import java.text.ParsePosition; 4 | import java.text.SimpleDateFormat; 5 | import java.util.Date; 6 | 7 | /** 8 | * 类型转换 9 | */ 10 | public class TypeConversion { 11 | 12 | /** 13 | * 字符串转换为时间类型 长时间格式:yyyy-MM-dd HH:mm:ss 14 | * @param date 15 | * @return 16 | */ 17 | public static Date stringToDate(String date) { 18 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 19 | ParsePosition pos = new ParsePosition(0); 20 | return sdf.parse(date, pos); 21 | } 22 | 23 | /** 24 | * 短字符串转换为时间类型 25 | * @param date 26 | * @return 27 | */ 28 | public static Date stringToDateShort(String date) { 29 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 30 | ParsePosition pos = new ParsePosition(0); 31 | return sdf.parse(date, pos); 32 | } 33 | 34 | /** 35 | * 时间类型转换为字符串 36 | * @param date 37 | * @return 38 | */ 39 | public static String dateToString(Date date) { 40 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 41 | return sdf.format(date); 42 | } 43 | 44 | /** 45 | * 短时间类型转换为字符串 46 | * @param date 47 | * @return 48 | */ 49 | public static String dateToStringShort(Date date) { 50 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 51 | return sdf.format(date); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/vo/Activity.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.vo; 2 | 3 | import org.apache.ibatis.type.Alias; 4 | 5 | @Alias("activity") 6 | public class Activity { 7 | 8 | private long activityId; 9 | private String activityName; 10 | private String activityImage; 11 | private String activityContent; 12 | private String userId; 13 | private String classId; 14 | private String startTime; 15 | private String pubTime; 16 | 17 | 18 | public long getActivityId() { 19 | return activityId; 20 | } 21 | 22 | public void setActivityId(long activityId) { 23 | this.activityId = activityId; 24 | } 25 | 26 | 27 | public String getActivityName() { 28 | return activityName; 29 | } 30 | 31 | public void setActivityName(String activityName) { 32 | this.activityName = activityName; 33 | } 34 | 35 | 36 | public String getActivityImage() { 37 | return activityImage; 38 | } 39 | 40 | public void setActivityImage(String activityImage) { 41 | this.activityImage = activityImage; 42 | } 43 | 44 | 45 | public String getActivityContent() { 46 | return activityContent; 47 | } 48 | 49 | public void setActivityContent(String activityContent) { 50 | this.activityContent = activityContent; 51 | } 52 | 53 | 54 | public String getUserId() { 55 | return userId; 56 | } 57 | 58 | public void setUserId(String userId) { 59 | this.userId = userId; 60 | } 61 | 62 | 63 | public String getClassId() { 64 | return classId; 65 | } 66 | 67 | public void setClassId(String classId) { 68 | this.classId = classId; 69 | } 70 | 71 | 72 | public String getStartTime() { 73 | return startTime; 74 | } 75 | 76 | public void setStartTime(String startTime) { 77 | this.startTime = startTime; 78 | } 79 | 80 | public String getPubTime() { 81 | return pubTime; 82 | } 83 | 84 | public void setPubTime(String pubTime) { 85 | this.pubTime = pubTime; 86 | } 87 | 88 | @Override 89 | public String toString() { 90 | return "Activity{" + 91 | "activityId=" + activityId + 92 | ", activityName='" + activityName + '\'' + 93 | ", activityImage='" + activityImage + '\'' + 94 | ", activityContent='" + activityContent + '\'' + 95 | ", userId='" + userId + '\'' + 96 | ", classId='" + classId + '\'' + 97 | ", startTime='" + startTime + '\'' + 98 | ", pubTime='" + pubTime + '\'' + 99 | '}'; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/vo/ActivityApply.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.vo; 2 | 3 | import org.apache.ibatis.type.Alias; 4 | 5 | @Alias("activityApply") 6 | public class ActivityApply { 7 | private long activityId; 8 | private String activityName; 9 | private String activityImage; 10 | private String activityContent; 11 | private Integer activityState; 12 | private String classId; 13 | private String className; 14 | private String userId; 15 | private String userPhone; 16 | private String userName; 17 | private String userImage; 18 | private String startTime; 19 | private String pubTime; 20 | private String image; 21 | private Integer personCount; 22 | private String punchTime; 23 | 24 | public long getActivityId() { 25 | return activityId; 26 | } 27 | 28 | public void setActivityId(long activityId) { 29 | this.activityId = activityId; 30 | } 31 | 32 | public String getActivityName() { 33 | return activityName; 34 | } 35 | 36 | public void setActivityName(String activityName) { 37 | this.activityName = activityName; 38 | } 39 | 40 | public String getActivityImage() { 41 | return activityImage; 42 | } 43 | 44 | public void setActivityImage(String activityImage) { 45 | this.activityImage = activityImage; 46 | } 47 | 48 | public String getActivityContent() { 49 | return activityContent; 50 | } 51 | 52 | public void setActivityContent(String activityContent) { 53 | this.activityContent = activityContent; 54 | } 55 | 56 | public Integer getActivityState() { 57 | return activityState; 58 | } 59 | 60 | public void setActivityState(Integer activityState) { 61 | this.activityState = activityState; 62 | } 63 | 64 | public String getClassId() { 65 | return classId; 66 | } 67 | 68 | public void setClassId(String classId) { 69 | this.classId = classId; 70 | } 71 | 72 | public String getClassName() { 73 | return className; 74 | } 75 | 76 | public void setClassName(String className) { 77 | this.className = className; 78 | } 79 | 80 | public String getUserId() { 81 | return userId; 82 | } 83 | 84 | public void setUserId(String userId) { 85 | this.userId = userId; 86 | } 87 | 88 | public String getUserPhone() { 89 | return userPhone; 90 | } 91 | 92 | public void setUserPhone(String userPhone) { 93 | this.userPhone = userPhone; 94 | } 95 | 96 | public String getUserName() { 97 | return userName; 98 | } 99 | 100 | public void setUserName(String userName) { 101 | this.userName = userName; 102 | } 103 | 104 | public String getUserImage() { 105 | return userImage; 106 | } 107 | 108 | public void setUserImage(String userImage) { 109 | this.userImage = userImage; 110 | } 111 | 112 | public String getStartTime() { 113 | return startTime; 114 | } 115 | 116 | public void setStartTime(String startTime) { 117 | this.startTime = startTime; 118 | } 119 | 120 | public String getPubTime() { 121 | return pubTime; 122 | } 123 | 124 | public void setPubTime(String pubTime) { 125 | this.pubTime = pubTime; 126 | } 127 | 128 | public String getImage() { 129 | return image; 130 | } 131 | 132 | public void setImage(String image) { 133 | this.image = image; 134 | } 135 | 136 | public Integer getPersonCount() { 137 | return personCount; 138 | } 139 | 140 | public void setPersonCount(Integer personCount) { 141 | this.personCount = personCount; 142 | } 143 | 144 | public String getPunchTime() { 145 | return punchTime; 146 | } 147 | 148 | public void setPunchTime(String punchTime) { 149 | this.punchTime = punchTime; 150 | } 151 | 152 | @Override 153 | public String toString() { 154 | return "ActivityApply{" + 155 | "activityId=" + activityId + 156 | ", activityName='" + activityName + '\'' + 157 | ", activityImage='" + activityImage + '\'' + 158 | ", activityContent='" + activityContent + '\'' + 159 | ", activityState=" + activityState + 160 | ", classId='" + classId + '\'' + 161 | ", className='" + className + '\'' + 162 | ", userId='" + userId + '\'' + 163 | ", userPhone='" + userPhone + '\'' + 164 | ", userName='" + userName + '\'' + 165 | ", userImage='" + userImage + '\'' + 166 | ", startTime='" + startTime + '\'' + 167 | ", pubTime='" + pubTime + '\'' + 168 | ", image='" + image + '\'' + 169 | ", personCount=" + personCount + 170 | ", punchTime='" + punchTime + '\'' + 171 | '}'; 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/vo/Apply.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.vo; 2 | 3 | import org.apache.ibatis.type.Alias; 4 | 5 | @Alias("apply") 6 | public class Apply { 7 | 8 | private long applyId; 9 | private Integer activityId; 10 | private String userId; 11 | private String image; 12 | private String punchTime; 13 | 14 | public long getApplyId() { 15 | return applyId; 16 | } 17 | 18 | public void setApplyId(long applyId) { 19 | this.applyId = applyId; 20 | } 21 | 22 | public Integer getActivityId() { 23 | return activityId; 24 | } 25 | 26 | public void setActivityId(Integer activityId) { 27 | this.activityId = activityId; 28 | } 29 | 30 | public String getUserId() { 31 | return userId; 32 | } 33 | 34 | public void setUserId(String userId) { 35 | this.userId = userId; 36 | } 37 | 38 | 39 | public String getImage() { 40 | return image; 41 | } 42 | 43 | public void setImage(String image) { 44 | this.image = image; 45 | } 46 | 47 | public String getPunchTime() { 48 | return punchTime; 49 | } 50 | 51 | public void setPunchTime(String punchTime) { 52 | this.punchTime = punchTime; 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return "Apply{" + 58 | "applyId=" + applyId + 59 | ", activityId=" + activityId + 60 | ", userId='" + userId + '\'' + 61 | ", image='" + image + '\'' + 62 | ", punchTime='" + punchTime + '\'' + 63 | '}'; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/vo/Classes.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.vo; 2 | 3 | import org.apache.ibatis.type.Alias; 4 | 5 | @Alias("classes") 6 | public class Classes { 7 | 8 | private String classId; 9 | private String className; 10 | 11 | 12 | public String getClassId() { 13 | return classId; 14 | } 15 | 16 | public void setClassId(String classId) { 17 | this.classId = classId; 18 | } 19 | 20 | 21 | public String getClassName() { 22 | return className; 23 | } 24 | 25 | public void setClassName(String className) { 26 | this.className = className; 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return "ClassController{" + 32 | "classId='" + classId + '\'' + 33 | ", className='" + className + '\'' + 34 | '}'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/vo/Student.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.vo; 2 | 3 | import org.apache.ibatis.type.Alias; 4 | 5 | @Alias("student") 6 | public class Student { 7 | 8 | private String studentId; 9 | private String studentName; 10 | private String studentImage; 11 | private String studentClass; 12 | 13 | 14 | public String getStudentId() { 15 | return studentId; 16 | } 17 | 18 | public void setStudentId(String studentId) { 19 | this.studentId = studentId; 20 | } 21 | 22 | 23 | public String getStudentName() { 24 | return studentName; 25 | } 26 | 27 | public void setStudentName(String studentName) { 28 | this.studentName = studentName; 29 | } 30 | 31 | 32 | public String getStudentImage() { 33 | return studentImage; 34 | } 35 | 36 | public void setStudentImage(String studentImage) { 37 | this.studentImage = studentImage; 38 | } 39 | 40 | 41 | public String getStudentClass() { 42 | return studentClass; 43 | } 44 | 45 | public void setStudentClass(String studentClass) { 46 | this.studentClass = studentClass; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "Student{" + 52 | "studentId='" + studentId + '\'' + 53 | ", studentName='" + studentName + '\'' + 54 | ", studentImage='" + studentImage + '\'' + 55 | ", studentClass='" + studentClass + '\'' + 56 | '}'; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/jinhui/classspirit/vo/User.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit.vo; 2 | 3 | import org.apache.ibatis.type.Alias; 4 | 5 | @Alias("user") 6 | public class User { 7 | 8 | private String userId; 9 | private String userPhone; 10 | private String userImage; 11 | private Integer userType; 12 | private String userName; 13 | private String studentId; 14 | private String classId; 15 | 16 | private String studentName; 17 | private String className; 18 | 19 | 20 | public String getUserId() { 21 | return userId; 22 | } 23 | 24 | public void setUserId(String userId) { 25 | this.userId = userId; 26 | } 27 | 28 | 29 | public String getUserPhone() { 30 | return userPhone; 31 | } 32 | 33 | public void setUserPhone(String userPhone) { 34 | this.userPhone = userPhone; 35 | } 36 | 37 | 38 | public String getUserImage() { 39 | return userImage; 40 | } 41 | 42 | public void setUserImage(String userImage) { 43 | this.userImage = userImage; 44 | } 45 | 46 | public Integer getUserType() { 47 | return userType; 48 | } 49 | 50 | public void setUserType(Integer userType) { 51 | this.userType = userType; 52 | } 53 | 54 | public String getUserName() { 55 | return userName; 56 | } 57 | 58 | public void setUserName(String userName) { 59 | this.userName = userName; 60 | } 61 | 62 | 63 | public String getStudentId() { 64 | return studentId; 65 | } 66 | 67 | public void setStudentId(String studentId) { 68 | this.studentId = studentId; 69 | } 70 | 71 | 72 | public String getClassId() { 73 | return classId; 74 | } 75 | 76 | public void setClassId(String classId) { 77 | this.classId = classId; 78 | } 79 | 80 | public String getStudentName() { 81 | return studentName; 82 | } 83 | 84 | public void setStudentName(String studentName) { 85 | this.studentName = studentName; 86 | } 87 | 88 | public String getClassName() { 89 | return className; 90 | } 91 | 92 | public void setClassName(String className) { 93 | this.className = className; 94 | } 95 | 96 | @Override 97 | public String toString() { 98 | return "User{" + 99 | "userId='" + userId + '\'' + 100 | ", userPhone='" + userPhone + '\'' + 101 | ", userImage='" + userImage + '\'' + 102 | ", userType=" + userType + 103 | ", userName='" + userName + '\'' + 104 | ", studentId='" + studentId + '\'' + 105 | ", classId='" + classId + '\'' + 106 | '}'; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | #数据库 2 | spring: 3 | datasource: 4 | url: jdbc:mysql://localhost:3306/classspirit?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8 5 | username: root 6 | password: 123456 7 | driver-class-name: com.mysql.jdbc.Driver 8 | # SpringBoot 2.1.x 新特性 9 | # driver-class-name: com.mysql.cj.jdbc.Driver 10 | 11 | http: 12 | encoding: 13 | #HTTP请求和响应的字符集 14 | charset: utf-8 15 | converters: 16 | #首选用于HTTP消息转换的JSON映射程序 17 | preferred-json-mapper: jackson 18 | servlet: 19 | multipart: 20 | #最大文件大小 21 | max-file-size: 10MB 22 | #应用程序名称 23 | application: 24 | name: classspirit 25 | 26 | mybatis: 27 | type-aliases-package: com.jinhui.classspirit.vo 28 | #mapper配置文件的位置 29 | mapper-locations: classpath:mapper/*Mapper.xml 30 | #myatbis配置文件的位置 31 | config-location: classpath:mybatis-conf.xml 32 | 33 | #log4j2 34 | logging: 35 | #日志记录配置文件的位置 36 | config: classpath:log4j2.xml 37 | #日志级别严重性映射 38 | level: 39 | root: info 40 | com.jinhui.classspirit: debug 41 | file: D:/debug/classspirit/classspirit.log 42 | 43 | #服务器 44 | server: 45 | # port: 8080 46 | servlet: 47 | session: 48 | #会话超时(以秒为单位) 49 | timeout: 3600s 50 | #应用程序的上下文路径 51 | context-path: /classspirit 52 | -------------------------------------------------------------------------------- /src/main/resources/classspirit.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : 5 | Source Server Version : 50544 6 | Source Host : 7 | Source Database : classspirit 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 50544 11 | File Encoding : 65001 12 | 13 | Date: 2019-01-10 10:17:40 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for activity 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `activity`; 22 | CREATE TABLE `activity` ( 23 | `activity_id` int(11) NOT NULL AUTO_INCREMENT, 24 | `activity_name` varchar(255) NOT NULL, 25 | `activity_image` varchar(255) NOT NULL, 26 | `activity_content` varchar(255) NOT NULL, 27 | `user_id` varchar(255) NOT NULL, 28 | `class_id` varchar(255) NOT NULL, 29 | `pub_time` varchar(255) NOT NULL, 30 | `start_time` varchar(255) NOT NULL, 31 | PRIMARY KEY (`activity_id`) 32 | ) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8; 33 | 34 | -- ---------------------------- 35 | -- Table structure for apply 36 | -- ---------------------------- 37 | DROP TABLE IF EXISTS `apply`; 38 | CREATE TABLE `apply` ( 39 | `apply_id` int(11) NOT NULL AUTO_INCREMENT, 40 | `activity_id` int(11) NOT NULL, 41 | `user_id` varchar(255) NOT NULL, 42 | `image` varchar(255) DEFAULT NULL, 43 | `punch_time` varchar(255) DEFAULT NULL, 44 | PRIMARY KEY (`apply_id`) 45 | ) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8; 46 | 47 | -- ---------------------------- 48 | -- Table structure for classes 49 | -- ---------------------------- 50 | DROP TABLE IF EXISTS `classes`; 51 | CREATE TABLE `classes` ( 52 | `class_id` varchar(255) NOT NULL, 53 | `class_name` varchar(255) NOT NULL, 54 | PRIMARY KEY (`class_id`) 55 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 56 | 57 | -- ---------------------------- 58 | -- Table structure for student 59 | -- ---------------------------- 60 | DROP TABLE IF EXISTS `student`; 61 | CREATE TABLE `student` ( 62 | `student_id` varchar(255) NOT NULL, 63 | `student_name` varchar(255) NOT NULL, 64 | `student_image` varchar(255) DEFAULT NULL, 65 | `student_class` varchar(255) NOT NULL, 66 | PRIMARY KEY (`student_id`) 67 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 68 | 69 | -- ---------------------------- 70 | -- Table structure for user 71 | -- ---------------------------- 72 | DROP TABLE IF EXISTS `user`; 73 | CREATE TABLE `user` ( 74 | `user_id` varchar(255) NOT NULL, 75 | `user_phone` varchar(20) DEFAULT NULL, 76 | `user_image` varchar(255) DEFAULT NULL, 77 | `user_type` varchar(2) NOT NULL, 78 | `user_name` varchar(255) DEFAULT NULL, 79 | `student_id` varchar(255) DEFAULT NULL, 80 | `class_id` varchar(255) DEFAULT NULL, 81 | PRIMARY KEY (`user_id`) 82 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 83 | -------------------------------------------------------------------------------- /src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss.SSS} |-%-5level [%thread] %c [%L] -| %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/main/resources/mapper/activityMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 51 | 52 | 105 | 106 | 107 | insert into activity(activity_name, activity_image, activity_content, user_id, class_id, pub_time, start_time) 108 | values 109 | (#{activityName},#{activityImage},#{activityContent},#{userId},#{classId},#{pubTime},#{startTime}) 110 | 111 | 112 | 117 | 118 | 128 | -------------------------------------------------------------------------------- /src/main/resources/mapper/applyMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 16 | 17 | 22 | 23 | 24 | insert into apply(activity_id, user_id, image, punch_time) 25 | VALUES 26 | (#{activityId},#{userId},#{image},#{punchTime}) 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/main/resources/mapper/classMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 15 | -------------------------------------------------------------------------------- /src/main/resources/mapper/studentMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11 | 12 | -------------------------------------------------------------------------------- /src/main/resources/mapper/userMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11 | 12 | 21 | 22 | 23 | UPDATE user 24 | 25 | 26 | user_phone = #{userPhone}, 27 | 28 | 29 | user_image = #{userImage}, 30 | 31 | 32 | user_type = #{userType}, 33 | 34 | 35 | user_name = #{userName}, 36 | 37 | 38 | student_id = #{studentId}, 39 | 40 | 41 | class_id = #{classId} 42 | 43 | 44 | WHERE user_id = #{userId} 45 | 46 | 47 | 48 | 51 | 52 | 53 | INSERT INTO user(user_id, user_image, user_type, user_name) 54 | VALUES(#{userId}, #{userImage}, #{userType}, #{userName}) 55 | 56 | 57 | 60 | -------------------------------------------------------------------------------- /src/main/resources/mybatis-conf.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 欢迎 6 | 7 | 8 |

Hello!

9 | 10 | -------------------------------------------------------------------------------- /src/test/java/com/jinhui/classspirit/ClassSpiritApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.jinhui.classspirit; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ClassSpiritApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | 18 | --------------------------------------------------------------------------------