package com.lyd.bikeController;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.lyd.bikeEntity.Bike;
import com.lyd.bikeEntity.Record;
import com.lyd.bikeEntity.User;
import com.lyd.bikeServiceDao.AdminServiceDao;
import com.lyd.bikeServiceDao.BikeServiceDao;
@Controller
public class UserBikeController {
//定义全局的静态标识
public static final String USER_PAY_SUCCESS="ok";
public static final String USER_PAY_FINAL="no";
public static final String USER_PAY_ONE="10元";
public static final String USER_PAY_TWO="20元";
public static final String USER_PAY_FIVE="50元";
public static final String USER_PAY_TEN="100元";
public static final String USER_PAY_POST="退还押金";
public static final String USER_PAY_RETURN="交付押金199元";
//业务逻辑层BikeMapper的注入
@Resource(name="bikeServiceDao")
private BikeServiceDao bikeServiceDao;
//业务逻辑层BikeMapper的注入
@Resource(name="adminServiceDao")
private AdminServiceDao adminServiceDao;
/**
* 用户得到单车列表
* @param offset 当前页
* @param limit 每页显示条数
* @param bikeId 单车编号
* @param bikeGenerationnum 单车代数
* @param bikeArea 单车所在城市
* @return
*/
@RequestMapping("/getBikeList")
@ResponseBody
public Object getBikeList(int offset,int limit,Integer bikeId, String bikeKind,String address,HttpServletRequest request,HttpServletResponse response,ModelMap model){
HttpSession session = request.getSession();
String flag=null;
if("第一代".equals(bikeKind)){
flag="1";
}
if("第二代".equals(bikeKind)){
flag="2";
}
if("第三代".equals(bikeKind)){
flag="3";
}
if("".equals(bikeKind)||bikeKind==null){
flag=null;
}
Integer valueOf = null;
if(flag!=null){
valueOf = Integer.valueOf(flag);
}
//得到单车的密码
Bike bikePassword = bikeServiceDao.getBikePassword(bikeId);
session.setAttribute("bike", bikePassword);
int currentPage=offset/limit+1;
Map<String, Object> bikeList = bikeServiceDao.getBikeList(currentPage, limit, bikeId, valueOf, address);
return bikeList;
}
@RequestMapping("/getBike")
@ResponseBody
//根据单车编号得到单车的密码
public Object getBike(Integer bikeId,HttpServletRequest request,HttpServletResponse response,ModelMap model){
//得到当前时间
Date date=new Date();
//时间格式化
SimpleDateFormat time=new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
String format = time.format(date);
HttpSession session = request.getSession();
String uId = session.getAttribute("userId").toString();
//得到该登录用户的数据
User selectUser = bikeServiceDao.selectUser(Integer.valueOf(uId));
//余额与押金验证
if((selectUser.getUserBalance()!=null&&selectUser.getUserBalance()>=0)&&(selectUser.getUserDeposit()!=null&&selectUser.getUserDeposit()>0)){
Bike bikePassword2 = bikeServiceDao.getBikePassword(bikeId);
//得到一个记录对象
Record record=new Record();
record.setUserId(Integer.valueOf(uId));
record.setBikeId(bikePassword2.getBikeId());
record.setStartDate(format);
//查询记录,判断是还车
Record selectRecord = bikeServiceDao.selectRecord(Integer.valueOf(uId));
//验证是否还车
if(selectRecord==null||(StringUtils.isNotBlank(selectRecord.getStartDate())&&StringUtils.isNotBlank(selectRecord.getReturnDate()))||(StringUtils.isBlank(selectRecord.getStartDate())&&StringUtils.isBlank(selectRecord.getReturnDate()))){
//在数据数据为空或没有未结算的记录的才可以进行数据的插入;
bikeServiceDao.insertRecord(record);
//修改单车状态
bikeServiceDao.updateBikeUse(bikeId, 1, 0);
}
Bike adminGetBike = adminServiceDao.adminGetBike(bikeId);
return adminGetBike;
}else{
Bike bike=new Bike();
bike.setBikePassword(null);
return bike;
}
}
//验证是否处理提交单车归还订单
@RequestMapping("/checkSaveOk")
@ResponseBody
public Object checkSaveOk(HttpServletRequest request,HttpServletResponse response,ModelMap model){
HttpSession session = request.getSession();
String uId = session.getAttribute("userId").toString();
//查询当前用户是否还车
Record selectRecord2 = bikeServiceDao.selectRecord(Integer.valueOf(uId));
return selectRecord2;
}
/**
* 用户还车列表
* @param offset
* @param limit
* @param request
* @param response
* @param model
* @return
*/
@RequestMapping("/selectReturnBike")
@ResponseBody
public Object selectReturnBike(int offset,int limit,HttpServletRequest request,HttpServletResponse response,ModelMap model){
HttpSession session = request.getSession();
String uId = session.getAttribute("userId").toString();
int currentPage=offset/limit+1;
Map<String, Object> selectReturnBike = bikeServiceDao.selectReturnBike(currentPage, limit,Integer.valueOf(uId));
return selectReturnBike;
}
/**
* 用户确骑行清单
* @param recordId 记录id
* @return
*/
@RequestMapping("/InsertReturnDate")
@ResponseBody
public Object InsertReturnDate(Integer recordId,HttpServletRequest request,HttpServletResponse response,ModelMap model){
//得到当前时间
Date date=new Date();
//时间格式化
SimpleDateFormat time=new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
String format = time.format(date);
//根据记录id得到对象
Record selectStratDate = bikeServiceDao.selectStratDate(recordId);
//得到一个记录对象
Record record=new Record();
//得到开始骑行的时间
String startDate = null;
if(selectStratDate!=null&&selectStratDate.getStartDate()!=null){
startDate = selectStratDate.getStartDate();
try {
//开始骑行时间字符串转日期
Date parse1 = time.parse(startDate);
//结束骑行时间转换
Date parse2 = time.parse(format);
//进行时间运算
long time2 = parse2.getTime()-parse1.getTime();
//天
long days=time2/(1000*60*60*24);
//小时
long hours=(time2-days*(1000 * 60 * 60 * 24))/(1000* 60 * 60);
//分
long minutes = (time2-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60))/(1000* 60);
System.out.println(""+days+"天"+hours+"小时"+minutes+"分");
//得到计费(每小时骑行单价为一元)
long payment=days*24*1+hours*1+1;
//将数据写入对象中
record.setRecordId(recordId);
record.setReturnDate(format);
record.setPayment(payment);
} catch (ParseException e) {
e.printStackTrace();
}
}
return record;
}
/**
* 用户确认单
* @param recordId 记录id
* @return
*/
@RequestMapping(value="/saveOrder",method=RequestMethod.POST)
@ResponseBody
public Object saveOrder(Integer recordId,String returnDate,Long payment, HttpServletRequest request,HttpServletResponse response,ModelMap model){
//得到session
HttpSession session = request.getSession();
if(recordId!=null&&StringUtils.isNotBlank(returnDate)&&payment!=null){
String uId = session.getAttribute("userId").toString();
//再次查询
Record selectRecord2 = bikeServiceDao.selectRecord(Integer.valueOf(uId));
//放入session作用域
session.setAttribute("selectRecord", selectRecord2.getReturnDate());
User selectUser = bikeServiceDao.selectUser(Integer.valueOf(uId));
//账号余额
Long userBalance = selectUser.getUserBalance();
if(userBalance-payment>0){
//将数据进行写入
boolean insertReturnDate = bikeServiceDao.updateReturnD
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
单车共享租用系统 (280个子文件)
UserBikeController.class 12KB
AdminBikeController.class 11KB
UserLoginController.class 10KB
ExcelUtils.class 8KB
BikeServiceDaoImpl.class 7KB
JsonMapper.class 6KB
AdminServiceDaoImpl.class 6KB
ServiceController.class 5KB
ComplainController.class 4KB
ServiceServiceDaoImpl.class 4KB
ComplainServiceDaoImpl.class 4KB
LoginServiceDaoImpl.class 3KB
User.class 3KB
Employee.class 3KB
MD5Utils.class 2KB
Bike.class 2KB
BikeMapper.class 2KB
Complain.class 2KB
Service.class 2KB
Record.class 2KB
Column.class 2KB
UserMapper.class 1KB
ServiceMapper.class 1KB
SerializeUtil.class 1KB
RecordMapper.class 1KB
AdminServiceDao.class 1KB
BikeServiceDao.class 1KB
ComplainMapper.class 1KB
LoginServiceDao.class 1KB
LimiteRole.class 1KB
EmployeeMapper.class 883B
ServiceServiceDao.class 804B
LimiteRoleMapper.class 752B
ColumnMapper.class 734B
ComplainServiceDao.class 703B
.classpath 771B
org.eclipse.wst.common.component 479B
org.eclipse.wst.jsdt.ui.superType.container 49B
bootstrap.min.css 137KB
style.css 65KB
font-awesome.css 34KB
bootstrap-theme.min.css 23KB
font-awesome.min.css 21KB
font.css 21KB
layer.css 14KB
bootstrap-datetimepicker.min.css 11KB
monthly.css 8KB
dataTables.bootstrap.css 7KB
bootstrap-table.min.css 6KB
style-responsive.css 6KB
sb-admin-2.css 5KB
layer.css 5KB
lightbox.css 4KB
select.css 2KB
minimal.css 1KB
metisMenu.min.css 781B
jqvmap.css 746B
morris.css 431B
boot-crm.css 52B
fontawesome-webfont.eot 75KB
glyphicons-halflings-regular.eot 20KB
loading-0.gif 6KB
loading-2.gif 2KB
loading-1.gif 701B
404.html 2KB
poi-ooxml-schemas-3.16.jar 5.6MB
xmlbeans-2.6.0.jar 2.6MB
poi-3.16.jar 2.56MB
ant-1.9.6.jar 1.94MB
aspectjweaver-1.8.9.jar 1.78MB
mybatis-3.4.4.jar 1.53MB
poi-ooxml-3.16.jar 1.37MB
ehcache-core-2.6.8.jar 1.28MB
jackson-databind-2.8.8.jar 1.18MB
spring-context-4.3.7.RELEASE.jar 1.09MB
spring-data-redis-1.7.11.RELEASE.jar 1.07MB
spring-core-4.3.7.RELEASE.jar 1.07MB
spring-webmvc-4.3.7.RELEASE.jar 894KB
log4j-core-2.3.jar 808KB
spring-web-4.3.7.RELEASE.jar 799KB
spring-beans-4.3.7.RELEASE.jar 745KB
commons-collections4-4.1.jar 734KB
javassist-3.21.0-GA.jar 718KB
mysql-connector-java-5.1.7-bin.jar 693KB
jedis-2.9.0.jar 541KB
log4j-1.2.17.jar 478KB
spring-jdbc-4.3.7.RELEASE.jar 418KB
jstl-1.2.jar 405KB
commons-lang3-3.3.jar 403KB
standard.jar 384KB
spring-aop-4.3.7.RELEASE.jar 371KB
jsqlparser-0.9.5.jar 314KB
cglib-3.2.5.jar 295KB
commons-codec-1.10.jar 278KB
jackson-core-2.8.8.jar 276KB
spring-tx-4.3.7.RELEASE.jar 261KB
spring-expression-4.3.7.RELEASE.jar 257KB
ognl-3.1.14.jar 230KB
commons-io-2.5.jar 204KB
spring-context-support-4.3.7.RELEASE.jar 183KB
共 280 条
- 1
- 2
- 3
资源评论
- 南槐生橘2019-04-11好像少了那个服务协议的前端htmllei_19942019-04-19是的,留了一个空缺,您可以自己加上的。
- Next码云2019-02-27没有数据库,wjflei_19942019-02-28有的 , 在我的资源库里面。https://download.csdn.net/download/lei_1994/10583356
lei_1994
- 粉丝: 30
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功