puhanshu
2022-01-14 55402cc48ecee2ac135624db4d31119b459a1be7
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/McsMerchantServiceImpl.java
@@ -18,6 +18,7 @@
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.dao.McsInformationDAO;
import com.panzhihua.service_community.util.NearbyUtil;
import com.spatial4j.core.shape.Rectangle;
import org.springframework.beans.BeanUtils;
@@ -67,6 +68,8 @@
    @Resource
    private McsGameDAO mcsGameDAO;
    @Resource
    private McsInformationDAO mcsInformationDAO;
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    /**
@@ -77,6 +80,14 @@
    @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);
        Integer litDays = mcsMerchantDTO.getLitDays();
@@ -250,7 +261,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);
@@ -262,6 +273,9 @@
                mcsMerchant.setCreatedBy(userId);
                mcsMerchant.setUpdatedBy(userId);
                num = this.baseMapper.insert(mcsMerchant);
                McsMerchantDTO mcsMerchantDTO = new McsMerchantDTO();
                mcsMerchantDTO.setName(mcsMerchant.getName());
                userService.putMcsMerchantUser(mcsMerchantDTO);
            } else {
                return R.fail("获取用户信息失败");
            }
@@ -274,11 +288,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());
@@ -390,6 +402,39 @@
        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());