From 96fa89f2a38da894f6eba493bd0067a71fe309ff Mon Sep 17 00:00:00 2001 From: xuelijun <977662702@qq.com> Date: Fri, 23 Jan 2026 14:39:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=BC=80=E5=A7=8B=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bocai.db | Bin 122880 -> 122880 bytes .../com/tem/bocai/entity/LoginInfoResult.java | 26 +++++++++++++++- .../bocai/service/impl/LoginServiceImpl.java | 20 ++++++------ .../tem/bocai/util/SQLiteDateConverter.java | 29 ++++++++++++++++++ 4 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/tem/bocai/util/SQLiteDateConverter.java diff --git a/bocai.db b/bocai.db index 2d18136bd7ef5d1aedad31a52223b643243a5745..a1c87a15445faecd4029958663a7af56e1be17c1 100644 GIT binary patch delta 575 zcmZoTz}|3xeS);$2L=WPIUwc-VkRIqnW$qd^MOGx?G-O~BLh1}Hv`WmzEJ+1T#VdK z9NoN19FqeRGB!?F!M?ehL!O11jgM{eTAnCIxrvTaTulai?Ba@wj4j%e)p*tAbMn(O z^Wrn}(()BFGE)>X^GZ_FQ;T#Il8aIkOH$(}=kd!-R^Swi)=|jGFHVimE6qiy$lA5HFXqVF)=?-2 zx&_6Gf}+ga#G*=t?9@t-`!qL)@NH6LX<^`R*(|6~#jjAs$jx9J&crEiY%I!TWME{b zYhb8rWUOFlVr6V%Wn?({h`p*g(;mm-6hk9pAVO1OX=Px5MW`S*+mI<@Go!}gW z1tu`EY!-O%g`b0o-<*Me4!=3jZf*Y5WF}4qMpt8DMq^{J)dq$}Mur9krpA`0=0>K* z1}5ePrUpRs;T9Mv7@As{SXvocyx2GSA6yvdS_3NsQ!8UjxDZ0+<~jc}6o3}*XW)Op bzaMDvW`0ElW>-d#Qd|}?ZGWK8sIUP5$V{5) delta 428 zcmZoTz}|3xeS);$T?PgQIUwc-VkRKgn5bhcbC*G{tb>=kk%66~n}KH&Unu`hE=F!A zj&5EVj>&-u85<|8VBg%$AbBPi*&#O$wjG&C8_ZxnYpP-3Lvt$Br&%DA_vi4 zT9l)tP?lJfoRL_hVPtBm36m^Njn6C1MKdoyFFrpl4J=rXu%#fexVSvO2xvK`L8S#L zI9*U$oLUs0mk4qjrp9uh-!L2y5aj9W7!;}C?Hb9cpaJr)CNJ0K5WY={o7oop;@`~Z z@SlJ4e}91qjI5gl9(>_vW8|O1z&~fRpu!~n&2#=|C~z?HKVSeN0ie(o{_PL+85K4F E0Px^`W&i*H diff --git a/src/main/java/com/tem/bocai/entity/LoginInfoResult.java b/src/main/java/com/tem/bocai/entity/LoginInfoResult.java index e9ce2fb..e2a4bdc 100644 --- a/src/main/java/com/tem/bocai/entity/LoginInfoResult.java +++ b/src/main/java/com/tem/bocai/entity/LoginInfoResult.java @@ -1,5 +1,7 @@ package com.tem.bocai.entity; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.tem.bocai.util.SQLiteDateConverter; import jakarta.persistence.*; import lombok.Data; import net.sourceforge.tess4j.TesseractException; @@ -44,11 +46,33 @@ public class LoginInfoResult { /* @Column(name = "current_num", nullable = false) private Integer currentNum;*/ - @Column(name = "create_time", nullable = false, updatable = false) + /*@Column(name = "create_time", nullable = false, updatable = false) @Temporal(TemporalType.TIMESTAMP) private Date createTime; @Column(name = "update_time", nullable = false) @Temporal(TemporalType.TIMESTAMP) + private Date updateTime;*/ + + + /* @Column(name = "create_time", nullable = false, updatable = false) + @CreationTimestamp // Hibernate注解,自动设置创建时间 + private Date createTime; + + @Column(name = "update_time", nullable = false) + @UpdateTimestamp // Hibernate注解,自动更新时间 + private Date updateTime;*/ + @Column(name = "create_time", nullable = false, updatable = false) + @CreationTimestamp + @Convert(converter = SQLiteDateConverter.class) + private Date createTime; + + @Column(name = "update_time", nullable = false) + @UpdateTimestamp + @Convert(converter = SQLiteDateConverter.class) private Date updateTime; + + @Column(name = "start_time") + @Convert(converter = SQLiteDateConverter.class) + private Date startTime; } \ No newline at end of file diff --git a/src/main/java/com/tem/bocai/service/impl/LoginServiceImpl.java b/src/main/java/com/tem/bocai/service/impl/LoginServiceImpl.java index 6756f9d..35c1907 100644 --- a/src/main/java/com/tem/bocai/service/impl/LoginServiceImpl.java +++ b/src/main/java/com/tem/bocai/service/impl/LoginServiceImpl.java @@ -13,6 +13,7 @@ import org.springframework.stereotype.Service; import net.sourceforge.tess4j.Tesseract; import org.apache.http.client.methods.*; import org.springframework.beans.factory.annotation.Autowired; + import java.io.*; import java.text.SimpleDateFormat; import java.util.Date; @@ -31,6 +32,7 @@ public class LoginServiceImpl implements LoginService { private LoginInfoRepository loginInfoRepository; private static final int MAX_CRA = 3; private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + @Override public String loginAutomatic(LoginInfoParam loginInfoParam) { String token = ""; @@ -70,7 +72,7 @@ public class LoginServiceImpl implements LoginService { e.printStackTrace(); } } - return ""; + return ""; } /* @Override @@ -158,7 +160,6 @@ public class LoginServiceImpl implements LoginService { public String saveUserInfo(LoginInfoResult loginInfoResult) { try { Optional existingUser = loginInfoRepository.findFirstByOrderByCreateTimeDesc(); - Date now = new Date(); if (existingUser.isPresent()) { // 获取数据库中已有的用户 @@ -182,18 +183,19 @@ public class LoginServiceImpl implements LoginService { } if (loginInfoResult.getOnOff() != null) { dbUser.setOnOff(loginInfoResult.getOnOff()); + if (loginInfoResult.getOnOff().equals(1)) { + dbUser.setStartTime(new Date()); + } } - - // 更新修改时间 - dbUser.setUpdateTime(now); - + // 不需要手动设置updateTime,@UpdateTimestamp会自动处理 // 保存更新后的实体 loginInfoRepository.save(dbUser); - } else { // 新增逻辑 - loginInfoResult.setCreateTime(now); - loginInfoResult.setUpdateTime(now); + // 不需要手动设置createTime和updateTime,注解会自动处理 + if (loginInfoResult.getOnOff() != null && loginInfoResult.getOnOff().equals(1)) { + loginInfoResult.setStartTime(new Date()); + } loginInfoRepository.save(loginInfoResult); } diff --git a/src/main/java/com/tem/bocai/util/SQLiteDateConverter.java b/src/main/java/com/tem/bocai/util/SQLiteDateConverter.java new file mode 100644 index 0000000..9f77573 --- /dev/null +++ b/src/main/java/com/tem/bocai/util/SQLiteDateConverter.java @@ -0,0 +1,29 @@ +package com.tem.bocai.util; + +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +// SQLite时间转换器 +@Converter +public class SQLiteDateConverter implements AttributeConverter { + + private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + @Override + public String convertToDatabaseColumn(Date date) { + return date == null ? null : sdf.format(date); + } + + @Override + public Date convertToEntityAttribute(String dateString) { + try { + return dateString == null ? null : sdf.parse(dateString); + } catch (ParseException e) { + return null; + } + } +} \ No newline at end of file