feat:添加商品详情接口

This commit is contained in:
haoxr 2020-11-27 15:10:17 +08:00
parent 8996499a91
commit 21a73e420d
17 changed files with 96 additions and 64 deletions

View File

@ -24,6 +24,11 @@
<groupId>io.github.openfeign</groupId>
<artifactId>feign-okhttp</artifactId>
</dependency>
<dependency>
<groupId>com.youlai</groupId>
<artifactId>ums-api</artifactId>
<version>${youlai.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -3,15 +3,20 @@ package com.youlai.mall.oms.bo;
import com.youlai.mall.oms.pojo.OmsOrder;
import com.youlai.mall.oms.pojo.OmsOrderItem;
import com.youlai.mall.ums.dto.MemberInfoDTO;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.List;
@Data
@Accessors(chain = true)
public class OrderBO {
private OmsOrder order;
private List<OmsOrderItem> orderItems;
private MemberInfoDTO member;
}

View File

@ -31,28 +31,38 @@ public class OmsOrder extends BaseEntity {
private Long couponId;
private Long orderPrice;
private Long skuPrice;
private Long freightPrice;
private Long couponPrice;
private Long orderPrice;
private Long integrationPrice;
private Long payPrice;
private String payId;
private Long payPrice;
private Integer payChannel;
private Date payTime;
private Date gmtPay;
private String logisticsChannel;
private String logisticsNo;
private Date deliveryTime;
private Date gmtDelivery;
private Long refundAmount;
private Integer refundType;
private String refundNote;
private Date gmtRefund;
private Date gmtConfirm;
}

View File

@ -17,8 +17,6 @@ public class OmsOrderItem extends BaseEntity {
private Long orderId;
private String orderSn;
private Long spuId;
private String spuName;
@ -33,6 +31,6 @@ public class OmsOrderItem extends BaseEntity {
private Integer skuQuantity;
private String pic;
private String skuPic;
}

View File

@ -0,0 +1,27 @@
package com.youlai.mall.ums.api;
import com.youlai.common.core.result.Result;
import com.youlai.mall.ums.dto.MemberInfoDTO;
import com.youlai.mall.ums.pojo.UmsMember;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
@FeignClient("mall-ums")
public interface MemberFeignService {
@PostMapping("/members")
Result add(@RequestBody UmsMember member);
/**
* 获取会员
* @param id
* @param queryMode 查询模式1-认证会员 2-订单会员
* @return
*/
@GetMapping("/members/{id}")
Result<MemberInfoDTO> getMember(@PathVariable Object id, @RequestParam(value = "queryMode") Integer queryMode);
}

View File

@ -1,23 +0,0 @@
package com.youlai.mall.ums.api;
import com.youlai.common.core.result.Result;
import com.youlai.mall.ums.dto.MemberDTO;
import com.youlai.mall.ums.pojo.UmsMember;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@FeignClient("youlai-mall-ums")
public interface UmsMemberFeignClient {
@GetMapping("/members/member/{openid}")
Result<MemberDTO> loadMemberByOpenid(@PathVariable String openid);
@PostMapping("/members")
Result add(@RequestBody UmsMember member);
}

View File

@ -0,0 +1,13 @@
package com.youlai.mall.ums.dto;
import lombok.Data;
@Data
public class MemberInfoDTO {
private Long id;
private String nickname;
private String mobile;
}

View File

@ -7,7 +7,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@FeignClient("youlai-admin")
public interface AdminUserFeignClient {
public interface UserFeignService {
@GetMapping("/users/user/{username}")
Result<UserDTO> loadUserByUsername(@PathVariable String username);

View File

@ -109,7 +109,7 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE);
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Cache-Control", "no-cache");
Result result = Result.custom(ResultCode.CLIENT_AUTHENTICATION_FAILED);
Result result = Result.failed(ResultCode.CLIENT_AUTHENTICATION_FAILED);
response.getWriter().print(JSONUtil.toJsonStr(result));
response.getWriter().flush();
};

View File

@ -16,7 +16,7 @@ import com.youlai.common.core.result.ResultCode;
import com.youlai.common.web.exception.BizException;
import com.youlai.mall.ums.dto.MemberDTO;
import com.youlai.mall.ums.pojo.UmsMember;
import com.youlai.mall.ums.api.UmsMemberFeignClient;
import com.youlai.mall.ums.api.MemberFeignService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
@ -50,7 +50,7 @@ public class AuthController {
private TokenEndpoint tokenEndpoint;
private RedisTemplate redisTemplate;
private WxMaService wxService;
private UmsMemberFeignClient umsMemberFeignClient;
private MemberFeignService memberFeignService;
private PasswordEncoder passwordEncoder;
private KeyPair keyPair;
@ -122,13 +122,10 @@ public class AuthController {
String openid = session.getOpenid();
String sessionKey = session.getSessionKey();
Result<MemberDTO> result = umsMemberFeignClient.loadMemberByOpenid(openid);
if (!ResultCode.SUCCESS.getCode().equals(result.getCode())) {
throw new BizException("获取会员信息失败");
}
MemberDTO memberDTO = result.getData();
Result<MemberDTO> result = memberFeignService.getMember(openid, 1);
String username;
if (memberDTO == null) { // 微信授权登录 会员信息不存在时 注册会员
if (ResultCode.USER_NOT_EXIST.getCode().equals(result.getCode())) { // 微信授权登录 会员信息不存在时 注册会员
String encryptedData = parameters.get("encryptedData");
String iv = parameters.get("iv");
@ -145,12 +142,13 @@ public class AuthController {
.setPassword(passwordEncoder.encode(openid).replace(AuthConstants.BCRYPT, Strings.EMPTY)) // 加密密码移除前缀加密方式 {bcrypt}
.setStatus(Constants.STATUS_NORMAL_VALUE);
Result res = umsMemberFeignClient.add(member);
Result res = memberFeignService.add(member);
if (!ResultCode.SUCCESS.getCode().equals(res.getCode())) {
throw new BizException("注册会员失败");
}
username = openid;
} else {
MemberDTO memberDTO = result.getData();
username = memberDTO.getUsername();
}

View File

@ -20,7 +20,7 @@ public class AuthExceptionHandler {
*/
@ExceptionHandler(InvalidGrantException.class)
public Result handleInvalidGrantException(InvalidGrantException e) {
return Result.custom(ResultCode.USERNAME_OR_PASSWORD_ERROR);
return Result.failed(ResultCode.USERNAME_OR_PASSWORD_ERROR);
}
@ -32,7 +32,7 @@ public class AuthExceptionHandler {
*/
@ExceptionHandler({InternalAuthenticationServiceException.class})
public Result handleInternalAuthenticationServiceException(InternalAuthenticationServiceException e) {
return Result.error(e.getMessage());
return Result.failed(e.getMessage());
}
}

View File

@ -1,16 +1,15 @@
package com.youlai.auth.service;
import com.youlai.admin.dto.UserDTO;
import com.youlai.admin.api.AdminUserFeignClient;
import com.youlai.admin.api.UserFeignService;
import com.youlai.auth.domain.User;
import com.youlai.common.core.constant.AuthConstants;
import com.youlai.common.core.result.Result;
import com.youlai.common.core.result.ResultCode;
import com.youlai.mall.ums.dto.MemberDTO;
import com.youlai.mall.ums.api.UmsMemberFeignClient;
import com.youlai.mall.ums.api.MemberFeignService;
import lombok.AllArgsConstructor;
import org.springframework.security.authentication.AccountExpiredException;
import org.springframework.security.authentication.CredentialsExpiredException;
import org.springframework.security.authentication.DisabledException;
import org.springframework.security.authentication.LockedException;
import org.springframework.security.core.userdetails.UserDetails;
@ -28,8 +27,8 @@ import javax.servlet.http.HttpServletRequest;
@AllArgsConstructor
public class UserDetailsServiceImpl implements UserDetailsService {
private AdminUserFeignClient adminUserFeignClient;
private UmsMemberFeignClient umsMemberFeignClient;
private UserFeignService userFeignService;
private MemberFeignService memberFeignService;
private HttpServletRequest request;
@Override
@ -38,7 +37,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
User user = null;
switch (clientId) {
case AuthConstants.ADMIN_CLIENT_ID: // 后台用户
Result<UserDTO> userResult = adminUserFeignClient.loadUserByUsername(username);
Result<UserDTO> userResult = userFeignService.loadUserByUsername(username);
if (userResult == null || !ResultCode.SUCCESS.getCode().equals(userResult.getCode())
|| userResult.getData() == null
) {
@ -49,7 +48,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
user = new User(userDTO);
break;
case AuthConstants.WEAPP_CLIENT_ID: // 小程序会员
Result<MemberDTO> memberResult = umsMemberFeignClient.loadMemberByOpenid(username);
Result<MemberDTO> memberResult = memberFeignService.getMember(username,2);
if (memberResult == null || !ResultCode.SUCCESS.getCode().equals(memberResult.getCode())
||memberResult.getData()==null) {
throw new UsernameNotFoundException("会员不存在");

View File

@ -34,11 +34,11 @@ public class Result<T> implements Serializable {
}
public static <T> Result<T> error() {
public static <T> Result<T> failed() {
return result(ResultCode.SYSTEM_EXECUTION_ERROR.getCode(), ResultCode.SYSTEM_EXECUTION_ERROR.getMsg(), null);
}
public static <T> Result<T> error(String msg) {
public static <T> Result<T> failed(String msg) {
return result(ResultCode.SYSTEM_EXECUTION_ERROR.getCode(), msg, null);
}
@ -46,11 +46,11 @@ public class Result<T> implements Serializable {
if (status) {
return success();
} else {
return error();
return failed();
}
}
public static <T> Result<T> custom(IResultCode resultCode) {
public static <T> Result<T> failed(IResultCode resultCode) {
return result(resultCode.getCode(), resultCode.getMsg(), null);
}

View File

@ -18,7 +18,7 @@ public enum ResultCode implements IResultCode, Serializable {
USER_ERROR("A0001","用户端错误"),
USER_LOGIN_ERROR("A0200","用户登录异常"),
USER_ACCOUNT_NOT_EXIST("A0201","户账户不存在"),
USER_NOT_EXIST("A0201","户不存在"),
USER_ACCOUNT_LOCKED("A0202","用户账户被冻结"),
USER_ACCOUNT_INVALID("A0203","用户账户已作废"),

View File

@ -18,21 +18,21 @@ public class GlobalExceptionHandler {
@ExceptionHandler(IllegalArgumentException.class)
public Result handleIllegalArgumentException(IllegalArgumentException e) {
return Result.error(e.getMessage());
return Result.failed(e.getMessage());
}
@ExceptionHandler(JsonProcessingException.class)
public Result handleJsonProcessingException(JsonProcessingException e) {
return Result.error(e.getMessage());
return Result.failed(e.getMessage());
}
@ExceptionHandler(BizException.class)
public Result handleBizException(BizException e) {
if (e.getResultCode() != null) {
return Result.custom(e.getResultCode());
return Result.failed(e.getResultCode());
}
return Result.error(e.getMessage());
return Result.failed(e.getMessage());
}
}

View File

@ -74,7 +74,7 @@ public class ResourceServerConfig {
response.getHeaders().set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
response.getHeaders().set("Access-Control-Allow-Origin", "*");
response.getHeaders().set("Cache-Control", "no-cache");
String body = JSONUtil.toJsonStr(Result.custom(ResultCode.USER_ACCESS_UNAUTHORIZED));
String body = JSONUtil.toJsonStr(Result.failed(ResultCode.USER_ACCESS_UNAUTHORIZED));
DataBuffer buffer = response.bufferFactory().wrap(body.getBytes(Charset.forName("UTF-8")));
return response.writeWith(Mono.just(buffer))
.doOnError(error -> DataBufferUtils.release(buffer));
@ -96,7 +96,7 @@ public class ResourceServerConfig {
response.getHeaders().set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
response.getHeaders().set("Access-Control-Allow-Origin", "*");
response.getHeaders().set("Cache-Control", "no-cache");
String body = JSONUtil.toJsonStr(Result.custom(ResultCode.TOKEN_INVALID_OR_EXPIRED));
String body = JSONUtil.toJsonStr(Result.failed(ResultCode.TOKEN_INVALID_OR_EXPIRED));
DataBuffer buffer = response.bufferFactory().wrap(body.getBytes(Charset.forName("UTF-8")));
return response.writeWith(Mono.just(buffer))
.doOnError(error -> DataBufferUtils.release(buffer));

View File

@ -59,7 +59,7 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered {
response.getHeaders().set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
response.getHeaders().set("Access-Control-Allow-Origin", "*");
response.getHeaders().set("Cache-Control", "no-cache");
String body = JSONUtil.toJsonStr(Result.custom(ResultCode.TOKEN_INVALID_OR_EXPIRED));
String body = JSONUtil.toJsonStr(Result.failed(ResultCode.TOKEN_INVALID_OR_EXPIRED));
DataBuffer buffer = response.bufferFactory().wrap(body.getBytes(Charset.forName("UTF-8")));
return response.writeWith(Mono.just(buffer));
}