puzhibing
2023-07-18 2386300f1ed591e6c46b7f32539cac7f2fd7d434
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package com.dsh.other.service.impl;
 
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dsh.other.entity.Site;
import com.dsh.other.entity.SiteBooking;
import com.dsh.other.entity.SiteType;
import com.dsh.other.entity.Store;
import com.dsh.other.mapper.SiteMapper;
import com.dsh.other.model.QuerySiteInfoVo;
import com.dsh.other.model.QuerySiteList;
import com.dsh.other.model.QuerySiteListVo;
import com.dsh.other.model.QuerySiteTimes;
import com.dsh.other.service.ISiteBookingService;
import com.dsh.other.service.ISiteService;
import com.dsh.other.service.ISiteTypeService;
import com.dsh.other.service.StoreService;
import com.dsh.other.util.GeodesyUtil;
import com.dsh.other.util.ToolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.text.SimpleDateFormat;
import java.util.*;
 
/**
 * @author zhibing.pu
 * @date 2023/7/13 16:11
 */
@Service
public class SiteServiceImpl extends ServiceImpl<SiteMapper, Site> implements ISiteService {
 
    @Autowired
    private ISiteTypeService siteTypeService;
 
    @Autowired
    private StoreService storeService;
 
    @Autowired
    private ISiteBookingService siteBookingService;
 
 
 
 
 
    /**
     * 获取场地列表
     * @param querySiteList
     * @return
     * @throws Exception
     */
    @Override
    public List<QuerySiteListVo> querySiteList(QuerySiteList querySiteList) throws Exception {
        querySiteList.setPageNum((querySiteList.getPageNum() - 1) *querySiteList.getPageSize());
        List<QuerySiteListVo> querySiteListVos = this.baseMapper.querySiteList(querySiteList);
        for (QuerySiteListVo querySiteListVo : querySiteListVos) {
            if(ToolUtil.isEmpty(querySiteList.getLon())){
                querySiteListVo.setDistance(0D);
                continue;
            }
            Map<String, Double> distance = GeodesyUtil.getDistance(querySiteList.getLon() + "," + querySiteList.getLat(), querySiteListVo.getStoreLon() + "," + querySiteListVo.getStoreLat());
            querySiteListVo.setDistance(distance.get("WGS84"));
        }
        return querySiteListVos;
    }
 
 
    /**
     * 获取场地详情
     * @param id
     * @return
     * @throws Exception
     */
    @Override
    public QuerySiteInfoVo querySiteInfo(Integer id) throws Exception {
        Site site = this.getById(id);
        SiteType siteType = siteTypeService.getById(site.getSiteTypeId());
        Store store = storeService.getById(site.getStoreId());
        QuerySiteInfoVo querySiteInfoVo = new QuerySiteInfoVo();
        querySiteInfoVo.setId(site.getId());
        querySiteInfoVo.setName(site.getName());
        querySiteInfoVo.setSiteTypeName(siteType.getName());
        querySiteInfoVo.setStoreName(store.getName());
        querySiteInfoVo.setStoreAddress(store.getAddress());
        querySiteInfoVo.setStoreLon(store.getLon());
        querySiteInfoVo.setStoreLat(store.getLat());
        querySiteInfoVo.setStorePhone(store.getPhone());
        querySiteInfoVo.setCashPrice(site.getCashPrice());
        querySiteInfoVo.setPlayPaiCoin(site.getPlayPaiCoin());
        return querySiteInfoVo;
    }
 
 
    /**
     * 获取场地预约日期数据
     * @param id
     * @param day
     * @return
     * @throws Exception
     */
    @Override
    public List<QuerySiteTimes> querySiteTimes(Integer id, String day) throws Exception {
        Site site = this.getById(id);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Calendar s = Calendar.getInstance();
        s.setTime(sdf.parse(day + " " + site.getAppointmentStartTime()));
        Calendar e = Calendar.getInstance();
        e.setTime(sdf.parse(day + " " + site.getAppointmentEndTime()));
 
        int hour = e.get(Calendar.HOUR_OF_DAY);
        int minute = e.get(Calendar.MINUTE);
        List<QuerySiteTimes> list = new ArrayList<>();
        while (true){
            int s_hour = s.get(Calendar.HOUR_OF_DAY);
            int s_minute = s.get(Calendar.MINUTE);
            String start = s_hour + ":" + s_minute;
 
            s.set(Calendar.MINUTE, s.get(Calendar.MINUTE) + 30);
            int e_hour = s.get(Calendar.HOUR_OF_DAY);
            int e_minute = s.get(Calendar.MINUTE);
            String end = e_hour + ":" + e_minute;
 
            QuerySiteTimes querySiteTimes = new QuerySiteTimes();
            querySiteTimes.setTime(start + "-" + end);
            querySiteTimes.setSelectable(1);
 
            SiteBooking siteBooking = siteBookingService.getOne(new QueryWrapper<SiteBooking>().eq("siteId", id).eq("state", 1)
                    .in("status", Arrays.asList(3, 4, 5)).last(" and DATE_FORMAT(startTime, '%Y-%m-%d %H:%i') <= '" + day + " " + start + "' and DATE_FORMAT(endTime, '%Y-%m-%d %H:%i') >= '" + day + " " + end + "'"));
            if(null != siteBooking){
                querySiteTimes.setSelectable(0);
            }
            list.add(querySiteTimes);
 
            if(e_hour == hour && minute == e_minute){
                break;
            }
        }
        return list;
    }
}