|
@@ -6,9 +6,11 @@ import cn.rankin.common.utils.enums.BaseOrderEnum;
|
|
import cn.rankin.common.utils.util.ListUtil;
|
|
import cn.rankin.common.utils.util.ListUtil;
|
|
import cn.rankin.data.api.user.dto.WhiteUserDTO;
|
|
import cn.rankin.data.api.user.dto.WhiteUserDTO;
|
|
import cn.rankin.data.api.user.dto.WhiteUserSearchDTO;
|
|
import cn.rankin.data.api.user.dto.WhiteUserSearchDTO;
|
|
|
|
+import cn.rankin.data.api.user.entity.Merchant;
|
|
import cn.rankin.data.api.user.entity.TerminalUser;
|
|
import cn.rankin.data.api.user.entity.TerminalUser;
|
|
import cn.rankin.data.api.user.entity.WhiteUser;
|
|
import cn.rankin.data.api.user.entity.WhiteUser;
|
|
import cn.rankin.userservice.code.UserServiceAPICode;
|
|
import cn.rankin.userservice.code.UserServiceAPICode;
|
|
|
|
+import cn.rankin.userservice.service.MerchantService;
|
|
import cn.rankin.userservice.service.TerminalUserService;
|
|
import cn.rankin.userservice.service.TerminalUserService;
|
|
import cn.rankin.userservice.service.WhiteUserService;
|
|
import cn.rankin.userservice.service.WhiteUserService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -16,16 +18,16 @@ import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.LinkedHashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping(value = "/white/user")
|
|
@RequestMapping(value = "/white/user")
|
|
public class WhiteUserController {
|
|
public class WhiteUserController {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
|
+ private MerchantService merchantService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
private TerminalUserService terminalUserService;
|
|
private TerminalUserService terminalUserService;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -43,6 +45,13 @@ public class WhiteUserController {
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.POST)
|
|
@RequestMapping(method = RequestMethod.POST)
|
|
public APIResult<WhiteUser> create(@RequestBody WhiteUserDTO whiteUserDTO) {
|
|
public APIResult<WhiteUser> create(@RequestBody WhiteUserDTO whiteUserDTO) {
|
|
|
|
+ String userId = whiteUserDTO.getUserId();
|
|
|
|
+ TerminalUser terminalUser = terminalUserService.find(userId);
|
|
|
|
+ if (terminalUser == null) {
|
|
|
|
+ return APIResult.error(UserServiceAPICode.NOT_EXISTS);
|
|
|
|
+ }
|
|
|
|
+ whiteUserDTO.setMerchantId(terminalUser.getMerchantId());
|
|
|
|
+
|
|
WhiteUser whiteUser = whiteUserService.addUser(whiteUserDTO);
|
|
WhiteUser whiteUser = whiteUserService.addUser(whiteUserDTO);
|
|
if (whiteUser != null) {
|
|
if (whiteUser != null) {
|
|
return APIResult.ok(whiteUser);
|
|
return APIResult.ok(whiteUser);
|
|
@@ -94,25 +103,45 @@ public class WhiteUserController {
|
|
}
|
|
}
|
|
String userId = whiteUser.getUserId();
|
|
String userId = whiteUser.getUserId();
|
|
TerminalUser terminalUser = terminalUserService.find(userId);
|
|
TerminalUser terminalUser = terminalUserService.find(userId);
|
|
|
|
+ Merchant merchant = merchantService.findOne(whiteUser.getMerchantId());
|
|
if (terminalUser != null) {
|
|
if (terminalUser != null) {
|
|
whiteUser.setCode(terminalUser.getCode());
|
|
whiteUser.setCode(terminalUser.getCode());
|
|
}
|
|
}
|
|
|
|
+ if (merchant != null) {
|
|
|
|
+ whiteUser.setMerchantName(merchant.getName());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
public void setUserInfo(List<WhiteUser> whiteUserList) {
|
|
public void setUserInfo(List<WhiteUser> whiteUserList) {
|
|
if (CollectionUtils.isEmpty(whiteUserList)) {
|
|
if (CollectionUtils.isEmpty(whiteUserList)) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+
|
|
List<String> userIdList = new ArrayList<>();
|
|
List<String> userIdList = new ArrayList<>();
|
|
- whiteUserList.forEach(whiteUser -> userIdList.add(whiteUser.getUserId()));
|
|
|
|
|
|
+ List<String> merchantIdList = new ArrayList<>();
|
|
|
|
+ for (WhiteUser whiteUser : whiteUserList) {
|
|
|
|
+ userIdList.add(whiteUser.getUserId());
|
|
|
|
+ String merchantId = whiteUser.getMerchantId();
|
|
|
|
+ if (merchantIdList.contains(merchantId)) {
|
|
|
|
+ merchantIdList.add(merchantId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
List<TerminalUser> terminalUserList = terminalUserService.findByIds(userIdList);
|
|
List<TerminalUser> terminalUserList = terminalUserService.findByIds(userIdList);
|
|
Map<String, TerminalUser> terminalUserMap = ListUtil.convert(terminalUserList, "id", TerminalUser.class);
|
|
Map<String, TerminalUser> terminalUserMap = ListUtil.convert(terminalUserList, "id", TerminalUser.class);
|
|
|
|
+ Map<String, Merchant> merchantMap = merchantService.getMerchantMap(merchantIdList);
|
|
|
|
+
|
|
for (WhiteUser whiteUser : whiteUserList) {
|
|
for (WhiteUser whiteUser : whiteUserList) {
|
|
String userId = whiteUser.getUserId();
|
|
String userId = whiteUser.getUserId();
|
|
TerminalUser terminalUser = terminalUserMap.get(userId);
|
|
TerminalUser terminalUser = terminalUserMap.get(userId);
|
|
if (terminalUser != null) {
|
|
if (terminalUser != null) {
|
|
whiteUser.setCode(terminalUser.getCode());
|
|
whiteUser.setCode(terminalUser.getCode());
|
|
}
|
|
}
|
|
|
|
+ String merchantId = whiteUser.getMerchantId();
|
|
|
|
+ Merchant merchant = merchantMap.get(merchantId);
|
|
|
|
+ if (merchant != null) {
|
|
|
|
+ whiteUser.setMerchantName(merchant.getName());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|