From 262cdc113a44bbd51f98a56ce91966dc7b2ea938 Mon Sep 17 00:00:00 2001
From: puhanshu <a9236326>
Date: 星期六, 08 一月 2022 17:55:25 +0800
Subject: [PATCH] 数字商业街代码提交

---
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/McsMerchantServiceImpl.java |   99 +++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 86 insertions(+), 13 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/McsMerchantServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/McsMerchantServiceImpl.java
index 318e000..145ea24 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/McsMerchantServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/McsMerchantServiceImpl.java
@@ -3,19 +3,25 @@
 import static java.util.Objects.isNull;
 import static java.util.Objects.nonNull;
 import static org.apache.commons.lang3.StringUtils.isBlank;
+import static org.apache.commons.lang3.StringUtils.isNotEmpty;
 
 import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
+import java.util.Random;
+import java.util.UUID;
 
 import javax.annotation.Resource;
-import javax.validation.constraints.NotBlank;
-import javax.validation.constraints.Pattern;
 
 import com.panzhihua.common.model.dtos.community.microCommercialStreet.LoginWithPhoneDTO;
+import com.panzhihua.common.model.dtos.community.microCommercialStreet.PutUserInfoDTO;
+import com.panzhihua.common.model.vos.community.microCommercialStreet.IndexTopStatisticsVO;
+import com.panzhihua.common.model.vos.community.microCommercialStreet.McsGameVO;
+import com.panzhihua.common.model.vos.community.microCommercialStreet.McsLoginUserInfoVO;
+import com.panzhihua.service_community.util.NearbyUtil;
+import com.spatial4j.core.shape.Rectangle;
 import org.springframework.beans.BeanUtils;
 import org.springframework.data.redis.core.StringRedisTemplate;
-import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -51,6 +57,7 @@
 public class McsMerchantServiceImpl extends ServiceImpl<McsMerchantDAO, McsMerchant> implements McsMerchantService {
 
     private static final String MERCHANT_PUBLISH_LIMIT_KEY = "MERCHANT_PUBLISH_LIMIT";
+    private static final String DEFAULT_IMAGE_URL = "https://www.psciio.com//idcard/91313573d071436ab1f934231b31c6e5.jpg";
     private static final int DEFAULT_PUBLISH_LIMIT = 2;
 
     @Resource
@@ -72,14 +79,9 @@
     public R addMcsMerchant(McsMerchantDTO mcsMerchantDTO) {
         McsMerchant mcsMerchant = new McsMerchant();
         BeanUtils.copyProperties(mcsMerchantDTO, mcsMerchant);
-        if (mcsMerchantDTO.getLevel().equals(1)) {
-            Integer litDays = mcsMerchantDTO.getLitDays();
-            if (isNull(litDays)) {
-                return R.fail("临时商家未设置点亮天数");
-            }
-            mcsMerchant.setExpireAt(DateUtils.addDay(new Date(), litDays));
-            mcsMerchant.setFirstLitAt(new Date());
-        }
+        Integer litDays = mcsMerchantDTO.getLitDays();
+        mcsMerchant.setExpireAt(DateUtils.addDay(new Date(), litDays));
+        mcsMerchant.setFirstLitAt(new Date());
         McsConfig publishLimitConfig = mcsConfigDAO.selectOne(new QueryWrapper<McsConfig>().lambda().eq(McsConfig::getKey, MERCHANT_PUBLISH_LIMIT_KEY));
         mcsMerchant.setPublishLimit(nonNull(publishLimitConfig) ? Integer.parseInt(publishLimitConfig.getValue()) : DEFAULT_PUBLISH_LIMIT);
         mcsMerchant.setUserId(0L);
@@ -301,7 +303,7 @@
             if (R.isOk(r)) {
                 if (nonNull(r.getData())) {
                     //已有用户
-                    LoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(JSONObject.toJSONString(r.getData()), LoginUserInfoVO.class);
+                    McsLoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(JSONObject.toJSONString(r.getData()), McsLoginUserInfoVO.class);
                     stringRedisTemplate.delete(redisKey);
                     return R.ok(loginUserInfoVO);
                 } else {
@@ -311,9 +313,12 @@
                     mcsMerchantDTO.setPassword("88888888");
                     mcsMerchantDTO.setAccountStatus(1);
                     mcsMerchantDTO.setPhone(phone);
+                    mcsMerchantDTO.setName("用户" + retrieveRandomCode(5));
+                    mcsMerchantDTO.setImageUrl(DEFAULT_IMAGE_URL);
                     R addUserResult = userService.addMcsMerchantUser(mcsMerchantDTO);
                     if (R.isOk(addUserResult)) {
-                        LoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(JSONObject.toJSONString(addUserResult.getData()), LoginUserInfoVO.class);
+                        McsLoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(JSONObject.toJSONString(addUserResult.getData()), McsLoginUserInfoVO.class);
+                        loginUserInfoVO.setPlaintextPassword("88888888");
                         stringRedisTemplate.delete(redisKey);
                         return R.ok(loginUserInfoVO);
                     }
@@ -326,6 +331,65 @@
         }
     }
 
+    /**
+     * 首页顶部数据
+     * @return
+     */
+    @Override
+    public R getMcsIndexTopData() {
+        IndexTopStatisticsVO statisticsVO = this.baseMapper.getMcsIndexTopData();
+        McsGameVO mcsGameVO = mcsGameDAO.selectPopularGame();
+        statisticsVO.setPopularGame(mcsGameVO);
+        return R.ok(statisticsVO);
+    }
+
+    /**
+     * H5分页查询数字商业街商家
+     * @param pageMcsMerchantDTO
+     * @return
+     */
+    @Override
+    public R pageH5McsMerchant(PageMcsMerchantDTO pageMcsMerchantDTO) {
+        Page page = new Page<>();
+        page.setSize(pageMcsMerchantDTO.getPageSize());
+        page.setCurrent(pageMcsMerchantDTO.getPageNum());
+        String lat = pageMcsMerchantDTO.getLat();
+        String lon = pageMcsMerchantDTO.getLon();
+        Integer distance = pageMcsMerchantDTO.getDistance();
+        IPage<McsMerchantVO> mcsMerchants;
+        if (isNotEmpty(lat) && isNotEmpty(lon) && nonNull(distance)) {
+            Rectangle rectangle = new NearbyUtil().getRectangle(distance, Double.parseDouble(lon), Double.parseDouble(lat));
+            mcsMerchants = this.baseMapper.pageH5McsMerchant(page, rectangle.getMinX(), rectangle.getMaxX(),
+                    rectangle.getMinY(), rectangle.getMaxY(), pageMcsMerchantDTO);
+        } else {
+            mcsMerchants = this.baseMapper.pageH5McsMerchant(page, null, null, null, null, pageMcsMerchantDTO);
+        }
+        return R.ok(mcsMerchants);
+    }
+
+    /**
+     * 修改用戶信息
+     * @param putUserInfoDTO
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public R putUserInfo(PutUserInfoDTO putUserInfoDTO) {
+        McsMerchant mcsMerchant = this.baseMapper.selectOne(new QueryWrapper<McsMerchant>().lambda().eq(McsMerchant::getUserId, putUserInfoDTO.getUserId()));
+        if (nonNull(mcsMerchant)) {
+            //修改商家名称
+            mcsMerchant.setLogo(putUserInfoDTO.getImageUrl());
+            mcsMerchant.setName(putUserInfoDTO.getName());
+            this.baseMapper.updateById(mcsMerchant);
+        }
+        LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO();
+        loginUserInfoVO.setImageUrl(putUserInfoDTO.getImageUrl());
+        loginUserInfoVO.setName(putUserInfoDTO.getName());
+        loginUserInfoVO.setUserId(putUserInfoDTO.getUserId());
+        userService.putUser(loginUserInfoVO);
+        return R.ok();
+    }
+
     private void retrieveMerchantSurplusLitDays(McsMerchantVO merchantVO) {
         Integer publishLimit = merchantVO.getPublishLimit();
         Integer publishCount = mcsGameDAO.selectPublishCount(merchantVO.getId());
@@ -336,4 +400,13 @@
             merchantVO.setSurplusLitDays(surplusLitDays > 0 ? surplusLitDays : 0);
         }
     }
+
+    private String retrieveRandomCode(int length) {
+        Random r = new Random();
+        StringBuilder rs = new StringBuilder();
+        for (int i = 0; i < length; i++) {
+            rs.append(r.nextInt(10));
+        }
+        return rs.toString();
+    }
 }

--
Gitblit v1.7.1