From 4eed47cc70adae18d005c2655ff02ce9c31cdf15 Mon Sep 17 00:00:00 2001 From: kangwenjing <1138819403@qq.com> Date: Wed, 22 Jul 2026 18:01:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E6=8A=A5=E5=A1=AB=E6=8A=A5=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E8=8C=83=E5=9B=B4=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 14340 -> 14340 bytes .../crm/service/impl/WorkServiceImpl.java | 8 +- backend/src/main/resources/application.yml | 14 ++-- .../main/resources/mapper/work/WorkMapper.xml | 74 +++++++++++++++--- .../crm/service/impl/WorkServiceImplTest.java | 15 ++++ frontend/src/pages/Work.tsx | 37 +++++++-- 6 files changed, 121 insertions(+), 27 deletions(-) diff --git a/.DS_Store b/.DS_Store index 0d152f935a011a2602682f9d09d2acc3cc7c7101..6bc69b37806dcd0437154032d004221be28ceded 100644 GIT binary patch delta 14 VcmZoEXerpxqQuC!xmBrN6aXuu1up;q delta 16 XcmZoEXerpxqBJ>BQ+V@qrCd<}JA4LB diff --git a/backend/src/main/java/com/unis/crm/service/impl/WorkServiceImpl.java b/backend/src/main/java/com/unis/crm/service/impl/WorkServiceImpl.java index 15e78f8e..68756f6c 100644 --- a/backend/src/main/java/com/unis/crm/service/impl/WorkServiceImpl.java +++ b/backend/src/main/java/com/unis/crm/service/impl/WorkServiceImpl.java @@ -103,6 +103,7 @@ public class WorkServiceImpl implements WorkService { private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); private static final DateTimeFormatter REPORT_DATE_TIME_TEXT_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm"); private static final ZoneId BUSINESS_ZONE_ID = ZoneId.of("Asia/Shanghai"); + private static final LocalTime DAILY_REPORT_CUTOFF_TIME = LocalTime.of(10, 0); private final WorkMapper workMapper; private final OpportunityMapper opportunityMapper; @@ -2465,7 +2466,12 @@ public class WorkServiceImpl implements WorkService { } private LocalDate currentBusinessDate() { - return LocalDate.now(BUSINESS_ZONE_ID); + return resolveBusinessDate(LocalDateTime.now(BUSINESS_ZONE_ID)); + } + + static LocalDate resolveBusinessDate(LocalDateTime businessDateTime) { + LocalDate date = businessDateTime.toLocalDate(); + return businessDateTime.toLocalTime().isBefore(DAILY_REPORT_CUTOFF_TIME) ? date.minusDays(1) : date; } private record PhotoMetadata(String cleanText, List photoUrls) {} diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index 1708106a..7b0fd03a 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -12,25 +12,21 @@ minio: spring: application: name: unis-crm-backend - jackson: - time-zone: Asia/Shanghai servlet: multipart: max-file-size: 500MB max-request-size: 600MB datasource: - url: jdbc:postgresql://127.0.0.1:5432/unis_crm + url: jdbc:postgresql://192.168.124.202:5432/unis_crm username: postgres - password: 199628 + password: unis@123 driver-class-name: org.postgresql.Driver - hikari: - connection-init-sql: SET TIME ZONE 'Asia/Shanghai' data: redis: - host: 127.0.0.1 + host: 192.168.124.202 port: 6379 - password: 199628@tlw - database: 14 + password: zghz@123 + database: 12 mybatis-plus: mapper-locations: classpath*:/mapper/**/*.xml diff --git a/backend/src/main/resources/mapper/work/WorkMapper.xml b/backend/src/main/resources/mapper/work/WorkMapper.xml index 965823b4..4bab1b43 100644 --- a/backend/src/main/resources/mapper/work/WorkMapper.xml +++ b/backend/src/main/resources/mapper/work/WorkMapper.xml @@ -4,6 +4,14 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + + case + when r.submit_time is not null and (r.submit_time at time zone 'Asia/Shanghai')::time < time '10:00' + then (r.submit_time at time zone 'Asia/Shanghai')::date - 1 + else coalesce((r.submit_time at time zone 'Asia/Shanghai')::date, r.report_date) + end + + and c.checkin_date >= #{startDate} @@ -34,10 +42,22 @@ - and r.report_date >= #{startDate} + and ( + case + when r.submit_time is not null and (r.submit_time at time zone 'Asia/Shanghai')::time < time '10:00' + then (r.submit_time at time zone 'Asia/Shanghai')::date - 1 + else coalesce((r.submit_time at time zone 'Asia/Shanghai')::date, r.report_date) + end + ) >= #{startDate} - and r.report_date <= #{endDate} + and ( + case + when r.submit_time is not null and (r.submit_time at time zone 'Asia/Shanghai')::time < time '10:00' + then (r.submit_time at time zone 'Asia/Shanghai')::date - 1 + else coalesce((r.submit_time at time zone 'Asia/Shanghai')::date, r.report_date) + end + ) <= #{endDate} and ( @@ -320,7 +340,7 @@ select r.id, '日报' as type, - to_char(r.report_date, 'YYYY-MM-DD') as date, + to_char(, 'YYYY-MM-DD') as date, to_char(r.submit_time, 'HH24:MI') as time, case when coalesce(nullif(btrim(u.display_name), ''), nullif(btrim(u.username), '')) is not null @@ -343,7 +363,11 @@ end as status, rc.score, rc.comment_content as comment, - coalesce(r.report_date::timestamp + r.submit_time::time, r.created_at) as sort_time + coalesce( + ()::timestamp + + (r.submit_time at time zone 'Asia/Shanghai')::time, + r.created_at + ) as sort_time from work_daily_report r left join sys_user u on u.user_id = r.user_id and u.is_deleted = 0 left join ( @@ -362,7 +386,7 @@ select r.id, '日报' as type, - to_char(r.report_date, 'YYYY-MM-DD') as date, + to_char(, 'YYYY-MM-DD') as date, to_char(r.submit_time, 'HH24:MI') as time, case when coalesce(nullif(btrim(u.display_name), ''), nullif(btrim(u.username), '')) is not null @@ -385,7 +409,11 @@ end as status, rc.score, rc.comment_content as comment, - coalesce(r.report_date::timestamp + r.submit_time::time, r.created_at) as sort_time + coalesce( + ()::timestamp + + (r.submit_time at time zone 'Asia/Shanghai')::time, + r.created_at + ) as sort_time from work_daily_report r left join sys_user u on u.user_id = r.user_id and u.is_deleted = 0 left join ( @@ -408,7 +436,7 @@ select r.id, '日报' as type, - to_char(r.report_date, 'YYYY-MM-DD') as date, + to_char(, 'YYYY-MM-DD') as date, to_char(r.submit_time, 'HH24:MI') as time, case when coalesce(nullif(btrim(u.display_name), ''), nullif(btrim(u.username), '')) is not null @@ -431,7 +459,11 @@ end as status, rc.score, rc.comment_content as comment, - coalesce(r.report_date::timestamp + r.submit_time::time, r.created_at) as sort_time + coalesce( + ()::timestamp + + (r.submit_time at time zone 'Asia/Shanghai')::time, + r.created_at + ) as sort_time from work_daily_report r left join sys_user u on u.user_id = r.user_id and u.is_deleted = 0 left join ( @@ -459,7 +491,7 @@ select r.id, '日报' as type, - to_char(r.report_date, 'YYYY-MM-DD') as date, + to_char(, 'YYYY-MM-DD') as date, to_char(r.submit_time, 'HH24:MI') as time, case when coalesce(nullif(btrim(u.display_name), ''), nullif(btrim(u.username), '')) is not null @@ -482,7 +514,11 @@ end as status, rc.score, rc.comment_content as comment, - coalesce(r.report_date::timestamp + r.submit_time::time, r.created_at) as sort_time + coalesce( + ()::timestamp + + (r.submit_time at time zone 'Asia/Shanghai')::time, + r.created_at + ) as sort_time from work_daily_report r left join sys_user u on u.user_id = r.user_id and u.is_deleted = 0 left join ( @@ -573,7 +609,14 @@ select r.id, - to_char(r.report_date, 'YYYY-MM-DD') as reportDate, + to_char( + case + when r.submit_time is not null and (r.submit_time at time zone 'Asia/Shanghai')::time < time '10:00' + then (r.submit_time at time zone 'Asia/Shanghai')::date - 1 + else coalesce((r.submit_time at time zone 'Asia/Shanghai')::date, r.report_date) + end, + 'YYYY-MM-DD' + ) as reportDate, to_char(r.submit_time, 'YYYY-MM-DD HH24:MI') as submitTime, coalesce(nullif(btrim(u.display_name), ''), nullif(btrim(u.username), ''), '') as userName, coalesce(nullif(btrim(org_info.org_names), ''), '') as deptName, diff --git a/backend/src/test/java/com/unis/crm/service/impl/WorkServiceImplTest.java b/backend/src/test/java/com/unis/crm/service/impl/WorkServiceImplTest.java index a46b0215..9c6a3d74 100644 --- a/backend/src/test/java/com/unis/crm/service/impl/WorkServiceImplTest.java +++ b/backend/src/test/java/com/unis/crm/service/impl/WorkServiceImplTest.java @@ -21,6 +21,7 @@ import com.unis.crm.dto.work.WorkReportLineItemRequest; import com.unis.crm.dto.work.WorkTomorrowPlanItemRequest; import com.unis.crm.mapper.OpportunityMapper; import java.time.LocalDate; +import java.time.LocalDateTime; import com.unis.crm.mapper.ProfileMapper; import com.unis.crm.mapper.WorkMapper; import com.unis.crm.service.CrmDataVisibilityService; @@ -718,6 +719,20 @@ class WorkServiceImplTest { eq(17L)); } + @Test + void resolveBusinessDate_shouldUsePreviousDateBeforeTenOClock() { + assertEquals( + LocalDate.of(2026, 7, 21), + WorkServiceImpl.resolveBusinessDate(LocalDateTime.of(2026, 7, 22, 9, 59, 59))); + } + + @Test + void resolveBusinessDate_shouldUseCurrentDateFromTenOClock() { + assertEquals( + LocalDate.of(2026, 7, 22), + WorkServiceImpl.resolveBusinessDate(LocalDateTime.of(2026, 7, 22, 10, 0))); + } + @Test void saveDailyReport_shouldNotSyncOpportunitySnapshotForNonSalesRole() { CreateWorkDailyReportRequest request = new CreateWorkDailyReportRequest(); diff --git a/frontend/src/pages/Work.tsx b/frontend/src/pages/Work.tsx index 45148a3d..e8ddb089 100644 --- a/frontend/src/pages/Work.tsx +++ b/frontend/src/pages/Work.tsx @@ -219,9 +219,30 @@ const FALLBACK_OPPORTUNITY_TYPE_OPTIONS = [ { value: "替换", label: "替换" }, ] as const; +function getCurrentReportDate(now = new Date()): string { + const parts = new Intl.DateTimeFormat("en-CA", { + timeZone: "Asia/Shanghai", + year: "numeric", + month: "2-digit", + day: "2-digit", + hour: "2-digit", + hourCycle: "h23", + }).formatToParts(now); + const values = Object.fromEntries(parts.map((part) => [part.type, part.value])); + const reportDate = new Date(Date.UTC(Number(values.year), Number(values.month) - 1, Number(values.day))); + if (Number(values.hour) < 10) { + reportDate.setUTCDate(reportDate.getUTCDate() - 1); + } + return [ + reportDate.getUTCFullYear(), + String(reportDate.getUTCMonth() + 1).padStart(2, "0"), + String(reportDate.getUTCDate()).padStart(2, "0"), + ].join("-"); +} + function createEmptyReportLine(): WorkReportLineItem { return { - workDate: format(new Date(), "yyyy-MM-dd"), + workDate: getCurrentReportDate(), bizType: "sales", bizId: "", bizName: "", @@ -790,7 +811,7 @@ export default function Work() { const isMobileViewport = useIsMobileViewport(); const isWecomInternalBrowser = useIsWecomBrowser(); const disableMobileMotion = isMobileViewport || isWecomInternalBrowser; - const currentWorkDate = format(new Date(), "yyyy-MM-dd"); + const currentWorkDate = getCurrentReportDate(); const hasAutoRefreshedLocation = useRef(false); const photoInputRef = useRef(null); const historyLoadMoreRef = useRef(null); @@ -3767,7 +3788,11 @@ function HistoryCard({

{item.type}

-

{[item.date, item.time].filter(Boolean).join(" ")}

+

+ {item.type === "日报" + ? `日报日期:${item.date || "未标注日期"}` + : [item.date, item.time].filter(Boolean).join(" ")} +

@@ -4330,7 +4355,7 @@ function ReportPanel({
- 日期 {currentWorkDate} + 日报日期 {currentWorkDate}