From 23a5de7ab49d6e49bcfeadcdd480fefa4513c385 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 20 Nov 2024 15:44:23 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/ysk/cashier/mybatis/entity/TbShopShareRecord.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbShopShareRecord.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbShopShareRecord.java index 087f44d5..c3724166 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbShopShareRecord.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbShopShareRecord.java @@ -4,6 +4,7 @@ import java.util.Date; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.extension.activerecord.Model; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import java.io.Serializable; @@ -43,10 +44,11 @@ public class TbShopShareRecord extends Model { //0 非新用户 1 未领取 2 已领取 3 已使用 private Integer status; //生效时间/获得奖励的时间 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date rewardTime; - + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date createTime; - + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date updateTime; From 870c1d604e8fd741fc85f1e9266565db056e3b0c Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 20 Nov 2024 16:25:44 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E5=88=86=E4=BA=AB=20=E6=97=A5=E6=9C=9F?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/ysk/cashier/mybatis/entity/TbShopShareRecord.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbShopShareRecord.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbShopShareRecord.java index c3724166..40dc708b 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbShopShareRecord.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbShopShareRecord.java @@ -44,12 +44,9 @@ public class TbShopShareRecord extends Model { //0 非新用户 1 未领取 2 已领取 3 已使用 private Integer status; //生效时间/获得奖励的时间 - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") - private Date rewardTime; - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") - private Date createTime; - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") - private Date updateTime; + private String rewardTime; + private String createTime; + private String updateTime; } From 449e36ab4a31626b3632c85e0848fc81f8a7ad41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=AD=E5=87=AF=E5=87=AF?= Date: Thu, 21 Nov 2024 09:54:02 +0800 Subject: [PATCH 03/10] =?UTF-8?q?jackson=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashier/config/interceptor/WebConfig.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/config/interceptor/WebConfig.java b/eladmin-system/src/main/java/cn/ysk/cashier/config/interceptor/WebConfig.java index 37878f29..62a14e17 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/config/interceptor/WebConfig.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/config/interceptor/WebConfig.java @@ -1,9 +1,15 @@ package cn.ysk.cashier.config.interceptor; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import java.util.TimeZone; + /** * @author lyf */ @@ -13,4 +19,25 @@ public class WebConfig implements WebMvcConfigurer { public void addInterceptors(InterceptorRegistry registry){ registry.addInterceptor(new UserInterceptor()); } + + @Bean + public MappingJackson2HttpMessageConverter jackson2HttpMessageConverter() { + MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); + ObjectMapper mapper = new ObjectMapper(); + + //忽略未知属性 + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + + //日期格式转换 + //mapper.setDateFormat(new SimpleDateFormat(DateUtils.DATE_TIME_PATTERN)); + mapper.setTimeZone(TimeZone.getTimeZone("GMT+8")); + + //Long类型转String类型 + //SimpleModule simpleModule = new SimpleModule(); + //simpleModule.addSerializer(Long.class, ToStringSerializer.instance); + //simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); + //mapper.registerModule(simpleModule); + converter.setObjectMapper(mapper); + return converter; + } } From b74e455f5dd70758cb42c9e51ed94b2e98937147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=AD=E5=87=AF=E5=87=AF?= Date: Thu, 21 Nov 2024 09:59:01 +0800 Subject: [PATCH 04/10] =?UTF-8?q?jackson=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/cn/ysk/cashier/config/interceptor/WebConfig.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/config/interceptor/WebConfig.java b/eladmin-system/src/main/java/cn/ysk/cashier/config/interceptor/WebConfig.java index 62a14e17..b509581a 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/config/interceptor/WebConfig.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/config/interceptor/WebConfig.java @@ -8,6 +8,7 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConvert import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import java.text.SimpleDateFormat; import java.util.TimeZone; /** @@ -29,7 +30,7 @@ public class WebConfig implements WebMvcConfigurer { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); //日期格式转换 - //mapper.setDateFormat(new SimpleDateFormat(DateUtils.DATE_TIME_PATTERN)); + mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); mapper.setTimeZone(TimeZone.getTimeZone("GMT+8")); //Long类型转String类型 From 088d8037b8c504b17832b12896b5a0074f3dc8f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=AD=E5=87=AF=E5=87=AF?= Date: Thu, 21 Nov 2024 10:22:45 +0800 Subject: [PATCH 05/10] =?UTF-8?q?jackson=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/ysk/cashier/config/interceptor/WebConfig.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/config/interceptor/WebConfig.java b/eladmin-system/src/main/java/cn/ysk/cashier/config/interceptor/WebConfig.java index b509581a..43053cd8 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/config/interceptor/WebConfig.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/config/interceptor/WebConfig.java @@ -4,11 +4,13 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import java.text.SimpleDateFormat; +import java.util.List; import java.util.TimeZone; /** @@ -21,6 +23,11 @@ public class WebConfig implements WebMvcConfigurer { registry.addInterceptor(new UserInterceptor()); } + @Override + public void configureMessageConverters(List> converters) { + converters.add(jackson2HttpMessageConverter()); + } + @Bean public MappingJackson2HttpMessageConverter jackson2HttpMessageConverter() { MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); From afed250715201ccfb2d91576582fdefd04d4064d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=AD=E5=87=AF=E5=87=AF?= Date: Thu, 21 Nov 2024 10:54:10 +0800 Subject: [PATCH 06/10] =?UTF-8?q?jackson=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ysk/cashier/config/ConfigurerAdapter.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/config/ConfigurerAdapter.java b/eladmin-system/src/main/java/cn/ysk/cashier/config/ConfigurerAdapter.java index 10dae8bb..9b17b0e2 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/config/ConfigurerAdapter.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/config/ConfigurerAdapter.java @@ -4,19 +4,25 @@ package cn.ysk.cashier.config; import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.support.config.FastJsonConfig; import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + import java.nio.charset.StandardCharsets; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; +import java.util.TimeZone; /** * WebMvcConfigurer @@ -70,5 +76,27 @@ public class ConfigurerAdapter implements WebMvcConfigurer { converter.setSupportedMediaTypes(supportMediaTypeList); converter.setDefaultCharset(StandardCharsets.UTF_8); converters.add(converter); + converters.add(jackson2HttpMessageConverter()); + } + + @Bean + public MappingJackson2HttpMessageConverter jackson2HttpMessageConverter() { + MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); + ObjectMapper mapper = new ObjectMapper(); + + //忽略未知属性 + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + + //日期格式转换 + mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); + mapper.setTimeZone(TimeZone.getTimeZone("GMT+8")); + + //Long类型转String类型 + //SimpleModule simpleModule = new SimpleModule(); + //simpleModule.addSerializer(Long.class, ToStringSerializer.instance); + //simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); + //mapper.registerModule(simpleModule); + converter.setObjectMapper(mapper); + return converter; } } From 6c25d89eb2c94c47b3d5360a2f52832a4def24ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=AD=E5=87=AF=E5=87=AF?= Date: Thu, 21 Nov 2024 10:59:53 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E4=BA=A4=E7=8F=ADbug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/ysk/cashier/config/interceptor/WebConfig.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/config/interceptor/WebConfig.java b/eladmin-system/src/main/java/cn/ysk/cashier/config/interceptor/WebConfig.java index 43053cd8..aab72a0c 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/config/interceptor/WebConfig.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/config/interceptor/WebConfig.java @@ -2,7 +2,6 @@ package cn.ysk.cashier.config.interceptor; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; @@ -25,10 +24,10 @@ public class WebConfig implements WebMvcConfigurer { @Override public void configureMessageConverters(List> converters) { - converters.add(jackson2HttpMessageConverter()); + //converters.add(jackson2HttpMessageConverter()); } - @Bean + //@Bean public MappingJackson2HttpMessageConverter jackson2HttpMessageConverter() { MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); ObjectMapper mapper = new ObjectMapper(); From 7a305e8901ee9c59b21a7ce42f76252885bc8d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=AD=E5=87=AF=E5=87=AF?= Date: Thu, 21 Nov 2024 11:11:06 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E4=BA=A4=E7=8F=ADbug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ysk/cashier/config/ConfigurerAdapter.java | 37 +++---------------- .../cashier/config/interceptor/WebConfig.java | 36 +----------------- .../entity/TbPointsExchangeRecord.java | 5 +++ 3 files changed, 12 insertions(+), 66 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/config/ConfigurerAdapter.java b/eladmin-system/src/main/java/cn/ysk/cashier/config/ConfigurerAdapter.java index 9b17b0e2..1f5d4535 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/config/ConfigurerAdapter.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/config/ConfigurerAdapter.java @@ -4,13 +4,10 @@ package cn.ysk.cashier.config; import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.support.config.FastJsonConfig; import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; @@ -19,10 +16,8 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import java.nio.charset.StandardCharsets; -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; -import java.util.TimeZone; /** * WebMvcConfigurer @@ -34,7 +29,9 @@ import java.util.TimeZone; @EnableWebMvc public class ConfigurerAdapter implements WebMvcConfigurer { - /** 文件配置 */ + /** + * 文件配置 + */ private final FileProperties properties; public ConfigurerAdapter(FileProperties properties) { @@ -56,8 +53,8 @@ public class ConfigurerAdapter implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { FileProperties.ElPath path = properties.getPath(); - String avatarUtl = "file:" + path.getAvatar().replace("\\","/"); - String pathUtl = "file:" + path.getPath().replace("\\","/"); + String avatarUtl = "file:" + path.getAvatar().replace("\\", "/"); + String pathUtl = "file:" + path.getPath().replace("\\", "/"); registry.addResourceHandler("/avatar/**").addResourceLocations(avatarUtl).setCachePeriod(0); registry.addResourceHandler("/file/**").addResourceLocations(pathUtl).setCachePeriod(0); registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/").setCachePeriod(0); @@ -71,32 +68,10 @@ public class ConfigurerAdapter implements WebMvcConfigurer { supportMediaTypeList.add(MediaType.APPLICATION_JSON); FastJsonConfig config = new FastJsonConfig(); config.setDateFormat("yyyy-MM-dd HH:mm:ss"); - config.setSerializerFeatures(SerializerFeature.WriteMapNullValue); + config.setSerializerFeatures(SerializerFeature.WriteMapNullValue, SerializerFeature.WriteDateUseDateFormat); converter.setFastJsonConfig(config); converter.setSupportedMediaTypes(supportMediaTypeList); converter.setDefaultCharset(StandardCharsets.UTF_8); converters.add(converter); - converters.add(jackson2HttpMessageConverter()); - } - - @Bean - public MappingJackson2HttpMessageConverter jackson2HttpMessageConverter() { - MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); - ObjectMapper mapper = new ObjectMapper(); - - //忽略未知属性 - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - - //日期格式转换 - mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); - mapper.setTimeZone(TimeZone.getTimeZone("GMT+8")); - - //Long类型转String类型 - //SimpleModule simpleModule = new SimpleModule(); - //simpleModule.addSerializer(Long.class, ToStringSerializer.instance); - //simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); - //mapper.registerModule(simpleModule); - converter.setObjectMapper(mapper); - return converter; } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/config/interceptor/WebConfig.java b/eladmin-system/src/main/java/cn/ysk/cashier/config/interceptor/WebConfig.java index aab72a0c..dfe6310f 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/config/interceptor/WebConfig.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/config/interceptor/WebConfig.java @@ -1,50 +1,16 @@ package cn.ysk.cashier.config.interceptor; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.context.annotation.Configuration; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import java.text.SimpleDateFormat; -import java.util.List; -import java.util.TimeZone; - /** * @author lyf */ @Configuration public class WebConfig implements WebMvcConfigurer { @Override - public void addInterceptors(InterceptorRegistry registry){ + public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new UserInterceptor()); } - - @Override - public void configureMessageConverters(List> converters) { - //converters.add(jackson2HttpMessageConverter()); - } - - //@Bean - public MappingJackson2HttpMessageConverter jackson2HttpMessageConverter() { - MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); - ObjectMapper mapper = new ObjectMapper(); - - //忽略未知属性 - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - - //日期格式转换 - mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); - mapper.setTimeZone(TimeZone.getTimeZone("GMT+8")); - - //Long类型转String类型 - //SimpleModule simpleModule = new SimpleModule(); - //simpleModule.addSerializer(Long.class, ToStringSerializer.instance); - //simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); - //mapper.registerModule(simpleModule); - converter.setObjectMapper(mapper); - return converter; - } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbPointsExchangeRecord.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbPointsExchangeRecord.java index ff1612b6..8582d389 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbPointsExchangeRecord.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbPointsExchangeRecord.java @@ -1,5 +1,6 @@ package cn.ysk.cashier.mybatis.entity; +import com.alibaba.fastjson.annotation.JSONField; import com.baomidou.mybatisplus.annotation.*; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -106,21 +107,25 @@ public class TbPointsExchangeRecord { /** * 取消/退款时间 */ + @JSONField(format = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date cancelOrRefundTime; /** * 实际支付时间 */ + @JSONField(format = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date payTime; /** * 创建时间(下单时间) */ + @JSONField(format = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date createTime; /** * 更新时间(核销时间) */ + @JSONField(format = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date updateTime; From b233f6ea215753e190b070f5e69dc3aac0406a45 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 21 Nov 2024 14:12:35 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E5=A4=9A=E9=97=A8=E5=BA=97=20=E5=88=97?= =?UTF-8?q?=E8=A1=A8/=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rest/AuthorizationController.java | 1 + .../security/security/TokenProvider.java | 10 ++++ .../security/service/OnlineUserService.java | 13 +++++ .../controller/shop/TbShopInfoController.java | 49 ++++++++++++++++--- .../ysk/cashier/dto/shop/TbShopInfoDto.java | 5 +- .../cn/ysk/cashier/pojo/shop/TbShopInfo.java | 10 +++- .../impl/shopimpl/TbShopInfoServiceImpl.java | 45 +++++++++++++++-- .../service/shop/TbShopInfoService.java | 3 +- 8 files changed, 121 insertions(+), 15 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/config/security/rest/AuthorizationController.java b/eladmin-system/src/main/java/cn/ysk/cashier/config/security/rest/AuthorizationController.java index 0865bed7..d9d1de1f 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/config/security/rest/AuthorizationController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/config/security/rest/AuthorizationController.java @@ -137,6 +137,7 @@ public class AuthorizationController { put("user", jwtUserDto); if (byAccount != null) { put("shopId", byAccount.getId()); + put("mainId", byAccount.getId()); put("loginType", org.apache.commons.lang3.StringUtils.isNotBlank(authUser.getLoginType())?authUser.getLoginType():"merchant"); put("shopName", byAccount.getShopName()); put("logo", byAccount.getLogo()); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/config/security/security/TokenProvider.java b/eladmin-system/src/main/java/cn/ysk/cashier/config/security/security/TokenProvider.java index d66bd65c..a035a0e2 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/config/security/security/TokenProvider.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/config/security/security/TokenProvider.java @@ -73,6 +73,16 @@ public class TokenProvider implements InitializingBean { .compact(); } + public String createToken(String name,String shopId) { + return jwtBuilder + // 加入ID确保生成的 Token 都不一致 + .setId(IdUtil.simpleUUID()) + .claim(AUTHORITIES_KEY, name) + .claim("shopId",shopId) + .setSubject(name) + .compact(); + } + /** * 依据Token 获取鉴权信息 * diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/config/security/service/OnlineUserService.java b/eladmin-system/src/main/java/cn/ysk/cashier/config/security/service/OnlineUserService.java index 360d2df2..450968dc 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/config/security/service/OnlineUserService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/config/security/service/OnlineUserService.java @@ -50,6 +50,19 @@ public class OnlineUserService { redisUtils.set(properties.getOnlineKey() + token, onlineUserDto, properties.getTokenValidityInSeconds()/1000); } + public void save(String username, String nickName, String token, HttpServletRequest request,Integer shopId){ + String ip = StringUtils.getIp(request); + String browser = StringUtils.getBrowser(request); + String address = StringUtils.getCityInfo(ip); + OnlineUserDto onlineUserDto = null; + try { + onlineUserDto = new OnlineUserDto(shopId,username, nickName, null, browser , ip, address, EncryptUtils.desEncrypt(token), new Date()); + } catch (Exception e) { + log.error(e.getMessage(),e); + } + redisUtils.set(properties.getOnlineKey() + token, onlineUserDto, properties.getTokenValidityInSeconds()/1000); + } + /** * 查询全部数据 * @param filter / diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopInfoController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopInfoController.java index cf037124..a910c753 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopInfoController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopInfoController.java @@ -1,11 +1,15 @@ package cn.ysk.cashier.controller.shop; import cn.ysk.cashier.annotation.Log; +import cn.ysk.cashier.annotation.rest.AnonymousGetMapping; import cn.ysk.cashier.annotation.rest.AnonymousPostMapping; +import cn.ysk.cashier.config.security.config.bean.SecurityProperties; import cn.ysk.cashier.config.security.security.TokenProvider; import cn.ysk.cashier.config.security.service.OnlineUserService; +import cn.ysk.cashier.config.security.service.dto.JwtUserDto; import cn.ysk.cashier.dto.shop.TbShopInfoDto; import cn.ysk.cashier.dto.shop.TbShopInfoQueryCriteria; +import cn.ysk.cashier.exception.BadRequestException; import cn.ysk.cashier.pojo.shop.TbShopInfo; import cn.ysk.cashier.service.shop.TbShopInfoService; import io.swagger.annotations.Api; @@ -15,10 +19,15 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; +import java.util.HashMap; import java.util.Map; /** @@ -36,14 +45,40 @@ public class TbShopInfoController { private final TbShopInfoService tbShopInfoService; private final OnlineUserService onlineUserService; private final TokenProvider tokenProvider; + private final SecurityProperties properties; -// @Log("导出数据") -// @ApiOperation("导出数据") -// @GetMapping(value = "/download") -// @PreAuthorize("@el.check('tbShopInfo:list')") -// public void exportTbShopInfo(HttpServletResponse response, TbShopInfoQueryCriteria criteria) throws IOException { -// tbShopInfoService.download(tbShopInfoService.queryAll(criteria), response); -// } + @AnonymousPostMapping("changChildShop") + @PostMapping("changChildShop") + @ApiOperation("切换子店铺") + public ResponseEntity changChildShop(@RequestBody TbShopInfoQueryCriteria criteria, HttpServletRequest request) { + TbShopInfoDto shopInfo = tbShopInfoService.findById(criteria.getId()); + if (shopInfo != null) { + //生成token + String token = tokenProvider.createToken(shopInfo.getAccount(), criteria.getId().toString()); + Map authInfo = new HashMap(2) {{ + put("token", properties.getTokenStartWith() + token); + if (shopInfo != null) { + put("shopId", shopInfo.getId()); + put("mainId", shopInfo.getMainId()); + put("loginType", "merchant"); + put("shopName", shopInfo.getShopName()); + put("logo", shopInfo.getLogo()); + } + }}; + // 保存在线信息 + onlineUserService.save(shopInfo.getAccount(), shopInfo.getShopName(), token, request, shopInfo.getId()); + return ResponseEntity.ok(authInfo); + } else { + throw new BadRequestException("店铺信息不存在"); + } + } + + @AnonymousGetMapping("queryChildShop") + @GetMapping("queryChildShop") + @ApiOperation("查询子店铺") + public ResponseEntity queryChildShop(TbShopInfoQueryCriteria criteria){ + return new ResponseEntity<>(tbShopInfoService.queryChildShop(criteria),HttpStatus.OK); + } @GetMapping @ApiOperation("查询/shop/list") diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/TbShopInfoDto.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/TbShopInfoDto.java index 534f40af..1cd23a78 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/TbShopInfoDto.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shop/TbShopInfoDto.java @@ -37,6 +37,7 @@ public class TbShopInfoDto implements Serializable { /** 自增id */ private Integer id; + private String mainId; /** 店铺帐号 */ @NotBlank(message = "店铺账号不能为空") @@ -101,6 +102,8 @@ public class TbShopInfoDto implements Serializable { /** 未用 */ private String mchId; + private Integer tubeType; + private String registerType; /** 是否独立的微信小程序 */ @@ -112,7 +115,7 @@ public class TbShopInfoDto implements Serializable { /** 类似于这种规则51.51.570 */ private String city; - /** 店铺类型 超市--MARKET---其它店SHOP */ + /** 店铺类型 单店--only 连锁店--chain--加盟店join*/ private String type; /** 行业 */ diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java index 5720d7bd..e8302686 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/shop/TbShopInfo.java @@ -41,6 +41,10 @@ public class TbShopInfo implements Serializable { @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; + @Column(name = "`main_id`") + @ApiModelProperty(value = "总店铺帐号") + private String mainId; + @Column(name = "`account`") @ApiModelProperty(value = "店铺帐号") private String account; @@ -138,9 +142,13 @@ public class TbShopInfo implements Serializable { private String city; @Column(name = "`type`") - @ApiModelProperty(value = "店铺类型 超市--MARKET---其它店SHOP") + @ApiModelProperty(value = "店铺类型 单店--only 连锁店--chain--加盟店join") private String type; + @Column(name = "`tube_type`") + @ApiModelProperty(value = "管理 0否 1是") + private Integer tubeType; + @Column(name = "`industry`") @ApiModelProperty(value = "行业") private String industry; diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java index d7277038..bd1925fa 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java @@ -11,6 +11,7 @@ import cn.ysk.cashier.exception.BadRequestException; import cn.ysk.cashier.exception.EntityNotFoundException; import cn.ysk.cashier.mapper.shop.TbShopInfoMapper; import cn.ysk.cashier.mybatis.mapper.MpShopInfoMapper; +import cn.ysk.cashier.pojo.order.TbCashierCart; import cn.ysk.cashier.pojo.shop.TbMerchantAccount; import cn.ysk.cashier.pojo.shop.TbMerchantRegister; import cn.ysk.cashier.pojo.shop.TbPlussShopStaff; @@ -43,6 +44,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import javax.imageio.ImageIO; +import javax.persistence.criteria.Predicate; import javax.servlet.http.HttpServletResponse; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -94,6 +96,28 @@ public class TbShopInfoServiceImpl implements TbShopInfoService { return PageUtil.toPage(page); } + @Override + public List queryChildShop(TbShopInfoQueryCriteria criteria){ + List list = tbShopInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> { + Predicate query1 = criteriaBuilder.equal(root.get("id"), criteria.getId()); + Predicate query2 = criteriaBuilder.and( + criteriaBuilder.equal(root.get("mainId"), criteria.getId()), + criteriaBuilder.notEqual(root.get("type"), "only"), + criteriaBuilder.equal(root.get("tubeType"), 1) + ); + + + // 再将两个子条件进行或运算组合成最终条件 + Predicate predicate = criteriaBuilder.or( + query1, + query2 + ); + + return predicate; + }); + return list; + } + // @Override // public List queryAll(TbShopInfoQueryCriteria criteria){ // return tbShopInfoMapper.toDto(tbShopInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); @@ -120,11 +144,6 @@ public class TbShopInfoServiceImpl implements TbShopInfoService { return tbShopInfo; } - @Override - public TbShopInfoDto finByAccount(String account) { - return null; - } - @Override @Transactional(rollbackFor = Exception.class) public TbShopInfoDto create(TbShopInfoDto resources) { @@ -163,6 +182,15 @@ public class TbShopInfoServiceImpl implements TbShopInfoService { //向redis中存入key redisUtils.set(CacheKey.ACT_CODE+resources.getAccount(),"1",tbShopInfo.getExpireAt()-Instant.now().toEpochMilli()); } + + if(org.apache.commons.lang3.StringUtils.isNotBlank(resources.getType()) && !"only".equals(resources.getType())){ + if(resources.getMainId() == null){ + throw new BadRequestException("连锁店或者扩展店 主店铺不能为空"); + } + }else { + tbShopInfo.setMainId(null); + } + //增加商户详情 TbShopInfo save = tbShopInfoRepository.save(tbShopInfo); if (resources.getRegisterCode() != null) { @@ -251,6 +279,13 @@ public class TbShopInfoServiceImpl implements TbShopInfoService { @Transactional(rollbackFor = Exception.class) public void update(TbShopInfo resources) { TbShopInfo tbShopInfo = tbShopInfoRepository.findById(resources.getId()).orElseGet(TbShopInfo::new); + if(org.apache.commons.lang3.StringUtils.isNotBlank(resources.getType()) && !"only".equals(resources.getType())){ + if(resources.getMainId() == null){ + throw new BadRequestException("连锁店或者扩展店 主店铺不能为空"); + } + }else { + tbShopInfo.setMainId(null); + } if (StringUtils.isNotBlank(resources.getShopName()) && !resources.getShopName().equals(tbShopInfo.getShopName())) { shopStaffRepository.updateNameById(resources.getShopName(),resources.getId().toString()); userRepository.updateNickName(resources.getAccount(),resources.getShopName()); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopInfoService.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopInfoService.java index a45d6309..b0167366 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopInfoService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/shop/TbShopInfoService.java @@ -39,6 +39,8 @@ public interface TbShopInfoService { */ Map queryAll(TbShopInfoQueryCriteria criteria); + List queryChildShop(TbShopInfoQueryCriteria criteria); + /** * 查询所有数据不分页 * @param criteria 条件参数 @@ -54,7 +56,6 @@ public interface TbShopInfoService { TbShopInfoDto findById(Integer id); TbShopInfo findByIdInfo(Integer id); - TbShopInfoDto finByAccount(String account); /** * 创建 * @param resources / From bd820cbd4dc1df587fc3d9a6bbd125bd96c3b45d Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 21 Nov 2024 14:16:45 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E5=A4=9A=E9=97=A8=E5=BA=97=20=E5=88=97?= =?UTF-8?q?=E8=A1=A8/=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/shop/TbShopInfoController.java | 7 ------- .../impl/shopimpl/TbShopInfoServiceImpl.java | 19 ++++--------------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopInfoController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopInfoController.java index c885de1b..7b45d0a8 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopInfoController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/TbShopInfoController.java @@ -7,7 +7,6 @@ import cn.ysk.cashier.config.security.config.bean.SecurityProperties; import cn.ysk.cashier.config.security.security.TokenProvider; import cn.ysk.cashier.config.security.service.OnlineUserService; import cn.ysk.cashier.dto.BindingDto; -import cn.ysk.cashier.config.security.service.dto.JwtUserDto; import cn.ysk.cashier.dto.shop.TbShopInfoDto; import cn.ysk.cashier.dto.shop.TbShopInfoQueryCriteria; import cn.ysk.cashier.exception.BadRequestException; @@ -20,10 +19,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -55,7 +50,6 @@ public class TbShopInfoController { private final SecurityProperties properties; - @AnonymousPostMapping("changChildShop") @PostMapping("changChildShop") @ApiOperation("切换子店铺") public ResponseEntity changChildShop(@RequestBody TbShopInfoQueryCriteria criteria, HttpServletRequest request) { @@ -81,7 +75,6 @@ public class TbShopInfoController { } } - @AnonymousGetMapping("queryChildShop") @GetMapping("queryChildShop") @ApiOperation("查询子店铺") public ResponseEntity queryChildShop(TbShopInfoQueryCriteria criteria){ diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java index 340e192f..999d95ee 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java @@ -1,8 +1,5 @@ package cn.ysk.cashier.service.impl.shopimpl; -import cn.hutool.core.util.StrUtil; -import cn.hutool.extra.qrcode.QrCodeUtil; -import cn.hutool.extra.qrcode.QrConfig; import cn.hutool.http.HttpUtil; import cn.ysk.cashier.config.security.security.TokenProvider; import cn.ysk.cashier.config.security.service.UserCacheManager; @@ -12,14 +9,15 @@ import cn.ysk.cashier.dto.shop.TbShopInfoQueryCriteria; import cn.ysk.cashier.exception.BadRequestException; import cn.ysk.cashier.exception.EntityNotFoundException; import cn.ysk.cashier.mapper.shop.TbShopInfoMapper; -import cn.ysk.cashier.mybatis.mapper.MpShopInfoMapper; -import cn.ysk.cashier.pojo.order.TbCashierCart; import cn.ysk.cashier.pojo.shop.TbMerchantAccount; import cn.ysk.cashier.pojo.shop.TbMerchantRegister; import cn.ysk.cashier.pojo.shop.TbPlussShopStaff; import cn.ysk.cashier.pojo.shop.TbShopInfo; import cn.ysk.cashier.repository.TbShopPayTypeRepository; -import cn.ysk.cashier.repository.shop.*; +import cn.ysk.cashier.repository.shop.TbMerchantAccountRepository; +import cn.ysk.cashier.repository.shop.TbMerchantRegisterRepository; +import cn.ysk.cashier.repository.shop.TbPlussShopStaffRepository; +import cn.ysk.cashier.repository.shop.TbShopInfoRepository; import cn.ysk.cashier.service.WxService; import cn.ysk.cashier.service.shop.TbShopInfoService; import cn.ysk.cashier.system.domain.Dept; @@ -32,11 +30,8 @@ import cn.ysk.cashier.system.service.ParamsService; import cn.ysk.cashier.system.service.UserService; import cn.ysk.cashier.utils.*; import com.alibaba.fastjson.JSONObject; -import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.io.ResourceLoader; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -46,13 +41,9 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import javax.imageio.ImageIO; import javax.persistence.criteria.Predicate; import javax.servlet.http.HttpServletResponse; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.InputStream; import java.time.Instant; import java.util.*; @@ -76,8 +67,6 @@ public class TbShopInfoServiceImpl implements TbShopInfoService { private final UserService userService; - private final UserCacheManager userCacheManager; - private final TokenProvider tokenProvider; private final ParamsService paramsService; private final TbMerchantRegisterRepository merchantRegisterRepository;