package com.ruoyi.web.controller.system;
|
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.List;
|
import javax.servlet.http.HttpServletResponse;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PutMapping;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.page.TableDataInfo;
|
import com.ruoyi.common.enums.BusinessType;
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
import com.ruoyi.system.domain.VehicleMileageStats;
|
import com.ruoyi.system.service.IVehicleMileageStatsService;
|
|
/**
|
* 车辆里程统计Controller
|
*/
|
@RestController
|
@RequestMapping("/system/mileageStats")
|
public class VehicleMileageStatsController extends BaseController {
|
|
@Autowired
|
private IVehicleMileageStatsService vehicleMileageStatsService;
|
|
/**
|
* 查询车辆里程统计列表
|
*/
|
@PreAuthorize("@ss.hasPermi('system:mileageStats:list')")
|
@GetMapping("/list")
|
public TableDataInfo list(VehicleMileageStats vehicleMileageStats) {
|
startPage();
|
List<VehicleMileageStats> list = vehicleMileageStatsService.selectVehicleMileageStatsList(vehicleMileageStats);
|
return getDataTable(list);
|
}
|
|
/**
|
* 导出车辆里程统计列表
|
*/
|
@PreAuthorize("@ss.hasPermi('system:mileageStats:export')")
|
@Log(title = "车辆里程统计", businessType = BusinessType.EXPORT)
|
@PostMapping("/export")
|
public void export(HttpServletResponse response, VehicleMileageStats vehicleMileageStats) {
|
List<VehicleMileageStats> list = vehicleMileageStatsService.selectVehicleMileageStatsList(vehicleMileageStats);
|
ExcelUtil<VehicleMileageStats> util = new ExcelUtil<VehicleMileageStats>(VehicleMileageStats.class);
|
util.exportExcel(response, list, "车辆里程统计数据");
|
}
|
|
/**
|
* 获取车辆里程统计详细信息
|
*/
|
@PreAuthorize("@ss.hasPermi('system:mileageStats:query')")
|
@GetMapping(value = "/{statsId}")
|
public AjaxResult getInfo(@PathVariable("statsId") Long statsId) {
|
return success(vehicleMileageStatsService.selectVehicleMileageStatsById(statsId));
|
}
|
|
/**
|
* 新增车辆里程统计
|
*/
|
@PreAuthorize("@ss.hasPermi('system:mileageStats:add')")
|
@Log(title = "车辆里程统计", businessType = BusinessType.INSERT)
|
@PostMapping
|
public AjaxResult add(@RequestBody VehicleMileageStats vehicleMileageStats) {
|
return toAjax(vehicleMileageStatsService.insertVehicleMileageStats(vehicleMileageStats));
|
}
|
|
/**
|
* 修改车辆里程统计
|
*/
|
@PreAuthorize("@ss.hasPermi('system:mileageStats:edit')")
|
@Log(title = "车辆里程统计", businessType = BusinessType.UPDATE)
|
@PutMapping
|
public AjaxResult edit(@RequestBody VehicleMileageStats vehicleMileageStats) {
|
return toAjax(vehicleMileageStatsService.updateVehicleMileageStats(vehicleMileageStats));
|
}
|
|
/**
|
* 删除车辆里程统计
|
*/
|
@PreAuthorize("@ss.hasPermi('system:mileageStats:remove')")
|
@Log(title = "车辆里程统计", businessType = BusinessType.DELETE)
|
@DeleteMapping("/{statsIds}")
|
public AjaxResult remove(@PathVariable Long[] statsIds) {
|
return toAjax(vehicleMileageStatsService.deleteVehicleMileageStatsByIds(statsIds));
|
}
|
|
/**
|
* 手动触发计算指定车辆指定日期的里程统计
|
*/
|
@PreAuthorize("@ss.hasPermi('system:mileageStats:calculate')")
|
@Log(title = "车辆里程统计", businessType = BusinessType.OTHER)
|
@PostMapping("/calculate")
|
public AjaxResult calculate(Long vehicleId, String statDate) {
|
try {
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
Date date = sdf.parse(statDate);
|
VehicleMileageStats stats = vehicleMileageStatsService.calculateAndSaveMileageStats(vehicleId, date);
|
if (stats != null) {
|
return success("里程统计计算成功", stats);
|
} else {
|
return error("该车辆在指定日期无GPS数据");
|
}
|
} catch (Exception e) {
|
return error("里程统计计算失败:" + e.getMessage());
|
}
|
}
|
|
/**
|
* 批量计算指定日期所有车辆的里程统计
|
*/
|
@PreAuthorize("@ss.hasPermi('system:mileageStats:batch')")
|
@Log(title = "车辆里程统计", businessType = BusinessType.OTHER)
|
@PostMapping("/batchCalculate")
|
public AjaxResult batchCalculate(String statDate) {
|
try {
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
Date date = sdf.parse(statDate);
|
int count = vehicleMileageStatsService.batchCalculateMileageStats(date);
|
return success("批量里程统计完成,成功统计 " + count + " 辆车");
|
} catch (Exception e) {
|
return error("批量里程统计失败:" + e.getMessage());
|
}
|
}
|
}
|