diff --git a/consumer/src/main/java/cn/lili/event/impl/StockUpdateExecute.java b/consumer/src/main/java/cn/lili/event/impl/StockUpdateExecute.java index 7c54b374..216b4331 100644 --- a/consumer/src/main/java/cn/lili/event/impl/StockUpdateExecute.java +++ b/consumer/src/main/java/cn/lili/event/impl/StockUpdateExecute.java @@ -1,5 +1,6 @@ package cn.lili.event.impl; +import cn.hutool.core.convert.Convert; import cn.lili.common.cache.Cache; import cn.lili.event.OrderStatusChangeEvent; import cn.lili.modules.goods.entity.dos.GoodsSku; @@ -188,7 +189,7 @@ public class StockUpdateExecute implements OrderStatusChangeEvent { List skuStocks = cache.multiGet(skuKeys); //循环写入商品库存 for (int i = 0; i < skuStocks.size(); i++) { - goodsSkus.get(i).setQuantity(Integer.parseInt(skuStocks.get(i).toString())); + goodsSkus.get(i).setQuantity(Convert.toInt(skuStocks.get(i).toString())); } //批量修改商品库存 goodsSkuService.updateBatchById(goodsSkus); @@ -197,7 +198,7 @@ public class StockUpdateExecute implements OrderStatusChangeEvent { if (!promotionKey.isEmpty()) { List promotionStocks = cache.multiGet(promotionKey); for (int i = 0; i < promotionKey.size(); i++) { - promotionGoods.get(i).setQuantity(Integer.parseInt(promotionStocks.get(i).toString())); + promotionGoods.get(i).setQuantity(Convert.toInt(promotionStocks.get(i).toString())); Integer num = promotionGoods.get(i).getNum(); promotionGoods.get(i).setNum((num != null ? num : 0) + order.getOrder().getGoodsNum()); } @@ -232,7 +233,7 @@ public class StockUpdateExecute implements OrderStatusChangeEvent { List skuStocks = cache.multiGet(skuKeys); //循环写入商品SKU库存 for (int i = 0; i < skuStocks.size(); i++) { - goodsSkus.get(i).setQuantity(Integer.parseInt(skuStocks.get(i).toString())); + goodsSkus.get(i).setQuantity(Convert.toInt(skuStocks.get(i).toString())); } log.info("订单取消,库存还原:{}", goodsSkus); //批量修改商品库存 diff --git a/consumer/src/main/java/cn/lili/timetask/handler/impl/goods/GoodsExecute.java b/consumer/src/main/java/cn/lili/timetask/handler/impl/goods/GoodsExecute.java index 3bcdbf1e..f9d92ea6 100644 --- a/consumer/src/main/java/cn/lili/timetask/handler/impl/goods/GoodsExecute.java +++ b/consumer/src/main/java/cn/lili/timetask/handler/impl/goods/GoodsExecute.java @@ -1,5 +1,6 @@ package cn.lili.timetask.handler.impl.goods; +import cn.hutool.core.convert.Convert; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import cn.lili.modules.goods.mapper.GoodsMapper; @@ -40,7 +41,7 @@ public class GoodsExecute implements EveryDayExecute { .between("create_time", DateUtil.yesterday(), new DateTime())); for (Map map : list) { - goodsMapper.addGoodsCommentNum(Integer.parseInt(map.get("num").toString()), map.get("goods_id").toString()); + goodsMapper.addGoodsCommentNum(Convert.toInt(map.get("num").toString()), map.get("goods_id").toString()); } } diff --git a/consumer/src/main/java/cn/lili/timetask/handler/impl/view/PageViewStatisticsExecute.java b/consumer/src/main/java/cn/lili/timetask/handler/impl/view/PageViewStatisticsExecute.java index 22c0a9f4..2daf4256 100644 --- a/consumer/src/main/java/cn/lili/timetask/handler/impl/view/PageViewStatisticsExecute.java +++ b/consumer/src/main/java/cn/lili/timetask/handler/impl/view/PageViewStatisticsExecute.java @@ -1,5 +1,6 @@ package cn.lili.timetask.handler.impl.view; +import cn.hutool.core.convert.Convert; import cn.lili.common.cache.Cache; import cn.lili.common.cache.CachePrefix; import cn.lili.common.utils.BeanUtil; @@ -167,15 +168,15 @@ class PageViewStatistics { //将字符串解析成需要的对象 str = str.substring(str.indexOf("}") + 2); String[] dateStr = str.split("-"); - Integer year = Integer.parseInt(dateStr[0]); - Integer month = Integer.parseInt(dateStr[1]); + Integer year = Convert.toInt(dateStr[0]); + Integer month = Convert.toInt(dateStr[1]); Integer day; //是否有店铺id if (dateStr.length > 3) { - day = Integer.parseInt(dateStr[2]); + day = Convert.toInt(dateStr[2]); this.storeId = dateStr[3]; } else { - day = Integer.parseInt(dateStr[2]); + day = Convert.toInt(dateStr[2]); } Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); diff --git a/framework/src/main/java/cn/lili/common/aop/limiter/LimitInterceptor.java b/framework/src/main/java/cn/lili/common/aop/limiter/LimitInterceptor.java index ff0b5210..2e625ef9 100644 --- a/framework/src/main/java/cn/lili/common/aop/limiter/LimitInterceptor.java +++ b/framework/src/main/java/cn/lili/common/aop/limiter/LimitInterceptor.java @@ -1,6 +1,7 @@ package cn.lili.common.aop.limiter; import cn.lili.common.aop.limiter.annotation.LimitPoint; +import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; import com.google.common.collect.ImmutableList; import lombok.extern.slf4j.Slf4j; @@ -60,7 +61,7 @@ public class LimitInterceptor { log.info("限制请求{}, 当前请求{},缓存key{}", limitCount, count.intValue(), key); //如果缓存里没有值,或者他的值小于限制频率 if (count.intValue() >= limitCount) { - throw new ServiceException("访问过于频繁,请稍后再试"); + throw new ServiceException(ResultCode.LIMIT_ERROR); } } //如果从redis中执行都值判定为空,则这里跳过 diff --git a/framework/src/main/java/cn/lili/common/enums/ResultCode.java b/framework/src/main/java/cn/lili/common/enums/ResultCode.java index d0dec479..d1b6598e 100644 --- a/framework/src/main/java/cn/lili/common/enums/ResultCode.java +++ b/framework/src/main/java/cn/lili/common/enums/ResultCode.java @@ -27,6 +27,17 @@ public enum ResultCode { * 参数异常 */ PARAMS_ERROR(4002, "参数异常"), + /** + * 非法请求 + */ + ILLEGAL_REQUEST_ERROR(4003, "非法请求,请重新刷新页面操作"), + + /** + * 高频访问错误 + */ + LIMIT_ERROR(4004,"访问过于频繁,请稍后再试"), + + /** @@ -65,6 +76,7 @@ public enum ResultCode { GOODS_SKU_QUANTITY_ERROR(11011, "商品库存数量不能为负数"), GOODS_SKU_QUANTITY_NOT_ENOUGH(11011, "商品库存不足"), MUST_HAVE_GOODS_SKU(11012,"规格必须要有一个!"), + GOODS_PARAMS_ERROR(11013,"商品参数错误,刷新后重试"), /** * 参数 @@ -349,16 +361,25 @@ public enum ResultCode { * 直播 */ STODIO_GOODS_EXIST_ERROR(44001,"直播商品已存在"), + COMMODITY_ERROR(44002,"添加直播商品失败"), /** * 秒杀 */ - SECKILL_NOT_EXIST(45001,"当前参与的秒杀活动不存在!"), + SECKILL_NOT_EXIST_ERROR(45001,"当前参与的秒杀活动不存在!"), + SECKILL_UPDATE_ERROR(45002,"当前秒杀活动活动已经开始,无法修改!"), + SECKILL_PRICE_ERROR(45003,"活动价格不能大于商品原价"), + SECKILL_TIME_ERROR(45004,"时刻参数异常"), + /** * 优惠券活动 */ COUPON_ACTIVITY_START_TIME_ERROR(46001,"活动时间小于当前时间,不能进行编辑删除操作"), + COUPON_ACTIVITY_MEMBER_ERROR(46002,"指定精准发券则必须指定会员,会员不可以为空"), + COUPON_ACTIVITY_ITEM_ERROR(46003,"优惠券活动必须指定优惠券,不能为空"), + COUPON_ACTIVITY_ITEM_MUST_NUM_ERROR(46004,"优惠券活动最多指定10个优惠券"), + COUPON_ACTIVITY_ITEM_NUM_ERROR(46005,"赠券数量必须大于0"), /** * 店铺 @@ -413,69 +434,68 @@ public enum ResultCode { */ SETTING_NOT_TO_SET(70001, "该参数不需要设置"), - /** - * 短信 - */ - SMS_SIGN_EXIST_ERROR(80001, "短信签名已存在"), + ALIPAY_NOT_SETTING(70002, "支付宝支付未配置"), + ALIPAY_EXCEPTION(70003, "支付宝支付错误,请稍后重试"), + + ALIPAY_PARAMS_EXCEPTION(70004, "支付宝参数异常"), + + LOGISTICS_NOT_SETTING(70005,"您还未配置快递查询"), + + ORDER_SETTING_ERROR(70006,"系统订单配置异常"), + + ALI_SMS_SETTING_ERROR(70007,"您还未配置阿里云短信"), + + SMS_SIGN_EXIST_ERROR(70008, "短信签名已存在"), /** * 站内信 */ - NOTICE_NOT_EXIST(80101, "当前消息模板不存在"), + NOTICE_NOT_EXIST(80001, "当前消息模板不存在"), - NOTICE_ERROR(80102, "修改站内信异常,请稍后重试"), + NOTICE_ERROR(80002, "修改站内信异常,请稍后重试"), /** * OSS */ - OSS_NOT_EXIST(80201, "OSS未配置"), + OSS_NOT_EXIST(80101, "OSS未配置"), - OSS_EXCEPTION(80202, "文件上传失败,请稍后重试"), + OSS_EXCEPTION(80102, "文件上传失败,请稍后重试"), /** * 验证码 */ - VERIFICATION_SEND_SUCCESS(80301, "短信验证码,发送成功"), + VERIFICATION_SEND_SUCCESS(80201, "短信验证码,发送成功"), - VERIFICATION_ERROR(80302, "验证失败"), + VERIFICATION_ERROR(80202, "验证失败"), - VERIFICATION_SMS_ERROR(80303, "短信验证码错误,请重新校验"), - - VERIFICATION_SMS_EXPIRED_ERROR(80304, "验证码已失效,请重新校验"), - - /** - * 配置错误 - */ - ALIPAY_NOT_SETTING(80401, "支付宝支付未配置"), - - ALIPAY_EXCEPTION(80402, "支付宝支付错误,请稍后重试"), - - ALIPAY_PARAMS_EXCEPTION(80403, "支付宝参数异常"), - - LOGISTICS_NOT_SETTING(80404,"您还未配置快递查询"), - - ORDER_SETTING_ERROR(80405,"系统订单配置异常"), - - ALI_SMS_SETTING_ERROR(80406,"您还未配置阿里云短信"), + VERIFICATION_SMS_ERROR(80203, "短信验证码错误,请重新校验"), + VERIFICATION_SMS_EXPIRED_ERROR(80204, "验证码已失效,请重新校验"), /** * 微信相关异常 */ - WECHAT_CONNECT_NOT_SETTING(80500, "微信联合登陆信息未配置"), + WECHAT_CONNECT_NOT_SETTING(80300, "微信联合登陆信息未配置"), - WECHAT_PAYMENT_NOT_SETTING(80501, "微信支付信息未配置"), + WECHAT_PAYMENT_NOT_SETTING(80301, "微信支付信息未配置"), - WECHAT_QRCODE_ERROR(80502, "微信二维码生成异常"), + WECHAT_QRCODE_ERROR(80302, "微信二维码生成异常"), - WECHAT_MP_MESSAGE_ERROR(80503, "微信小程序小消息订阅异常"), + WECHAT_MP_MESSAGE_ERROR(80303, "微信小程序小消息订阅异常"), - WECHAT_JSAPI_SIGN_ERROR(80504,"微信JsApi签名异常"), + WECHAT_JSAPI_SIGN_ERROR(80304,"微信JsApi签名异常"), WECHAT_CERT_ERROR(80505,"证书获取失败"), - APP_VERSION_EXIST(80600, "APP版本已存在"); + APP_VERSION_EXIST(80600, "APP版本已存在"), + + CUSTOM_WORDS_EXIST_ERROR(90000, "当前自定义分词已存在!"), + CUSTOM_WORDS_NOT_EXIST_ERROR(90000, "当前自定义分词不存在!"), + CONNECT_NOT_EXIST(90000,"登录方式不存在"), + + + ; private final Integer code; private final String message; diff --git a/framework/src/main/java/cn/lili/common/utils/StringUtils.java b/framework/src/main/java/cn/lili/common/utils/StringUtils.java index e97c61c4..b8e29aa7 100644 --- a/framework/src/main/java/cn/lili/common/utils/StringUtils.java +++ b/framework/src/main/java/cn/lili/common/utils/StringUtils.java @@ -1,5 +1,6 @@ package cn.lili.common.utils; +import cn.hutool.core.convert.Convert; import cn.hutool.core.util.StrUtil; import java.beans.BeanInfo; @@ -61,7 +62,7 @@ public class StringUtils extends StrUtil { return 0; } try { - value = Integer.parseInt(obj.toString()); + value = Convert.toInt(obj.toString()); } catch (Exception ex) { if (checked) { throw new RuntimeException("整型数字格式不正确"); diff --git a/framework/src/main/java/cn/lili/common/verification/service/impl/VerificationServiceImpl.java b/framework/src/main/java/cn/lili/common/verification/service/impl/VerificationServiceImpl.java index 6321b365..53a87813 100644 --- a/framework/src/main/java/cn/lili/common/verification/service/impl/VerificationServiceImpl.java +++ b/framework/src/main/java/cn/lili/common/verification/service/impl/VerificationServiceImpl.java @@ -2,6 +2,7 @@ package cn.lili.common.verification.service.impl; import cn.lili.common.cache.Cache; import cn.lili.common.cache.CachePrefix; +import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; import cn.lili.common.utils.StringUtils; import cn.lili.common.verification.SliderImageUtil; @@ -47,7 +48,7 @@ public class VerificationServiceImpl implements VerificationService { public Map createVerification(VerificationEnums verificationEnums, String uuid) throws IOException { if (uuid == null) { - throw new ServiceException("非法请求,请重新刷新页面操作"); + throw new ServiceException(ResultCode.ILLEGAL_REQUEST_ERROR); } //获取验证码配置 diff --git a/framework/src/main/java/cn/lili/config/elasticsearch/ElasticsearchConfig.java b/framework/src/main/java/cn/lili/config/elasticsearch/ElasticsearchConfig.java index 989220f8..e25bb9d7 100644 --- a/framework/src/main/java/cn/lili/config/elasticsearch/ElasticsearchConfig.java +++ b/framework/src/main/java/cn/lili/config/elasticsearch/ElasticsearchConfig.java @@ -1,5 +1,6 @@ package cn.lili.config.elasticsearch; +import cn.hutool.core.convert.Convert; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpHost; @@ -75,7 +76,7 @@ public class ElasticsearchConfig extends AbstractElasticsearchConfiguration { HttpHost[] httpHosts = new HttpHost[clusterNodes.size()]; for (int i = 0; i < clusterNodes.size(); i++) { String[] node = clusterNodes.get(i).split(":"); - httpHosts[i] = new HttpHost(node[0], Integer.parseInt(node[1]), elasticsearchProperties.getSchema()); + httpHosts[i] = new HttpHost(node[0], Convert.toInt(node[1]), elasticsearchProperties.getSchema()); } return httpHosts; } diff --git a/framework/src/main/java/cn/lili/config/sharding/CreateTimeShardingTableAlgorithm.java b/framework/src/main/java/cn/lili/config/sharding/CreateTimeShardingTableAlgorithm.java index e640e877..ab83fc26 100644 --- a/framework/src/main/java/cn/lili/config/sharding/CreateTimeShardingTableAlgorithm.java +++ b/framework/src/main/java/cn/lili/config/sharding/CreateTimeShardingTableAlgorithm.java @@ -1,5 +1,6 @@ package cn.lili.config.sharding; +import cn.hutool.core.convert.Convert; import cn.lili.common.utils.DateUtil; import com.google.common.collect.Range; import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm; @@ -34,10 +35,10 @@ public class CreateTimeShardingTableAlgorithm implements PreciseShardingAlgorith Collection collect = new ArrayList<>(); Range valueRange = rangeShardingValue.getValueRange(); - Integer startMonth = Integer.parseInt(DateUtil.toString(valueRange.lowerEndpoint().longValue(), "MM")); - Integer endMonth = Integer.parseInt(DateUtil.toString(valueRange.upperEndpoint().longValue(), "MM")); - Integer startYear = Integer.parseInt(DateUtil.toString(valueRange.lowerEndpoint().longValue(), "yyyy")); - Integer endYear = Integer.parseInt(DateUtil.toString(valueRange.upperEndpoint().longValue(), "yyyy")); + Integer startMonth = Convert.toInt(DateUtil.toString(valueRange.lowerEndpoint().longValue(), "MM")); + Integer endMonth = Convert.toInt(DateUtil.toString(valueRange.upperEndpoint().longValue(), "MM")); + Integer startYear = Convert.toInt(DateUtil.toString(valueRange.lowerEndpoint().longValue(), "yyyy")); + Integer endYear = Convert.toInt(DateUtil.toString(valueRange.upperEndpoint().longValue(), "yyyy")); //如果是同一年查询 //2020-1~2020-2 diff --git a/framework/src/main/java/cn/lili/modules/broadcast/serviceimpl/CommodityServiceImpl.java b/framework/src/main/java/cn/lili/modules/broadcast/serviceimpl/CommodityServiceImpl.java index beabdc2e..65608071 100644 --- a/framework/src/main/java/cn/lili/modules/broadcast/serviceimpl/CommodityServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/broadcast/serviceimpl/CommodityServiceImpl.java @@ -4,6 +4,7 @@ import cn.hutool.core.convert.Convert; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; +import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; import cn.lili.common.security.context.UserContext; import cn.lili.common.security.enums.UserEnums; @@ -50,7 +51,8 @@ public class CommodityServiceImpl extends ServiceImpl impleme try { //创建小程序直播 Map roomMap = wechatLivePlayerUtil.create(studio); - studio.setRoomId(Integer.parseInt(roomMap.get("roomId"))); + studio.setRoomId(Convert.toInt(roomMap.get("roomId"))); studio.setQrCodeUrl(roomMap.get("qrcodeUrl")); studio.setStoreId(UserContext.getCurrentUser().getStoreId()); studio.setStatus(StudioStatusEnum.NEW.name()); diff --git a/framework/src/main/java/cn/lili/modules/connect/request/AuthAlipayRequest.java b/framework/src/main/java/cn/lili/modules/connect/request/AuthAlipayRequest.java index b51f3d2d..89bb41d3 100644 --- a/framework/src/main/java/cn/lili/modules/connect/request/AuthAlipayRequest.java +++ b/framework/src/main/java/cn/lili/modules/connect/request/AuthAlipayRequest.java @@ -1,5 +1,6 @@ package cn.lili.modules.connect.request; +import cn.hutool.core.convert.Convert; import cn.lili.common.cache.Cache; import cn.lili.common.utils.StringUtils; import cn.lili.common.utils.UrlBuilder; @@ -56,7 +57,7 @@ public class AuthAlipayRequest extends AuthDefaultRequest { return AuthToken.builder() .accessToken(response.getAccessToken()) .uid(response.getUserId()) - .expireIn(Integer.parseInt(response.getExpiresIn())) + .expireIn(Convert.toInt(response.getExpiresIn())) .refreshToken(response.getRefreshToken()) .build(); } @@ -86,7 +87,7 @@ public class AuthAlipayRequest extends AuthDefaultRequest { .data(AuthToken.builder() .accessToken(response.getAccessToken()) .uid(response.getUserId()) - .expireIn(Integer.parseInt(response.getExpiresIn())) + .expireIn(Convert.toInt(response.getExpiresIn())) .refreshToken(response.getRefreshToken()) .build()) .build(); diff --git a/framework/src/main/java/cn/lili/modules/connect/request/AuthQQRequest.java b/framework/src/main/java/cn/lili/modules/connect/request/AuthQQRequest.java index 164ec3a1..15299731 100644 --- a/framework/src/main/java/cn/lili/modules/connect/request/AuthQQRequest.java +++ b/framework/src/main/java/cn/lili/modules/connect/request/AuthQQRequest.java @@ -1,5 +1,6 @@ package cn.lili.modules.connect.request; +import cn.hutool.core.convert.Convert; import cn.lili.common.cache.Cache; import cn.lili.common.utils.StringUtils; import cn.lili.common.utils.UrlBuilder; @@ -118,7 +119,7 @@ public class AuthQQRequest extends AuthDefaultRequest { } return AuthToken.builder() .accessToken(accessTokenObject.get("access_token")) - .expireIn(Integer.parseInt(accessTokenObject.getOrDefault("expires_in", "0"))) + .expireIn(Convert.toInt(accessTokenObject.getOrDefault("expires_in", "0"))) .refreshToken(accessTokenObject.get("refresh_token")) .build(); } diff --git a/framework/src/main/java/cn/lili/modules/connect/util/ConnectUtil.java b/framework/src/main/java/cn/lili/modules/connect/util/ConnectUtil.java index acf388a3..4dd3c02d 100644 --- a/framework/src/main/java/cn/lili/modules/connect/util/ConnectUtil.java +++ b/framework/src/main/java/cn/lili/modules/connect/util/ConnectUtil.java @@ -137,7 +137,7 @@ public class ConnectUtil { public AuthRequest getAuthRequest(String type) { ConnectAuthEnum authInterface = ConnectAuthEnum.valueOf(type); if (authInterface == null) { - throw new ServiceException("错误的登录方式"); + throw new ServiceException(ResultCode.CONNECT_NOT_EXIST); } AuthRequest authRequest = null; switch (authInterface) { diff --git a/framework/src/main/java/cn/lili/modules/goods/entity/dos/Goods.java b/framework/src/main/java/cn/lili/modules/goods/entity/dos/Goods.java index e4f8eefa..8c7c43c0 100644 --- a/framework/src/main/java/cn/lili/modules/goods/entity/dos/Goods.java +++ b/framework/src/main/java/cn/lili/modules/goods/entity/dos/Goods.java @@ -1,5 +1,6 @@ package cn.lili.modules.goods.entity.dos; +import cn.hutool.core.convert.Convert; import cn.hutool.json.JSONUtil; import cn.lili.base.BaseEntity; import cn.lili.common.enums.ResultCode; @@ -234,19 +235,19 @@ public class Goods extends BaseEntity { if (sku.get("sn") == null) { throw new ServiceException(ResultCode.GOODS_SKU_SN_ERROR); } - if (StringUtil.isEmpty(sku.get("price").toString()) || Integer.parseInt( sku.get("price").toString()) <= 0) { + if (StringUtil.isEmpty(sku.get("price").toString()) || Convert.toDouble( sku.get("price").toString()) <= 0) { throw new ServiceException(ResultCode.GOODS_SKU_PRICE_ERROR); } - if (StringUtil.isEmpty(sku.get("cost").toString()) || Integer.parseInt( sku.get("cost").toString()) <= 0) { + if (StringUtil.isEmpty(sku.get("cost").toString()) || Convert.toDouble( sku.get("cost").toString()) <= 0) { throw new ServiceException(ResultCode.GOODS_SKU_COST_ERROR); } //虚拟商品没有重量字段 if(sku.containsKey("weight")) { - if (StringUtil.isEmpty(sku.get("weight").toString()) || Integer.parseInt(sku.get("weight").toString()) < 0) { + if (StringUtil.isEmpty(sku.get("weight").toString()) || Convert.toDouble(sku.get("weight").toString()) < 0) { throw new ServiceException(ResultCode.GOODS_SKU_WEIGHT_ERROR); } } - if (StringUtil.isEmpty(sku.get("quantity").toString()) || Integer.parseInt( sku.get("quantity").toString()) < 0) { + if (StringUtil.isEmpty(sku.get("quantity").toString()) || Convert.toInt( sku.get("quantity").toString()) < 0) { throw new ServiceException(ResultCode.GOODS_SKU_QUANTITY_ERROR); } diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java index b9167c90..10bf49bf 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java @@ -367,11 +367,11 @@ public class GoodsServiceImpl extends ServiceImpl implements if(parameters.getId().equals(goodsParamsItemDTO.getParamId())){ //校验是否可以索引参数是否正确 if(!parameters.getIsIndex().equals(goodsParamsItemDTO.getIsIndex())){ - throw new ServiceException("商品参数错误,刷新后重试"); + throw new ServiceException(ResultCode.GOODS_PARAMS_ERROR); } //校验是否必填参数是否正确 if(!parameters.getRequired().equals(goodsParamsItemDTO.getRequired())){ - throw new ServiceException("商品参数错误,刷新后重试"); + throw new ServiceException(ResultCode.GOODS_PARAMS_ERROR); } } } diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java index 78ee307f..3ecdba7d 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java @@ -173,8 +173,8 @@ public class GoodsSkuServiceImpl extends ServiceImpl i } String quantity = stringRedisTemplate.opsForValue().get(GoodsSkuService.getStockCacheKey(id)); if (quantity != null) { - if (goodsSku.getQuantity() != Integer.parseInt(quantity)) { - goodsSku.setQuantity(Integer.parseInt(quantity)); + if (goodsSku.getQuantity() != Convert.toInt(quantity)) { + goodsSku.setQuantity(Convert.toInt(quantity)); this.updateById(goodsSku); } } else { @@ -381,7 +381,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl i String cacheKeys = GoodsSkuService.getStockCacheKey(skuId); String stockStr = stringRedisTemplate.opsForValue().get(cacheKeys); if (stockStr != null) { - return Integer.parseInt(stockStr); + return Convert.toInt(stockStr); } else { GoodsSku goodsSku = getGoodsSkuByIdFromCache(skuId); stringRedisTemplate.opsForValue().set(cacheKeys, goodsSku.getQuantity().toString()); diff --git a/framework/src/main/java/cn/lili/modules/member/serviceimpl/MemberServiceImpl.java b/framework/src/main/java/cn/lili/modules/member/serviceimpl/MemberServiceImpl.java index 7b4d531c..fec2fba2 100644 --- a/framework/src/main/java/cn/lili/modules/member/serviceimpl/MemberServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/member/serviceimpl/MemberServiceImpl.java @@ -1,6 +1,7 @@ package cn.lili.modules.member.serviceimpl; +import cn.hutool.core.convert.Convert; import cn.lili.common.cache.Cache; import cn.lili.common.cache.CachePrefix; import cn.lili.common.enums.ResultCode; @@ -177,7 +178,7 @@ public class MemberServiceImpl extends ServiceImpl impleme try { String username = UuidUtils.getUUID(); Member member = new Member(username, UuidUtils.getUUID(), authUser.getAvatar(), authUser.getNickname(), - authUser.getGender() != null ? Integer.parseInt(authUser.getGender().getCode()) : 0); + authUser.getGender() != null ? Convert.toInt(authUser.getGender().getCode()) : 0); //保存会员 this.save(member); Member loadMember = this.findByUsername(username); diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PointsGoodsSearchParams.java b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PointsGoodsSearchParams.java index 1b37c5d3..af2b717c 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PointsGoodsSearchParams.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PointsGoodsSearchParams.java @@ -1,5 +1,6 @@ package cn.lili.modules.promotion.entity.vos; +import cn.hutool.core.convert.Convert; import cn.hutool.core.text.CharSequenceUtil; import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -85,9 +86,9 @@ public class PointsGoodsSearchParams { if (CharSequenceUtil.isNotEmpty(points)) { String[] s = points.split("_"); if (s.length > 1) { - query.addCriteria(Criteria.where("points").gte(Integer.parseInt(s[0])).lte(Integer.parseInt(s[1]))); + query.addCriteria(Criteria.where("points").gte(Convert.toInt(s[0])).lte(Convert.toInt(s[1]))); } else { - query.addCriteria(Criteria.where("points").gte(Integer.parseInt(s[0]))); + query.addCriteria(Criteria.where("points").gte(Convert.toInt(s[0]))); } } if (recommend != null) { diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityServiceImpl.java index 3f14f82c..a8aa97c0 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityServiceImpl.java @@ -35,6 +35,8 @@ import org.springframework.stereotype.Service; import java.util.*; +import static cn.lili.common.enums.ResultCode.COUPON_ACTIVITY_ITEM_ERROR; + /** * 优惠券活动业务层实现 * @@ -216,18 +218,18 @@ public class CouponActivityServiceImpl extends ServiceImpl 10) { - throw new ServiceException("优惠券活动最多指定10个优惠券"); + throw new ServiceException(ResultCode.COUPON_ACTIVITY_ITEM_MUST_NUM_ERROR); } else { for (CouponActivityItem item : couponActivity.getCouponActivityItems()) { if (item.getNum() == null || item.getNum() <= 0) { - throw new ServiceException("赠券数量必须大于0"); + throw new ServiceException(ResultCode.COUPON_ACTIVITY_ITEM_NUM_ERROR); } } } diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java index c15773bd..2590e8e2 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java @@ -1,5 +1,6 @@ package cn.lili.modules.promotion.serviceimpl; +import cn.hutool.core.convert.Convert; import cn.hutool.core.text.CharSequenceUtil; import cn.lili.common.exception.ServiceException; import cn.lili.common.utils.BeanUtil; @@ -271,8 +272,8 @@ public class PromotionGoodsServiceImpl extends ServiceImpl entry : cacheSeckill.entrySet()) { - Integer timelineKey = Integer.parseInt(entry.getKey().toString()); + Integer timelineKey = Convert.toInt(entry.getKey().toString()); if (timelineKey.equals(timeline)) { seckillGoodsVoS = (List) entry.getValue(); } @@ -146,7 +147,7 @@ public class SeckillApplyServiceImpl extends ServiceImpl seckillApplyList) { SeckillVO seckill = mongoTemplate.findById(seckillId, SeckillVO.class); if (seckill == null) { - throw new ServiceException(ResultCode.SECKILL_NOT_EXIST); + throw new ServiceException(ResultCode.SECKILL_NOT_EXIST_ERROR); } //检查秒杀活动申请是否合法 checkSeckillApplyList(seckill.getHours(), seckillApplyList, storeId); @@ -200,10 +201,10 @@ public class SeckillApplyServiceImpl extends ServiceImpl ids) { SeckillVO seckillVO = this.mongoTemplate.findById(seckillId, SeckillVO.class); if (seckillVO == null) { - throw new ServiceException("当前秒杀活动活动不存在!"); + throw new ServiceException(ResultCode.SECKILL_NOT_EXIST_ERROR); } if (seckillVO.getPromotionStatus().equals(PromotionStatusEnum.START.name())) { - throw new ServiceException("当前秒杀活动活动已经开始,无法修改!"); + throw new ServiceException(ResultCode.SECKILL_UPDATE_ERROR); } seckillVO.getSeckillApplyList().removeIf(seckillApply -> ids.contains(seckillApply.getId())); this.mongoTemplate.save(seckillVO); @@ -222,13 +223,13 @@ public class SeckillApplyServiceImpl extends ServiceImpl seckillApply.getOriginalPrice()) { - throw new ServiceException("活动价格不能大于商品原价"); + throw new ServiceException(ResultCode.SECKILL_PRICE_ERROR); } //检查秒杀活动申请的时刻,是否存在在秒杀活动的时间段内 String[] rangeHours = hours.split(","); boolean containsSame = Arrays.stream(rangeHours).anyMatch(i -> i.equals(seckillApply.getTimeLine().toString())); if (!containsSame) { - throw new ServiceException("时刻参数异常"); + throw new ServiceException(ResultCode.SECKILL_TIME_ERROR); } //检查商品是否参加多个时间段的活动 if (existSku.contains(seckillApply.getSkuId())) { diff --git a/framework/src/main/java/cn/lili/modules/search/serviceimpl/CustomWordsServiceImpl.java b/framework/src/main/java/cn/lili/modules/search/serviceimpl/CustomWordsServiceImpl.java index 4eb7ea7a..4797774e 100644 --- a/framework/src/main/java/cn/lili/modules/search/serviceimpl/CustomWordsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/search/serviceimpl/CustomWordsServiceImpl.java @@ -1,5 +1,6 @@ package cn.lili.modules.search.serviceimpl; +import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; import cn.lili.common.utils.PageUtil; import cn.lili.common.vo.PageVO; @@ -63,7 +64,7 @@ public class CustomWordsServiceImpl extends ServiceImpl map = orderStatisticsDataService.getStoreOrderStatisticsPrice(); - storeIndexStatisticsVO.setOrderNum(Integer.parseInt(map.get("num").toString())); + storeIndexStatisticsVO.setOrderNum(Convert.toInt(map.get("num").toString())); storeIndexStatisticsVO.setOrderPrice(map.get("price") != null ? Double.parseDouble(map.get("price").toString()) : 0.0); //访问量