Преглед изворни кода

add merchant name of white user

huodongdong пре 6 година
родитељ
комит
8bb7d1122a

+ 1 - 2
rankin-cms-web/src/main/java/cn/rankin/cmsweb/controller/user/WhiteUserController.java

@@ -8,7 +8,6 @@ import cn.rankin.common.utils.api.model.APIResult;
 import cn.rankin.common.utils.api.page.Page;
 import cn.rankin.data.api.user.dto.WhiteUserDTO;
 import cn.rankin.data.api.user.dto.WhiteUserSearchDTO;
-import cn.rankin.data.api.user.entity.WhiteUser;
 import cn.rankin.data.api.user.vo.WhiteUserVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.propertyeditors.CustomDateEditor;
@@ -63,7 +62,7 @@ public class WhiteUserController {
     }
 
     @RequestMapping(value = "/list", method = RequestMethod.GET)
-    public APIResult<Page<WhiteUser>> search(WhiteUserSearchDTO searchDTO) {
+    public APIResult<Page<WhiteUserVo>> search(WhiteUserSearchDTO searchDTO) {
         return whiteUserService.search(searchDTO);
     }
 }

+ 2 - 3
rankin-cms-web/src/main/java/cn/rankin/cmsweb/service/user/WhiteUserService.java

@@ -4,7 +4,6 @@ import cn.rankin.common.utils.api.model.APIResult;
 import cn.rankin.common.utils.api.page.Page;
 import cn.rankin.data.api.user.dto.WhiteUserDTO;
 import cn.rankin.data.api.user.dto.WhiteUserSearchDTO;
-import cn.rankin.data.api.user.entity.WhiteUser;
 import cn.rankin.data.api.user.vo.WhiteUserVo;
 import org.springframework.cloud.netflix.feign.FeignClient;
 import org.springframework.web.bind.annotation.*;
@@ -13,7 +12,7 @@ import org.springframework.web.bind.annotation.*;
 public interface WhiteUserService {
 
     @RequestMapping(value = "/white/user/{userId}", method = RequestMethod.GET)
-    APIResult<WhiteUserVo> findUserByUserId(@PathVariable String userId);
+    APIResult<WhiteUserVo> findUserByUserId(@PathVariable("userId") String userId);
 
     @RequestMapping(value = "/white/user", method = RequestMethod.POST)
     APIResult<WhiteUserVo> addWhiteUser(@RequestBody WhiteUserDTO whiteUserDTO);
@@ -25,6 +24,6 @@ public interface WhiteUserService {
     APIResult<Boolean> deleteWhiteUser(@RequestBody WhiteUserDTO whiteUserDTO);
 
     @RequestMapping(value = "/white/user/list", method = RequestMethod.POST)
-    APIResult<Page<WhiteUser>> search(@RequestBody WhiteUserSearchDTO searchDTO);
+    APIResult<Page<WhiteUserVo>> search(@RequestBody WhiteUserSearchDTO searchDTO);
 
 }

+ 2 - 0
rankin-data-api/src/main/java/cn/rankin/data/api/user/dto/WhiteUserDTO.java

@@ -15,6 +15,8 @@ public class WhiteUserDTO implements Serializable{
 
     private String userId;
 
+    private String merchantId;
+
     private Date startTime;
 
     private Date endTime;

+ 6 - 0
rankin-data-api/src/main/java/cn/rankin/data/api/user/entity/WhiteUser.java

@@ -24,6 +24,9 @@ public class WhiteUser implements Serializable {
     @Column(name = "user_id", nullable = false, unique = true)
     private String userId;
 
+    @Column(name = "merchant_id", nullable = false)
+    private String merchantId;
+
     @Column(name = "start_time", nullable = false, columnDefinition = "timestamp NULL DEFAULT CURRENT_TIMESTAMP")
     private Date startTime;
 
@@ -45,4 +48,7 @@ public class WhiteUser implements Serializable {
     @Transient
     private String code;
 
+    @Transient
+    private String merchantName;
+
 }

+ 4 - 0
rankin-data-api/src/main/java/cn/rankin/data/api/user/vo/WhiteUserVo.java

@@ -15,6 +15,8 @@ public class WhiteUserVo implements Serializable {
 
     private String userId;
 
+    private String merchantId;
+
     private Date startTime;
 
     private Date endTime;
@@ -26,4 +28,6 @@ public class WhiteUserVo implements Serializable {
     private Date gmtModified;
 
     private String code;
+
+    private String merchantName;
 }

+ 34 - 5
rankin-user-service/src/main/java/cn/rankin/userservice/controller/WhiteUserController.java

@@ -6,9 +6,11 @@ import cn.rankin.common.utils.enums.BaseOrderEnum;
 import cn.rankin.common.utils.util.ListUtil;
 import cn.rankin.data.api.user.dto.WhiteUserDTO;
 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.WhiteUser;
 import cn.rankin.userservice.code.UserServiceAPICode;
+import cn.rankin.userservice.service.MerchantService;
 import cn.rankin.userservice.service.TerminalUserService;
 import cn.rankin.userservice.service.WhiteUserService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -16,16 +18,16 @@ import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 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
 @RequestMapping(value = "/white/user")
 public class WhiteUserController {
 
     @Autowired
+    private MerchantService merchantService;
+
+    @Autowired
     private TerminalUserService terminalUserService;
 
     @Autowired
@@ -43,6 +45,13 @@ public class WhiteUserController {
 
     @RequestMapping(method = RequestMethod.POST)
     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);
         if (whiteUser != null) {
             return APIResult.ok(whiteUser);
@@ -94,25 +103,45 @@ public class WhiteUserController {
         }
         String userId = whiteUser.getUserId();
         TerminalUser terminalUser = terminalUserService.find(userId);
+        Merchant merchant = merchantService.findOne(whiteUser.getMerchantId());
         if (terminalUser != null) {
             whiteUser.setCode(terminalUser.getCode());
         }
+        if (merchant != null) {
+            whiteUser.setMerchantName(merchant.getName());
+        }
     }
 
     public void setUserInfo(List<WhiteUser> whiteUserList) {
         if (CollectionUtils.isEmpty(whiteUserList)) {
             return;
         }
+
         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);
         Map<String, TerminalUser> terminalUserMap = ListUtil.convert(terminalUserList, "id", TerminalUser.class);
+        Map<String, Merchant> merchantMap = merchantService.getMerchantMap(merchantIdList);
+
         for (WhiteUser whiteUser : whiteUserList) {
             String userId = whiteUser.getUserId();
             TerminalUser terminalUser = terminalUserMap.get(userId);
             if (terminalUser != null) {
                 whiteUser.setCode(terminalUser.getCode());
             }
+            String merchantId = whiteUser.getMerchantId();
+            Merchant merchant = merchantMap.get(merchantId);
+            if (merchant != null) {
+                whiteUser.setMerchantName(merchant.getName());
+            }
         }
     }
 }

+ 0 - 1
rankin-user-service/src/main/java/cn/rankin/userservice/service/MerchantService.java

@@ -16,7 +16,6 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
 import javax.transaction.Transactional;
-import java.math.BigDecimal;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;