package com.power.travel.service;
import com.power.travel.core.Result;
import com.power.travel.core.ResultGenerator;
import com.power.travel.core.ServiceException;
import com.power.travel.enums.StatusEnum;
import com.power.travel.model.*;
import com.power.travel.repository.*;
import com.power.travel.util.CookieUitl;
import com.power.travel.util.IdGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.thymeleaf.util.StringUtils;
import javax.persistence.criteria.Predicate;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
@Service
public class SystemService {
@Autowired
private SysUserRepository sysUserRepository;
@Autowired
private UserRepository userRepository;
@Autowired
private HotelRepository hotelRepository;
@Autowired
private AttractionsRepository attractionsRepository;
@Autowired
private TravelRouteRepository travelRouteRepository;
@Autowired
private TravelStrategyRepository travelStrategyRepository;
private Random random = new Random(100);
public Result login(SysUser sysUser, HttpServletResponse response) {
SysUser sysUserByUsrname = sysUserRepository.findSysUserByUsername(sysUser.getUsername());
if (sysUserByUsrname == null) {
return ResultGenerator.genFailResult("用户名错误!");
} else {
if (sysUser.getPassword().equals(sysUserByUsrname.getPassword())) {
CookieUitl.set(response, "sysUsername", sysUser.getUsername(), 3600);
return ResultGenerator.genSuccessResult();
} else {
return ResultGenerator.genFailResult("密码错误");
}
}
}
public void logout(HttpServletRequest request, HttpServletResponse response) {
Cookie cookie = CookieUitl.get(request, "sysUsername");
if (cookie != null) {
CookieUitl.set(response, "sysUsername", null, 0);
}
}
public Page<User> getUserPage(Pageable pageable) {
Page<User> userPage = userRepository.findAll((root, query, cb) -> {
List<Predicate> predicates = new ArrayList<>();
query.where(predicates.toArray(new Predicate[]{}));
query.orderBy(cb.desc(root.get("id")));
return null;
}, pageable);
return userPage;
}
@Transactional(rollbackFor = Exception.class)
public Result saveUser(User user) {
System.out.println(user.getId());
if (StringUtils.isEmpty(user.getId())) {//没有id的情况
user.setId(IdGenerator.id());
} else {
User oldUser = getUserById(user.getId());
user.setUsername(oldUser.getUsername());
user.setName(oldUser.getName());
oldUser.setPassword(user.getPassword());
}
userRepository.saveAndFlush(user);
return ResultGenerator.genSuccessResult();
}
public User getUserById(String id) {
User user = userRepository.findById(id).orElseThrow(() -> new ServiceException("用户ID错误"));
return user;
}
public Page<Hotel> getHotelPage(Pageable pageable) {
Page<Hotel> hotelPage = hotelRepository.findAll((root, query, cb) -> {
List<Predicate> predicates = new ArrayList<>();
query.where(predicates.toArray(new Predicate[]{}));
query.orderBy(cb.desc(root.get("createDate")));
return null;
}, pageable);
return hotelPage;
}
@Transactional(rollbackFor = Exception.class)
public Result saveHotel(Hotel hotel) {
if (StringUtils.isEmpty(hotel.getId())) {//没有id的情况
hotel.setId(IdGenerator.id());
hotel.setStatus(StatusEnum.DOWM_STATUS.getCode());
hotel.setCreateDate(new Date());
int i = random.nextInt(100);
hotel.setImage("MY_kezhan_0" + (i % 8 + 1));
} else {
//有id的情况
Hotel oldHotel = getHotelById(hotel.getId());
hotel.setStatus(oldHotel.getStatus());
hotel.setCreateDate(oldHotel.getCreateDate());
hotel.setImage(oldHotel.getImage());
}
hotelRepository.saveAndFlush(hotel);
return ResultGenerator.genSuccessResult();
}
public Hotel getHotelById(String id) {
Hotel hotel = hotelRepository.findById(id).orElseThrow(() -> new ServiceException("酒店ID错误!"));
return hotel;
}
public Result updateStatus(String id) {
Hotel hotel = getHotelById(id);
if (hotel.getStatus().equals(StatusEnum.DOWM_STATUS.getCode())) {
//改变状态
hotel.setStatus(StatusEnum.UP_STATUS.getCode());
} else {
hotel.setStatus(StatusEnum.DOWM_STATUS.getCode());
}
hotelRepository.saveAndFlush(hotel);
return ResultGenerator.genSuccessResult();
}
public Page<Attractions> getAttractionsPage(Pageable pageable) {
Page<Attractions> attractionsPage = attractionsRepository.findAll((root, query, cb) -> {
List<Predicate> predicates = new ArrayList<>();
query.where(predicates.toArray(new Predicate[]{}));
query.orderBy(cb.desc(root.get("createDate")));
return null;
}, pageable);
return attractionsPage;
}
public Attractions getAttractionsById(String id) {
Attractions attractions = attractionsRepository.findById(id).orElseThrow(() -> new ServiceException("景点ID错误"));
return attractions;
}
public Result updateAttractionsStatus(String id) {
Attractions attractions = getAttractionsById(id);
if (attractions.getStatus().equals(StatusEnum.DOWM_STATUS.getCode())) {
//改变状态
attractions.setStatus(StatusEnum.UP_STATUS.getCode());
} else {
attractions.setStatus(StatusEnum.DOWM_STATUS.getCode());
}
attractionsRepository.saveAndFlush(attractions);
return ResultGenerator.genSuccessResult();
}
@Transactional(rollbackFor = Exception.class)
public Result saveAttractions(Attractions attractions) {
if (StringUtils.isEmpty(attractions.getId())) {//没有id的情况
attractions.setId(IdGenerator.id());
attractions.setStatus(StatusEnum.DOWM_STATUS.getCode());
attractions.setCreateDate(new Date());
int i = random.nextInt(100);
attractions.setImage("MY_jingdian_0" + (i % 8 + 1));
} else {
//有id的情况
Attractions oldAttractions = getAttractionsById(attractions.getId());
attractions.setStatus(oldAttractions.getStatus());
attractions.setCreateDate(oldAttractions.getCreateDate());
attractions.setImage(oldAttractions.getImage());
}
attractionsRepository.saveAndFlush(attractions);
return ResultGenerator.genSuccessResult();
}
public Page<TravelRoute> getTravelRoutePage(Pageable pageable) {
Page<TravelRoute> travelRoutePage = travelRouteRepository.findAll((root, query, cb) -> {
List<Predicate> predicates = new ArrayList<>();
query.where(predicates.toArray(new Predicate[]{}));
query.orderBy(cb.desc(root.get("createDate")));
return null;
}, pageable);
return travelRoutePage;
}
@Transactional(rollbackFor = Exception.class)
public Result saveTravelRoute(TravelRoute travelRoute) {
if (StringUtils.isEmpty(travelRoute.getId())) {//没有id的情况
travelRou
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
《旅游网站》项目适用于学到springboot阶段的小伙伴。 该项目主要使用Spring mvc、Spring、Hibernate、thymleaf、html、css、javascript、tomcat、mysql、servlet等技术来实现游玩路线、游玩攻略、酒店预订、景点预定、用户管理、酒店管理、景点管理、路线管理等系统功能。
资源推荐
资源详情
资源评论
收起资源包目录
动力节点Java毕设项目springboot项目实战《旅游网站》 (280个子文件)
linecons.css 147KB
bootstrap.min.css 118KB
animate.css 71KB
style.css 60KB
zozo.tabs.min.css 51KB
font-awesome.min.css 30KB
zozo.tabs.flat.min.css 23KB
slider-pro.css 16KB
bootstrap-datepicker.min.css 15KB
layer.css 14KB
slider-pro.min.css 13KB
style2.css 6KB
layer.css 5KB
owl.carousel.min.css 3KB
responsive.css 3KB
perfect-scrollbar.css 3KB
owl.theme.default.min.css 2KB
jquery.scrolling-tabs.css 2KB
openhand.cur 326B
closedhand.cur 326B
fontawesome-webfont.eot 162KB
glyphicons-halflings-regular.eot 20KB
linecons.eot 15KB
preloader.gif 70KB
loading-0.gif 6KB
ajax-loader.gif 3KB
loading-2.gif 2KB
loading-1.gif 701B
blank.gif 43B
user-center-edit.html 17KB
index.html 13KB
layout.html 11KB
pushStrategy.html 9KB
user-center.html 9KB
list.html 8KB
list.html 8KB
list.html 8KB
pageable.html 7KB
reserve-user-manage.html 7KB
list.html 7KB
index-register.html 7KB
user-center-editpw.html 6KB
strategy-manage.html 6KB
list.html 5KB
reserve-attractions.html 5KB
reserve-hotel.html 5KB
reserve-attractions-details.html 5KB
route-user-manage.html 5KB
reserve-hotel-details.html 5KB
travelStrategy.html 5KB
travelRoute.html 5KB
travelStrategy-details.html 4KB
travelRoute-details.html 4KB
layout.html 4KB
index-login.html 4KB
login.html 2KB
list.html 123B
volunteer_travel.iml 11KB
SystemService.java 12KB
ReserveService.java 8KB
StrategyService.java 8KB
SystemController.java 5KB
RouteService.java 5KB
ReserveController.java 5KB
StrategyController.java 4KB
RouteController.java 3KB
LoginService.java 2KB
UserCenterController.java 2KB
UserCenterService.java 2KB
TravelRoute.java 2KB
Hotel.java 2KB
TravelStrategy.java 2KB
Attractions.java 1KB
CookieUitl.java 1KB
IndexController.java 1KB
LoginController.java 1KB
UserHotel.java 1KB
UserStrategy.java 1KB
UserAttractions.java 1KB
ResultGenerator.java 1KB
User.java 1019B
UserRoute.java 919B
Result.java 893B
SysUser.java 777B
LoginServiceTest.java 695B
ResultCode.java 686B
UserRouteRepository.java 638B
UserAttractionsRepository.java 624B
UserHotelRepository.java 615B
UserStrategyRepository.java 612B
StatusEnum.java 558B
ServiceException.java 509B
SysUserRepository.java 440B
UserRepository.java 422B
AttractionsRepository.java 404B
HotelRepository.java 381B
TravelStrategyRepository.java 357B
VolunteerTravelApplicationTests.java 351B
TravelRouteRepository.java 342B
TravelPlatformApplication.java 337B
共 280 条
- 1
- 2
- 3
资源评论
qwsrfss
- 粉丝: 1
- 资源: 32
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 预计2030年全球昆虫源饲料市场规模将达到27.4亿美元
- 基于springboot的家政服务管理平台源码(java毕业设计完整源码+LW).zip
- 预计2030年全球铌酸锂薄膜(LNOI)和钽酸锂薄膜(LTOI)市场规模将达到7.7亿美元
- 基于企业微信的客户运营9问9答
- 地级市数字贸易关注度词频数据及城市数字贸易关注度词频数据(2003-2024年).txt
- HTML5 Canvas烟花动画:JavaScript与CSS的结合实现动态效果
- 全新UI-APP分发系统网站源码-全新IPA/APK APP分发平台+对接码支付+密钥生成
- 使用HTML和CSS打造闪烁彩灯的圣诞树网页
- 华为交换机网络设备MIB文件
- 最新更新!!!全国各省、市、县逐年水文数据(降水量)1950-2022
- 预计2030年全球铌酸锂单晶薄膜市场规模将达到4.17亿美元
- SXU-软件工程论文及绘图
- 预计2030年全球一次性刀叉餐具市场规模将达到28.1亿美元
- 预计2030年全球脂质纳米粒子(LNP)生产设备市场规模将达到3亿美元
- 基于springboot的农机电招平台源码(java毕业设计完整源码+LW).zip
- 智慧航道动态监测管理平台
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功