licailing il y a 5 ans
Parent
commit
404d9acafd

+ 4 - 0
src/main/java/com/izouma/dingdong/domain/User.java

@@ -97,4 +97,8 @@ public class User extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "余额", name = "money")
     private BigDecimal money;
 
+    //默认用户名
+    public String getDefaultUsername(String phone) {
+        return phone.replace(phone.substring(3, 7), "****");
+    }
 }

+ 3 - 0
src/main/java/com/izouma/dingdong/repo/merchant/MerchantClassificationRepo.java

@@ -12,6 +12,9 @@ import java.util.List;
 public interface MerchantClassificationRepo extends JpaRepository<MerchantClassification, Long>, JpaSpecificationExecutor<MerchantClassification> {
     List<MerchantClassification> findAllByMerchantId(Long merchantId);
 
+    //用户端显示商户下开启和显示的分类
+    List<MerchantClassification> findAllByMerchantIdAndIsShowTrueAndIsOpenTrue(Long merchantId);
+
     //List<MerchantClassification> findAllByUserId(Long userId);
 
     MerchantClassification findByMerchantIdAndName(Long merchantId, String Name);

+ 1 - 1
src/main/java/com/izouma/dingdong/service/UserService.java

@@ -55,7 +55,7 @@ public class UserService {
             }
             user = User.builder()
                     .username(phone)
-                    .nickname(UUID.randomUUID().toString())
+                    .nickname(user.getDefaultUsername(phone))
                     .blacklist(false)
                     .enabled(true)
                     .phone(phone)

+ 1 - 0
src/main/java/com/izouma/dingdong/service/merchant/MerchantClassificationService.java

@@ -40,6 +40,7 @@ public class MerchantClassificationService {
                 .name(classification.getName())
                 .goodsIds(classification.getGoodsIds())
                 .sort(classification.getSort())
+                .isShow(true)
                 .enabled(true)
                 .type(4)
                 .build();

+ 1 - 1
src/main/java/com/izouma/dingdong/service/merchant/MerchantSettingsService.java

@@ -262,7 +262,7 @@ public class MerchantSettingsService {
         //带距离 且按距离排好序
         List<MerchantDTO> dtos = merchantService.withDistance(merchantList, longitude, latitude, null);
 
-        if (ObjectUtil.isNotNull(sort)) {
+        if (ObjectUtil.isNotEmpty(sort)) {
             switch (sort) {
                 case 1:
                     //好评

+ 23 - 8
src/main/java/com/izouma/dingdong/web/merchant/MerchantClassificationController.java

@@ -31,8 +31,8 @@ import java.util.List;
 @AllArgsConstructor
 public class MerchantClassificationController extends BaseController {
     private MerchantClassificationService merchantClassificationService;
-    private MerchantClassificationRepo merchantClassificationRepo;
-    private MerchantService merchantService;
+    private MerchantClassificationRepo    merchantClassificationRepo;
+    private MerchantService               merchantService;
 
     //@PreAuthorize("hasRole('ADMIN')")
     @PostMapping("/save")
@@ -40,9 +40,11 @@ public class MerchantClassificationController extends BaseController {
     public MerchantClassification save(@RequestBody MerchantClassification record) {
         //修改
         if (record.getId() != null) {
-            MerchantClassification orig = merchantClassificationRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
+            MerchantClassification orig = merchantClassificationRepo.findById(record.getId())
+                    .orElseThrow(new BusinessException("无记录"));
             ObjUtils.merge(orig, record);
-            MerchantClassification byName = merchantClassificationRepo.findByMerchantIdAndName(orig.getMerchantId(), orig.getName());
+            MerchantClassification byName = merchantClassificationRepo.findByMerchantIdAndName(orig.getMerchantId(), orig
+                    .getName());
             if (ObjectUtil.isNotNull(byName)) {
                 if (!byName.getId().equals(orig.getId())) {
                     throw new BusinessException("该分类已存在");
@@ -50,9 +52,9 @@ public class MerchantClassificationController extends BaseController {
             }
             return merchantClassificationRepo.save(orig);
         }
-        MerchantClassification add = merchantClassificationService.add(SecurityUtils.getAuthenticatedUser().getId(), record);
         //添加
-        return add;
+        return merchantClassificationService.add(SecurityUtils.getAuthenticatedUser()
+                .getId(), record);
         //return merchantClassificationRepo.save(record);
     }
 
@@ -70,7 +72,8 @@ public class MerchantClassificationController extends BaseController {
 
     @PostMapping("/del/{id}")
     public void del(@PathVariable Long id) {
-        MerchantClassification classification = merchantClassificationRepo.findById(id).orElseThrow(new BusinessException("无分类"));
+        MerchantClassification classification = merchantClassificationRepo.findById(id)
+                .orElseThrow(new BusinessException("无分类"));
         if (StrUtil.isNotBlank(classification.getGoodsIds())) {
             throw new BusinessException("该分类下有商品,暂无法删除");
         }
@@ -87,7 +90,10 @@ public class MerchantClassificationController extends BaseController {
     @GetMapping("/my")
     @ApiOperation("商户下的分类名称")
     public List<MerchantClassification> my() {
-        List<MerchantClassification> merchantClassifications = merchantClassificationRepo.findAllByMerchantId(merchantService.findMerchantId(SecurityUtils.getAuthenticatedUser().getId()));
+        List<MerchantClassification> merchantClassifications
+                = merchantClassificationRepo
+                .findAllByMerchantId(merchantService.findMerchantId(SecurityUtils.getAuthenticatedUser()
+                        .getId()));
         merchantClassifications.sort(Comparator.comparing(MerchantClassification::getSort));
         return merchantClassifications;
     }
@@ -116,5 +122,14 @@ public class MerchantClassificationController extends BaseController {
         return merchantClassificationService.showGoods(classificationId);
     }
 
+    @GetMapping("/list")
+    @ApiOperation("商户下的分类列表")
+    public List<MerchantClassification> list(Long merchantId) {
+        List<MerchantClassification> merchantClassifications
+                = merchantClassificationRepo.findAllByMerchantIdAndIsShowTrueAndIsOpenTrue(merchantId);
+        merchantClassifications.sort(Comparator.comparing(MerchantClassification::getSort));
+        return merchantClassifications;
+    }
+
 }
 

+ 3 - 6
src/test/java/com/izouma/dingdong/contorller/OrderInfoControllerTest.java

@@ -31,15 +31,11 @@ public class OrderInfoControllerTest {
     @Autowired
     private AuthenticationController auth;
     @Autowired
-    private CategoryController categoryController;
-    @Autowired
     private GoodsController goodsController;
     @Autowired
     private MerchantRepo merchantRepo;
     @Autowired
     private OrderInfoService orderInfoService;
-    @Autowired
-    private MerchantNatureRepo merchantNatureRepo;
 
     //商家注册
     @Test
@@ -112,9 +108,9 @@ public class OrderInfoControllerTest {
     @Test
     public void testBuy(){
         UserOrderDTO dto = UserOrderDTO.builder()
-                .addressId(135L)
+                .addressId(1889L)
                 .payMethod(PayMethod.ALI_PAY)
-                .shoppingCartId(1704L)
+                .shoppingCartId(1985L)
                 //.remark("多加点!")
                 //.userCouponId(217L)
                 .build();
@@ -126,4 +122,5 @@ public class OrderInfoControllerTest {
     public void testMer(){
         orderInfoService.merReceiveOrder(1352L,true);
     }
+
 }

+ 6 - 0
src/test/java/com/izouma/dingdong/repo/UserRepoTest.java

@@ -44,4 +44,10 @@ public class UserRepoTest {
         List<User> list = userRepo.findAllByAuthoritiesNotContains(Authority.builder().name("ROLE_ADMIN").build());
         System.out.println(list);
     }
+
+    @Test
+    public void testUsername(){
+        String p ="18012345678";
+        System.out.println(p.replace(p.substring(3, 7), "****"));
+    }
 }

+ 9 - 2
src/test/java/com/izouma/dingdong/service/MerchantServiceTest.java

@@ -3,6 +3,7 @@ package com.izouma.dingdong.service;
 import com.izouma.dingdong.domain.merchant.MerchantSettings;
 import com.izouma.dingdong.dto.MerchantDTO;
 import com.izouma.dingdong.dto.PageQuery;
+import com.izouma.dingdong.exception.BusinessException;
 import com.izouma.dingdong.repo.merchant.MerchantSettingsRepo;
 import com.izouma.dingdong.service.merchant.MerchantService;
 import com.izouma.dingdong.service.merchant.MerchantSettingsService;
@@ -40,7 +41,7 @@ public class MerchantServiceTest {
                 .mid(189L)
                 .automaticOrder(true)
                 .build();
-        merchantService.change(merchantDTO);
+        System.out.println(merchantService.change(merchantDTO).getAutomaticOrder());
     }
 
     @Test
@@ -163,7 +164,7 @@ public class MerchantServiceTest {
 
     @Test
     public void testWeek() {
-        MerchantSettings settings = merchantSettingsRepo.findById(306L).orElse(null);
+        MerchantSettings settings = merchantSettingsRepo.findById(306L).orElseThrow(new BusinessException("无商家"));
         //  System.out.println(settings);
         System.out.println(settings.getWeek().contains(LocalDateTime.now().getDayOfWeek().toString()));
 
@@ -174,4 +175,10 @@ public class MerchantServiceTest {
     public void test5() {
         System.out.println(merchantSettingsService.recommended(1.0, 1.0, null, null, null, null, null, null, 82L).size());
     }
+
+    @Test
+    public void test6(){
+        System.out.println(merchantSettingsRepo.findById(190L).orElseThrow(new BusinessException("无商家")).getAutomaticOrder());
+    }
+
 }