分享好友 最新资讯首页 最新资讯分类 切换频道
基于微信小程序的电影订票系统(后端代码)
2024-11-26 03:22
package com.moke.wp.wx_weimai.service;

基于微信小程序的电影订票系统(后端代码)

import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.moke.wp.wx_weimai.config.es.CinemaRepository; import com.moke.wp.wx_weimai.config.exception.QQMapException; import com.moke.wp.wx_weimai.entity.Cinema; import com.moke.wp.wx_weimai.entity.CinemaBrand; import com.moke.wp.wx_weimai.entity.Vo.CinemaFilter; import com.moke.wp.wx_weimai.entity.Vo.CinemaVo; import com.moke.wp.wx_weimai.entity.Vo.SelectCity; import com.moke.wp.wx_weimai.mapper.CinemaBrandMapper; import com.moke.wp.wx_weimai.mapper.HallTypeMapper; import com.moke.wp.wx_weimai.config.map.QQMapUtil; import com.moke.wp.wx_weimai.config.util.Constant; import com.moke.wp.wx_weimai.config.util.HttpClientUtil; import com.moke.wp.wx_weimai.config.util.PageBean; import com.moke.wp.wx_weimai.entity.Vo.AdminCinema; import com.moke.wp.wx_weimai.mapper.CinemaMapper; import org.elasticsearch.common.unit.DistanceUnit; import org.elasticsearch.index.query.*; import org.elasticsearch.search.sort.GeoDistanceSortBuilder; import org.elasticsearch.search.sort.SortOrder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.elasticsearch.core.geo.GeoPoint; import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.*; import java.util.concurrent.TimeUnit; @Service public class CinemaService { @Autowired private RedisTemplate redisTemplate; @Autowired private CinemaMapper cinemaMapper; @Autowired private HallTypeMapper hallTypeMapper; @Autowired private CinemaBrandMapper cinemaBrandMapper; @Autowired private CinemaRepository cinemaRepository; public PageBean<CinemaVo> getCinemas(Integer movieId, String date, Integer pageNum, Integer limit, SelectCity cityInfo, Integer brandId, Integer serviceId, Integer hallType, String selectRegion) { // String key = "CinemasList,"; // if(movieId!=null) // key += movieId +","; // if(date!=null) // key += date + ","; // if(pageNum!=null) // key += pageNum + ","; // if(limit!=null) // key += cityInfo.getCityName() + ","; // if(brandId!=null) // key += brandId + ","; // if(serviceId!=null) // key += serviceId + ","; // if(hallType!=null) // key += hallType + ","; // if(selectRegion!=null) // key += selectRegion; // PageBean<CinemaVo> cinemaVoPageBean = (PageBean<CinemaVo>)redisTemplate.opsForValue().get(key); // if(cinemaVoPageBean!=null) // return cinemaVoPageBean; PageHelper.startPage(pageNum,limit); List<Cinema> cinemaList = cinemaMapper.getCinemas(movieId,date, cityInfo.getLatitude(),cityInfo.getLongitude(),cityInfo.getCityName(), brandId,serviceId,hallType,selectRegion); List<CinemaVo> cinemaVoList = new ArrayList<CinemaVo>(); BigDecimal tmp = new BigDecimal(1000); for(Cinema cinema : cinemaList){ cinema.setDistance(cinema.getDistance().divide(tmp).setScale(1,BigDecimal.ROUND_HALF_UP)); CinemaVo cinemaVo = new CinemaVo(); cinemaVo.setCinema(cinema); cinemaVo.setHallTypeList(hallTypeMapper.getHallTypeByCinemaId(cinema.getId())); cinemaVoList.add(cinemaVo); } PageInfo pageInfo = new PageInfo(cinemaList); PageBean<CinemaVo> page = new PageBean<CinemaVo>(); page.setPc(pageInfo.getPageNum()); page.setPs(pageInfo.getSize()); page.setTr(pageInfo.getPages()); page.setBeanList(cinemaVoList); // redisTemplate.opsForValue().set(key,page); // redisTemplate.expire(key,10,TimeUnit.MINUTES); return page; } public CinemaFilter getfilters(SelectCity cityInfo) { String key = "filter,"+cityInfo.getCityName(); CinemaFilter filter = (CinemaFilter) redisTemplate.opsForValue().get(key); if(filter!=null) return filter; CinemaFilter cinemaFilter = new CinemaFilter(); CinemaBrand cinemaBrand = new CinemaBrand(); cinemaBrand.setId(-1); cinemaBrand.setBrand("全部"); cinemaFilter.setCinemaBrandList(cinemaBrandMapper.getAll()); cinemaFilter.getCinemaBrandList().add(0,cinemaBrand); cinemaFilter.setHallTypeList(hallTypeMapper.getAll()); //获取 Map<String,String> map = new HashMap<>(); map.put("key",Constant.QQ_MAP_KEY); map.put("keyword",cityInfo.getCityName()); JSONObject object = JSONObject.parseObject(HttpClientUtil.doGet(Constant.QQ_MAP_SEARCH,map)); try { if(!object.getString("status").equals("0")) throw new QQMapException("QQ_MAP错误"); } catch (QQMapException e) { e.printStackTrace(); } JSONObject city = object.getJSONArray("result").getJSONArray(0).getJSONObject(0); map.remove("keyword"); map.put("id",city.getString("id")); object = JSONObject.parseObject(HttpClientUtil.doGet(Constant.QQ_MAP_DISTRICT,map)); try { if(!object.getString("status").equals("0")) throw new QQMapException("QQ_MAP错误"); } catch (QQMapException e) { e.printStackTrace(); } JSONArray tmp_district = object.getJSONArray("result").getJSONArray(0); List<String> district = new ArrayList<String>(); district.add("全城"); for(int i=0;i<tmp_district.size();i++){ JSONObject tmp = tmp_district.getJSONObject(i); district.add(tmp.getString("fullname")); } cinemaFilter.setDistrict(district); redisTemplate.opsForValue().set(key,cinemaFilter); redisTemplate.expire(key,1, TimeUnit.HOURS); return cinemaFilter; } public Cinema getCinemaByName(String nm) { Cinema cinema = new Cinema(); cinema.setNm(nm); return cinemaMapper.selectOne(cinema); } public void insertCinema(Cinema cinema) { cinemaMapper.insert(cinema); cinema.setLocation(new GeoPoint(cinema.getLatitude().doubleValue(),cinema.getLongitude().doubleValue())); //cinemaRepository.index(cinema); } public Page<Cinema> findPage(String keyword,double latitude, double longitude, Pageable pageable) { // 实现了SearchQuery接口,用于组装QueryBuilder和SortBuilder以及Pageable等 NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder(); // 分页 nativeSearchQueryBuilder.withPageable(pageable); // BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder(); // WildcardQueryBuilder queryBuilder1 = QueryBuilders.wildcardQuery("nm", "*"+keyword+"*"); // WildcardQueryBuilder queryBuilder2 = QueryBuilders.wildcardQuery("addr", "*"+keyword+"*"); // boolQueryBuilder.should(queryBuilder1); // boolQueryBuilder.should(queryBuilder2); QueryStringQueryBuilder queryBuilder = new QueryStringQueryBuilder(keyword); queryBuilder.analyzer("ik_smart"); queryBuilder.field("nm").field("addr"); // // 以某点为中心,搜索指定范围 // GeoDistanceQueryBuilder distanceQueryBuilder = new GeoDistanceQueryBuilder("location"); // distanceQueryBuilder.point(latitude, longitude); // // 定义查询单位:公里 // distanceQueryBuilder.distance(distance, DistanceUnit.KILOMETERS); // boolQueryBuilder.filter(distanceQueryBuilder);
最新文章
【系统架构设计】计算机网络
OSI/RM 结构模型 1977年,国际标准化组织为适应网络标准化发展的需求,制定了开放系统互联参考模型(Open System Interconnectio
全世界规模最大战争排名,第一名居然是清朝时期!
自打人类走上进化这条路,就想着法儿想要证明【一伙人就该被另一伙人支配】。古罗马角斗士时代一方有多大势力,就看他有多少人的
python tk随机内容生成器
MyRandom ran=new MyRandom();System.out.println(ran.nextString(1));System.out.println(ran.nextString(50, OnlyNum));System
ai自动写文章在线 在线写文章自动生成器
身为文案工作者,我深感写作之重要且充满挑战。如今,随着人工智能(AI)写作平台的出现,我的写作历程出现了巨大变革。在此,很
AI写系统性综述ChatGPT还远远不够未来百年能否实现
在科学研究的浩瀚海洋中,科研人员时常面临一个棘手的问题:如何有效整合和理解海量的科学文献。尽管网络的普及极大地丰富了文献
全球AI半导体技术排名:韩国强势第三,未来发展值得关注
近年来,人工智能(AI)技术的迅猛发展促进了相关硬件的创新,尤其是AI半导体的需求日益上升。根据最新的研究报告和韩国媒体的报
MVSO影视程序源码 影视自动采集_魔改超强SEO_自定义苹果cms资源站接口
?php// +----------------------------------------------------------------------// | ThinkPHP [ WE CAN DO IT JUST THINK ]/
多地楼市政策不断优化 房地产市场企稳态势渐明
原标题:多地楼市政策不断优化 房地产市场企稳态势渐明来源:人民网近日,海南省住房公积金管理局发布《关于调整优化住房公积金
新澳正版资料免费大全,词语作答释义解释汇总
随着互联网的普及和在线信息资源的丰富,人们对于各类资料的需求日益增长,在新时代,获取正版资料显得尤为重要,本文将介绍新澳
揭秘快速排名SEO软件,网站高效提升排名的秘密武器
快速排名SEO软件,是网站提升排名的得力助手。它通过优化关键词、内容布局和链接策略,帮助网站在搜索引擎中迅速提升排名,实现