上传代码

master
zhiyong.ning 4 years ago
parent 06f3fc8507
commit 6eebe5f946
  1. 108
      src/main/java/com/yipin/liuwanr/JwtUtils.java
  2. 12
      src/main/java/com/yipin/liuwanr/controller/CityController.java
  3. 6
      src/main/java/com/yipin/liuwanr/controller/UserController.java
  4. 25
      src/main/java/com/yipin/liuwanr/controller/UserInfoController.java
  5. 8
      src/main/java/com/yipin/liuwanr/entity/Class.java
  6. 6
      src/main/java/com/yipin/liuwanr/entity/Grade.java
  7. 4
      src/main/java/com/yipin/liuwanr/entity/StudentCity.java
  8. 4
      src/main/java/com/yipin/liuwanr/mapper/AssesmentMapper.java
  9. 13
      src/main/java/com/yipin/liuwanr/mapper/CityMapper.java
  10. 4
      src/main/java/com/yipin/liuwanr/mapper/ClassMapper.java
  11. 2
      src/main/java/com/yipin/liuwanr/mapper/CourseMapper.java
  12. 6
      src/main/java/com/yipin/liuwanr/mapper/StuProfessionalArchitectureMapper.java
  13. 4
      src/main/java/com/yipin/liuwanr/mapper/UserInfoMapper.java
  14. 4
      src/main/java/com/yipin/liuwanr/mapper/UserMapper.java
  15. 5
      src/main/java/com/yipin/liuwanr/service/AssesmentService.java
  16. 10
      src/main/java/com/yipin/liuwanr/service/CityService.java
  17. 25
      src/main/java/com/yipin/liuwanr/service/UserInfoService.java
  18. 16
      src/test/java/com/yipin/liuwanr/CityServiceTest.java
  19. 4
      src/test/java/com/yipin/liuwanr/ClassServiceTest.java

@ -0,0 +1,108 @@
//package com.yipin.liuwanr;
//
//
//import com.alibaba.fastjson.JSONObject;
//import com.sun.org.apache.xml.internal.security.algorithms.SignatureAlgorithm;
//import io.jsonwebtoken.Claims;
//import io.jsonwebtoken.ExpiredJwtException;
//import io.jsonwebtoken.JwtBuilder;
//import io.jsonwebtoken.Jwts;
//import io.jsonwebtoken.SignatureAlgorithm;
//import org.apache.commons.codec.binary.Base64;
//
//import javax.crypto.SecretKey;
//import javax.crypto.spec.SecretKeySpec;
//import java.security.SignatureException;
//import java.util.Date;
//
//public class JwtUtils {
// /**
// * 签发JWT
// *
// * @param id
// * @param subject 可以是JSON数据 尽可能少
// * @param ttlMillis
// * @return String
// *
// */
// public static String createJWT(String id, String subject, long ttlMillis) {
// ttlMillis = ttlMillis * 1000;
// SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
// long nowMillis = System.currentTimeMillis();
// Date now = new Date(nowMillis);
// SecretKey secretKey = generalKey();
// JwtBuilder builder = Jwts.builder().setId(String.valueOf(id)).setSubject(subject) // 主题
// .setIssuer("user") // 签发者
// .setIssuedAt(now) // 签发时间
// .signWith(signatureAlgorithm, secretKey); // 签名算法以及密匙
// if (ttlMillis >= 0) {
// long expMillis = nowMillis + ttlMillis;
// Date expDate = new Date(expMillis);
// builder.setExpiration(expDate); // 过期时间
// }
// return builder.compact();
// }
//
// public static void main(String[] args) {
// //System.out.printf(createJWT("1","111", 10000000));
// boolean isTrue = validateJWT("eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIxIiwic3ViIjoiMTExIiwiaXNzIjoidXNlciIsImlhdCI6MTYwMTM0MzYyNywiZXhwIjoxNjAxMzUzNjI3fQ.q5Ssg2LM1OzzgvVWqLhgP_Hko0-pfeNO5bvpUE5KQ-s");
// System.out.println(isTrue);
// }
//
// /**
// * 验证JWT
// *
// * @param jwtStr
// * @return
// */
// public static Boolean validateJWT(String jwtStr) {
// //boolean isValidate = false;
// Claims claims = null;
// try {
// claims = parseJWT(jwtStr);
// return true;
// } catch (ExpiredJwtException e) {
// return false;
// } catch (SignatureException e) {
// return false;
// } catch (Exception e) {
// return false;
// }
// //return checkResult;
// }
//
// public static SecretKey generalKey() {
// byte[] encodedKey = Base64.decodeBase64("DQJWT");
// SecretKey key = new SecretKeySpec(encodedKey, 0, encodedKey.length, "AES");
// return key;
// }
//
// /**
// *
// * 解析JWT字符串
// *
// * @param jwt
// * @return
// * @throws Exception
// */
// public static Claims parseJWT(String jwt) throws Exception {
// SecretKey secretKey = generalKey();
// return Jwts.parser().setSigningKey(secretKey).parseClaimsJws(jwt).getBody();
// }
//
// public static void putTokenToRedis(Long userId, String token, long times) {
// RedisUtil.setEx("dq:token:"+token, String.valueOf(userId), times);
// }
//
// public static <UserEntity> void putUserEntityToRedis(Long userId, UserEntity userEntity, long times) {
// RedisUtil.setEx("dq:userId:"+userId, JSONObject.toJSONString(userEntity), times);
// }
//
// public static void removeUserEntityByUserId(Long userId) {
// RedisUtil.del("dq:userId:"+userId);
// }
//
// public static void removeTokenByToken(String token) {
// RedisUtil.del("dq:token:"+token);
// }
//}

@ -2,6 +2,7 @@ package com.yipin.liuwanr.controller;
import java.util.HashMap;
import com.yipin.liuwanr.entity.StudentCity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
@ -12,7 +13,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.yipin.liuwanr.entity.City;
import com.yipin.liuwanr.entity.Response;
import com.yipin.liuwanr.helper.RedisHelper;
import com.yipin.liuwanr.service.CityService;
@ -32,9 +32,9 @@ public class CityController {
* 添加城市
*/
@PostMapping("/addCity")
Response addCustomer(@RequestBody City city) {
Response addCustomer(@RequestBody StudentCity studentCity) {
Response resp = new Response();
HashMap<String, Object> ret = cityService.addCity(city);
HashMap<String, Object> ret = cityService.addCity(studentCity);
int status = (int) ret.get("retcode");
if (200 == status) {
resp.setStatus(status);
@ -91,13 +91,13 @@ public class CityController {
* 更新城市
*/
@RequestMapping(value="/updateCity",method = RequestMethod.POST)
Response updateCity(@RequestBody City city) {
Response updateCity(@RequestBody StudentCity studentCity) {
Response resp = new Response();
if (city==null) {
if (studentCity ==null) {
resp.setStatus(300);
resp.setErrmessage("Parameter Invalid");
} else {
HashMap<String, Object> ret = cityService.updateCity(city);
HashMap<String, Object> ret = cityService.updateCity(studentCity);
int status = (int) ret.get("retcode");
if (200 == status) {
resp.setStatus(status);

@ -459,14 +459,14 @@ public class UserController {
Response updateLogInNumber(@RequestBody UserM user) {
Response resp = new Response();
Integer userId = user.getUserId();
String phone = user.getPhone();
String account = user.getUserAccount();
Integer accountRole = user.getAccountRole();
if (userId==null) {
resp.setStatus(300);
resp.setErrmessage("用户id不能为空!");
}else if(phone==null||phone==""){
}else if(account==null||account==""){
resp.setStatus(300);
resp.setErrmessage("用户电话不能为空!");
resp.setErrmessage("用户账号不能为空!");
} else if(accountRole==null){
resp.setStatus(300);
resp.setErrmessage("用户角色不能为空!");

@ -521,22 +521,23 @@ public class UserInfoController {
* 更新登录次数和时间
*/
@PostMapping("/updateLogInNumber")
Response updateLogInNumber(@RequestBody UserM user) {
Response updateLogInNumber(@RequestBody UserInfo userInfo) {
Response resp = new Response();
Integer userId = user.getUserId();
String phone = user.getPhone();
Integer accountRole = user.getAccountRole();
Integer userId = userInfo.getUserId();
String phone = userInfo.getPhone();
String roleId = userInfo.getRoleId();
if (userId==null) {
resp.setStatus(300);
resp.setErrmessage("用户id不能为空!");
}else if(phone==null||phone==""){
resp.setStatus(300);
resp.setErrmessage("用户电话不能为空!");
} else if(accountRole==null){
resp.setStatus(300);
resp.setErrmessage("用户角色不能为空!");
} else {
HashMap<String, Object> ret = userInfoService.updateLogInNumber(user);
// }else if(phone==null||phone==""){
// resp.setStatus(300);
// resp.setErrmessage("用户电话不能为空!");
// } else if(accountRole==null){
// resp.setStatus(300);
// resp.setErrmessage("用户角色不能为空!");
}
else {
HashMap<String, Object> ret = userInfoService.updateLogInNumber(userInfo);
int status = (int) ret.get("retcode");
if (200 == status) {
resp.setStatus(status);

@ -2,11 +2,11 @@ package com.yipin.liuwanr.entity;
/**
* 班级
*
* @author 全承珠
*
* @author Ning
*
*/
public class SutdentClass {
public class Class {
private Integer classId;
private String className;
@ -38,7 +38,7 @@ public class SutdentClass {
@Override
public String toString() {
return "SutdentClass{" +
return "Class{" +
"classId=" + classId +
", className='" + className + '\'' +
", gradeId=" + gradeId +

@ -14,13 +14,13 @@ public class Grade {
private String gradeName;
private Integer professionalArchitectureId;
private List<ExperimentalClass> experimentalClass;
private List<SutdentClass> classes;
private List<Class> classes;
public List<SutdentClass> getClasses() {
public List<Class> getClasses() {
return classes;
}
public void setClasses(List<SutdentClass> classes) {
public void setClasses(List<Class> classes) {
this.classes = classes;
}

@ -1,6 +1,6 @@
package com.yipin.liuwanr.entity;
public class City {
public class StudentCity {
//城市主键ID
private Integer cityId;
@ -29,7 +29,7 @@ public class City {
@Override
public String toString() {
return "City{" +
return "StudentCity{" +
"cityId=" + cityId +
", cityName='" + cityName + '\'' +
", provinceId=" + provinceId +

@ -1,9 +1,9 @@
package com.yipin.liuwanr.mapper;
import java.util.HashMap;
import java.util.List;
import com.yipin.liuwanr.entity.*;
import com.yipin.liuwanr.entity.Class;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Many;
@ -233,7 +233,7 @@ public interface AssesmentMapper {
* @return
*/
@Select("SELECT c.classId as classId,c.className as className from assessment ass left join class c on FIND_IN_SET(c.classId,ass.classId) where ass.id=#{assesmentId}")
List<SutdentClass> queryClass(Integer assesmentId);
List<Class> queryClass(Integer assesmentId);
//s.isdel=0 and
@Select("select s.studentId,studentName from student s left join experimental_class_student ecs on s.studentId=ecs.studentId where ecs.experimentalClassId=#{experimentalClassId} ")

@ -2,26 +2,25 @@ package com.yipin.liuwanr.mapper;
import java.util.List;
import com.yipin.liuwanr.entity.StudentCity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import com.yipin.liuwanr.entity.City;
public interface CityMapper {
@Insert("INSERT INTO city(cityName,provinceId,isdel)"
@Insert("INSERT INTO studentCity(cityName,provinceId,isdel)"
+ "VALUES(#{cityName},#{provinceId},0)")
void addCity(City city);
void addCity(StudentCity studentCity);
@Select({"<script>",
"SELECT cityId,cityName,provinceId from city where isdel = 0 and provinceId=#{provinceId} order by cityId ",
"</script> "})
List<City> queryCity(Integer provinceId);
List<StudentCity> queryCity(Integer provinceId);
@Update("UPDATE city SET isdel = 1 where cityId = #{cityId}")
void deleteCity(Integer cityId);
@Update("UPDATE city SET cityName = #{cityName} where cityId = #{cityId}")
void updateCity(City city);
@Update("UPDATE studentCity SET cityName = #{cityName} where cityId = #{cityId}")
void updateCity(StudentCity studentCity);
}

@ -2,9 +2,9 @@ package com.yipin.liuwanr.mapper;
import java.util.List;
import com.yipin.liuwanr.entity.Class;
import org.apache.ibatis.annotations.Select;
import com.yipin.liuwanr.entity.SutdentClass;
/**
*
*
@ -14,5 +14,5 @@ import com.yipin.liuwanr.entity.SutdentClass;
public interface ClassMapper {
@Select("select classId,className from class where className like concat(#{className},'%') ")
List<SutdentClass> queryGetByClassName(String className);
List<Class> queryGetByClassName(String className);
}

@ -58,7 +58,7 @@ public interface CourseMapper {
" <if test='professionalClassId!=null'>and c.professionalClassId = #{professionalClassId} </if>",
" <if test='professionalId!=null'>and c.professionalId = #{professionalId} </if>",
" <if test='searchContent!=null'> and c.courseName like CONCAT('%',#{searchContent},'%')</if>",
"GROUP BY courseId",
"GROUP BY c.courseId",
"order by c.creationTime desc",
"</script> "})
List<Course> queryCourse(Course course);

@ -2,6 +2,7 @@ package com.yipin.liuwanr.mapper;
import java.util.List;
import com.yipin.liuwanr.entity.Class;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
@ -10,7 +11,6 @@ import org.apache.ibatis.annotations.Update;
import com.yipin.liuwanr.entity.Grade;
import com.yipin.liuwanr.entity.StuProfessionalArchitecture;
import com.yipin.liuwanr.entity.Student;
import com.yipin.liuwanr.entity.SutdentClass;
public interface StuProfessionalArchitectureMapper {
@ -55,12 +55,12 @@ public interface StuProfessionalArchitectureMapper {
@Select({"<script>",
"SELECT classId,className from class where gradeId = #{gradeId} and isdel = 0",
"</script> "})
List<SutdentClass> queryStuClass(Integer gradeId);
List<Class> queryStuClass(Integer gradeId);
@Select({"<script>",
"SELECT classId,className from class where classId = #{classId}",
"</script> "})
List<SutdentClass> queryStuClassD(Integer classId);
List<Class> queryStuClassD(Integer classId);
@Insert("INSERT INTO class(className,gradeId)"
+ "VALUES(#{className},#{gradeId})")

@ -262,8 +262,8 @@ public interface UserInfoMapper {
void updateUserAvatars(@Param("userAvatars") String userAvatars, @Param("userId") Integer userId);
//更新用户登录次数和最后一次登录时间
@Update({"UPDATE user SET logInNumber=logInNumber+1, lastTimeOfLanding=now() WHERE userId=#{userId}"})
void updateLogInNumber(UserM user);
@Update({"UPDATE hr_user_info SET logInNumber=logInNumber+1, lastLoginTime=now() WHERE userId=#{userId}"})
void updateLogInNumber(UserInfo userInfo);
//更新学生登录次数和最后一次登录时间
@Update({"UPDATE student SET logInNumber=logInNumber+1, lastLoginTime=now() WHERE phone=#{phone}"})

@ -263,11 +263,11 @@ public interface UserMapper {
void updateLogInNumber(UserM user);
//更新用户登录次数和最后一次登录时间
@Update({ "UPDATE student SET logInNumber=logInNumber+1, lastLoginTime=now() WHERE phone=#{phone}"})
@Update({ "UPDATE student SET logInNumber=logInNumber+1, lastLoginTime=now() WHERE userId=#{userId}"})
void updateStudentLogInNumber(UserM user);
//更新用户登录次数和最后一次登录时间
@Update({ "UPDATE staff SET logNumber=logNumber+1, lastTimeOfLanding=now() WHERE phone=#{phone}"})
@Update({ "UPDATE staff SET logNumber=logNumber+1, lastTimeOfLanding=now() WHERE userId=#{userId}"})
void updateStaffLogInNumber(UserM user);
//查询账号是否存在

@ -19,10 +19,9 @@ import com.yipin.liuwanr.entity.PointRecord;
import com.yipin.liuwanr.entity.Record;
import com.yipin.liuwanr.entity.Score;
import com.yipin.liuwanr.entity.Student;
import com.yipin.liuwanr.entity.SutdentClass;
import com.yipin.liuwanr.entity.Class;
import com.yipin.liuwanr.helper.AssesmentHelper;
import com.yipin.liuwanr.mapper.AssesmentMapper;
import com.yipin.liuwanr.vo.AssesmentStudentVo;
@Service
public class AssesmentService {
@ -383,7 +382,7 @@ public class AssesmentService {
HashMap<String, Object> obj = new HashMap<String, Object>();
try {
List<ExperimentalClass> experimentalClasses = mapper.queryExperimental(assesmentId);
List<SutdentClass> classes = mapper.queryClass(assesmentId);
List<Class> classes = mapper.queryClass(assesmentId);
obj.put("experimentalClass", experimentalClasses);
obj.put("class", classes);

@ -2,11 +2,11 @@ package com.yipin.liuwanr.service;
import java.util.HashMap;
import com.yipin.liuwanr.entity.StudentCity;
import org.jboss.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yipin.liuwanr.entity.City;
import com.yipin.liuwanr.mapper.CityMapper;
@Service
@ -17,10 +17,10 @@ public class CityService {
@Autowired
private CityMapper cityMapper;
public HashMap<String, Object> addCity(City city){
public HashMap<String, Object> addCity(StudentCity studentCity){
HashMap<String, Object> resp = new HashMap<String, Object>();
try {
cityMapper.addCity(city);
cityMapper.addCity(studentCity);
resp.put("retcode", 200);
} catch (RuntimeException e) {
logger.error(e.getMessage());
@ -60,10 +60,10 @@ public class CityService {
return resp;
}
public HashMap<String, Object> updateCity(City city){
public HashMap<String, Object> updateCity(StudentCity studentCity){
HashMap<String, Object> resp = new HashMap<String, Object>();
try {
cityMapper.updateCity(city);
cityMapper.updateCity(studentCity);
resp.put("retcode", 200);
} catch (RuntimeException e) {
logger.error(e.getMessage());

@ -449,7 +449,8 @@ public class UserInfoService {
List<Student> studentList = userInfoMapper.queryStudentAll(id,roleId,schoolId);
obj.put("studentList",studentList);
ValueOperations<String, String> redis = stringRedisTemplate.opsForValue();
redis.set(token,userId+"", 30 * 60, TimeUnit.SECONDS);
//设置token 1小时候过期
redis.set(token,userId+"", 1, TimeUnit.HOURS);
resp.put("retcode", 200);
resp.put("retvalue", obj);
}else {
@ -611,19 +612,19 @@ public class UserInfoService {
}
//更新登录次数和时间
public HashMap<String, Object> updateLogInNumber(UserM user){
public HashMap<String, Object> updateLogInNumber(UserInfo userInfo){
HashMap<String, Object> resp = new HashMap<String, Object>();
try {
Integer accountRole = user.getAccountRole();
userInfoMapper.updateLogInNumber(user);
if (accountRole==3){
//更新员工登录次数和时间
userInfoMapper.updateStaffLogInNumber(user);
}
if (accountRole==4){
//更新学生登录次数和时间
userInfoMapper.updateStudentLogInNumber(user);
}
// Integer accountRole = user.getAccountRole();
userInfoMapper.updateLogInNumber(userInfo);
// if (accountRole==3){
// //更新员工登录次数和时间
// userInfoMapper.updateStaffLogInNumber(user);
// }
// if (accountRole==4){
// //更新学生登录次数和时间
// userInfoMapper.updateStudentLogInNumber(user);
// }
resp.put("retcode", 200);
} catch (RuntimeException e) {
logger.error(e.getMessage());

@ -1,6 +1,6 @@
package com.yipin.liuwanr;
import com.yipin.liuwanr.entity.City;
import com.yipin.liuwanr.entity.StudentCity;
import com.yipin.liuwanr.mapper.CityMapper;
import com.yipin.liuwanr.service.CityService;
import org.junit.Test;
@ -29,7 +29,7 @@ public class CityServiceTest {
/*@Test
@Transactional
public void testAddCity() {
City city = new City();
StudentCity city = new StudentCity();
city.setCityName("hhhh");
city.setProvinceId(2);
HashMap<String, Object> map = cityService.addCity(city);
@ -45,7 +45,7 @@ public class CityServiceTest {
Integer retcode = (Integer) map.get("retcode");
System.out.println(retcode);
if (retcode == 200) {
List<City> cities = (List<City>) map.get("retvalue");
List<StudentCity> cities = (List<StudentCity>) map.get("retvalue");
cities.forEach(item -> {
System.out.println(item.toString());
});
@ -71,11 +71,11 @@ public class CityServiceTest {
@Test
@Transactional
public void testUpdateCity() {
City city = new City();
city.setCityId(1);
city.setCityName("hhhh");
city.setProvinceId(2);
HashMap<String, Object> map = cityService.updateCity(city);
StudentCity studentCity = new StudentCity();
studentCity.setCityId(1);
studentCity.setCityName("hhhh");
studentCity.setProvinceId(2);
HashMap<String, Object> map = cityService.updateCity(studentCity);
map.forEach((key, value) -> System.out.println("key = " + key + " ===> value = " + value.toString()));
}
}

@ -1,6 +1,6 @@
package com.yipin.liuwanr;
import com.yipin.liuwanr.entity.SutdentClass;
import com.yipin.liuwanr.entity.Class;
import com.yipin.liuwanr.service.ClassService;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -24,7 +24,7 @@ public class ClassServiceTest {
Integer retcode = (Integer) map.get("retcode");
System.out.println(retcode);
if (retcode == 200) {
List<SutdentClass> classes = (List<SutdentClass>) map.get("retvalue");
List<Class> classes = (List<Class>) map.get("retvalue");
classes.forEach(item -> {
System.out.println(item.toString());
});

Loading…
Cancel
Save