From cbf3b0e15a7c00c399bfd23579b6a787adc04f6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E5=85=81=E6=9E=9E?= <3422692813@qq.com> Date: Tue, 24 Sep 2024 16:19:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B09.24?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/fleet/entity/FleetInfo.java | 2 + .../business/fleet/entity/FleetMember.java | 2 + .../service/impl/FleetInfoServiceImpl.java | 148 +++++++++++++++++- .../service/impl/FleetMemberServiceImpl.java | 135 +++++++++++++++- 4 files changed, 281 insertions(+), 6 deletions(-) diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/fleet/entity/FleetInfo.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/fleet/entity/FleetInfo.java index 0c46ef350..84bd021ac 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/fleet/entity/FleetInfo.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/fleet/entity/FleetInfo.java @@ -124,5 +124,7 @@ public class FleetInfo extends BaseEntity implements Serializable { */ @TableField(exist = false) private Double giveAmount1; + + private Integer userId; } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/fleet/entity/FleetMember.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/fleet/entity/FleetMember.java index 98ef012b5..68c202b29 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/fleet/entity/FleetMember.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/fleet/entity/FleetMember.java @@ -126,5 +126,7 @@ public class FleetMember extends BaseEntity implements Serializable { */ private Date updateTime; + private Integer userId; + } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/fleet/service/impl/FleetInfoServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/fleet/service/impl/FleetInfoServiceImpl.java index 1a81425ea..ae3c8eec7 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/fleet/service/impl/FleetInfoServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/fleet/service/impl/FleetInfoServiceImpl.java @@ -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 @Autowired private MtStoreMapper mtStoreMapper; + @Resource + private MtInvitationMapper mtInvitationMapper; + + @Resource + LJUserGradeService ljUserGradeService; + + @Resource + private UserBalanceService userBalanceService; + + @Resource + private ILJStoreService iljStoreService; + + @Override public IPage queryPage(Page page, FleetInfoVo fleetInfo) { AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo(); @@ -98,14 +123,51 @@ public class FleetInfoServiceImpl extends ServiceImpl */ @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() + .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() + .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() + .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 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; + } + } diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/fleet/service/impl/FleetMemberServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/fleet/service/impl/FleetMemberServiceImpl.java index 3fdf38dc9..faa88d4ae 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/fleet/service/impl/FleetMemberServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/fleet/service/impl/FleetMemberServiceImpl.java @@ -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 queryPage(Page page, FleetMemberVo fleetMember) { @@ -72,16 +101,34 @@ public class FleetMemberServiceImpl extends ServiceImpl() + .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() + .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