Commit 591c0ca7ad021f0168abec69b7826bdd126d4c94
1 parent
e79b3e45
新增数量计算防错更新方法
Showing
1 changed file
with
45 additions
and
2 deletions
huaheng-wms-core/src/main/java/org/jeecg/utils/HuahengJwtUtil.java
1 | 1 | package org.jeecg.utils; |
2 | 2 | |
3 | 3 | import java.lang.reflect.Field; |
4 | +import java.math.BigDecimal; | |
4 | 5 | import java.util.Date; |
5 | 6 | import java.util.List; |
6 | 7 | import java.util.UUID; |
... | ... | @@ -25,9 +26,11 @@ import com.auth0.jwt.exceptions.JWTDecodeException; |
25 | 26 | import com.auth0.jwt.interfaces.DecodedJWT; |
26 | 27 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
27 | 28 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
29 | +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | |
28 | 30 | |
29 | 31 | import cn.hutool.core.date.DateUtil; |
30 | 32 | import cn.hutool.core.util.ReflectUtil; |
33 | +import cn.hutool.core.util.StrUtil; | |
31 | 34 | |
32 | 35 | @Component |
33 | 36 | public class HuahengJwtUtil { |
... | ... | @@ -43,7 +46,7 @@ public class HuahengJwtUtil { |
43 | 46 | |
44 | 47 | /** 全仓CODE */ |
45 | 48 | public static final String ALL_WAREHOUSE_CODE = "ALL_WAREHOUSE"; |
46 | - | |
49 | + | |
47 | 50 | /** 定时任务操作人 */ |
48 | 51 | public static final String TASK_AUDIENCE_NAME = "SYSTEM_TASK"; |
49 | 52 | |
... | ... | @@ -260,5 +263,45 @@ public class HuahengJwtUtil { |
260 | 263 | return null; |
261 | 264 | } |
262 | 265 | } |
263 | -} | |
264 | 266 | |
267 | + /** | |
268 | + * 根据数据库中attribute的数量的值计算数量。quantity = 正数,增加attribute的值,quantity = 负数,减少attribute的值 | |
269 | + * @author TanYibin | |
270 | + * @createDate 2023年5月30日 | |
271 | + * @param <T> | |
272 | + * @param lambdaUpdateWrapper | |
273 | + * @param attribute | |
274 | + * @param quantity | |
275 | + */ | |
276 | + public static <T> void calculateQuantity(LambdaUpdateWrapper<T> lambdaUpdateWrapper, String attribute, BigDecimal quantity) { | |
277 | + HuahengJwtUtil.calculateQuantity(lambdaUpdateWrapper, null, attribute, quantity, false); | |
278 | + } | |
279 | + | |
280 | + /** | |
281 | + * 根据数据库中attribute的数量的值计算数量。quantity = 正数,增加attribute的值,quantity = 负数,减少attribute的值,并将t中属性的值设置为null,以免影响属性赋值 | |
282 | + * @author TanYibin | |
283 | + * @createDate 2023年5月30日 | |
284 | + * @param <T> | |
285 | + * @param lambdaUpdateWrapper | |
286 | + * @param attribute | |
287 | + * @param quantity | |
288 | + */ | |
289 | + public static <T> void calculateQuantity(LambdaUpdateWrapper<T> lambdaUpdateWrapper, T t, String attribute, BigDecimal quantity) { | |
290 | + HuahengJwtUtil.calculateQuantity(lambdaUpdateWrapper, t, attribute, quantity, false); | |
291 | + } | |
292 | + | |
293 | + public static <T> void calculateQuantity(LambdaUpdateWrapper<T> lambdaUpdateWrapper, String attribute, BigDecimal quantity, Boolean geZero) { | |
294 | + HuahengJwtUtil.calculateQuantity(lambdaUpdateWrapper, null, attribute, quantity, geZero); | |
295 | + } | |
296 | + | |
297 | + public static <T> void calculateQuantity(LambdaUpdateWrapper<T> lambdaUpdateWrapper, T t, String attribute, BigDecimal quantity, Boolean geZero) { | |
298 | + String sqlAttribute = StrUtil.toUnderlineCase(attribute); | |
299 | + if (geZero) { | |
300 | + lambdaUpdateWrapper.apply(quantity != null, sqlAttribute + " + {0} >= 0", quantity); | |
301 | + } | |
302 | + lambdaUpdateWrapper.setSql(quantity != null, sqlAttribute + " = " + sqlAttribute + " + " + quantity); | |
303 | + if (t != null) { | |
304 | + ReflectUtil.setFieldValue(t, attribute, null); | |
305 | + } | |
306 | + } | |
307 | +} | |
... | ... |