ActivityThemeVo.java
4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package cn.fw.dalaran.domain.vo;
import cn.fw.dalaran.domain.db.ActivityTheme;
import com.alibaba.fastjson.JSON;
import lombok.Data;
import javax.validation.constraints.Future;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author wmy3969
* @version 1.0
* @date 2022/1/11 23:46
* @Description 活动主题视图
*/
@Data
public class ActivityThemeVo {
/**
* 主键id
*/
private Long id;
/**
* 所属配置组id
*/
@NotNull(message = "所属配置组id不能为空")
private Long configGroupId;
/**
* 集团id
*/
private Long groupId;
/**
* 活动主题
*/
@NotBlank(message = "活动主题不能为空")
private String theme;
/**
* 活动话题
*/
@NotEmpty(message = "话题不能为空")
private List<String> topic;
/**
* 主题开始时间
*/
@NotNull(message = "主题开始时间不能为空")
private Date startTime;
/**
* 主题结束时间
*/
@NotNull(message = "主题结束时间不能为空")
@Future(message = "主题结束时间必须在当前时间之后")
private Date endTime;
/**
* 是否为全部门店
*/
private Integer allShop;
/**
* 适用门店清单(id)
*/
private List<Long> shopIds;
/**
* 适用门店清单(name)
*/
private List<String> shopNames;
/**
* 封面图文件信息
*/
@NotEmpty(message = "必须指定封面图文件")
private List<FileDesc> allFileDesc;
/**
* 能否修改主题
*/
private boolean canAlter;
/**
* vo->db
*
* @return 将视图传参转换成DB
*/
public static ActivityTheme toDB(ActivityThemeVo vo) {
/*if (!vo.allShop) {
if (CollectionUtils.isEmpty(vo.getShopIds()) || CollectionUtils.isEmpty(vo.getShopNames())) {
throw new BusinessException("非全部门店时, 请必须指定具体门店");
}
}*/
final ActivityTheme db = new ActivityTheme();
db.setId(vo.getId());
/*db.setGroupId(vo.getGroupId());*/
db.setTheme(vo.getTheme());
db.setTopic(JSON.toJSONString(vo.getTopic().stream()
.map(item -> {
String replace = item.replace("#", "");
return "#" + replace;
})
.collect(Collectors.toList()))
.replace("[", "")
.replace("]", "")
.replace("\"", ""));
db.setStartTime(getThisDayMinTime(vo.getStartTime()));
db.setEndTime(getThisDayMaxTime(vo.getEndTime()));
/*db.setAllShop(vo.allShop ? 1 : 0);
if (!vo.allShop) {
db.setShopIds(vo.getShopIds()
.stream()
.map(Object::toString)
.collect(Collectors.joining(","))
.replace("\"", ""));
db.setShopNames(JSON.toJSONString(vo.getShopNames())
.replace("[", "")
.replace("]", "")
.replace("\"", ""));
}*/
return db;
}
/**
* 设置指定日期当天开始时间-->时分秒 00:00:00
*
* @param date 需要处理的时间
* @return 该时间当天最小值
*/
public static Date getThisDayMinTime(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
}
/**
* 设置指定日期当天最晚时间-->时分秒 23:59:59
*
* @param date 需要处理的时间
* @return 该时间当天最大值
*/
public static Date getThisDayMaxTime(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
return calendar.getTime();
}
}