| New file |
| | |
| | | package com.oying.modules.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.oying.modules.system.domain.Invitations; |
| | | import com.oying.modules.system.domain.User; |
| | | import com.oying.modules.system.domain.dto.InvitationsVo; |
| | | import com.oying.modules.system.mapper.UserMapper; |
| | | import com.oying.utils.FileUtil; |
| | | import com.oying.utils.SecurityUtils; |
| | | import lombok.RequiredArgsConstructor; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.oying.modules.system.service.InvitationsService; |
| | | import com.oying.modules.system.domain.dto.InvitationsQueryCriteria; |
| | | import com.oying.modules.system.mapper.InvitationsMapper; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import com.oying.utils.PageUtil; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.io.IOException; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | |
| | | import com.oying.utils.PageResult; |
| | | |
| | | /** |
| | | * @author pxb |
| | | * @description 服务实现 |
| | | * @date 2025-10-20 |
| | | **/ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class InvitationsServiceImpl extends ServiceImpl<InvitationsMapper, Invitations> implements InvitationsService { |
| | | |
| | | private final InvitationsMapper invitationsMapper; |
| | | private final UserMapper userMapper; |
| | | |
| | | @Override |
| | | public PageResult<Invitations> queryAll(InvitationsQueryCriteria criteria, Page<Object> page) { |
| | | return PageUtil.toPage(invitationsMapper.findAll(criteria, page)); |
| | | } |
| | | |
| | | @Override |
| | | public List<Invitations> queryAll(InvitationsQueryCriteria criteria) { |
| | | return invitationsMapper.findAll(criteria); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void create(Invitations resources) { |
| | | invitationsMapper.insert(resources); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void update(Invitations resources) { |
| | | Invitations invitations = getById(resources.getInvitationsId()); |
| | | invitations.copy(resources); |
| | | invitationsMapper.updateById(invitations); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void deleteAll(List<Long> ids) { |
| | | invitationsMapper.deleteBatchIds(ids); |
| | | } |
| | | |
| | | @Override |
| | | public void download(List<Invitations> all, HttpServletResponse response) throws IOException { |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | for (Invitations invitations : all) { |
| | | Map<String, Object> map = new LinkedHashMap<>(); |
| | | map.put("邀请人ID", invitations.getInviterId()); |
| | | map.put("邀请人电话", invitations.getInviterPhone()); |
| | | map.put("邀请人姓名", invitations.getInviterName()); |
| | | map.put("邀请人openid", invitations.getInviterOpenId()); |
| | | map.put("新用户openid", invitations.getNewUserOpenId()); |
| | | map.put("新用户ID", invitations.getNewUserId()); |
| | | map.put("新用户姓名", invitations.getNewUserName()); |
| | | map.put("新用户电话", invitations.getNewUserPhone()); |
| | | map.put("记录类型", invitations.getType()); |
| | | map.put("用户类型", invitations.getUserType()); |
| | | map.put("1success 0pending 2failed", invitations.getStatus()); |
| | | map.put("奖励数值", invitations.getRewardValue()); |
| | | map.put("奖励类型", invitations.getRewardType()); |
| | | map.put("创建者", invitations.getCreateBy()); |
| | | map.put("更新者", invitations.getUpdateBy()); |
| | | map.put("创建日期", invitations.getCreateTime()); |
| | | map.put("更新时间", invitations.getUpdateTime()); |
| | | list.add(map); |
| | | } |
| | | FileUtil.downloadExcel(list, response); |
| | | } |
| | | |
| | | @Override |
| | | public Object addInvitations(InvitationsVo invitationsVo) { |
| | | // SecurityUtils.getCurrentUserId(); |
| | | // 判断是否为新用户 |
| | | if(userMapper.selectById(invitationsVo.getNewUserId()) == null) { |
| | | throw new RuntimeException("用户不存在"); |
| | | } |
| | | Invitations selectOne = invitationsMapper.selectOne(new QueryWrapper<Invitations>().eq("new_user_id", invitationsVo.getNewUserId())); |
| | | if(selectOne != null) { |
| | | throw new RuntimeException("用户已被邀请过!"); |
| | | } |
| | | // 查询邀请人信息 |
| | | User user = userMapper.selectById(invitationsVo.getInviterId()); |
| | | Invitations invitations = new Invitations(); |
| | | invitations.setInviterId(invitationsVo.getInviterId()); |
| | | invitations.setInviterPhone(user.getUsername()); |
| | | invitations.setInviterName(user.getNickName()); |
| | | invitations.setInviterOpenId(user.getOpenid()); |
| | | if(invitationsVo.getUserType().equals("QS") || invitationsVo.getUserType().equals("MJQS")) { |
| | | invitations.setInviterOpenId(user.getRiderOpenId()); |
| | | } |
| | | // 查询被邀请人的信息 |
| | | User newUser = userMapper.selectById(invitationsVo.getNewUserId()); |
| | | invitations.setNewUserOpenId(newUser.getOpenid()); |
| | | if(invitationsVo.getUserType().equals("QS") || invitationsVo.getUserType().equals("MJQS")) { |
| | | invitations.setNewUserOpenId(newUser.getRiderOpenId()); |
| | | } |
| | | invitations.setNewUserId(invitationsVo.getNewUserId()); |
| | | invitations.setNewUserName(newUser.getNickName()); |
| | | invitations.setNewUserPhone(newUser.getUsername()); |
| | | invitations.setUserType(invitationsVo.getUserType()); |
| | | // 邀请 |
| | | invitations.setType("YQ"); |
| | | invitations.setStatus("1"); |
| | | invitationsMapper.insert(invitations); |
| | | return invitations; |
| | | } |
| | | |
| | | } |