分享好友 最新资讯首页 最新资讯分类 切换频道
基于微信小程序的电影订票系统(后端代码)
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);
最新文章
删了微信好友怎么加回来
在使用微信的过程中,我们可能会因为各种原因不小心删除了某些好友。当意识到这一操作时,很多人会感到懊恼,尤其是对于那些重要
50个小学生百科知识来挑战快问快答!__2
网上科普有关“50个小学生百科知识来挑战快问快答!_”话题很是火热,小编也是针对50个小学生百科知识来挑战快问快答!_寻找了一
中国十大镜片品牌排行榜,mikibobo镜片属于什么档次,极致性价比
选一个好镜片,就像选一个好手机,不但用着好,而且是身份地位的象征。市场有不同规格和价位段的产品。有进口的高端的镜片,有国
五河网站排名优化费用是如何计算的?
五河SEO网站优化提升自然流量的方式有哪些?五河优化长尾关键词,虽然这些关键词无法在短期内给网站带来更多流量,但对网站的长
外贸网站全球推广与SEO国际化策略指南
外贸网站国际化推广与SEO优化全攻略,涵盖多语言、文化适应性、关键词研究、本地化内容策略、链接建设、移动优化等关键步骤。通
seo 关键词排名报价方案分析:费用与网站项目维度规模等有关
SEO关键词排名报价可谓五花八门,很多SEO外包公司都喜欢提供,这也导致了很多甲方客户对SEO行业的普遍印象偏低,那么SEO外包的报
【A3360快速问医生下载】HTC A3360快速问医生12.3.0免费下载
身体不舒服?找快速问医生,随时随地免费问医生~~网上问诊,首选快速问医生APP,累计已服务数千万患者。在线医务工作者实名认证
360网站收录有什么用 360网站收录:提升曝光,助力SEO优化
在当今这个信息爆炸的时代,互联网已成为企业展示自身形象、推广产品与服务、吸引潜在客户的关键舞台而在这一浩瀚的网络海洋中,
小米新专利聚焦数据推荐技术,提升检索模型预测能力
2024年12月12日,金融界报道,北京小米移动软件有限公司申请了一项名为“数据推荐方法、装置、电子设备及存储介质”的专利,公开
2025年度食堂食材【非八大类食材(蔬菜、水产、干货类)】配送服务项目中标结果公示
序号投标供应商名称资格响应文件1深圳市新源农产品供应链有限公司按要求提供《投标人基本情况表》;按要求提供营业执照;按要求