From 37f52097847f9025589c79034be2454432c55433 Mon Sep 17 00:00:00 2001
From: xyc <jc_xiong@hotmail.com>
Date: 星期五, 02 十月 2026 10:12:27 +0800
Subject: [PATCH] docs(交接): 记录关机前开发服务已停止

---
 traffic-audit-server/src/main/java/com/trafficaudit/holiday/service/HolidayConfigService.java |  202 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 202 insertions(+), 0 deletions(-)

diff --git a/traffic-audit-server/src/main/java/com/trafficaudit/holiday/service/HolidayConfigService.java b/traffic-audit-server/src/main/java/com/trafficaudit/holiday/service/HolidayConfigService.java
new file mode 100644
index 0000000..6b281c7
--- /dev/null
+++ b/traffic-audit-server/src/main/java/com/trafficaudit/holiday/service/HolidayConfigService.java
@@ -0,0 +1,202 @@
+package com.trafficaudit.holiday.service;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.trafficaudit.holiday.HolidayConstants;
+import com.trafficaudit.holiday.entity.HolidayCalendar;
+import com.trafficaudit.holiday.entity.HolidayPassengerCoefficient;
+import com.trafficaudit.holiday.mapper.HolidayCalendarMapper;
+import com.trafficaudit.holiday.mapper.HolidayPassengerCoefficientMapper;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class HolidayConfigService {
+
+    @Resource
+    private HolidayCalendarMapper holidayCalendarMapper;
+
+    @Resource
+    private HolidayPassengerCoefficientMapper coefficientMapper;
+
+    public List<HolidayCalendar> listHolidays(Integer year, String holidayType) {
+        LambdaQueryWrapper<HolidayCalendar> wrapper = new LambdaQueryWrapper<HolidayCalendar>()
+                .eq(year != null, HolidayCalendar::getYear, year)
+                .eq(holidayType != null && !holidayType.trim().isEmpty(), HolidayCalendar::getHolidayType, holidayType)
+                .orderByAsc(HolidayCalendar::getYear)
+                .orderByAsc(HolidayCalendar::getHolidayType)
+                .orderByAsc(HolidayCalendar::getDayIndex);
+        return holidayCalendarMapper.selectList(wrapper);
+    }
+
+    public List<HolidayCalendar> findHolidayDays(int year, String holidayType) {
+        return holidayCalendarMapper.selectList(new LambdaQueryWrapper<HolidayCalendar>()
+                .eq(HolidayCalendar::getYear, year)
+                .eq(HolidayCalendar::getHolidayType, holidayType)
+                .orderByAsc(HolidayCalendar::getDayIndex));
+    }
+
+    public HolidayCalendar findHolidayByDate(LocalDate date) {
+        return holidayCalendarMapper.selectOne(new LambdaQueryWrapper<HolidayCalendar>()
+                .eq(HolidayCalendar::getHolidayDate, date)
+                .orderByAsc(HolidayCalendar::getDayIndex)
+                .last("limit 1"));
+    }
+
+    @Transactional
+    public HolidayCalendar saveHoliday(Map<String, Object> params) {
+        Long id = longValue(params.get("id"));
+        Integer year = intValue(params.get("year"));
+        String holidayType = stringValue(params.get("holidayType"));
+        LocalDate holidayDate = dateValue(params.get("holidayDate"));
+        Integer dayIndex = intValue(params.get("dayIndex"));
+        if (year == null || year < 2000 || year > 2100) {
+            throw new IllegalArgumentException("骞翠唤涓嶆纭�");
+        }
+        if (!HolidayConstants.isValidHolidayType(holidayType)) {
+            throw new IllegalArgumentException("鑺傚亣鏃ュ垎绫讳笉姝g‘");
+        }
+        if (holidayDate == null || holidayDate.getYear() != year) {
+            throw new IllegalArgumentException("鏃ユ湡蹇呴』灞炰簬鎵�閫夊勾浠�");
+        }
+        if (dayIndex == null || dayIndex < 1) {
+            throw new IllegalArgumentException("绗嚑鏃ュ繀椤讳粠 1 寮�濮�");
+        }
+        LambdaQueryWrapper<HolidayCalendar> duplicate = new LambdaQueryWrapper<HolidayCalendar>()
+                .eq(HolidayCalendar::getYear, year)
+                .eq(HolidayCalendar::getHolidayType, holidayType)
+                .and(w -> w.eq(HolidayCalendar::getHolidayDate, holidayDate)
+                        .or().eq(HolidayCalendar::getDayIndex, dayIndex));
+        if (id != null) {
+            duplicate.ne(HolidayCalendar::getId, id);
+        }
+        if (holidayCalendarMapper.selectCount(duplicate) > 0) {
+            throw new IllegalArgumentException("鍚屼竴鑺傚亣鏃ヤ笅鐨勬棩鏈熸垨绗嚑鏃ュ凡瀛樺湪");
+        }
+
+        HolidayCalendar entity = id == null ? new HolidayCalendar() : holidayCalendarMapper.selectById(id);
+        if (entity == null) {
+            throw new IllegalArgumentException("鑺傚亣鏃ヨ褰曚笉瀛樺湪");
+        }
+        if (id == null) {
+            entity.setCreatedAt(LocalDateTime.now());
+        }
+        entity.setYear(year);
+        entity.setHolidayType(holidayType);
+        entity.setHolidayDate(holidayDate);
+        entity.setDayIndex(dayIndex);
+        entity.setUpdatedAt(LocalDateTime.now());
+        if (id == null) {
+            holidayCalendarMapper.insert(entity);
+        } else {
+            holidayCalendarMapper.updateById(entity);
+        }
+        return entity;
+    }
+
+    @Transactional
+    public void deleteHoliday(Long id) {
+        if (id == null) {
+            throw new IllegalArgumentException("缂哄皯璁板綍 id");
+        }
+        holidayCalendarMapper.deleteById(id);
+    }
+
+    public List<HolidayPassengerCoefficient> listCoefficients(Integer year) {
+        return coefficientMapper.selectList(new LambdaQueryWrapper<HolidayPassengerCoefficient>()
+                .eq(year != null, HolidayPassengerCoefficient::getYear, year)
+                .orderByAsc(HolidayPassengerCoefficient::getYear)
+                .orderByAsc(HolidayPassengerCoefficient::getDateCategory));
+    }
+
+    public BigDecimal coefficientOf(int year, String dateCategory) {
+        HolidayPassengerCoefficient row = coefficientMapper.selectOne(
+                new LambdaQueryWrapper<HolidayPassengerCoefficient>()
+                        .eq(HolidayPassengerCoefficient::getYear, year)
+                        .eq(HolidayPassengerCoefficient::getDateCategory, dateCategory)
+                        .last("limit 1"));
+        return row == null ? null : row.getCoefficient();
+    }
+
+    @Transactional
+    public HolidayPassengerCoefficient saveCoefficient(Map<String, Object> params) {
+        Long id = longValue(params.get("id"));
+        Integer year = intValue(params.get("year"));
+        String dateCategory = stringValue(params.get("dateCategory"));
+        BigDecimal coefficient = decimalValue(params.get("coefficient"));
+        if (year == null || year < 2000 || year > 2100) {
+            throw new IllegalArgumentException("骞翠唤涓嶆纭�");
+        }
+        if (!HolidayConstants.isValidDateCategory(dateCategory)) {
+            throw new IllegalArgumentException("鏃ユ湡鍒嗙被涓嶆纭�");
+        }
+        if (coefficient == null || coefficient.compareTo(BigDecimal.ZERO) <= 0) {
+            throw new IllegalArgumentException("瀹㈣繍绯绘暟蹇呴』澶т簬 0");
+        }
+        LambdaQueryWrapper<HolidayPassengerCoefficient> duplicate = new LambdaQueryWrapper<HolidayPassengerCoefficient>()
+                .eq(HolidayPassengerCoefficient::getYear, year)
+                .eq(HolidayPassengerCoefficient::getDateCategory, dateCategory);
+        if (id != null) {
+            duplicate.ne(HolidayPassengerCoefficient::getId, id);
+        }
+        if (coefficientMapper.selectCount(duplicate) > 0) {
+            throw new IllegalArgumentException("璇ュ勾浠藉拰鏃ユ湡鍒嗙被鐨勫杩愮郴鏁板凡瀛樺湪");
+        }
+
+        HolidayPassengerCoefficient entity = id == null ? new HolidayPassengerCoefficient() : coefficientMapper.selectById(id);
+        if (entity == null) {
+            throw new IllegalArgumentException("瀹㈣繍绯绘暟璁板綍涓嶅瓨鍦�");
+        }
+        if (id == null) {
+            entity.setCreatedAt(LocalDateTime.now());
+        }
+        entity.setYear(year);
+        entity.setDateCategory(dateCategory);
+        entity.setCoefficient(coefficient);
+        entity.setUpdatedAt(LocalDateTime.now());
+        if (id == null) {
+            coefficientMapper.insert(entity);
+        } else {
+            coefficientMapper.updateById(entity);
+        }
+        return entity;
+    }
+
+    @Transactional
+    public void deleteCoefficient(Long id) {
+        if (id == null) {
+            throw new IllegalArgumentException("缂哄皯璁板綍 id");
+        }
+        coefficientMapper.deleteById(id);
+    }
+
+    private Long longValue(Object value) {
+        if (value == null || value.toString().trim().isEmpty()) return null;
+        return Long.valueOf(value.toString());
+    }
+
+    private Integer intValue(Object value) {
+        if (value == null || value.toString().trim().isEmpty()) return null;
+        return Integer.valueOf(value.toString());
+    }
+
+    private BigDecimal decimalValue(Object value) {
+        if (value == null || value.toString().trim().isEmpty()) return null;
+        return com.trafficaudit.holiday.HolidayNumberUtils.decimalValue(value);
+    }
+
+    private String stringValue(Object value) {
+        return value == null ? null : value.toString().trim();
+    }
+
+    private LocalDate dateValue(Object value) {
+        if (value == null || value.toString().trim().isEmpty()) return null;
+        return LocalDate.parse(value.toString());
+    }
+}

--
Gitblit v1.9.1