diff --git a/src/main/java/com/yipin/liuwanr/controller/OrderController.java b/src/main/java/com/yipin/liuwanr/controller/OrderController.java index 19ab635..684dfe4 100644 --- a/src/main/java/com/yipin/liuwanr/controller/OrderController.java +++ b/src/main/java/com/yipin/liuwanr/controller/OrderController.java @@ -40,15 +40,12 @@ public class OrderController { @Transactional @PostMapping("/addOrder") public Response addOrder(@RequestBody OrderVo vo) throws Exception { - long timeStamp = new Date().getTime();//获取时间戳 - String orderNumber = String.valueOf(timeStamp);//long转String - vo.getOrder().setOrderNumber(orderNumber); Response resp = new Response(); Order order = vo.getOrder(); ContractInformation contractInformation = vo.getContractInformation(); if (vo.getOrder().getCityId() == null) { resp.setStatus(300); - resp.setErrmessage("Parameter Invalid"); + resp.setErrmessage("参数为空!"); } else { HashMap ret = orderService.addOrder(order); Integer orderId = (Integer) ret.get("orderId"); @@ -78,17 +75,17 @@ public class OrderController { }else { resp.setStatus(status2); resp.setErrmessage(ret2.get("retvalue").toString()); - throw new Exception(); + throw new Exception("添加课程权限失败!"); } }else { resp.setStatus(status1); resp.setErrmessage(ret1.get("retvalue").toString()); - throw new Exception(); + throw new Exception("添加合同信息失败!"); } } else { resp.setStatus(status); resp.setErrmessage(ret.get("retvalue").toString()); - throw new Exception(); + throw new Exception("添加订单失败!"); } } } diff --git a/src/main/java/com/yipin/liuwanr/controller/UserController.java b/src/main/java/com/yipin/liuwanr/controller/UserController.java index 9928e73..7e7e610 100644 --- a/src/main/java/com/yipin/liuwanr/controller/UserController.java +++ b/src/main/java/com/yipin/liuwanr/controller/UserController.java @@ -102,18 +102,52 @@ public class UserController { @PostMapping("/addUser") Response addUser(@RequestBody UserM user) { Response resp = new Response(); - if (user.getCityId()==null) {//城市是否为空 + //用户手机号 + String phone = user.getPhone(); + //用户名称 + String name = user.getName(); + //省份id + Integer provinceId = user.getProvinceId(); + //用户角色id + Integer accountRole = user.getAccountRole(); + //城市id + Integer cityId = user.getCityId(); + //学校id + Integer schoolId = user.getSchoolId(); + if (phone==null||phone=="") { resp.setStatus(300); - resp.setErrmessage("Parameter Invalid"); - } else { - HashMap ret = userService.addUser(user); - int status = (int) ret.get("retcode"); - if (200 == status) { - resp.setStatus(status); - resp.setMessage(ret.get("retvalue")); - } else { - resp.setStatus(status); - resp.setErrmessage(ret.get("retvalue").toString()); + resp.setErrmessage("电话不能为空!"); + }else if(name==null||name==""){ + resp.setStatus(300); + resp.setErrmessage("姓名不能为空!"); + }else if(provinceId==null){ + resp.setStatus(300); + resp.setErrmessage("省份不能为空!"); + }else if(accountRole==null){ + resp.setStatus(300); + resp.setErrmessage("用户角色不能为空!"); + }else if(cityId==null){ + resp.setStatus(300); + resp.setErrmessage("城市不能为空!"); + }else if(schoolId==null){ + resp.setStatus(300); + resp.setErrmessage("学校不能为空!"); + }else { + HashMap ret1 = userService.queryPhone(phone); + int status1 = (int) ret1.get("retcode"); + if (status1==200){ + HashMap ret = userService.addUser(user); + int status = (int) ret.get("retcode"); + if (200 == status) { + resp.setStatus(status); + resp.setMessage(ret.get("retvalue")); + } else { + resp.setStatus(status); + resp.setErrmessage(ret.get("retvalue").toString()); + } + }else{ + resp.setStatus(status1); + resp.setErrmessage(ret1.get("retvalue").toString()); } } return resp; @@ -292,4 +326,36 @@ public class UserController { } return resp; } + + /** + * 更新登录次数和时间 + */ + @PostMapping("/updateLogInNumber") + Response updateLogInNumber(@RequestBody UserM user) { + Response resp = new Response(); + Integer userId = user.getUserId(); + String phone = user.getPhone(); + Integer accountRole = user.getAccountRole(); + 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 ret = userService.updateLogInNumber(user); + int status = (int) ret.get("retcode"); + if (200 == status) { + resp.setStatus(status); + resp.setMessage(ret.get("retvalue")); + } else { + resp.setStatus(status); + resp.setErrmessage(ret.get("retvalue").toString()); + } + } + return resp; + } } diff --git a/src/main/java/com/yipin/liuwanr/mapper/OrderMapper.java b/src/main/java/com/yipin/liuwanr/mapper/OrderMapper.java index f8b2ffa..11cd13e 100644 --- a/src/main/java/com/yipin/liuwanr/mapper/OrderMapper.java +++ b/src/main/java/com/yipin/liuwanr/mapper/OrderMapper.java @@ -35,7 +35,7 @@ public interface OrderMapper { //缺少个过期时间 "INSERT INTO hr_course_permissions(courseId,usePeriod,marketPrice,transactionPrice,discount,portAddressId,isDeliverGoods,isdel,orderId) VALUES" + "" - + " (#{c.courseId},#{c.usePeriod},#{c.marketPrice},#{c.transactionPrice},#{c.discount},#{c.portAddressId},#{c.isDeliverGoods},0,#{c.orderId},#{c.expirationTime})" + + " (#{c.courseId},#{c.usePeriod},#{c.marketPrice},#{c.transactionPrice},#{c.discount},#{c.portAddressId},#{c.isDeliverGoods},0,#{c.orderId})" + "", " "}) void addCoursePermissionss(@Param("coursePermissionss")List coursePermissionss); diff --git a/src/main/java/com/yipin/liuwanr/mapper/UserMapper.java b/src/main/java/com/yipin/liuwanr/mapper/UserMapper.java index 1bd4dcc..d9ec9cb 100644 --- a/src/main/java/com/yipin/liuwanr/mapper/UserMapper.java +++ b/src/main/java/com/yipin/liuwanr/mapper/UserMapper.java @@ -126,7 +126,7 @@ public interface UserMapper { " and u.creationTime>DATE_SUB(CURDATE(), INTERVAL 9 MONTH)", " and u.creationTime>DATE_SUB(CURDATE(), INTERVAL 12 MONTH)", " and u.creationTime between #{creationTime} and #{endTime}", - "GROUP BY u.creationTime desc", + "GROUP BY u.userId order by u.creationTime desc", " "}) List queryUser(UserM user); @@ -146,6 +146,9 @@ public interface UserMapper { @Select("SELECT u.* from user u where isdel=0 and phone = #{phone} and password = #{password}") UserM logins(UserM user); + + @Select("SELECT u.* from user u where isdel=0 and phone = #{phone}") + UserM queryPhone(String phone); @Select({"" }) void addUserM(@Param("users")List users); - + + //修改用户头像 @Update("update user set userAvatars=#{userAvatars} where userId=#{userId}") 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 student SET logInNumber=logInNumber+1, lastLoginTime=now() WHERE phone=#{phone}"}) + void updateStudentLogInNumber(UserM user); + + //更新用户登录次数和最后一次登录时间 + @Update({ "UPDATE staff SET logNumber=logNumber+1, lastTimeOfLanding=now() WHERE phone=#{phone}"}) + void updateStaffLogInNumber(UserM user); } \ No newline at end of file diff --git a/src/main/java/com/yipin/liuwanr/service/OrderService.java b/src/main/java/com/yipin/liuwanr/service/OrderService.java index dd5614b..fe7c1a5 100644 --- a/src/main/java/com/yipin/liuwanr/service/OrderService.java +++ b/src/main/java/com/yipin/liuwanr/service/OrderService.java @@ -28,9 +28,13 @@ public class OrderService { @Autowired private OrderMapper orderMapper; + //添加合同信息 public HashMap addOrder(Order order){ HashMap resp = new HashMap(); try { + long timeStamp = new Date().getTime();//获取时间戳 + String orderNumber = String.valueOf(timeStamp);//long转String + order.setOrderNumber(orderNumber); orderMapper.addOrder(order); resp.put("orderId", order.getOrderId()); resp.put("retcode", 200); @@ -38,12 +42,11 @@ public class OrderService { } catch (RuntimeException e) { logger.error(e.getMessage()); resp.put("retcode", 500); - resp.put("retvalue", "Inquiry Failed"); + resp.put("retvalue", "添加订单失败!"); return resp; } return resp; } - //添加合同信息 public HashMap addContractInformation(ContractInformation contractInformation){ HashMap resp = new HashMap(); try { @@ -52,7 +55,7 @@ public class OrderService { } catch (RuntimeException e) { logger.error(e.getMessage()); resp.put("retcode", 500); - resp.put("retvalue", "Inquiry Failed"); + resp.put("retvalue", "添加信息合同失败!"); return resp; } return resp; @@ -80,7 +83,7 @@ public class OrderService { } catch (RuntimeException e) { logger.error(e.getMessage()); resp.put("retcode", 500); - resp.put("retvalue", "Inquiry Failed"); + resp.put("retvalue", "添加课程权限失败!"); return resp; } return resp; diff --git a/src/main/java/com/yipin/liuwanr/service/UserService.java b/src/main/java/com/yipin/liuwanr/service/UserService.java index 51311c3..d3e956f 100644 --- a/src/main/java/com/yipin/liuwanr/service/UserService.java +++ b/src/main/java/com/yipin/liuwanr/service/UserService.java @@ -100,7 +100,26 @@ public class UserService { } return result; } - + + public HashMap queryPhone(String phone) { + HashMap resp = new HashMap(); + try { + resp.put("retvalue", userMapper.queryPhone(phone)); + if (resp.get("retvalue")==null) { + resp.put("retcode", 200); + }else { + resp.put("retcode", 300); + resp.put("retvalue", "新增失败,账号已存在!"); + } + } catch (RuntimeException e) { + logger.error(e.getMessage()); + resp.put("retcode", 500); + resp.put("retvalue", "Inquiry Failed"); + return resp; + } + return resp; + } + public HashMap addUser(UserM user){ HashMap resp = new HashMap(); try { @@ -221,8 +240,6 @@ public class UserService { //用户图片路径 String userAvatars=result.getFileUrl(); userMapper.updateUserAvatars(userAvatars,userId); - - resp.put("retcode", 200); resp.put("retvalue", userAvatars); } catch (Exception e) { @@ -233,5 +250,28 @@ public class UserService { } return resp; } - + + //更新登录次数和时间 + public HashMap updateLogInNumber(UserM user){ + HashMap resp = new HashMap(); + try { + Integer accountRole = user.getAccountRole(); + userMapper.updateLogInNumber(user); + if (accountRole==3){ + //更新员工登录次数和时间 + userMapper.updateStaffLogInNumber(user); + } + if (accountRole==4){ + //更新学生登录次数和时间 + userMapper.updateStudentLogInNumber(user); + } + resp.put("retcode", 200); + } catch (RuntimeException e) { + logger.error(e.getMessage()); + resp.put("retcode", 500); + resp.put("retvalue", "更新登录次数失败!"); + return resp; + } + return resp; + } }