Browse Source

Merge branch 'develop' of gitadmin/tuoheng_qmhh into release

tags/V1.8.0^2
xuziqing 1 year ago
parent
commit
708eccaab9
1 changed files with 59 additions and 16 deletions
  1. +59
    -16
      tuoheng-api/src/main/java/com/tuoheng/api/service/impl/WestreamUserServiceImpl.java

+ 59
- 16
tuoheng-api/src/main/java/com/tuoheng/api/service/impl/WestreamUserServiceImpl.java View File

@@ -2,18 +2,20 @@ package com.tuoheng.api.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tuoheng.api.entity.domain.Identity;
import com.tuoheng.api.entity.domain.WestreamUser;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.tuoheng.api.constants.DictConstants;
import com.tuoheng.api.entity.domain.*;
import com.tuoheng.api.entity.request.OnlineNumQuery;
import com.tuoheng.api.entity.request.WestreamUserQuery;
import com.tuoheng.api.mapper.IdentityMapper;
import com.tuoheng.api.mapper.WestreamUserMapper;
import com.tuoheng.api.mapper.*;
import com.tuoheng.api.service.IWestreamUserService;
import com.tuoheng.api.utils.PointsTitleConstants;
import com.tuoheng.common.common.BaseServiceImpl;
import com.tuoheng.common.config.CommonConfig;
import com.tuoheng.common.utils.CommonUtils;
import com.tuoheng.common.utils.JsonResult;
import com.tuoheng.common.utils.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@@ -35,6 +37,12 @@ public class WestreamUserServiceImpl extends BaseServiceImpl<WestreamUserMapper,

@Autowired
private IdentityMapper identityMapper;
@Autowired
private ThDictDataMapper dictDataMapper;
@Autowired
private ThDictMapper dictMapper;
@Autowired
private UserPointsDetailMapper userPointsDetailMapper;


@Override
@@ -51,7 +59,7 @@ public class WestreamUserServiceImpl extends BaseServiceImpl<WestreamUserMapper,

@Override
public JsonResult login(WestreamUser westreamUser) {
if(null == westreamUser.getTenantId() || StringUtils.isEmpty(westreamUser.getOpenid())){
if (null == westreamUser.getTenantId() || StringUtils.isEmpty(westreamUser.getOpenid())) {
return JsonResult.error("参数为空!");
}
WestreamUser westreamUserQuery = westreamUserMapper.selectOne(new LambdaQueryWrapper<WestreamUser>()
@@ -59,28 +67,63 @@ public class WestreamUserServiceImpl extends BaseServiceImpl<WestreamUserMapper,
.eq(WestreamUser::getTenantId, westreamUser.getTenantId())
.eq(WestreamUser::getOpenid, westreamUser.getOpenid()));

if(ObjectUtil.isNull(westreamUserQuery)){
if (ObjectUtil.isNull(westreamUserQuery)) {
//昵称生成规则:护河行者+4位随机数
int random = (int) (Math.random()*9000+1000);//随机生成一个四位整数
westreamUser.setNickname("护河行者"+random);
int random = (int) (Math.random() * 9000 + 1000);//随机生成一个四位整数
westreamUser.setNickname("护河行者" + random);
String url = "qmhh/headimgurl/" + (new Random().nextInt(11) + 1) + ".jpg";
westreamUser.setHeadimgurl(url);
westreamUser.setCreateTime(new Date());
//添加积分及其积分明细
addIntegral(westreamUserQuery);
westreamUserMapper.insert(westreamUser);

westreamUser.setNickname("护河行者"+ westreamUser.getId());
westreamUser.setNickname("护河行者" + westreamUser.getId());
westreamUserMapper.updateById(westreamUser);
}else {
westreamUserQuery.setLoginNum(westreamUserQuery.getLoginNum()+1);
} else {
westreamUserQuery.setLoginNum(westreamUserQuery.getLoginNum() + 1);
westreamUserMapper.updateById(westreamUserQuery);
}

return JsonResult.success();
}

private void addIntegral(WestreamUser westreamUserQuery) {
//注册程序 积分设置
ThDict thDict = dictMapper.selectOne(new LambdaQueryWrapper<ThDict>()
.eq(ThDict::getTenantId, westreamUserQuery.getTenantId())
.eq(ThDict::getCode, DictConstants.POINTS_RULE_CODE)
.eq(ThDict::getMark, 1));
if(ObjectUtils.isNotNull(thDict)){
ThDictData thDictData = dictDataMapper.selectOne(new LambdaQueryWrapper<ThDictData>()
.eq(ThDictData::getDictId, thDict.getId())
.eq(ThDictData::getName, DictConstants.APP_REGISTRY));
if(ObjectUtils.isNotNull(thDictData)){
if(StringUtils.isNotEmpty(thDictData.getValue())){
//查询用户昵称
WestreamUser westreamUser = westreamUserMapper.selectOne(new LambdaQueryWrapper<WestreamUser>()
.eq(WestreamUser::getTenantId, westreamUserQuery.getTenantId())
.eq(WestreamUser::getOpenid, westreamUserQuery.getOpenid())
.eq(WestreamUser::getMark, 1));
//积分明细表入库
UserPointsDetail userPointsDetail = new UserPointsDetail();
BeanUtils.copyProperties(westreamUserQuery,userPointsDetail);
userPointsDetail.setNickname(westreamUser.getNickname());
userPointsDetail.setPointsChange(Integer.parseInt(thDictData.getValue()));
userPointsDetail.setPointsTime(new Date());
userPointsDetail.setChangeName(PointsTitleConstants.USER_REGISTRY);
userPointsDetail.setType(1);
userPointsDetail.setCreateTime(new Date());
userPointsDetailMapper.insert(userPointsDetail);
//TODO 对接商城
}
}
}
}

@Override
public JsonResult userInfo(WestreamUserQuery westreamUserQuery) {
if(null == westreamUserQuery.getTenantId() || StringUtils.isEmpty(westreamUserQuery.getOpenid())){
if (null == westreamUserQuery.getTenantId() || StringUtils.isEmpty(westreamUserQuery.getOpenid())) {
return JsonResult.error("参数为空!");
}

@@ -88,12 +131,12 @@ public class WestreamUserServiceImpl extends BaseServiceImpl<WestreamUserMapper,
.eq(WestreamUser::getMark, 1)
.eq(WestreamUser::getTenantId, westreamUserQuery.getTenantId())
.eq(WestreamUser::getOpenid, westreamUserQuery.getOpenid()));
if(ObjectUtil.isNull(westreamUser)){
if (ObjectUtil.isNull(westreamUser)) {
return JsonResult.error("用户不存在!");
}

Identity identity = identityMapper.selectById(westreamUser.getIdentityId());
if(ObjectUtil.isNotNull(identity)){
if (ObjectUtil.isNotNull(identity)) {
westreamUser.setIdentityName(identity.getIdentityName());
westreamUser.setIdentityRemark(identity.getIdentityRemark());
}
@@ -103,14 +146,14 @@ public class WestreamUserServiceImpl extends BaseServiceImpl<WestreamUserMapper,

@Override
public JsonResult editInfo(WestreamUser westreamUser) {
if(null == westreamUser.getId()){
if (null == westreamUser.getId()) {
return JsonResult.error("用户ID为空!");
}
Integer count = westreamUserMapper.selectCount(new LambdaQueryWrapper<WestreamUser>()
.ne(WestreamUser::getId, westreamUser.getId())
.eq(WestreamUser::getMark, 1)
.eq(WestreamUser::getNickname, westreamUser.getNickname()));
if(count > 0){
if (count > 0) {
return JsonResult.error("用户昵称已存在!");
}
westreamUserMapper.updateById(westreamUser);

Loading…
Cancel
Save