| New file |
| | |
| | | package com.trafficaudit.holiday.controller; |
| | | |
| | | import com.trafficaudit.common.Result; |
| | | import com.trafficaudit.holiday.entity.HolidayVehicleAdjustment; |
| | | import com.trafficaudit.holiday.service.HolidayVehicleAdjustmentService; |
| | | import com.trafficaudit.security.utils.JwtUtils; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestHeader; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @RestController |
| | | @RequestMapping("/api/holiday/adjustments") |
| | | public class HolidayVehicleAdjustmentController { |
| | | |
| | | @Resource |
| | | private HolidayVehicleAdjustmentService adjustmentService; |
| | | @Resource |
| | | private JwtUtils jwtUtils; |
| | | |
| | | @GetMapping |
| | | public Result<List<HolidayVehicleAdjustment>> list(@RequestParam(value = "year", required = false) Integer year) { |
| | | return Result.ok(adjustmentService.list(year)); |
| | | } |
| | | |
| | | @GetMapping("/source-value") |
| | | public Result<BigDecimal> sourceValue(@RequestParam("year") Integer year, |
| | | @RequestParam("flowDate") String flowDate) { |
| | | try { |
| | | return Result.ok(adjustmentService.findOriginalValue(year, LocalDate.parse(flowDate))); |
| | | } catch (Exception e) { |
| | | return Result.error(400, e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @PostMapping("/save") |
| | | public Result<HolidayVehicleAdjustment> save(@RequestHeader(value = "Authorization", required = false) String auth, |
| | | @RequestBody Map<String, Object> params) { |
| | | if (!isAdmin(auth)) return Result.error(403, "仅 admin 可以维护往年国省道数据调整"); |
| | | try { |
| | | return Result.ok(adjustmentService.save(params)); |
| | | } catch (Exception e) { |
| | | return Result.error(400, e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @PostMapping("/delete") |
| | | public Result<Void> delete(@RequestHeader(value = "Authorization", required = false) String auth, |
| | | @RequestParam("id") Long id) { |
| | | if (!isAdmin(auth)) return Result.error(403, "仅 admin 可以维护往年国省道数据调整"); |
| | | try { |
| | | adjustmentService.delete(id); |
| | | return Result.ok(); |
| | | } catch (Exception e) { |
| | | return Result.error(400, e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | private boolean isAdmin(String auth) { |
| | | return "admin".equals(jwtUtils.resolveUsername(auth)); |
| | | } |
| | | } |