1.使用hutool进行Object to Int格式转换

2.添加部分resultCode
This commit is contained in:
lifenlong 2021-07-01 08:33:19 +08:00
parent 346465630c
commit f6706d6394
24 changed files with 127 additions and 85 deletions

View File

@ -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);
//批量修改商品库存

View File

@ -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<String, Object> 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());
}
}

View File

@ -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);

View File

@ -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中执行都值判定为空则这里跳过

View File

@ -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;

View File

@ -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("整型数字格式不正确");

View File

@ -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<String, Object> createVerification(VerificationEnums verificationEnums, String uuid) throws IOException {
if (uuid == null) {
throw new ServiceException("非法请求,请重新刷新页面操作");
throw new ServiceException(ResultCode.ILLEGAL_REQUEST_ERROR);
}
//获取验证码配置

View File

@ -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;
}

View File

@ -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<String> collect = new ArrayList<>();
Range<Integer> 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

View File

@ -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<CommodityMapper, Commodity
//添加直播商品
JSONObject json = wechatLivePlayerUtil.addGoods(commodity);
if(!json.getStr("errcode").equals("0")){
throw new ServiceException(json.getStr("errmsg"));
log.error(json.getStr("errmsg"));
throw new ServiceException(ResultCode.COMMODITY_ERROR);
}
commodity.setLiveGoodsId(Convert.toInt(json.getStr("goodsId")));
commodity.setAuditId(json.getStr("auditId"));

View File

@ -1,5 +1,6 @@
package cn.lili.modules.broadcast.serviceimpl;
import cn.hutool.core.convert.Convert;
import cn.hutool.json.JSONUtil;
import cn.lili.common.delayqueue.BroadcastMessage;
import cn.lili.common.enums.ResultCode;
@ -63,7 +64,7 @@ public class StudioServiceImpl extends ServiceImpl<StudioMapper, Studio> impleme
try {
//创建小程序直播
Map<String, String> 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());

View File

@ -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();

View File

@ -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();
}

View File

@ -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) {

View File

@ -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);
}

View File

@ -367,11 +367,11 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> 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);
}
}
}

View File

@ -173,8 +173,8 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> 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<GoodsSkuMapper, GoodsSku> 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());

View File

@ -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<MemberMapper, Member> 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);

View File

@ -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) {

View File

@ -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<CouponActivityMapper,
//指定会员判定
if (couponActivity.getActivityScope().equals(CouponActivitySendTypeEnum.DESIGNATED.name())) {
if (couponActivity.getMemberDTOS().size() == 0) {
throw new ServiceException("指定精准发券则必须指定会员,会员不可以为空");
throw new ServiceException(ResultCode.COUPON_ACTIVITY_MEMBER_ERROR);
}
}
//优惠券数量判定
if (couponActivity.getCouponActivityItems().size() == 0) {
throw new ServiceException("优惠券活动必须指定优惠券,不能为空");
throw new ServiceException(ResultCode.COUPON_ACTIVITY_ITEM_ERROR);
} else if (couponActivity.getCouponActivityItems().size() > 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);
}
}
}

View File

@ -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<PromotionGoodsMapper,
if (promotionGoods == null) {
throw new ServiceException("当前促销商品不存在!");
}
if (promotionGoodsStock != null && CharSequenceUtil.isNotEmpty(promotionGoodsStock) && promotionGoods.getQuantity() == Integer.parseInt(promotionGoodsStock)) {
return Integer.parseInt(promotionGoodsStock);
if (promotionGoodsStock != null && CharSequenceUtil.isNotEmpty(promotionGoodsStock) && promotionGoods.getQuantity() == Convert.toInt(promotionGoodsStock)) {
return Convert.toInt(promotionGoodsStock);
} else {
stringRedisTemplate.opsForValue().set(promotionStockKey, promotionGoods.getQuantity().toString());
return promotionGoods.getQuantity();

View File

@ -2,6 +2,7 @@ package cn.lili.modules.promotion.serviceimpl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.text.CharSequenceUtil;
@ -103,7 +104,7 @@ public class SeckillApplyServiceImpl extends ServiceImpl<SeckillApplyMapper, Sec
} else {
//如缓存中存在则取缓存中转为展示的信息
for (Map.Entry<Object, Object> entry : cacheSeckill.entrySet()) {
Integer timelineKey = Integer.parseInt(entry.getKey().toString());
Integer timelineKey = Convert.toInt(entry.getKey().toString());
if (timelineKey.equals(timeline)) {
seckillGoodsVoS = (List<SeckillGoodsVO>) entry.getValue();
}
@ -146,7 +147,7 @@ public class SeckillApplyServiceImpl extends ServiceImpl<SeckillApplyMapper, Sec
public void addSeckillApply(String seckillId, String storeId, List<SeckillApplyVO> 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<SeckillApplyMapper, Sec
public void removeSeckillApplyByIds(String seckillId, List<String> 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<SeckillApplyMapper, Sec
for (SeckillApplyVO seckillApply : seckillApplyList) {
seckillApply.setStoreId(storeId);
if (seckillApply.getPrice() > 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())) {

View File

@ -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<CustomWordsMapper, Custo
@Override
public boolean addCustomWords(CustomWordsVO customWordsVO) {
if (this.existWords(customWordsVO.getName())) {
throw new ServiceException("当前自定义分词已存在!");
throw new ServiceException(ResultCode.CUSTOM_WORDS_EXIST_ERROR);
}
return this.save(customWordsVO);
}
@ -77,7 +78,7 @@ public class CustomWordsServiceImpl extends ServiceImpl<CustomWordsMapper, Custo
@Override
public boolean deleteCustomWords(String id) {
if (this.getById(id) == null) {
throw new ServiceException("当前自定义分词不存在!");
throw new ServiceException(ResultCode.CUSTOM_WORDS_NOT_EXIST_ERROR);
}
return this.removeById(id);
}
@ -91,7 +92,7 @@ public class CustomWordsServiceImpl extends ServiceImpl<CustomWordsMapper, Custo
@Override
public boolean updateCustomWords(CustomWordsVO customWordsVO) {
if (this.getById(customWordsVO.getId()) == null) {
throw new ServiceException("当前自定义分词不存在!");
throw new ServiceException(ResultCode.CUSTOM_WORDS_NOT_EXIST_ERROR);
}
return this.updateById(customWordsVO);
}

View File

@ -1,5 +1,6 @@
package cn.lili.modules.statistics.serviceimpl;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateTime;
import cn.lili.common.security.context.UserContext;
import cn.lili.common.security.enums.UserEnums;
@ -195,7 +196,7 @@ public class IndexStatisticsServiceImpl implements IndexStatisticsService {
storeIndexStatisticsVO.setGoodsNum(goodsService.goodsNum(GoodsStatusEnum.UPPER, null));
//订单总数量订单总金额
Map<String, Object> 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);
//访问量