文章目录
- 一、项目演示
- 二、项目介绍
- 三、运行截图
- 四、主要代码
- 1. 分页获取预约数据代码
- 2.保存预约信息代码
- 3.修改订单状态代码
一、项目演示
项目演示地址: 视频地址
二、项目介绍
项目描述:这是一个基于SpringBoot+Vue框架开发的充电桩管理系统。首先,这是一个前后端分离的项目,代码简洁规范,注释说明详细,易于理解和学习。其次,这项目功能丰富,具有一个充电桩管理系统该有的所有功能。
项目功能:此项目分为两个角色:普通用户和管理员。普通用户有登录注册、浏览个人数据统计信息、管理个人信息、浏览运营商信息、浏览电站信息、浏览充电桩信息、预约充电桩、报修充电桩、管理个人预约信息、开始充电、结束充电、查看个人订单信息、支付订单、查看个人报修信息、查看个人告警信息、查看留言信息等等功能。管理员有查看全部数据统计信息、管理所有用户信息、管理所有运营商信息、管理所有电站信息、管理所有充电桩信息、管理所有预约信息、管理所有订单信息、管理所有报修信息、管理所有告警信息、管理所有留言信息等等功能。
应用技术:SpringBoot + Vue3.0 + MySQL + MyBatis + Redis + ElementUI-Plus + Vite
运行环境:IntelliJ IDEA2019.3.5 + MySQL5.7(项目压缩包中自带) + Redis5.0.5(项目压缩包中自带) + JDK1.8 + Maven3.6.3(项目压缩包中自带)+ Node14.16.1(项目压缩包中自带)
三、运行截图
四、主要代码
1. 分页获取预约数据代码
/**
* 分页获取预约数据
* @param pageDTO
* @return
*/
@Override
public ResponseDTO<PageDTO<AppointDTO>> getAppointList(PageDTO<AppointDTO> pageDTO) {
AppointExample appointExample = new AppointExample();
// 不知道当前页多少,默认为第一页
if(pageDTO.getPage() == null){
pageDTO.setPage(1);
}
// 不知道每页多少条记录,默认为每页5条记录
if(pageDTO.getSize() == null){
pageDTO.setSize(5);
}
AppointExample.Criteria c1 = appointExample.createCriteria();
if(pageDTO.getParam() != null) {
AppointDTO appointDTO = pageDTO.getParam();
if(!CommonUtil.isEmpty(appointDTO.getUserId())) {
c1.andUserIdEqualTo(appointDTO.getUserId());
} else {
UserExample userExample = new UserExample();
userExample.createCriteria().andUsernameLike("%" + appointDTO.getUsername() + "%");
List<String> userIdList = userMapper.selectByExample(userExample).stream().map(User::getId).collect(Collectors.toList());
if(userIdList.size() == 0) {
pageDTO.setTotal(0L);
pageDTO.setList(new ArrayList<>());
return ResponseDTO.success(pageDTO);
}
c1.andUserIdIn(userIdList);
}
if(!(CommonUtil.isEmpty(appointDTO.getChargeId())) && !"0".equals(appointDTO.getChargeId())) {
c1.andChargeIdEqualTo(appointDTO.getChargeId());
}
}
appointExample.setOrderByClause("create_time desc");
PageHelper.startPage(pageDTO.getPage(), pageDTO.getSize());
// 分页查出预约数据
List<Appoint> appointList = appointMapper.selectByExample(appointExample);
PageInfo<Appoint> pageInfo = new PageInfo<>(appointList);
// 获取数据的总数
pageDTO.setTotal(pageInfo.getTotal());
// 将domain类型数据 转成 DTO类型数据
List<AppointDTO> appointDTOList = CopyUtil.copyList(appointList, AppointDTO.class);
for(AppointDTO appointDTO : appointDTOList) {
User user = userMapper.selectByPrimaryKey(appointDTO.getUserId());
appointDTO.setUserDTO(CopyUtil.copy(user, UserDTO.class));
// 当前时间超过结束时间,且状态为待使用的预约,状态自动改为已取消
// 当前时间超过结束时间,且状态为充电中的预约,状态自动改为已完成
String[] splitTime = appointDTO.getTime().split("-");
Date endDate = CommonUtil.getFormatterDate(CommonUtil.getFormatterDate(appointDTO.getDay(), "yyyy-MM-dd") + " " + splitTime[1], "yyyy-MM-dd HH:mm");
Appoint appoint = CopyUtil.copy(appointDTO, Appoint.class);
if(new Date().getTime() > endDate.getTime()) {
if(AppointStateEnum.WAIT.getCode().equals(appointDTO.getState())) {
appoint.setState(AppointStateEnum.CANCEL.getCode());
appointDTO.setState(AppointStateEnum.CANCEL.getCode());
} else if(AppointStateEnum.USE.getCode().equals(appointDTO.getState())) {
appoint.setState(AppointStateEnum.OVER.getCode());
appoint.setEndTime(endDate);
appointDTO.setEndTime(endDate);
appointDTO.setState(AppointStateEnum.OVER.getCode());
Charge charge = chargeMapper.selectByPrimaryKey(appointDTO.getChargeId());
BigDecimal totalPrice = charge.getPrice().multiply(new BigDecimal(DateUtil.between(appointDTO.getStartTime(), endDate, DateUnit.MINUTE)));
Order order = new Order();
order.setId(UuidUtil.getShortUuid());
order.setCreateTime(new Date());
order.setUserId(appointDTO.getUserId());
order.setChargeId(appointDTO.getChargeId());
order.setChargeName(appointDTO.getChargeName());
order.setTotalPrice(totalPrice);
if(orderMapper.insertSelective(order) == 0) {
return ResponseDTO.errorByMsg(CodeMsg.ORDER_ADD_ERROR);
}
}
appointMapper.updateByPrimaryKeySelective(appoint);
}
}
pageDTO.setList(appointDTOList);
return ResponseDTO.success(pageDTO);
}
2.保存预约信息代码
/**
* 保存预约信息
* @param appointDTO
* @return
*/
@Override
public ResponseDTO<Boolean> saveAppoint(AppointDTO appointDTO) {
// 进行统一表单验证
CodeMsg validate = ValidateEntityUtil.validate(appointDTO);
if (!validate.getCode().equals(CodeMsg.SUCCESS.getCode())) {
return ResponseDTO.errorByMsg(validate);
}
Appoint appoint = CopyUtil.copy(appointDTO, Appoint.class);
Charge charge = chargeMapper.selectByPrimaryKey(appoint.getChargeId());
if(ChargeStateEnum.REPAIR.getCode().equals(charge.getState())) {
return ResponseDTO.errorByMsg(CodeMsg.CHARGE_REPAIR_ERROR);
}
User user = userMapper.selectByPrimaryKey(appoint.getUserId());
if(user == null) {
return ResponseDTO.errorByMsg(CodeMsg.USER_NOT_EXIST);
}
if(CommonUtil.isEmpty(appoint.getId())) {
// 添加操作
if(user.getRate() < 80) {
return ResponseDTO.errorByMsg(CodeMsg.RATE_NOT_ENOUGH);
}
appoint.setId(UuidUtil.getShortUuid());
appoint.setCreateTime(new Date());
// 判断预约日期时间段是否重复
if(isDayExist(appoint, "")){
return ResponseDTO.errorByMsg(CodeMsg.APPOINT_DAY_EXIST);
}
if(appointMapper.insertSelective(appoint) == 0) {
return ResponseDTO.errorByMsg(CodeMsg.APPOINT_ADD_ERROR);
}
} else {
// 修改操作
// 判断预约日期时间段是否重复
if(isDayExist(appoint, appoint.getId())){
return ResponseDTO.errorByMsg(CodeMsg.APPOINT_DAY_EXIST);
}
if(appointMapper.updateByPrimaryKeySelective(appoint) == 0) {
return ResponseDTO.errorByMsg(CodeMsg.APPOINT_EDIT_ERROR);
}
}
return ResponseDTO.successByMsg(true, "保存成功!");
}
3.修改订单状态代码
/**
* 修改订单状态
* @param orderDTO
* @return
*/
@Override
public ResponseDTO<Boolean> editOrderState(OrderDTO orderDTO) {
if(CommonUtil.isEmpty(orderDTO.getId())) {
return ResponseDTO.errorByMsg(CodeMsg.DATA_ERROR);
}
Order orderDB = orderMapper.selectByPrimaryKey(orderDTO.getId());
Order order = CopyUtil.copy(orderDTO, Order.class);
User user = userMapper.selectByPrimaryKey(orderDB.getUserId());
if(user == null) {
return ResponseDTO.errorByMsg(CodeMsg.USER_NOT_EXIST);
}
if(!OrderStateEnum.PAYED.getCode().equals(orderDB.getState()) && OrderStateEnum.PAYED.getCode().equals(order.getState())) {
Rate rate = new Rate();
rate.setId(UuidUtil.getShortUuid());
if(user.getRate() + 5 >= 100) {
user.setRate(100);
} else {
user.setRate(user.getRate() + 5);
}
rate.setNowScore(user.getRate());
rate.setScore(5);
rate.setType(RateTypeEnum.ADD.getCode());
rate.setUserId(orderDB.getUserId());
rate.setCreateTime(new Date());
rate.setContent("成功支付,奖励信誉分5分!");
if(rateMapper.insertSelective(rate) == 0) {
return ResponseDTO.errorByMsg(CodeMsg.RATE_ADD_ERROR);
}
if(userMapper.updateByPrimaryKeySelective(user) == 0) {
return ResponseDTO.errorByMsg(CodeMsg.USER_EDIT_ERROR);
}
}
if(orderMapper.updateByPrimaryKeySelective(order) == 0) {
return ResponseDTO.errorByMsg(CodeMsg.ORDER_EDIT_ERROR);
}
return ResponseDTO.success(true);
}