Compare commits
2 Commits
16626af8f2
...
2ac80ae4d0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ac80ae4d0 | ||
|
|
e5e540305d |
@@ -12,4 +12,11 @@ public class DeviceActivationRequest {
|
||||
@NotBlank(message = "MAC地址不能为空")
|
||||
private String mac;
|
||||
|
||||
@ApiModelProperty(value = "设备型号", required = true)
|
||||
@NotBlank(message = "设备型号不能为空")
|
||||
private String modelId;
|
||||
|
||||
@ApiModelProperty(value = "时间戳", required = true)
|
||||
private String timestamp;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.corewing.app.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SubmitActivityRequest {
|
||||
|
||||
@ApiModelProperty("活动id")
|
||||
private String activityId;
|
||||
|
||||
/* 创作平台 */
|
||||
@ApiModelProperty("创作平台")
|
||||
private String creationPlatform;
|
||||
|
||||
/* 提交内容 */
|
||||
@ApiModelProperty("提交内容")
|
||||
private String content;
|
||||
}
|
||||
71
src/main/java/com/corewing/app/entity/BizActivity.java
Normal file
71
src/main/java/com/corewing/app/entity/BizActivity.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package com.corewing.app.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.corewing.app.common.base.CommonEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 活动
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@TableName("biz_activity")
|
||||
public class BizActivity extends CommonEntity {
|
||||
|
||||
/* id */
|
||||
@TableId
|
||||
private String id;
|
||||
|
||||
/* 活动图 */
|
||||
private String thumbnail;
|
||||
|
||||
/* 活动标题 */
|
||||
private String title;
|
||||
|
||||
/* 活动描述 */
|
||||
private String description;
|
||||
|
||||
/* 活动分类 */
|
||||
private String category;
|
||||
|
||||
/* 活动平台 */
|
||||
private String platformCategory;
|
||||
|
||||
/* 活动人数 */
|
||||
private Integer participationCount;
|
||||
|
||||
/* 当前参与人数 */
|
||||
private Integer currentCount;
|
||||
|
||||
/* 活动详情 */
|
||||
private String content;
|
||||
|
||||
/* 活动开始时间 */
|
||||
private Date startTime;
|
||||
|
||||
/* 活动结束时间 */
|
||||
private Date endTime;
|
||||
|
||||
/* 活动状态 */
|
||||
private String status;
|
||||
|
||||
/* 是否开启活动参与人员审核 */
|
||||
private String personnelReview;
|
||||
|
||||
/* 活动排序 */
|
||||
private Integer sortCode;
|
||||
|
||||
/* 备注 */
|
||||
private String remark;
|
||||
|
||||
/* 扩展 */
|
||||
private String extJson;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.corewing.app.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.corewing.app.common.base.CommonEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@TableName("biz_activity_lottery")
|
||||
public class BizActivityLottery extends CommonEntity {
|
||||
|
||||
/* id */
|
||||
@TableId
|
||||
private String id;
|
||||
|
||||
/* 活动id */
|
||||
private String activityId;
|
||||
|
||||
/* 分类 */
|
||||
private String category;
|
||||
|
||||
/* 用户名 */
|
||||
private String userName;
|
||||
|
||||
/* 用户id */
|
||||
private Long userId;
|
||||
|
||||
/* 状态 */
|
||||
private String status;
|
||||
|
||||
/* 提交内容 */
|
||||
private String content;
|
||||
|
||||
/* 审核时间 */
|
||||
private Date reviewTime;
|
||||
|
||||
/* 创作平台 */
|
||||
private String creationPlatform;
|
||||
|
||||
/* 备注 */
|
||||
private String remark;
|
||||
|
||||
/* 排序 */
|
||||
private Integer sortCode;
|
||||
|
||||
/* 扩展字段 */
|
||||
private String extJson;
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import lombok.EqualsAndHashCode;
|
||||
* 设备表
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
|
||||
@Data
|
||||
@TableName("biz_device")
|
||||
public class BizDevice extends CommonEntity {
|
||||
@@ -28,6 +29,9 @@ public class BizDevice extends CommonEntity {
|
||||
@ApiModelProperty("公布状态")
|
||||
private String publicStatus;
|
||||
|
||||
@ApiModelProperty("型号")
|
||||
private String categoryId;
|
||||
|
||||
@ApiModelProperty("排序")
|
||||
private int sortCode;
|
||||
|
||||
|
||||
@@ -22,6 +22,9 @@ public class BizDeviceCategory extends CommonEntity {
|
||||
@ApiModelProperty("设备型号缩略图")
|
||||
private String thumbnail;
|
||||
|
||||
@ApiModelProperty("型号id")
|
||||
private Integer modelId;
|
||||
|
||||
@ApiModelProperty("设备型号名称")
|
||||
private String categoryName;
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.corewing.app.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.corewing.app.entity.BizActivityLottery;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface BizActivityLotteryMapper extends BaseMapper<BizActivityLottery> {
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.corewing.app.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.corewing.app.entity.BizActivity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface BizActivityMapper extends BaseMapper<BizActivity> {
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.corewing.app.modules.app;
|
||||
|
||||
import com.corewing.app.common.Result;
|
||||
import com.corewing.app.dto.SubmitActivityRequest;
|
||||
import com.corewing.app.service.BizActivityLotteryService;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Api(tags = "活动控制")
|
||||
@Controller
|
||||
@RequestMapping("/api/app/activity")
|
||||
public class AppActivityController {
|
||||
|
||||
@Resource
|
||||
private BizActivityLotteryService bizActivityLotteryService;
|
||||
|
||||
/**
|
||||
* 活动参与地址
|
||||
* @param activityId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/eventVenue/{activityId}")
|
||||
public String eventVenue(@PathVariable String activityId) {
|
||||
return "/activity/eventVenue";
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交活动
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/submitActivity")
|
||||
@ResponseBody
|
||||
public Result<String> submitActivity(SubmitActivityRequest submitActivityRequest) {
|
||||
return Result.isBool(bizActivityLotteryService.submitActivity(submitActivityRequest));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -31,5 +31,12 @@ public class AppDeviceController {
|
||||
return Result.success(activationService.activation(deviceActivationRequest));
|
||||
}
|
||||
|
||||
@CommonLog("工厂激活设备")
|
||||
@ApiOperation("工厂激活设备")
|
||||
@PostMapping("factoryActivation")
|
||||
public Result<Boolean> factoryActivation(@RequestBody DeviceActivationRequest deviceActivationRequest) {
|
||||
return Result.success(activationService.factoryActivation(deviceActivationRequest));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.corewing.app.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.corewing.app.dto.SubmitActivityRequest;
|
||||
import com.corewing.app.entity.BizActivityLottery;
|
||||
|
||||
public interface BizActivityLotteryService extends IService<BizActivityLottery> {
|
||||
|
||||
Boolean submitActivity(SubmitActivityRequest submitActivityRequest);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.corewing.app.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.corewing.app.entity.BizActivity;
|
||||
|
||||
public interface BizActivityService extends IService<BizActivity> {
|
||||
}
|
||||
@@ -6,4 +6,6 @@ import com.corewing.app.entity.BizDeviceActivation;
|
||||
|
||||
public interface BizDeviceActivationService extends IService<BizDeviceActivation> {
|
||||
Boolean activation(DeviceActivationRequest deviceActivationRequest);
|
||||
|
||||
Boolean factoryActivation(DeviceActivationRequest deviceActivationRequest);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.corewing.app.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.corewing.app.dto.SubmitActivityRequest;
|
||||
import com.corewing.app.entity.BizActivity;
|
||||
import com.corewing.app.entity.BizActivityLottery;
|
||||
import com.corewing.app.mapper.BizActivityLotteryMapper;
|
||||
import com.corewing.app.service.BizActivityLotteryService;
|
||||
import com.corewing.app.service.BizActivityService;
|
||||
import com.corewing.app.util.DateUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
public class BizActivityLotteryServiceImpl extends ServiceImpl<BizActivityLotteryMapper, BizActivityLottery> implements BizActivityLotteryService {
|
||||
|
||||
@Resource
|
||||
private BizActivityService bizActivityService;
|
||||
|
||||
@Override
|
||||
public Boolean submitActivity(SubmitActivityRequest submitActivityRequest) {
|
||||
|
||||
Long userid = StpUtil.getLoginIdAsLong();
|
||||
|
||||
BizActivity activity = bizActivityService.getById(submitActivityRequest.getActivityId());
|
||||
if(activity == null) {
|
||||
throw new RuntimeException("该活动不存在");
|
||||
}
|
||||
|
||||
// 验证活动是否在有效期内
|
||||
if(activity.getStartTime() != null && activity.getEndTime() != null) {
|
||||
if(!DateUtils.isBefore(activity.getStartTime())) {
|
||||
throw new RuntimeException("活动还未开始");
|
||||
}
|
||||
|
||||
if(!DateUtils.isAfter(activity.getEndTime())) {
|
||||
throw new RuntimeException("活动已过期");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 校验是否参与
|
||||
LambdaQueryWrapper<BizActivityLottery> checkLotteryWrapper = new LambdaQueryWrapper<>();
|
||||
checkLotteryWrapper.eq(BizActivityLottery::getUserId, userid);
|
||||
checkLotteryWrapper.eq(BizActivityLottery::getActivityId, submitActivityRequest.getActivityId());
|
||||
if(count(checkLotteryWrapper) > 0) {
|
||||
throw new RuntimeException("该活动你已经参与");
|
||||
}
|
||||
|
||||
BizActivityLottery bizActivityLottery = new BizActivityLottery();
|
||||
bizActivityLottery.setActivityId(submitActivityRequest.getActivityId());
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.corewing.app.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.corewing.app.entity.BizActivity;
|
||||
import com.corewing.app.mapper.BizActivityMapper;
|
||||
import com.corewing.app.service.BizActivityService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class BizActivityServiceImpl extends ServiceImpl<BizActivityMapper, BizActivity> implements BizActivityService {
|
||||
}
|
||||
@@ -7,12 +7,15 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.corewing.app.dto.DeviceActivationRequest;
|
||||
import com.corewing.app.entity.BizDevice;
|
||||
import com.corewing.app.entity.BizDeviceActivation;
|
||||
import com.corewing.app.entity.BizDeviceCategory;
|
||||
import com.corewing.app.mapper.BizDeviceActivationMapper;
|
||||
import com.corewing.app.service.BizDeviceActivationService;
|
||||
import com.corewing.app.service.BizDeviceCategoryService;
|
||||
import com.corewing.app.service.BizDeviceService;
|
||||
import com.corewing.app.util.CommonServletUtil;
|
||||
import com.corewing.app.util.IpUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
@@ -24,6 +27,9 @@ public class BizDeviceActivationServiceImpl extends ServiceImpl<BizDeviceActivat
|
||||
@Resource
|
||||
private BizDeviceService deviceService;
|
||||
|
||||
@Resource
|
||||
private BizDeviceCategoryService categoryService;
|
||||
|
||||
@Override
|
||||
public Boolean activation(DeviceActivationRequest deviceActivationRequest) {
|
||||
Object loginId = StpUtil.getLoginId();
|
||||
@@ -57,4 +63,26 @@ public class BizDeviceActivationServiceImpl extends ServiceImpl<BizDeviceActivat
|
||||
deviceActivation.setDeviceId(bizDevice.getId());
|
||||
return this.saveOrUpdate(deviceActivation);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public Boolean factoryActivation(DeviceActivationRequest deviceActivationRequest) {
|
||||
LambdaQueryWrapper<BizDeviceActivation> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(BizDeviceActivation::getDeviceMac, deviceActivationRequest.getMac());
|
||||
BizDeviceActivation checkDeviceActivation = getOne(wrapper);
|
||||
if(checkDeviceActivation != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<BizDeviceCategory> findWrapper = new LambdaQueryWrapper<>();
|
||||
findWrapper.eq(BizDeviceCategory::getModelId, deviceActivationRequest.getModelId());
|
||||
BizDeviceCategory deviceCategory = categoryService.getOne(findWrapper);
|
||||
|
||||
BizDevice device = new BizDevice();
|
||||
device.setDeviceMac(deviceActivationRequest.getMac());
|
||||
device.setStatus("0");
|
||||
device.setPublicStatus("1");
|
||||
device.setCategoryId(deviceCategory.getId());
|
||||
return deviceService.save(device);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,526 @@
|
||||
package com.corewing.app.util;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
|
||||
public class DateUtils {
|
||||
|
||||
// 格式化LocalDateTime为字符串
|
||||
public static void main(String[] args) {
|
||||
//2026-02-24 08:40:90
|
||||
System.out.println(isAfter(parseToLocalDateTime("2026-02-22 08:40:30")));
|
||||
}
|
||||
|
||||
//==================== 字符串格式化方法 ====================
|
||||
|
||||
/**
|
||||
* 将字符串格式化为LocalDateTime
|
||||
* @param dateTimeStr 日期时间字符串
|
||||
* @param pattern 格式模式,如:yyyy-MM-dd HH:mm:ss
|
||||
* @return LocalDateTime对象
|
||||
*/
|
||||
public static LocalDateTime parseToLocalDateTime(String dateTimeStr, String pattern) {
|
||||
if (dateTimeStr == null || dateTimeStr.isEmpty() || pattern == null || pattern.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
|
||||
return LocalDateTime.parse(dateTimeStr, formatter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串格式化为LocalDate
|
||||
* @param dateStr 日期字符串
|
||||
* @param pattern 格式模式,如:yyyy-MM-dd
|
||||
* @return LocalDate对象
|
||||
*/
|
||||
public static LocalDate parseToLocalDate(String dateStr, String pattern) {
|
||||
if (dateStr == null || dateStr.isEmpty() || pattern == null || pattern.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
|
||||
return LocalDate.parse(dateStr, formatter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串格式化为LocalTime
|
||||
* @param timeStr 时间字符串
|
||||
* @param pattern 格式模式,如:HH:mm:ss
|
||||
* @return LocalTime对象
|
||||
*/
|
||||
public static LocalTime parseToLocalTime(String timeStr, String pattern) {
|
||||
if (timeStr == null || timeStr.isEmpty() || pattern == null || pattern.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
|
||||
return LocalTime.parse(timeStr, formatter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串格式化为Date
|
||||
* @param dateTimeStr 日期时间字符串
|
||||
* @param pattern 格式模式,如:yyyy-MM-dd HH:mm:ss
|
||||
* @return Date对象
|
||||
*/
|
||||
public static Date parseToDate(String dateTimeStr, String pattern) {
|
||||
if (dateTimeStr == null || dateTimeStr.isEmpty() || pattern == null || pattern.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
|
||||
return sdf.parse(dateTimeStr);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("日期解析失败: " + dateTimeStr, e);
|
||||
}
|
||||
}
|
||||
|
||||
//==================== 常用格式的快捷方法 ====================
|
||||
|
||||
/**
|
||||
* 将字符串格式化为LocalDateTime(默认格式:yyyy-MM-dd HH:mm:ss)
|
||||
*/
|
||||
public static LocalDateTime parseToLocalDateTime(String dateTimeStr) {
|
||||
return parseToLocalDateTime(dateTimeStr, "yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串格式化为LocalDate(默认格式:yyyy-MM-dd)
|
||||
*/
|
||||
public static LocalDate parseToLocalDate(String dateStr) {
|
||||
return parseToLocalDate(dateStr, "yyyy-MM-dd");
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串格式化为LocalTime(默认格式:HH:mm:ss)
|
||||
*/
|
||||
public static LocalTime parseToLocalTime(String timeStr) {
|
||||
return parseToLocalTime(timeStr, "HH:mm:ss");
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串格式化为Date(默认格式:yyyy-MM-dd HH:mm:ss)
|
||||
*/
|
||||
public static Date parseToDate(String dateTimeStr) {
|
||||
return parseToDate(dateTimeStr, "yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
|
||||
//==================== 智能解析方法 ====================
|
||||
|
||||
/**
|
||||
* 智能解析字符串为LocalDateTime(自动识别常见格式)
|
||||
* 支持格式:
|
||||
* - yyyy-MM-dd HH:mm:ss
|
||||
* - yyyy/MM/dd HH:mm:ss
|
||||
* - yyyy-MM-dd'T'HH:mm:ss
|
||||
* - yyyy-MM-dd HH:mm
|
||||
* - yyyy-MM-dd
|
||||
* - yyyy/MM/dd
|
||||
*/
|
||||
public static LocalDateTime smartParseToLocalDateTime(String dateTimeStr) {
|
||||
if (dateTimeStr == null || dateTimeStr.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String str = dateTimeStr.trim();
|
||||
|
||||
// 尝试各种格式
|
||||
try {
|
||||
// 格式1: yyyy-MM-dd HH:mm:ss
|
||||
return LocalDateTime.parse(str, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
} catch (Exception e1) {
|
||||
try {
|
||||
// 格式2: yyyy/MM/dd HH:mm:ss
|
||||
return LocalDateTime.parse(str, DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"));
|
||||
} catch (Exception e2) {
|
||||
try {
|
||||
// 格式3: yyyy-MM-dd'T'HH:mm:ss
|
||||
return LocalDateTime.parse(str, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
|
||||
} catch (Exception e3) {
|
||||
try {
|
||||
// 格式4: yyyy-MM-dd HH:mm
|
||||
return LocalDateTime.parse(str, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
|
||||
} catch (Exception e4) {
|
||||
try {
|
||||
// 格式5: yyyy-MM-dd (转为当天开始时间)
|
||||
LocalDate date = LocalDate.parse(str, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
return date.atStartOfDay();
|
||||
} catch (Exception e5) {
|
||||
try {
|
||||
// 格式6: yyyy/MM/dd
|
||||
LocalDate date = LocalDate.parse(str, DateTimeFormatter.ofPattern("yyyy/MM/dd"));
|
||||
return date.atStartOfDay();
|
||||
} catch (Exception e6) {
|
||||
throw new IllegalArgumentException("无法解析的日期时间字符串: " + str);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 智能解析字符串为LocalDate(自动识别常见格式)
|
||||
* 支持格式:
|
||||
* - yyyy-MM-dd
|
||||
* - yyyy/MM/dd
|
||||
* - yyyyMMdd
|
||||
* - dd/MM/yyyy
|
||||
*/
|
||||
public static LocalDate smartParseToLocalDate(String dateStr) {
|
||||
if (dateStr == null || dateStr.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String str = dateStr.trim();
|
||||
|
||||
try {
|
||||
return LocalDate.parse(str, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
} catch (Exception e1) {
|
||||
try {
|
||||
return LocalDate.parse(str, DateTimeFormatter.ofPattern("yyyy/MM/dd"));
|
||||
} catch (Exception e2) {
|
||||
try {
|
||||
return LocalDate.parse(str, DateTimeFormatter.ofPattern("yyyyMMdd"));
|
||||
} catch (Exception e3) {
|
||||
try {
|
||||
return LocalDate.parse(str, DateTimeFormatter.ofPattern("dd/MM/yyyy"));
|
||||
} catch (Exception e4) {
|
||||
throw new IllegalArgumentException("无法解析的日期字符串: " + str);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//==================== 格式化输出方法 ====================
|
||||
|
||||
/**
|
||||
* 将LocalDateTime格式化为字符串
|
||||
* @param dateTime LocalDateTime对象
|
||||
* @param pattern 格式模式
|
||||
* @return 格式化后的字符串
|
||||
*/
|
||||
public static String format(LocalDateTime dateTime, String pattern) {
|
||||
if (dateTime == null || pattern == null || pattern.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
|
||||
return dateTime.format(formatter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将LocalDate格式化为字符串
|
||||
*/
|
||||
public static String format(LocalDate date, String pattern) {
|
||||
if (date == null || pattern == null || pattern.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
|
||||
return date.format(formatter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将LocalTime格式化为字符串
|
||||
*/
|
||||
public static String format(LocalTime time, String pattern) {
|
||||
if (time == null || pattern == null || pattern.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
|
||||
return time.format(formatter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将Date格式化为字符串
|
||||
*/
|
||||
public static String format(Date time, String pattern) {
|
||||
if (time == null || pattern == null || pattern.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
// 创建SimpleDateFormat实例
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
|
||||
// 格式化日期为字符串
|
||||
return sdf.format(time);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 将LocalDateTime格式化为默认格式:yyyy-MM-dd HH:mm:ss
|
||||
*/
|
||||
public static String formatDateTime(LocalDateTime dateTime) {
|
||||
return format(dateTime, "yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
|
||||
/**
|
||||
* 将LocalDate格式化为默认格式:yyyy-MM-dd
|
||||
*/
|
||||
public static String formatDate(LocalDate date) {
|
||||
return format(date, "yyyy-MM-dd");
|
||||
}
|
||||
|
||||
/**
|
||||
* 将LocalTime格式化为默认格式:HH:mm:ss
|
||||
*/
|
||||
public static String formatTime(LocalTime time) {
|
||||
return format(time, "HH:mm:ss");
|
||||
}
|
||||
|
||||
/**
|
||||
* 将Date格式化为默认格式:yyyy-MM-dd HH:mm:ss
|
||||
*/
|
||||
public static String formatDateTime(Date date) {
|
||||
return format(date, "yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
|
||||
//==================== 判断方法 ====================
|
||||
|
||||
/**
|
||||
* 判断传入时间是否大于当前时间
|
||||
* @param time 支持:Date, LocalDateTime, LocalDate, String
|
||||
*/
|
||||
public static boolean isAfter(Object time) {
|
||||
LocalDateTime dateTime = convertToLocalDateTime(time);
|
||||
return dateTime.isAfter(LocalDateTime.now());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断传入时间是否小于当前时间
|
||||
* @param time 支持:Date, LocalDateTime, LocalDate, String
|
||||
*/
|
||||
public static boolean isBefore(Object time) {
|
||||
LocalDateTime dateTime = convertToLocalDateTime(time);
|
||||
return dateTime.isBefore(LocalDateTime.now());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断传入时间是否等于当前时间(近似到分钟)
|
||||
* @param time 支持:Date, LocalDateTime, LocalDate, String
|
||||
*/
|
||||
public static boolean isEqual(Object time) {
|
||||
LocalDateTime dateTime = convertToLocalDateTime(time);
|
||||
LocalDateTime now = LocalDateTime.now().withSecond(0).withNano(0);
|
||||
return dateTime.withSecond(0).withNano(0).isEqual(now);
|
||||
}
|
||||
|
||||
//==================== 日期时间专用判断 ====================
|
||||
|
||||
/**
|
||||
* 判断传入时间是否大于等于当前时间
|
||||
*/
|
||||
public static boolean isAfterOrEqual(Object time) {
|
||||
LocalDateTime dateTime = convertToLocalDateTime(time);
|
||||
return !dateTime.isBefore(LocalDateTime.now());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断传入时间是否小于等于当前时间
|
||||
*/
|
||||
public static boolean isBeforeOrEqual(Object time) {
|
||||
LocalDateTime dateTime = convertToLocalDateTime(time);
|
||||
return !dateTime.isAfter(LocalDateTime.now());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断传入时间是否大于等于指定时间
|
||||
* @param time 要判断的时间
|
||||
* @param targetTime 目标时间
|
||||
*/
|
||||
public static boolean isAfterOrEqual(Object time, Object targetTime) {
|
||||
LocalDateTime dateTime = convertToLocalDateTime(time);
|
||||
LocalDateTime target = convertToLocalDateTime(targetTime);
|
||||
return !dateTime.isBefore(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断传入时间是否小于等于指定时间
|
||||
* @param time 要判断的时间
|
||||
* @param targetTime 目标时间
|
||||
*/
|
||||
public static boolean isBeforeOrEqual(Object time, Object targetTime) {
|
||||
LocalDateTime dateTime = convertToLocalDateTime(time);
|
||||
LocalDateTime target = convertToLocalDateTime(targetTime);
|
||||
return !dateTime.isAfter(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断传入时间是否在指定时间范围内(包含边界)
|
||||
* @param time 要判断的时间
|
||||
* @param start 开始时间
|
||||
* @param end 结束时间
|
||||
*/
|
||||
public static boolean isBetween(Object time, Object start, Object end) {
|
||||
LocalDateTime dateTime = convertToLocalDateTime(time);
|
||||
LocalDateTime startTime = convertToLocalDateTime(start);
|
||||
LocalDateTime endTime = convertToLocalDateTime(end);
|
||||
return !dateTime.isBefore(startTime) && !dateTime.isAfter(endTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断传入时间是否在指定时间范围内(不包含边界)
|
||||
* @param time 要判断的时间
|
||||
* @param start 开始时间
|
||||
* @param end 结束时间
|
||||
*/
|
||||
public static boolean isBetweenExclusive(Object time, Object start, Object end) {
|
||||
LocalDateTime dateTime = convertToLocalDateTime(time);
|
||||
LocalDateTime startTime = convertToLocalDateTime(start);
|
||||
LocalDateTime endTime = convertToLocalDateTime(end);
|
||||
return dateTime.isAfter(startTime) && dateTime.isBefore(endTime);
|
||||
}
|
||||
|
||||
//==================== 两个时间比较 ====================
|
||||
|
||||
/**
|
||||
* 判断time1是否大于time2
|
||||
*/
|
||||
public static boolean isAfter(Object time1, Object time2) {
|
||||
LocalDateTime dt1 = convertToLocalDateTime(time1);
|
||||
LocalDateTime dt2 = convertToLocalDateTime(time2);
|
||||
return dt1.isAfter(dt2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断time1是否小于time2
|
||||
*/
|
||||
public static boolean isBefore(Object time1, Object time2) {
|
||||
LocalDateTime dt1 = convertToLocalDateTime(time1);
|
||||
LocalDateTime dt2 = convertToLocalDateTime(time2);
|
||||
return dt1.isBefore(dt2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断两个时间是否相等
|
||||
*/
|
||||
public static boolean isEqual(Object time1, Object time2) {
|
||||
LocalDateTime dt1 = convertToLocalDateTime(time1);
|
||||
LocalDateTime dt2 = convertToLocalDateTime(time2);
|
||||
return dt1.isEqual(dt2);
|
||||
}
|
||||
|
||||
//==================== 日期专用判断 ====================
|
||||
|
||||
/**
|
||||
* 判断传入日期是否大于今天(只比较年月日)
|
||||
*/
|
||||
public static boolean isAfterDate(Object date) {
|
||||
LocalDate localDate = convertToLocalDate(date);
|
||||
return localDate.isAfter(LocalDate.now());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断传入日期是否小于今天(只比较年月日)
|
||||
*/
|
||||
public static boolean isBeforeDate(Object date) {
|
||||
LocalDate localDate = convertToLocalDate(date);
|
||||
return localDate.isBefore(LocalDate.now());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断传入日期是否等于今天
|
||||
*/
|
||||
public static boolean isToday(Object date) {
|
||||
LocalDate localDate = convertToLocalDate(date);
|
||||
return localDate.isEqual(LocalDate.now());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断传入日期是否大于等于今天(只比较年月日)
|
||||
*/
|
||||
public static boolean isAfterOrEqualDate(Object date) {
|
||||
LocalDate localDate = convertToLocalDate(date);
|
||||
return !localDate.isBefore(LocalDate.now());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断传入日期是否小于等于今天(只比较年月日)
|
||||
*/
|
||||
public static boolean isBeforeOrEqualDate(Object date) {
|
||||
LocalDate localDate = convertToLocalDate(date);
|
||||
return !localDate.isAfter(LocalDate.now());
|
||||
}
|
||||
|
||||
//==================== 私有转换方法 ====================
|
||||
|
||||
/**
|
||||
* 将各种类型转换为LocalDateTime
|
||||
*/
|
||||
private static LocalDateTime convertToLocalDateTime(Object time) {
|
||||
if (time == null) {
|
||||
throw new IllegalArgumentException("时间不能为null");
|
||||
}
|
||||
|
||||
// 1. LocalDateTime
|
||||
if (time instanceof LocalDateTime) {
|
||||
return (LocalDateTime) time;
|
||||
}
|
||||
|
||||
// 2. LocalDate
|
||||
if (time instanceof LocalDate) {
|
||||
return ((LocalDate) time).atStartOfDay();
|
||||
}
|
||||
|
||||
// 3. Date
|
||||
if (time instanceof Date) {
|
||||
return ((Date) time).toInstant()
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toLocalDateTime();
|
||||
}
|
||||
|
||||
// 4. String
|
||||
if (time instanceof String) {
|
||||
return smartParseToLocalDateTime((String) time);
|
||||
}
|
||||
|
||||
// 5. Long (时间戳)
|
||||
if (time instanceof Long) {
|
||||
return LocalDateTime.ofInstant(
|
||||
java.time.Instant.ofEpochMilli((Long) time),
|
||||
ZoneId.systemDefault()
|
||||
);
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("不支持的时间类型: " + time.getClass().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* 将各种类型转换为LocalDate
|
||||
*/
|
||||
private static LocalDate convertToLocalDate(Object date) {
|
||||
if (date == null) {
|
||||
throw new IllegalArgumentException("日期不能为null");
|
||||
}
|
||||
|
||||
// 1. LocalDate
|
||||
if (date instanceof LocalDate) {
|
||||
return (LocalDate) date;
|
||||
}
|
||||
|
||||
// 2. LocalDateTime
|
||||
if (date instanceof LocalDateTime) {
|
||||
return ((LocalDateTime) date).toLocalDate();
|
||||
}
|
||||
|
||||
// 3. Date
|
||||
if (date instanceof Date) {
|
||||
return ((Date) date).toInstant()
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toLocalDate();
|
||||
}
|
||||
|
||||
// 4. String
|
||||
if (date instanceof String) {
|
||||
return smartParseToLocalDate((String) date);
|
||||
}
|
||||
|
||||
// 5. Long (时间戳)
|
||||
if (date instanceof Long) {
|
||||
return LocalDateTime.ofInstant(
|
||||
java.time.Instant.ofEpochMilli((Long) date),
|
||||
ZoneId.systemDefault()
|
||||
).toLocalDate();
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("不支持的日期类型: " + date.getClass().getName());
|
||||
}
|
||||
}
|
||||
6
src/main/resources/mapper/BizActivityLotteryMapper.xml
Normal file
6
src/main/resources/mapper/BizActivityLotteryMapper.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?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.corewing.app.mapper.BizActivityLotteryMapper">
|
||||
|
||||
|
||||
</mapper>
|
||||
6
src/main/resources/mapper/BizActivityMapper.xml
Normal file
6
src/main/resources/mapper/BizActivityMapper.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?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.corewing.app.mapper.BizActivityMapper">
|
||||
|
||||
|
||||
</mapper>
|
||||
10
src/main/resources/templates/activity/eventVenue.html
Normal file
10
src/main/resources/templates/activity/eventVenue.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
123213
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user