kongdeqiang
2023-03-02 ee83188936c8ac306144f6c8cd119b6d7574dfc6
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
package com.boying.controller;
 
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.boying.common.R;
import com.boying.entity.OrderRecord;
import com.boying.entity.OutPark;
import com.boying.entity.User;
import com.boying.entity.vo.OrderRecordVo;
import com.boying.service.OrderRecordService;
import com.boying.service.OutParkService;
import com.boying.service.ParkService;
import com.boying.service.UserService;
import io.swagger.models.auth.In;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.logging.Handler;
import java.util.stream.Collectors;
 
@RestController
@RequestMapping("orderrecord")
@RequiredArgsConstructor
public class OrderRecordController {
 
    private final OrderRecordService orderRecordService;
    private final OutParkService outParkService;
    private final ParkService parkService;
    private final UserService userService;
 
    @PostMapping("/getByCarNo")
    public Object getByCarNo(Page page,String carNo,String month,String phone) {
        List<OrderRecordVo> recordVos = new ArrayList<>();
        QueryWrapper<OrderRecord> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(OrderRecord::getCarNo,carNo)
                .eq(OrderRecord::getTicketStatus,1)
                .like(OrderRecord::getUpdateTime,month)
                .orderByDesc(OrderRecord::getCreateTime);
        Page page1 = orderRecordService.page(page, wrapper);
        List<OrderRecord> records = page1.getRecords();
        if(records.size()>0){
            for (OrderRecord orderRecord : records) {
                OutPark byId = outParkService.getById(orderRecord.getQueryId());
                OrderRecordVo orderRecordVo = new OrderRecordVo();
                BeanUtils.copyProperties(orderRecord,orderRecordVo);
                orderRecordVo.setEnterTime(byId.getEnterTime());
                orderRecordVo.setOutTime(byId.getCreateTime());
                orderRecordVo.setParkName(parkService.getById(byId.getParkId()).getName());
                recordVos.add(orderRecordVo);
            }
            page1.setRecords(recordVos);
            return R.ok(page1);
        }else {
            return R.failed("暂无数据");
        }
    }
 
    @PostMapping("/findCountPage")
    public Object findCountPage(Integer parkId,String startTime,String endTime) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        QueryWrapper<OutPark> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(parkId != null,OutPark::getParkId,parkId)
                .isNotNull(OutPark::getPayCode)
                .eq(OutPark::getStatus,1);
        if(startTime != null && endTime != null){
            wrapper.lambda().between(OutPark::getUpdateTime,DateUtil.beginOfDay(sdf.parse(startTime)), DateUtil.endOfDay(sdf.parse(endTime)));
        }
        List<OutPark> list = outParkService.list(wrapper);
        List<Map<String,Object>> resultList = new ArrayList<>();
        if(list.size()>0){
            Map<Object, List<OutPark>> collect = list.stream().collect(
                    Collectors.groupingBy(b ->   b.getParkId()
            ));
            for (Map.Entry<Object, List<OutPark>> objectListEntry : collect.entrySet()) {
                Integer key = (Integer) objectListEntry.getKey();
                List<OutPark> value = objectListEntry.getValue();
                Double collect1 = value.stream().collect(Collectors.summingDouble(OutPark::getPrice));
                Map<String,Object> map  = new HashMap<>();
                map.put("parkName",parkService.getById(key).getName());
                map.put("orderNum",value.size());
                map.put("orderMoney",collect1);
                resultList.add(map);
            }
        }
        return R.ok(resultList);
    }
 
 
}