第二次
parent
cc778ef584
commit
8446839261
|
@ -19,14 +19,14 @@ public class Packet {
|
|||
// 定义一个String类型的变量packetTheme
|
||||
private String packetTheme;
|
||||
// 定义一个Integer类型的变量packetPrice
|
||||
private Integer packetPrice;
|
||||
private Double packetPrice;
|
||||
// 使用@DateTimeFormat注解,将Date类型的变量packetDate的格式设置为yyyy-MM-dd
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private Date packetDate;
|
||||
// 定义一个Integer类型的变量packetCount
|
||||
private Integer packetCount;
|
||||
// 定义一个BigDecimal类型的变量packetRema 剩余
|
||||
private BigDecimal packetRema;
|
||||
private Double packetRema;
|
||||
// 定义一个Integer类型的变量packetClai 已领取个数
|
||||
private Integer packetClai;
|
||||
// 定义一个Integer类型的变量packetDuration 持续时间
|
||||
|
@ -38,4 +38,5 @@ public class Packet {
|
|||
// 定义一个Integer类型的变量packetSnag 状态是否抢到
|
||||
private Integer packetSnag;
|
||||
private Integer userId;
|
||||
private Integer packetRequest;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public class User {
|
|||
// 性别
|
||||
private String sex;
|
||||
// 余额
|
||||
private BigDecimal money;
|
||||
private Double money;
|
||||
private Integer oneid;
|
||||
private Integer twoid;
|
||||
private Integer threeid;
|
||||
|
|
|
@ -13,8 +13,8 @@ import java.util.Date;
|
|||
@Data
|
||||
public class PacketRequest {
|
||||
|
||||
private Integer packetPrice;
|
||||
private Integer packetPrices;
|
||||
private Double packetPrice;
|
||||
private Double packetPrices;
|
||||
|
||||
// 使用@DateTimeFormat注解,将Date类型的变量packetDate的格式设置为yyyy-MM-dd
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
|
|
|
@ -14,11 +14,11 @@ public class RedPacketRequest {
|
|||
// 定义一个Integer类型的变量packetId
|
||||
private Integer packetId;
|
||||
// 定义一个Integer类型的变量packetPrice 金额
|
||||
private Integer packetPrice;
|
||||
private Double packetPrice;
|
||||
// 定义一个Integer类型的变量packetCount 数量
|
||||
private Integer packetCount;
|
||||
// 定义一个BigDecimal类型的变量packetRema 剩余金额
|
||||
private BigDecimal packetRema;
|
||||
private Double packetRema;
|
||||
// 定义一个Integer类型的变量packetClai 已领取个数
|
||||
private Integer packetClai;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ public class SendPacket {
|
|||
// 定义一个String类型的变量packetTheme
|
||||
private String packetTheme;
|
||||
// 定义一个Integer类型的变量packetPrice
|
||||
private Integer packetPrice;
|
||||
private Double packetPrice;
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private Date packetDate;
|
||||
// 定义一个Integer类型的变量packetCount
|
||||
|
|
|
@ -22,34 +22,63 @@ import java.util.List;
|
|||
public interface PacketMapper {
|
||||
|
||||
|
||||
// 根据请求获取包列表
|
||||
List<Packet> packList(PacketRequest packetRequest);
|
||||
|
||||
// 根据用户ID查询好友列表
|
||||
List<Integer> findFriends(Integer userId);
|
||||
|
||||
// 根据用户ID查询用户名
|
||||
List<User> finduserName(@Param("findFriends") List<Integer> findFriends);
|
||||
|
||||
// 发送包
|
||||
Integer InterPacket(SendPacket sendPacket);
|
||||
|
||||
// 给指定用户发送包
|
||||
void InterGive(@Param("packetId") Integer packetId, @Param("userIds") List<Integer> userIds);
|
||||
|
||||
void updateUserMoney(@Param("userId") Integer userId, @Param("packetPrice") Integer packetPrice);
|
||||
// 更新用户余额
|
||||
void updateUserMoney(@Param("userId") Integer userId, @Param("packetPrice") Double packetPrice);
|
||||
|
||||
// 查询包
|
||||
List<Packet> selectPacket();
|
||||
|
||||
|
||||
void updateaddUserMoney(@Param("userId") Integer userId, @Param("i") int i);
|
||||
// 更新用户余额
|
||||
void updateaddUserMoney(@Param("userId") Integer userId, @Param("i") double i);
|
||||
|
||||
// 查询结束金额
|
||||
User selectEndMoney(Integer userId);
|
||||
|
||||
Packet selectPacketById(Integer packetId);
|
||||
// 根据包ID查询包
|
||||
Packet selectPacketById(@Param("packetId") Integer packetId);
|
||||
|
||||
// 根据用户ID和包ID查询真实信息
|
||||
Give findTrue(@Param("userId") Integer userId, @Param("packetId") Integer packetId);
|
||||
|
||||
// 根据包ID查询包数量
|
||||
Packet findPackCount(Integer packetId);
|
||||
|
||||
// 更新红包请求
|
||||
void UpdateRem( RedPacketRequest redPacketRequest);
|
||||
|
||||
|
||||
// 更新发送状态
|
||||
void UpdateGiveState(@Param("packetId") Integer packetId, @Param("userId") Integer userId);
|
||||
|
||||
// 更新红包状态
|
||||
void UpdatePacketSang(@Param("packetId") Integer packetId);
|
||||
|
||||
// 更新余额
|
||||
void UpdateYue(@Param("v") double v, @Param("userId") Integer userId);
|
||||
|
||||
// 更新包状态
|
||||
void UpdatePacketState(Integer packetId);
|
||||
|
||||
// 更新红包请求
|
||||
void UpdateRPacketRequest(Integer packetId);
|
||||
|
||||
// 根据包ID查询包数量
|
||||
Packet findPacketCounts(Integer packetId);
|
||||
|
||||
}
|
||||
|
|
|
@ -15,16 +15,12 @@ import com.bwie.user.mapper.PacketMapper;
|
|||
import com.bwie.user.service.PacketService;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -50,6 +46,7 @@ public class PacketServicelmpl implements PacketService {
|
|||
|
||||
/**
|
||||
* 红包列表
|
||||
*
|
||||
* @param packetRequest
|
||||
* @return
|
||||
*/
|
||||
|
@ -62,14 +59,15 @@ public class PacketServicelmpl implements PacketService {
|
|||
String s = redisTemplate.opsForValue().get(TokenConstants.LOGIN_TOKEN_KEY + userKey);
|
||||
User user = JSON.parseObject(s, User.class);
|
||||
//用户只能搜索到用户可以抢到的红包(2分)
|
||||
packetRequest.setUserId(user.getUserId());
|
||||
List<Packet> packetList = packetMapper.packList(packetRequest);
|
||||
packetRequest.setUserId(user.getUserId());
|
||||
List<Packet> packetList = packetMapper.packList(packetRequest);
|
||||
PageInfo info = new PageInfo(packetList);
|
||||
return Result.success(info.getList(),info.getTotal()+"");
|
||||
return Result.success(info.getList(), info.getTotal() + "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 好友复选框
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
|
@ -88,6 +86,7 @@ public class PacketServicelmpl implements PacketService {
|
|||
|
||||
/**
|
||||
* 发红包
|
||||
*
|
||||
* @param sendPacket
|
||||
* @return
|
||||
*/
|
||||
|
@ -100,29 +99,28 @@ public class PacketServicelmpl implements PacketService {
|
|||
String s = redisTemplate.opsForValue().get(TokenConstants.LOGIN_TOKEN_KEY + userKey);
|
||||
User user = JSON.parseObject(s, User.class);
|
||||
//余额
|
||||
BigDecimal money = user.getMoney();
|
||||
Integer packetPrice = sendPacket.getPacketPrice();
|
||||
int newMoney = money.intValue();
|
||||
double newMoney = user.getMoney();
|
||||
double packetPrice = sendPacket.getPacketPrice();
|
||||
|
||||
if (packetPrice>newMoney){
|
||||
if (packetPrice > newMoney) {
|
||||
throw new AuthException("余额不足!!!");
|
||||
}
|
||||
sendPacket.setUserId(user.getUserId());
|
||||
//添加红包表
|
||||
Integer i = packetMapper.InterPacket(sendPacket);
|
||||
if (i>0){
|
||||
Integer i = packetMapper.InterPacket(sendPacket);
|
||||
if (i > 0) {
|
||||
//添加中间表
|
||||
List<Integer> userIds = sendPacket.getUserIds();
|
||||
Integer packetId = sendPacket.getPacketId();
|
||||
packetMapper.InterGive(packetId,userIds);
|
||||
packetMapper.InterGive(packetId, userIds);
|
||||
//修改monry余额
|
||||
packetMapper.updateUserMoney(user.getUserId(),packetPrice);
|
||||
packetMapper.updateUserMoney(user.getUserId(), packetPrice);
|
||||
//查询当前值
|
||||
User endMoney = packetMapper.selectEndMoney(user.getUserId());
|
||||
user.setMoney(endMoney.getMoney());
|
||||
redisTemplate.opsForValue().set(TokenConstants.LOGIN_TOKEN_KEY+userKey,JSON.toJSONString(user));
|
||||
redisTemplate.opsForValue().set(TokenConstants.LOGIN_TOKEN_KEY + userKey, JSON.toJSONString(user));
|
||||
//存缓存 key:红包ID 值:红包金额 过期时间:红包持续时间
|
||||
redisTemplate.opsForValue().set(packetId+"",sendPacket.getPacketPrice()+"",sendPacket.getPacketDuration(), TimeUnit.MINUTES);
|
||||
redisTemplate.opsForValue().set(packetId + "", sendPacket.getPacketPrice() + "", sendPacket.getPacketDuration(), TimeUnit.MINUTES);
|
||||
return Result.success("发送成功");
|
||||
}
|
||||
return Result.error("添加失败");
|
||||
|
@ -130,89 +128,112 @@ public class PacketServicelmpl implements PacketService {
|
|||
|
||||
/**
|
||||
* 抢红包(阿里路亚)(牛逼了哦)(哦呦)(傻波一)(哈皮波斯带)(什么玩意)(牛逼轰轰)(张耀东)
|
||||
*
|
||||
* @param redPacketRequest
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Result redPacket(RedPacketRequest redPacketRequest) {
|
||||
//判断红包时间是否过期
|
||||
if (!redisTemplate.hasKey(redPacketRequest.getPacketId()+"")){
|
||||
throw new AuthException("红包已过期!!!!!!!");
|
||||
}
|
||||
if (!redisTemplate.hasKey(redPacketRequest.getPacketId() + "")) {
|
||||
throw new AuthException("红包已过期!!!!!!!");
|
||||
}
|
||||
//获取当前登录人
|
||||
String token = request.getHeader(TokenConstants.TOKEN);
|
||||
String userKey = JwtUtils.getUserKey(token);
|
||||
String s = redisTemplate.opsForValue().get(TokenConstants.LOGIN_TOKEN_KEY + userKey);
|
||||
User user = JSON.parseObject(s, User.class);
|
||||
//检查是否抢到
|
||||
Give give = packetMapper.findTrue(user.getUserId(),redPacketRequest.getPacketId());
|
||||
if(give.getGiveState() !=1){
|
||||
Give give = packetMapper.findTrue(user.getUserId(), redPacketRequest.getPacketId());
|
||||
if (give.getGiveState() != 1) {
|
||||
throw new AuthException("已抢过~~~~~");
|
||||
}
|
||||
//查询红包个数
|
||||
Packet packet = packetMapper.findPackCount(redPacketRequest.getPacketId());
|
||||
if(packet.getPacketCount()==0){
|
||||
if (packet.getPacketCount() == 0) {
|
||||
throw new AuthException("红包已抢完~~~~~");
|
||||
}
|
||||
//红包已领取个数
|
||||
Integer packetClai = packet.getPacketClai();
|
||||
//红包总个数
|
||||
Integer packetCount = packet.getPacketCount();
|
||||
//查询剩余个数
|
||||
Integer newCount = packetCount - packetClai;
|
||||
|
||||
//红包金额
|
||||
Double packetPrice = packet.getPacketPrice();
|
||||
//剩余金额
|
||||
Double packetRema = packet.getPacketRema();
|
||||
//发红包的金额
|
||||
Double newPrice = packetPrice-packetRema;
|
||||
//创建锁对象
|
||||
// RLock lock = redissonClient.getLock("one");
|
||||
|
||||
//获取锁
|
||||
// try {
|
||||
// lock.tryLock(5,TimeUnit.MINUTES);
|
||||
//红包金额
|
||||
Integer totalAmount = redPacketRequest.getPacketPrice();
|
||||
//红包个数
|
||||
Integer num = redPacketRequest.getPacketCount();
|
||||
//转型
|
||||
int newInt = totalAmount;
|
||||
double doubleValue = (double) newInt;
|
||||
|
||||
//转型
|
||||
|
||||
//保留后两位
|
||||
DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
||||
String format = decimalFormat.format(doubleValue);
|
||||
double vv = Double.parseDouble(format);
|
||||
//储存每个红包的金额
|
||||
double[] redPacket = new double[num];
|
||||
//创建随机数
|
||||
Random random = new Random();
|
||||
//循环
|
||||
for (int i = 0; i < num - 1; i++) {
|
||||
double amout = random.nextDouble()*(vv/num)*2;
|
||||
redPacket[i] = amout;
|
||||
vv -=amout;
|
||||
}
|
||||
redPacket[num-1]= vv;
|
||||
Arrays.sort(redPacket);
|
||||
for (double v : redPacket) {
|
||||
//释放锁
|
||||
String format = decimalFormat.format(newPrice);
|
||||
double endPrice = Double.parseDouble(format);
|
||||
//储存每个红包的金额
|
||||
double[] redPacket = new double[newCount];
|
||||
//创建随机数
|
||||
Random random = new Random();
|
||||
//循环
|
||||
for (int i = 0; i < newCount - 1; i++) {
|
||||
double amout = random.nextDouble() * (endPrice / newCount) * 2;
|
||||
redPacket[i] = amout;
|
||||
}
|
||||
redPacket[newCount - 1] = endPrice;
|
||||
Arrays.sort(redPacket);
|
||||
|
||||
//释放锁
|
||||
// if (lock.isHeldByCurrentThread()){
|
||||
// if (lock.isLocked()){
|
||||
// lock.unlock();
|
||||
// }
|
||||
// }
|
||||
//保留后两位
|
||||
DecimalFormat decimalFormats = new DecimalFormat("#.##");
|
||||
String formats = decimalFormats.format(v);
|
||||
double v1 = Double.parseDouble(formats);
|
||||
//修改红包余额
|
||||
//余额等于 红包金额 - 抢到的红包金额 num = 5
|
||||
//保留后两位
|
||||
DecimalFormat decimalFormats = new DecimalFormat("#.##");
|
||||
String formats = decimalFormats.format(redPacket[0]);
|
||||
double v1 = Double.parseDouble(formats);
|
||||
//修改红包余额
|
||||
//余额等于 红包金额 - 抢到的红包金额 num = 5
|
||||
|
||||
double newVv= vv-v;
|
||||
int newLl =num-1; //修改红包个数
|
||||
BigDecimal bigDecimal = new BigDecimal(Double.toString(newVv));
|
||||
double newVv = endPrice - redPacket[0];
|
||||
|
||||
int a = (int)v;
|
||||
//最后一个包
|
||||
if (1==newCount){
|
||||
Packet pa = packetMapper.findPacketCounts(redPacketRequest.getPacketId());
|
||||
//剩余金额
|
||||
Double packetRema1 = pa.getPacketRema();
|
||||
redPacketRequest.setPacketRema(0.00);
|
||||
redPacketRequest.setPacketPrice(packetRema1);
|
||||
packetMapper.UpdateRem(redPacketRequest);
|
||||
//修改红包抢到状态 修改中间表
|
||||
packetMapper.UpdateGiveState(redPacketRequest.getPacketId(), user.getUserId());
|
||||
//修改用户余额
|
||||
packetMapper.UpdateYue(redPacket[0],user.getUserId());
|
||||
//修改红包状态
|
||||
packetMapper.UpdatePacketSang(pa.getPacketId());
|
||||
return Result.success("抢红包成功,恭喜您喜得" + packetRema1 + ",元");
|
||||
}
|
||||
|
||||
redPacketRequest.setPacketRema(bigDecimal);
|
||||
redPacketRequest.setPacketPrice(a);
|
||||
redPacketRequest.setPacketCount(newLl);
|
||||
packetMapper.UpdateRem(redPacketRequest);
|
||||
//修改是否抢到 修改中间表
|
||||
packetMapper.UpdateGiveState(redPacketRequest.getPacketId(),user.getUserId());
|
||||
System.out.println("哈哈哈:"+v1+"次数为"+num);
|
||||
return Result.success("抢红包成功,恭喜您喜得"+v1+",元");
|
||||
}
|
||||
|
||||
|
||||
redPacketRequest.setPacketRema(newVv);
|
||||
redPacketRequest.setPacketPrice(redPacket[0]);
|
||||
|
||||
packetMapper.UpdateRem(redPacketRequest);
|
||||
//修改红包抢到状态 修改中间表
|
||||
packetMapper.UpdateGiveState(redPacketRequest.getPacketId(), user.getUserId());
|
||||
//修改用户余额
|
||||
packetMapper.UpdateYue(redPacket[0],user.getUserId());
|
||||
|
||||
return Result.success("抢红包成功,恭喜您喜得" + v1 + ",元");
|
||||
|
||||
|
||||
//
|
||||
|
@ -227,31 +248,36 @@ public class PacketServicelmpl implements PacketService {
|
|||
// lock.unlock();
|
||||
// }
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时器扫描
|
||||
* 定时器扫描 返回余额
|
||||
*/
|
||||
@Scheduled(cron = "0/10 * * * * ?")
|
||||
public void take(){
|
||||
public void take() {
|
||||
System.out.println("当当当当>>>>>>定时器启动......轰隆隆!轰隆隆!轰隆隆!轰隆隆!");
|
||||
//查询红包表
|
||||
List<Packet> packets = packetMapper.selectPacket();
|
||||
|
||||
if (!packets.isEmpty()){
|
||||
for (Packet packet : packets) {
|
||||
if (!packets.isEmpty()) {
|
||||
for (Packet packet : packets) {
|
||||
|
||||
if (!redisTemplate.hasKey(packet.getPacketId()+"")){
|
||||
//查询剩余金额
|
||||
Packet packet1 = packetMapper.selectPacketById(packet.getPacketId());
|
||||
BigDecimal packetRema = packet1.getPacketRema();
|
||||
int i = packetRema.intValue();
|
||||
if (i>0){
|
||||
packetMapper.updateaddUserMoney(packet.getUserId(),i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//问题:怎么解决累计加
|
||||
if (!redisTemplate.hasKey(packet.getPacketId() + "")) {
|
||||
//修改红包状态
|
||||
packetMapper.UpdatePacketState(packet.getPacketId());
|
||||
//查询剩余金额
|
||||
Packet packet1 = packetMapper.selectPacketById(packet.getPacketId());
|
||||
double packetRema = packet1.getPacketRema();
|
||||
if (packetRema > 0.01) {
|
||||
//退还用户余额
|
||||
packetMapper.updateaddUserMoney(packet.getUserId(), packetRema);
|
||||
//修改红包退回状态
|
||||
packetMapper.UpdateRPacketRequest(packet.getPacketId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,11 +21,23 @@
|
|||
update user set money = money+#{i} where user_id = #{userId}
|
||||
</update>
|
||||
<update id="UpdateRem">
|
||||
update packet set packet_price = packet_price-#{packetPrice} ,packet_rema = packet_rema+#{packetRema},packet_count=#{packetCount} where packet_id = #{packetId}
|
||||
update packet set packet_rema = packet_rema+#{packetRema},packet_clai = packet_clai+1 where packet_id = #{packetId}
|
||||
</update>
|
||||
<update id="UpdateGiveState">
|
||||
update give set give_state = 2 where packet_id = #{packetId} and user_id = #{userId}
|
||||
</update>
|
||||
<update id="UpdatePacketSang">
|
||||
update packet set packet_snag = 2 where packet_id = #{packetId}
|
||||
</update>
|
||||
<update id="UpdateYue">
|
||||
update user set money = money+#{v} where user_id = #{userId}
|
||||
</update>
|
||||
<update id="UpdatePacketState">
|
||||
update packet set packet_snag = 2 where packet_id = #{packetId}
|
||||
</update>
|
||||
<update id="UpdateRPacketRequest">
|
||||
update packet set packet_request = 2 where packet_id = #{packetId}
|
||||
</update>
|
||||
|
||||
<select id="packList" resultType="com.bwie.common.domain.Packet">
|
||||
SELECT p.*,g.give_state giveState FROM packet p
|
||||
|
@ -71,7 +83,7 @@
|
|||
where user_id= #{userId};
|
||||
</select>
|
||||
<select id="selectPacketById" resultType="com.bwie.common.domain.Packet">
|
||||
select packet_rema from packet where packet_id=#{packetId}
|
||||
select packet_rema from packet where packet_id=#{packetId} and packet_request = 1
|
||||
</select>
|
||||
<select id="findTrue" resultType="com.bwie.common.domain.Give">
|
||||
select give_state
|
||||
|
@ -80,7 +92,10 @@
|
|||
and user_id = #{userId};
|
||||
</select>
|
||||
<select id="findPackCount" resultType="com.bwie.common.domain.Packet">
|
||||
select packet_count from packet where packet_id=#{packetId}
|
||||
select packet_count,packet_clai,packet_price,packet_rema from packet where packet_id=#{packetId}
|
||||
</select>
|
||||
<select id="findPacketCounts" resultType="com.bwie.common.domain.Packet">
|
||||
select packet_id,packet_clai,packet_rema from packet where packet_id = #{packetId}
|
||||
</select>
|
||||
|
||||
|
||||
|
|
|
@ -106,5 +106,11 @@ public class UserController {
|
|||
public Result updateFriedRequest(@PathVariable("feiId") Integer feiId,@PathVariable("state") Integer state){
|
||||
return userService.updateFriedRequest(feiId,state);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除好友申请列表
|
||||
*/
|
||||
@PostMapping("/deleteFriedRequest")
|
||||
public Result deleteFriedRequest(@RequestBody Integer[] ids){
|
||||
return userService.deleteFriedRequest(ids);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,46 +21,65 @@ import java.util.List;
|
|||
@Component
|
||||
@Mapper
|
||||
public interface UserMapper {
|
||||
// 根据用户名查找用户
|
||||
User findName(String username);
|
||||
|
||||
// 添加用户
|
||||
Integer Sign(AddUser addUser);
|
||||
|
||||
// 获取用户好友列表
|
||||
List<Integer> FriendId(Integer userId);
|
||||
|
||||
// 获取用户好友列表
|
||||
List<User> FriedList(Conditit conditit);
|
||||
|
||||
// 获取所有用户
|
||||
List<Integer> findAllUser();
|
||||
|
||||
// 获取所有用户
|
||||
List<User> findAddAllUser(Inqri inqri);
|
||||
|
||||
// 查找好友状态
|
||||
Friend findCf(@Param("userId") Integer userId, @Param("userId1") Integer userId1);
|
||||
|
||||
// 添加好友
|
||||
Integer InsertFei(@Param("userId") Integer userId, @Param("userId1") Integer userId1);
|
||||
|
||||
// 查找好友状态
|
||||
Fie findFieState(@Param("userId") Integer userId, @Param("userId1") Integer userId1);
|
||||
|
||||
// 更新好友状态
|
||||
void updFriedState(@Param("feiState") Integer feiState, @Param("userId") Integer userId);
|
||||
|
||||
// 获取好友列表
|
||||
List<Integer> FieList(Integer userId);
|
||||
|
||||
|
||||
// 获取所有商品
|
||||
List<Procut> AllProcut();
|
||||
|
||||
|
||||
// 添加用户
|
||||
List<User> findAddAll(@Param("id") List<Integer> id);
|
||||
|
||||
// 更新好友请求状态
|
||||
void updateFriedRequest(@Param("feiId") Integer feiId, @Param("state") Integer state);
|
||||
|
||||
// 查找好友id
|
||||
Fie findUserId(Integer feiId);
|
||||
|
||||
// 添加好友
|
||||
void addFriend(@Param("userId") Integer userId, @Param("id") Integer id);
|
||||
|
||||
// 添加好友
|
||||
void addFriends(@Param("id") Integer id, @Param("userId") Integer userId);
|
||||
|
||||
// 删除用户
|
||||
Integer deleUser(@Param("userId") Integer userId, @Param("userId1") Integer userId1);
|
||||
|
||||
// 删除用户
|
||||
Integer deleUsers(@Param("userId") Integer userId, @Param("userId1") Integer userId1);
|
||||
|
||||
|
||||
//批量删除好友申请
|
||||
void deleteFriedRequest(@Param("ids") Integer[] ids);
|
||||
|
||||
}
|
||||
|
|
|
@ -35,4 +35,5 @@ public interface UserService {
|
|||
|
||||
Result updateFriedRequest(Integer feiId, Integer state);
|
||||
|
||||
Result deleteFriedRequest(Integer[] ids);
|
||||
}
|
||||
|
|
|
@ -18,12 +18,12 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.lang.reflect.Array.set;
|
||||
|
||||
/**
|
||||
* @author gxb
|
||||
* @description TODO
|
||||
|
@ -143,13 +143,17 @@ public class UserServicelmpl implements UserService{
|
|||
List<Integer> friendId = userMapper.FriendId(user.getUserId());
|
||||
//查询所有用户
|
||||
List<Integer> userList = userMapper.findAllUser();
|
||||
//去重
|
||||
HashSet<Integer> friend = new HashSet<>(friendId);
|
||||
HashSet<Integer> userId = new HashSet<>(userList);
|
||||
HashSet<Integer> hashSet = new HashSet<>();
|
||||
hashSet.addAll(friend);
|
||||
hashSet.addAll(userId);
|
||||
ArrayList<Integer> newUserIds = new ArrayList<>(hashSet);
|
||||
|
||||
//将两个列表转换为集合
|
||||
Set<Integer> set1 = new HashSet<>(friendId);
|
||||
Set<Integer> set2 = new HashSet<>(userList);
|
||||
|
||||
//获取两个集合的不重复值
|
||||
set2.removeAll(set1);
|
||||
List<Integer> newUserIds = new ArrayList<Integer>(set2);
|
||||
|
||||
System.out.println("去重后的Ids"+newUserIds);
|
||||
|
||||
//塞值
|
||||
inqri.setUserIds(newUserIds);
|
||||
List<User> users = userMapper.findAddAllUser(inqri);
|
||||
|
@ -252,6 +256,17 @@ public class UserServicelmpl implements UserService{
|
|||
return Result.success("成功!!!!!!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Result deleteFriedRequest(Integer[] ids) {
|
||||
userMapper.deleteFriedRequest(ids);
|
||||
return Result.success("删除成功");
|
||||
}
|
||||
|
||||
|
||||
|
||||
private List<Procut> getChilren(Procut p,List<Procut> procutList){
|
||||
|
|
|
@ -37,6 +37,13 @@
|
|||
from friend
|
||||
where user_id = #{userId} and friend_friends = #{userId1};
|
||||
</delete>
|
||||
<delete id="deleteFriedRequest">
|
||||
delete from fei where fei_id in (
|
||||
<foreach collection="ids" item="id" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
)
|
||||
</delete>
|
||||
|
||||
<select id="findName" resultType="com.bwie.common.domain.User">
|
||||
select <include refid="user"></include>
|
||||
|
|
Loading…
Reference in New Issue