From ae9afa472f35ccddfe295ab691aee72b420960b3 Mon Sep 17 00:00:00 2001 From: "382696293@qq.com" <382696293@qq.com> Date: Thu, 29 Feb 2024 11:19:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=A4=E7=90=86=E8=AE=B0=E5=BD=95=EF=BC=9A?= =?UTF-8?q?=E6=80=BB=E6=8A=A4=E7=90=86=E6=AC=A1=E6=95=B0=EF=BC=8C=E6=9C=AC?= =?UTF-8?q?=E5=B9=B4=E6=8A=A4=E7=90=86=E6=AC=A1=E6=95=B0=EF=BC=8C=E6=9C=AC?= =?UTF-8?q?=E6=9C=88=E6=8A=A4=E7=90=86=E6=AC=A1=E6=95=B0=EF=BC=8C=E6=9C=AC?= =?UTF-8?q?=E5=91=A8=E6=8A=A4=E7=90=86=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/mapper/WxNursingLogMapper.java | 2 + .../resources/mapper/WxNursingLogMapper.xml | 28 +++++++- .../service/impl/WxNursingLogServiceImpl.java | 64 +++++++++++++++++-- 3 files changed, 89 insertions(+), 5 deletions(-) diff --git a/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/mapper/WxNursingLogMapper.java b/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/mapper/WxNursingLogMapper.java index 3025590..0eaf23a 100644 --- a/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/mapper/WxNursingLogMapper.java +++ b/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/mapper/WxNursingLogMapper.java @@ -64,4 +64,6 @@ public interface WxNursingLogMapper { public int deleteWxNursingLogByIds(Long[] ids); List selectWxNursingLogByIdList(@Param("idList") List idList); + + WxNursingLog selectLastNursingLogByUserId(@Param("userId") Long userId, @Param("instrumentId") Long instrumentId); } diff --git a/flossom-common/flossom-common-core/src/main/resources/mapper/WxNursingLogMapper.xml b/flossom-common/flossom-common-core/src/main/resources/mapper/WxNursingLogMapper.xml index b7031f5..bb625c9 100644 --- a/flossom-common/flossom-common-core/src/main/resources/mapper/WxNursingLogMapper.xml +++ b/flossom-common/flossom-common-core/src/main/resources/mapper/WxNursingLogMapper.xml @@ -19,10 +19,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + - select id, user_id, instrument_id, instrument_name, online, mode_id, mode_name, nursing_time, completion_percentage, status, create_by, create_time, update_by, update_time from wx_nursing_log + select id, user_id, instrument_id, instrument_name, online, mode_id, mode_name, nursing_time, completion_percentage, status, create_by, create_time, update_by, update_time, nursing_days, nursing_days_week, nursing_days_month, nursing_days_year from wx_nursing_log + + insert into wx_nursing_log @@ -113,6 +127,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" create_time, update_by, update_time, + nursing_days, + nursing_days_week, + nursing_days_month, + nursing_days_year, #{userId}, @@ -128,6 +146,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{createTime}, #{updateBy}, #{updateTime}, + #{nursingDays}, + #{nursingDaysWeek}, + #{nursingDaysMonth}, + #{nursingDaysYear}, @@ -147,6 +169,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" create_time = #{createTime}, update_by = #{updateBy}, update_time = #{updateTime}, + nursing_days = #{nursingDays}, + nursing_days_week = #{nursingDaysWeek}, + nursing_days_month = #{nursingDaysMonth}, + nursing_days_year = #{nursingDaysYear}, where id = #{id} diff --git a/flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/service/impl/WxNursingLogServiceImpl.java b/flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/service/impl/WxNursingLogServiceImpl.java index 4ebfb69..2b544cc 100644 --- a/flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/service/impl/WxNursingLogServiceImpl.java +++ b/flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/service/impl/WxNursingLogServiceImpl.java @@ -1,9 +1,6 @@ package com.flossom.miniProgram.service.impl; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.ZoneId; +import java.time.*; import java.time.temporal.TemporalAdjusters; import java.util.List; import java.util.Map; @@ -191,6 +188,65 @@ public class WxNursingLogServiceImpl implements IWxNursingLogService { wxNursingLog.setUpdateBy(SecurityUtils.getLoginUser().getWxUserMember().getNickname()); wxNursingLog.setUpdateTime(DateUtils.getNowDate()); wxNursingLog.setStatus(Status.OK.getCode().longValue()); + + /* 护理天数计算 */ + // 1、获取最近一条护理记录 + WxNursingLog lastNursingLog = wxNursingLogMapper.selectLastNursingLogByUserId(SecurityUtils.getLoginUser().getWxUserMember().getId(), wxNursingLog.getInstrumentId()); + if (lastNursingLog != null) { + // 2、有最近的一条护理记录 + // 获取护理时间和当前时间,转为 localDateTime + LocalDateTime nursingDateTime = LocalDateTime.ofInstant(lastNursingLog.getCreateTime().toInstant(), ZoneId.systemDefault()); + LocalDateTime nowDateTime = LocalDateTime.now(); + // 2.1、总护理天数:直接 +1 + if (lastNursingLog.getNursingDays() != null) { + wxNursingLog.setNursingDays(lastNursingLog.getNursingDays() + 1); + } else { + // 总护理天数为null,说明之前没有计算总数,目前是直接重新开始 + wxNursingLog.setNursingDays(1); + } + // 2.2、本年护理天数:判断是否是本年的记录,是 +1,不是则为1 + LocalDateTime firstDateOfYear = nowDateTime.with(TemporalAdjusters.firstDayOfYear()).with(LocalTime.MIN); + LocalDateTime lastDateOfYear = nowDateTime.with(TemporalAdjusters.lastDayOfYear()).with(LocalTime.MAX); + if (lastNursingLog.getNursingDaysYear() != null && ( + nursingDateTime.isEqual(firstDateOfYear) || nursingDateTime.isEqual(lastDateOfYear) + || (nursingDateTime.isAfter(firstDateOfYear) && nursingDateTime.isBefore(lastDateOfYear)) + )) { + wxNursingLog.setNursingDaysYear(lastNursingLog.getNursingDaysYear() + 1); + } else { + // 本年护理天数为null,有两种情况,要么之前没有计算,要么是新的一年的第一条护理记录,目前是直接重新开始 + wxNursingLog.setNursingDaysYear(1); + } + // 2.3、本月护理天数:判断是否是本月的记录,是 +1,不是则为1 + LocalDateTime firstDateOfMonth = nowDateTime.with(TemporalAdjusters.firstDayOfMonth()).with(LocalTime.MIN); + LocalDateTime lastDateOfMonth = nowDateTime.with(TemporalAdjusters.lastDayOfMonth()).with(LocalTime.MAX); + if (lastNursingLog.getNursingDaysMonth() != null && ( + nursingDateTime.isEqual(firstDateOfMonth) || nursingDateTime.isEqual(lastDateOfMonth) + || (nursingDateTime.isAfter(firstDateOfMonth) && nursingDateTime.isBefore(lastDateOfMonth)) + )) { + wxNursingLog.setNursingDaysMonth(lastNursingLog.getNursingDaysMonth() + 1); + } else { + // 本月护理天数为null,有两种情况,要么之前没有计算,要么是新的一月的第一条护理记录,目前是直接重新开始 + wxNursingLog.setNursingDaysMonth(1); + } + // 2.4、本周护理天数:判断是否是本周的记录,是 +1,不是则为1 + LocalDateTime firstDateOfWeek = nowDateTime.toLocalDate().with(DayOfWeek.MONDAY).atStartOfDay(); + LocalDateTime lastDateOfWeek = nowDateTime.toLocalDate().with(DayOfWeek.SUNDAY).atTime(LocalTime.MAX); + if (lastNursingLog.getNursingDaysWeek() != null && ( + nursingDateTime.isEqual(firstDateOfWeek) || nursingDateTime.isEqual(lastDateOfWeek) + || (nursingDateTime.isAfter(firstDateOfWeek) && nursingDateTime.isBefore(lastDateOfWeek)) + )) { + wxNursingLog.setNursingDaysWeek(lastNursingLog.getNursingDaysWeek() + 1); + } else { + // 本周护理天数为null,有两种情况,要么之前没有计算,要么是新的一周的第一条护理记录,目前是直接重新开始 + wxNursingLog.setNursingDaysWeek(1); + } + } else { + // 3、没有最近的一条护理记录 + wxNursingLog.setNursingDays(1); + wxNursingLog.setNursingDaysYear(1); + wxNursingLog.setNursingDaysMonth(1); + wxNursingLog.setNursingDaysWeek(1); + } wxNursingLogMapper.insertWxNursingLog(wxNursingLog); } }