提交 6886ea2c authored 作者: 李秋林's avatar 李秋林

controller层返回值手动添加R封闭

上级 96b60d06
...@@ -16,4 +16,5 @@ public class WangxiaoluPromotionServiceApplication { ...@@ -16,4 +16,5 @@ public class WangxiaoluPromotionServiceApplication {
SpringApplication.run(WangxiaoluPromotionServiceApplication.class, args); SpringApplication.run(WangxiaoluPromotionServiceApplication.class, args);
} }
} }
package com.wangxiaolu.promotion.advice;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.wangxiaolu.promotion.exception.APIException;
import com.wangxiaolu.promotion.result.basedata.R;
import com.wangxiaolu.promotion.result.basedata.RCode;
import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
/**
* @author : liqiulin
* @date : 2024-03-28 17
* @describe : todo 自动封装
*/
@RestControllerAdvice
public class ControllerResponseAdvice implements ResponseBodyAdvice<Object> {
@Override
public boolean supports(MethodParameter methodParameter, Class<? extends HttpMessageConverter<?>> aClass) {
// response是R类型或者注释了NotControllerResponseAdvice都不进行包装
return !methodParameter.getParameterType().isAssignableFrom(R.class);
}
@Override
public Object beforeBodyWrite(Object data, MethodParameter methodParameter, MediaType mediaType, Class<? extends HttpMessageConverter<?>> aClass, ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse) {
// String类型不能直接包装
if (methodParameter.getGenericParameterType().equals(String.class)) {
ObjectMapper objectMapper = new ObjectMapper();
try {
// 将数据包装在ResultVo里后转换为json串进行返回
return objectMapper.writeValueAsString(new R(data));
} catch (JsonProcessingException e) {
throw new APIException(RCode.RESPONSE_PACK_ERROR, e.getMessage());
}
}
// 包装成R返回
return new R(data);
}
}
package com.wangxiaolu.promotion.config.aspet;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.support.spring.PropertyPreFilters;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
@Slf4j
@Component
@Aspect
public class ControllerLogAspect {
/**
* 对controller包中的所有类中的所有public类进行增强
*/
@Pointcut("execution(public * com.wangxiaolu.promotion.controller..*.*(..))")
private void pointcut(){}
@Before("pointcut()")
public void before(JoinPoint joinPoint){
/**
* 此次请求
*/
ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = sra.getRequest();
// Signature signature = joinPoint.getSignature();
// String name = signature.getName();
log.info("------------- 开始 -------------");
log.info("请求地址:{}:{}", request.getMethod(), request.getRequestURL().toString());
// log.info("类路径:{};方法名:{}", signature.getDeclaringTypeName(), name);
Object[] args = joinPoint.getArgs();
Object[] arguments = new Object[args.length];
for (int i = 0; i < args.length; i++) {
if (args[i] instanceof ServletRequest
|| args[i] instanceof ServletResponse
|| args[i] instanceof MultipartFile) {
continue;
}
arguments[i] = args[i];
}
String[] excludeProperties = {"password", "file"};
PropertyPreFilters filters = new PropertyPreFilters();
PropertyPreFilters.MySimplePropertyPreFilter excludeFilter = filters.addFilter();
excludeFilter.addExcludes(excludeProperties);
log.info("请求参数: {}", JSONObject.toJSONString(arguments, excludeFilter));
}
@Around("pointcut()")
public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
long millis = System.currentTimeMillis();
Object result = proceedingJoinPoint.proceed();
String[] excludeProperties = {"password", "file"};
PropertyPreFilters filters = new PropertyPreFilters();
PropertyPreFilters.MySimplePropertyPreFilter excludeFilter = filters.addFilter();
excludeFilter.addExcludes(excludeProperties);
log.info("返回结果: {}", JSONObject.toJSONString(result, excludeFilter));
log.info("------------- 结束 耗时:{} ms -------------", System.currentTimeMillis() - millis);
return result;
}
}
package com.wangxiaolu.promotion.controller.activity.temporary; package com.wangxiaolu.promotion.controller.activity.temporary;
import com.wangxiaolu.promotion.pojo.activity.temporary.dto.TemporaryClockDto; import com.wangxiaolu.promotion.pojo.activity.temporary.dto.TemporaryClockDto;
import com.wangxiaolu.promotion.result.basedata.R;
import com.wangxiaolu.promotion.service.activity.temporary.TemporaryActivityClockQueryService; import com.wangxiaolu.promotion.service.activity.temporary.TemporaryActivityClockQueryService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -26,18 +27,21 @@ public class TemporaryActivityClockQueryController { ...@@ -26,18 +27,21 @@ public class TemporaryActivityClockQueryController {
* 根据促销员id查询今日打卡信息 * 根据促销员id查询今日打卡信息
*/ */
@GetMapping("/{temporary_id}") @GetMapping("/{temporary_id}")
public TemporaryClockDto findTodayTemporaryClockByTemId(@PathVariable("temporary_id") @NotNull Integer temporaryId) { public R findTodayTemporaryClockByTemId(@PathVariable("temporary_id") @NotNull Integer temporaryId) {
return temporaryActivityClockQueryService.findTodayTemporaryClockByTemId(temporaryId); TemporaryClockDto clockDto = temporaryActivityClockQueryService.findTodayTemporaryClockByTemId(temporaryId);
return R.success(clockDto);
} }
/** /**
* 根据促销员id查询指定日期打卡信息 * 根据促销员id查询指定日期打卡信息
*
* @param temporaryId 促销员id * @param temporaryId 促销员id
* @param createDate 指定日期,格式:2024-04-25 * @param createDate 指定日期,格式:2024-04-25
* @return 打卡信息 * @return 打卡信息
*/ */
@GetMapping("/date") @GetMapping("/date")
public TemporaryClockDto findTemporaryClockByTemIdAndDate(Integer temporaryId, String createDate) { public R findTemporaryClockByTemIdAndDate(Integer temporaryId, String createDate) {
return temporaryActivityClockQueryService.findTemporaryClockByTemIdAndDate(temporaryId, createDate); TemporaryClockDto clockDto = temporaryActivityClockQueryService.findTemporaryClockByTemIdAndDate(temporaryId, createDate);
return R.success(clockDto);
} }
} }
package com.wangxiaolu.promotion.controller.activity.temporary; package com.wangxiaolu.promotion.controller.activity.temporary;
import com.wangxiaolu.promotion.exception.ParamException; import com.wangxiaolu.promotion.exception.ParamException;
import com.wangxiaolu.promotion.result.basedata.R;
import com.wangxiaolu.promotion.result.basedata.RCode; import com.wangxiaolu.promotion.result.basedata.RCode;
import com.wangxiaolu.promotion.enums.activity.ClockType; import com.wangxiaolu.promotion.enums.activity.ClockType;
import com.wangxiaolu.promotion.pojo.activity.temporary.dto.TemporaryActivityReportedDto; import com.wangxiaolu.promotion.pojo.activity.temporary.dto.TemporaryActivityReportedDto;
...@@ -36,7 +37,7 @@ public class TemporaryActivityCoreController { ...@@ -36,7 +37,7 @@ public class TemporaryActivityCoreController {
* 促销员当日打卡信息保存 * 促销员当日打卡信息保存
*/ */
@PostMapping("/today/clock") @PostMapping("/today/clock")
public void clockInTodayActivity(@RequestBody @Validated TemporaryClockVo clockVo) { public R clockInTodayActivity(@RequestBody @Validated TemporaryClockVo clockVo) {
Integer clockType = clockVo.getClockType(); Integer clockType = clockVo.getClockType();
boolean isClockIn = ClockType.TEMPORARY_CLOCK_IN.equals(clockType); boolean isClockIn = ClockType.TEMPORARY_CLOCK_IN.equals(clockType);
// 上班卡必需有店铺id // 上班卡必需有店铺id
...@@ -61,6 +62,7 @@ public class TemporaryActivityCoreController { ...@@ -61,6 +62,7 @@ public class TemporaryActivityCoreController {
builderClockOutData(clockVo, dto, clockTime); builderClockOutData(clockVo, dto, clockTime);
} }
tempActivityCoreService.clockInTodayActivity(dto, clockType); tempActivityCoreService.clockInTodayActivity(dto, clockType);
return R.success();
} }
/** /**
...@@ -68,7 +70,7 @@ public class TemporaryActivityCoreController { ...@@ -68,7 +70,7 @@ public class TemporaryActivityCoreController {
* 返回活动生成id * 返回活动生成id
*/ */
@PostMapping("/today/reported") @PostMapping("/today/reported")
public Long todayActivityDataReported(@RequestBody @Validated TemporaryActivityDataVo activityVo) { public R todayActivityDataReported(@RequestBody @Validated TemporaryActivityDataVo activityVo) {
TemporaryActivityReportedDto temActDto = new TemporaryActivityReportedDto(); TemporaryActivityReportedDto temActDto = new TemporaryActivityReportedDto();
BeanUtils.copyProperties(activityVo, temActDto); BeanUtils.copyProperties(activityVo, temActDto);
temActDto.setId(activityVo.getActivityReportedId()); temActDto.setId(activityVo.getActivityReportedId());
...@@ -76,9 +78,9 @@ public class TemporaryActivityCoreController { ...@@ -76,9 +78,9 @@ public class TemporaryActivityCoreController {
// 有ID则修改,无ID则新建 // 有ID则修改,无ID则新建
if (Objects.nonNull(activityVo.getActivityReportedId())) { if (Objects.nonNull(activityVo.getActivityReportedId())) {
tempActivityCoreService.activityDataReportedUpdate(temActDto); tempActivityCoreService.activityDataReportedUpdate(temActDto);
return activityVo.getActivityReportedId(); return R.success(activityVo.getActivityReportedId());
} }
return tempActivityCoreService.activityDataReportedSave(temActDto); return R.success(tempActivityCoreService.activityDataReportedSave(temActDto));
} }
/** /**
...@@ -86,8 +88,9 @@ public class TemporaryActivityCoreController { ...@@ -86,8 +88,9 @@ public class TemporaryActivityCoreController {
* 修改审批状态 * 修改审批状态
*/ */
@PutMapping("/reported/approve/submit/{id}") @PutMapping("/reported/approve/submit/{id}")
public void activityReportedSubmit(@PathVariable("id") @NotNull Long id) { public R activityReportedSubmit(@PathVariable("id") @NotNull Long id) {
tempActivityCoreService.activityReportedSubmit(id); tempActivityCoreService.activityReportedSubmit(id);
return R.success();
} }
......
...@@ -2,6 +2,7 @@ package com.wangxiaolu.promotion.controller.activity.temporary; ...@@ -2,6 +2,7 @@ package com.wangxiaolu.promotion.controller.activity.temporary;
import com.wangxiaolu.promotion.pojo.PageInfo; import com.wangxiaolu.promotion.pojo.PageInfo;
import com.wangxiaolu.promotion.pojo.activity.temporary.dto.TemporaryActivityReportedDto; import com.wangxiaolu.promotion.pojo.activity.temporary.dto.TemporaryActivityReportedDto;
import com.wangxiaolu.promotion.result.basedata.R;
import com.wangxiaolu.promotion.service.activity.temporary.TemporaryActivityQueryService; import com.wangxiaolu.promotion.service.activity.temporary.TemporaryActivityQueryService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -28,26 +29,26 @@ public class TemporaryActivityQueryController { ...@@ -28,26 +29,26 @@ public class TemporaryActivityQueryController {
* @return 所有任务(分页查询) * @return 所有任务(分页查询)
*/ */
@PostMapping("/all/{id}") @PostMapping("/all/{id}")
public PageInfo findtemporaryIdActivityDataList(@PathVariable("id") @NotNull Integer temporaryId, @RequestBody PageInfo pageInfo) { public R findtemporaryIdActivityDataList(@PathVariable("id") @NotNull Integer temporaryId, @RequestBody PageInfo pageInfo) {
temporaryActivityQueryService.findtemporaryIdActivityDataList(temporaryId, pageInfo); temporaryActivityQueryService.findtemporaryIdActivityDataList(temporaryId, pageInfo);
return pageInfo; return R.success(pageInfo);
} }
/** /**
* 根据促销员id查询今日任务 * 根据促销员id查询今日任务
*/ */
@GetMapping("/today/{id}") @GetMapping("/today/{id}")
public TemporaryActivityReportedDto findTemporaryTodayActivityData(@PathVariable("id") @NotNull Integer temporaryId) { public R findTemporaryTodayActivityData(@PathVariable("id") @NotNull Integer temporaryId) {
TemporaryActivityReportedDto dto = temporaryActivityQueryService.findtemporaryIdTodayActivityData(temporaryId); TemporaryActivityReportedDto dto = temporaryActivityQueryService.findtemporaryIdTodayActivityData(temporaryId);
return dto; return R.success(dto);
} }
/** /**
* 根据任务id查询 * 根据任务id查询
*/ */
@GetMapping("/{id}") @GetMapping("/{id}")
public TemporaryActivityReportedDto findTemporaryActivityById(@PathVariable("id") @NotNull Long activityId) { public R findTemporaryActivityById(@PathVariable("id") @NotNull Long activityId) {
TemporaryActivityReportedDto dto = temporaryActivityQueryService.findTemporaryActivityById(activityId); TemporaryActivityReportedDto dto = temporaryActivityQueryService.findTemporaryActivityById(activityId);
return dto; return R.success(dto);
} }
} }
package com.wangxiaolu.promotion.controller.user; package com.wangxiaolu.promotion.controller.user;
import com.wangxiaolu.promotion.pojo.user.vo.UserLoginParam; import com.wangxiaolu.promotion.pojo.user.vo.UserLoginParam;
import com.wangxiaolu.promotion.result.basedata.R;
import com.wangxiaolu.promotion.service.user.PromotionService; import com.wangxiaolu.promotion.service.user.PromotionService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
...@@ -23,7 +24,8 @@ public class PromotionLoginController { ...@@ -23,7 +24,8 @@ public class PromotionLoginController {
PromotionService promotionService; PromotionService promotionService;
@PostMapping("/login") @PostMapping("/login")
public void login(@Validated @RequestBody UserLoginParam userLoginParam){ public R login(@Validated @RequestBody UserLoginParam userLoginParam){
promotionService.login(userLoginParam); promotionService.login(userLoginParam);
return R.success();
} }
} }
...@@ -2,6 +2,7 @@ package com.wangxiaolu.promotion.controller.user; ...@@ -2,6 +2,7 @@ package com.wangxiaolu.promotion.controller.user;
import com.wangxiaolu.promotion.pojo.user.dto.QinCeClienteleStoreDto; import com.wangxiaolu.promotion.pojo.user.dto.QinCeClienteleStoreDto;
import com.wangxiaolu.promotion.pojo.user.vo.ClienteleStoreQueryVo; import com.wangxiaolu.promotion.pojo.user.vo.ClienteleStoreQueryVo;
import com.wangxiaolu.promotion.result.basedata.R;
import com.wangxiaolu.promotion.service.user.QinCeClienteleDataQueryService; import com.wangxiaolu.promotion.service.user.QinCeClienteleDataQueryService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
...@@ -28,8 +29,8 @@ public class QinCeClienteleDataQueryController { ...@@ -28,8 +29,8 @@ public class QinCeClienteleDataQueryController {
* 模糊查询门店名称 * 模糊查询门店名称
*/ */
@PostMapping("/store/list") @PostMapping("/store/list")
public List<QinCeClienteleStoreDto> getStoreList(@RequestBody ClienteleStoreQueryVo storeQueryVo){ public R getStoreList(@RequestBody ClienteleStoreQueryVo storeQueryVo) {
return qinCeClienteleDataQueryService.getStoreList(storeQueryVo); return R.success(qinCeClienteleDataQueryService.getStoreList(storeQueryVo));
} }
......
package com.wangxiaolu.promotion.controller.user; package com.wangxiaolu.promotion.controller.user;
import com.wangxiaolu.promotion.result.basedata.R;
import com.wangxiaolu.promotion.service.user.QinCeDataTaskService; import com.wangxiaolu.promotion.service.user.QinCeDataTaskService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -22,24 +23,27 @@ public class QinCeDataTaskController { ...@@ -22,24 +23,27 @@ public class QinCeDataTaskController {
* 同步组织架构/部门数据 * 同步组织架构/部门数据
*/ */
@GetMapping("/department") @GetMapping("/department")
public void departmentTask(){ public R departmentTask(){
qinCeDataTaskService.departmentSyncTask(); qinCeDataTaskService.departmentSyncTask();
return R.success();
} }
/** /**
* 同步员工数据 * 同步员工数据
*/ */
@GetMapping("/employee") @GetMapping("/employee")
public void employeeTask(){ public R employeeTask(){
qinCeDataTaskService.employeeSyncTask(); qinCeDataTaskService.employeeSyncTask();
return R.success();
} }
/** /**
* 同步[终端数据] * 同步[终端数据]
*/ */
@GetMapping("/shops") @GetMapping("/shops")
public void shopDetailAllTask(){ public R shopDetailAllTask(){
qinCeDataTaskService.shopDetailAllTask(); qinCeDataTaskService.shopDetailAllTask();
return R.success();
} }
......
package com.wangxiaolu.promotion.controller.user; package com.wangxiaolu.promotion.controller.user;
import com.wangxiaolu.promotion.exception.ParamException; import com.wangxiaolu.promotion.exception.ParamException;
import com.wangxiaolu.promotion.result.basedata.R;
import com.wangxiaolu.promotion.result.basedata.RCode; import com.wangxiaolu.promotion.result.basedata.RCode;
import com.wangxiaolu.promotion.service.user.TencentCoreService; import com.wangxiaolu.promotion.service.user.TencentCoreService;
import com.wangxiaolu.promotion.common.util.DataUtils; import com.wangxiaolu.promotion.common.util.DataUtils;
...@@ -28,12 +29,13 @@ public class UserSendSms { ...@@ -28,12 +29,13 @@ public class UserSendSms {
* 腾讯云短信 * 腾讯云短信
*/ */
@PostMapping("/send/ver_code") @PostMapping("/send/ver_code")
public void sendSms(@RequestBody Map<String, String> phoneInfo) { public R sendSms(@RequestBody Map<String, String> phoneInfo) {
String phone = phoneInfo.get("phone"); String phone = phoneInfo.get("phone");
if (StringUtils.isEmpty(phone) || !DataUtils.phonePattern(phone)) { if (StringUtils.isEmpty(phone) || !DataUtils.phonePattern(phone)) {
throw new ParamException(RCode.PHONE_PARAM_ERROR, null); throw new ParamException(RCode.PHONE_PARAM_ERROR, null);
} }
tencentCoreService.sendSmsPhoneVerCode(phone); tencentCoreService.sendSmsPhoneVerCode(phone);
return R.success();
} }
......
...@@ -6,6 +6,7 @@ import com.wangxiaolu.promotion.common.redis.service.RedisCache; ...@@ -6,6 +6,7 @@ import com.wangxiaolu.promotion.common.redis.service.RedisCache;
import com.wangxiaolu.promotion.exception.ParamException; import com.wangxiaolu.promotion.exception.ParamException;
import com.wangxiaolu.promotion.pojo.user.dto.WxTemporaryInfoDto; import com.wangxiaolu.promotion.pojo.user.dto.WxTemporaryInfoDto;
import com.wangxiaolu.promotion.pojo.user.vo.WxTemporaryEnrollVo; import com.wangxiaolu.promotion.pojo.user.vo.WxTemporaryEnrollVo;
import com.wangxiaolu.promotion.result.basedata.R;
import com.wangxiaolu.promotion.result.basedata.RCode; import com.wangxiaolu.promotion.result.basedata.RCode;
import com.wangxiaolu.promotion.service.wechat.WeChatUserCoreService; import com.wangxiaolu.promotion.service.wechat.WeChatUserCoreService;
import com.wangxiaolu.promotion.common.util.DataUtils; import com.wangxiaolu.promotion.common.util.DataUtils;
...@@ -38,7 +39,7 @@ public class WeChatUserCoreController { ...@@ -38,7 +39,7 @@ public class WeChatUserCoreController {
* 促销员注册信息 * 促销员注册信息
*/ */
@PostMapping("/temporary/enroll") @PostMapping("/temporary/enroll")
public boolean enrollUserInfo(@RequestBody @Validated WxTemporaryEnrollVo wxTemporaryEnrollVo) { public R enrollUserInfo(@RequestBody @Validated WxTemporaryEnrollVo wxTemporaryEnrollVo) {
log.info("微信-促销员注册:{}", JSONObject.toJSONString(wxTemporaryEnrollVo)); log.info("微信-促销员注册:{}", JSONObject.toJSONString(wxTemporaryEnrollVo));
// 人员信息校验 // 人员信息校验
boolean isIden = DataUtils.idenCardPattern(wxTemporaryEnrollVo.getIdenNumber()); boolean isIden = DataUtils.idenCardPattern(wxTemporaryEnrollVo.getIdenNumber());
...@@ -59,7 +60,7 @@ public class WeChatUserCoreController { ...@@ -59,7 +60,7 @@ public class WeChatUserCoreController {
WxTemporaryInfoDto temporaryDto = new WxTemporaryInfoDto(); WxTemporaryInfoDto temporaryDto = new WxTemporaryInfoDto();
BeanUtils.copyProperties(wxTemporaryEnrollVo, temporaryDto); BeanUtils.copyProperties(wxTemporaryEnrollVo, temporaryDto);
return weChatUserCoreService.saveWxUserInfoTemporary(temporaryDto); return R.success(weChatUserCoreService.saveWxUserInfoTemporary(temporaryDto));
} }
} }
package com.wangxiaolu.promotion.controller.wechat; package com.wangxiaolu.promotion.controller.wechat;
import com.wangxiaolu.promotion.common.util.DataUtils;
import com.wangxiaolu.promotion.exception.ParamException; import com.wangxiaolu.promotion.exception.ParamException;
import com.wangxiaolu.promotion.pojo.user.dto.WxTemporaryInfoDto; import com.wangxiaolu.promotion.pojo.user.dto.WxTemporaryInfoDto;
import com.wangxiaolu.promotion.pojo.user.vo.WxTemporaryLoginVo; import com.wangxiaolu.promotion.pojo.user.vo.WxTemporaryLoginVo;
import com.wangxiaolu.promotion.result.basedata.R;
import com.wangxiaolu.promotion.result.basedata.RCode; import com.wangxiaolu.promotion.result.basedata.RCode;
import com.wangxiaolu.promotion.service.wechat.WeChatUserQueryService; import com.wangxiaolu.promotion.service.wechat.WeChatUserQueryService;
import com.wangxiaolu.promotion.common.util.DataUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -32,12 +33,13 @@ public class WeChatUserQueryController { ...@@ -32,12 +33,13 @@ public class WeChatUserQueryController {
* @return 非null则登录成功 * @return 非null则登录成功
*/ */
@PostMapping("/temporary/login/phone_openid") @PostMapping("/temporary/login/phone_openid")
public boolean temporaryLoginByPhoneAndOpenId(@RequestBody WxTemporaryLoginVo wxTemporaryLoginVo) { public R temporaryLoginByPhoneAndOpenId(@RequestBody WxTemporaryLoginVo wxTemporaryLoginVo) {
phontAndOpenIdVerify(wxTemporaryLoginVo); phontAndOpenIdVerify(wxTemporaryLoginVo);
if (!DataUtils.phonePattern(wxTemporaryLoginVo.getPhone())) { if (!DataUtils.phonePattern(wxTemporaryLoginVo.getPhone())) {
throw new ParamException(RCode.PHONE_PARAM_ERROR, null); throw new ParamException(RCode.PHONE_PARAM_ERROR, null);
} }
return weChatUserQueryService.loginTemporaryByOpenIdAndPhone(wxTemporaryLoginVo.getOpenId(), wxTemporaryLoginVo.getPhone()); String s = weChatUserQueryService.loginTemporaryByOpenIdAndPhone(wxTemporaryLoginVo.getOpenId(), wxTemporaryLoginVo.getPhone());
return R.success(s);
} }
...@@ -45,13 +47,13 @@ public class WeChatUserQueryController { ...@@ -45,13 +47,13 @@ public class WeChatUserQueryController {
* 促销员信息查询 * 促销员信息查询
*/ */
@PostMapping("/temporary/phone_openid") @PostMapping("/temporary/phone_openid")
public WxTemporaryInfoDto getTemporaryInfoByOpenIdAndPhone(@RequestBody WxTemporaryLoginVo wxTemporaryLoginVo) { public R getTemporaryInfoByOpenIdAndPhone(@RequestBody WxTemporaryLoginVo wxTemporaryLoginVo) {
phontAndOpenIdVerify(wxTemporaryLoginVo); phontAndOpenIdVerify(wxTemporaryLoginVo);
WxTemporaryInfoDto temporaryInfoDto = weChatUserQueryService.getTemporaryInfoByOpenIdAndPhone(wxTemporaryLoginVo.getOpenId(), wxTemporaryLoginVo.getPhone()); WxTemporaryInfoDto temporaryInfoDto = weChatUserQueryService.getTemporaryInfoByOpenIdAndPhone(wxTemporaryLoginVo.getOpenId(), wxTemporaryLoginVo.getPhone());
if (Objects.isNull(temporaryInfoDto)) { if (Objects.isNull(temporaryInfoDto)) {
throw new ParamException(RCode.LOGIN_PARAM_ERROR, null); throw new ParamException(RCode.LOGIN_PARAM_ERROR, null);
} }
return temporaryInfoDto; return R.success(temporaryInfoDto);
} }
private void phontAndOpenIdVerify(WxTemporaryLoginVo wxTemporaryLoginVo) { private void phontAndOpenIdVerify(WxTemporaryLoginVo wxTemporaryLoginVo) {
......
...@@ -9,7 +9,7 @@ import com.wangxiaolu.promotion.pojo.user.dto.WxTemporaryInfoDto; ...@@ -9,7 +9,7 @@ import com.wangxiaolu.promotion.pojo.user.dto.WxTemporaryInfoDto;
*/ */
public interface WeChatUserQueryService { public interface WeChatUserQueryService {
boolean loginTemporaryByOpenIdAndPhone(String openId,String phone); String loginTemporaryByOpenIdAndPhone(String openId, String phone);
WxTemporaryInfoDto getTemporaryInfoByOpenIdAndPhone(String openId,String phone); WxTemporaryInfoDto getTemporaryInfoByOpenIdAndPhone(String openId,String phone);
} }
package com.wangxiaolu.promotion.service.wechat.impl; package com.wangxiaolu.promotion.service.wechat.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.wangxiaolu.promotion.common.redis.RedisKeys;
import com.wangxiaolu.promotion.common.redis.service.RedisCache; import com.wangxiaolu.promotion.common.redis.service.RedisCache;
import com.wangxiaolu.promotion.domain.user.dao.TemporaryInfoDao; import com.wangxiaolu.promotion.domain.user.dao.TemporaryInfoDao;
import com.wangxiaolu.promotion.pojo.user.dto.WxTemporaryInfoDto; import com.wangxiaolu.promotion.pojo.user.dto.WxTemporaryInfoDto;
...@@ -11,6 +12,8 @@ import org.slf4j.LoggerFactory; ...@@ -11,6 +12,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
/** /**
...@@ -33,18 +36,20 @@ public class WeChatUserQueryServiceImpl implements WeChatUserQueryService { ...@@ -33,18 +36,20 @@ public class WeChatUserQueryServiceImpl implements WeChatUserQueryService {
* 根据openId、手机号登录 * 根据openId、手机号登录
*/ */
@Override @Override
public boolean loginTemporaryByOpenIdAndPhone(String openId, String phone) { public String loginTemporaryByOpenIdAndPhone(String openId, String phone) {
WxTemporaryInfoDto temDto = temporaryInfoDao.getUnimportantData(openId, phone); WxTemporaryInfoDto temDto = temporaryInfoDao.getUnimportantData(openId, phone);
boolean exist = !Objects.isNull(temDto); boolean exist = !Objects.isNull(temDto);
String temporaryToken = "";
if (exist) { if (exist) {
log.info("微信-促销员{}登录成功(openId、手机号),openId:{},phone:{}", temDto.getName(), openId, phone); log.info("微信-促销员{}登录成功(openId、手机号),openId:{},phone:{}", temDto.getName(), openId, phone);
log.info(JSONObject.toJSONString(temDto)); // 生成一个token
temporaryToken = jwtUtils.getTemporaryToken(openId, phone);
redisCache.addToJsonToDays(RedisKeys.UserKeys.TEMPORARY_TOKEN.getKey()+temporaryToken,temDto,1);
} else { } else {
log.info("微信-促销员登录失败,当前信息未注册(openId、手机号),openId:{},phone:{}", openId, phone); log.info("微信-促销员登录失败,当前信息未注册(openId、手机号),openId:{},phone:{}", openId, phone);
} }
return temporaryToken;
return exist;
} }
@Override @Override
......
...@@ -25,7 +25,7 @@ class TemporaryActivityCoreControllerTest { ...@@ -25,7 +25,7 @@ class TemporaryActivityCoreControllerTest {
void todayActivityDataReported() { void todayActivityDataReported() {
TemporaryActivityDataVo activityVo = new TemporaryActivityDataVo(); TemporaryActivityDataVo activityVo = new TemporaryActivityDataVo();
Long aLong = temporaryActivityCoreController.todayActivityDataReported(activityVo); // Long aLong = temporaryActivityCoreController.todayActivityDataReported(activityVo);
System.out.println(" 促销员活动上报成功,生成id:" + aLong); // System.out.println(" 促销员活动上报成功,生成id:" + aLong);
} }
} }
\ No newline at end of file
...@@ -25,8 +25,8 @@ class WeChatUserQueryControllerTest { ...@@ -25,8 +25,8 @@ class WeChatUserQueryControllerTest {
@Test @Test
void temporaryLoginByPhoneAndOpenId() { void temporaryLoginByPhoneAndOpenId() {
WxTemporaryLoginVo loginVO = new WxTemporaryLoginVo().setOpenId("oCMt-66hnlY9-bQcZAAZKX0p3s6I").setPhone("15701654502"); WxTemporaryLoginVo loginVO = new WxTemporaryLoginVo().setOpenId("oCMt-66hnlY9-bQcZAAZKX0p3s6I").setPhone("15701654502");
boolean b = weChatUserQueryController.temporaryLoginByPhoneAndOpenId(loginVO); // boolean b = weChatUserQueryController.temporaryLoginByPhoneAndOpenId(loginVO);
System.out.println("temporaryLoginByPhoneAndOpenId 登录结果:" + b); // System.out.println("temporaryLoginByPhoneAndOpenId 登录结果:" + b);
} }
@Test @Test
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论