|
|
@@ -8,17 +8,21 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.xunmei.common.core.constant.CacheConstants;
|
|
|
import com.xunmei.common.core.domain.worktime.domain.SysWorkTime;
|
|
|
+import com.xunmei.common.core.thread.ThreadPoolConfig;
|
|
|
import com.xunmei.common.core.util.BeanHelper;
|
|
|
import com.xunmei.common.core.utils.DateUtils;
|
|
|
import com.xunmei.common.core.utils.Ymd;
|
|
|
import com.xunmei.common.core.utils.snowId.DateHelper;
|
|
|
import com.xunmei.common.core.web.domain.AjaxResult;
|
|
|
import com.xunmei.common.core.web.page.TableDataInfo;
|
|
|
+import com.xunmei.common.redis.utils.RedisUtils;
|
|
|
import com.xunmei.common.security.utils.SecurityUtils;
|
|
|
-import com.xunmei.system.api.domain.SysOrg;
|
|
|
+import com.xunmei.system.api.vo.SysOrgVO;
|
|
|
import com.xunmei.system.domain.SysWorkTimeSet;
|
|
|
import com.xunmei.system.domain.SysWorkTimeSetDayofweek;
|
|
|
import com.xunmei.system.mapper.SysWorkTimeMapper;
|
|
|
@@ -28,14 +32,19 @@ import com.xunmei.system.service.ISysOrgService;
|
|
|
import com.xunmei.system.service.ISysWorkTimeService;
|
|
|
import com.xunmei.system.service.ISysWorkTimeSetService;
|
|
|
import com.xunmei.system.util.StreamHelper;
|
|
|
+import io.netty.util.internal.StringUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.xunmei.common.core.web.domain.AjaxResult.error;
|
|
|
@@ -47,6 +56,7 @@ import static com.xunmei.common.core.web.domain.AjaxResult.success;
|
|
|
* @author xunmei
|
|
|
* @date 2023-08-14
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class SysWorkTimeSetServiceImpl extends ServiceImpl<SysWorkTimeSetMapper, SysWorkTimeSet> implements ISysWorkTimeSetService {
|
|
|
@Autowired
|
|
|
@@ -59,6 +69,9 @@ public class SysWorkTimeSetServiceImpl extends ServiceImpl<SysWorkTimeSetMapper,
|
|
|
private SysWorkTimeMapper sysWorkTimeMapper;
|
|
|
@Autowired
|
|
|
private ISysWorkTimeService workTimeService;
|
|
|
+ @Autowired
|
|
|
+ @Qualifier(ThreadPoolConfig.SOC_EXECUTOR)
|
|
|
+ private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
|
|
|
|
@Override
|
|
|
public TableDataInfo<SysWorkTimeSet> selectPage(SysWorkTimeSet sysWorkTimeSet) {
|
|
|
@@ -345,28 +358,22 @@ public class SysWorkTimeSetServiceImpl extends ServiceImpl<SysWorkTimeSetMapper,
|
|
|
// if (CollectionUtils.isNotEmpty(orgIds)) {
|
|
|
List<SysWorkTimeSet> sets = new ArrayList<>();
|
|
|
SysWorkTimeSet set = null;
|
|
|
- SysOrg org = null;
|
|
|
+ //此处应该判断缓存是否为空,但是若此处缓存为空,系统应该处于不可用的情况的,所以不判断了
|
|
|
+ List<SysOrgVO> cacheList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
|
|
|
+ List<SysOrgVO> collect = cacheList.stream().filter(o -> orgIds.contains(o.getId())).collect(Collectors.toList());
|
|
|
List<SysWorkTimeSetDayofweek> dayOfWeeks = new ArrayList<>();
|
|
|
- Set<Long> workTimeSetIds = new HashSet<>();
|
|
|
+ List<SysWorkTimeSet> insertList = new ArrayList<>();
|
|
|
+ List<SysWorkTimeSet> updateList = new ArrayList<>();
|
|
|
+ List<SysWorkTimeSet> list = sysWorkTimeSetMapper.selectByOrgIdList(orgIds);
|
|
|
for (Long orgId : orgIds) {
|
|
|
-
|
|
|
- QueryWrapper<SysWorkTimeSet> qw = new QueryWrapper<>();
|
|
|
- qw.lambda().eq(SysWorkTimeSet::getOrgId, orgId);
|
|
|
- List<SysWorkTimeSet> list = sysWorkTimeSetMapper.selectList(qw);
|
|
|
- if (list.isEmpty()) {
|
|
|
+ Optional<SysOrgVO> orgOptional = collect.stream().filter(o -> o.getId().equals(orgId)).findFirst();
|
|
|
+ set = list.stream().filter(f -> ObjectUtil.equal(f.getOrgId(), orgId)).findFirst().orElse(null);
|
|
|
+ if (set == null) {
|
|
|
set = new SysWorkTimeSet();
|
|
|
- org = orgService.selectSysOrgById(orgId);
|
|
|
- } else {
|
|
|
- set = list.get(0);
|
|
|
+ set.setCreateTime(new Date());
|
|
|
+ set.setCreateBy(SecurityUtils.getUsername());
|
|
|
+ set.setOrgName(orgOptional.isPresent() ? orgOptional.get().getName() : StringUtil.EMPTY_STRING);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- /*if (request.getId() != null) {
|
|
|
- set = sysWorkTimeSetMapper.selectById(request.getId());
|
|
|
- } else {
|
|
|
- set = new SysWorkTimeSet();
|
|
|
- org = orgService.selectSysOrgById(orgId);
|
|
|
- }*/
|
|
|
BeanHelper.copyProperties(set, request);
|
|
|
set.setOrgId(orgId);
|
|
|
set.setYear((long) year);
|
|
|
@@ -374,41 +381,34 @@ public class SysWorkTimeSetServiceImpl extends ServiceImpl<SysWorkTimeSetMapper,
|
|
|
set.setUpdateTime(new Date());
|
|
|
set.setUpdateBy(SecurityUtils.getUsername());
|
|
|
if (set.getId() == null) {
|
|
|
- if (org != null) {
|
|
|
- set.setOrgName(org.getShortName());
|
|
|
- }
|
|
|
- set.setCreateTime(new Date());
|
|
|
- set.setCreateBy(SecurityUtils.getUsername());
|
|
|
- sysWorkTimeSetMapper.insert(set);
|
|
|
-
|
|
|
+ set.setId(IdWorker.getId());
|
|
|
+ insertList.add(set);
|
|
|
} else {
|
|
|
- sysWorkTimeSetMapper.updateById(set);
|
|
|
+ updateList.add(set);
|
|
|
}
|
|
|
-
|
|
|
Long id = set.getId();
|
|
|
-
|
|
|
- List<SysWorkTimeSetDayofweek> tmp = request.getDayOfWeeks().stream().map(w -> {
|
|
|
- SysWorkTimeSetDayofweek dw = new SysWorkTimeSetDayofweek();
|
|
|
- BeanUtils.copyProperties(w, dw);
|
|
|
- return dw;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- tmp.forEach(w -> {
|
|
|
+ request.getDayOfWeeks().forEach(w -> {
|
|
|
w.setWorkTimeSetId(id);
|
|
|
});
|
|
|
-
|
|
|
- dayOfWeeks.addAll(tmp);
|
|
|
- set.setDayOfWeeks(dayOfWeeks);
|
|
|
+ dayOfWeeks.addAll(request.getDayOfWeeks());
|
|
|
+ set.setDayOfWeeks(request.getDayOfWeeks());
|
|
|
sets.add(set);
|
|
|
- workTimeSetIds.add(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!insertList.isEmpty()) {
|
|
|
+ baseMapper.batchInsertByXML(insertList);
|
|
|
+ }
|
|
|
+ if (!updateList.isEmpty()) {
|
|
|
+ baseMapper.batchUpdateByXML(updateList);
|
|
|
}
|
|
|
//清除可能存在的旧作息数据
|
|
|
+ List<Long> workTimeSetIds = sets.stream().map(SysWorkTimeSet::getId).collect(Collectors.toList());
|
|
|
sysWorkTimeSetDayofweekMapper.delete(new LambdaQueryWrapper<SysWorkTimeSetDayofweek>().in(SysWorkTimeSetDayofweek::getWorkTimeSetId, workTimeSetIds));
|
|
|
- for (SysWorkTimeSetDayofweek s : dayOfWeeks) {
|
|
|
- sysWorkTimeSetDayofweekMapper.insert(s);
|
|
|
- }
|
|
|
+ sysWorkTimeSetDayofweekMapper.batchInsertByXML(dayOfWeeks);
|
|
|
if (CollectionUtils.isNotEmpty(dayOfWeeks)) {
|
|
|
changeOrgWorkTime(sets, request.getEffectiveDate(), orgIds);
|
|
|
}
|
|
|
+
|
|
|
// }
|
|
|
return success();
|
|
|
}
|
|
|
@@ -506,7 +506,8 @@ public class SysWorkTimeSetServiceImpl extends ServiceImpl<SysWorkTimeSetMapper,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void changeOrgWorkTime(List<SysWorkTimeSet> sets, Date effectiveDate, List<Long> orgIds) {
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void changeOrgWorkTime(List<SysWorkTimeSet> sets, Date effectiveDate, List<Long> orgIds) {
|
|
|
//如果生效年份等于当前年份,那么就重新生成生效日期后当年以及下一年的作息时间
|
|
|
int effectiveYear = new DateHelper(effectiveDate).getYear();
|
|
|
int dateNowYear = new DateHelper(new Date()).getYear();
|
|
|
@@ -531,64 +532,71 @@ public class SysWorkTimeSetServiceImpl extends ServiceImpl<SysWorkTimeSetMapper,
|
|
|
//添加当月生效日期后的作息时间及下个月的作息时间
|
|
|
final List<DateTime> dateTimeList = DateUtil.rangeToList(effectiveDate, cal.getTime(), DateField.DAY_OF_MONTH);
|
|
|
List<SysWorkTime> workTimeEditDtoListAll = new ArrayList<>();
|
|
|
- for (SysWorkTimeSet workTime : sets) {
|
|
|
- List<SysWorkTime> workTimeEditDtoList = new ArrayList<>();
|
|
|
- for (DateTime time : dateTimeList) {
|
|
|
- Optional<SysWorkTimeSetDayofweek> dayOfWeekSetNew = workTime.getDayOfWeeks().stream().filter(w -> w.getDayOfWeek() == time.dayOfWeek()).findFirst();
|
|
|
- SysWorkTimeSetDayofweek dayOfWeekSet = dayOfWeekSetNew.orElse(null);
|
|
|
- boolean isEnable = ObjectUtil.isNotNull(dayOfWeekSet) && ObjectUtil.isNotNull(dayOfWeekSet.getIsWorkday()) && dayOfWeekSet.getIsWorkday() > 0;
|
|
|
- SysWorkTime dto = new SysWorkTime();
|
|
|
- dto.setDate(time);
|
|
|
- dto.setIsEnable(isEnable ? 1L : 0);
|
|
|
- dto.setIsDuty(ObjectUtil.isNotNull(dayOfWeekSet) ? dayOfWeekSet.getIsDuty() : null);
|
|
|
|
|
|
- if (ObjectUtil.isNull(dayOfWeekSet) || !(dayOfWeekSet.getIsWorkday() > 0)) {
|
|
|
- Optional<SysWorkTimeSetDayofweek> firstWorkDay = workTime.getDayOfWeeks().stream().filter(f -> f.getIsWorkday() > 0).findFirst();
|
|
|
- dayOfWeekSet = firstWorkDay.orElseGet(SysWorkTimeSetDayofweek::new);
|
|
|
- }
|
|
|
- dto.setWorkTime(dayOfWeekSet.getWorkTime());
|
|
|
- dto.setWorkOffTime(dayOfWeekSet.getWorkOffTime());
|
|
|
- dto.setOpenTime(dayOfWeekSet.getOpenTime());
|
|
|
- dto.setCloseTime(dayOfWeekSet.getCloseTime());
|
|
|
- dto.setNoonbreakStart(dayOfWeekSet.getNoonbreakStart());
|
|
|
- dto.setNoonbreakEnd(dayOfWeekSet.getNoonbreakEnd());
|
|
|
- workTimeEditDtoList.add(dto);
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ buildData(sets, effectiveDate, orgIds, dateTimeList, workTimeEditDtoListAll, list);
|
|
|
+ }, threadPoolTaskExecutor);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void buildData(List<SysWorkTimeSet> sets, Date effectiveDate, List<Long> orgIds, List<DateTime> dateTimeList, List<SysWorkTime> workTimeEditDtoListAll, List<SysWorkTime> list) {
|
|
|
+ for (SysWorkTimeSet workTime : sets) {
|
|
|
+ List<SysWorkTime> workTimeEditDtoList = new ArrayList<>();
|
|
|
+ for (DateTime time : dateTimeList) {
|
|
|
+ Optional<SysWorkTimeSetDayofweek> dayOfWeekSetNew = workTime.getDayOfWeeks().stream().filter(w -> w.getDayOfWeek() == time.dayOfWeek()).findFirst();
|
|
|
+ SysWorkTimeSetDayofweek dayOfWeekSet = dayOfWeekSetNew.orElse(null);
|
|
|
+ boolean isEnable = ObjectUtil.isNotNull(dayOfWeekSet) && ObjectUtil.isNotNull(dayOfWeekSet.getIsWorkday()) && dayOfWeekSet.getIsWorkday() > 0;
|
|
|
+ SysWorkTime dto = new SysWorkTime();
|
|
|
+ dto.setDate(time);
|
|
|
+ dto.setIsEnable(isEnable ? 1L : 0);
|
|
|
+ dto.setIsDuty(ObjectUtil.isNotNull(dayOfWeekSet) ? dayOfWeekSet.getIsDuty() : null);
|
|
|
+
|
|
|
+ if (ObjectUtil.isNull(dayOfWeekSet) || !(dayOfWeekSet.getIsWorkday() > 0)) {
|
|
|
+ Optional<SysWorkTimeSetDayofweek> firstWorkDay = workTime.getDayOfWeeks().stream().filter(f -> f.getIsWorkday() > 0).findFirst();
|
|
|
+ dayOfWeekSet = firstWorkDay.orElseGet(SysWorkTimeSetDayofweek::new);
|
|
|
}
|
|
|
- workTimeEditDtoListAll.addAll(workTimeEditDtoList);
|
|
|
+ dto.setWorkTime(dayOfWeekSet.getWorkTime());
|
|
|
+ dto.setWorkOffTime(dayOfWeekSet.getWorkOffTime());
|
|
|
+ dto.setOpenTime(dayOfWeekSet.getOpenTime());
|
|
|
+ dto.setCloseTime(dayOfWeekSet.getCloseTime());
|
|
|
+ dto.setNoonbreakStart(dayOfWeekSet.getNoonbreakStart());
|
|
|
+ dto.setNoonbreakEnd(dayOfWeekSet.getNoonbreakEnd());
|
|
|
+ workTimeEditDtoList.add(dto);
|
|
|
}
|
|
|
- if (CollectionUtils.isNotEmpty(workTimeEditDtoListAll)) {
|
|
|
- SysWorkTimeSet requesta = new SysWorkTimeSet();
|
|
|
- requesta.setOrgIds(orgIds);
|
|
|
- //获取所有的作息配置
|
|
|
- List<SysWorkTimeSet> listSet = sysWorkTimeSetMapper.selectWorkTimeSetList(requesta);
|
|
|
- for (Long orgId : orgIds) {
|
|
|
- List<SysWorkTimeSet> listSetOrg = listSet.stream().filter(f -> f.getOrgId().equals(orgId) && f.getEffectiveDate().getTime() != effectiveDate.getTime()).collect(Collectors.toList());
|
|
|
- if (CollectionUtils.isNotEmpty(listSetOrg)) {
|
|
|
- List<Date> dateList = new ArrayList<>();
|
|
|
- dateList.add(effectiveDate);
|
|
|
- listSetOrg.forEach(f -> {
|
|
|
- dateList.add(f.getEffectiveDate());
|
|
|
- });
|
|
|
- //dateList排序
|
|
|
- dateList.sort(Comparator.comparing(Date::getTime));
|
|
|
- //取出request.getEffectiveDate()在dateList中的位置
|
|
|
- int index = dateList.indexOf(effectiveDate);
|
|
|
- if (index != dateList.size() - 1) {
|
|
|
- Date effectiveDateNext = dateList.get(index + 1);
|
|
|
- //取出workTimeEditDtoListAll中ymd_date在EffectiveDate和effectiveDateNext之间的数据
|
|
|
- List<SysWorkTime> workTimeEditDtoList = workTimeEditDtoListAll.stream().filter(f -> f.getDate().getTime() >= effectiveDate.getTime() && f.getDate().getTime() < effectiveDateNext.getTime()).collect(Collectors.toList());
|
|
|
- List<Date> remDates = workTimeEditDtoList.stream().map(SysWorkTime::getDate).collect(Collectors.toList());
|
|
|
- workTimeService.remove(new LambdaQueryWrapper<SysWorkTime>().eq(SysWorkTime::getOrgId, orgId).in(SysWorkTime::getYmdDate, remDates).eq(SysWorkTime::getIsManual, 0));
|
|
|
- batchnew(orgId, workTimeEditDtoList, list);
|
|
|
- } else {
|
|
|
- workTimeService.remove(new LambdaQueryWrapper<SysWorkTime>().eq(SysWorkTime::getOrgId, orgId).ge(SysWorkTime::getYmdDate, effectiveDate).eq(SysWorkTime::getIsManual, 0));
|
|
|
- batchnew(orgId, workTimeEditDtoListAll, list);
|
|
|
- }
|
|
|
+ workTimeEditDtoListAll.addAll(workTimeEditDtoList);
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(workTimeEditDtoListAll)) {
|
|
|
+ SysWorkTimeSet requesta = new SysWorkTimeSet();
|
|
|
+ requesta.setOrgIds(orgIds);
|
|
|
+ //获取所有的作息配置
|
|
|
+ List<SysWorkTimeSet> listSet = sysWorkTimeSetMapper.selectWorkTimeSetList(requesta);
|
|
|
+ for (Long orgId : orgIds) {
|
|
|
+ List<SysWorkTimeSet> listSetOrg = listSet.stream().filter(f -> f.getOrgId().equals(orgId) && f.getEffectiveDate().getTime() != effectiveDate.getTime()).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isNotEmpty(listSetOrg)) {
|
|
|
+ List<Date> dateList = new ArrayList<>();
|
|
|
+ dateList.add(effectiveDate);
|
|
|
+ listSetOrg.forEach(f -> {
|
|
|
+ dateList.add(f.getEffectiveDate());
|
|
|
+ });
|
|
|
+ //dateList排序
|
|
|
+ dateList.sort(Comparator.comparing(Date::getTime));
|
|
|
+ //取出request.getEffectiveDate()在dateList中的位置
|
|
|
+ int index = dateList.indexOf(effectiveDate);
|
|
|
+ if (index != dateList.size() - 1) {
|
|
|
+ Date effectiveDateNext = dateList.get(index + 1);
|
|
|
+ //取出workTimeEditDtoListAll中ymd_date在EffectiveDate和effectiveDateNext之间的数据
|
|
|
+ List<SysWorkTime> workTimeEditDtoList = workTimeEditDtoListAll.stream().filter(f -> f.getDate().getTime() >= effectiveDate.getTime() && f.getDate().getTime() < effectiveDateNext.getTime()).collect(Collectors.toList());
|
|
|
+ List<Date> remDates = workTimeEditDtoList.stream().map(SysWorkTime::getDate).collect(Collectors.toList());
|
|
|
+ workTimeService.remove(new LambdaQueryWrapper<SysWorkTime>().eq(SysWorkTime::getOrgId, orgId).in(SysWorkTime::getYmdDate, remDates).eq(SysWorkTime::getIsManual, 0));
|
|
|
+ batchnew(orgId, workTimeEditDtoList, list);
|
|
|
} else {
|
|
|
+ workTimeService.remove(new LambdaQueryWrapper<SysWorkTime>().eq(SysWorkTime::getOrgId, orgId).ge(SysWorkTime::getYmdDate, effectiveDate).eq(SysWorkTime::getIsManual, 0));
|
|
|
batchnew(orgId, workTimeEditDtoListAll, list);
|
|
|
}
|
|
|
-
|
|
|
+ } else {
|
|
|
+ batchnew(orgId, workTimeEditDtoListAll, list);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|