Merge branch 'master' into Bulbasaur

This commit is contained in:
lifenlong
2021-05-18 17:35:48 +08:00
87 changed files with 616 additions and 297 deletions

View File

@@ -3,12 +3,15 @@ package cn.lili.common.elasticsearch;
import cn.hutool.core.bean.BeanUtil;
import cn.lili.config.elasticsearch.ElasticsearchProperties;
import lombok.extern.slf4j.Slf4j;
import org.assertj.core.api.Assertions;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.client.HttpAsyncResponseConsumerFactory;
import org.elasticsearch.client.RequestOptions;
@@ -16,6 +19,7 @@ import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.client.indices.PutMappingRequest;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.QueryBuilders;
@@ -24,6 +28,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
/**
* @author paulG
@@ -84,15 +91,251 @@ public abstract class BaseElasticsearchService {
// Settings for this index
request.settings(Settings.builder().put("index.number_of_shards", elasticsearchProperties.getIndex().getNumberOfShards()).put("index.number_of_replicas", elasticsearchProperties.getIndex().getNumberOfReplicas()));
//创建索引
CreateIndexResponse createIndexResponse = client.indices().create(request, COMMON_OPTIONS);
createMapping(index);
log.info(" whether all of the nodes have acknowledged the request : {}", createIndexResponse.isAcknowledged());
log.info(" Indicates whether the requisite number of shard copies were started for each shard in the index before timing out :{}", createIndexResponse.isShardsAcknowledged());
return;
} catch (Exception e) {
e.printStackTrace();
throw new ElasticsearchException("创建索引 {" + index + "} 失败:" + e.getMessage());
}
}
public void createMapping(String index) throws Exception {
String source =
" {\n" +
" \"properties\": {\n" +
" \"_class\": {\n" +
" \"type\": \"text\",\n" +
" \"fields\": {\n" +
" \"keyword\": {\n" +
" \"type\": \"keyword\",\n" +
" \"ignore_above\": 256\n" +
" }\n" +
" }\n" +
" },\n" +
" \"attrList\": {\n" +
" \"type\": \"nested\",\n" +
" \"properties\": {\n" +
" \"name\": {\n" +
" \"type\": \"keyword\"\n" +
" },\n" +
" \"type\": {\n" +
" \"type\": \"long\"\n" +
" },\n" +
" \"value\": {\n" +
" \"type\": \"keyword\"\n" +
" }\n" +
" }\n" +
" },\n" +
" \"brandId\": {\n" +
" \"type\": \"text\",\n" +
" \"fielddata\": true,\n" +
" \"fields\": {\n" +
" \"keyword\": {\n" +
" \"type\": \"keyword\",\n" +
" \"ignore_above\": 256\n" +
" }\n" +
" }\n" +
" },\n" +
" \"buyCount\": {\n" +
" \"type\": \"long\"\n" +
" },\n" +
" \"releaseTime\": {\n" +
" \"type\": \"text\",\n" +
" \"fielddata\": true, \n" +
" \"fields\": {\n" +
" \"keyword\": {\n" +
" \"type\": \"keyword\",\n" +
" \"ignore_above\": 256\n" +
" }\n" +
" }\n" +
" },\n" +
" \"categoryPath\": {\n" +
" \"type\": \"text\",\n" +
" \"fielddata\": true,\n" +
" \"fields\": {\n" +
" \"keyword\": {\n" +
" \"type\": \"keyword\",\n" +
" \"ignore_above\": 256\n" +
" }\n" +
" }\n" +
" },\n" +
" \"commentNum\": {\n" +
" \"type\": \"long\"\n" +
" },\n" +
" \"goodsId\": {\n" +
" \"type\": \"text\",\n" +
" \"fields\": {\n" +
" \"keyword\": {\n" +
" \"type\": \"keyword\",\n" +
" \"ignore_above\": 256\n" +
" }\n" +
" }\n" +
" },\n" +
" \"goodsName\": {\n" +
" \"type\": \"text\",\n" +
" \"fielddata\": true, \n" +
" \"analyzer\": \"ik_max_word\",\n" +
" \"fields\": {\n" +
" \"keyword\": {\n" +
" \"type\": \"keyword\",\n" +
" \"ignore_above\": 256\n" +
" }\n" +
" }\n" +
" },\n" +
" \"grade\": {\n" +
" \"type\": \"float\"\n" +
" },\n" +
" \"highPraiseNum\": {\n" +
" \"type\": \"long\"\n" +
" },\n" +
" \"id\": {\n" +
" \"type\": \"text\",\n" +
" \"fields\": {\n" +
" \"keyword\": {\n" +
" \"type\": \"keyword\",\n" +
" \"ignore_above\": 256\n" +
" }\n" +
" }\n" +
" },\n" +
" \"intro\": {\n" +
" \"type\": \"text\",\n" +
" \"fields\": {\n" +
" \"keyword\": {\n" +
" \"type\": \"keyword\",\n" +
" \"ignore_above\": 256\n" +
" }\n" +
" }\n" +
" },\n" +
" \"isAuth\": {\n" +
" \"type\": \"text\",\n" +
" \"fields\": {\n" +
" \"keyword\": {\n" +
" \"type\": \"keyword\",\n" +
" \"ignore_above\": 256\n" +
" }\n" +
" }\n" +
" },\n" +
" \"marketEnable\": {\n" +
" \"type\": \"text\",\n" +
" \"fielddata\": true, \n" +
" \"fields\": {\n" +
" \"keyword\": {\n" +
" \"type\": \"keyword\",\n" +
" \"ignore_above\": 256\n" +
" }\n" +
" }\n" +
" },\n" +
" \"mobileIntro\": {\n" +
" \"type\": \"text\",\n" +
" \"fields\": {\n" +
" \"keyword\": {\n" +
" \"type\": \"keyword\",\n" +
" \"ignore_above\": 256\n" +
" }\n" +
" }\n" +
" },\n" +
" \"point\": {\n" +
" \"type\": \"long\"\n" +
" },\n" +
" \"price\": {\n" +
" \"type\": \"float\"\n" +
" },\n" +
" \"salesModel\": {\n" +
" \"type\": \"text\",\n" +
" \"fields\": {\n" +
" \"keyword\": {\n" +
" \"type\": \"keyword\",\n" +
" \"ignore_above\": 256\n" +
" }\n" +
" }\n" +
" },\n" +
" \"selfOperated\": {\n" +
" \"type\": \"boolean\"\n" +
" },\n" +
" \"sellerId\": {\n" +
" \"type\": \"text\",\n" +
" \"fields\": {\n" +
" \"keyword\": {\n" +
" \"type\": \"keyword\",\n" +
" \"ignore_above\": 256\n" +
" }\n" +
" }\n" +
" },\n" +
" \"sellerName\": {\n" +
" \"type\": \"text\",\n" +
" \"fielddata\": true, \n" +
" \"fields\": {\n" +
" \"keyword\": {\n" +
" \"type\": \"keyword\",\n" +
" \"ignore_above\": 256\n" +
" }\n" +
" }\n" +
" },\n" +
" \"shopCategoryPath\": {\n" +
" \"type\": \"text\",\n" +
" \"fielddata\": true, \n" +
" \"fields\": {\n" +
" \"keyword\": {\n" +
" \"type\": \"keyword\",\n" +
" \"ignore_above\": 256\n" +
" }\n" +
" }\n" +
" },\n" +
" \"sn\": {\n" +
" \"type\": \"text\",\n" +
" \"fields\": {\n" +
" \"keyword\": {\n" +
" \"type\": \"keyword\",\n" +
" \"ignore_above\": 256\n" +
" }\n" +
" }\n" +
" },\n" +
" \"thumbnail\": {\n" +
" \"type\": \"text\",\n" +
" \"fields\": {\n" +
" \"keyword\": {\n" +
" \"type\": \"keyword\",\n" +
" \"ignore_above\": 256\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n";
PutMappingRequest request = new PutMappingRequest(index)
.source(source, XContentType.JSON);
// AcknowledgedResponse putMappingResponse = client.indices().putMapping(request,
// RequestOptions.DEFAULT);
//
// boolean acknowledged = putMappingResponse.isAcknowledged();
// if (acknowledged) {
// log.error("Succeed to put mapping");
// }
CountDownLatch latch = new CountDownLatch(1);
AtomicReference response = new AtomicReference<AcknowledgedResponse>();
client.indices().putMappingAsync(
request,
RequestOptions.DEFAULT,
new ActionListener<AcknowledgedResponse>() {
@Override
public void onResponse(AcknowledgedResponse r) {
response.set(r);
latch.countDown();
}
@Override
public void onFailure(Exception e) {
latch.countDown();
}
});
latch.await(10, TimeUnit.SECONDS);
Assertions.assertThat(((AcknowledgedResponse) response.get()).isAcknowledged()).isTrue();
}
/**
* Description: 判断某个index是否存在
*

View File

@@ -260,6 +260,7 @@ public enum ResultCode {
* OSS
*/
OSS_NOT_EXIST(80201,"OSS未配置"),
OSS_EXCEPTION(80202,"文件上传失败,请稍后重试"),
/**
* 验证码
@@ -267,7 +268,17 @@ public enum ResultCode {
VERIFICATION_SEND_SUCCESS(80301,"短信验证码,发送成功"),
VERIFICATION_ERROR(80302,"验证失败"),
VERIFICATION_SMS_ERROR(80303,"短信验证码错误,请重新校验"),
VERIFICATION_SMS_EXPIRED_ERROR(80304,"验证码已失效,请重新校验")
VERIFICATION_SMS_EXPIRED_ERROR(80304,"验证码已失效,请重新校验"),
/**
* 配置错误
*/
ALIPAY_NOT_SETTING(80401,"支付宝支付未配置"),
ALIPAY_EXCEPTION(80402,"支付宝支付错误,请稍后重试"),
ALIPAY_PARAMS_EXCEPTION(80403,"支付宝参数异常"),
WECHAT_PAY_NOT_SETTING(80402,"微信支付未配置"),
;
private final Integer code;

View File

@@ -1,7 +1,6 @@
package cn.lili.common.exception;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.utils.ResultUtil;
import cn.lili.common.vo.ResultMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
@@ -23,7 +22,7 @@ import java.util.List;
*/
@RestControllerAdvice
@Slf4j
public class GlobalControllerExceptionHandler {
public class GlobalControllerExceptionHandler {
/**
* 如果超过长度,则前后段交互体验不佳,使用默认错误消息
@@ -44,9 +43,9 @@ public class GlobalControllerExceptionHandler {
//如果是自定义异常,则获取异常,返回自定义错误消息
if (e instanceof ServiceException) {
ResultCode resultCode=((ServiceException) e).getResultCode();
ResultCode resultCode = ((ServiceException) e).getResultCode();
if (resultCode != null) {
return ResultUtil.error(resultCode.code(), resultCode.message());
throw new ServiceException(resultCode);
}
}
@@ -55,7 +54,7 @@ public class GlobalControllerExceptionHandler {
if (e != null && e.getMessage() != null && e.getMessage().length() < MAX_LENGTH) {
errorMsg = e.getMessage();
}
return ResultUtil.error(400, errorMsg);
throw new ServiceException(ResultCode.ERROR, errorMsg);
}
@ExceptionHandler(RuntimeException.class)
@@ -64,7 +63,7 @@ public class GlobalControllerExceptionHandler {
log.error("全局异常[RuntimeException]:", e);
return ResultUtil.error(400, "服务器异常,请稍后重试");
throw new ServiceException(ResultCode.ERROR, "服务器异常,请稍后重试");
}
// /**
@@ -101,9 +100,9 @@ public class GlobalControllerExceptionHandler {
BindException exception = (BindException) e;
List<FieldError> fieldErrors = exception.getBindingResult().getFieldErrors();
for (FieldError error : fieldErrors) {
return ResultUtil.error(400,error.getDefaultMessage());
throw new ServiceException(ResultCode.ERROR, error.getDefaultMessage());
}
return ResultUtil.error(ResultCode.ERROR);
throw new ServiceException(ResultCode.ERROR);
}
}

View File

@@ -27,4 +27,9 @@ public class ServiceException extends RuntimeException {
this.resultCode = resultCode;
}
public ServiceException(ResultCode resultCode, String message) {
this.resultCode = resultCode;
this.msg = message;
}
}

View File

@@ -66,7 +66,7 @@ public class SmsUtilAliImplService implements SmsUtil, AliSmsUtil {
Map<String, String> params = new HashMap<>();
params.put("code", code);
cache.put(cacheKey(verificationEnums, mobile, uuid), code, 300L);
this.sendSmsCode("北京宏业汇成科技有限公司",mobile, params, "SMS_205755300");
this.sendSmsCode("北京宏业汇成科技有限公司", mobile, params, "SMS_205755300");
break;
}
case UPDATE_PASSWORD: {
@@ -79,7 +79,7 @@ public class SmsUtilAliImplService implements SmsUtil, AliSmsUtil {
Map<String, String> params = new HashMap<>();
params.put("code", code);
cache.put(cacheKey(verificationEnums, memberMobile, uuid), code, 300L);
this.sendSmsCode("北京宏业汇成科技有限公司",mobile, params, "SMS_205755297");
this.sendSmsCode("北京宏业汇成科技有限公司", mobile, params, "SMS_205755297");
break;
}
//如果不是有效的验证码手段,则此处不进行短信操作
@@ -112,7 +112,6 @@ public class SmsUtilAliImplService implements SmsUtil, AliSmsUtil {
.setTemplateParam(JSONUtil.toJsonStr(param));
try {
SendSmsResponse response = client.sendSms(sendSmsRequest);
System.out.println(response.getBody().getCode());
} catch (Exception e) {
e.printStackTrace();
}
@@ -123,8 +122,9 @@ public class SmsUtilAliImplService implements SmsUtil, AliSmsUtil {
com.aliyun.dysmsapi20170525.Client client = this.createClient();
List<String> sign = mobile;
List<String> sign = new ArrayList<String>();
sign.addAll(mobile);
sign.replaceAll(e -> signName);
//手机号拆成多个小组进行发送
@@ -140,7 +140,7 @@ public class SmsUtilAliImplService implements SmsUtil, AliSmsUtil {
signNameList.add(sign.subList((i * 100), endPoint));
}
//发送短信
// //发送短信
for (int i = 0; i < mobileList.size(); i++) {
SendBatchSmsRequest sendBatchSmsRequest = new SendBatchSmsRequest()
.setPhoneNumberJson(JSONUtil.toJsonStr(mobileList.get(i)))
@@ -160,23 +160,24 @@ public class SmsUtilAliImplService implements SmsUtil, AliSmsUtil {
public void addSmsSign(SmsSign smsSign) throws Exception {
//设置参数添加短信签名
com.aliyun.dysmsapi20170525.Client client = this.createClient();
System.out.println(smsSign.getBusinessLicense().substring(smsSign.getBusinessLicense().lastIndexOf(".") + 1));
System.out.println(smsSign.getLicense().substring(smsSign.getLicense().lastIndexOf(".")));
//营业执照
AddSmsSignRequest.AddSmsSignRequestSignFileList signFileList0 = new AddSmsSignRequest.AddSmsSignRequestSignFileList()
.setFileContents(Base64Utils.encode(smsSign.getBusinessLicense()))
.setFileSuffix(smsSign.getBusinessLicense().substring(smsSign.getBusinessLicense().lastIndexOf(".") + 1));
//授权委托书
// AddSmsSignRequest.AddSmsSignRequestSignFileList signFileList1 = new AddSmsSignRequest.AddSmsSignRequestSignFileList()
// .setFileContents(Base64Utils.encode(smsSign.getLicense()))
// .setFileSuffix(smsSign.getLicense().substring(smsSign.getLicense().lastIndexOf(".") + 1));
AddSmsSignRequest.AddSmsSignRequestSignFileList signFileList1 = new AddSmsSignRequest.AddSmsSignRequestSignFileList()
.setFileContents(Base64Utils.encode(smsSign.getLicense()))
.setFileSuffix(smsSign.getLicense().substring(smsSign.getLicense().lastIndexOf(".")) + 1);
//添加短信签名
AddSmsSignRequest addSmsSignRequest = new AddSmsSignRequest()
.setSignName(smsSign.getSignName())
.setSignSource(smsSign.getSignSource())
.setRemark(smsSign.getRemark())
.setSignFileList(java.util.Arrays.asList(
signFileList0
signFileList0,
signFileList1
));
AddSmsSignResponse response = client.addSmsSign(addSmsSignRequest);
if (!response.getBody().getCode().equals("OK")) {

View File

@@ -17,10 +17,6 @@ public class ResultUtil<T> {
* 正常响应
*/
private static final Integer SUCCESS = 200;
/**
* 业务异常
*/
private static final Integer ERROR = 400;
/**
@@ -44,30 +40,6 @@ public class ResultUtil<T> {
return this.resultMessage;
}
/**
* 服务器异常 追加状态码
*
* @param resultCode 返回码
*/
public ResultMessage<T> setErrorMsg(ResultCode resultCode) {
this.resultMessage.setSuccess(false);
this.resultMessage.setMessage(resultCode.message());
this.resultMessage.setCode(resultCode.code());
return this.resultMessage;
}
/**
* 服务器异常 追加状态码
* @param code 状态码
* @param msg 返回消息
*/
public ResultMessage<T> setErrorMsg(Integer code, String msg) {
this.resultMessage.setSuccess(false);
this.resultMessage.setMessage(msg);
this.resultMessage.setCode(code);
return this.resultMessage;
}
/**
* 返回成功消息
@@ -95,20 +67,4 @@ public class ResultUtil<T> {
public static <T> ResultMessage<T> success(ResultCode resultCode) {
return new ResultUtil<T>().setSuccessMsg(resultCode);
}
/**
* 返回失败
* @param resultCode 返回状态码
*/
public static <T> ResultMessage<T> error(ResultCode resultCode) {
return new ResultUtil<T>().setErrorMsg(resultCode);
}
/**
* 返回失败
* @param code 状态码
* @param msg 返回消息
*/
public static <T> ResultMessage<T> error(Integer code, String msg) {
return new ResultUtil<T>().setErrorMsg(code, msg);
}
}

View File

@@ -60,7 +60,7 @@ public class VueCodeGenerator {
try {
result = generateClassData(path);
} catch (Exception e) {
return ResultUtil.error(ResultCode.ERROR);
throw new ServiceException(ResultCode.ERROR);
}
return ResultUtil.data(result);
}

View File

@@ -3,6 +3,7 @@ package cn.lili.modules.connect.util;
import cn.hutool.json.JSONUtil;
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.token.Token;
import cn.lili.common.utils.ResultUtil;
@@ -27,7 +28,6 @@ import cn.lili.modules.system.entity.dto.connect.dto.QQConnectSettingItem;
import cn.lili.modules.system.entity.dto.connect.dto.WechatConnectSettingItem;
import cn.lili.modules.system.entity.enums.SettingEnum;
import cn.lili.modules.system.service.SettingService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -83,12 +83,12 @@ public class ConnectUtil {
token = connectService.unionLoginCallback(type, authUser, callback.getState());
resultMessage = ResultUtil.data(token);
} catch (ServiceException e) {
resultMessage = ResultUtil.error(400,e.getMessage());
throw new ServiceException(ResultCode.ERROR, e.getMessage());
}
}
//否则录入响应结果,等待前端获取信息
else {
resultMessage = ResultUtil.error(400,response.getMsg());
throw new ServiceException(ResultCode.ERROR, response.getMsg());
}
//缓存写入登录结果300秒有效
cache.put(CachePrefix.CONNECT_RESULT.getPrefix() + callback.getCode(), resultMessage, 300L);

View File

@@ -601,7 +601,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
sku.setThumbnail(thumbnail);
//规格信息
sku.setId(map.getOrDefault("id", "").toString());
sku.setId(Convert.toStr(map.get("id"),"").toString());
sku.setSn(Convert.toStr(map.get("sn")));
sku.setWeight(Convert.toDouble(map.get("weight"), 0D));
sku.setPrice(Convert.toDouble(map.get("price"), 0D));

View File

@@ -115,7 +115,7 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> impleme
@Override
public Token usernameLogin(String username, String password) {
Member member = this.findByUsername(username);
Member member = this.findMember(username);
//判断用户是否存在
if (member == null || !member.getDisabled()) {
throw new ServiceException(ResultCode.USER_NOT_EXIST);
@@ -131,7 +131,7 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> impleme
@Override
public Token usernameStoreLogin(String username, String password) {
Member member = this.findByUsername(username);
Member member = this.findMember(username);
//判断用户是否存在
if (member == null || !member.getDisabled()) {
throw new ServiceException(ResultCode.USER_NOT_EXIST);
@@ -153,6 +153,18 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> impleme
return storeTokenGenerate.createToken(member.getUsername(), false);
}
/**
* 传递手机号或者用户名
*
* @param userName
* @return
*/
private Member findMember(String userName) {
QueryWrapper<Member> queryWrapper = new QueryWrapper();
queryWrapper.eq("username", userName).or().eq("mobile", userName);
return memberMapper.selectOne(queryWrapper);
}
@Override
public Token autoRegister(ConnectAuthUser authUser) {
@@ -344,7 +356,7 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> impleme
queryWrapper.like(StringUtils.isNotBlank(memberSearchVO.getMobile()), "mobile", memberSearchVO.getMobile());
//按照会员状态查询
queryWrapper.eq(StringUtils.isNotBlank(memberSearchVO.getDisabled()), "disabled",
memberSearchVO.getDisabled().equals(SwitchEnum.OPEN.name())?1:0);
memberSearchVO.getDisabled().equals(SwitchEnum.OPEN.name()) ? 1 : 0);
queryWrapper.orderByDesc("create_time");
return this.page(PageUtil.initPage(page), queryWrapper);
}

View File

@@ -10,7 +10,6 @@ import cn.lili.modules.message.entity.dto.SmsReachDTO;
import cn.lili.modules.message.mapper.SmsReachMapper;
import cn.lili.modules.message.service.SmsReachService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -40,7 +39,7 @@ public class SmsReachServiceImpl extends ServiceImpl<SmsReachMapper, SmsReach> i
BeanUtil.copyProperties(smsReach,smsReachDTO);
smsReachDTO.setMobile(mobile);
this.save(smsReach);
//发送订单变更mq消息
//发送短信批量发送mq消息
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(smsReachDTO), RocketmqSendCallbackBuilder.commonCallback());
}

View File

@@ -1,6 +1,5 @@
package cn.lili.modules.message.serviceimpl;
import cn.lili.common.enums.MessageCode;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.exception.ServiceException;
import cn.lili.common.sms.AliSmsUtil;
@@ -13,7 +12,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -71,7 +69,6 @@ public class SmsSignServiceImpl extends ServiceImpl<SmsSignMapper, SmsSign> impl
//查询签名状态
for (SmsSign smsSign : list) {
map = aliSmsUtil.querySmsSign(smsSign.getSignName());
smsSign.setSignStatus((Integer) map.get("SignStatus"));
smsSign.setReason(map.get("Reason").toString());
this.updateById(smsSign);

View File

@@ -10,7 +10,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -65,7 +64,7 @@ public class SmsTemplateServiceImpl extends ServiceImpl<SmsTemplateMapper, SmsTe
List<SmsTemplate> list = list(new LambdaQueryWrapper<SmsTemplate>().eq(SmsTemplate::getTemplateStatus, 0));
//查询签名状态
for (SmsTemplate smsTemplate : list) {
map = aliSmsUtil.querySmsTemplate(smsTemplate.getTemplateName());
map = aliSmsUtil.querySmsTemplate(smsTemplate.getTemplateCode());
smsTemplate.setTemplateStatus((Integer) map.get("TemplateStatus"));
smsTemplate.setReason(map.get("Reason").toString());
smsTemplate.setTemplateCode(map.get("TemplateCode").toString());

View File

@@ -24,6 +24,10 @@ public enum ArticleEnum {
* 证照信息
*/
LICENSE_INFORMATION,
/**
* 店铺入驻
*/
STORE_REGISTER,
/**
* 其他文章
*/

View File

@@ -69,4 +69,12 @@ public interface ArticleService extends IService<Article> {
*/
@Cacheable(key = "#type")
Article customGetByType(String type);
/**
* 修改文章状态
* @param id 文章ID
* @param status 显示状态
*/
@CacheEvict(key = "#id")
Boolean updateArticleStatus(String id,boolean status);
}

View File

@@ -3,6 +3,7 @@ package cn.lili.modules.page.serviceimpl;
import cn.hutool.core.util.StrUtil;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.enums.SwitchEnum;
import cn.lili.common.exception.ServiceException;
import cn.lili.common.utils.BeanUtil;
import cn.lili.common.utils.PageUtil;
@@ -78,4 +79,11 @@ public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> impl
}
return null;
}
@Override
public Boolean updateArticleStatus(String id, boolean status) {
Article article=this.getById(id);
article.setOpenStatus(status? SwitchEnum.OPEN.name():SwitchEnum.CLOSE.name());
return this.updateById(article);
}
}

View File

@@ -71,7 +71,7 @@ public class AliPayPlugin implements Payment {
CashierParam cashierParam = cashierSupport.cashierParam(payParam);
//请求订单编号
String outTradeNo = SnowFlake.getIdStr();
//准备支付参数
AlipayTradeWapPayModel payModel = new AlipayTradeWapPayModel();
payModel.setBody(cashierParam.getTitle());
payModel.setSubject(cashierParam.getDetail());
@@ -86,7 +86,8 @@ public class AliPayPlugin implements Payment {
AliPayRequest.wapPay(response, payModel, callbackUrl(apiProperties.getBuyer(), PaymentMethodEnum.ALIPAY),
notifyUrl(apiProperties.getBuyer(), PaymentMethodEnum.ALIPAY));
} catch (Exception e) {
e.printStackTrace();
log.error("H5支付异常", e);
throw new ServiceException(ResultCode.ALIPAY_EXCEPTION);
}
return null;
}
@@ -121,8 +122,11 @@ public class AliPayPlugin implements Payment {
String orderInfo = AliPayRequest.appPayToResponse(payModel, notifyUrl(apiProperties.getBuyer(), PaymentMethodEnum.ALIPAY)).getBody();
return ResultUtil.data(orderInfo);
} catch (AlipayApiException e) {
e.printStackTrace();
return ResultUtil.error(ResultCode.PAY_ERROR);
log.error("支付宝支付异常:", e);
throw new ServiceException(ResultCode.ALIPAY_EXCEPTION);
} catch (Exception e) {
log.error("支付业务异常:", e);
throw new ServiceException(ResultCode.PAY_ERROR);
}
}
@@ -151,9 +155,9 @@ public class AliPayPlugin implements Payment {
JSONObject jsonObject = JSONObject.parseObject(resultStr);
return ResultUtil.data(jsonObject.getJSONObject("alipay_trade_precreate_response").getString("qr_code"));
} catch (Exception e) {
e.printStackTrace();
log.error("支付业务异常:", e);
throw new ServiceException(ResultCode.PAY_ERROR);
}
return null;
}
@@ -169,6 +173,7 @@ public class AliPayPlugin implements Payment {
model.setRefundAmount(refundLog.getTotalAmount() + "");
model.setRefundReason(refundLog.getRefundReason());
model.setOutRequestNo(refundLog.getOutOrderNo());
//交互退款
try {
AlipayTradeRefundResponse alipayTradeRefundResponse = AliPayApi.tradeRefundToResponse(model);
log.error("支付宝退款,参数:{},支付宝响应:{}", JSONUtil.toJsonStr(model), JSONUtil.toJsonStr(alipayTradeRefundResponse));
@@ -180,7 +185,8 @@ public class AliPayPlugin implements Payment {
}
refundLogService.save(refundLog);
} catch (Exception e) {
e.printStackTrace();
log.error("支付退款异常:", e);
throw new ServiceException(ResultCode.PAY_ERROR);
}
}
@@ -192,9 +198,11 @@ public class AliPayPlugin implements Payment {
if (StringUtils.isNotEmpty(refundLog.getPaymentReceivableNo())) {
model.setTradeNo(refundLog.getPaymentReceivableNo());
} else {
throw new ServiceException(ResultCode.ERROR);
log.error("退款时,支付参数为空导致异常:{}", refundLog);
throw new ServiceException(ResultCode.ALIPAY_PARAMS_EXCEPTION);
}
try {
//与阿里进行交互
AlipayTradeCancelResponse alipayTradeCancelResponse = AliPayApi.tradeCancelToResponse(model);
if (alipayTradeCancelResponse.isSuccess()) {
refundLog.setIsRefund(true);
@@ -204,7 +212,7 @@ public class AliPayPlugin implements Payment {
}
refundLogService.save(refundLog);
} catch (Exception e) {
e.printStackTrace();
log.error("支付宝退款异常",e);
}
}
@@ -256,8 +264,7 @@ public class AliPayPlugin implements Payment {
log.info("支付回调通知:支付失败-参数:{}", map);
}
} catch (AlipayApiException e) {
e.printStackTrace();
throw new ServiceException("支付回调通知异常");
log.error("支付回调通知异常", e);
}
}
@@ -272,7 +279,7 @@ public class AliPayPlugin implements Payment {
if (setting != null) {
return JSONUtil.toBean(setting.getSettingValue(), AlipayPaymentSetting.class);
}
throw new ServiceException("支付未配置");
throw new ServiceException(ResultCode.ALIPAY_NOT_SETTING);
}

View File

@@ -138,7 +138,7 @@ public class WechatPlugin implements Payment {
return ResultUtil.data(JSONUtil.toJsonStr(response.getBody()));
} catch (Exception e) {
e.printStackTrace();
return ResultUtil.error(ResultCode.PAY_ERROR);
throw new ServiceException(ResultCode.PAY_ERROR);
}
}
@@ -206,10 +206,10 @@ public class WechatPlugin implements Payment {
return ResultUtil.data(map);
}
log.error("微信支付参数验证错误,请及时处理");
return ResultUtil.error(ResultCode.PAY_ERROR);
throw new ServiceException(ResultCode.PAY_ERROR);
} catch (Exception e) {
log.error("支付异常", e);
return ResultUtil.error(ResultCode.PAY_ERROR);
throw new ServiceException(ResultCode.PAY_ERROR);
}
}
@@ -269,10 +269,10 @@ public class WechatPlugin implements Payment {
return ResultUtil.data(map);
}
log.error("微信支付参数验证错误,请及时处理");
return ResultUtil.error(ResultCode.PAY_ERROR);
throw new ServiceException(ResultCode.PAY_ERROR);
} catch (Exception e) {
log.error("支付异常", e);
return ResultUtil.error(ResultCode.PAY_ERROR);
throw new ServiceException(ResultCode.PAY_ERROR);
}
}
@@ -324,14 +324,14 @@ public class WechatPlugin implements Payment {
return ResultUtil.data(new JSONObject(response.getBody()).getStr("code_url"));
} else {
log.error("微信支付参数验证错误,请及时处理");
return ResultUtil.error(ResultCode.PAY_ERROR);
throw new ServiceException(ResultCode.PAY_ERROR);
}
} catch (ServiceException e) {
log.error("支付异常", e);
return ResultUtil.error(ResultCode.PAY_ERROR);
throw new ServiceException(ResultCode.PAY_ERROR);
} catch (Exception e) {
log.error("支付异常", e);
return ResultUtil.error(ResultCode.PAY_ERROR);
throw new ServiceException(ResultCode.PAY_ERROR);
}
}
@@ -407,10 +407,10 @@ public class WechatPlugin implements Payment {
return ResultUtil.data(map);
}
log.error("微信支付参数验证错误,请及时处理");
return ResultUtil.error(ResultCode.PAY_ERROR);
throw new ServiceException(ResultCode.PAY_ERROR);
} catch (Exception e) {
log.error("支付异常", e);
return ResultUtil.error(ResultCode.PAY_ERROR);
throw new ServiceException(ResultCode.PAY_ERROR);
}
}

View File

@@ -34,6 +34,7 @@ import org.elasticsearch.search.SearchHit;
import org.mybatis.spring.MyBatisSystemException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
@@ -61,6 +62,8 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
private GoodsWordsService goodsWordsService;
@Autowired
private PromotionService promotionService;
@Autowired
private ElasticsearchRestTemplate elasticsearchRestTemplate;
@Override
public void addIndex(EsGoodsIndex goods) {
@@ -149,7 +152,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
public void initIndex(List<EsGoodsIndex> goodsIndexList) {
//索引名称拼接
String indexName = elasticsearchProperties.getIndexPrefix() + "_" + EsSuffix.GOODS_INDEX_NAME;
// deleteIndexRequest(indexName);
//如果索引不存在,则创建索引
if (!indexExist(indexName)) {
createIndexRequest(indexName);

View File

@@ -82,7 +82,7 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
if (CharSequenceUtil.isNotEmpty(searchDTO.getKeyword())) {
cache.incrementScore(HotWordsRedisKeyEnum.SEARCH_HOT_WORD.name(), searchDTO.getKeyword());
}
NativeSearchQueryBuilder searchQueryBuilder = createSearchQueryBuilder(searchDTO, pageVo, false);
NativeSearchQueryBuilder searchQueryBuilder = createSearchQueryBuilder(searchDTO, pageVo, true);
NativeSearchQuery searchQuery = searchQueryBuilder.build();
log.info("searchGoods DSL:{}", searchQuery.getQuery());
@@ -260,10 +260,14 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
//分页
nativeSearchQueryBuilder.withPageable(pageable);
}
//查询参数非空判定
if (searchDTO != null) {
//过滤条件
BoolQueryBuilder filterBuilder = QueryBuilders.boolQuery();
//查询条件
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
//对查询条件进行处理
this.commonSearch(filterBuilder, queryBuilder, searchDTO, isAggregation);
// 未上架的商品不显示
@@ -279,6 +283,7 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
this.keywordSearch(filterBuilder, queryBuilder, searchDTO.getKeyword(), isAggregation);
}
//如果是聚合查询
if (isAggregation) {
nativeSearchQueryBuilder.withQuery(filterBuilder);
} else {
@@ -297,23 +302,36 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
return nativeSearchQueryBuilder;
}
/**
* 查询属性处理
* @param filterBuilder
* @param queryBuilder
* @param searchDTO
* @param isAggregation
*/
private void commonSearch(BoolQueryBuilder filterBuilder, BoolQueryBuilder queryBuilder, EsGoodsSearchDTO searchDTO, boolean isAggregation) {
//品牌判定
if (CharSequenceUtil.isNotEmpty(searchDTO.getBrandId())) {
String[] brands = searchDTO.getBrandId().split("@");
filterBuilder.must(QueryBuilders.termsQuery("brandId", brands));
}
//规格项判定
if (searchDTO.getNameIds() != null && !searchDTO.getNameIds().isEmpty()) {
filterBuilder.must(QueryBuilders.nestedQuery(ATTR_PATH, QueryBuilders.termsQuery("attrList.nameId", searchDTO.getNameIds()), ScoreMode.None));
}
//分类判定
if (CharSequenceUtil.isNotEmpty(searchDTO.getCategoryId())) {
filterBuilder.must(QueryBuilders.wildcardQuery("categoryPath", "*" + searchDTO.getCategoryId() + "*"));
}
//店铺分类判定
if (CharSequenceUtil.isNotEmpty(searchDTO.getStoreCatId())) {
filterBuilder.must(QueryBuilders.wildcardQuery("storeCategoryPath", "*" + searchDTO.getStoreCatId() + "*"));
}
//店铺判定
if (CharSequenceUtil.isNotEmpty(searchDTO.getStoreId())) {
filterBuilder.filter(QueryBuilders.termQuery("storeId", searchDTO.getStoreId()));
}
//属性判定
if (CharSequenceUtil.isNotEmpty(searchDTO.getProp())) {
String[] props = searchDTO.getProp().split("@");
List<String> nameList = new ArrayList<>();
@@ -340,6 +358,7 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
searchDTO.getNotShowCol().put(ATTR_NAME_KEY, nameList);
searchDTO.getNotShowCol().put(ATTR_VALUE_KEY, valueList);
}
//价格区间判定
if (CharSequenceUtil.isNotEmpty(searchDTO.getPrice())) {
String[] prices = searchDTO.getPrice().split("_");
if(prices.length==0){
@@ -355,20 +374,33 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService {
}
}
/**
* 关键字查询处理
* @param filterBuilder
* @param queryBuilder
* @param keyword
* @param isAggregation
*/
private void keywordSearch(BoolQueryBuilder filterBuilder, BoolQueryBuilder queryBuilder, String keyword, boolean isAggregation) {
List<FunctionScoreQueryBuilder.FilterFunctionBuilder> filterFunctionBuilders = new ArrayList<>();
//商品名字匹配
filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.wildcardQuery("goodsName", "*" + keyword + "*"),
ScoreFunctionBuilders.weightFactorFunction(10)));
//属性匹配
filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.nestedQuery(ATTR_PATH, QueryBuilders.wildcardQuery(ATTR_VALUE, "*" + keyword + "*"), ScoreMode.None),
ScoreFunctionBuilders.weightFactorFunction(8)));
FunctionScoreQueryBuilder.FilterFunctionBuilder[] builders = new FunctionScoreQueryBuilder.FilterFunctionBuilder[filterFunctionBuilders.size()];
filterFunctionBuilders.toArray(builders);
FunctionScoreQueryBuilder functionScoreQueryBuilder = QueryBuilders.functionScoreQuery(builders)
.scoreMode(FunctionScoreQuery.ScoreMode.SUM)
.setMinScore(2);
//聚合搜索则将结果放入过滤条件
if (isAggregation) {
filterBuilder.must(functionScoreQueryBuilder);
} else {
}
//否则放入查询条件
else {
queryBuilder.must(functionScoreQueryBuilder);
}
}

View File

@@ -21,15 +21,17 @@ public class StoreCompanyDTO {
@ApiModelProperty(value = "公司名称")
private String companyName;
@Size(min = 2, max = 100)
@NotBlank(message = "地址不能为空")
@ApiModelProperty(value = "地址名称, ''分割")
private String addressPath;
private String storeAddressPath;
@Size(min = 2, max = 100)
@NotBlank(message = "地址ID不能为空")
@ApiModelProperty(value = "地址id''分割 ")
private String addressIdPath;
private String storeAddressIdPath;
@NotBlank(message = "地址详情")
@ApiModelProperty(value = "地址详情")
private String storeAddressDetail;
@Size(min = 1, max = 200)
@NotBlank(message = "公司地址不能为空")