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、JPA、Thmleaf实现的旅游网站管理系统 (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
closedhand.cur 326B
openhand.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
资源评论
在札幌度假的小犀牛
- 粉丝: 211
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Lawrence C. Evans Partial Differential Equations.djvu
- CFA知识点梳理系列:CFA Level II, Reading 4 Big Data Projects
- 专业问题 · 语雀.mhtml
- 基于Vue+TP6的B2B2C多场景电商商城设计源码
- 基于小程序的研知识题库小程序源代码(java+小程序+mysql).zip
- 基于小程序的微信小程序的点餐系统源代码(java+小程序+mysql).zip
- 基于小程序的宿舍管理小程序源代码(java+小程序+mysql).zip
- 基于小程序的小区服务系统源代码(python+小程序+mysql).zip
- QT项目之中国象棋人工智能
- 基于小程序的疫情核酸预约小程序源代码(java+小程序+mysql).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功