luodangjia
2024-09-12 c5462d60b99823adb10d9e9eda671920118538f7
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
package com.ruoyi.chargingPile.controller;
 
 
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.*;
import com.ruoyi.chargingPile.dto.ParkingRecordPageQuery;
import com.ruoyi.chargingPile.dto.ParkingRecordQueryDto;
import com.ruoyi.chargingPile.export.TParkingRecordExport;
import com.ruoyi.chargingPile.service.TParkingLotService;
import com.ruoyi.chargingPile.service.TParkingRecordService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.WebUtils;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.order.api.query.TOrderInvoiceQuery;
import com.ruoyi.order.api.vo.TCharingUserEquimentVO;
import com.ruoyi.order.api.vo.TOrderInvoiceVO;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2024-08-08
 */
@RestController
@RequestMapping("/t-parking-record")
public class TParkingRecordController {
    @Resource
    private TParkingRecordService parkingRecordService;
    @Resource
    private TParkingLotService parkingLotService;
 
    @ApiOperation(tags = {"后台-订单管理-停车记录"},value = "列表")
    @PostMapping(value = "/page")
    public R<Page<TParkingRecord>> page(@RequestBody ParkingRecordPageQuery query) {
        Page<TParkingRecord> page = parkingRecordService.lambdaQuery().ge(query.getStart() != null, TParkingRecord::getCreateTime, query.getStart())
                .le(query.getEnd() != null, TParkingRecord::getCreateTime, query.getEnd())
                .like(query.getLicensePlate() != null, TParkingRecord::getLicensePlate, query.getLicensePlate())
                .eq(query.getStatus() != null, TParkingRecord::getStatus, query.getStatus())
                .eq(query.getOutParkingType() != null, TParkingRecord::getOutParkingType, query.getOutParkingType())
                .page(Page.of(query.getPageCurr(), query.getPageSize()));
 
        for (TParkingRecord record : page.getRecords()) {
            record.setName(parkingLotService.getById(record.getParkingLotId()).getName());
            record.setUid(record.getId().toString());
        }
        return R.ok(page);
    }
 
    @ApiOperation(tags = {"后台-订单管理-停车记录"},value = "停车缴费订单列表")
    @PostMapping(value = "/pageList")
    public R<TParkingRecordPageInfoVO> pageList(@RequestBody ParkingRecordQuery query) {
        return R.ok(parkingRecordService.pageList(query));
    }
    @ApiOperation(tags = {"后台-订单管理-停车记录"},value = "导出")
    @PutMapping("/export")
    public void export(@RequestBody ParkingRecordQuery query)
    {
        List<TParkingRecordVO> records = parkingRecordService.pageList(query).getParkingRecordVOS().getRecords();
        List<TParkingRecordExport> orderInvoiceExports = new ArrayList<>();
        for (TParkingRecordVO orderInvoiceVO : records) {
            TParkingRecordExport orderInvoiceExport = new TParkingRecordExport();
            BeanUtils.copyProperties(orderInvoiceVO,orderInvoiceExport);
            if (orderInvoiceVO.getFreeDuration()!=null){
                orderInvoiceExport.setParkingDuration(orderInvoiceVO.getParkingDuration()-orderInvoiceVO.getFreeDuration());
            }else{
                orderInvoiceExport.setParkingDuration(orderInvoiceVO.getParkingDuration());
            }
            if (orderInvoiceVO.getTimeoutAmount()!=null){
                orderInvoiceExport.setAmount(orderInvoiceVO.getOrderAmount().subtract(orderInvoiceVO.getTimeoutAmount()));
            }else{
                orderInvoiceExport.setAmount(orderInvoiceVO.getOrderAmount());
            }
            orderInvoiceExports.add(orderInvoiceExport);
        }
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TParkingRecordExport.class, orderInvoiceExports);
        HttpServletResponse response = WebUtils.response();
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        ServletOutputStream outputStream = null;
        try {
            String fileName = URLEncoder.encode("停车记录.xls", "utf-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setHeader("Pragma", "no-cache");
            response.setHeader("Cache-Control", "no-cache");
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    @ApiOperation(tags = {"后台-订单管理-停车记录"},value = "详情")
    @GetMapping(value = "/detail")
    public R<TParkingRecord> detail(Long id) {
      return R.ok(parkingRecordService.getById(id));
    }
 
    @ApiOperation(tags = {"后台-订单管理-停车记录"},value = "出场")
    @GetMapping(value = "/out")
    public R out(Long id) {
        TParkingRecord byId = parkingRecordService.getById(id);
        byId.setStatus(2);
        parkingRecordService.updateById(byId);
        return R.ok();
 
    }
    
    
    /**
     * 根据车牌和状态查询停车数据
     * @param query
     * @return
     */
    @PostMapping("/getParkingRecord")
    public R<TParkingRecord> getParkingRecord(@RequestBody GetParkingRecord query){
        TParkingRecord one = parkingRecordService.getOne(new LambdaQueryWrapper<TParkingRecord>()
                .eq(TParkingRecord::getLicensePlate, query.getLicensePlate()).eq(TParkingRecord::getStatus, query.getStatus()));
        return R.ok(one);
    }
    
    
    /**
     * 修改停车数据
     * @param parkingRecord
     */
    @PostMapping("/updateParkingRecord")
    public void updateParkingRecord(@RequestBody TParkingRecord parkingRecord){
        parkingRecordService.updateById(parkingRecord);
    }
    
    
    /**
     * 根据id获取数据
     * @param id
     * @return
     */
    @PostMapping("/getParkingRecordById")
    public R<TParkingRecord> getParkingRecordById(@RequestParam("id") Long id){
        TParkingRecord parkingRecord = parkingRecordService.getById(id);
        return R.ok(parkingRecord);
    }
    
    
    /**
     * 添加数据
     * @param parkingRecord
     */
    @PostMapping("/addParkingRecord")
    public void addParkingRecord(@RequestBody TParkingRecord parkingRecord){
        parkingRecordService.save(parkingRecord);
    }
 
    @ResponseBody
    @PostMapping(value = "/parking/data")
    @ApiOperation(value = "统计", tags = {"管理后台-数据分析-车场运营分析"})
    public R<TParkLotRecordVO> data(@RequestBody ParkingRecordQueryDto parkingRecordQueryDto){
        //上方折线图
        TParkLotRecordVO tParkLotRecordVO = new TParkLotRecordVO();
 
        if (parkingRecordQueryDto.getDayType()==1) {
            List<Map<String, Object>> maps = parkingRecordService.parkingData(parkingRecordQueryDto);
            tParkLotRecordVO.setMaps(maps);
        }else {
            List<Map<String, Object>> maps = parkingRecordService.parkingDataByDate(parkingRecordQueryDto);
            tParkLotRecordVO.setMaps(maps);
        }
 
        //车辆类型饼图
        List<Map<String, Object>> carColor  =   parkingRecordService.getCarColor(parkingRecordQueryDto);
 
        //出场类型
        List<Map<String, Object>> outType  =   parkingRecordService.getOutType(parkingRecordQueryDto);
 
        //进场充电占比
        List<Map<String, Object>> isCharge  =   parkingRecordService.getIsCharge(parkingRecordQueryDto);
 
 
        tParkLotRecordVO.setCarColor(carColor);
        tParkLotRecordVO.setOutType(outType);
        tParkLotRecordVO.setIsCharge(isCharge);
        return R.ok(tParkLotRecordVO);
 
    }
 
 
    @ResponseBody
    @PostMapping(value = "/parking/work")
    @ApiOperation(value = "停车订单统计", tags = {"管理后台-工作台"})
    public R<TParkLotRecordCountVo> work(@RequestBody ParkingRecordQueryDto parkingRecordQueryDto){
        List<TParkingRecord> list = parkingRecordService.lambdaQuery().eq(parkingRecordQueryDto.getParkingLotId() != null, TParkingRecord::getParkingLotId, parkingRecordQueryDto.getParkingLotId())
                .between(TParkingRecord::getCreateTime, parkingRecordQueryDto.getStartTime(), parkingRecordQueryDto.getEndTime()).list();
        int count1 = list.size();
        //统计出list中chargingOrderId为null的数据个数
        int count2 = list.stream().filter(item -> item.getChargingOrderId() == null).collect(Collectors.toList()).size();
        int count3 = count1-count2;
        //计算出list中parkingDuration的总和
        int count4 = 0;
        for (TParkingRecord tParkingRecord : list) {
            count4 = count4+tParkingRecord.getParkingDuration();
        }
        //计算出list中orderAmount的总和
        BigDecimal count5 = list.stream().map(TParkingRecord::getOrderAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
 
        TParkLotRecordCountVo tParkLotRecordCountVo = new TParkLotRecordCountVo();
        tParkLotRecordCountVo.setCount1(count1);
        tParkLotRecordCountVo.setCount2(count2);
        tParkLotRecordCountVo.setCount3(count3);
        tParkLotRecordCountVo.setCount4(count4);
        tParkLotRecordCountVo.setCount5(count5);
 
        return R.ok(tParkLotRecordCountVo);
 
    }
 
    @ResponseBody
    @PostMapping(value = "/parking/income")
    @ApiOperation(value = "停车收入统计", tags = {"管理后台-工作台"})
    public R income(@RequestBody ParkingRecordQueryDto parkingRecordQueryDto){
 
       List<Map<String,Object>>  maps =  parkingRecordService.income(parkingRecordQueryDto);
        return R.ok(maps);
    }
}