From b0027c86cdf6b9f537abceade8cd5315a278e67d Mon Sep 17 00:00:00 2001
From: manailin <261030956@qq.com>
Date: 星期日, 25 九月 2022 00:09:54 +0800
Subject: [PATCH] Merge remote-tracking branch 'remotes/origin/sanshuohuitang_dev' into huacheng_test
---
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/McsMerchantServiceImpl.java | 173 +++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 149 insertions(+), 24 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..7c20dff 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
@@ -7,15 +7,12 @@
import java.util.Arrays;
import java.util.Date;
import java.util.List;
+import java.util.Random;
import javax.annotation.Resource;
-import javax.validation.constraints.NotBlank;
-import javax.validation.constraints.Pattern;
-import com.panzhihua.common.model.dtos.community.microCommercialStreet.LoginWithPhoneDTO;
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;
@@ -27,18 +24,26 @@
import com.panzhihua.common.exceptions.ServiceException;
import com.panzhihua.common.model.dtos.community.convenient.DisableOrEnableConvenientMerchantDTO;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.DisableOrEnableMcsMerchantDTO;
+import com.panzhihua.common.model.dtos.community.microCommercialStreet.LoginWithPhoneDTO;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.McsMerchantDTO;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.PageMcsMerchantDTO;
+import com.panzhihua.common.model.dtos.community.microCommercialStreet.PutUserInfoDTO;
import com.panzhihua.common.model.vos.LoginUserInfoVO;
import com.panzhihua.common.model.vos.R;
+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.common.model.vos.community.microCommercialStreet.McsMerchantVO;
import com.panzhihua.common.service.user.UserService;
import com.panzhihua.common.utlis.DateUtils;
import com.panzhihua.service_community.dao.McsConfigDAO;
import com.panzhihua.service_community.dao.McsGameDAO;
+import com.panzhihua.service_community.dao.McsInformationDAO;
import com.panzhihua.service_community.dao.McsMerchantDAO;
+import com.panzhihua.service_community.dao.McsOrderDao;
import com.panzhihua.service_community.entity.McsConfig;
import com.panzhihua.service_community.entity.McsMerchant;
+import com.panzhihua.service_community.entity.McsOrder;
import com.panzhihua.service_community.service.McsMerchantService;
/**
@@ -51,7 +56,9 @@
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;
+ private static final String CUSTOMER_SERVICE_CONTACT_NUM="CUSTOMER_SERVICE_CONTACT_NUM";
@Resource
private UserService userService;
@@ -60,7 +67,11 @@
@Resource
private McsGameDAO mcsGameDAO;
@Resource
+ private McsInformationDAO mcsInformationDAO;
+ @Resource
private StringRedisTemplate stringRedisTemplate;
+ @Resource
+ private McsOrderDao mcsOrderDao;
/**
* 新增数字商业街商家
@@ -70,16 +81,19 @@
@Override
@Transactional(rollbackFor = Exception.class)
public R addMcsMerchant(McsMerchantDTO mcsMerchantDTO) {
+ McsMerchant existMerchant = this.baseMapper.selectOne(new QueryWrapper<McsMerchant>().lambda().eq(McsMerchant::getPhone, mcsMerchantDTO.getPhone()));
+ if (nonNull(existMerchant)) {
+ if (existMerchant.getIsDel()) {
+ this.baseMapper.deleteById(existMerchant.getId());
+ } else {
+ return R.fail("手机号已存在");
+ }
+ }
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);
@@ -159,7 +173,10 @@
return R.fail("商家不存在");
}
mcsMerchant.setIsDel(true);
- this.baseMapper.updateById(mcsMerchant);
+ int num = this.baseMapper.updateById(mcsMerchant);
+ if (num > 0) {
+ this.baseMapper.enableUserStatus(mcsMerchant.getUserId());
+ }
return R.ok();
}
@@ -217,19 +234,28 @@
return R.fail("账号不存在");
}
retrieveMerchantSurplusLitDays(merchantVO);
+ McsConfig mcsConfig=mcsConfigDAO.selectOne(new QueryWrapper<McsConfig>().lambda().eq(McsConfig::getKey,CUSTOMER_SERVICE_CONTACT_NUM));
+ if(mcsConfig!=null){
+ merchantVO.setCustomPhone(mcsConfig.getValue());
+ }
+
return R.ok(merchantVO);
}
/**
* 完成订单更新/新增商家信息
*
- * @param merchantName
+ * @param orderNo
* @param configId
* @param userId
* @return
*/
@Override
- public R updateOrAddMcsMerchantAfterOrder(String merchantName, Long configId, Long userId) {
+ public R updateOrAddMcsMerchantAfterOrder(String orderNo, Long configId, Long userId) {
+ McsOrder mcsOrder = mcsOrderDao.selectOne(new QueryWrapper<McsOrder>().lambda().eq(McsOrder::getOrderNo, orderNo));
+ if (isNull(mcsOrder)) {
+ return R.fail("订单不存在");
+ }
McsMerchant mcsMerchant = this.baseMapper.selectOne(new QueryWrapper<McsMerchant>().lambda().eq(McsMerchant::getUserId, userId));
McsConfig mcsConfig = mcsConfigDAO.selectById(configId);
if (isNull(mcsConfig) || isBlank(mcsConfig.getValue())) {
@@ -240,6 +266,7 @@
return R.fail("配置有误");
}
Integer litDays = (Integer)packageObject.get("day");
+ String merchantName = mcsOrder.getMerchantName();
Date nowDate = new Date();
int num;
if (isNull(mcsMerchant)) {
@@ -248,7 +275,7 @@
if (R.isOk(userInfoVOR) && nonNull(userInfoVOR.getData())) {
LoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(JSONObject.toJSONString(userInfoVOR.getData()), LoginUserInfoVO.class);
mcsMerchant = new McsMerchant();
- mcsMerchant.setName(isBlank(merchantName) ? "默认名称" : merchantName);
+ mcsMerchant.setName(isBlank(merchantName) ? loginUserInfoVO.getName() : merchantName);
mcsMerchant.setPhone(loginUserInfoVO.getPhone());
mcsMerchant.setAccount(loginUserInfoVO.getAccount());
mcsMerchant.setLevel(1);
@@ -259,7 +286,13 @@
mcsMerchant.setUserId(userId);
mcsMerchant.setCreatedBy(userId);
mcsMerchant.setUpdatedBy(userId);
+ mcsMerchant.setAddress(mcsOrder.getAddress());
+ mcsMerchant.setLat(mcsOrder.getLat());
+ mcsMerchant.setLon(mcsOrder.getLon());
num = this.baseMapper.insert(mcsMerchant);
+ McsMerchantDTO mcsMerchantDTO = new McsMerchantDTO();
+ mcsMerchantDTO.setName(mcsMerchant.getName());
+ userService.putMcsMerchantUser(mcsMerchantDTO);
} else {
return R.fail("获取用户信息失败");
}
@@ -272,11 +305,9 @@
} else {
nowExpireAt = DateUtils.addDay(previousExpireAt, litDays);
}
- McsMerchant mcsMerchant1 = new McsMerchant();
- mcsMerchant1.setId(mcsMerchant.getId());
- mcsMerchant1.setExpireAt(nowExpireAt);
- mcsMerchant1.setUpdatedBy(userId);
- num = this.baseMapper.updateById(mcsMerchant1);
+ mcsMerchant.setExpireAt(nowExpireAt);
+ mcsMerchant.setUpdatedBy(userId);
+ num = this.baseMapper.updateById(mcsMerchant);
}
if (num > 0) {
return R.ok(mcsMerchant.getId());
@@ -301,7 +332,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 +342,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,14 +360,105 @@
}
}
+ /**
+ * 首页顶部数据
+ * @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());
+ IPage<McsMerchantVO> mcsMerchants = this.baseMapper.pageH5McsMerchant(page, 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();
+ }
+
+ /**
+ * 根据userId获取商家信息
+ * @param userId
+ * @return
+ */
+ @Override
+ public R retrieveMcsMerchantInfoByUserId(Long userId) {
+ McsMerchant mcsMerchant = this.baseMapper.selectOne(new QueryWrapper<McsMerchant>().lambda()
+ .eq(McsMerchant::getUserId, userId).eq(McsMerchant::getIsDel, false));
+ McsMerchantVO mcsMerchantVO = null;
+ if (nonNull(mcsMerchant)) {
+ mcsMerchantVO = new McsMerchantVO();
+ BeanUtils.copyProperties(mcsMerchant, mcsMerchantVO);
+ }
+ return R.ok(mcsMerchantVO);
+ }
+
+ /**
+ * 定时任务-每隔5分钟执行一次,将已到期的微商业街商家旗下所有的游戏/资讯全部下架
+ * @return
+ */
+ @Override
+ public R offResourceForMcsMerchant() {
+ int num = 0;
+ List<Long> needDealIds = this.baseMapper.selectNeedDealExpiredMerchant();
+ if (nonNull(needDealIds) && !needDealIds.isEmpty()) {
+ mcsGameDAO.setOffByMerchantIds(needDealIds);
+ mcsInformationDAO.setOffByMerchantIds(needDealIds);
+ num = this.baseMapper.updateIsPauseStatus(needDealIds);
+ }
+ return R.ok("执行任务数:" + num);
+ }
+
private void retrieveMerchantSurplusLitDays(McsMerchantVO merchantVO) {
Integer publishLimit = merchantVO.getPublishLimit();
Integer publishCount = mcsGameDAO.selectPublishCount(merchantVO.getId());
Integer idleTotal = publishLimit - publishCount;
merchantVO.setIdleTotal(idleTotal > 0 ? idleTotal : 0);
if (nonNull(merchantVO.getExpireAt())) {
- int surplusLitDays = DateUtils.differentDays(new Date(), merchantVO.getExpireAt());
+ int surplusLitDays = DateUtils.retrieveRemainingDays(merchantVO.getExpireAt());
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