Pārlūkot izejas kodu

1排班验证志愿者身份,2排班只能设置当天及以后,3客户看见排班时间只能看见今天及其以后

wangwl 1 mēnesi atpakaļ
vecāks
revīzija
e82d4a08aa

+ 6 - 2
leromro-core/src/main/java/com/leromro/core/controller/VolunteerWorkDateController.java

@@ -5,6 +5,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.stream.Collectors;
 import javax.servlet.http.HttpServletResponse;
+import javax.validation.Valid;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
@@ -22,6 +23,8 @@ import io.swagger.annotations.ApiOperation;
 import org.springframework.format.annotation.DateTimeFormat;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.ObjectError;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import com.leromro.common.annotation.Log;
 import com.leromro.common.core.controller.BaseController;
@@ -55,7 +58,7 @@ public class VolunteerWorkDateController extends BaseController
     @ApiOperation("修改志愿者排班日期及时间")
     @Log(title = "志愿者排班日期", businessType = BusinessType.UPDATE)
     @PutMapping
-    public AjaxResult edit(@RequestBody List<VolunteerWorkDate> list)
+    public AjaxResult edit(@RequestBody @Valid List<VolunteerWorkDate> list)
     {
         return volunteerWorkDateService.updateVolunteerWorkDate(list);
     }
@@ -82,7 +85,8 @@ public class VolunteerWorkDateController extends BaseController
     @GetMapping("/getVolunteerWorkDate")
     public R<List<LocalDate>> getVolunteerWorkDate(@RequestParam("volunteerId") Long volunteerId) {
         List<LocalDate> list = volunteerWorkDateService.list(new LambdaQueryWrapper<VolunteerWorkDate>()
-                .eq(VolunteerWorkDate::getVolunteerId, volunteerId))
+                .eq(VolunteerWorkDate::getVolunteerId, volunteerId)
+                .ge(VolunteerWorkDate::getWorkDate, LocalDate.now()))
                 .stream().map(VolunteerWorkDate::getWorkDate).sorted().collect(Collectors.toList());
         return R.ok(list);
     }

+ 5 - 0
leromro-core/src/main/java/com/leromro/core/domain/VolunteerWorkDate.java

@@ -13,6 +13,8 @@ import lombok.*;
 import com.leromro.common.annotation.Excel;
 import com.leromro.common.core.domain.BaseEntity;
 
+import javax.validation.constraints.NotNull;
+
 /**
  * 志愿者排班日期对象 l_volunteer_work_date
  * 
@@ -40,16 +42,19 @@ public class VolunteerWorkDate extends BaseEntity
     private Long volunteerId;
 
     /** 排班日期 */
+    @NotNull(message = "排班日期不能为空")
     @JsonFormat(pattern = "yyyy-MM-dd")
     @ApiModelProperty("排班日期")
     private LocalDate workDate;
 
     /** 工作开始时间 */
+    @NotNull(message = "工作开始时间不能为空")
     @JsonFormat(pattern = "H:mm")
     @ApiModelProperty("工作开始时间")
     private LocalTime workStartTime;
 
     /** 工作结束时间 */
+    @NotNull(message = "工作结束时间不能为空")
     @JsonFormat(pattern = "H:mm")
     @ApiModelProperty("工作结束时间")
     private LocalTime workEndTime;

+ 2 - 2
leromro-core/src/main/java/com/leromro/core/facade/VolunteerWorkDateFacade.java

@@ -57,9 +57,9 @@ public class VolunteerWorkDateFacade {
             VolunteerReservationTimeVO vo = VolunteerReservationTimeVO.builder()
                     .reservationTime(startTime)
                     .build();
-            if (times.contains(startTime)){
+            if (times.contains(startTime) || startTime.isBefore(LocalTime.now())){
                 vo.setHasReservation(1);
-                vo.setClientId(timeMapUser.get(startTime));
+//                vo.setClientId(timeMapUser.get(startTime));
             }else {
                 vo.setHasReservation(0);
             }

+ 21 - 3
leromro-core/src/main/java/com/leromro/core/service/impl/VolunteerWorkDateServiceImpl.java

@@ -15,8 +15,10 @@ import com.leromro.common.core.domain.AjaxResult;
 import com.leromro.common.core.domain.R;
 import com.leromro.common.exception.ServiceException;
 import com.leromro.common.utils.SecurityUtils;
+import com.leromro.core.domain.VolunteerInfo;
 import com.leromro.core.mapper.VolunteerWorkDateMapper;
 import com.leromro.common.utils.DateUtils;
+import com.leromro.core.service.IVolunteerInfoService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.leromro.core.mapper.VolunteerWorkDateMapper;
@@ -36,6 +38,9 @@ public class VolunteerWorkDateServiceImpl extends ServiceImpl<VolunteerWorkDateM
     @Autowired
     private VolunteerWorkDateMapper volunteerWorkDateMapper;
 
+    @Autowired
+    private IVolunteerInfoService volunteerInfoService;
+
     /**
      * 查询志愿者排班日期
      * 
@@ -84,10 +89,22 @@ public class VolunteerWorkDateServiceImpl extends ServiceImpl<VolunteerWorkDateM
     {
         // 获取当前用户信息
         Long userId = SecurityUtils.getUserId();
-        // 查询出所有已经预约的日期
+        //判断当前用户是否已经注册了志愿者
+        List<VolunteerInfo> infos = volunteerInfoService.list(new LambdaQueryWrapper<VolunteerInfo>()
+                .eq(VolunteerInfo::getUserId, userId));
+        if (CollectionUtil.isEmpty(infos)){
+            return AjaxResult.error("您还未注册为志愿者,请先注册");
+        }
+        //判断是否排了今天之前的日期
+        LocalDate workDate = list.get(0).getWorkDate();
+        if (workDate.isBefore(LocalDate.now())){
+            return AjaxResult.error("排班日期不能设置为今天以前");
+        }
+        // 查询出所有已经预约的日期,今天和今天以后的
         List<VolunteerWorkDate> reservationList = this.list(new LambdaQueryWrapper<VolunteerWorkDate>()
                 .eq(VolunteerWorkDate::getVolunteerId, userId)
-                .eq(VolunteerWorkDate::getHasReservation, 1));
+                .eq(VolunteerWorkDate::getHasReservation, 1)
+                .ge(VolunteerWorkDate::getWorkDate, LocalDate.now()));
         // 如果存在则判断已经预约的日期是否被删除,如果被删除则提示不能修改
         if (CollectionUtil.isNotEmpty(reservationList)){
             List<LocalDate> dates = list.stream().map(VolunteerWorkDate::getWorkDate).collect(Collectors.toList());
@@ -137,7 +154,8 @@ public class VolunteerWorkDateServiceImpl extends ServiceImpl<VolunteerWorkDateM
         // 获取当前用户信息
         Long userId = SecurityUtils.getUserId();
         List<VolunteerWorkDate> list = this.list(new LambdaQueryWrapper<VolunteerWorkDate>()
-                .eq(VolunteerWorkDate::getVolunteerId, userId));
+                .eq(VolunteerWorkDate::getVolunteerId, userId)
+                .ge(VolunteerWorkDate::getWorkDate, LocalDate.now()));
         return R.ok(list);
     }
 }