欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Java 实战项目之诚途旅游系统的实现流程

程序员文章站 2022-06-25 08:01:24
采用ssm架构实现的旅游网站系统 包括网站展示和后台管理功能,网站主要是页面浏览以及评论、制定旅游方案、智能推荐功能 后台就是维护网站展示的内容,添加旅游景点、管理用户、查看用户的搜索记录功能酒店信息...

采用ssm架构实现的旅游网站系统 包括网站展示和后台管理功能,网站主要是页面浏览以及评论、制定旅游方案、智能推荐功能 后台就是维护网站展示的内容,添加旅游景点、管理用户、查看用户的搜索记录功能

Java 实战项目之诚途旅游系统的实现流程

Java 实战项目之诚途旅游系统的实现流程

Java 实战项目之诚途旅游系统的实现流程

Java 实战项目之诚途旅游系统的实现流程

Java 实战项目之诚途旅游系统的实现流程

酒店信息控制层:

/**
 * 控制器层
 *
 */
@controller
@crossorigin
@requestmapping("/hotel")
public class hotelcontroller {
 
	@autowired
	private hotelservice hotelservice;
 
	@autowired
	private scenicservice scenicservice;
 
 
 
	/**
	 * 查询全部酒店信息
	 * @return
	 */
	@responsebody
	@requestmapping(value = "/list",method= requestmethod.get)
	public result findall(){
		list<hotel> all = hotelservice.findall();
		return new result(true, statuscode.ok,"查询成功",all,all.size());
	}
	
	/**
	 * 根据id查询
	 * @param id id
	 * @return
	 */
	@responsebody
	@requestmapping(value="/{id}",method= requestmethod.get)
	public result findbyid(@pathvariable long id){
		return new result(true,statuscode.ok,"查询成功",hotelservice.findbyid(id));
	}
 
 
	/**
	 * 酒店添加操作
	 * @param hotel
	 */
	@responsebody
	@requestmapping(value = "/add",method=requestmethod.post)
	public result add(hotel hotel){
		if(stringutils.isempty(hotel.getname())){
			return new result(false,statuscode.error,"请填写酒店名称");
		}
		if(stringutils.isempty(hotel.getimg())){
			return new result(false,statuscode.error,"请上传酒店封面图片");
		}
		if(stringutils.isempty(hotel.getaddr())){
			return new result(false,statuscode.error,"请填写酒店地址");
		}
		if(stringutils.isempty(hotel.getmiaoshu())){
			return new result(false,statuscode.error,"请填写酒店描述");
		}
		hotel.setcommentcount(0);
		hotel.setstar(0);
		if(hotelservice.add(hotel)==null){
			return new result(false,statuscode.error,"酒店添加失败");
		}
		return new result(true,statuscode.ok,"添加成功");
	}
 
 
	/**
	 * 分页+多条件查询
	 * @param searchmap 查询条件封装
	 * @param page 页码
	 * @param size 页大小
	 * @return 分页结果
	 */
	@responsebody
	@requestmapping(value="/search/{page}/{size}",method=requestmethod.post)
	public result findsearch(@requestbody map searchmap , @pathvariable int page, @pathvariable int size){
		page<hotel> pagelist = hotelservice.findsearch(searchmap, page, size);
		return  new result(true,statuscode.ok,"查询成功",  new pageresult<hotel>(pagelist.gettotalelements(), pagelist.getcontent()) );
	}
 
	/**
     * 根据条件查询
     * @param searchmap
     * @return
     */
	@responsebody
    @requestmapping(value="/search",method = requestmethod.post)
    public result findsearch( @requestbody map searchmap){
        return new result(true,statuscode.ok,"查询成功",hotelservice.findsearch(searchmap));
    }
 
 
	/**
	 * 修改
	 * @param hotel
	 */
	@responsebody
	@requestmapping(value="/edit",method= requestmethod.put)
	public result update(hotel hotel){
		hotel hotelbyid = hotelservice.findbyid(hotel.getid());
		if(hotelbyid==null){
			return new result(false,statuscode.error,"该酒店信息不存在");
		}
		if(stringutils.isempty(hotel.getname())){
			return new result(false,statuscode.error,"请填写酒店名称");
		}
		beanutils.copyproperties(hotel,hotelbyid,"id","img","miaoshu","day","startdate","addr","commentcount");
		if(hotelservice.update(hotelbyid)==null){
			return new result(false,statuscode.error,"酒店编辑失败");
		}
		return new result(true,statuscode.ok,"修改成功");
	}
	
	/**
	 * 删除
	 * @param id
	 */
	@responsebody
	@requestmapping(value="/{id}",method= requestmethod.delete)
	public result delete(@pathvariable string id ){
		hotelservice.deletebyid(id);
		return new result(true,statuscode.ok,"删除成功");
	}
 
	/**
	 * 酒店列表跳转路径
	 * @return
	 */
	@requestmapping(value = "/hotellist")
	public string hotellist(){
		return "admin/hotelmanage/hotellist";
	}
 
	@requestmapping(value = "/hoteladd")
	public string hoteladd(){
		return "admin/hotelmanage/hoteladd";
	}
 
 
	/**
	 * 查询单个酒店
	 * @param model
	 * @param id
	 * @return
	 */
	@requestmapping("/oneattr")
	public string one_attr(model model, long id){
		hotel scenic=hotelservice.findbyid(id);
		model.addattribute("oneattr",scenic);
		return "page/hoteldetail";
	}
 
	@requestmapping("/local")
	public string localrefresh(model model,long id) {
		hotel hotel=hotelservice.findbyid(id);
			//	sort sort=new sort(sort.direction.desc,"star");
			system.out.println("1111"+hotel.tostring());
			list<scenic> scenics=scenicservice.findbycountrylike(hotel.getaddr());
			system.out.println("2222"+scenics.tostring());
			collections.sort(scenics, new comparator<scenic>() {
				@override
				public int compare(scenic o1, scenic o2) {
					if (o1.getstart()<o2.getstart()){
						return 2;
					}
					if (o1.getstart().equals(o2.getstart()) ){
						return 1;
					}
					return -1;
				}
			});
			if (scenics.size()>=4){
				list newlist=scenics.sublist(0,3);
				model.addattribute("scenics",newlist);
			}else {
				model.addattribute("scenics",scenics);
			}
 
		return "page/hoteldetail::table_refresh";
	}
}

管理员信息控制器层:

/**
 * 控制器层
 *
 */
@controller
@crossorigin
@requestmapping("/admin")
public class admincontroller {
 
	@autowired
	private adminservice adminservice;
	
	@autowired
	bcryptpasswordencoder encoder;
 
	/**
	 * 查询全部数据
	 * @return
	 */
	@responsebody
	@requestmapping(method= requestmethod.get)
	public result findall(){
		return new result(true, statuscode.ok,"查询成功",adminservice.findall());
	}
	
	/**
	 * 根据id查询
	 * @param id id
	 * @return
	 */
	@responsebody
	@requestmapping(value="/{id}",method= requestmethod.get)
	public result findbyid(@pathvariable long id){
		return new result(true,statuscode.ok,"查询成功",adminservice.findbyid(id));
	}
 
 
	/**
	 * 分页+多条件查询
	 * @param searchmap 查询条件封装
	 * @param page 页码
	 * @param size 页大小
	 * @return 分页结果
	 */
	@responsebody
	@requestmapping(value="/search/{page}/{size}",method=requestmethod.post)
	public result findsearch(@requestbody map searchmap , @pathvariable int page, @pathvariable int size){
		page<admin> pagelist = adminservice.findsearch(searchmap, page, size);
		return  new result(true,statuscode.ok,"查询成功",  new pageresult<admin>(pagelist.gettotalelements(), pagelist.getcontent()) );
	}
 
	/**
     * 根据条件查询
     * @param searchmap
     * @return
     */
	@responsebody
    @requestmapping(value="/search",method = requestmethod.post)
    public result findsearch( @requestbody map searchmap){
        return new result(true,statuscode.ok,"查询成功",adminservice.findsearch(searchmap));
    }
	
	/**
	 * 增加
	 * @param admin
	 */
	@responsebody
	@requestmapping(method=requestmethod.post)
	public result add(@requestbody admin admin  ){
		adminservice.add(admin);
		return new result(true,statuscode.ok,"增加成功");
	}
	
	/**
	 * 修改
	 * @param admin
	 */
	@responsebody
	@requestmapping(value="/{id}",method= requestmethod.put)
	public result update(@requestbody admin admin, @pathvariable long id ){
		admin.setid(id);
		adminservice.update(admin);		
		return new result(true,statuscode.ok,"修改成功");
	}
	
	/**
	 * 删除
	 * @param id
	 */
	@responsebody
	@requestmapping(value="/{id}",method= requestmethod.delete)
	public result delete(@pathvariable string id ){
		adminservice.deletebyid(id);
		return new result(true,statuscode.ok,"删除成功");
	}
 
	/**
	 * 管理员跳转
	 * @return
	 */
	@requestmapping(value = "/adminlogin")
	public string adminlogin()
	{
		return "admin/login/login";
	}
 
 
	/**
	 *  admin登录
	 * @param loginmap
	 * @param request
	 * @return
	 */
	@responsebody
	@requestmapping(value="/login",method= requestmethod.post)
	public result login(@requestparam map<string,string> loginmap,httpservletrequest request){
		admin admin = adminservice.finbynameandpassword(loginmap.get("name"),loginmap.get("password"));
		if (admin!=null){
 
			request.getsession().setattribute("admin",admin);
			map map=new hashmap();
			map.put("name",admin.getname());
			return new result(true,statuscode.ok,"登录成功");
		}else {
			return new result(false,statuscode.error,"账号密码错误");
		}
	}
 
	/**
	 * 管理员登录成功
	 * @return
	 */
	@requestmapping(value = "/index")
	public string success(){
		return "admin/index";
	}
 
 
	/**
	 * 用户列表
	 * @return
	 */
	@requestmapping(value = "/userlist")
	public string user(){
		return "admin/usermanage/userlist";
	}
 
	@requestmapping(value = "/echars")
	public string analysis(){
		return "admin/echars/console";
	}
 
 
	/**
	 * 管理员退出登录
	 * @return
	 */
	@requestmapping(value = "/logout")
	public string logout(httpsession session){
		session.removeattribute("admin");
		return "admin/login/login";
	}
 
 
	/**
	 * 管理员修改密码
	 * @return
	 */
	@responsebody
	@requestmapping(value = "/passwd")
	public result passwd(httpsession session,string passwd,string oldpad){
 
		admin admindmin= (admin) session.getattribute("admin");
		admin admins=adminservice.findbyid(admindmin.getid());
		boolean old=encoder.matches(oldpad,admins.getpassword());
		if (old){
			string newpassd=encoder.encode(passwd);
			admins.setpassword(newpassd);
			adminservice.update(admins);
			return new result(true,statuscode.ok,"成功");
		}else {
			return new result(false,statuscode.error,"更新失败");
		}
	}
 
}

景点信息控制层:

/**
 * 景点信息控制层
 */
@controller
@crossorigin
@requestmapping("/travel")
public class recomtravelcontroller {
 
    @autowired
    private scenicservice scenicservice;
 
    @autowired
    private scenicdao scenicdao;
 
    @autowired
    private hotelservice hotelservice;
 
    @autowired
    private hoteldao hoteldao;
 
    /**
     *查询星级
     * @return
     */
    @responsebody
    @requestmapping(value = "/star",method = requestmethod.post)
    public result judgestar(string id,string start){
        system.out.println(id+"===="+start);
        optional<scenic> s = scenicdao.findbyid(id);
        if (s.ispresent()){
            scenic scenic = s.get();
            int valuestar = (integer.valueof(start)+integer.valueof(scenic.getstart()))/2;
            scenic.setstart(valuestar);
            scenicdao.save(scenic);
            system.out.println("数据不为空!");
            return new result(true,1,"","");
        }else {
            system.out.println("数据为空!");
            return new result(false,0,"","");
 
        }
 
    }
 
 
    /**
     *查询星级
     * @return
     */
    @responsebody
    @requestmapping(value = "/hotel",method = requestmethod.post)
    public result judgehotelstar(long id,string start){
        hotel scenic = hotelservice.findbyid(id);
        if (scenic!=null){
            int valuestar = (integer.valueof(start)+integer.valueof(scenic.getstar()))/2;
            scenic.setstar(valuestar);
            hoteldao.save(scenic);
            system.out.println("数据不为空!");
            return new result(true,1,"","");
        }else {
            system.out.println("数据为空!");
            return new result(false,0,"","");
 
        }
 
    }
 
 
    /**
     * 查询单个景点
     * @param model
     * @param id
     * @return
     */
    @requestmapping("/oneattr")
    public string one_attr(model model,long id){
        scenic scenic=scenicservice.findbyid(id);
        model.addattribute("oneattr",scenic);
        return "page/product";
    }
 
 
    /**
     * 景点模糊查询分页
     * @param model
     * @param start
     * @param limit
     * @param search_key
     * @return
     */
    @requestmapping("/search_attrs")
    public string search_attrs(model model,@requestparam(value = "start" ,defaultvalue = "0")integer start,
                             @requestparam(value = "limit" ,defaultvalue = "6")integer limit,
                               @requestparam string search_key){
        start=start<0?0:start;
        sort sort=new sort(sort.direction.desc,"id");
        pageable pageable=pagerequest.of(start,limit,sort);
        specification specification=new specification() {
            @override
            public predicate topredicate(root root, criteriaquery criteriaquery, criteriabuilder criteriabuilder) {
                list<predicate> scenics=new arraylist<>();
                if (stringutils.isnotblank(search_key)){
                    scenics.add( criteriabuilder.like(root.get("name"),"%"+search_key+"%"));
                }
                return criteriabuilder.and(scenics.toarray(new predicate[scenics.size()]));
            }
        };
        page<scenic> page=scenicdao.findall(specification,pageable);
 
        model.addattribute("name",search_key);
        model.addattribute("attrs",page);
        model.addattribute("number",page.getnumber());
        model.addattribute("numberofelements",page.getnumberofelements());
        model.addattribute("size",page.getsize());
        model.addattribute("totalelements",page.gettotalelements());
        model.addattribute("totalpages",page.gettotalpages());
        model.addattribute("first",page.isfirst());
        model.addattribute("last",page.islast());
        return "page/travel";
    }
 
    @requestmapping("/local")
    public string localrefresh(model model,long id) {
        scenic scenic=scenicservice.findbyid(id);
        system.out.println(scenic.tostring());
        list<hotel> hotels=hotelservice.findbycountrylike(scenic.getcontry());
        collections.sort(hotels, new comparator<hotel>() {
            @override
            public int compare(hotel o1, hotel o2) {
                if (o1.getstar()<o2.getstar()){
                    return 2;
                }
                if (o1.getstar().equals(o2.getstar()) ){
                    return 1;
                }
                return -1;
            }
        });
        if (hotels.size()>=4){
            list newlist=hotels.sublist(0,3);
            model.addattribute("scenics",newlist);
            system.out.println("个数:"+newlist.size());
        }else {
            model.addattribute("scenics",hotels);
            system.out.println("个数2:"+hotels.size());
 
        }
        return "page/product::table_refresh";
    }
 
 
 
}

订单控制器层:

/**
 * 订单控制器层
 *
 */
@controller
@crossorigin
@requestmapping("/orders")
public class orderscontroller {
 
	@autowired
	private ordersservice ordersservice;
 
 
 
	@autowired
	private hotelordersservice hotel_ordersservice;
 
	@autowired
	private hotelservice hotelservice;
 
	@autowired
	private scenicservice scenicservice;
 
	
	/**
	 * 查询全部数据
	 * @return
	 */
	@responsebody
	@requestmapping(value = "/list",method= requestmethod.get)
	public result findall(){
		list<orders> all = ordersservice.findall();
		return new result(true, statuscode.ok,"查询成功",all,all.size());
	}
 
	/**
	 * 查询全部订单
	 * @return
	 */
	@responsebody
	@requestmapping(value = "/allorders",method = requestmethod.post)
	public string findallorders(httpsession session, model model) throws parseexception {
		user user= (user) session.getattribute("user");
		model.addattribute("orders",ordersservice.findorders(user.getid().tostring()));
		return "index_header::table_refresh";
	}
 
	/**
	 * 查询全部订单
	 * @return
	 */
	@responsebody
	@requestmapping(value = "/allorder",method = requestmethod.post)
	public list<orders> findallorder(httpsession session) throws parseexception {
		user user= (user) session.getattribute("user");
		return ordersservice.findorders(user.getid().tostring());
	}
 
 
	/**
	 * 查询全部订单
	 * @return
	 */
	@responsebody
	@requestmapping(value = "/allorderhotel",method = requestmethod.post)
	public list<hotelorders> findallorderhotel(httpsession session){
		user user= (user) session.getattribute("user");
		list<hotelorders> hotel_orders=hotel_ordersservice.hotel_orders(user.getid());
		return hotel_orders;
	}
 
 
 
	/**
	 * 根据id查询
	 * @param id id
	 * @return
	 */
	@responsebody
	@requestmapping(value="/{id}",method= requestmethod.get)
	public result findbyid(@pathvariable long id){
		return new result(true,statuscode.ok,"查询成功",ordersservice.findbyid(id));
	}
 
 
	/**
	 * 分页+多条件查询
	 * @param searchmap 查询条件封装
	 * @param page 页码
	 * @param size 页大小
	 * @return 分页结果
	 */
	@responsebody
	@requestmapping(value="/search/{page}/{size}",method=requestmethod.post)
	public result findsearch(@requestbody map searchmap , @pathvariable int page, @pathvariable int size){
		page<orders> pagelist = ordersservice.findsearch(searchmap, page, size);
		return  new result(true,statuscode.ok,"查询成功",  new pageresult<orders>(pagelist.gettotalelements(), pagelist.getcontent()) );
	}
 
	/**
     * 根据条件查询
     * @param searchmap
     * @return
     */
	@responsebody
    @requestmapping(value="/search",method = requestmethod.post)
    public result findsearch( @requestbody map searchmap){
        return new result(true,statuscode.ok,"查询成功",ordersservice.findsearch(searchmap));
    }
	
	/**
	 * 订单添加操作
	 * @param orders
	 */
	@responsebody
	@requestmapping(value ="/add",method=requestmethod.post)
	public result add(orders orders, httpsession session){
		//获取数量
		user user = (user) session.getattribute("user");
		if (user == null){
			return new result(false,statuscode.accesserror,"请登录");
		}
 
		return ordersservice.add(orders,user.getid(),orders.getid(),orders.getqty());
	}
	
	/**
	 * 修改
	 * @param
	 */
	@responsebody
	@requestmapping(value="/{id}",method= requestmethod.put)
	public result update(@pathvariable long id){
		ordersservice.updatestatus(id);
		return new result(true,statuscode.ok,"修改成功");
	}
	
	/**
	 * 删除
	 * @param id
	 */
	@responsebody
	@requestmapping(value="/{id}",method= requestmethod.delete)
	public result delete(@pathvariable long id ){
		ordersservice.deletebyid(id);
		return new result(true,statuscode.ok,"删除成功");
	}
 
	@requestmapping(value = "/orderslist")
	public string orderslist(){
		return "admin/ordersmanage/orderslist";
	}
 
 
	/**
	 * 酒店评分
	 * @param hotel
	 * @return
	 */
	@responsebody
	@postmapping("/hotelorderstar")
	public result hotelorderstar(hotel hotel,@requestparam("orderid")long orderid){
		long id = hotel.getid();
		hotel newhotel = hotelservice.findbyid(id);
		if(newhotel==null){
			return new result(false,statuscode.error,"未找到该酒店!");
		}
		integer currentstar = hotel.getstar();
		integer totalstar = newhotel.getstar();
		if(currentstar<0){
			return new result(false,statuscode.error,"请选择评分!");
		}
		integer commentcount = newhotel.getcommentcount();
		commentcount=commentcount+1;
		totalstar=currentstar+totalstar;
		int avgstar = totalstar / commentcount;
		hotel.setcommentcount(commentcount);
		hotel.setstar(avgstar);
		integer hotel1 = hotelservice.updatestar(hotel);
		hotel_ordersservice.updatestarstatus(orderid);
		if(hotel1==null){
			return new result(false,statuscode.error,"评分更新失败!");
		}
		return new result(true,statuscode.ok,"评价成功!");
	}
 
	/**
	 * 景点评分
	 * @param scenic
	 * @return
	 */
	@responsebody
	@postmapping("/travelorderstar")
	public result travelorderstar(scenic scenic,@requestparam("orderid")long orderid){
		long id = scenic.getid();
		scenic newscenic = scenicservice.findbyid(id);
		if(newscenic==null){
			return new result(false,statuscode.error,"未找到该景点!");
		}
		integer totalstar = newscenic.getstart();
		integer currentstar = scenic.getstart();
		if(currentstar<0){
			return new result(false,statuscode.error,"请选择评分!");
		}
		integer commentcount = newscenic.getcommentcount();
		commentcount=commentcount+1;
		totalstar=currentstar+totalstar;
		int avgstar = totalstar / commentcount;
		scenic.setcommentcount(commentcount);
		scenic.setstart(avgstar);
		integer scenic1 = scenicservice.updatestar(scenic);
		ordersservice.updatestarstatus(orderid);
		if(scenic1==null){
			return new result(false,statuscode.error,"评分更新失败!");
		}
		return new result(true,statuscode.ok,"评价成功!");
	}
 
 
}

到此这篇关于java 实战项目之诚途旅游系统的实现流程的文章就介绍到这了,更多相关java 旅游系统内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!