修复订单、用户接口

master
zhiyong.ning 4 years ago
parent d1007821b2
commit 4f340c9456
  1. 11
      src/main/java/com/yipin/liuwanr/controller/OrderController.java
  2. 70
      src/main/java/com/yipin/liuwanr/controller/UserController.java
  3. 2
      src/main/java/com/yipin/liuwanr/mapper/OrderMapper.java
  4. 18
      src/main/java/com/yipin/liuwanr/mapper/UserMapper.java
  5. 11
      src/main/java/com/yipin/liuwanr/service/OrderService.java
  6. 44
      src/main/java/com/yipin/liuwanr/service/UserService.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<String, Object> 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("添加订单失败!");
}
}
}

@ -102,10 +102,40 @@ 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");
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<String, Object> ret1 = userService.queryPhone(phone);
int status1 = (int) ret1.get("retcode");
if (status1==200){
HashMap<String, Object> ret = userService.addUser(user);
int status = (int) ret.get("retcode");
if (200 == status) {
@ -115,6 +145,10 @@ public class UserController {
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<String, Object> 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;
}
}

@ -35,7 +35,7 @@ public interface OrderMapper {
//缺少个过期时间
"INSERT INTO hr_course_permissions(courseId,usePeriod,marketPrice,transactionPrice,discount,portAddressId,isDeliverGoods,isdel,orderId) VALUES"
+ "<foreach collection = 'coursePermissionss' item='c' separator=','>"
+ " (#{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})"
+ "</foreach>",
"</script> "})
void addCoursePermissionss(@Param("coursePermissionss")List<CoursePermissions> coursePermissionss);

@ -126,7 +126,7 @@ public interface UserMapper {
" <if test='month==9'>and u.creationTime>DATE_SUB(CURDATE(), INTERVAL 9 MONTH)</if>",
" <if test='month==12'>and u.creationTime>DATE_SUB(CURDATE(), INTERVAL 12 MONTH)</if>",
" <if test='creationTime!=null and endTime!=null and endTime!=\"\" and creationTime!=\"\" '> and u.creationTime between #{creationTime} and #{endTime}</if>",
"GROUP BY u.creationTime desc",
"GROUP BY u.userId order by u.creationTime desc",
"</script> "})
List<UserM> queryUser(UserM user);
@ -147,6 +147,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({"<script>",
"SELECT u.*,d.disciplineName,p.professionalName,pc.professionalClassName,schoolName from user u,discipline d,professional p,professional_class pc,school s where u.isdel = 0 and u.disciplineId = d.disciplineId and u.professionalId = p.professionalId and u.professionalClassId = pc.professionalClassId and u.schoolId = s.schoolId and u.userId = #{userId}",
"</script> "})
@ -166,6 +169,19 @@ public interface UserMapper {
})
void addUserM(@Param("users")List<UserM> 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);
}

@ -28,9 +28,13 @@ public class OrderService {
@Autowired
private OrderMapper orderMapper;
//添加合同信息
public HashMap<String, Object> addOrder(Order order){
HashMap<String, Object> resp = new HashMap<String, Object>();
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<String, Object> addContractInformation(ContractInformation contractInformation){
HashMap<String, Object> resp = new HashMap<String, Object>();
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;

@ -101,6 +101,25 @@ public class UserService {
return result;
}
public HashMap<String, Object> queryPhone(String phone) {
HashMap<String, Object> resp = new HashMap<String, Object>();
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<String, Object> addUser(UserM user){
HashMap<String, Object> resp = new HashMap<String, Object>();
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) {
@ -234,4 +251,27 @@ public class UserService {
return resp;
}
//更新登录次数和时间
public HashMap<String, Object> updateLogInNumber(UserM user){
HashMap<String, Object> resp = new HashMap<String, Object>();
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;
}
}

Loading…
Cancel
Save