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.Park;
|
import com.boying.entity.vo.OrderRecordVo;
|
import com.boying.entity.vo.OutParkVo;
|
import com.boying.service.OrderRecordService;
|
import com.boying.service.OutParkService;
|
import com.boying.service.ParkService;
|
import com.boying.service.UserService;
|
import io.swagger.annotations.ApiOperation;
|
|
import lombok.RequiredArgsConstructor;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.time.LocalDate;
|
import java.time.Month;
|
import java.time.YearMonth;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
@RestController
|
@RequestMapping("ffzf/orderrecord")
|
@RequiredArgsConstructor
|
public class OrderRecordController {
|
|
private final OrderRecordService orderRecordService;
|
private final OutParkService outParkService;
|
private final ParkService parkService;
|
private final UserService userService;
|
|
/**
|
* 分页查询
|
* @param page 分页对象
|
* @param orderRecord 订单表
|
* @return
|
*/
|
@ApiOperation(value = "分页查询", notes = "分页查询")
|
@PostMapping("/findPage" )
|
public R getOrderRecordPage(Page page, OrderRecord orderRecord) {
|
QueryWrapper<OrderRecord> wrapper = new QueryWrapper<>();
|
wrapper.lambda()
|
.eq(OrderRecord::getType,orderRecord.getType())
|
.eq(OrderRecord::getStatus,1)
|
.like(StringUtils.isNotBlank(orderRecord.getCarNo()),OrderRecord::getCarNo,orderRecord.getCarNo())
|
.isNotNull(OrderRecord::getPayCode)
|
.orderByDesc(OrderRecord::getCreateTime);
|
Page page1 = orderRecordService.page(page, wrapper);
|
List<OrderRecord> records = page1.getRecords();
|
for (OrderRecord record : records) {
|
if(record.getImgInId() != null){
|
record.setImgInPath("/ffzf/fileinfo/showImgById/"+record.getImgInId());
|
}
|
if(record.getImgOutId() != null){
|
record.setImgOutPath("/ffzf/fileinfo/showImgById/"+record.getImgOutId());
|
}
|
}
|
page1.setRecords(records);
|
return R.ok(page1);
|
}
|
|
|
@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<>();
|
Park byId = parkService.getById(key);
|
if(byId != null){
|
map.put("parkName",byId.getName());
|
}else {
|
map.put("parkName","未知停车场");
|
}
|
map.put("orderNum",value.size());
|
map.put("orderMoney",collect1);
|
resultList.add(map);
|
}
|
}
|
return R.ok(resultList);
|
}
|
|
@PostMapping("/findCountPageByDay")
|
public Object findCountPageByDay(Integer parkId,String day) throws ParseException {
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
if(StringUtils.isBlank(day)){
|
return R.failed("请选择时间查询");
|
}else {
|
List<Park> parkList= new ArrayList<>();
|
if(parkId==null){
|
parkList = parkService.list();
|
}else {
|
Park byId = parkService.getById(parkId);
|
parkList.add(byId);
|
}
|
String[] split = day.split("-");
|
Integer year = Integer.parseInt(split[0]);
|
Integer month = Integer.parseInt(split[1]);
|
// 使用YearMonth.of()创建YearMonth实例
|
YearMonth yearMonth = YearMonth.of(year, month);
|
// 使用YearMonth实例的lengthOfMonth()方法获取该月的最大天数
|
int maxDay = yearMonth.lengthOfMonth();
|
String start = day+"-01";
|
String end = day+"-"+maxDay;
|
List<OutParkVo> list = outParkService.getVoList(parkId,start,end);
|
List<Map<String,Object>> resultMapList = new ArrayList<>();
|
|
List<String>str=new ArrayList<String>();
|
for (int i = 1; i <= maxDay; i++) {
|
if(i<10){
|
String d=day+"-0"+i;
|
str.add(d);
|
}else {
|
String d=day+"-"+i;
|
str.add(d);
|
}
|
}
|
for (String s : str) {
|
List<OutParkVo> resultList = new ArrayList<>();
|
List<OutParkVo> collect = list.stream().filter(item -> item.getTi().equals(s)).collect(Collectors.toList());
|
for (Park park : parkList) {
|
List<OutParkVo> vos = collect.stream().filter(item -> item.getParkId().equals(park.getId())).collect(Collectors.toList());
|
if(vos!=null && vos.size()>0){
|
OutParkVo vo = vos.get(0);
|
vo.setParkName(park.getName());
|
if(vo.getNum()==null){
|
vo.setNum(0);
|
}
|
resultList.add(vo);
|
}else {
|
OutParkVo outParkVo = new OutParkVo();
|
outParkVo.setTi(s);
|
outParkVo.setNum(0);
|
outParkVo.setParkId(park.getId());
|
outParkVo.setParkName(park.getName());
|
outParkVo.setPrice(0.0d);
|
resultList.add(outParkVo);
|
}
|
}
|
Map<String ,Object>map = new HashMap<>();
|
map.put("day",s);
|
map.put("data",resultList);
|
resultMapList.add(map);
|
}
|
return R.ok(resultMapList);
|
}
|
}
|
|
public static void main(String[] args) {
|
// 获取当前日期
|
LocalDate currentDate = LocalDate.now();
|
// 获取当前月份
|
Month currentMonth = currentDate.getMonth();
|
int maxLength = currentMonth.maxLength();
|
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
List<String>str=new ArrayList<String>();
|
//String monthStart=df.format(new Date()).substring(0,8)+"01";
|
for (int i = 1; i <= maxLength; i++) {
|
if(i<10){
|
String d=df.format(new Date()).substring(0,8)+"0"+i;
|
str.add(d);
|
}else {
|
String d=df.format(new Date()).substring(0,8)+i;
|
str.add(d);
|
}
|
}
|
for (String s : str) {
|
System.out.println(s);
|
}
|
|
// 假设我们要获取2023年3月的最大日期
|
int year = 2023;
|
int month = 3;
|
// 使用YearMonth.of()创建YearMonth实例
|
YearMonth yearMonth = YearMonth.of(year, month);
|
// 使用YearMonth实例的lengthOfMonth()方法获取该月的最大天数
|
int maxDay = yearMonth.lengthOfMonth();
|
System.out.println(maxDay);
|
}
|
|
|
}
|