无关风月
2024-12-11 4d7a208f388e42e7dd83dab0e38eadfa0847de1c
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
142
143
144
145
146
147
148
149
150
151
package com.ruoyi.chargingPile.service.impl;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.chargingPile.api.dto.GetSiteListDTO;
import com.ruoyi.chargingPile.api.feignClient.SiteClient;
import com.ruoyi.chargingPile.api.model.Site;
import com.ruoyi.chargingPile.api.model.TParkingLot;
import com.ruoyi.chargingPile.api.model.TParkingRecord;
import com.ruoyi.chargingPile.api.query.ParkingRecordQuery;
import com.ruoyi.chargingPile.api.vo.TParkingRecordPageInfoVO;
import com.ruoyi.chargingPile.api.vo.TParkingRecordVO;
import com.ruoyi.chargingPile.dto.ParkingRecordQueryDto;
import com.ruoyi.chargingPile.mapper.SiteMapper;
import com.ruoyi.chargingPile.mapper.TParkingLotMapper;
import com.ruoyi.chargingPile.mapper.TParkingRecordMapper;
import com.ruoyi.chargingPile.service.TParkingRecordService;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaochen
 * @since 2024-08-08
 */
@Service
public class TParkingRecordServiceImpl extends ServiceImpl<TParkingRecordMapper, TParkingRecord> implements TParkingRecordService {
 
    @Autowired
    private SiteMapper siteMapper;
    @Autowired
    private TParkingLotMapper parkingLotMapper;
    @Resource
    private SiteClient siteClient;
 
    @Override
    public BigDecimal getSum(LocalDate sixBefore) {
        return this.baseMapper.getSum(sixBefore);
    }
 
    @Autowired
    private TokenService tokenService;
    @Override
    public TParkingRecordPageInfoVO pageList(ParkingRecordQuery query) {
        Long userId = tokenService.getLoginUser().getUserid();
        //如果没传siteId,获取当前登陆人所有的siteIds
        List<Integer> siteIds = new ArrayList<>();
        if (query.getSiteId()==null){
            if (userId != null){
                List<GetSiteListDTO> data = siteClient.getSiteListByUserId(userId).getData();
                for (GetSiteListDTO datum : data) {
                    siteIds.add(datum.getId());
                }
            }
        }else {
            siteIds.add(query.getSiteId());
        }
        if (siteIds.isEmpty()){
            siteIds.add(-1);
        }
        query.setSiteIds(siteIds);
        PageInfo<TParkingRecordVO> pageInfo = new PageInfo<>(query.getPageCurr(),query.getPageSize());
        // 查询站点的停车场id
        if(Objects.nonNull(query.getSiteId())){
            Site site = siteMapper.selectById(query.getSiteId());
            if (site!=null){
                List<TParkingLot> tParkingLots = parkingLotMapper.selectList(Wrappers.lambdaQuery(TParkingLot.class)
                        .eq(TParkingLot::getSiteId, site.getId()));
                List<Integer> lotIds = tParkingLots.stream().map(TParkingLot::getId).collect(Collectors.toList());
                if(CollectionUtils.isEmpty(lotIds)){
                    TParkingRecordPageInfoVO tParkingRecordPageInfoVO = new TParkingRecordPageInfoVO();
                    tParkingRecordPageInfoVO.setParkingRecordVOS(new PageInfo<TParkingRecordVO>());
                    return tParkingRecordPageInfoVO;
                }
                query.setLotIds(lotIds);
            }
 
        }
        List<TParkingRecordVO> list = this.baseMapper.pageList(query,pageInfo);
        for (TParkingRecordVO tParkingRecordVO : list) {
            if (tParkingRecordVO.getParkingDuration()==null){
                tParkingRecordVO.setFeeDuration(0);
            }else if(tParkingRecordVO.getFreeDuration()==null){
                tParkingRecordVO.setFeeDuration(tParkingRecordVO.getParkingDuration());
            }else{
                tParkingRecordVO.setFeeDuration(tParkingRecordVO.getParkingDuration()-tParkingRecordVO.getFreeDuration());
            }
            tParkingRecordVO.setOrderAmount(tParkingRecordVO.getOrderAmount()!=null?tParkingRecordVO.getOrderAmount():new BigDecimal("0")
                    .add(tParkingRecordVO.getTimeoutAmount()!=null?tParkingRecordVO.getTimeoutAmount():new BigDecimal("0")));
            tParkingRecordVO.setParkingFee(tParkingRecordVO.getOrderAmount());
        }
        pageInfo.setRecords(list);
        // 查询总数
        TParkingRecordPageInfoVO infoVO = this.baseMapper.getParkingRecordCount(query);
        if (infoVO==null){
            infoVO = new TParkingRecordPageInfoVO();
            infoVO.setTimeoutAmountSum(new BigDecimal("0"));
            infoVO.setOrderCount(0);
            infoVO.setParkingDurationSum(0);
            infoVO.setFeeDurationSum(0);
        }
        infoVO.setParkingRecordVOS(pageInfo);
        return infoVO;
    }
 
    @Override
    public List<Map<String, Object>> parkingData(ParkingRecordQueryDto parkingRecordQueryDto) {
        return this.baseMapper.parkingData(parkingRecordQueryDto);
    }
 
    @Override
    public List<Map<String, Object>> parkingDataByDate(ParkingRecordQueryDto parkingRecordQueryDto) {
        return this.baseMapper.parkingDataByDate(parkingRecordQueryDto);
    }
 
    @Override
    public List<Map<String, Object>> getCarColor(ParkingRecordQueryDto parkingRecordQueryDto) {
        return this.baseMapper.getCarColor(parkingRecordQueryDto);
    }
 
    @Override
    public List<Map<String, Object>> getOutType(ParkingRecordQueryDto parkingRecordQueryDto) {
        return this.baseMapper.getOutType(parkingRecordQueryDto);
    }
 
    @Override
    public List<Map<String, Object>> getIsCharge(ParkingRecordQueryDto parkingRecordQueryDto) {
        return this.baseMapper.getIsCharge(parkingRecordQueryDto);
    }
 
    @Override
    public List<Map<String, Object>> income(ParkingRecordQueryDto parkingRecordQueryDto) {
        return this.baseMapper.income(parkingRecordQueryDto);
    }
}