Skip to content

Commit bb8b140

Browse files
committed
Add custom filters
1 parent db8df4a commit bb8b140

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2023-2033 WanSen AI Team, Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
5+
* with the License. A copy of the License is located at
6+
*
7+
* http://opensource.wansenai.com/apache2.0/
8+
*
9+
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
10+
* OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11+
* and limitations under the License.
12+
*/
13+
package com.wansensoft.bo
14+
15+
import com.fasterxml.jackson.core.JsonGenerator
16+
import com.fasterxml.jackson.databind.JsonSerializer
17+
import com.fasterxml.jackson.databind.SerializerProvider
18+
import java.math.BigDecimal
19+
import java.math.RoundingMode
20+
21+
class BigDecimalSerializerBO : JsonSerializer<BigDecimal>() {
22+
override fun serialize(value: BigDecimal?, gen: JsonGenerator, serializers: SerializerProvider) {
23+
if (value != null) {
24+
val scaledValue = value.setScale(3, RoundingMode.HALF_UP)
25+
if (scaledValue.stripTrailingZeros().scale() <= 0) {
26+
gen.writeNumber(scaledValue.toBigInteger())
27+
} else {
28+
gen.writeNumber(scaledValue)
29+
}
30+
} else {
31+
gen.writeNull()
32+
}
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.wansensoft.dto.product
2+
3+
data class ProductUnitStatusDTO(
4+
5+
val id: Long? = null,
6+
7+
var status: Int? = null
8+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.wansensoft.service;
2+
3+
import com.wansensoft.utils.redis.RedisUtil;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.springframework.stereotype.Service;
6+
import org.springframework.web.context.request.RequestContextHolder;
7+
import org.springframework.web.context.request.ServletRequestAttributes;
8+
9+
import java.util.Optional;
10+
11+
@Service
12+
@Slf4j
13+
public class BaseService {
14+
15+
private final RedisUtil redisUtil;
16+
17+
public BaseService(RedisUtil redisUtil) {
18+
this.redisUtil = redisUtil;
19+
}
20+
21+
public Long getCurrentUserId() {
22+
var token = httpServletRequestContextToken();
23+
return Long.parseLong(redisUtil.getString(token + ":userId"));
24+
}
25+
26+
public Long getCurrentTenantId() {
27+
var token = httpServletRequestContextToken();
28+
return Long.parseLong(redisUtil.getString(token + ":tenantId"));
29+
}
30+
31+
public String getCurrentUserName() {
32+
var token = httpServletRequestContextToken();
33+
return redisUtil.getString(token + ":userName");
34+
}
35+
36+
public String getCurrentUserAccount() {
37+
var token = httpServletRequestContextToken();
38+
return redisUtil.getString(token + ":userAccount");
39+
}
40+
41+
private String httpServletRequestContextToken() {
42+
var sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
43+
if (sra == null) {
44+
log.error("[异常]获取HttpServletRequest为空");
45+
}
46+
return Optional.ofNullable(sra.getRequest().getHeader("Authorization")).orElseThrow(null);
47+
}
48+
}

0 commit comments

Comments
 (0)