6 Commits 6c88f83b22 ... 120a7c07df

Author SHA1 Message Date
  zhentao 120a7c07df wyc 2 months ago
  zhentao e66aea35d0 Merge branch 'fjj' into wyc 2 months ago
  fengjiajia 61da00f1cb fjj 2 months ago
  zhentao 337d11d2c3 Merge branch 'fjj' into wyc 2 months ago
  fengjiajia ba7bf29ddf Merge branch 'wyc' into fjj 2 months ago
  fengjiajia 92583a1061 fjj 2 months ago

+ 1 - 11
src/main/java/com/zhentao/ZyzApplication.java

@@ -1,8 +1,6 @@
 package com.zhentao;
 
-import com.baomidou.mybatisplus.annotation.DbType;
-import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
-import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
+
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -15,12 +13,4 @@ public class ZyzApplication {
     public static void main(String[] args) {
         SpringApplication.run(ZyzApplication.class, args);
     }
-    @Bean
-    public MybatisPlusInterceptor mybatisPlusInterceptor() {
-        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
-        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); // 如果配置多个插件, 切记分页最后添加
-        // 如果有多数据源可以不配具体类型, 否则都建议配上具体的 DbType
-        return interceptor;
-
-    }
 }

+ 7 - 0
src/main/java/com/zhentao/user/controller/UserController.java

@@ -51,4 +51,11 @@ public class UserController {
     public Result loginnote(){
         return userService.getUser();
     }
+
+    @PostMapping("updateLocation")
+    public Result updateLocation(@RequestHeader("token") String token, @RequestParam String jingdu, @RequestParam String weidu) {
+        String userIdFromToken = TokenUtils.getUserIdFromToken(token);
+        Long userId = Long.parseLong(userIdFromToken);
+        return userService.updateUserLocation(userId, jingdu, weidu);
+    }
 }

+ 3 - 0
src/main/java/com/zhentao/user/domain/User.java

@@ -125,6 +125,9 @@ public class User implements Serializable {
      */
     private String salt;
 
+    private String jingdu;
+    private String weidu;
+
     @TableField(exist = false)
     private static final long serialVersionUID = 1L;
     private Integer grade;

+ 3 - 0
src/main/java/com/zhentao/user/service/UserService.java

@@ -20,4 +20,7 @@ public interface UserService extends IService<User> {
 
     Result adduser(String uid);
     Result getUser();
+
+    // 添加更新经纬度的方法
+    Result updateUserLocation(Long userId, String jingdu, String weidu);
 }

+ 15 - 0
src/main/java/com/zhentao/user/service/impl/UserServiceImpl.java

@@ -311,6 +311,21 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User>
     }
 
     @Override
+    public Result updateUserLocation(Long userId, String jingdu, String weidu) {
+        User user = this.getById(userId);
+        if (user == null) {
+            return Result.ERR(null, "用户不存在");
+        }
+        user.setJingdu(jingdu);
+        user.setWeidu(weidu);
+        boolean update = this.updateById(user);
+        if (update) {
+            return Result.OK(null, "经纬度更新成功");
+        } else {
+            return Result.ERR(null, "经纬度更新失败");
+        }
+    }
+    @Override
     public Result getUser() {
         List<User> list = this.list();
         return Result.OK(list,"查询成功");

+ 22 - 0
src/main/java/com/zhentao/volunteer/controller/VolunteerActivityController.java

@@ -1,8 +1,10 @@
 package com.zhentao.volunteer.controller;
 
 import com.zhentao.common.config.NullLogin;
+import com.zhentao.common.utils.TokenUtils;
 import com.zhentao.common.vo.Result;
 import com.zhentao.volunteer.dto.VolunteerActivityDto;
+import com.zhentao.volunteer.service.UserActiveService;
 import com.zhentao.volunteer.service.VolunteerActivityService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -14,6 +16,10 @@ public class VolunteerActivityController {
     @Autowired
     private VolunteerActivityService volunteerActivityService;
 
+
+    @Autowired
+    private UserActiveService userActiveService;
+
     // 根据类型id查询所有活动
     @PostMapping("findActivityByTypeId")
 
@@ -24,14 +30,30 @@ public class VolunteerActivityController {
 
     // 查询热点为0的支援活动
     @GetMapping("findHotActivities")
+
     public Result findHotActivity() {
         Result hotActivity = volunteerActivityService.findHotActivity();
         return Result.OK(hotActivity, "查询成功");
     }
 
     @GetMapping("findAll")
+    @NullLogin
     public Result findAll() {
         Result all = volunteerActivityService.findAll();
         return Result.OK(all, "查询成功");
     }
+
+    //用户报名
+    @GetMapping("signUp")
+    public Result signUp(@RequestHeader("token") String token, @RequestParam("activityId") Long activityId) {
+        // 获取当前登录用户的信息
+        String userIdFromToken = TokenUtils.getUserIdFromToken(token);
+        // 根据活动ID和用户ID报名活动
+        boolean b = userActiveService.signUpForActivity(activityId, Long.valueOf(userIdFromToken));
+        if (!b) {
+            return Result.ERR(b, "报名失败");
+        } else {
+            return Result.OK(b, "报名成功");
+        }
+    }
 }

+ 79 - 0
src/main/java/com/zhentao/volunteer/domain/UserActive.java

@@ -0,0 +1,79 @@
+package com.zhentao.volunteer.domain;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+/**
+ * 
+ * @TableName user_active
+ */
+@TableName(value ="user_active")
+@Data
+public class UserActive {
+    /**
+     * id
+     */
+    @TableId
+    private Long id;
+
+    /**
+     * 用户id
+     */
+    private Long userId;
+
+    /**
+     * 活动id
+     */
+    private Long activeId;
+
+    /**
+     * 活动人数未满(0 人数未满 1人数已满 2活动已结束)
+     */
+    private Integer status;
+
+    @Override
+    public boolean equals(Object that) {
+        if (this == that) {
+            return true;
+        }
+        if (that == null) {
+            return false;
+        }
+        if (getClass() != that.getClass()) {
+            return false;
+        }
+        UserActive other = (UserActive) that;
+        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
+            && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
+            && (this.getActiveId() == null ? other.getActiveId() == null : this.getActiveId().equals(other.getActiveId()))
+            && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()));
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
+        result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
+        result = prime * result + ((getActiveId() == null) ? 0 : getActiveId().hashCode());
+        result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
+        return result;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append(getClass().getSimpleName());
+        sb.append(" [");
+        sb.append("Hash = ").append(hashCode());
+        sb.append(", id=").append(id);
+        sb.append(", userId=").append(userId);
+        sb.append(", activeId=").append(activeId);
+        sb.append(", status=").append(status);
+        sb.append("]");
+        return sb.toString();
+    }
+}

+ 20 - 0
src/main/java/com/zhentao/volunteer/mapper/UserActiveMapper.java

@@ -0,0 +1,20 @@
+package com.zhentao.volunteer.mapper;
+
+import com.zhentao.volunteer.domain.UserActive;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import io.lettuce.core.dynamic.annotation.Param;
+
+/**
+* @author lenovo
+* @description 针对表【user_active】的数据库操作Mapper
+* @createDate 2025-07-07 19:34:37
+* @Entity com.zhentao.volunteer.domain.UserActive
+*/
+public interface UserActiveMapper extends BaseMapper<UserActive> {
+
+
+}
+
+
+
+

+ 4 - 0
src/main/java/com/zhentao/volunteer/mapper/VolunteerActivityDetailMapper.java

@@ -2,6 +2,9 @@ package com.zhentao.volunteer.mapper;
 
 import com.zhentao.volunteer.domain.VolunteerActivityDetail;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import io.lettuce.core.dynamic.annotation.Param;
+
+import java.time.LocalDateTime;
 
 /**
 * @author lenovo
@@ -11,6 +14,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 */
 public interface VolunteerActivityDetailMapper extends BaseMapper<VolunteerActivityDetail> {
 
+
 }
 
 

+ 14 - 0
src/main/java/com/zhentao/volunteer/service/UserActiveService.java

@@ -0,0 +1,14 @@
+package com.zhentao.volunteer.service;
+
+import com.zhentao.volunteer.domain.UserActive;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+* @author lenovo
+* @description 针对表【user_active】的数据库操作Service
+* @createDate 2025-07-07 19:34:37
+*/
+public interface UserActiveService extends IService<UserActive> {
+    //用户报名活动
+    boolean signUpForActivity(Long activityId, Long userId);
+}

+ 2 - 0
src/main/java/com/zhentao/volunteer/service/VolunteerActivityService.java

@@ -20,5 +20,7 @@ public interface VolunteerActivityService extends IService<VolunteerActivity> {
 
     //查询热点为0的志愿活动
     Result findHotActivity();
+
+
     Result findAll();
 }

+ 114 - 0
src/main/java/com/zhentao/volunteer/service/impl/UserActiveServiceImpl.java

@@ -0,0 +1,114 @@
+package com.zhentao.volunteer.service.impl;
+
+import cn.hutool.core.util.IdUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zhentao.volunteer.domain.UserActive;
+import com.zhentao.volunteer.domain.VolunteerActivity;
+import com.zhentao.volunteer.domain.VolunteerActivityDetail;
+import com.zhentao.volunteer.mapper.VolunteerActivityDetailMapper;
+import com.zhentao.volunteer.mapper.VolunteerActivityMapper;
+import com.zhentao.volunteer.service.UserActiveService;
+import com.zhentao.volunteer.mapper.UserActiveMapper;
+import com.zhentao.volunteer.service.VolunteerActivityDetailService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.annotation.AccessType;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.time.LocalDateTime;
+import java.util.Date;
+import java.util.UUID;
+
+/**
+* @author lenovo
+* @description 针对表【user_active】的数据库操作Service实现
+* @createDate 2025-07-07 19:34:37
+*/
+@Service
+public class UserActiveServiceImpl extends ServiceImpl<UserActiveMapper, UserActive>
+    implements UserActiveService{
+    // 中间表
+    @Autowired
+    private UserActiveMapper userActiveMapper;
+    @Autowired
+    private VolunteerActivityMapper volunteerActivityMapper;
+    // 活动
+    @Autowired
+    private VolunteerActivityDetailMapper volunteerActivityDetailMapper;
+    @Autowired
+    private VolunteerActivityDetailService volunteerActivityDetailService;
+    @Override
+    @Transactional
+    public boolean signUpForActivity(Long activityId, Long userId) {
+        // 检查用户是否已经报名该活动
+        QueryWrapper<UserActive> userActiveQueryWrapper = new QueryWrapper<>();
+        userActiveQueryWrapper.eq("user_id", userId).eq("active_id", activityId);
+        UserActive existingRecord = userActiveMapper.selectOne(userActiveQueryWrapper);
+        if (existingRecord != null) {
+            return false; // 用户已经报名该活动,返回失败
+        }
+
+        // 根据活动ID查询活动详情
+        VolunteerActivityDetail detail = volunteerActivityDetailMapper.selectById(activityId);
+        VolunteerActivity activity = volunteerActivityMapper.selectById(activityId);
+
+        if (detail != null && activity != null) {
+            // 检查活动是否已满
+            Integer maxParticipants = activity.getMaxParticipants();
+            Integer currentParticipants = detail.getCurrentParticipants();
+            if (currentParticipants == null) {
+                currentParticipants = 0;
+            }
+
+            if (maxParticipants != null && currentParticipants >= maxParticipants) {
+                // 活动已满,创建报名记录并设置状态为1(人数已满)
+                UserActive userActive = new UserActive();
+                userActive.setUserId(userId);
+                userActive.setActiveId(activityId);
+                userActive.setStatus(1);
+                userActiveMapper.insert(userActive);
+                return false;
+            }
+
+            // 检查活动是否已结束
+            Date endTime = activity.getEndTime();
+            if (endTime != null && new Date().after(endTime)) {
+                // 活动已结束,创建报名记录并设置状态为2(活动已结束)
+                UserActive userActive = new UserActive();
+                userActive.setUserId(userId);
+                userActive.setActiveId(activityId);
+                userActive.setStatus(2);
+                userActiveMapper.insert(userActive);
+                return false;
+            }
+
+            // 增加报名人数
+            detail.setCurrentParticipants(currentParticipants + 1);
+
+            // 检查是否已满
+            if (maxParticipants != null && currentParticipants + 1 >= maxParticipants) {
+                detail.setIsFull(1);
+            }
+
+            // 更新活动详情到数据库
+            boolean updateResult = volunteerActivityDetailService.updateById(detail);
+            if (updateResult) {
+                // 创建报名记录并设置状态为0(人数未满)
+                UserActive userActive = new UserActive();
+                long l = IdUtil.getSnowflake(1, 1).nextId();
+                userActive.setId(l);
+                userActive.setUserId(userId);
+                userActive.setActiveId(activityId);
+                userActive.setStatus(0);
+                userActiveMapper.insert(userActive);
+                return true;
+            }
+        }
+        return false;
+    }
+}
+
+
+
+

+ 20 - 0
src/main/resources/com/zhentao/volunteer/mapper/UserActiveMapper.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.zhentao.volunteer.mapper.UserActiveMapper">
+
+    <resultMap id="BaseResultMap" type="com.zhentao.volunteer.domain.UserActive">
+            <id property="id" column="id" />
+            <result property="userId" column="user_id" />
+            <result property="activeId" column="active_id" />
+            <result property="status" column="status" />
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        id,user_id,active_id,status
+    </sql>
+
+
+
+</mapper>

+ 26 - 23
src/main/resources/mapper/UserMapper.xml

@@ -5,28 +5,31 @@
 <mapper namespace="com.zhentao.user.mapper.UserMapper">
 
     <resultMap id="BaseResultMap" type="com.zhentao.user.domain.User">
-            <id property="id" column="id" jdbcType="BIGINT"/>
-            <result property="username" column="username" jdbcType="VARCHAR"/>
-            <result property="password" column="password" jdbcType="VARCHAR"/>
-            <result property="realName" column="real_name" jdbcType="VARCHAR"/>
-            <result property="phone" column="phone" jdbcType="VARCHAR"/>
-            <result property="email" column="email" jdbcType="VARCHAR"/>
-            <result property="avatar" column="avatar" jdbcType="VARCHAR"/>
-            <result property="gender" column="gender" jdbcType="TINYINT"/>
-            <result property="birthDate" column="birth_date" jdbcType="DATE"/>
-            <result property="status" column="status" jdbcType="TINYINT"/>
-            <result property="lastLoginTime" column="last_login_time" jdbcType="TIMESTAMP"/>
-            <result property="lastLoginIp" column="last_login_ip" jdbcType="VARCHAR"/>
-            <result property="lastLoginDevice" column="last_login_device" jdbcType="VARCHAR"/>
-            <result property="faceDataId" column="face_data_id" jdbcType="VARCHAR"/>
-            <result property="faceImageUrl" column="face_image_url" jdbcType="VARCHAR"/>
-            <result property="faceLoginEnabled" column="face_login_enabled" jdbcType="TINYINT"/>
-            <result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
-            <result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
-            <result property="deleted" column="deleted" jdbcType="TINYINT"/>
-            <result property="salt" column="salt" jdbcType="VARCHAR"/>
-            <result property="grade" column="grade" javaType="int"/>
-            <result property="attention" column="attention" javaType="int"/>
+        <id property="id" column="id" jdbcType="BIGINT"/>
+        <result property="username" column="username" jdbcType="VARCHAR"/> <!-- 保持不变,MyBatis支持VARCHAR -->
+        <result property="password" column="password" jdbcType="VARCHAR"/>
+        <result property="realName" column="real_name" jdbcType="VARCHAR"/>
+        <result property="phone" column="phone" jdbcType="VARCHAR"/>
+        <result property="email" column="email" jdbcType="VARCHAR"/>
+        <result property="avatar" column="avatar" jdbcType="VARCHAR"/>
+        <result property="gender" column="gender" jdbcType="TINYINT"/>
+        <result property="birthDate" column="birth_date" jdbcType="DATE"/>
+        <result property="status" column="status" jdbcType="TINYINT"/>
+        <result property="lastLoginTime" column="last_login_time" jdbcType="TIMESTAMP"/>
+        <result property="lastLoginIp" column="last_login_ip" jdbcType="VARCHAR"/>
+        <result property="lastLoginDevice" column="last_login_device" jdbcType="VARCHAR"/>
+        <result property="faceDataId" column="face_data_id" jdbcType="VARCHAR"/>
+        <result property="faceImageUrl" column="face_image_url" jdbcType="VARCHAR"/>
+        <result property="faceLoginEnabled" column="face_login_enabled" jdbcType="TINYINT"/>
+        <result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
+        <result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
+        <result property="deleted" column="deleted" jdbcType="TINYINT"/>
+        <result property="salt" column="salt" jdbcType="VARCHAR"/>
+        <result property="grade" column="grade" javaType="int" jdbcType="INTEGER"/> <!-- 添加jdbcType -->
+        <result property="attention" column="attention" javaType="int" jdbcType="INTEGER"/> <!-- 添加jdbcType -->
+        <result property="jingdu" column="jingdu" javaType="java.lang.String"/> <!-- 修正为全限定类名 -->
+        <result property="weidu" column="weidu" javaType="java.lang.String"/> <!-- 修正为全限定类名 -->
+
     </resultMap>
 
     <sql id="Base_Column_List">
@@ -36,6 +39,6 @@
         status,last_login_time,last_login_ip,
         last_login_device,face_data_id,face_image_url,
         face_login_enabled,created_at,updated_at,
-        deleted,salt,grade,attention
+        deleted,salt,grade,attention,jingdu,weidu
     </sql>
 </mapper>

+ 3 - 0
src/main/resources/mapper/VolunteerActivityDetailMapper.xml

@@ -67,4 +67,7 @@
         estimated_cost,actual_cost,cost_description,
         deleted
     </sql>
+
+
+
 </mapper>