|
|
|
@ -34,6 +34,7 @@ import java.time.format.DateTimeParseException;
|
|
|
|
|
import java.time.temporal.ChronoField;
|
|
|
|
|
import java.time.temporal.TemporalAccessor;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
@ -56,174 +57,16 @@ public class YysCalendarServiceImpl extends ServiceImpl<YysCalendarMapper, YysCa
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<YysCalendarEntity> getList(YysCalendarPagination yysCalendarPagination) {
|
|
|
|
|
return getTypeList(yysCalendarPagination, yysCalendarPagination.getDataType());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 列表查询
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<YysCalendarEntity> getTypeList(YysCalendarPagination yysCalendarPagination, String dataType) {
|
|
|
|
|
String userId = userProvider.get().getUserId();
|
|
|
|
|
List<String> AllIdList = new ArrayList();
|
|
|
|
|
List<List<String>> intersectionList = new ArrayList<>();
|
|
|
|
|
boolean isPc = ServletUtil.getHeader("jnpf-origin").equals("pc");
|
|
|
|
|
String columnData = !isPc ? YysCalendarConstant.getAppColumnData() : YysCalendarConstant.getColumnData();
|
|
|
|
|
ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(columnData, ColumnDataModel.class);
|
|
|
|
|
String ruleJson = !isPc ? JsonUtil.getObjectToString(columnDataModel.getRuleListApp()) : JsonUtil.getObjectToString(columnDataModel.getRuleList());
|
|
|
|
|
|
|
|
|
|
int total = 0;
|
|
|
|
|
int yysCalendarNum = 0;
|
|
|
|
|
QueryWrapper<YysCalendarEntity> yysCalendarQueryWrapper = new QueryWrapper<>();
|
|
|
|
|
List<String> allSuperIDlist = new ArrayList<>();
|
|
|
|
|
String superOp = "";
|
|
|
|
|
if (ObjectUtil.isNotEmpty(yysCalendarPagination.getSuperQueryJson())) {
|
|
|
|
|
List<String> allSuperList = new ArrayList<>();
|
|
|
|
|
List<List<String>> intersectionSuperList = new ArrayList<>();
|
|
|
|
|
String queryJson = yysCalendarPagination.getSuperQueryJson();
|
|
|
|
|
SuperJsonModel superJsonModel = JsonUtil.getJsonToBean(queryJson, SuperJsonModel.class);
|
|
|
|
|
int superNum = 0;
|
|
|
|
|
QueryWrapper<YysCalendarEntity> yysCalendarSuperWrapper = new QueryWrapper<>();
|
|
|
|
|
yysCalendarSuperWrapper = generaterSwapUtil.getCondition(new QueryModel(yysCalendarSuperWrapper, YysCalendarEntity.class, queryJson, "0"));
|
|
|
|
|
int yysCalendarNum1 = yysCalendarSuperWrapper.getExpression().getNormal().size();
|
|
|
|
|
if (yysCalendarNum1 > 0) {
|
|
|
|
|
List<String> yysCalendarList = this.list(yysCalendarSuperWrapper).stream().map(YysCalendarEntity::getId).collect(Collectors.toList());
|
|
|
|
|
allSuperList.addAll(yysCalendarList);
|
|
|
|
|
intersectionSuperList.add(yysCalendarList);
|
|
|
|
|
superNum++;
|
|
|
|
|
}
|
|
|
|
|
superOp = superNum > 0 ? superJsonModel.getMatchLogic() : "";
|
|
|
|
|
//and or
|
|
|
|
|
if (superOp.equalsIgnoreCase("and")) {
|
|
|
|
|
allSuperIDlist = generaterSwapUtil.getIntersection(intersectionSuperList);
|
|
|
|
|
} else {
|
|
|
|
|
allSuperIDlist = allSuperList;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<String> allRuleIDlist = new ArrayList<>();
|
|
|
|
|
String ruleOp = "";
|
|
|
|
|
if (ObjectUtil.isNotEmpty(ruleJson)) {
|
|
|
|
|
List<String> allRuleList = new ArrayList<>();
|
|
|
|
|
List<List<String>> intersectionRuleList = new ArrayList<>();
|
|
|
|
|
SuperJsonModel ruleJsonModel = JsonUtil.getJsonToBean(ruleJson, SuperJsonModel.class);
|
|
|
|
|
int ruleNum = 0;
|
|
|
|
|
QueryWrapper<YysCalendarEntity> yysCalendarSuperWrapper = new QueryWrapper<>();
|
|
|
|
|
yysCalendarSuperWrapper = generaterSwapUtil.getCondition(new QueryModel(yysCalendarSuperWrapper, YysCalendarEntity.class, ruleJson, "0"));
|
|
|
|
|
int yysCalendarNum1 = yysCalendarSuperWrapper.getExpression().getNormal().size();
|
|
|
|
|
if (yysCalendarNum1 > 0) {
|
|
|
|
|
List<String> yysCalendarList = this.list(yysCalendarSuperWrapper).stream().map(YysCalendarEntity::getId).collect(Collectors.toList());
|
|
|
|
|
allRuleList.addAll(yysCalendarList);
|
|
|
|
|
intersectionRuleList.add(yysCalendarList);
|
|
|
|
|
ruleNum++;
|
|
|
|
|
}
|
|
|
|
|
ruleOp = ruleNum > 0 ? ruleJsonModel.getMatchLogic() : "";
|
|
|
|
|
//and or
|
|
|
|
|
if (ruleOp.equalsIgnoreCase("and")) {
|
|
|
|
|
allRuleIDlist = generaterSwapUtil.getIntersection(intersectionRuleList);
|
|
|
|
|
} else {
|
|
|
|
|
allRuleIDlist = allRuleList;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
boolean pcPermission = false;
|
|
|
|
|
boolean appPermission = false;
|
|
|
|
|
if (isPc && pcPermission) {
|
|
|
|
|
if (!userProvider.get().getIsAdministrator()) {
|
|
|
|
|
Object yysCalendarObj = generaterSwapUtil.getAuthorizeCondition(new QueryModel(yysCalendarQueryWrapper, YysCalendarEntity.class, yysCalendarPagination.getMenuId(), "0"));
|
|
|
|
|
if (ObjectUtil.isEmpty(yysCalendarObj)) {
|
|
|
|
|
return new ArrayList<>();
|
|
|
|
|
} else {
|
|
|
|
|
yysCalendarQueryWrapper = (QueryWrapper<YysCalendarEntity>) yysCalendarObj;
|
|
|
|
|
if (yysCalendarQueryWrapper.getExpression().getNormal().size() > 0) {
|
|
|
|
|
yysCalendarNum++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!isPc && appPermission) {
|
|
|
|
|
if (!userProvider.get().getIsAdministrator()) {
|
|
|
|
|
Object yysCalendarObj = generaterSwapUtil.getAuthorizeCondition(new QueryModel(yysCalendarQueryWrapper, YysCalendarEntity.class, yysCalendarPagination.getMenuId(), "0"));
|
|
|
|
|
if (ObjectUtil.isEmpty(yysCalendarObj)) {
|
|
|
|
|
return new ArrayList<>();
|
|
|
|
|
} else {
|
|
|
|
|
yysCalendarQueryWrapper = (QueryWrapper<YysCalendarEntity>) yysCalendarObj;
|
|
|
|
|
if (yysCalendarQueryWrapper.getExpression().getNormal().size() > 0) {
|
|
|
|
|
yysCalendarNum++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (isPc) {
|
|
|
|
|
if (ObjectUtil.isNotEmpty(yysCalendarPagination.getYears())) {
|
|
|
|
|
yysCalendarNum++;
|
|
|
|
|
QueryWrapper<YysCalendarEntity> wrapper = new QueryWrapper<>();
|
|
|
|
|
|
|
|
|
|
// List YearsList = JsonUtil.getJsonToList(yysCalendarPagination.getYears(), String.class);
|
|
|
|
|
// Long fir = Long.valueOf(String.valueOf(YearsList.get(0)));
|
|
|
|
|
// Long sec = Long.valueOf(String.valueOf(YearsList.get(1)));
|
|
|
|
|
//
|
|
|
|
|
// yysCalendarQueryWrapper.lambda().ge(YysCalendarEntity::getYears, new Date(fir))
|
|
|
|
|
// .le(YysCalendarEntity::getYears, DateUtil.stringToDate(DateUtil.daFormatYmd(sec) + " 23:59:59"));
|
|
|
|
|
|
|
|
|
|
yysCalendarQueryWrapper.lambda().eq(YysCalendarEntity::getYears, yysCalendarPagination.getYears().toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
List<String> intersection = generaterSwapUtil.getIntersection(intersectionList);
|
|
|
|
|
if (total > 0) {
|
|
|
|
|
if (intersection.size() == 0) {
|
|
|
|
|
intersection.add("jnpfNullList");
|
|
|
|
|
}
|
|
|
|
|
yysCalendarQueryWrapper.lambda().in(YysCalendarEntity::getId, intersection);
|
|
|
|
|
}
|
|
|
|
|
//是否有高级查询
|
|
|
|
|
if (StringUtil.isNotEmpty(superOp)) {
|
|
|
|
|
if (allSuperIDlist.size() == 0) {
|
|
|
|
|
allSuperIDlist.add("jnpfNullList");
|
|
|
|
|
}
|
|
|
|
|
List<String> finalAllSuperIDlist = allSuperIDlist;
|
|
|
|
|
yysCalendarQueryWrapper.lambda().and(t -> t.in(YysCalendarEntity::getId, finalAllSuperIDlist));
|
|
|
|
|
}
|
|
|
|
|
//是否有数据过滤查询
|
|
|
|
|
if (StringUtil.isNotEmpty(ruleOp)) {
|
|
|
|
|
if (allRuleIDlist.size() == 0) {
|
|
|
|
|
allRuleIDlist.add("jnpfNullList");
|
|
|
|
|
}
|
|
|
|
|
List<String> finalAllRuleIDlist = allRuleIDlist;
|
|
|
|
|
yysCalendarQueryWrapper.lambda().and(t -> t.in(YysCalendarEntity::getId, finalAllRuleIDlist));
|
|
|
|
|
}
|
|
|
|
|
//假删除标志
|
|
|
|
|
yysCalendarQueryWrapper.lambda().isNull(YysCalendarEntity::getDeleteMark);
|
|
|
|
|
|
|
|
|
|
//排序
|
|
|
|
|
if (StringUtil.isEmpty(yysCalendarPagination.getSidx())) {
|
|
|
|
|
yysCalendarQueryWrapper.lambda().orderByDesc(YysCalendarEntity::getId);
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
String sidx = yysCalendarPagination.getSidx();
|
|
|
|
|
String[] strs = sidx.split("_name");
|
|
|
|
|
YysCalendarEntity yysCalendarEntity = new YysCalendarEntity();
|
|
|
|
|
Field declaredField = yysCalendarEntity.getClass().getDeclaredField(strs[0]);
|
|
|
|
|
declaredField.setAccessible(true);
|
|
|
|
|
String value = declaredField.getAnnotation(TableField.class).value();
|
|
|
|
|
yysCalendarQueryWrapper = "asc".equals(yysCalendarPagination.getSort().toLowerCase()) ? yysCalendarQueryWrapper.orderByAsc(value) : yysCalendarQueryWrapper.orderByDesc(value);
|
|
|
|
|
} catch (NoSuchFieldException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ("0".equals(dataType)) {
|
|
|
|
|
if ((total > 0 && AllIdList.size() > 0) || total == 0) {
|
|
|
|
|
Page<YysCalendarEntity> page = new Page<>(yysCalendarPagination.getCurrentPage(), yysCalendarPagination.getPageSize());
|
|
|
|
|
IPage<YysCalendarEntity> userIPage = this.page(page, yysCalendarQueryWrapper);
|
|
|
|
|
return yysCalendarPagination.setData(userIPage.getRecords(), userIPage.getTotal());
|
|
|
|
|
} else {
|
|
|
|
|
List<YysCalendarEntity> list = new ArrayList();
|
|
|
|
|
return yysCalendarPagination.setData(list, list.size());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return this.list(yysCalendarQueryWrapper);
|
|
|
|
|
if (ObjectUtil.isNotEmpty(yysCalendarPagination.getYears())) {
|
|
|
|
|
wrapper.lambda().eq(YysCalendarEntity::getYears, yysCalendarPagination.getYears().toString());
|
|
|
|
|
}
|
|
|
|
|
wrapper.lambda().isNull(YysCalendarEntity::getDeleteMark);
|
|
|
|
|
wrapper.last("ORDER BY CAST(day AS UNSIGNED)");
|
|
|
|
|
Page<YysCalendarEntity> page = new Page<>(yysCalendarPagination.getCurrentPage(), yysCalendarPagination.getPageSize());
|
|
|
|
|
IPage<YysCalendarEntity> userIPage = this.page(page, wrapper);
|
|
|
|
|
return yysCalendarPagination.setData(userIPage.getRecords(), userIPage.getTotal());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -276,7 +119,6 @@ public class YysCalendarServiceImpl extends ServiceImpl<YysCalendarMapper, YysCa
|
|
|
|
|
@Transactional
|
|
|
|
|
public String saveOrUpdate(YysCalendarForm yysCalendarForm, String id, boolean isSave) {
|
|
|
|
|
UserInfo userInfo = userProvider.get();
|
|
|
|
|
YysCalendarEntity entity = BeanUtil.copyProperties(yysCalendarForm, YysCalendarEntity.class);
|
|
|
|
|
LambdaQueryWrapper<YysCalendarEntity> wrapper = new LambdaQueryWrapper<>(YysCalendarEntity.class)
|
|
|
|
|
.eq(YysCalendarEntity::getYears, yysCalendarForm.getYears());
|
|
|
|
|
if (CollectionUtils.isNotEmpty(this.list(wrapper))) {
|
|
|
|
@ -286,12 +128,14 @@ public class YysCalendarServiceImpl extends ServiceImpl<YysCalendarMapper, YysCa
|
|
|
|
|
//根据年月判断多少天 然后循环创建多少条数据
|
|
|
|
|
int countedDays = this.countDays(yysCalendarForm.getYears());
|
|
|
|
|
for (int i = 1; i <= countedDays; i++) {
|
|
|
|
|
YysCalendarEntity entity = BeanUtil.copyProperties(yysCalendarForm, YysCalendarEntity.class);
|
|
|
|
|
String mainId = RandomUtil.uuId();
|
|
|
|
|
entity.setCreatorTime(DateUtil.getNowDate());
|
|
|
|
|
entity.setCreatorUserId(userInfo.getUserId());
|
|
|
|
|
entity.setId(mainId);
|
|
|
|
|
entity.setVersion(0);
|
|
|
|
|
entity.setDay(String.valueOf(i));
|
|
|
|
|
entity.setWeek(this.DateToWeekday(entity.getYears(), entity.getDay()));
|
|
|
|
|
list.add(entity);
|
|
|
|
|
}
|
|
|
|
|
boolean result = this.saveBatch(list);
|
|
|
|
@ -314,11 +158,37 @@ public class YysCalendarServiceImpl extends ServiceImpl<YysCalendarMapper, YysCa
|
|
|
|
|
this.updateById(calendar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int countDays(String dateStr) {
|
|
|
|
|
private int countDays(String years) {
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMM");
|
|
|
|
|
TemporalAccessor parsed = formatter.parse(dateStr);
|
|
|
|
|
TemporalAccessor parsed = formatter.parse(years);
|
|
|
|
|
LocalDate date = LocalDate.of(parsed.get(ChronoField.YEAR), parsed.get(ChronoField.MONTH_OF_YEAR), 1);
|
|
|
|
|
// 获取这个月的天数
|
|
|
|
|
return date.lengthOfMonth();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String DateToWeekday(String years, String day) {
|
|
|
|
|
String year = years.substring(0, 4);
|
|
|
|
|
String mouth = years.substring(4, 6);
|
|
|
|
|
LocalDate date = LocalDate.of(Integer.parseInt(year), Integer.parseInt(mouth), Integer.parseInt(day));
|
|
|
|
|
// 获取星期几,注意周日是1,周一是2,...,周六是7
|
|
|
|
|
int dayOfWeek = date.getDayOfWeek().getValue();
|
|
|
|
|
switch (dayOfWeek) {
|
|
|
|
|
case 1:
|
|
|
|
|
return "星期一";
|
|
|
|
|
case 2:
|
|
|
|
|
return "星期二";
|
|
|
|
|
case 3:
|
|
|
|
|
return "星期三";
|
|
|
|
|
case 4:
|
|
|
|
|
return "星期四";
|
|
|
|
|
case 5:
|
|
|
|
|
return "星期五";
|
|
|
|
|
case 6:
|
|
|
|
|
return "星期六";
|
|
|
|
|
case 7:
|
|
|
|
|
return "星期日";
|
|
|
|
|
default:
|
|
|
|
|
return "未知";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|