Merge branch 'main' of https://dd3skj.picp.vip/JyuHsin/zhgh_cug_v4
# Conflicts: # src/main/resources/static/components/module/activity/UserScope.vue
This commit is contained in:
+53
-10
@@ -317,10 +317,7 @@ public class ActivityBasicScopeController {
|
||||
cnd.orderBy(activityUserScopePageParam.getPageOrderName(), activityUserScopePageParam.getPageOrderBy().equalsIgnoreCase("ascending") ? "ASC" : "DESC");
|
||||
}
|
||||
|
||||
if (activityUserScopePageParam.getActivityGroupId() != null) {
|
||||
Sql sqlx = activityBasicScopeService.buildGroupUserIdSubSql(activityUserScopePageParam.getActivityGroupId());
|
||||
cnd.and("u.id", activityUserScopePageParam.getReverseSelection() ? "IN" : "NOT IN", sqlx);
|
||||
}
|
||||
appendActivityGroupCondition(cnd, activityUserScopePageParam);
|
||||
|
||||
cnd.andEX("u.id", IN_OR_NIN_OP, activityUserScopePageParam.getUserId());
|
||||
|
||||
@@ -332,7 +329,7 @@ public class ActivityBasicScopeController {
|
||||
cnd.and("u.welfareMember", EQ_OR_NEQ_OP, 1);
|
||||
}
|
||||
if (ArrayUtils.contains(activityUserScopePageParam.getMemberTypes(), "基金会员")) {
|
||||
cnd.and(new Static(" u.loginname " + IN_OR_NIN_OP + " (select loginname from sick_fund_member)"));
|
||||
cnd.and("u.aidFundMember", EQ_OR_NEQ_OP, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,8 +375,12 @@ public class ActivityBasicScopeController {
|
||||
cnd.andEX("u.unionid", "=", SecurityUtil.getUnionId());
|
||||
}
|
||||
}
|
||||
cnd.andEX("u.unionid", EQ_OR_NEQ_OP, activityUserScopePageParam.getUnionId());
|
||||
cnd.andEX("u.unitid", EQ_OR_NEQ_OP, activityUserScopePageParam.getUnitId());
|
||||
String[] unionIds = getUnionIds(activityUserScopePageParam);
|
||||
if (Lang.isNotEmpty(unionIds)) {
|
||||
cnd.andEX("u.unionid", IN_OR_NIN_OP, unionIds);
|
||||
} else {
|
||||
cnd.andEX("u.unionid", EQ_OR_NEQ_OP, activityUserScopePageParam.getUnionId());
|
||||
}
|
||||
cnd.andEX("u.personType", IN_OR_NIN_OP, activityUserScopePageParam.getPersonTypes());
|
||||
cnd.andEX("u.userState", IN_OR_NIN_OP, activityUserScopePageParam.getUserStates());
|
||||
cnd.andEX("u.sex", IN_OR_NIN_OP, activityUserScopePageParam.getSexTypes());
|
||||
@@ -394,6 +395,34 @@ public class ActivityBasicScopeController {
|
||||
|
||||
}
|
||||
|
||||
private void appendActivityGroupCondition(Cnd cnd, ActivityUserScopePageParam activityUserScopePageParam) {
|
||||
Integer activityGroupId = activityUserScopePageParam.getActivityGroupId();
|
||||
if (activityGroupId == null) {
|
||||
return;
|
||||
}
|
||||
boolean reverseSelection = Boolean.TRUE.equals(activityUserScopePageParam.getReverseSelection());
|
||||
Integer groupType = activityBasicScopeService.getGroupType(activityGroupId);
|
||||
if (GROUP_TYPE_RESULT == groupType) {
|
||||
String existsSql = """
|
||||
EXISTS (
|
||||
SELECT 1
|
||||
FROM activity_user_scope aus
|
||||
WHERE aus.groupId = %d
|
||||
AND aus.userId = u.id
|
||||
)
|
||||
""".formatted(activityGroupId);
|
||||
cnd.and(new Static(reverseSelection ? existsSql : "NOT " + existsSql));
|
||||
return;
|
||||
}
|
||||
|
||||
ActivityUserScope groupInfo = activityBasicScopeService.getGroupInfo(activityGroupId);
|
||||
if (groupInfo == null || StrUtil.isBlank(groupInfo.getGroupSql())) {
|
||||
return;
|
||||
}
|
||||
String groupSql = "(" + groupInfo.getGroupSql() + ")";
|
||||
cnd.and(new Static(reverseSelection ? groupSql : "NOT " + groupSql));
|
||||
}
|
||||
|
||||
/**
|
||||
* 结果分组会把当前筛选出的用户快照保存下来,因此只落 userId 明细数据。
|
||||
*/
|
||||
@@ -577,7 +606,7 @@ public class ActivityBasicScopeController {
|
||||
conditionList.add("u.welfareMember " + eqOrNeq + " 1");
|
||||
}
|
||||
if (ArrayUtils.contains(activityUserScopePageParam.getMemberTypes(), "基金会员")) {
|
||||
conditionList.add("u.loginname " + inOrNotIn + " (select loginname from sick_fund_member)");
|
||||
conditionList.add("u.aidFundMember " + eqOrNeq + " 1");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -601,8 +630,12 @@ public class ActivityBasicScopeController {
|
||||
conditionList.add("u.unionid = " + wrapSqlValue(SecurityUtil.getUnionId()));
|
||||
}
|
||||
|
||||
addSingleValueCondition(conditionList, "u.unionid", eqOrNeq, activityUserScopePageParam.getUnionId());
|
||||
addSingleValueCondition(conditionList, "u.unitid", eqOrNeq, activityUserScopePageParam.getUnitId());
|
||||
String[] unionIds = getUnionIds(activityUserScopePageParam);
|
||||
if (Lang.isNotEmpty(unionIds)) {
|
||||
addArrayCondition(conditionList, "u.unionid", inOrNotIn, unionIds);
|
||||
} else {
|
||||
addSingleValueCondition(conditionList, "u.unionid", eqOrNeq, activityUserScopePageParam.getUnionId());
|
||||
}
|
||||
addArrayCondition(conditionList, "u.personType", inOrNotIn, activityUserScopePageParam.getPersonTypes());
|
||||
addArrayCondition(conditionList, "u.userState", inOrNotIn, activityUserScopePageParam.getUserStates());
|
||||
addArrayCondition(conditionList, "u.sex", inOrNotIn, activityUserScopePageParam.getSexTypes());
|
||||
@@ -637,6 +670,16 @@ public class ActivityBasicScopeController {
|
||||
}
|
||||
}
|
||||
|
||||
private String[] getUnionIds(ActivityUserScopePageParam activityUserScopePageParam) {
|
||||
if (Lang.isNotEmpty(activityUserScopePageParam.getUnionIds())) {
|
||||
return activityUserScopePageParam.getUnionIds();
|
||||
}
|
||||
if (StrUtil.isNotBlank(activityUserScopePageParam.getUnionId())) {
|
||||
return new String[]{activityUserScopePageParam.getUnionId()};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void addArrayCondition(List<String> conditionList, String columnName, String operator, String[] values) {
|
||||
if (Lang.isNotEmpty(values)) {
|
||||
conditionList.add(columnName + " " + operator + " (" + buildSqlStringList(values) + ")");
|
||||
|
||||
@@ -20,7 +20,8 @@ import java.io.Serializable;
|
||||
@Comment("活动人员范围设置")
|
||||
@TableIndexes({
|
||||
@Index(name = "INDEX_ACTIVITY_USER_SCOPE_GROUPID", fields = {"groupId"}, unique = false),
|
||||
@Index(name = "INDEX_ACTIVITY_USER_SCOPE_USERID", fields = {"userId"}, unique = false)
|
||||
@Index(name = "INDEX_ACTIVITY_USER_SCOPE_USERID", fields = {"userId"}, unique = false),
|
||||
@Index(name = "INDEX_ACTIVITY_USER_SCOPE_GROUPID_USERID", fields = {"groupId", "userId"}, unique = false)
|
||||
})
|
||||
public class ActivityUserScope extends BaseModel implements Serializable {
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ public class ActivityUserScopePageParam extends PageForm {
|
||||
|
||||
// 工会id
|
||||
private String unionId;
|
||||
private String[] unionIds;
|
||||
// 单位id
|
||||
private String unitId;
|
||||
// 人类型
|
||||
|
||||
+561
-19
@@ -15,6 +15,7 @@ import com.budwk.app.flow.constant.FlowConst;
|
||||
import com.budwk.app.flow.engine.FlowEngine;
|
||||
import com.budwk.app.flow.entity.ProcessInstance;
|
||||
import com.budwk.app.flow.entity.ProcessTask;
|
||||
import com.budwk.app.flow.enums.ProcessInstanceStateEnum;
|
||||
import com.budwk.app.flow.enums.ProcessSubmitTypeEnum;
|
||||
import com.budwk.app.sys.models.SysHoliday;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
@@ -29,6 +30,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.dao.util.cri.SqlExpressionGroup;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
@@ -40,16 +43,19 @@ import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import java.time.Year;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@IocBean
|
||||
@Ok("json:full")
|
||||
@Api(tags = "场地预约-场馆")
|
||||
@Api(tags = "\u573a\u5730\u9884\u7ea6-\u573a\u9986")
|
||||
@At("/platform/siteCug/apply")
|
||||
public class SiteCugApplyController {
|
||||
|
||||
@@ -67,20 +73,23 @@ public class SiteCugApplyController {
|
||||
@At("/")
|
||||
@SaCheckPermission("siteCug.apply")
|
||||
@Ok("beetl:/platform/zhgh/dayofficework/siteCug/apply/index.html")
|
||||
public void index() {}
|
||||
public void index() {
|
||||
}
|
||||
|
||||
@At("/h5")
|
||||
@SaCheckPermission(value = {"siteCug.apply", "h5.siteCug.apply"}, mode = SaMode.OR)
|
||||
@Ok("beetl:/platform/zhghh5/dayofficework/siteCug/apply/index.html")
|
||||
public void h5Index() {}
|
||||
public void h5Index() {
|
||||
}
|
||||
|
||||
@At("/form/h5")
|
||||
@SaCheckPermission(value = {"siteCug.apply", "h5.siteCug.apply"}, mode = SaMode.OR)
|
||||
@Ok("beetl:/platform/zhghh5/dayofficework/siteCug/apply/form/index.html")
|
||||
public void h5Form() {}
|
||||
public void h5Form() {
|
||||
}
|
||||
|
||||
@At
|
||||
@ApiOperation("分页查询场地")
|
||||
@ApiOperation("\u5206\u9875\u67e5\u8be2\u573a\u5730")
|
||||
@SaCheckPermission(value = {"siteCug.apply", "h5.siteCug.apply"}, mode = SaMode.OR)
|
||||
public Result pageData(PageForm pageForm, @Param("type") String type) {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
@@ -102,17 +111,530 @@ public class SiteCugApplyController {
|
||||
|
||||
List<SiteCugFunctionType> typeList = dao.query(SiteCugFunctionType.class, Cnd.NEW());
|
||||
Map<String, String> typeMap = typeList.stream().collect(Collectors.toMap(SiteCugFunctionType::getId, SiteCugFunctionType::getName));
|
||||
List<String> siteIds = listMap.stream().map(item -> item.getString("id")).filter(StrUtil::isNotBlank).toList();
|
||||
String today = DateUtil.today();
|
||||
String dayStart = today + " 00:00:00";
|
||||
String dayEnd = today + " 23:59:59";
|
||||
Map<String, List<SiteCugApply>> applyMap = queryTodayApplyMap(siteIds, dayStart, dayEnd);
|
||||
Set<String> holidaySet = dao.query(SysHoliday.class, Cnd.NEW()).stream()
|
||||
.map(SysHoliday::getDay)
|
||||
.filter(StrUtil::isNotBlank)
|
||||
.collect(Collectors.toSet());
|
||||
for (NutMap map : listMap) {
|
||||
map.put("typeName", typeMap.get(map.getString("typeId")));
|
||||
map.put("reserveTimeTypeName", getReserveTimeTypeName(map.getInt("reserveTimeType")));
|
||||
map.put("timelineSegments", buildTimelineSegments(map, applyMap.getOrDefault(map.getString("id"), new ArrayList<>()), today, holidaySet));
|
||||
}
|
||||
return Result.success(pagination);
|
||||
}
|
||||
|
||||
@At
|
||||
@ApiOperation("提交预约")
|
||||
@ApiOperation("\u67e5\u8be2\u573a\u5730\u53ef\u9884\u7ea6\u65f6\u6bb5")
|
||||
@SaCheckPermission(value = {"siteCug.apply", "h5.siteCug.apply"}, mode = SaMode.OR)
|
||||
@SLog(tag = "场馆功能管理-场地预约", msg = "提交场地预约")
|
||||
public Result availability(@Param("siteId") String siteId, @Param("date") String date) {
|
||||
if (StrUtil.isBlank(siteId)) {
|
||||
return Result.error("\u573a\u5730\u4e0d\u80fd\u4e3a\u7a7a");
|
||||
}
|
||||
String targetDate = StrUtil.isBlank(date) ? DateUtil.today() : date;
|
||||
if (!targetDate.matches("^\\d{4}-\\d{2}-\\d{2}$")) {
|
||||
return Result.error("\u9884\u7ea6\u65e5\u671f\u683c\u5f0f\u4e0d\u6b63\u786e");
|
||||
}
|
||||
SiteCugInfo siteInfo = infoService.fetch(siteId);
|
||||
if (siteInfo == null) {
|
||||
return Result.error("\u573a\u5730\u4e0d\u5b58\u5728");
|
||||
}
|
||||
Set<String> holidaySet = queryHolidaySet();
|
||||
List<SiteCugApply> applyList = queryDayApplyList(siteId, targetDate + " 00:00:00", targetDate + " 23:59:59");
|
||||
return Result.success(NutMap.NEW()
|
||||
.addv("date", targetDate)
|
||||
.addv("reserveTimeType", siteInfo.getReserveTimeType())
|
||||
.addv("reserveTimeTypeName", getReserveTimeTypeName(siteInfo.getReserveTimeType()))
|
||||
.addv("blocks", buildAvailabilityBlocks(siteInfo, targetDate, applyList, holidaySet)));
|
||||
}
|
||||
|
||||
private Map<String, List<SiteCugApply>> queryTodayApplyMap(List<String> siteIds, String dayStart, String dayEnd) {
|
||||
if (siteIds == null || siteIds.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
Sql sql = Sqls.create("""
|
||||
select
|
||||
sa.*
|
||||
from
|
||||
site_cug_apply sa
|
||||
left join wf_process_instance ins on ins.businessNo = sa.id
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("sa.siteId", "in", siteIds);
|
||||
cnd.and("ins.state", "in", List.of(
|
||||
ProcessInstanceStateEnum.DOING.getCode(),
|
||||
ProcessInstanceStateEnum.FINISHED.getCode(),
|
||||
ProcessInstanceStateEnum.PENDING.getCode()
|
||||
));
|
||||
cnd.and("sa.reserveEndTime", ">=", dayStart);
|
||||
cnd.and("sa.reserveStartTime", "<=", dayEnd);
|
||||
sql.setCondition(cnd);
|
||||
sql.setEntity(dao.getEntity(SiteCugApply.class));
|
||||
sql.setCallback(Sqls.callback.entities());
|
||||
dao.execute(sql);
|
||||
List<SiteCugApply> applyList = sql.getList(SiteCugApply.class);
|
||||
if (applyList == null || applyList.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
return applyList.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.groupingBy(SiteCugApply::getSiteId));
|
||||
}
|
||||
|
||||
private List<SiteCugApply> queryDayApplyList(String siteId, String dayStart, String dayEnd) {
|
||||
if (StrUtil.isBlank(siteId)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
Sql sql = Sqls.create("""
|
||||
select
|
||||
sa.*
|
||||
from
|
||||
site_cug_apply sa
|
||||
left join wf_process_instance ins on ins.businessNo = sa.id
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("sa.siteId", "=", siteId);
|
||||
cnd.and("ins.state", "in", List.of(
|
||||
ProcessInstanceStateEnum.DOING.getCode(),
|
||||
ProcessInstanceStateEnum.FINISHED.getCode(),
|
||||
ProcessInstanceStateEnum.PENDING.getCode()
|
||||
));
|
||||
cnd.and("sa.reserveEndTime", ">=", dayStart);
|
||||
cnd.and("sa.reserveStartTime", "<=", dayEnd);
|
||||
sql.setCondition(cnd);
|
||||
sql.setEntity(dao.getEntity(SiteCugApply.class));
|
||||
sql.setCallback(Sqls.callback.entities());
|
||||
dao.execute(sql);
|
||||
List<SiteCugApply> applyList = sql.getList(SiteCugApply.class);
|
||||
return applyList == null ? new ArrayList<>() : applyList;
|
||||
}
|
||||
|
||||
private Set<String> queryHolidaySet() {
|
||||
return dao.query(SysHoliday.class, Cnd.NEW()).stream()
|
||||
.map(SysHoliday::getDay)
|
||||
.filter(StrUtil::isNotBlank)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
private String getReserveTimeTypeName(Integer reserveTimeType) {
|
||||
if (reserveTimeType != null && reserveTimeType == 2) {
|
||||
return "\u5168\u5929\u5019\u9884\u7ea6";
|
||||
}
|
||||
return "\u5206\u6bb5\u9884\u7ea6";
|
||||
}
|
||||
|
||||
private List<NutMap> buildTimelineSegments(NutMap site, List<SiteCugApply> applyList, String today, Set<String> holidaySet) {
|
||||
List<NutMap> segments = new ArrayList<>();
|
||||
boolean isWeekend = isWeekend(today);
|
||||
boolean isHoliday = holidaySet.contains(today);
|
||||
List<int[]> openRanges = buildOpenRanges(site, isWeekend, isHoliday);
|
||||
List<int[]> disabledRanges = buildDisabledRanges(site, today);
|
||||
List<int[]> reservedRanges = buildReservedRanges(applyList, today);
|
||||
int totalMinutes = 24 * 60;
|
||||
int segmentMinutes = 30;
|
||||
for (int start = 0; start < totalMinutes; start += segmentMinutes) {
|
||||
int end = start + segmentMinutes;
|
||||
String status = "closed";
|
||||
if (intersectsAny(start, end, openRanges)) {
|
||||
status = "available";
|
||||
}
|
||||
if (intersectsAny(start, end, disabledRanges)) {
|
||||
status = "closed";
|
||||
}
|
||||
if (!"closed".equals(status) && intersectsAny(start, end, reservedRanges)) {
|
||||
status = "reserved";
|
||||
}
|
||||
segments.add(NutMap.NEW()
|
||||
.addv("status", status)
|
||||
.addv("startMinute", start)
|
||||
.addv("endMinute", end));
|
||||
}
|
||||
return segments;
|
||||
}
|
||||
|
||||
private List<int[]> buildOpenRanges(NutMap site, boolean isWeekend, boolean isHoliday) {
|
||||
if (isWeekend) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
if (Boolean.TRUE.equals(site.getBoolean("filterHolidays")) && isHoliday) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
Integer reserveTimeType = site.getInt("reserveTimeType");
|
||||
if (reserveTimeType != null && reserveTimeType == 2) {
|
||||
NutMap fullDayOpenHour = toNutMap(site.get("fullDayOpenHour"));
|
||||
if (fullDayOpenHour.isEmpty()) {
|
||||
List<NutMap> openHours = toNutMapList(site.get("openHours"));
|
||||
fullDayOpenHour = openHours.isEmpty() ? NutMap.NEW() : openHours.get(0);
|
||||
}
|
||||
return parseTimeRanges(List.of(fullDayOpenHour));
|
||||
}
|
||||
List<NutMap> segmentedOpenHours = toNutMapList(site.get("segmentedOpenHours"));
|
||||
if (segmentedOpenHours.isEmpty()) {
|
||||
segmentedOpenHours = toNutMapList(site.get("openHours"));
|
||||
}
|
||||
return parseTimeRanges(segmentedOpenHours);
|
||||
}
|
||||
|
||||
private List<int[]> buildDisabledRanges(NutMap site, String today) {
|
||||
List<NutMap> disabledList = toNutMapList(site.get("notApplyTimeList"));
|
||||
List<int[]> result = new ArrayList<>();
|
||||
for (NutMap item : disabledList) {
|
||||
if (item == null || !StrUtil.equals(today, item.getString("date"))) {
|
||||
continue;
|
||||
}
|
||||
Integer start = parseTimeToMinutes(item.getString("startTime"));
|
||||
Integer end = parseTimeToMinutes(item.getString("endTime"));
|
||||
if (start != null && end != null && end > start) {
|
||||
result.add(new int[]{start, end});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<int[]> buildReservedRanges(List<SiteCugApply> applyList, String today) {
|
||||
List<int[]> result = new ArrayList<>();
|
||||
String dayStart = today + " 00:00:00";
|
||||
String dayEnd = today + " 23:59:59";
|
||||
DateTime startOfDay = DateUtil.parseDateTime(dayStart);
|
||||
DateTime endOfDay = DateUtil.parseDateTime(dayEnd);
|
||||
for (SiteCugApply item : applyList) {
|
||||
if (item == null || StrUtil.hasBlank(item.getReserveStartTime(), item.getReserveEndTime())) {
|
||||
continue;
|
||||
}
|
||||
DateTime reserveStart = DateUtil.parseDateTime(item.getReserveStartTime());
|
||||
DateTime reserveEnd = DateUtil.parseDateTime(item.getReserveEndTime());
|
||||
if (!reserveEnd.isAfter(reserveStart)) {
|
||||
continue;
|
||||
}
|
||||
DateTime actualStart = reserveStart.isBefore(startOfDay) ? startOfDay : reserveStart;
|
||||
DateTime actualEnd = reserveEnd.isAfter(endOfDay) ? endOfDay : reserveEnd;
|
||||
int startMinute = actualStart.hour(true) * 60 + actualStart.minute();
|
||||
int endMinute = actualEnd.hour(true) * 60 + actualEnd.minute();
|
||||
if (actualEnd.second() > 0) {
|
||||
endMinute = Math.min(24 * 60, endMinute + 1);
|
||||
}
|
||||
if (endMinute > startMinute) {
|
||||
result.add(new int[]{startMinute, endMinute});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<int[]> parseTimeRanges(List<NutMap> sourceList) {
|
||||
List<int[]> result = new ArrayList<>();
|
||||
for (NutMap item : sourceList) {
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
Integer start = parseTimeToMinutes(item.getString("startTime"));
|
||||
Integer end = parseTimeToMinutes(item.getString("endTime"));
|
||||
if (start != null && end != null && end > start) {
|
||||
result.add(new int[]{start, end});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private NutMap toNutMap(Object value) {
|
||||
if (value instanceof NutMap nutMap) {
|
||||
return nutMap;
|
||||
}
|
||||
if (value instanceof Map<?, ?> map) {
|
||||
NutMap nutMap = NutMap.NEW();
|
||||
map.forEach((key, val) -> nutMap.put(String.valueOf(key), val));
|
||||
return nutMap;
|
||||
}
|
||||
return NutMap.NEW();
|
||||
}
|
||||
|
||||
private List<NutMap> toNutMapList(Object value) {
|
||||
List<NutMap> result = new ArrayList<>();
|
||||
if (!(value instanceof List<?> list)) {
|
||||
return result;
|
||||
}
|
||||
for (Object item : list) {
|
||||
result.add(toNutMap(item));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Integer parseTimeToMinutes(String timeText) {
|
||||
if (StrUtil.isBlank(timeText)) {
|
||||
return null;
|
||||
}
|
||||
List<String> parts = Arrays.stream(timeText.split(":"))
|
||||
.filter(StrUtil::isNotBlank)
|
||||
.toList();
|
||||
if (parts.size() < 2) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
int hour = Integer.parseInt(parts.get(0));
|
||||
int minute = Integer.parseInt(parts.get(1));
|
||||
if (hour < 0 || hour > 24 || minute < 0 || minute > 59) {
|
||||
return null;
|
||||
}
|
||||
if (hour == 24 && minute > 0) {
|
||||
return null;
|
||||
}
|
||||
return hour * 60 + minute;
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean intersectsAny(int start, int end, List<int[]> ranges) {
|
||||
for (int[] range : ranges) {
|
||||
if (range != null && start < range[1] && end > range[0]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isWeekend(String dateText) {
|
||||
DateTime date = DateUtil.parseDate(dateText);
|
||||
int week = date.dayOfWeek() - 1;
|
||||
return week == 0 || week == 6;
|
||||
}
|
||||
|
||||
private List<NutMap> buildAvailabilityBlocks(SiteCugInfo siteInfo, String day, List<SiteCugApply> applyList, Set<String> holidaySet) {
|
||||
if (siteInfo.getReserveTimeType() != null && siteInfo.getReserveTimeType() == 2) {
|
||||
return buildFullDayAvailabilityBlocks(siteInfo, day, applyList, holidaySet);
|
||||
}
|
||||
return buildSegmentedAvailabilityBlocks(siteInfo, day, applyList, holidaySet);
|
||||
}
|
||||
|
||||
private List<NutMap> buildSegmentedAvailabilityBlocks(SiteCugInfo siteInfo, String day, List<SiteCugApply> applyList, Set<String> holidaySet) {
|
||||
List<NutMap> sourceList = siteInfo.getSegmentedOpenHours();
|
||||
if (sourceList == null || sourceList.isEmpty()) {
|
||||
sourceList = siteInfo.getOpenHours();
|
||||
}
|
||||
List<NutMap> result = new ArrayList<>();
|
||||
List<int[]> reservedRanges = buildReservedRanges(applyList, day);
|
||||
List<int[]> disabledRanges = buildDisabledRanges(toSiteNutMap(siteInfo), day);
|
||||
boolean siteClosed = isSiteClosed(siteInfo, day, holidaySet);
|
||||
for (int i = 0; i < sourceList.size(); i++) {
|
||||
NutMap item = toNutMap(sourceList.get(i));
|
||||
Integer slotStart = parseTimeToMinutes(item.getString("startTime"));
|
||||
Integer slotEnd = parseTimeToMinutes(item.getString("endTime"));
|
||||
int unitMinutes = parseTimeUnitMinutes(item.get("timeUnit"));
|
||||
if (slotStart == null || slotEnd == null || slotEnd <= slotStart || unitMinutes <= 0) {
|
||||
continue;
|
||||
}
|
||||
String groupLabel = "\u573a\u6b21" + (i + 1) + " " + formatMinutes(slotStart) + "-" + formatMinutes(slotEnd) + " / " + formatUnitText(unitMinutes);
|
||||
for (int cursor = slotStart; cursor + unitMinutes <= slotEnd; cursor += unitMinutes) {
|
||||
int blockEnd = cursor + unitMinutes;
|
||||
result.add(buildAvailabilityBlock(day, cursor, blockEnd, reservedRanges, disabledRanges, siteClosed, i, groupLabel));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<NutMap> buildFullDayAvailabilityBlocks(SiteCugInfo siteInfo, String day, List<SiteCugApply> applyList, Set<String> holidaySet) {
|
||||
NutMap source = getFullDayOpenHourConfig(siteInfo);
|
||||
Integer slotStart = parseTimeToMinutes(source.getString("startTime"));
|
||||
Integer slotEnd = parseTimeToMinutes(source.getString("endTime"));
|
||||
int unitMinutes = parseTimeUnitMinutes(source.get("timeUnit"));
|
||||
if (slotStart == null || slotEnd == null || slotEnd <= slotStart || unitMinutes <= 0) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<NutMap> result = new ArrayList<>();
|
||||
List<int[]> reservedRanges = buildReservedRanges(applyList, day);
|
||||
List<int[]> disabledRanges = buildDisabledRanges(toSiteNutMap(siteInfo), day);
|
||||
boolean siteClosed = isSiteClosed(siteInfo, day, holidaySet);
|
||||
String groupLabel = "\u5168\u5929\u5019\u65f6\u6bb5 / " + formatUnitText(unitMinutes);
|
||||
for (int cursor = slotStart; cursor + unitMinutes <= slotEnd; cursor += unitMinutes) {
|
||||
int blockEnd = cursor + unitMinutes;
|
||||
result.add(buildAvailabilityBlock(day, cursor, blockEnd, reservedRanges, disabledRanges, siteClosed, 0, groupLabel));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private NutMap buildAvailabilityBlock(String day, int startMinute, int endMinute, List<int[]> reservedRanges, List<int[]> disabledRanges, boolean siteClosed, int groupIndex, String groupLabel) {
|
||||
String status = "available";
|
||||
if (siteClosed || intersectsAny(startMinute, endMinute, disabledRanges)) {
|
||||
status = "closed";
|
||||
} else if (intersectsAny(startMinute, endMinute, reservedRanges)) {
|
||||
status = "reserved";
|
||||
}
|
||||
return NutMap.NEW()
|
||||
.addv("key", day + "_" + startMinute + "_" + endMinute)
|
||||
.addv("groupIndex", groupIndex)
|
||||
.addv("groupLabel", groupLabel)
|
||||
.addv("status", status)
|
||||
.addv("startMinute", startMinute)
|
||||
.addv("endMinute", endMinute)
|
||||
.addv("startTime", formatMinutes(startMinute))
|
||||
.addv("endTime", formatMinutes(endMinute))
|
||||
.addv("label", formatMinutes(startMinute) + "-" + formatMinutes(endMinute))
|
||||
.addv("startDateTime", day + " " + formatMinutes(startMinute) + ":00")
|
||||
.addv("endDateTime", day + " " + formatMinutes(endMinute) + ":00");
|
||||
}
|
||||
|
||||
private boolean isSiteClosed(SiteCugInfo siteInfo, String day, Set<String> holidaySet) {
|
||||
if (isWeekend(day)) {
|
||||
return true;
|
||||
}
|
||||
return Boolean.TRUE.equals(siteInfo.getFilterHolidays()) && holidaySet.contains(day);
|
||||
}
|
||||
|
||||
private NutMap toSiteNutMap(SiteCugInfo siteInfo) {
|
||||
return NutMap.NEW()
|
||||
.addv("notApplyTimeList", siteInfo.getNotApplyTimeList())
|
||||
.addv("filterHolidays", siteInfo.getFilterHolidays())
|
||||
.addv("reserveTimeType", siteInfo.getReserveTimeType())
|
||||
.addv("openHours", siteInfo.getOpenHours())
|
||||
.addv("segmentedOpenHours", siteInfo.getSegmentedOpenHours())
|
||||
.addv("fullDayOpenHour", siteInfo.getFullDayOpenHour());
|
||||
}
|
||||
|
||||
private NutMap getFullDayOpenHourConfig(SiteCugInfo siteInfo) {
|
||||
NutMap source = toNutMap(siteInfo.getFullDayOpenHour());
|
||||
if (!source.isEmpty()) {
|
||||
return source;
|
||||
}
|
||||
List<NutMap> openHours = siteInfo.getOpenHours();
|
||||
return openHours == null || openHours.isEmpty() ? NutMap.NEW() : toNutMap(openHours.get(0));
|
||||
}
|
||||
|
||||
private int parseTimeUnitMinutes(Object value) {
|
||||
if (value == null) {
|
||||
return 60;
|
||||
}
|
||||
try {
|
||||
double unit = Double.parseDouble(String.valueOf(value));
|
||||
if (unit <= 0) {
|
||||
return 60;
|
||||
}
|
||||
return (int) Math.round(unit);
|
||||
} catch (NumberFormatException e) {
|
||||
return 60;
|
||||
}
|
||||
}
|
||||
|
||||
private String formatMinutes(int totalMinutes) {
|
||||
int hour = totalMinutes / 60;
|
||||
int minute = totalMinutes % 60;
|
||||
return String.format("%02d:%02d", hour, minute);
|
||||
}
|
||||
|
||||
private String formatUnitText(int unitMinutes) {
|
||||
return unitMinutes + "\u5206\u949f";
|
||||
}
|
||||
|
||||
private Result validateApplySelectionBySchedule(SiteCugApply apply) {
|
||||
if (apply == null || StrUtil.hasBlank(apply.getSiteId(), apply.getReserveStartTime(), apply.getReserveEndTime())) {
|
||||
return Result.success();
|
||||
}
|
||||
SiteCugInfo siteInfo = infoService.fetch(apply.getSiteId());
|
||||
if (siteInfo == null) {
|
||||
return Result.error("\u573a\u5730\u4e0d\u5b58\u5728");
|
||||
}
|
||||
DateTime start = DateUtil.parseDateTime(apply.getReserveStartTime());
|
||||
DateTime end = DateUtil.parseDateTime(apply.getReserveEndTime());
|
||||
String startDay = DateUtil.formatDate(start);
|
||||
String endDay = DateUtil.formatDate(end);
|
||||
if (!StrUtil.equals(startDay, endDay)) {
|
||||
return Result.error("\u9884\u7ea6\u65f6\u95f4\u5fc5\u987b\u5728\u540c\u4e00\u5929\u5185");
|
||||
}
|
||||
Set<String> holidaySet = queryHolidaySet();
|
||||
List<SiteCugApply> applyList = queryDayApplyList(apply.getSiteId(), startDay + " 00:00:00", startDay + " 23:59:59").stream()
|
||||
.filter(item -> item != null && !StrUtil.equals(item.getId(), apply.getId()))
|
||||
.collect(Collectors.toList());
|
||||
if (siteInfo.getReserveTimeType() != null && siteInfo.getReserveTimeType() == 2) {
|
||||
if (!isWithinOpenRanges(siteInfo, startDay, start, end, holidaySet)) {
|
||||
return Result.error("\u5168\u5929\u5019\u9884\u7ea6\u8bf7\u5728\u5f53\u5929\u5f00\u653e\u65f6\u95f4\u5185\u6309\u9884\u7ea6\u65f6\u95f4\u5355\u4f4d\u9009\u62e9\u4e00\u4e2a\u6216\u591a\u4e2a\u8fde\u7eed\u65f6\u6bb5");
|
||||
}
|
||||
if (!isAlignedWithFullDayTimeUnit(siteInfo, start, end)) {
|
||||
return Result.error("\u5168\u5929\u5019\u9884\u7ea6\u7684\u5f00\u59cb\u548c\u7ed3\u675f\u65f6\u95f4\u5fc5\u987b\u7b26\u5408\u9884\u7ea6\u65f6\u95f4\u5355\u4f4d");
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
List<NutMap> blocks = buildSegmentedAvailabilityBlocks(siteInfo, startDay, applyList, holidaySet);
|
||||
String startText = apply.getReserveStartTime();
|
||||
String endText = apply.getReserveEndTime();
|
||||
for (int i = 0; i < blocks.size(); i++) {
|
||||
NutMap block = blocks.get(i);
|
||||
if (!"available".equals(block.getString("status"))) {
|
||||
continue;
|
||||
}
|
||||
if (!StrUtil.equals(startText, block.getString("startDateTime"))) {
|
||||
continue;
|
||||
}
|
||||
String currentEnd = block.getString("endDateTime");
|
||||
if (StrUtil.equals(endText, currentEnd)) {
|
||||
return Result.success();
|
||||
}
|
||||
for (int j = i + 1; j < blocks.size(); j++) {
|
||||
NutMap nextBlock = blocks.get(j);
|
||||
NutMap prevBlock = blocks.get(j - 1);
|
||||
if (!"available".equals(nextBlock.getString("status"))) {
|
||||
break;
|
||||
}
|
||||
if (!StrUtil.equals(prevBlock.getString("endDateTime"), nextBlock.getString("startDateTime"))) {
|
||||
break;
|
||||
}
|
||||
currentEnd = nextBlock.getString("endDateTime");
|
||||
if (StrUtil.equals(endText, currentEnd)) {
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.error("\u5206\u6bb5\u9884\u7ea6\u8bf7\u6309\u573a\u6b21\u65f6\u95f4\u5355\u4f4d\u9009\u62e9\u4e00\u4e2a\u6216\u591a\u4e2a\u8fde\u7eed\u65f6\u6bb5");
|
||||
}
|
||||
|
||||
private boolean isWithinOpenRanges(SiteCugInfo siteInfo, String day, DateTime start, DateTime end, Set<String> holidaySet) {
|
||||
if (isSiteClosed(siteInfo, day, holidaySet)) {
|
||||
return false;
|
||||
}
|
||||
List<int[]> openRanges = buildOpenRanges(toSiteNutMap(siteInfo), false, false);
|
||||
List<int[]> disabledRanges = buildDisabledRanges(toSiteNutMap(siteInfo), day);
|
||||
int startMinute = start.hour(true) * 60 + start.minute();
|
||||
int endMinute = end.hour(true) * 60 + end.minute();
|
||||
if (end.second() > 0) {
|
||||
endMinute = Math.min(24 * 60, endMinute + 1);
|
||||
}
|
||||
final int finalEndMinute = endMinute;
|
||||
boolean inOpenRange = openRanges.stream().anyMatch(range -> startMinute >= range[0] && finalEndMinute <= range[1]);
|
||||
return inOpenRange && !intersectsAny(startMinute, finalEndMinute, disabledRanges);
|
||||
}
|
||||
|
||||
private boolean isAlignedWithFullDayTimeUnit(SiteCugInfo siteInfo, DateTime start, DateTime end) {
|
||||
if (start == null || end == null || start.second() > 0 || end.second() > 0) {
|
||||
return false;
|
||||
}
|
||||
NutMap source = getFullDayOpenHourConfig(siteInfo);
|
||||
Integer slotStart = parseTimeToMinutes(source.getString("startTime"));
|
||||
Integer slotEnd = parseTimeToMinutes(source.getString("endTime"));
|
||||
int unitMinutes = parseTimeUnitMinutes(source.get("timeUnit"));
|
||||
if (slotStart == null || slotEnd == null || slotEnd <= slotStart || unitMinutes <= 0) {
|
||||
return false;
|
||||
}
|
||||
int startMinute = start.hour(true) * 60 + start.minute();
|
||||
int endMinute = end.hour(true) * 60 + end.minute();
|
||||
return startMinute >= slotStart
|
||||
&& endMinute <= slotEnd
|
||||
&& endMinute > startMinute
|
||||
&& (startMinute - slotStart) % unitMinutes == 0
|
||||
&& (endMinute - slotStart) % unitMinutes == 0;
|
||||
}
|
||||
|
||||
@At
|
||||
@ApiOperation("\u63d0\u4ea4\u9884\u7ea6")
|
||||
@SaCheckPermission(value = {"siteCug.apply", "h5.siteCug.apply"}, mode = SaMode.OR)
|
||||
@SLog(tag = "\u573a\u9986\u529f\u80fd\u7ba1\u7406-\u573a\u5730\u9884\u7ea6", msg = "\u63d0\u4ea4\u573a\u5730\u9884\u7ea6")
|
||||
public Result submit(@Param("data") SiteCugApply apply) {
|
||||
Result scheduleValidate = validateApplySelectionBySchedule(apply);
|
||||
if (scheduleValidate.getCode() != 0) {
|
||||
return scheduleValidate;
|
||||
}
|
||||
Map<Boolean, String> validate = applyService.validateApply(apply);
|
||||
if (validate.containsKey(false)) {
|
||||
return Result.error(validate.get(false));
|
||||
@@ -122,19 +644,23 @@ public class SiteCugApplyController {
|
||||
}
|
||||
|
||||
@At("/submitYearly")
|
||||
@ApiOperation("按本年后续同星期同时间段批量提交预约")
|
||||
@ApiOperation("\u6309\u672c\u5e74\u540e\u7eed\u540c\u661f\u671f\u540c\u65f6\u95f4\u6bb5\u6279\u91cf\u63d0\u4ea4\u9884\u7ea6")
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
@SaCheckPermission(value = {"siteCug.apply", "h5.siteCug.apply"}, mode = SaMode.OR)
|
||||
@SLog(tag = "场馆功能管理-场地预约", msg = "批量提交本年场地预约")
|
||||
@SLog(tag = "\u573a\u9986\u529f\u80fd\u7ba1\u7406-\u573a\u5730\u9884\u7ea6", msg = "\u6279\u91cf\u63d0\u4ea4\u672c\u5e74\u573a\u5730\u9884\u7ea6")
|
||||
public Result submitYearly(@Param("data") SiteCugApply apply) {
|
||||
List<SiteCugApply> applyList = buildYearlyApplyList(apply);
|
||||
if (applyList.isEmpty()) {
|
||||
return Result.error("未生成可预约的日期");
|
||||
return Result.error("\u672a\u751f\u6210\u53ef\u9884\u7ea6\u7684\u65e5\u671f");
|
||||
}
|
||||
for (SiteCugApply item : applyList) {
|
||||
Result scheduleValidate = validateApplySelectionBySchedule(item);
|
||||
if (scheduleValidate.getCode() != 0) {
|
||||
return scheduleValidate;
|
||||
}
|
||||
Map<Boolean, String> validate = applyService.validateApply(item);
|
||||
if (validate.containsKey(false)) {
|
||||
return Result.error(String.format("%s 预约失败:%s", item.getReserveStartTime(), validate.get(false)));
|
||||
return Result.error(String.format("%s \u9884\u7ea6\u5931\u8d25\uff1a%s", item.getReserveStartTime(), validate.get(false)));
|
||||
}
|
||||
}
|
||||
String yearlyBatchNo = YEARLY_BATCH_PREFIX + UUID.randomUUID();
|
||||
@@ -142,11 +668,11 @@ public class SiteCugApplyController {
|
||||
item.setBackOption(yearlyBatchNo);
|
||||
submitSingleApply(item);
|
||||
}
|
||||
return Result.success(String.format("已成功预约本年剩余%d个时间段", applyList.size()));
|
||||
return Result.success(String.format("\u5df2\u6210\u529f\u9884\u7ea6\u622a\u81f3%s\u5171%d\u4e2a\u65f6\u95f4\u6bb5", apply.getYearlyReserveEndDate(), applyList.size()));
|
||||
}
|
||||
|
||||
@At
|
||||
@ApiOperation("查询预约限制配置")
|
||||
@ApiOperation("\u67e5\u8be2\u9884\u7ea6\u9650\u5236\u914d\u7f6e")
|
||||
@SaCheckPermission(value = {"siteCug.apply", "h5.siteCug.apply"}, mode = SaMode.OR)
|
||||
public Result timeLimitConfig(@Param("siteId") String siteId) {
|
||||
if (StrUtil.isBlank(siteId)) {
|
||||
@@ -174,7 +700,7 @@ public class SiteCugApplyController {
|
||||
}
|
||||
|
||||
private List<SiteCugApply> buildYearlyApplyList(SiteCugApply apply) {
|
||||
if (apply == null || StrUtil.hasBlank(apply.getReserveStartTime(), apply.getReserveEndTime())) {
|
||||
if (apply == null || StrUtil.hasBlank(apply.getReserveStartTime(), apply.getReserveEndTime(), apply.getYearlyReserveEndDate())) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
DateTime start = DateUtil.parseDateTime(apply.getReserveStartTime());
|
||||
@@ -182,6 +708,10 @@ public class SiteCugApplyController {
|
||||
if (!end.isAfter(start)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
DateTime reserveEndDate = parseReserveEndDate(apply.getYearlyReserveEndDate());
|
||||
if (reserveEndDate == null || reserveEndDate.isBefore(DateUtil.beginOfDay(start))) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
SiteCugInfo siteInfo = infoService.fetch(apply.getSiteId());
|
||||
if (siteInfo == null) {
|
||||
return new ArrayList<>();
|
||||
@@ -205,9 +735,9 @@ public class SiteCugApplyController {
|
||||
int endMinute = end.minute();
|
||||
int endSecond = end.second();
|
||||
Date current = DateUtil.beginOfDay(start);
|
||||
Date endOfYear = DateUtil.endOfYear(start);
|
||||
Date batchEndDate = DateUtil.endOfDay(reserveEndDate);
|
||||
List<SiteCugApply> result = new ArrayList<>();
|
||||
while (current.compareTo(endOfYear) <= 0) {
|
||||
while (current.compareTo(batchEndDate) <= 0) {
|
||||
DateTime currentDate = DateUtil.date(current);
|
||||
String currentDay = DateUtil.formatDate(currentDate);
|
||||
if (currentDate.dayOfWeek() - 1 == targetWeek && !holidayList.contains(currentDay)) {
|
||||
@@ -222,6 +752,17 @@ public class SiteCugApplyController {
|
||||
return result;
|
||||
}
|
||||
|
||||
private DateTime parseReserveEndDate(String endDate) {
|
||||
if (StrUtil.isBlank(endDate)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return DateUtil.parseDate(endDate);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private DateTime buildDateTime(DateTime date, int hour, int minute, int second) {
|
||||
return DateUtil.parseDateTime(String.format("%s %02d:%02d:%02d", DateUtil.formatDate(date), hour, minute, second));
|
||||
}
|
||||
@@ -245,7 +786,8 @@ public class SiteCugApplyController {
|
||||
.setReserveEndTime(apply.getReserveEndTime())
|
||||
.setJoinCount(apply.getJoinCount())
|
||||
.setApplyCause(apply.getApplyCause())
|
||||
.setBackOption(apply.getBackOption());
|
||||
.setBackOption(apply.getBackOption())
|
||||
.setYearlyReserveEndDate(apply.getYearlyReserveEndDate());
|
||||
}
|
||||
|
||||
private void submitSingleApply(SiteCugApply apply) {
|
||||
@@ -261,4 +803,4 @@ public class SiteCugApplyController {
|
||||
flowEngine.executeProcessTask(task.getId(), SecurityUtil.getUserId(), args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+120
-10
@@ -27,12 +27,13 @@ import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@IocBean
|
||||
@Ok("json:full")
|
||||
@Api(tags = "场地管理-场馆")
|
||||
@Api(tags = "siteCug manage")
|
||||
@At("/platform/siteCug/manage")
|
||||
public class SiteCugManageController {
|
||||
|
||||
@@ -47,7 +48,7 @@ public class SiteCugManageController {
|
||||
public void index() {}
|
||||
|
||||
@At
|
||||
@ApiOperation("分页查询")
|
||||
@ApiOperation("page data")
|
||||
@SaCheckPermission("siteCug.manage")
|
||||
public Result pageData(PageForm pageForm, @Param("type") String type) {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
@@ -76,9 +77,9 @@ public class SiteCugManageController {
|
||||
}
|
||||
|
||||
@At
|
||||
@ApiOperation("新增/修改场地")
|
||||
@ApiOperation("submit")
|
||||
@SaCheckPermission("siteCug.manage")
|
||||
@SLog(tag = "场馆功能管理-场地管理", msg = "新增/修改场地")
|
||||
@SLog(tag = "siteCug.manage", msg = "submit site")
|
||||
public Object submit(@Param("data") SiteCugInfo info) {
|
||||
List<NutMap> notApplyTimeList = info.getNotApplyTimeList();
|
||||
if (notApplyTimeList != null) {
|
||||
@@ -89,27 +90,81 @@ public class SiteCugManageController {
|
||||
|| StrUtil.isBlank(item.getString("endTime"))
|
||||
|| item.getString("startTime").compareTo(item.getString("endTime")) >= 0);
|
||||
if (invalid) {
|
||||
return Result.error("禁用时间设置有误");
|
||||
return Result.error("Invalid disabled time settings");
|
||||
}
|
||||
}
|
||||
|
||||
if (info.getReserveTimeType() == null) {
|
||||
info.setReserveTimeType(1);
|
||||
}
|
||||
List<NutMap> segmentedOpenHours = info.getSegmentedOpenHours();
|
||||
NutMap fullDayOpenHour = info.getFullDayOpenHour();
|
||||
if ((segmentedOpenHours == null || segmentedOpenHours.isEmpty()) && info.getReserveTimeType() == 1) {
|
||||
segmentedOpenHours = info.getOpenHours();
|
||||
}
|
||||
if ((fullDayOpenHour == null || fullDayOpenHour.isEmpty()) && info.getReserveTimeType() == 2 && info.getOpenHours() != null && !info.getOpenHours().isEmpty()) {
|
||||
fullDayOpenHour = info.getOpenHours().get(0);
|
||||
}
|
||||
if (info.getReserveTimeType() == 1) {
|
||||
if (segmentedOpenHours == null || segmentedOpenHours.isEmpty()) {
|
||||
return Result.error("Please add at least one booking slot");
|
||||
}
|
||||
boolean invalid = segmentedOpenHours.stream().anyMatch(item ->
|
||||
item == null
|
||||
|| StrUtil.isBlank(item.getString("startTime"))
|
||||
|| StrUtil.isBlank(item.getString("endTime"))
|
||||
|| item.getString("startTime").compareTo(item.getString("endTime")) >= 0
|
||||
|| !isPositiveNumber(item.get("timeUnit")));
|
||||
if (invalid) {
|
||||
return Result.error("Invalid segmented booking slot settings");
|
||||
}
|
||||
if (hasOverlap(segmentedOpenHours)) {
|
||||
return Result.error("Segmented booking slots cannot overlap");
|
||||
}
|
||||
segmentedOpenHours = segmentedOpenHours.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(this::normalizeOpenHourTimeUnit)
|
||||
.collect(Collectors.toList());
|
||||
info.setSegmentedOpenHours(segmentedOpenHours);
|
||||
info.setOpenHours(segmentedOpenHours);
|
||||
} else if (info.getReserveTimeType() == 2) {
|
||||
if (fullDayOpenHour == null || fullDayOpenHour.isEmpty()) {
|
||||
return Result.error("Please set the full-day booking time range");
|
||||
}
|
||||
NutMap item = fullDayOpenHour;
|
||||
if (item == null
|
||||
|| StrUtil.isBlank(item.getString("startTime"))
|
||||
|| StrUtil.isBlank(item.getString("endTime"))
|
||||
|| item.getString("startTime").compareTo(item.getString("endTime")) >= 0) {
|
||||
return Result.error("Invalid full-day booking time range");
|
||||
}
|
||||
if (!isPositiveNumber(item.get("timeUnit"))) {
|
||||
return Result.error("Invalid full-day booking time unit");
|
||||
}
|
||||
fullDayOpenHour = normalizeOpenHourTimeUnit(fullDayOpenHour);
|
||||
info.setFullDayOpenHour(fullDayOpenHour);
|
||||
info.setOpenHours(List.of(fullDayOpenHour));
|
||||
}
|
||||
|
||||
if (info.getFilterHolidays() == null) {
|
||||
info.setFilterHolidays(false);
|
||||
}
|
||||
infoService.insertOrUpdate(info);
|
||||
return Result.success();
|
||||
SiteCugInfo savedInfo = infoService.fetch(info.getId());
|
||||
return Result.success(savedInfo == null ? info : savedInfo);
|
||||
}
|
||||
|
||||
@At
|
||||
@ApiOperation("删除场地")
|
||||
@ApiOperation("delete")
|
||||
@SaCheckPermission("siteCug.manage")
|
||||
@SLog(tag = "场馆功能管理-场地管理", msg = "删除场地")
|
||||
@SLog(tag = "siteCug.manage", msg = "delete site")
|
||||
public Object delete(String id) {
|
||||
infoService.delete(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@At
|
||||
@ApiOperation("查询场地")
|
||||
@ApiOperation("query sites")
|
||||
@SaCheckLogin
|
||||
public Result querySites() {
|
||||
List<SiteCugInfo> list = infoService.query(Cnd.where(SiteCugInfo::getState, "=", true).desc(SiteCugInfo::getSortNum));
|
||||
@@ -117,7 +172,7 @@ public class SiteCugManageController {
|
||||
}
|
||||
|
||||
@At
|
||||
@ApiOperation("查询单个场地")
|
||||
@ApiOperation("query site info")
|
||||
@SaCheckLogin
|
||||
public Result info(String id) {
|
||||
SiteCugInfo info = infoService.fetch(id);
|
||||
@@ -129,4 +184,59 @@ public class SiteCugManageController {
|
||||
map.put("typeName", type == null ? "" : type.getName());
|
||||
return Result.success(map);
|
||||
}
|
||||
|
||||
private boolean isPositiveNumber(Object value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return Double.parseDouble(String.valueOf(value)) > 0;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private NutMap normalizeOpenHourTimeUnit(NutMap item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
item.put("timeUnit", normalizeTimeUnitMinutes(item.get("timeUnit")));
|
||||
return item;
|
||||
}
|
||||
|
||||
private int normalizeTimeUnitMinutes(Object value) {
|
||||
if (value == null) {
|
||||
return 60;
|
||||
}
|
||||
try {
|
||||
double parsed = Double.parseDouble(String.valueOf(value));
|
||||
if (parsed <= 0) {
|
||||
return 60;
|
||||
}
|
||||
return (int) Math.round(parsed);
|
||||
} catch (Exception e) {
|
||||
return 60;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasOverlap(List<NutMap> openHours) {
|
||||
if (openHours == null || openHours.size() < 2) {
|
||||
return false;
|
||||
}
|
||||
List<NutMap> validHours = openHours.stream()
|
||||
.filter(item -> item != null
|
||||
&& StrUtil.isNotBlank(item.getString("startTime"))
|
||||
&& StrUtil.isNotBlank(item.getString("endTime"))
|
||||
&& item.getString("startTime").compareTo(item.getString("endTime")) < 0)
|
||||
.sorted((a, b) -> a.getString("startTime").compareTo(b.getString("startTime")))
|
||||
.collect(Collectors.toList());
|
||||
for (int i = 1; i < validHours.size(); i++) {
|
||||
NutMap prev = validHours.get(i - 1);
|
||||
NutMap current = validHours.get(i);
|
||||
if (current.getString("startTime").compareTo(prev.getString("endTime")) < 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -81,6 +81,7 @@ public class SiteCugMineController {
|
||||
t.finishTime,
|
||||
t.taskParentId,
|
||||
t.variable taskVariable,
|
||||
CASE WHEN info.reserveType = 'club' THEN info.clubName ELSE info.applyUnionName END AS reserveTargetName,
|
||||
CASE
|
||||
WHEN ins.state in (10, 20) AND (t.displayName LIKE '%校工会允许%' OR t.taskName = 'c8c03407-cf26-4e0b-82f1-b2afc9c79996')
|
||||
THEN 1
|
||||
@@ -105,7 +106,6 @@ public class SiteCugMineController {
|
||||
SqlExpressionGroup seg = new SqlExpressionGroup();
|
||||
seg.or(SiteCugApply::getApplyUserName, "like", "%" + pageForm.getSearchKeyword() + "%");
|
||||
seg.or(SiteCugApply::getApplyLoginName, "like", "%" + pageForm.getSearchKeyword() + "%");
|
||||
seg.or("si.name", "like", "%" + pageForm.getSearchKeyword() + "%");
|
||||
cnd.and(seg);
|
||||
}
|
||||
cnd.andEX("si.typeId", "=", siteType);
|
||||
|
||||
+32
-2
@@ -75,6 +75,7 @@ public class SiteCugSchoolUnionAuditController {
|
||||
SELECT
|
||||
info.*,
|
||||
si.name as siteName,
|
||||
CASE WHEN info.reserveType = 'club' THEN info.clubName ELSE info.applyUnionName END AS reserveTargetName,
|
||||
ins.id AS instanceId,
|
||||
ins.businessNo,
|
||||
ins.state instanceState,
|
||||
@@ -113,7 +114,6 @@ public class SiteCugSchoolUnionAuditController {
|
||||
SqlExpressionGroup seg = new SqlExpressionGroup();
|
||||
seg.or(SiteCugApply::getApplyUserName, "like", "%" + pageForm.getSearchKeyword() + "%");
|
||||
seg.or(SiteCugApply::getApplyLoginName, "like", "%" + pageForm.getSearchKeyword() + "%");
|
||||
seg.or("si.name", "like", "%" + pageForm.getSearchKeyword() + "%");
|
||||
cnd.and(seg);
|
||||
}
|
||||
cnd.andEX("si.typeId", "=", siteType);
|
||||
@@ -129,7 +129,7 @@ public class SiteCugSchoolUnionAuditController {
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(pageForm.getPageOrderName()) && StrUtil.isNotBlank(pageForm.getPageOrderBy())) {
|
||||
cnd.orderBy(pageForm.getPageOrderName(), PageUtil.getOrder(pageForm.getPageOrderBy()));
|
||||
cnd.orderBy(resolveOrderColumn(pageForm.getPageOrderName()), PageUtil.getOrder(pageForm.getPageOrderBy()));
|
||||
} else {
|
||||
cnd.desc("info.createdAt");
|
||||
}
|
||||
@@ -139,6 +139,36 @@ public class SiteCugSchoolUnionAuditController {
|
||||
return Result.success(pageVO);
|
||||
}
|
||||
|
||||
private String resolveOrderColumn(String pageOrderName) {
|
||||
if (StrUtil.isBlank(pageOrderName)) {
|
||||
return "info.createdAt";
|
||||
}
|
||||
switch (pageOrderName) {
|
||||
case "siteName":
|
||||
return "si.name";
|
||||
case "applyUserName":
|
||||
return "info.applyUserName";
|
||||
case "applyLoginName":
|
||||
return "info.applyLoginName";
|
||||
case "yearlyBatch":
|
||||
return "yearlyBatch";
|
||||
case "reserveTargetName":
|
||||
return "reserveTargetName";
|
||||
case "reserveStartTime":
|
||||
return "info.reserveStartTime";
|
||||
case "reserveEndTime":
|
||||
return "info.reserveEndTime";
|
||||
case "applyMobile":
|
||||
return "info.applyMobile";
|
||||
case "curTaskName":
|
||||
return "curTaskName";
|
||||
case "instanceState":
|
||||
return "ins.state";
|
||||
default:
|
||||
return "info.createdAt";
|
||||
}
|
||||
}
|
||||
|
||||
@At("/executeTask")
|
||||
@ApiOperation("执行审核任务")
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
|
||||
@@ -109,4 +109,6 @@ public class SiteCugApply extends BaseModel {
|
||||
@Comment("反馈意见")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 200)
|
||||
private String backOption;
|
||||
|
||||
private String yearlyReserveEndDate;
|
||||
}
|
||||
|
||||
@@ -78,6 +78,27 @@ public class SiteCugInfo extends BaseModel {
|
||||
@ColDefine(type = ColType.MYSQL_JSON)
|
||||
private List<NutMap> notApplyTimeList;
|
||||
|
||||
@Column
|
||||
@Comment("预约时间段类型(1分段预约,2全天候预约)")
|
||||
@ColDefine(type = ColType.INT)
|
||||
@Default("1")
|
||||
private Integer reserveTimeType;
|
||||
|
||||
@Column
|
||||
@Comment("场次信息")
|
||||
@ColDefine(type = ColType.MYSQL_JSON)
|
||||
private List<NutMap> openHours;
|
||||
|
||||
@Column
|
||||
@Comment("分段预约场次信息")
|
||||
@ColDefine(type = ColType.MYSQL_JSON)
|
||||
private List<NutMap> segmentedOpenHours;
|
||||
|
||||
@Column
|
||||
@Comment("全天候预约时间段")
|
||||
@ColDefine(type = ColType.MYSQL_JSON)
|
||||
private NutMap fullDayOpenHour;
|
||||
|
||||
@Column
|
||||
@Comment("开启状态")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
@@ -94,4 +115,9 @@ public class SiteCugInfo extends BaseModel {
|
||||
@Comment("场地介绍")
|
||||
@ColDefine(type = ColType.TEXT)
|
||||
private String introduce;
|
||||
}
|
||||
|
||||
@Column
|
||||
@Comment("场地照片")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String sitePhoto;
|
||||
}
|
||||
|
||||
+1
-1
@@ -136,6 +136,7 @@ public class SiteCugApplyServiceImpl extends BaseServiceImpl<SiteCugApply> imple
|
||||
si.name AS siteName,
|
||||
ins.id AS instanceId,
|
||||
ins.processDefineId instanceProcessDefineId,
|
||||
CASE WHEN info.backOption LIKE 'YEARLY_BATCH:%' THEN 1 ELSE 0 END AS yearlyBatch,
|
||||
CASE WHEN info.reserveType = 'club' THEN '协会预约' ELSE '分工会预约' END AS reserveTypeName,
|
||||
CASE WHEN info.reserveType = 'club' THEN info.clubName ELSE info.applyUnionName END AS reserveTargetName,
|
||||
DATE_FORMAT(info.createdAt, '%Y-%m-%d %H:%i:%s') AS applyTime
|
||||
@@ -155,7 +156,6 @@ public class SiteCugApplyServiceImpl extends BaseServiceImpl<SiteCugApply> imple
|
||||
SqlExpressionGroup seg = new SqlExpressionGroup();
|
||||
seg.or(SiteCugApply::getApplyUserName, "like", "%" + pageForm.getSearchKeyword() + "%");
|
||||
seg.or(SiteCugApply::getApplyLoginName, "like", "%" + pageForm.getSearchKeyword() + "%");
|
||||
seg.or("si.name", "like", "%" + pageForm.getSearchKeyword() + "%");
|
||||
cnd.and(seg);
|
||||
}
|
||||
if (StrUtil.isNotBlank(pageForm.getReserveTargetKeyword())) {
|
||||
|
||||
+10
-8
@@ -2,6 +2,7 @@ package com.budwk.app.zhgh.staffmanage.member.controller.statistics;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.zhgh.staffmanage.member.param.pageform.MemberStatisticsPageForm;
|
||||
import com.budwk.app.zhgh.staffmanage.member.service.MemberStatisticsService;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
@@ -39,14 +40,12 @@ public class MemberAnalysisController {
|
||||
|
||||
@At
|
||||
@SaCheckPermission("member.statistics.analysis")
|
||||
public Result pageData(@Param(value = "queryId") String queryId,
|
||||
@Param(value = "queryType") String queryType,
|
||||
@Param(value = "currentYear") Integer currentYear) {
|
||||
public Result pageData(@Param("..") MemberStatisticsPageForm pageForm) {
|
||||
List<NutMap> list = new ArrayList<>();
|
||||
if ("fgh".equals(queryType)) {
|
||||
list = memberStatisticsService.getUnionAnalysisData(queryId, currentYear);
|
||||
if ("fgh".equals(pageForm.getQueryType())) {
|
||||
list = memberStatisticsService.getUnionAnalysisData(pageForm);
|
||||
} else {
|
||||
list = memberStatisticsService.getUnitAnalysisData(queryId, currentYear);
|
||||
list = memberStatisticsService.getUnitAnalysisData(pageForm);
|
||||
}
|
||||
return Result.success(list);
|
||||
}
|
||||
@@ -58,10 +57,13 @@ public class MemberAnalysisController {
|
||||
public void doExport(@Param("queryType") String queryType, @Param("currentYear") String currentYear,
|
||||
@Param("queryId") String queryId, HttpServletResponse response) {
|
||||
List<NutMap> list = new ArrayList<>();
|
||||
MemberStatisticsPageForm pageForm = new MemberStatisticsPageForm();
|
||||
pageForm.setQueryId(queryId);
|
||||
pageForm.setCurrentYear(Integer.valueOf(currentYear));
|
||||
if ("union".equals(queryType)) {
|
||||
list = memberStatisticsService.getUnionAnalysisData(queryId, Integer.valueOf(currentYear));
|
||||
list = memberStatisticsService.getUnionAnalysisData(pageForm);
|
||||
} else {
|
||||
list = memberStatisticsService.getUnitAnalysisData(queryId, Integer.valueOf(currentYear));
|
||||
list = memberStatisticsService.getUnitAnalysisData(pageForm);
|
||||
}
|
||||
NutMap sumMap = NutMap.NEW();
|
||||
sumMap.put("union".equals(queryType) ? "unionName" : "unitName", "合计");
|
||||
|
||||
+16
-2
@@ -40,7 +40,14 @@ public interface MemberStatisticsService extends BaseService<Sys_user> {
|
||||
* @param currentYear 所属年度
|
||||
* @return
|
||||
*/
|
||||
List<NutMap> getUnionAnalysisData(String unionId, Integer currentYear);
|
||||
/**
|
||||
* 获取工会分析数据。
|
||||
* pageForm 中除了机构和年份外,还会带上人员分类、人员属性等附加筛选条件。
|
||||
*
|
||||
* @param pageForm 统计查询参数
|
||||
* @return 工会分析结果
|
||||
*/
|
||||
List<NutMap> getUnionAnalysisData(MemberStatisticsPageForm pageForm);
|
||||
|
||||
|
||||
/**
|
||||
@@ -49,7 +56,14 @@ public interface MemberStatisticsService extends BaseService<Sys_user> {
|
||||
* @param currentYear 所属年度
|
||||
* @return
|
||||
*/
|
||||
List<NutMap> getUnitAnalysisData(String unitId, Integer currentYear);
|
||||
/**
|
||||
* 获取单位分析数据。
|
||||
* pageForm 中除了机构和年份外,还会带上人员分类、人员属性等附加筛选条件。
|
||||
*
|
||||
* @param pageForm 统计查询参数
|
||||
* @return 单位分析结果
|
||||
*/
|
||||
List<NutMap> getUnitAnalysisData(MemberStatisticsPageForm pageForm);
|
||||
|
||||
/**
|
||||
* 导出分析数据
|
||||
|
||||
+170
-17
@@ -29,6 +29,7 @@ import org.nutz.lang.util.NutMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
@@ -212,32 +213,79 @@ public class MemberStatisticsServiceImpl extends BaseServiceImpl<Sys_user> imple
|
||||
|
||||
|
||||
@Override
|
||||
public List<NutMap> getUnionAnalysisData(String queryId, Integer currentYear) {
|
||||
public List<NutMap> getUnionAnalysisData(MemberStatisticsPageForm pageForm) {
|
||||
String queryId = pageForm.getQueryId();
|
||||
Integer currentYear = pageForm.getCurrentYear();
|
||||
String lastYearPersonFilter = getAnalysisPersonFilterSql(pageForm, "his");
|
||||
String currentPersonFilter = getAnalysisPersonFilterSql(pageForm, "u");
|
||||
boolean useCurrentUserView = ((Integer) DateUtil.thisYear()).equals(currentYear);
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
gh.id,
|
||||
gh.unionCode,
|
||||
gh.`name` as unionName,
|
||||
( SELECT count( 1 ) FROM member_history his LEFT JOIN vw_user u on u.id = his.userId WHERE his.`year` = @lastYear AND u.unionId = gh.id ) AS lastYearMemberNum,
|
||||
( SELECT count( 1 ) FROM member_apply_record WHERE changeUnionId is not null AND unionId = gh.id AND unionId != changeUnionId AND YEAR ( applyDateTime ) = @currentYear ) AS memberUnitChangeNumIn,
|
||||
( SELECT count( 1 ) FROM member_apply_record WHERE changeUnionId is not null AND changeUnionId = gh.id AND unionId != changeUnionId AND YEAR ( applyDateTime ) = @currentYear ) AS memberUnitChangeNumOut,
|
||||
( SELECT count( 1 ) FROM sys_user_history his LEFT JOIN `vw_user` u ON u.loginname = his.loginname WHERE JSON_CONTAINS(his.changeTypes, '["NEW", "RESTORE"]', '$') AND u.unionId = gh.id AND YEAR ( his.changeTime ) = @currentYear ) AS newResetMemberNum,
|
||||
( SELECT count( 1 ) FROM sys_user_history his LEFT JOIN `vw_user` u ON u.loginname = his.loginname WHERE JSON_CONTAINS(his.changeTypes, '["WITHDRAWAL"]', '$') AND u.unionId = gh.id AND YEAR ( his.changeTime ) = @currentYear ) AS reduceOtherNum,
|
||||
( SELECT count( 1 ) FROM $table where member = 1 and unionId = gh.id) as currentYearMemberNum
|
||||
IFNULL(lastYear.lastYearMemberNum, 0) AS lastYearMemberNum,
|
||||
IFNULL(changeIn.memberUnitChangeNumIn, 0) AS memberUnitChangeNumIn,
|
||||
IFNULL(changeOut.memberUnitChangeNumOut, 0) AS memberUnitChangeNumOut,
|
||||
IFNULL(newReset.newResetMemberNum, 0) AS newResetMemberNum,
|
||||
IFNULL(reduceOther.reduceOtherNum, 0) AS reduceOtherNum,
|
||||
IFNULL(currentMember.currentYearMemberNum, 0) AS currentYearMemberNum
|
||||
FROM
|
||||
sys_union gh
|
||||
LEFT JOIN (
|
||||
SELECT his.unionId, COUNT(1) AS lastYearMemberNum
|
||||
FROM member_history his
|
||||
WHERE his.`year` = @lastYear $lastYearPersonFilter
|
||||
GROUP BY his.unionId
|
||||
) lastYear ON lastYear.unionId = gh.id
|
||||
LEFT JOIN (
|
||||
SELECT unionId, COUNT(1) AS memberUnitChangeNumIn
|
||||
FROM member_apply_record
|
||||
WHERE changeUnionId is not null AND unionId != changeUnionId AND YEAR(applyDateTime) = @currentYear
|
||||
GROUP BY unionId
|
||||
) changeIn ON changeIn.unionId = gh.id
|
||||
LEFT JOIN (
|
||||
SELECT changeUnionId AS unionId, COUNT(1) AS memberUnitChangeNumOut
|
||||
FROM member_apply_record
|
||||
WHERE changeUnionId is not null AND unionId != changeUnionId AND YEAR(applyDateTime) = @currentYear
|
||||
GROUP BY changeUnionId
|
||||
) changeOut ON changeOut.unionId = gh.id
|
||||
LEFT JOIN (
|
||||
SELECT u.unionId, COUNT(1) AS newResetMemberNum
|
||||
FROM sys_user_history his
|
||||
JOIN vw_user u ON u.loginname = his.loginname
|
||||
WHERE JSON_CONTAINS(his.changeTypes, '["NEW", "RESTORE"]', '$')
|
||||
AND YEAR(his.changeTime) = @currentYear $currentPersonFilter
|
||||
GROUP BY u.unionId
|
||||
) newReset ON newReset.unionId = gh.id
|
||||
LEFT JOIN (
|
||||
SELECT u.unionId, COUNT(1) AS reduceOtherNum
|
||||
FROM sys_user_history his
|
||||
JOIN vw_user u ON u.loginname = his.loginname
|
||||
WHERE JSON_CONTAINS(his.changeTypes, '["WITHDRAWAL"]', '$')
|
||||
AND YEAR(his.changeTime) = @currentYear $currentPersonFilter
|
||||
GROUP BY u.unionId
|
||||
) reduceOther ON reduceOther.unionId = gh.id
|
||||
LEFT JOIN (
|
||||
SELECT u.unionId, COUNT(1) AS currentYearMemberNum
|
||||
FROM $table u
|
||||
WHERE u.member = 1 $currentPersonFilter $currentYearFilter
|
||||
GROUP BY u.unionId
|
||||
) currentMember ON currentMember.unionId = gh.id
|
||||
$condition
|
||||
""");
|
||||
sql.setParam("lastYear", currentYear - 1);
|
||||
sql.setParam("currentYear", currentYear);
|
||||
sql.setVar("table", ((Integer) DateUtil.thisYear()).equals(currentYear) ? "`vw_user`" : "member_history");
|
||||
sql.setVar("table", useCurrentUserView ? "`vw_user`" : "member_history");
|
||||
sql.setVar("lastYearPersonFilter", new Static(lastYearPersonFilter));
|
||||
sql.setVar("currentPersonFilter", new Static(currentPersonFilter));
|
||||
sql.setVar("currentYearFilter", new Static(getAnalysisYearFilterSql("u", useCurrentUserView, currentYear)));
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (!AuthUtil.hasRoleOr(RoleConstant.SYSADMIN.name(), RoleConstant.SCHOOL_UNION_ADMIN.name())) {
|
||||
cnd.and("gh.id", "=", SecurityUtil.getUnionId());
|
||||
} else {
|
||||
cnd.andEX("gh.id", "=", queryId);
|
||||
}
|
||||
cnd.groupBy("gh.id, gh.unionCode, gh.name");
|
||||
cnd.asc("gh.unionCode");
|
||||
sql.setCondition(cnd);
|
||||
List<NutMap> list = listMap(sql);
|
||||
@@ -250,24 +298,73 @@ public class MemberStatisticsServiceImpl extends BaseServiceImpl<Sys_user> imple
|
||||
|
||||
|
||||
@Override
|
||||
public List<NutMap> getUnitAnalysisData(String queryId, Integer currentYear) {
|
||||
public List<NutMap> getUnitAnalysisData(MemberStatisticsPageForm pageForm) {
|
||||
String queryId = pageForm.getQueryId();
|
||||
Integer currentYear = pageForm.getCurrentYear();
|
||||
String lastYearPersonFilter = getAnalysisPersonFilterSql(pageForm, "his");
|
||||
String currentPersonFilter = getAnalysisPersonFilterSql(pageForm, "u");
|
||||
boolean useCurrentUserView = ((Integer) DateUtil.thisYear()).equals(currentYear);
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
dw.id,
|
||||
dw.unitcode as unitCode,
|
||||
dw.`name` as unitName,
|
||||
( SELECT count( 1 ) FROM member_history WHERE `year` = @lastYear AND unitId = dw.id ) AS lastYearMemberNum,
|
||||
( SELECT count( 1 ) FROM member_apply_record WHERE changeUnitId is not null AND unitId = dw.id AND unitId != changeUnitId AND YEAR ( applyDateTime ) = @currentYear ) AS memberUnitChangeNumIn,
|
||||
( SELECT count( 1 ) FROM member_apply_record WHERE changeUnitId is not null AND changeUnitId = dw.id AND unitId != changeUnitId AND YEAR ( applyDateTime ) = @currentYear ) AS memberUnitChangeNumOut,
|
||||
( SELECT count( 1 ) FROM sys_user_history his LEFT JOIN vw_user u ON u.loginname = his.loginname WHERE JSON_CONTAINS(his.changeTypes, '["NEW", "RESTORE"]', '$') AND u.unitId = dw.id AND YEAR ( his.changeTime ) = @currentYear ) AS newResetMemberNum,
|
||||
( SELECT count( 1 ) FROM sys_user_history his LEFT JOIN vw_user u ON u.loginname = his.loginname WHERE JSON_CONTAINS(his.changeTypes, '["WITHDRAWAL"]', '$') AND u.unitId = dw.id AND YEAR ( his.changeTime ) = @currentYear ) AS reduceOtherNum,
|
||||
( SELECT count( 1 ) from vw_user where member = 1 and unitId = dw.id) as currentYearMemberNum
|
||||
IFNULL(lastYear.lastYearMemberNum, 0) AS lastYearMemberNum,
|
||||
IFNULL(changeIn.memberUnitChangeNumIn, 0) AS memberUnitChangeNumIn,
|
||||
IFNULL(changeOut.memberUnitChangeNumOut, 0) AS memberUnitChangeNumOut,
|
||||
IFNULL(newReset.newResetMemberNum, 0) AS newResetMemberNum,
|
||||
IFNULL(reduceOther.reduceOtherNum, 0) AS reduceOtherNum,
|
||||
IFNULL(currentMember.currentYearMemberNum, 0) AS currentYearMemberNum
|
||||
FROM
|
||||
sys_unit dw
|
||||
LEFT JOIN (
|
||||
SELECT his.unitId, COUNT(1) AS lastYearMemberNum
|
||||
FROM member_history his
|
||||
WHERE his.`year` = @lastYear $lastYearPersonFilter
|
||||
GROUP BY his.unitId
|
||||
) lastYear ON lastYear.unitId = dw.id
|
||||
LEFT JOIN (
|
||||
SELECT unitId, COUNT(1) AS memberUnitChangeNumIn
|
||||
FROM member_apply_record
|
||||
WHERE changeUnitId is not null AND unitId != changeUnitId AND YEAR(applyDateTime) = @currentYear
|
||||
GROUP BY unitId
|
||||
) changeIn ON changeIn.unitId = dw.id
|
||||
LEFT JOIN (
|
||||
SELECT changeUnitId AS unitId, COUNT(1) AS memberUnitChangeNumOut
|
||||
FROM member_apply_record
|
||||
WHERE changeUnitId is not null AND unitId != changeUnitId AND YEAR(applyDateTime) = @currentYear
|
||||
GROUP BY changeUnitId
|
||||
) changeOut ON changeOut.unitId = dw.id
|
||||
LEFT JOIN (
|
||||
SELECT u.unitId, COUNT(1) AS newResetMemberNum
|
||||
FROM sys_user_history his
|
||||
JOIN vw_user u ON u.loginname = his.loginname
|
||||
WHERE JSON_CONTAINS(his.changeTypes, '["NEW", "RESTORE"]', '$')
|
||||
AND YEAR(his.changeTime) = @currentYear $currentPersonFilter
|
||||
GROUP BY u.unitId
|
||||
) newReset ON newReset.unitId = dw.id
|
||||
LEFT JOIN (
|
||||
SELECT u.unitId, COUNT(1) AS reduceOtherNum
|
||||
FROM sys_user_history his
|
||||
JOIN vw_user u ON u.loginname = his.loginname
|
||||
WHERE JSON_CONTAINS(his.changeTypes, '["WITHDRAWAL"]', '$')
|
||||
AND YEAR(his.changeTime) = @currentYear $currentPersonFilter
|
||||
GROUP BY u.unitId
|
||||
) reduceOther ON reduceOther.unitId = dw.id
|
||||
LEFT JOIN (
|
||||
SELECT u.unitId, COUNT(1) AS currentYearMemberNum
|
||||
FROM $table u
|
||||
WHERE u.member = 1 $currentPersonFilter $currentYearFilter
|
||||
GROUP BY u.unitId
|
||||
) currentMember ON currentMember.unitId = dw.id
|
||||
$condition
|
||||
""");
|
||||
sql.setParam("lastYear", currentYear - 1);
|
||||
sql.setParam("currentYear", currentYear);
|
||||
sql.setVar("lastYearPersonFilter", new Static(lastYearPersonFilter));
|
||||
sql.setVar("currentPersonFilter", new Static(currentPersonFilter));
|
||||
sql.setVar("table", useCurrentUserView ? "`vw_user`" : "member_history");
|
||||
sql.setVar("currentYearFilter", new Static(getAnalysisYearFilterSql("u", useCurrentUserView, currentYear)));
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("dw.unitLevel", "=", 3);
|
||||
if (!AuthUtil.hasRoleOr(RoleConstant.SYSADMIN.name(), RoleConstant.SCHOOL_UNION_ADMIN.name())) {
|
||||
@@ -275,7 +372,6 @@ public class MemberStatisticsServiceImpl extends BaseServiceImpl<Sys_user> imple
|
||||
} else {
|
||||
cnd.andEX("dw.id", "=", queryId);
|
||||
}
|
||||
cnd.groupBy("dw.id", "dw.unitcode", "dw.name");
|
||||
cnd.asc("dw.unitcode");
|
||||
sql.setCondition(cnd);
|
||||
List<NutMap> list = listMap(sql);
|
||||
@@ -286,6 +382,61 @@ public class MemberStatisticsServiceImpl extends BaseServiceImpl<Sys_user> imple
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分析统计的 SQL 由多个子查询组成,外层机构条件不会自动作用到人员子查询。
|
||||
* 这里统一拼出人员分类、人员属性的过滤片段,分别注入到各个统计子查询里,
|
||||
* 保证 analysis 页面和前端标签筛选口径一致。
|
||||
*
|
||||
* @param pageForm 查询参数
|
||||
* @param alias 子查询里的人员表别名
|
||||
* @return 可直接拼接到子查询 WHERE 末尾的 SQL 片段
|
||||
*/
|
||||
private String getAnalysisPersonFilterSql(MemberStatisticsPageForm pageForm, String alias) {
|
||||
StringBuilder sqlBuilder = new StringBuilder();
|
||||
sqlBuilder.append(getAnalysisInSql(alias, "aidFundMemberUserType", pageForm.getAidFundMemberUserTypes()));
|
||||
sqlBuilder.append(getAnalysisInSql(alias, "userAttribute", pageForm.getUserAttributes()));
|
||||
return sqlBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* analysis 的当前数量在查历史年度时会切到 member_history,
|
||||
* 这里统一补年度条件,避免历史年度把整张历史表都统计进去。
|
||||
*
|
||||
* @param alias 子查询别名
|
||||
* @param useCurrentUserView 是否使用当前人员视图
|
||||
* @param currentYear 查询年度
|
||||
* @return 年度过滤 SQL 片段
|
||||
*/
|
||||
private String getAnalysisYearFilterSql(String alias, boolean useCurrentUserView, Integer currentYear) {
|
||||
if (useCurrentUserView) {
|
||||
return "";
|
||||
}
|
||||
return " AND " + alias + ".`year` = " + currentYear;
|
||||
}
|
||||
|
||||
/**
|
||||
* 这里仅用于拼接 analysis 模块固定字段的 IN 条件,
|
||||
* 会过滤空值并转义单引号,避免直接把前端原始值拼回 SQL。
|
||||
*
|
||||
* @param alias 子查询别名
|
||||
* @param columnName 字段名
|
||||
* @param values 筛选值列表
|
||||
* @return IN 条件 SQL 片段
|
||||
*/
|
||||
private String getAnalysisInSql(String alias, String columnName, List<String> values) {
|
||||
if (Lang.isEmpty(values)) {
|
||||
return "";
|
||||
}
|
||||
List<String> validValues = values.stream().filter(Strings::isNotBlank).collect(Collectors.toList());
|
||||
if (Lang.isEmpty(validValues)) {
|
||||
return "";
|
||||
}
|
||||
String inValueSql = validValues.stream()
|
||||
.map(value -> "'" + value.replace("'", "''") + "'")
|
||||
.collect(Collectors.joining(", "));
|
||||
return " AND " + alias + "." + columnName + " IN (" + inValueSql + ")";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Workbook exportAnalysisExcel(List<NutMap> list, String queryType) {
|
||||
@@ -348,6 +499,7 @@ public class MemberStatisticsServiceImpl extends BaseServiceImpl<Sys_user> imple
|
||||
// sql.setVar("abbr", new Static("his"));
|
||||
}
|
||||
cnd.andEX("u.userAttribute", "in", pageForm.getUserAttributes());
|
||||
cnd.andEX("u.aidFundMemberUserType", "in", pageForm.getAidFundMemberUserTypes());
|
||||
cnd.groupBy("un.id", "un.unionCode", "un.name");
|
||||
cnd.asc("un.unionCode");
|
||||
sql.setCondition(cnd);
|
||||
@@ -388,6 +540,7 @@ public class MemberStatisticsServiceImpl extends BaseServiceImpl<Sys_user> imple
|
||||
sql.setVar("yearCnd", new Static(" AND u.`year` = %d".formatted(currentYear)));
|
||||
}
|
||||
cnd.andEX("u.userAttribute", "in", pageForm.getUserAttributes());
|
||||
cnd.andEX("u.aidFundMemberUserType", "in", pageForm.getAidFundMemberUserTypes());
|
||||
cnd.and("un.unitLevel", "=", 2);
|
||||
cnd.groupBy("un.id", "un.unitcode", "un.name");
|
||||
cnd.asc("un.unitcode");
|
||||
|
||||
@@ -55,4 +55,10 @@ public class WelfareListPageForm extends PageForm {
|
||||
@ApiModelProperty("在职状态")
|
||||
private String[] userStates;
|
||||
|
||||
@ApiModelProperty("人员分类")
|
||||
private String aidFundMemberUserType;
|
||||
|
||||
@ApiModelProperty("人员属性")
|
||||
private String userAttribute;
|
||||
|
||||
}
|
||||
|
||||
@@ -31,4 +31,10 @@ public class WelfareSelectionSituationPageForm extends PageForm {
|
||||
|
||||
@ApiModelProperty("是否已选择")
|
||||
private Boolean isSelect;
|
||||
|
||||
@ApiModelProperty("人员分类")
|
||||
private String aidFundMemberUserType;
|
||||
|
||||
@ApiModelProperty("人员属性")
|
||||
private String userAttribute;
|
||||
}
|
||||
|
||||
@@ -417,6 +417,8 @@ public class WelfareListServiceImpl extends BaseServiceImpl<WelfareList> impleme
|
||||
cnd.andEX("t1.personType", "in", pageForm.getPersonTypes());
|
||||
cnd.andEX("t1.preparedBy", "in", pageForm.getPreparedBys());
|
||||
cnd.andEX("t1.userState", "in", pageForm.getUserStates());
|
||||
cnd.andEX("t2.aidFundMemberUserType", "=", pageForm.getAidFundMemberUserType());
|
||||
cnd.andEX("t2.userAttribute", "=", pageForm.getUserAttribute());
|
||||
if (StrUtil.isAllBlank(pageForm.getPageOrderName(), pageForm.getPageOrderBy())) {
|
||||
cnd.asc("t1.welfareUnionName");
|
||||
cnd.asc("t1.welfareUnitName");
|
||||
|
||||
+2
@@ -83,6 +83,8 @@ public class WelfareSelectionSituationServiceImpl extends BaseServiceImpl<Welfar
|
||||
|
||||
cnd.and("t1.projectId", "=", pageForm.getProjectId());
|
||||
cnd.andEX("t2.selectOptionId", "=", pageForm.getWelfareOptionId());
|
||||
cnd.andEX("t4.aidFundMemberUserType", "=", pageForm.getAidFundMemberUserType());
|
||||
cnd.andEX("t4.userAttribute", "=", pageForm.getUserAttribute());
|
||||
|
||||
if (StrUtil.isNotBlank(pageForm.getUserName())) {
|
||||
cnd.where().andLike("t4.username", pageForm.getUserName());
|
||||
|
||||
Reference in New Issue
Block a user