代码补正

This commit is contained in:
xiao-fajia 2024-08-27 14:45:51 +08:00
parent e1dcb45e0b
commit 629f85d8fd
3 changed files with 102 additions and 85 deletions

View File

@ -43,9 +43,9 @@ public class RescueCarSpendController extends BaseController {
/**
* 导出车辆消费管理列表
*/
@PreAuthorize("@ss.hasPermission('rescue:rescueCarSpend:export')")
// @PreAuthorize("@ss.hasPermission('rescue:rescueCarSpend:export')")
// @Log(title = "车辆消费管理", businessType = BusinessType.EXPORT)
@PostMapping("/export")
@GetMapping("/export")
public void export(HttpServletResponse response, RescueCarSpend rescueCarSpend) {
List<RescueCarSpend> list = rescueCarSpendService.list();
ExcelUtil<RescueCarSpend> util = new ExcelUtil<RescueCarSpend>(RescueCarSpend.class);

View File

@ -178,12 +178,8 @@ public class RescueInfoSystem extends BaseController {
break;
}
}
// 导出 Excel
Map<Integer, Integer> columnWidthMap = new HashMap<>();
// 第一列的索引是0宽度设置为20个字符宽
columnWidthMap.put(9, 20);
columnWidthMap.put(10, 20);
ExcelUtils.write(response, "救援订单.xls", "数据", RescueInfo.class, list, columnWidthMap);
ExcelUtil<RescueInfo> util = new ExcelUtil<RescueInfo>(RescueInfo.class);
util.exportExcel(response, list, "救援订单数据");
}
//指派司机
@ -365,13 +361,26 @@ public class RescueInfoSystem extends BaseController {
return CommonResult.success(res);
}
/** TODO 有问题,处理时间太长,还会报错 */
@GetMapping("/exportManagement")
public void exportManagement(HttpServletResponse response, RescueInfo rescueInfo) {
List<MoneyManagement> list = rescueInfoService.moneyManagement(rescueInfo);
public void exportManagement(HttpServletResponse response, RescueInfo rescueInfo,
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
List<MoneyManagement> result = new ArrayList<>();
while (true){
Page<RescueInfo> page = new Page<>(pageNo, pageSize);
IPage<RescueInfo> rescueInfos = rescueInfoService.getRescueInfoByDriver(rescueInfo, page);
if (ObjectUtil.isEmpty(rescueInfos) || rescueInfos.getRecords().isEmpty()){
break;
}
List<MoneyManagement> list = rescueInfoService.moneyManagement2(rescueInfos.getRecords(), rescueInfo.getRescueStart());
result.addAll(list);
pageNo ++;
}
JSONObject jsonObject = rescueInfoService.listData(rescueInfo);
ExcelUtil<MoneyManagement> util = new ExcelUtil<MoneyManagement>(MoneyManagement.class);
String title = "施救总金额:" + jsonObject.getString("allMoney") + "元 出车次数:" + jsonObject.getString("allNum") + "次 提成总金额:" + jsonObject.getString("tcAll") + " 元 燃油费小计:" + jsonObject.getString("refuelMoney") + "";
util.exportExcel(response, list, "救援财务报表", title);
util.exportExcel(response, result, "救援财务报表", title);
}
/**

View File

@ -946,81 +946,89 @@ public class RescueInfoServiceImpl extends ServiceImpl<RescueInfoMapper, RescueI
return resList;
}
/** 有问题 */
@Deprecated
public List<MoneyManagement> moneyManagement(RescueInfo rescueInfo) {
// List<RescueInfo> rescueInfos = baseMapper.getRescueInfoByDriver(rescueInfo);
// List<MoneyManagement> resList = new ArrayList<>();
// Double rescueTcBig = 0d;
// Double rescueTcMid = 0d;
// Double rescueTcSmall = 0d;
// RescueConfig rescueConfig = rescueConfigService.selectRescueConfigByDeptId();
// if (ObjectUtils.isNotEmpty(rescueConfig)) {
// rescueTcBig = Optional.ofNullable(rescueConfig.getRescueTcBig()).orElse(0d);
// rescueTcMid = Optional.ofNullable(rescueConfig.getRescueTcMid()).orElse(0d);
// rescueTcSmall = Optional.ofNullable(rescueConfig.getRescueTcSmall()).orElse(0d);
// }
// for (RescueInfo info : rescueInfos) {
// MoneyManagement moneyManagement = new MoneyManagement();
// moneyManagement.setDriverName(info.getDriverName());
// Double grossWages = 0d;
// Double tempSetMoney = ObjectUtils.isNotEmpty(info.getSetMoney()) ? Double.valueOf(info.getSetMoney()) / 100d : 0d;
// Double tempCheckpointMoney = ObjectUtils.isNotEmpty(info.getCheckpointMoney()) ? info.getCheckpointMoney() : 0d;
// JSONObject monthRescueRefuelRecord = new JSONObject();
// monthRescueRefuelRecord.put("refuelMoney", 0);
// monthRescueRefuelRecord.put("refuelNum", 0);
// monthRescueRefuelRecord.put("refuelDistance", 0);
// try {
// LambdaQueryWrapper<RescueCarInfo> queryWrapper = new LambdaQueryWrapper<>();
// queryWrapper.eq(RescueCarInfo::getRescueCarNum, info.getDriverCarNum()).last("limit 1");
// RescueCarInfo carInfo = carInfoService.getOne(queryWrapper);
// monthRescueRefuelRecord = refuelRecordService.getMonthRescueRefuelRecord(info.getDriverId(), DateUtil.format(info.getRescueTime(), "yyyy-MM"), carInfo.getId());
// } catch (Exception ignored) {
// }
// moneyManagement.setLicenseNum(info.getLicenseNum());
// moneyManagement.setFeeType(info.getFeeType());
// moneyManagement.setRescueTime(info.getRescueTime());
// moneyManagement.setDiverCarNum(info.getDriverCarNum());
// moneyManagement.setSetMoney(tempSetMoney);
// moneyManagement.setCheckpointMoney(info.getCheckpointMoney());
// moneyManagement.setUpMoney(tempSetMoney - tempCheckpointMoney);
// moneyManagement.setEmptyingDistance(info.getEmptyNum());
// String carType = "3";
// if (StringUtils.isNotEmpty(info.getDriverCarNum())) {
// RescueCarInfo carInfo = carInfoService.selectRescueCarInfoByNum(info.getDriverCarNum());
// carType = carInfo.getRescueCarType();
// }
// if (carType.equals("1")) {
// //大车
// moneyManagement.setRoyaltyRatio(rescueTcBig);
// moneyManagement.setRoyaltyMoney(tempSetMoney * rescueTcBig);
// } else if (carType.equals("2")) {
// //中车
// moneyManagement.setRoyaltyRatio(rescueTcMid);
// moneyManagement.setRoyaltyMoney(tempSetMoney * rescueTcMid);
// } else {
// //小车
// moneyManagement.setRoyaltyRatio(rescueTcSmall);
// moneyManagement.setRoyaltyMoney(tempSetMoney * rescueTcSmall);
// }
// //获取当前车 当前驾驶员 这个月跑了几次
// JSONObject driverInfoObj = baseMapper.getDriverCarNum(info.getDriverId(), info.getDriverCarNum(), rescueInfo.getRescueStart());
// //计算平均燃油费和平均油耗
// Double avgFuelConsumption = 0d;
// Double mglYh = 0d;
// if (driverInfoObj.getInteger("allNum") != 0) {
// avgFuelConsumption = monthRescueRefuelRecord.getDouble("refuelMoney") / driverInfoObj.getInteger("allNum");
// mglYh = monthRescueRefuelRecord.getDouble("refuelNum") / driverInfoObj.getDouble("allDistance");
// }
// moneyManagement.setFuelCost(avgFuelConsumption);
// moneyManagement.setOilConsumption(mglYh);
// Double oilSubsidy = Optional.ofNullable(info.getEmptyNum()).orElse(0d) * mglYh;
// moneyManagement.setOilSubsidy(oilSubsidy);
// grossWages = grossWages + moneyManagement.getRoyaltyMoney() + oilSubsidy - avgFuelConsumption;
// moneyManagement.setGrossWages(grossWages);
// resList.add(moneyManagement);
// }
//
// return resList;
return null;
List<MoneyManagement> resList = new ArrayList<>();
Double rescueTcBig = 0d;
Double rescueTcMid = 0d;
Double rescueTcSmall = 0d;
RescueConfig rescueConfig = rescueConfigService.selectRescueConfigByDeptId();
if (ObjectUtils.isNotEmpty(rescueConfig)) {
rescueTcBig = Optional.ofNullable(rescueConfig.getRescueTcBig()).orElse(0d);
rescueTcMid = Optional.ofNullable(rescueConfig.getRescueTcMid()).orElse(0d);
rescueTcSmall = Optional.ofNullable(rescueConfig.getRescueTcSmall()).orElse(0d);
}
Integer pageNo = 1;
while (true){
Page<RescueInfo> page = new Page<>(pageNo, 500);
IPage<RescueInfo> rescueInfos = baseMapper.getRescueInfoByDriver(rescueInfo, page);
if (ObjectUtil.isEmpty(rescueInfos) && rescueInfos.getRecords().isEmpty()){
break;
}
for (RescueInfo info : rescueInfos.getRecords()) {
MoneyManagement moneyManagement = new MoneyManagement();
moneyManagement.setDriverName(info.getDriverName());
Double grossWages = 0d;
Double tempSetMoney = ObjectUtils.isNotEmpty(info.getSetMoney()) ? Double.valueOf(info.getSetMoney()) / 100d : 0d;
Double tempCheckpointMoney = ObjectUtils.isNotEmpty(info.getCheckpointMoney()) ? info.getCheckpointMoney() : 0d;
JSONObject monthRescueRefuelRecord = new JSONObject();
monthRescueRefuelRecord.put("refuelMoney", 0);
monthRescueRefuelRecord.put("refuelNum", 0);
monthRescueRefuelRecord.put("refuelDistance", 0);
try {
LambdaQueryWrapper<RescueCarInfo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(RescueCarInfo::getRescueCarNum, info.getDriverCarNum()).last("limit 1");
RescueCarInfo carInfo = carInfoService.getOne(queryWrapper);
monthRescueRefuelRecord = refuelRecordService.getMonthRescueRefuelRecord(info.getDriverId(), DateUtil.format(info.getRescueTime(), "yyyy-MM"), carInfo.getId());
} catch (Exception ignored) {
}
moneyManagement.setLicenseNum(info.getLicenseNum());
moneyManagement.setFeeType(info.getFeeType());
moneyManagement.setRescueTime(info.getRescueTime());
moneyManagement.setDiverCarNum(info.getDriverCarNum());
moneyManagement.setSetMoney(tempSetMoney);
moneyManagement.setCheckpointMoney(info.getCheckpointMoney());
moneyManagement.setUpMoney(tempSetMoney - tempCheckpointMoney);
moneyManagement.setEmptyingDistance(info.getEmptyNum());
String carType = "3";
if (StringUtils.isNotEmpty(info.getDriverCarNum())) {
RescueCarInfo carInfo = carInfoService.selectRescueCarInfoByNum(info.getDriverCarNum());
carType = carInfo.getRescueCarType();
}
if (carType.equals("1")) {
//大车
moneyManagement.setRoyaltyRatio(rescueTcBig);
moneyManagement.setRoyaltyMoney(tempSetMoney * rescueTcBig);
} else if (carType.equals("2")) {
//中车
moneyManagement.setRoyaltyRatio(rescueTcMid);
moneyManagement.setRoyaltyMoney(tempSetMoney * rescueTcMid);
} else {
//小车
moneyManagement.setRoyaltyRatio(rescueTcSmall);
moneyManagement.setRoyaltyMoney(tempSetMoney * rescueTcSmall);
}
//获取当前车 当前驾驶员 这个月跑了几次
JSONObject driverInfoObj = baseMapper.getDriverCarNum(info.getDriverId(), info.getDriverCarNum(), rescueInfo.getRescueStart());
//计算平均燃油费和平均油耗
Double avgFuelConsumption = 0d;
Double mglYh = 0d;
if (driverInfoObj.getInteger("allNum") != 0) {
avgFuelConsumption = monthRescueRefuelRecord.getDouble("refuelMoney") / driverInfoObj.getInteger("allNum");
mglYh = monthRescueRefuelRecord.getDouble("refuelNum") / driverInfoObj.getDouble("allDistance");
}
moneyManagement.setFuelCost(avgFuelConsumption);
moneyManagement.setOilConsumption(mglYh);
Double oilSubsidy = Optional.ofNullable(info.getEmptyNum()).orElse(0d) * mglYh;
moneyManagement.setOilSubsidy(oilSubsidy);
grossWages = grossWages + moneyManagement.getRoyaltyMoney() + oilSubsidy - avgFuelConsumption;
moneyManagement.setGrossWages(grossWages);
resList.add(moneyManagement);
}
pageNo ++;
}
return resList;
}
@Override