zhuyifan

fix

......@@ -15,4 +15,5 @@ public class BusinessConfig {
private String hisCustomerQueryUrl;
private String clientCustomerQueryUrl;
private String payUrl;
private String payClientId;
}
......
......@@ -56,4 +56,6 @@ public interface CommonConstants {
String LOGIN_SOURCE = "loginSource";
String OPEN_ID = "openId";
}
......
......@@ -37,6 +37,10 @@ public class LoginContextHolder {
return CONTEXT_HOLDER.get().getEnterpriseId();
}
public static String getOpenId() {
return CONTEXT_HOLDER.get().getOpenId();
}
public static void clear() {
CONTEXT_HOLDER.remove();
}
......@@ -54,7 +58,8 @@ public class LoginContextHolder {
private String name;
private String openid;
@Builder.Default
private String openId = "";
}
......
......@@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import java.security.NoSuchAlgorithmException;
@Api(tags = "登陆")
@ApiSupport(order = -1)
......@@ -32,7 +33,7 @@ public class LoginController {
@ApiOperation(value = "登陆")
@PostMapping("/login")
@ResponseStatus(HttpStatus.OK)
public SaTokenInfo login(@Valid @RequestBody PermissionDTO.LoginDto loginDto) {
public SaTokenInfo login(@Valid @RequestBody PermissionDTO.LoginDto loginDto) throws NoSuchAlgorithmException {
return loginService.login(loginDto);
}
}
......
......@@ -65,7 +65,7 @@ public class OrderController {
return orderService.getOrderDetailsByOrderId(orderId);
}
@ApiOperation(value = "创建订单")
@ApiOperation(value = "小程序创建订单")
@PostMapping("/orders")
@ResponseStatus(HttpStatus.OK)
@RepeatSubmit(prefix = "createOrder", isLockByLoginUser = false)
......
package com.infoloop.tianting.enums;
import com.infoloop.tianting.exception.BaseEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum LoginSourceEnum{
CUSTOMER(1, "小程序住院客户"),
MINI_PROGRAM(2, "小程序非住院客户"),
CUSTOMER(1, "住院客户"),
MINI_PROGRAM(2, "阳光厅客户"),
OPERATOR(3, "院区端"),
KDS(4, "KDS"),
;
......
......@@ -12,15 +12,12 @@ import com.infoloop.tianting.enums.LoginSourceEnum;
import com.infoloop.tianting.exception.ClientEndExceptions;
import com.infoloop.tianting.exception.ErrorCodeEnum;
import com.infoloop.tianting.model.common.ResponseResult;
import com.infoloop.tianting.service.ClientCustomerService;
import com.infoloop.tianting.service.client.ClientCustomerServiceRpcClient;
import com.infoloop.tianting.service.client.OperatorServiceRpcClient;
import com.infoloop.tianting.service.client.WOperatorServiceRpcClient;
import com.infoloop.tianting.utils.ResponseUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.jni.Error;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
......@@ -71,6 +68,7 @@ public class LoginInterceptor extends HandlerInterceptorAdapter {
final var enterpriseId = Convert.toInt(StpUtil.getExtra(CommonConstants.ENTERPRISE_ID));
final var loginSource = Convert.toInt(StpUtil.getExtra(CommonConstants.LOGIN_SOURCE));
if (loginSource.equals(LoginSourceEnum.CUSTOMER.getValue())) {
final var openId = Convert.toStr(StpUtil.getExtra(CommonConstants.OPEN_ID));
final var loginId = StpUtil.getLoginIdAsInt();
final var customer = clientCustomerServiceRpcClient.getClientCustomerById(enterpriseId, loginId);
if (customer == null) {
......@@ -78,7 +76,7 @@ public class LoginInterceptor extends HandlerInterceptorAdapter {
ResponseUtil.write(response, ResponseResult.failed(ErrorCodeEnum.VALIDATE_FAILED));
return false;
}
builder.id(loginId).enterpriseId(enterpriseId).name(customer.getResponse().getName());
builder.id(loginId).enterpriseId(enterpriseId).name(customer.getResponse().getName()).openId(openId);
return true;
} else if (loginSource.equals(LoginSourceEnum.OPERATOR.getValue())){
final var loginId = StpUtil.getLoginIdAsInt();
......@@ -101,7 +99,7 @@ public class LoginInterceptor extends HandlerInterceptorAdapter {
return true;
} else {
final var loginId = StpUtil.getLoginIdAsString();
builder.openid(loginId).enterpriseId(enterpriseId);
builder.openId(loginId).enterpriseId(enterpriseId);
return true;
}
}
......
......@@ -3,6 +3,8 @@ package com.infoloop.tianting.service;
import cn.dev33.satoken.stp.SaTokenInfo;
import com.infoloop.tianting.model.dto.PermissionDTO.LoginDto;
import java.security.NoSuchAlgorithmException;
public interface LoginService {
SaTokenInfo login(LoginDto loginDto);
SaTokenInfo login(LoginDto loginDto) throws NoSuchAlgorithmException;
}
......
......@@ -545,6 +545,7 @@ public class OrderServiceRpcClient {
.setRoomNo(createOrderDto.getRoomNo())
.setShouldCreateTableCode(createOrderDto.getOrderType().equals(OrderTypeEnum.DINE_IN.getValue()) || !createOrderDto.getTableCode().isEmpty())
.setTableCode(createOrderDto.getTableCode())
.setShouldCreateOnlinePay(true)
.setOnlinePay(createOrderDto.getOnlinePay())
.setShouldCreatePayStatus(createOrderDto.getOnlinePay())
.setPayStatus(PayStatusEnum.TO_PAY)
......@@ -581,7 +582,6 @@ public class OrderServiceRpcClient {
if ((skuSellQuantityRpcResponse.getTodaySellQuantity() + orderDetail.getCount()) > skuSellQuantityRpcResponse.getMaxSellQuantity()) {
log.error("skuSellQuantityRpcResponse stock no enough; stallId:{}, skuId:{}, count:{}", createOrderDto.getStallId(), orderDetail.getSkuId(), orderDetail.getCount());
skuStockMap.put(skuMap.get(orderDetail.getSkuId()).getName(), skuSellQuantityRpcResponse.getMaxSellQuantity() - skuSellQuantityRpcResponse.getTodaySellQuantity());
continue;
}
}
if (!soldOutSkus.isEmpty()) {
......
......@@ -23,7 +23,6 @@ import com.infoloop.tianting.utils.EncryptionUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
......@@ -33,6 +32,7 @@ import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.math.BigDecimal;
import java.text.MessageFormat;
import java.text.ParseException;
import java.time.LocalDateTime;
......@@ -47,9 +47,8 @@ public class PayServiceClient {
private final BusinessConfig businessConfig;
private final OrderServiceRpcClient orderServiceRpcClient;
private final XmlMapper xmlMapper = new XmlMapper();
@Value("${payment.client-id:Order0001}")
private String clientId;
public PayResponseDto payInform(PayInformRequestDto payRequestDto) {
final var orderById = orderServiceRpcClient.getOrderById(Integer.valueOf(payRequestDto.getOrderId()));
......@@ -57,7 +56,7 @@ public class PayServiceClient {
log.info("Order {} not found or canceled, skipping.", payRequestDto.getOrderId());
throw ClientEndExceptions.BusinessException.build(ErrorCodeEnum.ORDER_CANCEL);
}
String url = businessConfig.getPayUrl();
String url = MessageFormat.format(businessConfig.getPayUrl(), businessConfig.getPayClientId());
String requestDate = DateUtil.formatDate(LocalDateTime.now(), DateUtil.YMDHMS);
ThirdPartyPayInformRequestDto jsonData = buildRequestData(payRequestDto, requestDate);
String jsonDataString;
......@@ -79,7 +78,7 @@ public class PayServiceClient {
private ThirdPartyPayInformRequestDto buildRequestData(PayInformRequestDto payRequestDto, String requestDate) {
ThirdPartyPayInformRequestDto jsonData = new ThirdPartyPayInformRequestDto();
jsonData.setClientId(clientId);
jsonData.setClientId(businessConfig.getPayClientId());
jsonData.setTradeId(payRequestDto.getOrderId());
jsonData.setRequestDate(requestDate);
jsonData.setRequestSource("OFWXApplet");
......@@ -89,7 +88,7 @@ public class PayServiceClient {
jsonData.setRemark("");
jsonData.setTransAmount(payRequestDto.getPrice());
jsonData.setTradeDesc("");
jsonData.setSign(EncryptionUtil.sha1Encryption(clientId + payRequestDto.getOrderId() + requestDate + clientId));
jsonData.setSign(EncryptionUtil.sha1Encryption(businessConfig.getPayClientId() + payRequestDto.getOrderId() + requestDate + businessConfig.getPayClientId()));
return jsonData;
}
......
......@@ -18,6 +18,9 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@Slf4j
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
......@@ -29,78 +32,82 @@ public class LoginServiceImpl implements LoginService {
private final WOperatorServiceRpcClient wOperatorServiceRpcClient;
@Override
public SaTokenInfo login(LoginDto loginDto) {
public SaTokenInfo login(LoginDto loginDto) throws NoSuchAlgorithmException {
if (loginDto.isShouldLoginWithOpenCode()) {
final var wxUserOpenIdDto = wxMiniProgramHttpClient.getUserOpenIdByCode(loginDto.getOpenCode());
StpUtil.login(
wxUserOpenIdDto.getOpenid(),
SaLoginModel.create()
StpUtil.login(wxUserOpenIdDto.getOpenid(), SaLoginModel.create()
.setExtra(CommonConstants.ENTERPRISE_ID, loginDto.getEnterpriseId())
.setExtra(CommonConstants.LOGIN_SOURCE, loginDto.getLoginSourceEnum().getValue())
.build());
return StpUtil.getTokenInfo();
} else if (loginDto.isShouldLoginWithHisCustomerId()) {
var customer =
clientCustomerServiceRpcClient
.getClientCustomerByHISCustomerId(loginDto.getHisCustomerId())
.getResponse();
var customer = clientCustomerServiceRpcClient.getClientCustomerByHISCustomerId(loginDto.getHisCustomerId()).getResponse();
if (customer.getId() == 0) {
// 根据hisCustomerId拿不到用户的话再去根据合同号去his查一次,即认为是月子中心客户
customer =
clientCustomerServiceRpcClient
.getClientCustomerByContactNo(loginDto.getHisCustomerId())
.getResponse();
customer = clientCustomerServiceRpcClient.getClientCustomerByContactNo(loginDto.getHisCustomerId()).getResponse();
if (customer.getId() == 0) {
throw ClientEndExceptions.IncorrectRequestValue.build(ErrorCodeEnum.VALIDATE_FAILED.name());
} else {
var record =
clientCustomerServiceRpcClient.getClientCustomerHospitalRecordsByCustomerId(
customer.getEnterpriseId(), customer.getId());
if (!record.hasResponse()
|| record.getResponse().getHospitalStatus()
!= ClientCustomerHospitalRecordHospitalStatusEnum.CURRENT) {
throw ClientEndExceptions.IncorrectRequestValue.build(
ErrorCodeEnum.VALIDATE_FAILED.name());
var record = clientCustomerServiceRpcClient.getClientCustomerHospitalRecordsByCustomerId(customer.getEnterpriseId(), customer.getId());
if (!record.hasResponse() || record.getResponse().getHospitalStatus() != ClientCustomerHospitalRecordHospitalStatusEnum.CURRENT) {
throw ClientEndExceptions.IncorrectRequestValue.build(ErrorCodeEnum.VALIDATE_FAILED.name());
}
}
} else {
var record = clientCustomerServiceRpcClient.getClientCustomerHospitalRecordsByCustomerId(customer.getEnterpriseId(), customer.getId());
if (!record.hasResponse() || record.getResponse().getHospitalStatus() != ClientCustomerHospitalRecordHospitalStatusEnum.CURRENT) {
throw ClientEndExceptions.IncorrectRequestValue.build(ErrorCodeEnum.VALIDATE_FAILED.name());
}
StpUtil.login(
customer.getId(),
SaLoginModel.create()
}
final var wxUserOpenIdDto = wxMiniProgramHttpClient.getUserOpenIdByCode(loginDto.getOpenCode());
StpUtil.login(customer.getId(), SaLoginModel.create()
.setExtra(CommonConstants.ENTERPRISE_ID, customer.getEnterpriseId())
.setExtra(CommonConstants.LOGIN_SOURCE, loginDto.getLoginSourceEnum().getValue())
.setExtra(CommonConstants.OPEN_ID, wxUserOpenIdDto.getOpenid())
.build());
return StpUtil.getTokenInfo();
} else if (loginDto.isShouldLoginWithOperatorPhone()) {
final var operator =
operatorServiceRpcClient.getCOperatorByMobileOrEmail(loginDto.getOperatorPhone());
final var operator = operatorServiceRpcClient.getCOperatorByMobileOrEmail(loginDto.getOperatorPhone());
if (operator.getId() == 0) {
throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.UNAUTHORIZED.name());
}
StpUtil.login(
operator.getId(),
SaLoginModel.create()
if (!operator.getPassword().equals(sha1Hash(loginDto.getPassword()))) {
throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.VALIDATE_FAILED.name());
}
StpUtil.login(operator.getId(), SaLoginModel.create()
.setExtra(CommonConstants.ENTERPRISE_ID, operator.getEnterpriseId())
.setExtra(CommonConstants.LOGIN_SOURCE, loginDto.getLoginSourceEnum().getValue())
.build());
return StpUtil.getTokenInfo();
} else {
final var operator =
wOperatorServiceRpcClient.getWOperatorByEmail(loginDto.getEmail()).getResponse();
final var operator = wOperatorServiceRpcClient.getWOperatorByEmail(loginDto.getEmail()).getResponse();
if (operator.getId() == 0) {
throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.UNAUTHORIZED.name());
}
// if (!operator.getPassword().equals(loginDto.getPassword())) {
// throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.VALIDATE_FAILED.name());
// }
StpUtil.login(
operator.getId(),
SaLoginModel.create()
if (!operator.getPassword().equals(sha1Hash(loginDto.getPassword()))) {
throw ClientEndExceptions.AuthenticationFailure.build(ErrorCodeEnum.VALIDATE_FAILED.name());
}
StpUtil.login(operator.getId(), SaLoginModel.create()
.setExtra(CommonConstants.ENTERPRISE_ID, operator.getEnterpriseId())
.setExtra(CommonConstants.LOGIN_SOURCE, loginDto.getLoginSourceEnum().getValue())
.build());
return StpUtil.getTokenInfo();
}
}
public static String sha1Hash(String input) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.update(input.getBytes());
byte[] digest = md.digest();
return bytesToHex(digest);
}
private static String bytesToHex(byte[] bytes) {
StringBuilder sb = new StringBuilder();
for (byte b : bytes) {
sb.append(String.format("%02x", b));
}
return sb.toString();
}
}
......
......@@ -92,8 +92,8 @@ public class OrderServiceImpl implements OrderService {
final var record = clientCustomerServiceRpcClient.getClientCustomerHospitalRecordsByCustomerId(customer.getEnterpriseId(), customer.getId()).getResponse();
CreateOrderDto createOrderDto = new CreateOrderDto();
createOrderDto.setShouldCreateCustomerId(true);
createOrderDto.setShouldCreateOpenId(false);
createOrderDto.setOpenId("");
createOrderDto.setShouldCreateOpenId(true);
createOrderDto.setOpenId(operatorLoginInfo.getOpenId());
createOrderDto.setTableCode(operatorCreateOrderDto.getTableCode());
createOrderDto.setCustomerId(operatorCreateOrderDto.getCustomerId());
createOrderDto.setStallId(operatorCreateOrderDto.getStallId());
......@@ -156,13 +156,11 @@ public class OrderServiceImpl implements OrderService {
.doctors(Stream.of(doctors, dietDoctors).flatMap(List::stream).collect(Collectors.toList()))
.build();
createOrderDto.setCustomerNoticeJson(customerNotice);
createOrderDto.setUpdatedBy(operatorLoginInfo.getId());
createOrderDto.setUpdateSource(OrderSourceEnum.STALL.getNumber());
List<CreateOrderDetailDto> orderDetailDtoList = new ArrayList<>();
final var menuDetails = menuServiceRpcClient.queryMenuDetailsByMenuId(menu.getEnterpriseId(), operatorCreateOrderDto.getMenuId()).getResponsesList();
final var skuIds =
menuDetails.stream()
final var skuIds = menuDetails.stream()
.map(SingleMenuDetailRpcResponse::getSkuId)
.collect(Collectors.toList());
final var rpcSkus = skuServiceRpcClient.getDishSkusByIds(skuIds).getResponseList();
......
......@@ -75,7 +75,8 @@ miniprogram.appSecret=5b309517bf918abf760b2195e91b99f3
business-config.hisCustomerQueryUrl = https://nutri.amcare.com.cn/v3/hiscustomers/current/query
business-config.clientCustomerQueryUrl = https://nutri.amcare.com.cn/v3/clientcustomers/current/query
business-config.payUrl = http://10.2.5.162:21051/API/Microapp/CreateOrder?appid=Order0001
business-config.payUrl = http://10.2.5.162:21051/API/Microapp/CreateOrder?appid={0}
business-config.payClientId = Order
##Actuator\u914D\u7F6E
management.server.port=8088
......