救援大屏救援订单接口

This commit is contained in:
许允枞 2024-10-23 18:30:38 +08:00
parent 771a4eeadf
commit b467dfeeb5
4 changed files with 126 additions and 1 deletions

View File

@ -0,0 +1,26 @@
package cn.iocoder.yudao.module.rescue.controller.admin;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.rescue.service.IRescueOrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/rescue/bigScree")
public class RescueBigScreeController {
@Autowired
private IRescueOrderInfoService rescueOrderInfoService;
/**
*
* @param type count 数量 money 金额
* @param timeType day month year
* @return
*/
@GetMapping("/getRescueOrderCount")
public CommonResult getRescueOrderCount(String type, String timeType){
return CommonResult.success(rescueOrderInfoService.getRescueOrderCount(type,timeType));
}
}

View File

@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* 救援订单Mapper接口
@ -33,5 +34,4 @@ public interface RescueOrderInfoMapper extends BaseMapper<RescueOrderInfo>
*/
public List<RescueOrderInfo> selectRescueOrderInfoList(RescueOrderInfo rescueOrderInfo);
Double avgPartnerScore(@Param("driverId") Long driverId);
}

View File

@ -69,4 +69,12 @@ public interface IRescueOrderInfoService extends IService<RescueOrderInfo>
RescueOrderInfo getOrderByOrderNo(String orderNo);
Map<String, String> payNotify( JSONObject jsonObject);
public void reviewOrder(String rescueId, Integer starLevel, String reviewStr) throws Exception;
/**
*
* @param type count 数量 money 金额
* @param timeType day month year
* @return
*/
List<Map<String, Object>> getRescueOrderCount(String type, String timeType);
}

View File

@ -1,6 +1,9 @@
package cn.iocoder.yudao.module.rescue.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import cn.iocoder.yudao.module.rescue.domain.*;
@ -22,6 +25,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
@ -313,4 +317,91 @@ public class RescueOrderInfoServiceImpl extends ServiceImpl<RescueOrderInfoMappe
driverInfoService.updateById(driverInfo);
}
}
/**
* @param type count 数量 money 金额
* @param timeType day month year
* @return
*/
@Override
public List<Map<String, Object>> getRescueOrderCount(String type, String timeType) {
List<Map<String, Object>> res = new ArrayList<>();
DateTime startTime = DateUtil.date();
DateTime endTime = new DateTime();
List<DateTime> dateList = new ArrayList<>();
switch (timeType) {
case "day":
startTime = DateUtil.beginOfDay(startTime);
endTime = DateUtil.endOfDay(endTime);
dateList = DateUtil.rangeToList(startTime, endTime, DateField.HOUR_OF_DAY);
break;
case "month":
startTime = DateUtil.beginOfMonth(startTime);
endTime = DateUtil.endOfMonth(endTime);
dateList = DateUtil.rangeToList(startTime, endTime, DateField.DAY_OF_MONTH);
break;
case "year":
startTime = DateUtil.beginOfYear(startTime);
endTime = DateUtil.endOfYear(endTime);
dateList = DateUtil.rangeToList(startTime, endTime, DateField.MONTH);
break;
}
LambdaQueryWrapper<RescueOrderInfo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.between(RescueOrderInfo::getCreateTime, startTime, endTime);
queryWrapper.eq(RescueOrderInfo::getOrderStatus, "3");
List<RescueOrderInfo> list = this.list(queryWrapper);
for (DateTime dateTime : dateList) {
String name = "";
switch (timeType) {
case "day":
name = dateTime.toString("HH:mm");
break;
case "month":
name = dateTime.toString("MM-dd");
break;
case "year":
name = dateTime.toString("YYYY-MM");
break;
}
Map<String, Object> map = new HashMap<>();
DateTime endTime1 = getEndTime(timeType, dateTime);
List<RescueOrderInfo> rescueOrderInfos = filterOrdersByDate(list, dateTime, endTime1);
map.put("name", name);
if ("count".equals(type)) {
long count = rescueOrderInfos.stream().count();
map.put("value", count);
}else if ("money".equals(type)) {
// 使用 stream() 计算总金额并防止空指针异常
long money = rescueOrderInfos.stream()
.filter(Objects::nonNull) // 过滤掉 null 对象
.filter(order -> Objects.nonNull(order.getPayMoney())) // 过滤掉 payMoney null 的对象
.mapToLong(RescueOrderInfo::getPayMoney) // 获取支付金额
.sum(); // 计算总和
//将分转为元
map.put("value", (double)money / 100);
}
res.add(map);
}
return res;
}
public DateTime getEndTime(String timeType, DateTime startTime){
switch (timeType) {
case "day":
return DateUtil.endOfHour(startTime);
case "month":
return DateUtil.endOfDay(startTime);
case "year":
return DateUtil.endOfMonth(startTime);
}
return null;
}
public List<RescueOrderInfo> filterOrdersByDate(List<RescueOrderInfo> orders, Date startDate, Date endDate) {
return orders.stream()
.filter(order -> order.getOrderTime() != null &&
!order.getOrderTime().before(startDate) &&
!order.getOrderTime().after(endDate))
.collect(Collectors.toList());
}
}