|
|
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.ListUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
import com.xunmei.common.core.enums.OrgTypeEnum;
|
|
|
import com.xunmei.common.core.exception.ServiceException;
|
|
|
@@ -25,6 +26,7 @@ import java.util.Comparator;
|
|
|
import java.util.List;
|
|
|
import java.util.Date;
|
|
|
import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class CockpitServiceImpl implements CockpitService {
|
|
|
@@ -38,7 +40,7 @@ public class CockpitServiceImpl implements CockpitService {
|
|
|
public List<TaskStatisticVo> resumption(TaskStatisticDto dto) {
|
|
|
Date date = getStartDate(dto.getPeriod());
|
|
|
String orgPath = remoteOrgService.selectOrgById(dto.getOrgId(), SecurityConstants.INNER).getPath();
|
|
|
- List<TaskStatisticVo> list = cockpitMapper.resumption(date, orgPath);
|
|
|
+ List<TaskStatisticVo> list = cockpitMapper.resumption(date, DateUtil.endOfDay(new Date()), orgPath);
|
|
|
return taskStatistic(list, dto);
|
|
|
}
|
|
|
|
|
|
@@ -46,7 +48,7 @@ public class CockpitServiceImpl implements CockpitService {
|
|
|
public List<TaskStatisticVo> safetyCheck(TaskStatisticDto dto) {
|
|
|
Date date = getStartDate(dto.getPeriod());
|
|
|
String orgPath = remoteOrgService.selectOrgById(dto.getOrgId(), SecurityConstants.INNER).getPath();
|
|
|
- List<TaskStatisticVo> list = cockpitMapper.safetyCheck(date, orgPath);
|
|
|
+ List<TaskStatisticVo> list = cockpitMapper.safetyCheck(date, DateUtil.endOfDay(new Date()), orgPath);
|
|
|
return taskStatistic(list, dto);
|
|
|
}
|
|
|
|
|
|
@@ -54,7 +56,7 @@ public class CockpitServiceImpl implements CockpitService {
|
|
|
public List<TaskStatisticVo> monitor(TaskStatisticDto dto) {
|
|
|
Date date = getStartDate(dto.getPeriod());
|
|
|
String orgPath = remoteOrgService.selectOrgById(dto.getOrgId(), SecurityConstants.INNER).getPath();
|
|
|
- List<TaskStatisticVo> list = cockpitMapper.monitor(date, orgPath);
|
|
|
+ List<TaskStatisticVo> list = cockpitMapper.monitor(date, DateUtil.endOfDay(new Date()), orgPath);
|
|
|
return taskStatistic(list, dto);
|
|
|
}
|
|
|
|
|
|
@@ -62,7 +64,7 @@ public class CockpitServiceImpl implements CockpitService {
|
|
|
public List<TaskStatisticVo> edu(TaskStatisticDto dto) {
|
|
|
Date date = getStartDate(dto.getPeriod());
|
|
|
String orgPath = remoteOrgService.selectOrgById(dto.getOrgId(), SecurityConstants.INNER).getPath();
|
|
|
- List<TaskStatisticVo> list = cockpitMapper.edu(date, orgPath);
|
|
|
+ List<TaskStatisticVo> list = cockpitMapper.edu(date, DateUtil.endOfDay(new Date()), orgPath);
|
|
|
return taskStatistic(list, dto);
|
|
|
}
|
|
|
|
|
|
@@ -70,7 +72,7 @@ public class CockpitServiceImpl implements CockpitService {
|
|
|
public List<TaskStatisticVo> drill(TaskStatisticDto dto) {
|
|
|
Date date = getStartDate(dto.getPeriod());
|
|
|
String orgPath = remoteOrgService.selectOrgById(dto.getOrgId(), SecurityConstants.INNER).getPath();
|
|
|
- List<TaskStatisticVo> list = cockpitMapper.drill(date, orgPath);
|
|
|
+ List<TaskStatisticVo> list = cockpitMapper.drill(date, DateUtil.endOfDay(new Date()), orgPath);
|
|
|
return taskStatistic(list, dto);
|
|
|
}
|
|
|
|
|
|
@@ -81,14 +83,14 @@ public class CockpitServiceImpl implements CockpitService {
|
|
|
for (OrgGA38StatisticVo orgVo : data) {
|
|
|
for (OrgGA38StatisticVo statisticVo : r) {
|
|
|
if (orgVo.getOrgPath().startsWith(statisticVo.getOrgPath())) {
|
|
|
- statisticVo.setTotal(orgVo.getTotal() + statisticVo.getTotal());
|
|
|
+ statisticVo.setTotal(1 + statisticVo.getTotal());
|
|
|
statisticVo.setReachCount(orgVo.getReachCount() + statisticVo.getReachCount());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
r.forEach(i -> {
|
|
|
- if (ObjectUtil.equal(i.getTotal(), 0)) {
|
|
|
+ if (ObjectUtil.equal(i.getTotal(), 0F)) {
|
|
|
i.setReachRate(1F);
|
|
|
} else {
|
|
|
i.setReachRate(i.getReachCount() / i.getTotal());
|
|
|
@@ -97,7 +99,7 @@ public class CockpitServiceImpl implements CockpitService {
|
|
|
r.sort(new Comparator<OrgGA38StatisticVo>() {
|
|
|
@Override
|
|
|
public int compare(OrgGA38StatisticVo o1, OrgGA38StatisticVo o2) {
|
|
|
- return o1.getReachRate().compareTo(o2.getReachRate());
|
|
|
+ return NumberUtil.compare(o1.getReachRate(), o2.getReachRate());
|
|
|
}
|
|
|
});
|
|
|
|
|
|
@@ -123,7 +125,7 @@ public class CockpitServiceImpl implements CockpitService {
|
|
|
}
|
|
|
|
|
|
r.forEach(i -> {
|
|
|
- if (ObjectUtil.equal(i.getTaskTotal(), 0)) {
|
|
|
+ if (ObjectUtil.equal(i.getTaskTotal(), 0F)) {
|
|
|
i.setCompletedRate(1F);
|
|
|
} else {
|
|
|
i.setCompletedRate(i.getCompletedCount() / i.getTaskTotal());
|
|
|
@@ -137,11 +139,11 @@ public class CockpitServiceImpl implements CockpitService {
|
|
|
if (ObjectUtil.equal(period, PeriodEnum.Today.getCode())) {
|
|
|
return DateUtil.beginOfDay(new Date());
|
|
|
} else if (ObjectUtil.equal(period, PeriodEnum.Nearly7Days.getCode())) {
|
|
|
- return DateUtil.beginOfDay(DateUtil.offsetDay(new Date(), 7));
|
|
|
+ return DateUtil.beginOfDay(DateUtil.offsetDay(new Date(), -7));
|
|
|
} else if (ObjectUtil.equal(period, PeriodEnum.Nearly30Days.getCode())) {
|
|
|
- return DateUtil.beginOfDay(DateUtil.offsetDay(new Date(), 30));
|
|
|
+ return DateUtil.beginOfDay(DateUtil.offsetDay(new Date(), -30));
|
|
|
} else if (ObjectUtil.equal(period, PeriodEnum.Nearly90Days.getCode())) {
|
|
|
- return DateUtil.beginOfDay(DateUtil.offsetDay(new Date(), 90));
|
|
|
+ return DateUtil.beginOfDay(DateUtil.offsetDay(new Date(), -90));
|
|
|
} else if (ObjectUtil.equal(period, PeriodEnum.ThisYear.getCode())) {
|
|
|
return DateUtil.beginOfDay(DateUtil.beginOfYear(new Date()));
|
|
|
} else {
|
|
|
@@ -150,50 +152,64 @@ public class CockpitServiceImpl implements CockpitService {
|
|
|
}
|
|
|
|
|
|
private List<TaskStatisticVo> getTaskChildren(Long orgId) {
|
|
|
- List<SysOrg> children = remoteOrgService.selectSysOrgByParentId(orgId, SecurityConstants.INNER);
|
|
|
- List<Integer> enableOrgType = ListUtil.toList(
|
|
|
- OrgTypeEnum.HANG_SHE.getCode(),
|
|
|
- OrgTypeEnum.WANGDIAN_YEWUKU.getCode(),
|
|
|
- OrgTypeEnum.DIQU_HANG_SHE.getCode(),
|
|
|
- OrgTypeEnum.YINGYE_WANGDIAN.getCode()
|
|
|
- );
|
|
|
+ List<SysOrg> children = getChildren(orgId);
|
|
|
List<TaskStatisticVo> list = new ArrayList<>();
|
|
|
+
|
|
|
for (SysOrg child : children) {
|
|
|
- if (enableOrgType.contains(child.getType())) {
|
|
|
- TaskStatisticVo vo = new TaskStatisticVo();
|
|
|
- vo.setOrgPath(child.getPath());
|
|
|
- vo.setOrgId(child.getId());
|
|
|
- vo.setOrgName(child.getName());
|
|
|
- vo.setTaskTotal(0F);
|
|
|
- vo.setCompletedCount(0F);
|
|
|
- list.add(vo);
|
|
|
- }
|
|
|
+ TaskStatisticVo vo = new TaskStatisticVo();
|
|
|
+ vo.setOrgPath(child.getPath());
|
|
|
+ vo.setOrgId(child.getId());
|
|
|
+ vo.setOrgName(child.getName());
|
|
|
+ vo.setTaskTotal(0F);
|
|
|
+ vo.setCompletedCount(0F);
|
|
|
+ list.add(vo);
|
|
|
}
|
|
|
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
private List<OrgGA38StatisticVo> getGA38Children(Long orgId) {
|
|
|
+ List<SysOrg> children = getChildren(orgId);
|
|
|
+ List<OrgGA38StatisticVo> list = new ArrayList<>();
|
|
|
+ for (SysOrg child : children) {
|
|
|
+ OrgGA38StatisticVo vo = new OrgGA38StatisticVo();
|
|
|
+ vo.setOrgPath(child.getPath());
|
|
|
+ vo.setOrgId(child.getId());
|
|
|
+ vo.setOrgName(child.getName());
|
|
|
+ vo.setTotal(0F);
|
|
|
+ vo.setReachCount(0F);
|
|
|
+ list.add(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<SysOrg> getChildren(Long orgId) {
|
|
|
List<SysOrg> children = remoteOrgService.selectSysOrgByParentId(orgId, SecurityConstants.INNER);
|
|
|
+ List<SysOrg> banshichu = children.stream()
|
|
|
+ .filter(c -> ObjectUtil.equal(c.getType(), OrgTypeEnum.BAN_SHI_CHU.getCode()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isNotEmpty(banshichu)) {
|
|
|
+ List<SysOrg> diquHS = remoteOrgService.selectSysOrgByParentIds(banshichu.stream().map(SysOrg::getId).collect(Collectors.toList()), SecurityConstants.INNER);
|
|
|
+ children.addAll(diquHS);
|
|
|
+ }
|
|
|
List<Integer> enableOrgType = ListUtil.toList(
|
|
|
OrgTypeEnum.HANG_SHE.getCode(),
|
|
|
OrgTypeEnum.WANGDIAN_YEWUKU.getCode(),
|
|
|
OrgTypeEnum.DIQU_HANG_SHE.getCode(),
|
|
|
OrgTypeEnum.YINGYE_WANGDIAN.getCode()
|
|
|
);
|
|
|
- List<OrgGA38StatisticVo> list = new ArrayList<>();
|
|
|
- for (SysOrg child : children) {
|
|
|
- if (enableOrgType.contains(child.getType())) {
|
|
|
- OrgGA38StatisticVo vo = new OrgGA38StatisticVo();
|
|
|
- vo.setOrgPath(child.getPath());
|
|
|
- vo.setOrgId(child.getId());
|
|
|
- vo.setOrgName(child.getName());
|
|
|
- vo.setTotal(0F);
|
|
|
- vo.setReachCount(0F);
|
|
|
- list.add(vo);
|
|
|
- }
|
|
|
- }
|
|
|
+ List<TaskStatisticVo> list = new ArrayList<>();
|
|
|
+ children.sort(new Comparator<SysOrg>() {
|
|
|
+ @Override
|
|
|
+ public int compare(SysOrg o1, SysOrg o2) {
|
|
|
+ if (ObjectUtil.isNull(o1.getSort()) || ObjectUtil.isNull(o2.getSort())) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
|
|
|
- return list;
|
|
|
+ return o1.getSort().compareTo(o2.getSort());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return children.stream().filter(c -> enableOrgType.contains(c.getType())).collect(Collectors.toList());
|
|
|
}
|
|
|
}
|