zhuyifan

fix

...@@ -56,4 +56,6 @@ public interface CommonConstants { ...@@ -56,4 +56,6 @@ public interface CommonConstants {
56 56
57 String LOGIN_SOURCE = "loginSource"; 57 String LOGIN_SOURCE = "loginSource";
58 58
59 + String OPEN_ID = "openId";
60 +
59 } 61 }
......
...@@ -37,6 +37,10 @@ public class LoginContextHolder { ...@@ -37,6 +37,10 @@ public class LoginContextHolder {
37 return CONTEXT_HOLDER.get().getEnterpriseId(); 37 return CONTEXT_HOLDER.get().getEnterpriseId();
38 } 38 }
39 39
40 + public static String getOpenId() {
41 + return CONTEXT_HOLDER.get().getOpenId();
42 + }
43 +
40 public static void clear() { 44 public static void clear() {
41 CONTEXT_HOLDER.remove(); 45 CONTEXT_HOLDER.remove();
42 } 46 }
...@@ -54,7 +58,8 @@ public class LoginContextHolder { ...@@ -54,7 +58,8 @@ public class LoginContextHolder {
54 58
55 private String name; 59 private String name;
56 60
57 - private String openid; 61 + @Builder.Default
62 + private String openId = "";
58 63
59 } 64 }
60 65
......
...@@ -65,7 +65,7 @@ public class OrderController { ...@@ -65,7 +65,7 @@ public class OrderController {
65 return orderService.getOrderDetailsByOrderId(orderId); 65 return orderService.getOrderDetailsByOrderId(orderId);
66 } 66 }
67 67
68 - @ApiOperation(value = "创建订单") 68 + @ApiOperation(value = "小程序创建订单")
69 @PostMapping("/orders") 69 @PostMapping("/orders")
70 @ResponseStatus(HttpStatus.OK) 70 @ResponseStatus(HttpStatus.OK)
71 @RepeatSubmit(prefix = "createOrder", isLockByLoginUser = false) 71 @RepeatSubmit(prefix = "createOrder", isLockByLoginUser = false)
......
1 package com.infoloop.tianting.enums; 1 package com.infoloop.tianting.enums;
2 2
3 -import com.infoloop.tianting.exception.BaseEnum;
4 import lombok.AllArgsConstructor; 3 import lombok.AllArgsConstructor;
5 import lombok.Getter; 4 import lombok.Getter;
6 5
7 @Getter 6 @Getter
8 @AllArgsConstructor 7 @AllArgsConstructor
9 public enum LoginSourceEnum{ 8 public enum LoginSourceEnum{
10 - CUSTOMER(1, "小程序住院客户"), 9 + CUSTOMER(1, "住院客户"),
11 - MINI_PROGRAM(2, "小程序非住院客户"), 10 + MINI_PROGRAM(2, "阳光厅客户"),
12 OPERATOR(3, "院区端"), 11 OPERATOR(3, "院区端"),
13 KDS(4, "KDS"), 12 KDS(4, "KDS"),
14 ; 13 ;
......
...@@ -12,15 +12,12 @@ import com.infoloop.tianting.enums.LoginSourceEnum; ...@@ -12,15 +12,12 @@ import com.infoloop.tianting.enums.LoginSourceEnum;
12 import com.infoloop.tianting.exception.ClientEndExceptions; 12 import com.infoloop.tianting.exception.ClientEndExceptions;
13 import com.infoloop.tianting.exception.ErrorCodeEnum; 13 import com.infoloop.tianting.exception.ErrorCodeEnum;
14 import com.infoloop.tianting.model.common.ResponseResult; 14 import com.infoloop.tianting.model.common.ResponseResult;
15 -import com.infoloop.tianting.service.ClientCustomerService;
16 import com.infoloop.tianting.service.client.ClientCustomerServiceRpcClient; 15 import com.infoloop.tianting.service.client.ClientCustomerServiceRpcClient;
17 import com.infoloop.tianting.service.client.OperatorServiceRpcClient; 16 import com.infoloop.tianting.service.client.OperatorServiceRpcClient;
18 import com.infoloop.tianting.service.client.WOperatorServiceRpcClient; 17 import com.infoloop.tianting.service.client.WOperatorServiceRpcClient;
19 import com.infoloop.tianting.utils.ResponseUtil; 18 import com.infoloop.tianting.utils.ResponseUtil;
20 import lombok.RequiredArgsConstructor; 19 import lombok.RequiredArgsConstructor;
21 import lombok.extern.slf4j.Slf4j; 20 import lombok.extern.slf4j.Slf4j;
22 -import org.apache.tomcat.jni.Error;
23 -import org.springframework.beans.factory.annotation.Autowired;
24 import org.springframework.http.HttpStatus; 21 import org.springframework.http.HttpStatus;
25 import org.springframework.stereotype.Component; 22 import org.springframework.stereotype.Component;
26 import org.springframework.web.method.HandlerMethod; 23 import org.springframework.web.method.HandlerMethod;
...@@ -71,6 +68,7 @@ public class LoginInterceptor extends HandlerInterceptorAdapter { ...@@ -71,6 +68,7 @@ public class LoginInterceptor extends HandlerInterceptorAdapter {
71 final var enterpriseId = Convert.toInt(StpUtil.getExtra(CommonConstants.ENTERPRISE_ID)); 68 final var enterpriseId = Convert.toInt(StpUtil.getExtra(CommonConstants.ENTERPRISE_ID));
72 final var loginSource = Convert.toInt(StpUtil.getExtra(CommonConstants.LOGIN_SOURCE)); 69 final var loginSource = Convert.toInt(StpUtil.getExtra(CommonConstants.LOGIN_SOURCE));
73 if (loginSource.equals(LoginSourceEnum.CUSTOMER.getValue())) { 70 if (loginSource.equals(LoginSourceEnum.CUSTOMER.getValue())) {
71 + final var openId = Convert.toStr(StpUtil.getExtra(CommonConstants.OPEN_ID));
74 final var loginId = StpUtil.getLoginIdAsInt(); 72 final var loginId = StpUtil.getLoginIdAsInt();
75 final var customer = clientCustomerServiceRpcClient.getClientCustomerById(enterpriseId, loginId); 73 final var customer = clientCustomerServiceRpcClient.getClientCustomerById(enterpriseId, loginId);
76 if (customer == null) { 74 if (customer == null) {
...@@ -78,7 +76,7 @@ public class LoginInterceptor extends HandlerInterceptorAdapter { ...@@ -78,7 +76,7 @@ public class LoginInterceptor extends HandlerInterceptorAdapter {
78 ResponseUtil.write(response, ResponseResult.failed(ErrorCodeEnum.VALIDATE_FAILED)); 76 ResponseUtil.write(response, ResponseResult.failed(ErrorCodeEnum.VALIDATE_FAILED));
79 return false; 77 return false;
80 } 78 }
81 - builder.id(loginId).enterpriseId(enterpriseId).name(customer.getResponse().getName()); 79 + builder.id(loginId).enterpriseId(enterpriseId).name(customer.getResponse().getName()).openId(openId);
82 return true; 80 return true;
83 } else if (loginSource.equals(LoginSourceEnum.OPERATOR.getValue())){ 81 } else if (loginSource.equals(LoginSourceEnum.OPERATOR.getValue())){
84 final var loginId = StpUtil.getLoginIdAsInt(); 82 final var loginId = StpUtil.getLoginIdAsInt();
...@@ -101,7 +99,7 @@ public class LoginInterceptor extends HandlerInterceptorAdapter { ...@@ -101,7 +99,7 @@ public class LoginInterceptor extends HandlerInterceptorAdapter {
101 return true; 99 return true;
102 } else { 100 } else {
103 final var loginId = StpUtil.getLoginIdAsString(); 101 final var loginId = StpUtil.getLoginIdAsString();
104 - builder.openid(loginId).enterpriseId(enterpriseId); 102 + builder.openId(loginId).enterpriseId(enterpriseId);
105 return true; 103 return true;
106 } 104 }
107 } 105 }
......
...@@ -545,6 +545,7 @@ public class OrderServiceRpcClient { ...@@ -545,6 +545,7 @@ public class OrderServiceRpcClient {
545 .setRoomNo(createOrderDto.getRoomNo()) 545 .setRoomNo(createOrderDto.getRoomNo())
546 .setShouldCreateTableCode(createOrderDto.getOrderType().equals(OrderTypeEnum.DINE_IN.getValue()) || !createOrderDto.getTableCode().isEmpty()) 546 .setShouldCreateTableCode(createOrderDto.getOrderType().equals(OrderTypeEnum.DINE_IN.getValue()) || !createOrderDto.getTableCode().isEmpty())
547 .setTableCode(createOrderDto.getTableCode()) 547 .setTableCode(createOrderDto.getTableCode())
548 + .setShouldCreateOnlinePay(true)
548 .setOnlinePay(createOrderDto.getOnlinePay()) 549 .setOnlinePay(createOrderDto.getOnlinePay())
549 .setShouldCreatePayStatus(createOrderDto.getOnlinePay()) 550 .setShouldCreatePayStatus(createOrderDto.getOnlinePay())
550 .setPayStatus(PayStatusEnum.TO_PAY) 551 .setPayStatus(PayStatusEnum.TO_PAY)
...@@ -581,7 +582,6 @@ public class OrderServiceRpcClient { ...@@ -581,7 +582,6 @@ public class OrderServiceRpcClient {
581 if ((skuSellQuantityRpcResponse.getTodaySellQuantity() + orderDetail.getCount()) > skuSellQuantityRpcResponse.getMaxSellQuantity()) { 582 if ((skuSellQuantityRpcResponse.getTodaySellQuantity() + orderDetail.getCount()) > skuSellQuantityRpcResponse.getMaxSellQuantity()) {
582 log.error("skuSellQuantityRpcResponse stock no enough; stallId:{}, skuId:{}, count:{}", createOrderDto.getStallId(), orderDetail.getSkuId(), orderDetail.getCount()); 583 log.error("skuSellQuantityRpcResponse stock no enough; stallId:{}, skuId:{}, count:{}", createOrderDto.getStallId(), orderDetail.getSkuId(), orderDetail.getCount());
583 skuStockMap.put(skuMap.get(orderDetail.getSkuId()).getName(), skuSellQuantityRpcResponse.getMaxSellQuantity() - skuSellQuantityRpcResponse.getTodaySellQuantity()); 584 skuStockMap.put(skuMap.get(orderDetail.getSkuId()).getName(), skuSellQuantityRpcResponse.getMaxSellQuantity() - skuSellQuantityRpcResponse.getTodaySellQuantity());
584 - continue;
585 } 585 }
586 } 586 }
587 if (!soldOutSkus.isEmpty()) { 587 if (!soldOutSkus.isEmpty()) {
......
...@@ -3,6 +3,7 @@ package com.infoloop.tianting.service.impl; ...@@ -3,6 +3,7 @@ package com.infoloop.tianting.service.impl;
3 import cn.dev33.satoken.stp.SaLoginModel; 3 import cn.dev33.satoken.stp.SaLoginModel;
4 import cn.dev33.satoken.stp.SaTokenInfo; 4 import cn.dev33.satoken.stp.SaTokenInfo;
5 import cn.dev33.satoken.stp.StpUtil; 5 import cn.dev33.satoken.stp.StpUtil;
6 +import cn.hutool.crypto.SecureUtil;
6 import com.infoloop.tianting.clientcustomerservice.ClientCustomerHospitalRecordHospitalStatusEnum; 7 import com.infoloop.tianting.clientcustomerservice.ClientCustomerHospitalRecordHospitalStatusEnum;
7 import com.infoloop.tianting.constant.CommonConstants; 8 import com.infoloop.tianting.constant.CommonConstants;
8 import com.infoloop.tianting.exception.ClientEndExceptions; 9 import com.infoloop.tianting.exception.ClientEndExceptions;
...@@ -32,70 +33,59 @@ public class LoginServiceImpl implements LoginService { ...@@ -32,70 +33,59 @@ public class LoginServiceImpl implements LoginService {
32 public SaTokenInfo login(LoginDto loginDto) { 33 public SaTokenInfo login(LoginDto loginDto) {
33 if (loginDto.isShouldLoginWithOpenCode()) { 34 if (loginDto.isShouldLoginWithOpenCode()) {
34 final var wxUserOpenIdDto = wxMiniProgramHttpClient.getUserOpenIdByCode(loginDto.getOpenCode()); 35 final var wxUserOpenIdDto = wxMiniProgramHttpClient.getUserOpenIdByCode(loginDto.getOpenCode());
35 - StpUtil.login( 36 + StpUtil.login(wxUserOpenIdDto.getOpenid(), SaLoginModel.create()
36 - wxUserOpenIdDto.getOpenid(), 37 + .setExtra(CommonConstants.ENTERPRISE_ID, loginDto.getEnterpriseId())
37 - SaLoginModel.create() 38 + .setExtra(CommonConstants.LOGIN_SOURCE, loginDto.getLoginSourceEnum().getValue())
38 - .setExtra(CommonConstants.ENTERPRISE_ID, loginDto.getEnterpriseId()) 39 + .build());
39 - .setExtra(CommonConstants.LOGIN_SOURCE, loginDto.getLoginSourceEnum().getValue())
40 - .build());
41 return StpUtil.getTokenInfo(); 40 return StpUtil.getTokenInfo();
42 } else if (loginDto.isShouldLoginWithHisCustomerId()) { 41 } else if (loginDto.isShouldLoginWithHisCustomerId()) {
43 - var customer = 42 + var customer = clientCustomerServiceRpcClient.getClientCustomerByHISCustomerId(loginDto.getHisCustomerId()).getResponse();
44 - clientCustomerServiceRpcClient
45 - .getClientCustomerByHISCustomerId(loginDto.getHisCustomerId())
46 - .getResponse();
47 if (customer.getId() == 0) { 43 if (customer.getId() == 0) {
48 // 根据hisCustomerId拿不到用户的话再去根据合同号去his查一次,即认为是月子中心客户 44 // 根据hisCustomerId拿不到用户的话再去根据合同号去his查一次,即认为是月子中心客户
49 - customer = 45 + customer = clientCustomerServiceRpcClient.getClientCustomerByContactNo(loginDto.getHisCustomerId()).getResponse();
50 - clientCustomerServiceRpcClient
51 - .getClientCustomerByContactNo(loginDto.getHisCustomerId())
52 - .getResponse();
53 if (customer.getId() == 0) { 46 if (customer.getId() == 0) {
54 throw ClientEndExceptions.IncorrectRequestValue.build(ErrorCodeEnum.VALIDATE_FAILED.name()); 47 throw ClientEndExceptions.IncorrectRequestValue.build(ErrorCodeEnum.VALIDATE_FAILED.name());
55 } else { 48 } else {
56 - var record = 49 + var record = clientCustomerServiceRpcClient.getClientCustomerHospitalRecordsByCustomerId(customer.getEnterpriseId(), customer.getId());
57 - clientCustomerServiceRpcClient.getClientCustomerHospitalRecordsByCustomerId( 50 + if (!record.hasResponse() || record.getResponse().getHospitalStatus() != ClientCustomerHospitalRecordHospitalStatusEnum.CURRENT) {
58 - customer.getEnterpriseId(), customer.getId()); 51 + throw ClientEndExceptions.IncorrectRequestValue.build(ErrorCodeEnum.VALIDATE_FAILED.name());
59 - if (!record.hasResponse()
60 - || record.getResponse().getHospitalStatus()
61 - != ClientCustomerHospitalRecordHospitalStatusEnum.CURRENT) {
62 - throw ClientEndExceptions.IncorrectRequestValue.build(
63 - ErrorCodeEnum.VALIDATE_FAILED.name());
64 } 52 }
65 } 53 }
54 + } else {
55 + var record = clientCustomerServiceRpcClient.getClientCustomerHospitalRecordsByCustomerId(customer.getEnterpriseId(), customer.getId());
56 + if (!record.hasResponse() || record.getResponse().getHospitalStatus() != ClientCustomerHospitalRecordHospitalStatusEnum.CURRENT) {
57 + throw ClientEndExceptions.IncorrectRequestValue.build(ErrorCodeEnum.VALIDATE_FAILED.name());
58 + }
66 } 59 }
67 - StpUtil.login( 60 + final var wxUserOpenIdDto = wxMiniProgramHttpClient.getUserOpenIdByCode(loginDto.getOpenCode());
68 - customer.getId(), 61 + StpUtil.login(customer.getId(), SaLoginModel.create()
69 - SaLoginModel.create() 62 + .setExtra(CommonConstants.ENTERPRISE_ID, customer.getEnterpriseId())
70 - .setExtra(CommonConstants.ENTERPRISE_ID, customer.getEnterpriseId()) 63 + .setExtra(CommonConstants.LOGIN_SOURCE, loginDto.getLoginSourceEnum().getValue())
71 - .setExtra(CommonConstants.LOGIN_SOURCE, loginDto.getLoginSourceEnum().getValue()) 64 + .setExtra(CommonConstants.OPEN_ID, wxUserOpenIdDto.getOpenid())
72 - .build()); 65 + .build());
73 return StpUtil.getTokenInfo(); 66 return StpUtil.getTokenInfo();
74 } else if (loginDto.isShouldLoginWithOperatorPhone()) { 67 } else if (loginDto.isShouldLoginWithOperatorPhone()) {
75 - final var operator = 68 + final var operator = operatorServiceRpcClient.getCOperatorByMobileOrEmail(loginDto.getOperatorPhone());
76 - operatorServiceRpcClient.getCOperatorByMobileOrEmail(loginDto.getOperatorPhone());
77 if (operator.getId() == 0) { 69 if (operator.getId() == 0) {
78 throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.UNAUTHORIZED.name()); 70 throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.UNAUTHORIZED.name());
79 } 71 }
80 - StpUtil.login( 72 + if (!operator.getPassword().equals(SecureUtil.sha1(loginDto.getPassword()))) {
81 - operator.getId(), 73 + throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.VALIDATE_FAILED.name());
82 - SaLoginModel.create() 74 + }
75 + StpUtil.login(operator.getId(), SaLoginModel.create()
83 .setExtra(CommonConstants.ENTERPRISE_ID, operator.getEnterpriseId()) 76 .setExtra(CommonConstants.ENTERPRISE_ID, operator.getEnterpriseId())
84 .setExtra(CommonConstants.LOGIN_SOURCE, loginDto.getLoginSourceEnum().getValue()) 77 .setExtra(CommonConstants.LOGIN_SOURCE, loginDto.getLoginSourceEnum().getValue())
85 .build()); 78 .build());
86 return StpUtil.getTokenInfo(); 79 return StpUtil.getTokenInfo();
87 } else { 80 } else {
88 - final var operator = 81 + final var operator = wOperatorServiceRpcClient.getWOperatorByEmail(loginDto.getEmail()).getResponse();
89 - wOperatorServiceRpcClient.getWOperatorByEmail(loginDto.getEmail()).getResponse();
90 if (operator.getId() == 0) { 82 if (operator.getId() == 0) {
91 throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.UNAUTHORIZED.name()); 83 throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.UNAUTHORIZED.name());
92 } 84 }
93 -// if (!operator.getPassword().equals(loginDto.getPassword())) { 85 + if (!operator.getPassword().equals(SecureUtil.sha1(loginDto.getPassword()))) {
94 -// throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.VALIDATE_FAILED.name()); 86 + throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.VALIDATE_FAILED.name());
95 -// } 87 + }
96 - StpUtil.login( 88 + StpUtil.login(operator.getId(), SaLoginModel.create()
97 - operator.getId(),
98 - SaLoginModel.create()
99 .setExtra(CommonConstants.ENTERPRISE_ID, operator.getEnterpriseId()) 89 .setExtra(CommonConstants.ENTERPRISE_ID, operator.getEnterpriseId())
100 .setExtra(CommonConstants.LOGIN_SOURCE, loginDto.getLoginSourceEnum().getValue()) 90 .setExtra(CommonConstants.LOGIN_SOURCE, loginDto.getLoginSourceEnum().getValue())
101 .build()); 91 .build());
......
...@@ -92,8 +92,8 @@ public class OrderServiceImpl implements OrderService { ...@@ -92,8 +92,8 @@ public class OrderServiceImpl implements OrderService {
92 final var record = clientCustomerServiceRpcClient.getClientCustomerHospitalRecordsByCustomerId(customer.getEnterpriseId(), customer.getId()).getResponse(); 92 final var record = clientCustomerServiceRpcClient.getClientCustomerHospitalRecordsByCustomerId(customer.getEnterpriseId(), customer.getId()).getResponse();
93 CreateOrderDto createOrderDto = new CreateOrderDto(); 93 CreateOrderDto createOrderDto = new CreateOrderDto();
94 createOrderDto.setShouldCreateCustomerId(true); 94 createOrderDto.setShouldCreateCustomerId(true);
95 - createOrderDto.setShouldCreateOpenId(false); 95 + createOrderDto.setShouldCreateOpenId(true);
96 - createOrderDto.setOpenId(""); 96 + createOrderDto.setOpenId(operatorLoginInfo.getOpenId());
97 createOrderDto.setTableCode(operatorCreateOrderDto.getTableCode()); 97 createOrderDto.setTableCode(operatorCreateOrderDto.getTableCode());
98 createOrderDto.setCustomerId(operatorCreateOrderDto.getCustomerId()); 98 createOrderDto.setCustomerId(operatorCreateOrderDto.getCustomerId());
99 createOrderDto.setStallId(operatorCreateOrderDto.getStallId()); 99 createOrderDto.setStallId(operatorCreateOrderDto.getStallId());
...@@ -156,13 +156,11 @@ public class OrderServiceImpl implements OrderService { ...@@ -156,13 +156,11 @@ public class OrderServiceImpl implements OrderService {
156 .doctors(Stream.of(doctors, dietDoctors).flatMap(List::stream).collect(Collectors.toList())) 156 .doctors(Stream.of(doctors, dietDoctors).flatMap(List::stream).collect(Collectors.toList()))
157 .build(); 157 .build();
158 createOrderDto.setCustomerNoticeJson(customerNotice); 158 createOrderDto.setCustomerNoticeJson(customerNotice);
159 -
160 createOrderDto.setUpdatedBy(operatorLoginInfo.getId()); 159 createOrderDto.setUpdatedBy(operatorLoginInfo.getId());
161 createOrderDto.setUpdateSource(OrderSourceEnum.STALL.getNumber()); 160 createOrderDto.setUpdateSource(OrderSourceEnum.STALL.getNumber());
162 List<CreateOrderDetailDto> orderDetailDtoList = new ArrayList<>(); 161 List<CreateOrderDetailDto> orderDetailDtoList = new ArrayList<>();
163 final var menuDetails = menuServiceRpcClient.queryMenuDetailsByMenuId(menu.getEnterpriseId(), operatorCreateOrderDto.getMenuId()).getResponsesList(); 162 final var menuDetails = menuServiceRpcClient.queryMenuDetailsByMenuId(menu.getEnterpriseId(), operatorCreateOrderDto.getMenuId()).getResponsesList();
164 - final var skuIds = 163 + final var skuIds = menuDetails.stream()
165 - menuDetails.stream()
166 .map(SingleMenuDetailRpcResponse::getSkuId) 164 .map(SingleMenuDetailRpcResponse::getSkuId)
167 .collect(Collectors.toList()); 165 .collect(Collectors.toList());
168 final var rpcSkus = skuServiceRpcClient.getDishSkusByIds(skuIds).getResponseList(); 166 final var rpcSkus = skuServiceRpcClient.getDishSkusByIds(skuIds).getResponseList();
......