Commit f2954a9f authored by jiatao's avatar jiatao

1:添加签到的时间验证

2:添加签到的经纬度验证
3:添加用户查看历史记录的接口
parent 9cd0439a
...@@ -235,7 +235,7 @@ public class CasAuthService { ...@@ -235,7 +235,7 @@ public class CasAuthService {
if (StringUtils.isNull(role)){ if (StringUtils.isNull(role)){
throw new ServiceException("分配角色信息为空,请联系管理员"); throw new ServiceException("分配角色信息为空,请联系管理员");
} }
user.setUserType(identityTypeCode.getCode());
user.setRoleIds(new Long[]{role.getRoleId()}); user.setRoleIds(new Long[]{role.getRoleId()});
if (StringUtils.isNotEmpty(userInfo.getOrganizationCode())){ if (StringUtils.isNotEmpty(userInfo.getOrganizationCode())){
......
...@@ -12,9 +12,11 @@ import com.ruoyi.common.utils.SecurityUtils; ...@@ -12,9 +12,11 @@ import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.ReservationApproval; import com.ruoyi.system.domain.ReservationApproval;
import com.ruoyi.system.domain.SpaceSeat; import com.ruoyi.system.domain.SpaceSeat;
import com.ruoyi.system.domain.vo.Location;
import com.ruoyi.system.service.IReservationApprovalService; import com.ruoyi.system.service.IReservationApprovalService;
import com.ruoyi.system.service.ISpaceSeatService; import com.ruoyi.system.service.ISpaceSeatService;
import com.ruoyi.system.service.ISysUserService; import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.system.task.verifySignApproval.VerifySignApprovalProcessorWithLocation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -41,6 +43,9 @@ public class ReservationApprovalController extends BaseController { ...@@ -41,6 +43,9 @@ public class ReservationApprovalController extends BaseController {
@Autowired @Autowired
private ISysUserService userService; private ISysUserService userService;
@Autowired
private VerifySignApprovalProcessorWithLocation verifySignApprovalProcessor;
@PreAuthorize("@ss.hasPermi('system:approval:list')") @PreAuthorize("@ss.hasPermi('system:approval:list')")
@GetMapping("/list") @GetMapping("/list")
...@@ -102,16 +107,14 @@ public class ReservationApprovalController extends BaseController { ...@@ -102,16 +107,14 @@ public class ReservationApprovalController extends BaseController {
List<ReservationApproval> list = reservationApprovalService.list(new LambdaQueryWrapper<ReservationApproval>() List<ReservationApproval> list = reservationApprovalService.list(new LambdaQueryWrapper<ReservationApproval>()
.eq(ReservationApproval::getSubmitBy,SecurityUtils.getUsername()) .eq(ReservationApproval::getSubmitBy,SecurityUtils.getUsername())
.in(ReservationApproval::getStatus, ApprovalStatus.PASS.getCode(),ApprovalStatus.WAITING.getCode(),ApprovalStatus.ALREADY_SIGN.getCode()) .in(ReservationApproval::getStatus, ApprovalStatus.PASS.getCode(),ApprovalStatus.WAITING.getCode())
.ge(ReservationApproval::getStartAt,new Date()) .ge(ReservationApproval::getStartAt,new Date()))
.last("limit 0,3"))
//按特定顺序排序 待签到 -> 待审核 -> 已签到 //按特定顺序排序 待签到 -> 待审核 -> 已签到
.stream().sorted(Comparator.comparingInt(r->{ .stream().sorted(Comparator.comparingInt(r->{
int status = Integer.parseInt(r.getStatus()); int status = Integer.parseInt(r.getStatus());
if (status == 1) return 0; if (status == 1) return 0;
else if (status == 0) return 1; else if (status == 0) return 1;
else if (status == 2) return 2; else return 2;
else return 3;
})).collect(Collectors.toList()); })).collect(Collectors.toList());
...@@ -128,6 +131,42 @@ public class ReservationApprovalController extends BaseController { ...@@ -128,6 +131,42 @@ public class ReservationApprovalController extends BaseController {
return AjaxResult.success(list); return AjaxResult.success(list);
} }
/**
* 最近预约
* @return
*/
@PreAuthorize("@ss.hasPermi('system:approval:RecentReservation')")
@GetMapping("/myHistories")
public TableDataInfo myHistories(ReservationApproval reservationApproval){
startPage();
List<ReservationApproval> list = reservationApprovalService.list(new LambdaQueryWrapper<ReservationApproval>()
.eq(ReservationApproval::getSubmitBy,SecurityUtils.getUsername())
.eq(StringUtils.isNotEmpty(reservationApproval.getSeatCode()),ReservationApproval::getSeatCode,reservationApproval.getSeatCode())
.eq(StringUtils.isNotEmpty(reservationApproval.getStatus()),ReservationApproval::getStatus,reservationApproval.getStatus())
.lt(StringUtils.isNotNull(reservationApproval.getEndAt()),ReservationApproval::getEndAt,reservationApproval.getEndAt())
.ge(StringUtils.isNotNull(reservationApproval.getStartAt()),ReservationApproval::getStartAt,reservationApproval.getStartAt())
.orderByDesc(ReservationApproval::getStartAt));
List<String> seatCodes = list.stream().map(ReservationApproval::getSeatCode).collect(Collectors.toList());
Map<String, SpaceSeat> spaceSeatMap = spaceSeatService.selectSpaceSeatByCodes(seatCodes)
.stream().collect(Collectors.toMap(SpaceSeat::getSeatCode, Function.identity()));
for (ReservationApproval approval : list) {
approval.setSpaceSeat(spaceSeatMap.getOrDefault(approval.getSeatCode(),new SpaceSeat()));
}
return getDataTable(list);
}
/** /**
* 提交审核 * 提交审核
* @param reservationApproval * @param reservationApproval
...@@ -186,22 +225,51 @@ public class ReservationApprovalController extends BaseController { ...@@ -186,22 +225,51 @@ public class ReservationApprovalController extends BaseController {
@PostMapping("/sign/{approvalId}") @PostMapping("/sign/{approvalId}")
public AjaxResult sign(@PathVariable("approvalId") Long approvalId){ public AjaxResult sign(@PathVariable("approvalId") Long approvalId){
ReservationApproval reservationApproval = reservationApprovalService.getById(approvalId); ReservationApproval reservationApproval = reservationApprovalService.getById(approvalId);
if (StringUtils.isNull(reservationApproval)){ if (StringUtils.isNull(reservationApproval)){
throw new ServiceException("参数错误,查询不到指定的申请"); throw new ServiceException("参数错误,查询不到指定的申请");
} }
Date currDate = new Date(); // 获取座位和房间信息(在Controller层获取)
if (currDate.getTime() < DateUtil.offsetMinute(reservationApproval.getStartAt(),-10).getTime()){ SpaceSeat spaceSeat = spaceSeatService.getSpaceSeatWithRoom(reservationApproval.getSeatCode());
throw new ServiceException("还未到签到时间"); if (spaceSeat == null) {
throw new ServiceException("座位信息不存在");
}
// 使用验证器验证签到规则
verifySignApprovalProcessor.verifySignRule(reservationApproval);
reservationApproval.setStatus(ApprovalStatus.ALREADY_SIGN.getCode());
return AjaxResult.success(reservationApprovalService.updateById(reservationApproval));
}
/**
* 带位置验证的签到
* @param approvalId 预约ID
* @param location 用户位置信息
* @return
*/
@PreAuthorize("@ss.hasPermi('system:approval:submit')")
@PostMapping("/signWithLocation/{approvalId}")
public AjaxResult signWithLocation(@PathVariable("approvalId") Long approvalId, @RequestBody Location location){
ReservationApproval reservationApproval = reservationApprovalService.getById(approvalId);
if (StringUtils.isNull(reservationApproval)){
throw new ServiceException("参数错误,查询不到指定的申请");
} }
if (currDate.getTime() > reservationApproval.getEndAt().getTime()){ // 获取座位和房间信息(在Controller层获取)
throw new ServiceException("已过签到时间"); SpaceSeat spaceSeat = spaceSeatService.getSpaceSeatWithRoom(reservationApproval.getSeatCode());
if (spaceSeat == null) {
throw new ServiceException("座位信息不存在");
} }
// 使用验证器验证签到规则(包含位置验证)
verifySignApprovalProcessor.verifySignRuleWithLocation(reservationApproval, location);
reservationApproval.setStatus(ApprovalStatus.ALREADY_SIGN.getCode()); reservationApproval.setStatus(ApprovalStatus.ALREADY_SIGN.getCode());
......
package com.ruoyi.system.cas; package com.ruoyi.system.cas;
import lombok.Data;
import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
......
...@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; ...@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.ruoyi.common.utils.DictUtils; import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.vo.OpenTime; import com.ruoyi.system.domain.vo.OpenTime;
import com.ruoyi.system.domain.vo.Location;
import com.ruoyi.system.service.impl.SchoolBuildServiceImpl; import com.ruoyi.system.service.impl.SchoolBuildServiceImpl;
import com.ruoyi.system.service.impl.SchoolCampusServiceImpl; import com.ruoyi.system.service.impl.SchoolCampusServiceImpl;
import com.ruoyi.system.service.impl.SchoolFloorServiceImpl; import com.ruoyi.system.service.impl.SchoolFloorServiceImpl;
...@@ -15,6 +16,7 @@ import com.ruoyi.common.annotation.Excel; ...@@ -15,6 +16,7 @@ import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity; import com.ruoyi.common.core.domain.BaseEntity;
import java.util.List; import java.util.List;
import java.util.Optional;
/** /**
* 房间对象 space * 房间对象 space
...@@ -65,6 +67,10 @@ public class Space extends BaseEntity ...@@ -65,6 +67,10 @@ public class Space extends BaseEntity
@TableField(value = "open_time",typeHandler = JacksonTypeHandler.class) @TableField(value = "open_time",typeHandler = JacksonTypeHandler.class)
private OpenTime openTime; private OpenTime openTime;
/** 经纬度信息 */
@TableField(value = "location",typeHandler = JacksonTypeHandler.class)
private Location location;
/** 最小预约时长/分钟 */ /** 最小预约时长/分钟 */
@Excel(name = "最小预约时长/分钟") @Excel(name = "最小预约时长/分钟")
private Long miniMumDuration; private Long miniMumDuration;
...@@ -166,6 +172,10 @@ public class Space extends BaseEntity ...@@ -166,6 +172,10 @@ public class Space extends BaseEntity
} }
public Location getLocation() {
return Optional.ofNullable(location).orElse(new Location());
}
public String getCampusName(){ public String getCampusName(){
if (StringUtils.isNotEmpty(this.campusCode)){ if (StringUtils.isNotEmpty(this.campusCode)){
......
...@@ -42,7 +42,7 @@ public class SpaceSeat extends BaseEntity ...@@ -42,7 +42,7 @@ public class SpaceSeat extends BaseEntity
@TableField(value = "del_flag",fill = FieldFill.INSERT) @TableField(value = "del_flag",fill = FieldFill.INSERT)
private String delFlag; private String delFlag;
@TableField @TableField(exist = false)
private Space space; private Space space;
/** /**
......
package com.ruoyi.system.domain.vo;
import lombok.Data;
/**
* 经纬度对象
*
* @author ruoyi
*/
@Data
public class Location {
/** 纬度 */
private Double latitude;
/** 经度 */
private Double longitude;
public Location() {
}
public Location(Double latitude, Double longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
/**
* 计算两点之间的距离(单位:米)
* 使用Haversine公式计算球面距离
*
* @param anotherLocation 另一个位置点
* @return 距离(米)
*/
public Double distanceTo(Location anotherLocation) {
if (anotherLocation == null || latitude == null || longitude == null
|| anotherLocation.getLatitude() == null || anotherLocation.getLongitude() == null) {
return null;
}
double lat1 = Math.toRadians(latitude);
double lon1 = Math.toRadians(longitude);
double lat2 = Math.toRadians(anotherLocation.getLatitude());
double lon2 = Math.toRadians(anotherLocation.getLongitude());
double dLat = lat2 - lat1;
double dLon = lon2 - lon1;
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(lat1) * Math.cos(lat2) *
Math.sin(dLon / 2) * Math.sin(dLon / 2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
// 地球半径(米)
double earthRadius = 6371000;
return earthRadius * c;
}
}
\ No newline at end of file
...@@ -76,4 +76,12 @@ public interface ISpaceSeatService extends IService<SpaceSeat> ...@@ -76,4 +76,12 @@ public interface ISpaceSeatService extends IService<SpaceSeat>
* @return 结果 * @return 结果
*/ */
public Boolean deleteSpaceSeatBySeatId(Long seatId); public Boolean deleteSpaceSeatBySeatId(Long seatId);
/**
* 根据座位编码获取座位信息(包含房间信息)
*
* @param seatCode 座位编码
* @return 座位信息(包含房间信息)
*/
public SpaceSeat getSpaceSeatWithRoom(String seatCode);
} }
...@@ -14,7 +14,6 @@ import com.ruoyi.common.utils.StringUtils; ...@@ -14,7 +14,6 @@ import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.uuid.IdUtils; import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.system.domain.Space; import com.ruoyi.system.domain.Space;
import com.ruoyi.system.mapper.SpaceMapper; import com.ruoyi.system.mapper.SpaceMapper;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SpaceSeatMapper; import com.ruoyi.system.mapper.SpaceSeatMapper;
...@@ -157,4 +156,29 @@ public class SpaceSeatServiceImpl extends ServiceImpl<SpaceSeatMapper,SpaceSeat> ...@@ -157,4 +156,29 @@ public class SpaceSeatServiceImpl extends ServiceImpl<SpaceSeatMapper,SpaceSeat>
{ {
return removeById(seatId); return removeById(seatId);
} }
/**
* 根据座位编码获取座位信息(包含房间信息)
*
* @param seatCode 座位编码
* @return 座位信息(包含房间信息)
*/
@Override
public SpaceSeat getSpaceSeatWithRoom(String seatCode)
{
SpaceSeat spaceSeat = this.getOne(
new LambdaQueryWrapper<SpaceSeat>()
.eq(SpaceSeat::getSeatCode, seatCode)
);
if (spaceSeat != null && StringUtils.isNotEmpty(spaceSeat.getSpaceCode())) {
Space space = spaceMapper.selectOne(
new LambdaQueryWrapper<Space>()
.eq(Space::getSpaceCode, spaceSeat.getSpaceCode())
);
spaceSeat.setSpace(space);
}
return spaceSeat;
}
} }
package com.ruoyi.system.task.verifyReservationApproval; package com.ruoyi.system.task.verifyReservationApproval.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.enums.ApprovalStatus; import com.ruoyi.common.enums.ApprovalStatus;
...@@ -7,6 +7,7 @@ import com.ruoyi.common.utils.SecurityUtils; ...@@ -7,6 +7,7 @@ import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.ReservationApproval; import com.ruoyi.system.domain.ReservationApproval;
import com.ruoyi.system.service.IReservationApprovalService; import com.ruoyi.system.service.IReservationApprovalService;
import com.ruoyi.system.service.ISysConfigService; import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.task.verifyReservationApproval.VerifyReservationApprovalProcessor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
......
package com.ruoyi.system.task.verifyReservationApproval; package com.ruoyi.system.task.verifyReservationApproval.impl;
import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.ReservationApproval; import com.ruoyi.system.domain.ReservationApproval;
import com.ruoyi.system.service.IReservationApprovalService; import com.ruoyi.system.service.IReservationApprovalService;
import com.ruoyi.system.task.verifyReservationApproval.VerifyReservationApprovalProcessor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
......
package com.ruoyi.system.task.verifyReservationApproval; package com.ruoyi.system.task.verifyReservationApproval.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
...@@ -8,6 +8,7 @@ import com.ruoyi.system.domain.ReservationApproval; ...@@ -8,6 +8,7 @@ import com.ruoyi.system.domain.ReservationApproval;
import com.ruoyi.system.domain.ReservationBlacklist; import com.ruoyi.system.domain.ReservationBlacklist;
import com.ruoyi.system.service.IReservationBlacklistService; import com.ruoyi.system.service.IReservationBlacklistService;
import com.ruoyi.system.task.verifyReservationApproval.VerifyReservationApprovalProcessor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -20,7 +21,7 @@ import java.util.Date; ...@@ -20,7 +21,7 @@ import java.util.Date;
*/ */
@Component @Component
@Order(2) @Order(2)
public class BlackListProcessor implements VerifyReservationApprovalProcessor{ public class BlackListProcessor implements VerifyReservationApprovalProcessor {
@Autowired @Autowired
......
package com.ruoyi.system.task.verifyReservationApproval; package com.ruoyi.system.task.verifyReservationApproval.impl;
import cn.hutool.core.date.LocalDateTimeUtil; import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
...@@ -7,20 +7,18 @@ import com.ruoyi.common.exception.ServiceException; ...@@ -7,20 +7,18 @@ import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.system.domain.ReservationApproval; import com.ruoyi.system.domain.ReservationApproval;
import com.ruoyi.system.service.IReservationApprovalService; import com.ruoyi.system.service.IReservationApprovalService;
import com.ruoyi.system.service.ISysConfigService; import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.task.verifyReservationApproval.VerifyReservationApprovalProcessor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
/** /**
* 违约次数校验 * 违约次数校验
*/ */
@Component @Component
@Order(1) @Order(1)
public class DefaultApprovalProcessor implements VerifyReservationApprovalProcessor{ public class DefaultApprovalProcessor implements VerifyReservationApprovalProcessor {
@Autowired @Autowired
......
package com.ruoyi.system.task.verifySignApproval;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.system.domain.ReservationApproval;
import com.ruoyi.system.domain.Space;
import com.ruoyi.system.domain.SpaceSeat;
import com.ruoyi.system.domain.vo.Location;
import com.ruoyi.system.service.ISpaceSeatService;
import com.ruoyi.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* 签到位置验证器
*
* @author ruoyi
*/
@Component
public class SignLocationVerifier {
@Autowired
private ISpaceSeatService spaceSeatService;
@Autowired
private ISysConfigService configService;
/** 最大允许距离(米) */
private static final Double DEFAULT_DISTANCE = 100.0;
/**
* 验证位置信息
*
* @param approval 预约审批信息
* @param userLocation 用户当前位置
*/
public void verifyLocation(ReservationApproval approval, Location userLocation) {
if (userLocation == null) {
// 未提供用户位置,跳过位置验证
return;
}
// 获取座位和房间信息
SpaceSeat spaceSeat = spaceSeatService.getSpaceSeatWithRoom(approval.getSeatCode());
if (spaceSeat == null) {
throw new ServiceException("座位信息不存在");
}
Space space = spaceSeat.getSpace();
if (space == null) {
throw new ServiceException("房间信息不存在");
}
// 检查房间是否设置了经纬度
if (space.getLocation() == null || space.getLocation().getLatitude() == null || space.getLocation().getLongitude() == null) {
// 房间未设置位置信息,跳过位置验证
return;
}
String distanceConfig = configService.selectConfigByKey("sign_distance");
Double maxDistance = parseDoubleConfig(distanceConfig);
// 计算距离
Double distance = space.getLocation().distanceTo(userLocation);
if (distance != null && distance > maxDistance) {
throw new ServiceException("距离房间位置超过" + maxDistance + "米,无法签到");
}
}
/**
* 解析配置参数为整数
*/
public static Double parseDoubleConfig(String configValue) {
if (configValue == null || configValue.trim().isEmpty()) {
return DEFAULT_DISTANCE;
}
try {
return Double.parseDouble(configValue.trim());
} catch (NumberFormatException e) {
return DEFAULT_DISTANCE;
}
}
}
\ No newline at end of file
package com.ruoyi.system.task.verifySignApproval;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.ReservationApproval;
import com.ruoyi.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
@Component
public class SignTimeVerifier {
@Autowired
private ISysConfigService configService;
/**
* 验证签到时间
*
* @param approval 预约审批信息
*/
public void verifySignTime(ReservationApproval approval) {
Date currentTime = new Date();
Date startTime = approval.getStartAt();
Date endTime = approval.getEndAt();
if (startTime == null || endTime == null) {
throw new ServiceException("预约时间信息不完整");
}
// 获取配置参数
String signBeforeStartTimeStr = configService.selectConfigByKey("sign_before_start_time");
String signBeforeEndTimeStr = configService.selectConfigByKey("sign_before_end_time");
int signBeforeStartTime = parseIntConfig(signBeforeStartTimeStr, 10); // 默认10分钟
int signBeforeEndTime = parseIntConfig(signBeforeEndTimeStr, 10); // 默认10分钟
// 计算允许签到的开始时间(预约开始时间前 signBeforeStartTime 分钟)
Date signStartTime = DateUtils.addMinutes(startTime, -signBeforeStartTime);
// 计算允许签到的结束时间(预约结束时间前 signBeforeEndTime 分钟)
Date signEndTime = DateUtils.addMinutes(endTime, -signBeforeEndTime);
// 验证当前时间是否在允许签到的时间范围内
if (currentTime.before(signStartTime)) {
throw new ServiceException("签到时间未到,请在预约开始前" + signBeforeStartTime + "分钟内签到");
}
if (currentTime.after(signEndTime)) {
throw new ServiceException("签到时间已过,无法签到");
}
}
/**
* 解析配置参数为整数
*/
public static int parseIntConfig(String configValue, int defaultValue) {
if (configValue == null || configValue.trim().isEmpty()) {
return defaultValue;
}
try {
return Integer.parseInt(configValue.trim());
} catch (NumberFormatException e) {
return defaultValue;
}
}
}
package com.ruoyi.system.task.verifySignApproval;
import com.ruoyi.system.domain.ReservationApproval;
public interface VerifySignApprovalProcessor {
/**
* 校验
* @param approval
*/
public void verifySignRule(ReservationApproval approval);
}
package com.ruoyi.system.task.verifySignApproval;
import com.ruoyi.system.domain.ReservationApproval;
import com.ruoyi.system.domain.vo.Location;
/**
* 带位置验证的签到验证处理器接口
*
* @author ruoyi
*/
public interface VerifySignApprovalProcessorWithLocation extends VerifySignApprovalProcessor {
/**
* 校验签到规则(包含位置验证)
*
* @param approval 预约审批信息
* @param userLocation 用户当前位置
*/
void verifySignRuleWithLocation(ReservationApproval approval, Location userLocation);
}
\ No newline at end of file
package com.ruoyi.system.task.verifySignApproval.impl;
import com.ruoyi.system.domain.ReservationApproval;
import com.ruoyi.system.domain.vo.Location;
import com.ruoyi.system.service.ISpaceSeatService;
import com.ruoyi.system.task.verifySignApproval.SignLocationVerifier;
import com.ruoyi.system.task.verifySignApproval.SignTimeVerifier;
import com.ruoyi.system.task.verifySignApproval.VerifySignApprovalProcessor;
import com.ruoyi.system.task.verifySignApproval.VerifySignApprovalProcessorWithLocation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* 签到验证处理器实现类
*
* @author ruoyi
*/
@Component
public class VerifySignApprovalProcessorImpl implements VerifySignApprovalProcessor, VerifySignApprovalProcessorWithLocation {
@Autowired
private SignTimeVerifier signTimeVerifier;
@Autowired
private SignLocationVerifier signLocationVerifier;
@Override
public void verifySignRule(ReservationApproval approval) {
// 验证签到时间
signTimeVerifier.verifySignTime(approval);
}
@Override
public void verifySignRuleWithLocation(ReservationApproval approval, Location userLocation) {
// 先验证时间
signTimeVerifier.verifySignTime(approval);
// 再验证位置
signLocationVerifier.verifyLocation(approval, userLocation);
}
}
\ No newline at end of file
...@@ -67,6 +67,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -67,6 +67,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="userName != null and userName != ''"> <if test="userName != null and userName != ''">
AND u.user_name like concat('%', #{userName}, '%') AND u.user_name like concat('%', #{userName}, '%')
</if> </if>
<if test="nickName != null and nickName != ''">
AND u.nick_name like concat('%',#{nickName},'%')
</if>
<if test="status != null and status != ''"> <if test="status != null and status != ''">
AND u.status = #{status} AND u.status = #{status}
</if> </if>
...@@ -82,7 +85,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -82,7 +85,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="deptId != null and deptId != 0"> <if test="deptId != null and deptId != 0">
AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId}, ancestors) )) AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId}, ancestors) ))
</if> </if>
<if test="userName != null and userNames.size >0 "> <if test="userNames != null and userNames.size >0 ">
AND u.user_name in AND u.user_name in
<foreach collection="userNames" item="item" open="(" close=")" separator=","> <foreach collection="userNames" item="item" open="(" close=")" separator=",">
#{item} #{item}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment