Merge remote-tracking branch 'origin/main'

This commit is contained in:
cun-nan 2024-09-24 16:30:56 +08:00
commit de3013171f
4 changed files with 281 additions and 6 deletions

View File

@ -124,5 +124,7 @@ public class FleetInfo extends BaseEntity implements Serializable {
*/
@TableField(exist = false)
private Double giveAmount1;
private Integer userId;
}

View File

@ -126,5 +126,7 @@ public class FleetMember extends BaseEntity implements Serializable {
*/
private Date updateTime;
private Integer userId;
}

View File

@ -1,6 +1,7 @@
package com.fuint.business.fleet.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -17,15 +18,26 @@ import com.fuint.business.fleet.vo.FleetInfoVo;
import com.fuint.business.member.entity.LJStaff;
import com.fuint.business.member.service.ILJStaffService;
import com.fuint.business.store.mapper.MtStoreMapper;
import com.fuint.business.storeInformation.entity.LJStore;
import com.fuint.business.storeInformation.service.ILJStoreService;
import com.fuint.business.userManager.entity.LJUserGrade;
import com.fuint.business.userManager.entity.MtInvitation;
import com.fuint.business.userManager.entity.UserBalance;
import com.fuint.business.userManager.mapper.MtInvitationMapper;
import com.fuint.business.userManager.service.LJUserGradeService;
import com.fuint.business.userManager.service.UserBalanceService;
import com.fuint.common.dto.AccountInfo;
import com.fuint.common.service.MemberService;
import com.fuint.common.util.TokenUtil;
import com.fuint.repository.mapper.MtUserMapper;
import com.fuint.repository.model.MtUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
import java.util.Random;
/**
@ -49,6 +61,19 @@ public class FleetInfoServiceImpl extends ServiceImpl<FleetInfoMapper,FleetInfo>
@Autowired
private MtStoreMapper mtStoreMapper;
@Resource
private MtInvitationMapper mtInvitationMapper;
@Resource
LJUserGradeService ljUserGradeService;
@Resource
private UserBalanceService userBalanceService;
@Resource
private ILJStoreService iljStoreService;
@Override
public IPage<FleetInfoVo> queryPage(Page page, FleetInfoVo fleetInfo) {
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
@ -98,14 +123,51 @@ public class FleetInfoServiceImpl extends ServiceImpl<FleetInfoMapper,FleetInfo>
*/
@Override
public int insert(FleetInfo fleetInfo) {
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
FleetInfo fleetInfo1 = selectByName(fleetInfo.getFleetName());
if (ObjectUtil.isNotEmpty(fleetInfo1)){
return 0;
}
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
//判断当前车队负责人是否存在账号
MtUser mtUser = mtUserMapper.selectOne(new LambdaQueryWrapper<MtUser>()
.eq(MtUser::getMobile, fleetInfo.getMobile())
.last("limit 1"));
if (ObjectUtil.isEmpty(mtUser)) {
mtUser = new MtUser();
mtUser.setUserNo(editUserNo());
mtUser.setMobile(fleetInfo.getMobile());
mtUser.setName(fleetInfo.getFleetLeader());
mtUser.setDescription("车队信息自动注册");
mtUser.setCreateTime(DateUtil.date());
mtUserMapper.insert(mtUser);
//注册完成后再查询一次
mtUser = mtUserMapper.selectOne(new LambdaQueryWrapper<MtUser>()
.eq(MtUser::getMobile, fleetInfo.getMobile())
.last("limit 1"));
createVaseInfo(mtUser, nowAccountInfo.getStoreId().toString(), fleetInfo.getStaffId(), null);
}
fleetInfo.setUserId(mtUser.getId());
fleetInfo.setStoreId(nowAccountInfo.getStoreId());
fleetInfo.setChainStoreId(nowAccountInfo.getChainStoreId());
return baseMapper.insert(fleetInfo);
int insert = baseMapper.insert(fleetInfo);
if (insert > 0) {
// fleet_member表新增一条记录
FleetInfo fleetInfo2 = baseMapper.selectOne(new LambdaQueryWrapper<FleetInfo>()
.eq(FleetInfo::getUserId, mtUser.getId()));
FleetMember fleetMember = new FleetMember();
BeanUtil.copyProperties(fleetInfo, fleetMember);
fleetMember.setFleetId(fleetInfo2.getId());
fleetMember.setUserId(mtUser.getId());
fleetMember.setMobile(fleetInfo.getMobile());
fleetMember.setName(fleetInfo.getFleetLeader());
return fleetMemberMapper.insert(fleetMember);
}
return 0;
}
/**
@ -170,4 +232,86 @@ public class FleetInfoServiceImpl extends ServiceImpl<FleetInfoMapper,FleetInfo>
fleetInfoUniVo.setStoreName(mtStoreMapper.selectById(storeId).getName());
return fleetInfoUniVo;
}
/**
* 创建用户的基础信息
*/
private void createVaseInfo (MtUser mtUser, String storeId,String staffId, String inviterId) {
LJStore store = iljStoreService.selectStoreByStoreId(Integer.parseInt(storeId));
// 根据userid和连锁店id查询是否存在对应的余额信息
UserBalance userBalance = userBalanceService.selectUserBalance(mtUser.getId(), store.getChainStoreId());
if (ObjectUtil.isEmpty(userBalance)) {
// 新增余额信息
UserBalance userBalanceAdd = new UserBalance();
userBalanceAdd.setMtUserId(mtUser.getId());
userBalanceAdd.setStoreId(Integer.parseInt(storeId));
userBalanceAdd.setChainStoreId(store.getChainStoreId());
userBalanceAdd.setCardBalance(0.0);
userBalanceAdd.setGiveAmount(0.0);
userBalanceAdd.setPoints(0);
userBalanceAdd.setUsedPoints(0);
userBalanceAdd.setGrowthValue(0);
userBalanceAdd.setConsumeNum(0);
userBalanceAdd.setUserStatus("0");
userBalanceAdd.setUserSource("门店扫码");
LJUserGrade ljUserGrade = ljUserGradeService.selectUserGradeByStoreId(Integer.parseInt(storeId));
if (ObjectUtil.isNotEmpty(ljUserGrade) && ObjectUtil.isNotEmpty(ljUserGrade.getId())) {
userBalanceAdd.setGradeId(ljUserGrade.getId());
}
// 新增会员余额信息
userBalanceService.insertUserBalance(userBalanceAdd);
}else {
LJUserGrade ljUserGrade = ljUserGradeService.selectUserGradeByStoreId(Integer.parseInt(storeId));
if (ObjectUtil.isNotEmpty(ljUserGrade) && ObjectUtil.isNotEmpty(ljUserGrade.getId())) {
userBalance.setGradeId(ljUserGrade.getId());
}
userBalanceService.updateUserBalance(userBalance);
}
// 查询关联表里面是否有信息 注册邀请
MtInvitation mtInvitation1 = mtInvitationMapper.queryByStoreId(Integer.parseInt(storeId), mtUser.getId());
if (ObjectUtil.isEmpty(mtInvitation1)) {
MtInvitation mtInvitation = new MtInvitation();
mtInvitation.setUserId(mtUser.getId());
mtInvitation.setStoreId(Integer.parseInt(storeId));
if (ObjectUtil.isNotEmpty(staffId) && staffId !="") {
mtInvitation.setStaffId(Integer.parseInt(staffId));
}
if (ObjectUtil.isNotEmpty(inviterId) && inviterId !="") {
mtInvitation.setInviterId(Integer.parseInt(inviterId));
}
if (!ObjectUtil.isEmpty(store)){
mtInvitation.setChainStoreId(store.getChainStoreId());
}
mtInvitationMapper.insert(mtInvitation);
}
}
//生成用户编号
private String editUserNo() {
Random random = new Random();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 7; i++) {
sb.append(random.nextInt(10));
}
String digits = sb.toString();
int sum = 0;
for (int i = 0; i < digits.length(); i++) {
int digit = Integer.parseInt(String.valueOf(digits.charAt(i)));
if (i % 2 == 0) {
sum += digit;
} else {
sum += digit * 3;
}
}
int checksum = (10 - (sum % 10)) % 10;
String number = digits + checksum;
return number;
}
}

View File

@ -1,5 +1,6 @@
package com.fuint.business.fleet.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -12,13 +13,28 @@ import com.fuint.business.fleet.mapper.FleetMemberMapper;
import com.fuint.business.fleet.service.FleetInfoService;
import com.fuint.business.fleet.service.FleetMemberService;
import com.fuint.business.fleet.vo.FleetMemberVo;
import com.fuint.business.storeInformation.entity.LJStore;
import com.fuint.business.storeInformation.service.ILJStoreService;
import com.fuint.business.userManager.entity.LJUserGrade;
import com.fuint.business.userManager.entity.MtInvitation;
import com.fuint.business.userManager.entity.UserBalance;
import com.fuint.business.userManager.mapper.MtInvitationMapper;
import com.fuint.business.userManager.service.LJUserGradeService;
import com.fuint.business.userManager.service.LJUserService;
import com.fuint.business.userManager.service.UserBalanceService;
import com.fuint.business.userManager.vo.LJUserVo;
import com.fuint.common.dto.AccountInfo;
import com.fuint.common.service.impl.MemberServiceImpl;
import com.fuint.common.util.TokenUtil;
import com.fuint.repository.mapper.MtUserMapper;
import com.fuint.repository.model.MtUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Random;
/**
* 车队成员(FleetMember)表服务实现类
*
@ -32,6 +48,19 @@ public class FleetMemberServiceImpl extends ServiceImpl<FleetMemberMapper,FleetM
private LJUserService userService;
@Autowired
private FleetInfoService fleetInfoService;
@Autowired
private MtUserMapper mtUserMapper;
@Resource
private MtInvitationMapper mtInvitationMapper;
@Resource
LJUserGradeService ljUserGradeService;
@Resource
private UserBalanceService userBalanceService;
@Resource
private ILJStoreService iljStoreService;
@Override
public IPage<FleetMemberVo> queryPage(Page page, FleetMemberVo fleetMember) {
@ -72,16 +101,34 @@ public class FleetMemberServiceImpl extends ServiceImpl<FleetMemberMapper,FleetM
*/
@Override
public int insert(FleetMember fleetMember) {
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
FleetMember fleetMember1 = queryByMobile(fleetMember.getMobile());
if (ObjectUtil.isNotEmpty(fleetMember1)) {
return 0;
}
LJUserVo user = userService.selectUserByMobileAndChantStoreId(fleetMember.getMobile());
if (ObjectUtil.isEmpty(user)){
return 2;
// LJUserVo user = userService.selectUserByMobileAndChantStoreId(fleetMember.getMobile());
//判断当前车队负责人是否存在账号
MtUser mtUser = mtUserMapper.selectOne(new LambdaQueryWrapper<MtUser>()
.eq(MtUser::getMobile, fleetMember.getMobile())
.last("limit 1"));
if (ObjectUtil.isEmpty(mtUser)){
//注册用户
mtUser = new MtUser();
mtUser.setUserNo(editUserNo());
mtUser.setMobile(fleetMember.getMobile());
mtUser.setName(fleetMember.getName());
mtUser.setDescription("车队成员自动注册");
mtUser.setCreateTime(DateUtil.date());
mtUserMapper.insert(mtUser);
//注册完成后再查询一次
mtUser = mtUserMapper.selectOne(new LambdaQueryWrapper<MtUser>()
.eq(MtUser::getMobile, fleetMember.getMobile())
.last("limit 1"));
createVaseInfo(mtUser, nowAccountInfo.getStoreId().toString(), null, null);
}
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
fleetMember.setUserId(mtUser.getId());
fleetMember.setStoreId(nowAccountInfo.getStoreId());
fleetMember.setChainStoreId(nowAccountInfo.getChainStoreId());
return baseMapper.insert(fleetMember);
@ -144,4 +191,84 @@ public class FleetMemberServiceImpl extends ServiceImpl<FleetMemberMapper,FleetM
fleetMember.setIfLogOff("1");
return baseMapper.updateById(fleetMember);
}
/**
* 创建用户的基础信息
*/
private void createVaseInfo (MtUser mtUser, String storeId,String staffId, String inviterId) {
LJStore store = iljStoreService.selectStoreByStoreId(Integer.parseInt(storeId));
// 根据userid和连锁店id查询是否存在对应的余额信息
UserBalance userBalance = userBalanceService.selectUserBalance(mtUser.getId(), store.getChainStoreId());
if (ObjectUtil.isEmpty(userBalance)) {
// 新增余额信息
UserBalance userBalanceAdd = new UserBalance();
userBalanceAdd.setMtUserId(mtUser.getId());
userBalanceAdd.setStoreId(Integer.parseInt(storeId));
userBalanceAdd.setChainStoreId(store.getChainStoreId());
userBalanceAdd.setCardBalance(0.0);
userBalanceAdd.setGiveAmount(0.0);
userBalanceAdd.setPoints(0);
userBalanceAdd.setUsedPoints(0);
userBalanceAdd.setGrowthValue(0);
userBalanceAdd.setConsumeNum(0);
userBalanceAdd.setUserStatus("0");
userBalanceAdd.setUserSource("门店扫码");
LJUserGrade ljUserGrade = ljUserGradeService.selectUserGradeByStoreId(Integer.parseInt(storeId));
if (ObjectUtil.isNotEmpty(ljUserGrade) && ObjectUtil.isNotEmpty(ljUserGrade.getId())) {
userBalanceAdd.setGradeId(ljUserGrade.getId());
}
// 新增会员余额信息
userBalanceService.insertUserBalance(userBalanceAdd);
}else {
LJUserGrade ljUserGrade = ljUserGradeService.selectUserGradeByStoreId(Integer.parseInt(storeId));
if (ObjectUtil.isNotEmpty(ljUserGrade) && ObjectUtil.isNotEmpty(ljUserGrade.getId())) {
userBalance.setGradeId(ljUserGrade.getId());
}
userBalanceService.updateUserBalance(userBalance);
}
// 查询关联表里面是否有信息 注册邀请
MtInvitation mtInvitation1 = mtInvitationMapper.queryByStoreId(Integer.parseInt(storeId), mtUser.getId());
if (ObjectUtil.isEmpty(mtInvitation1)) {
MtInvitation mtInvitation = new MtInvitation();
mtInvitation.setUserId(mtUser.getId());
mtInvitation.setStoreId(Integer.parseInt(storeId));
if (ObjectUtil.isNotEmpty(staffId) && staffId !="") {
mtInvitation.setStaffId(Integer.parseInt(staffId));
}
if (ObjectUtil.isNotEmpty(inviterId) && inviterId !="") {
mtInvitation.setInviterId(Integer.parseInt(inviterId));
}
if (!ObjectUtil.isEmpty(store)){
mtInvitation.setChainStoreId(store.getChainStoreId());
}
mtInvitationMapper.insert(mtInvitation);
}
}
//生成用户编号
private String editUserNo() {
Random random = new Random();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 7; i++) {
sb.append(random.nextInt(10));
}
String digits = sb.toString();
int sum = 0;
for (int i = 0; i < digits.length(); i++) {
int digit = Integer.parseInt(String.valueOf(digits.charAt(i)));
if (i % 2 == 0) {
sum += digit;
} else {
sum += digit * 3;
}
}
int checksum = (10 - (sum % 10)) % 10;
String number = digits + checksum;
return number;
}
}