|
@@ -18,11 +18,13 @@ import cn.rankin.data.api.user.vo.TerminalDeviceVo;
|
|
|
import cn.rankin.data.api.user.vo.TerminalUserVo;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
@@ -52,6 +54,7 @@ public class UserService {
|
|
|
|
|
|
public APIResult<UserInfoVo> login(LoginInfoDTO loginInfoDTO) {
|
|
|
String deviceCode = loginInfoDTO.getDeviceCode();
|
|
|
+ String merchant = loginInfoDTO.getMerchant();
|
|
|
String eid = loginInfoDTO.getEid();
|
|
|
String loginPassword = loginInfoDTO.getPassword();
|
|
|
log.info("user login start, user={}", JSON.toJSONString(loginInfoDTO));
|
|
@@ -63,12 +66,20 @@ public class UserService {
|
|
|
return APIResult.error(ApiWebCode.LOGIN_ERROR);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
String storePassword = userVo.getPassword();
|
|
|
if (!SecurityManager.validate(loginPassword, storePassword)) {
|
|
|
log.error("密码校验错误, loginPassword={}, storePassword={}", loginPassword, storePassword);
|
|
|
return APIResult.error(ApiWebCode.PASSWORD_ERROR);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+/* if(StringUtils.isNotBlank(merchant) && !merchant.equals(userVo.getMerchantSimple())){
|
|
|
+ log.error("渠道校验错误, requestMerchant={}, userMerchant={}", merchant, userVo.getMerchantSimple());
|
|
|
+ return APIResult.error(ApiWebCode.LOGIN_ERROR);
|
|
|
+ }*/
|
|
|
+
|
|
|
String userId = userVo.getId();
|
|
|
String ip = loginInfoDTO.getIp();
|
|
|
String terminal = loginInfoDTO.getTerminal();
|
|
@@ -90,7 +101,7 @@ public class UserService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- TerminalDeviceVo deviceVo = this.bind(userId, deviceCode, ip, terminal);
|
|
|
+ TerminalDeviceVo deviceVo = this.bind(userId, deviceCode, merchant, ip, terminal);
|
|
|
if (deviceVo == null) {
|
|
|
return APIResult.error(ApiWebCode.DEVICE_BOUND_ERROR);
|
|
|
}
|
|
@@ -118,16 +129,17 @@ public class UserService {
|
|
|
return APIResult.ok();
|
|
|
}
|
|
|
|
|
|
- public TerminalDeviceVo bind(String userId, String deviceCode, String ip, String terminal) {
|
|
|
+ public TerminalDeviceVo bind(String userId, String deviceCode, String merchant, String ip, String terminal) {
|
|
|
TerminalDeviceDTO deviceDTO = new TerminalDeviceDTO();
|
|
|
deviceDTO.setUserId(userId);
|
|
|
deviceDTO.setDeviceCode(deviceCode);
|
|
|
+ deviceDTO.setMerchant(merchant);
|
|
|
deviceDTO.setIp(ip);
|
|
|
deviceDTO.setTerminal(terminal);
|
|
|
APIResult<TerminalDeviceVo> apiResult = userClient.deviceBind(deviceDTO);
|
|
|
if (!apiResult.getSuccess()) {
|
|
|
log.error("bind user api error");
|
|
|
- return null;
|
|
|
+ throw new RuntimeException(apiResult.getMessage());
|
|
|
}
|
|
|
return apiResult.getData();
|
|
|
}
|
|
@@ -168,19 +180,40 @@ public class UserService {
|
|
|
return toDeviceUserVo(userVo, deviceVo);
|
|
|
}
|
|
|
|
|
|
- public APIResult<UserInfoVo> refresh(String deviceCode, Boolean force) {
|
|
|
- APIResult<TerminalDeviceVo> deviceAPIResult = userClient.findByDeviceCode(deviceCode);
|
|
|
+ public APIResult<UserInfoVo> refresh(String deviceCode, String merchant, Boolean force) {
|
|
|
+
|
|
|
+ APIResult<List<TerminalDeviceVo>> deviceAPIResult = userClient.findByDeviceCode(deviceCode);
|
|
|
if (!deviceAPIResult.getSuccess()) {
|
|
|
log.error("load device api error, {}", deviceAPIResult.getMessage());
|
|
|
return APIResult.error(ApiWebCode.NOT_FOUND);
|
|
|
}
|
|
|
|
|
|
- TerminalDeviceVo deviceVo = deviceAPIResult.getData();
|
|
|
- if (deviceVo == null) {
|
|
|
+ List<TerminalDeviceVo> deviceVoList = deviceAPIResult.getData();
|
|
|
+ if (CollectionUtils.isEmpty(deviceVoList)) {
|
|
|
log.error("device code not bind any eid! deviceCode={}", deviceCode);
|
|
|
return APIResult.error(ApiWebCode.NOT_EXISTS);
|
|
|
}
|
|
|
|
|
|
+ TerminalDeviceVo deviceVo = null;
|
|
|
+
|
|
|
+ for (TerminalDeviceVo dv : deviceVoList) {
|
|
|
+ //判断当前鉴权账号
|
|
|
+ if(StringUtils.isBlank(dv.getMerchant())){
|
|
|
+ //如果设备渠道code为空,则设置为当前渠道code
|
|
|
+ dv.setMerchant(merchant);
|
|
|
+ //更新数据库
|
|
|
+ updateDeviceBind(dv);
|
|
|
+ deviceVo = dv;
|
|
|
+ }else if(StringUtils.isNotBlank(merchant) && merchant.equals(dv.getMerchant())) {
|
|
|
+ deviceVo = dv;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(null == deviceVo){
|
|
|
+ log.error("by device code not find this merchant! deviceCode={},merchant={}", deviceCode, merchant);
|
|
|
+ return APIResult.error(ApiWebCode.INVALID_TOKEN);
|
|
|
+ }
|
|
|
+
|
|
|
String uid = deviceVo.getUserId();
|
|
|
|
|
|
DeviceUserVo deviceUserVo;
|
|
@@ -209,6 +242,17 @@ public class UserService {
|
|
|
return APIResult.ok(userInfoVo);
|
|
|
}
|
|
|
|
|
|
+ private void updateDeviceBind(TerminalDeviceVo terminalDeviceVo) {
|
|
|
+ TerminalDeviceDTO deviceDTO = new TerminalDeviceDTO();
|
|
|
+ deviceDTO.setId(terminalDeviceVo.getId());
|
|
|
+ deviceDTO.setMerchant(terminalDeviceVo.getMerchant());
|
|
|
+ APIResult<TerminalDeviceVo> apiResult = userClient.updateDeviceBind(deviceDTO);
|
|
|
+ if (!apiResult.getSuccess()) {
|
|
|
+ log.error("update bind user api error");
|
|
|
+ throw new RuntimeException("update bind user api error");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// cache user and device info
|
|
|
public void save(DeviceUserVo deviceUserVo) {
|
|
|
String key = getUserFormatKey(deviceUserVo.getUid());
|