|
|
|
@ -2,15 +2,21 @@ package cn.iocoder.yudao.module.system.service.home;
|
|
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
|
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.RoleNameAndSelectTypeVO; |
|
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.enterprise.vo.LabelValueVO; |
|
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.home.vo.*; |
|
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.taskinfo.vo.TaskInfoPageReqVO; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.enterprise.EnterpriseDO; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.taskinfo.TaskInfoDO; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.userarea.UserAreaDO; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.mysql.enterprise.EnterpriseMapper; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.mysql.enterprisetag.EnterpriseTagMapper; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.mysql.taskinfo.TaskInfoMapper; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.mysql.userarea.UserAreaMapper; |
|
|
|
|
import cn.iocoder.yudao.module.system.service.auth.AdminAuthService; |
|
|
|
|
import cn.iocoder.yudao.module.system.service.auth.AdminAuthServiceImpl; |
|
|
|
|
import cn.iocoder.yudao.module.system.service.dept.DeptService; |
|
|
|
|
import cn.iocoder.yudao.module.system.service.dict.DictDataService; |
|
|
|
|
import cn.iocoder.yudao.module.system.service.taskinfo.TaskInfoService; |
|
|
|
|
import cn.iocoder.yudao.module.system.service.user.AdminUserService; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
@ -19,12 +25,11 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.Comparator; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
|
|
@Service |
|
|
|
|
public class HomeServiceImpl implements HomeService{ |
|
|
|
@ -36,149 +41,153 @@ public class HomeServiceImpl implements HomeService{
|
|
|
|
|
private TaskInfoMapper taskInfoMapper; |
|
|
|
|
@Resource |
|
|
|
|
private AdminAuthService authService; |
|
|
|
|
@Resource |
|
|
|
|
private UserAreaMapper userAreaMapper; |
|
|
|
|
@Resource |
|
|
|
|
private DictDataService dictDataService; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public HomeCountResVO appCount1(HomeSelectVO homeSelectVO) { |
|
|
|
|
// 1. 初始化参数处理
|
|
|
|
|
processDeptSelection(homeSelectVO); |
|
|
|
|
|
|
|
|
|
//如果不传部门id 上来就是根据用户的所在的部门查询
|
|
|
|
|
RoleNameAndSelectTypeVO typeVO = authService.roleTypeByUserId(); |
|
|
|
|
// 2. 构建结果对象
|
|
|
|
|
HomeCountResVO result = new HomeCountResVO(); |
|
|
|
|
|
|
|
|
|
if (homeSelectVO.getDeptId() == null) { |
|
|
|
|
if ("self".equals(typeVO.getRoleName())) { |
|
|
|
|
homeSelectVO.setDeptId(typeVO.getDeptId()); |
|
|
|
|
} |
|
|
|
|
if ("queue".equals(typeVO.getRoleName())) { |
|
|
|
|
homeSelectVO.setDeptId(typeVO.getValue()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 3. 统计企业数量
|
|
|
|
|
result.setEnterpriseCount(getEnterpriseCount(homeSelectVO)); |
|
|
|
|
|
|
|
|
|
HomeCountResVO homeCountResVO = new HomeCountResVO(); |
|
|
|
|
// 4. 处理任务统计数据
|
|
|
|
|
processTaskStatistics(result, homeSelectVO); |
|
|
|
|
|
|
|
|
|
//查企业
|
|
|
|
|
final Integer enterpriseCount = this.getEnterpriseCount(homeSelectVO); |
|
|
|
|
homeCountResVO.setEnterpriseCount(enterpriseCount); |
|
|
|
|
// 5. 处理分组统计饼图
|
|
|
|
|
processGroupStatistics(result, homeSelectVO); |
|
|
|
|
|
|
|
|
|
//查询任务和执法
|
|
|
|
|
final List<HomeExecFinishVO> homeExecFinishVOS = taskInfoMapper.selectHomeExecFinish(homeSelectVO); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
List<Integer> taskExecList = new ArrayList<>(); |
|
|
|
|
List<Integer> taskFinishList = new ArrayList<>(); |
|
|
|
|
if (homeExecFinishVOS != null && homeExecFinishVOS.size() > 0) { |
|
|
|
|
homeExecFinishVOS.forEach(item->{ |
|
|
|
|
taskExecList.add(item.getExecCount()); |
|
|
|
|
taskFinishList.add(item.getFinishCount()); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// 参数处理方法
|
|
|
|
|
private void processDeptSelection(HomeSelectVO homeSelectVO) { |
|
|
|
|
if (homeSelectVO.getDeptId() != null) return; |
|
|
|
|
|
|
|
|
|
RoleNameAndSelectTypeVO roleInfo = authService.roleTypeByUserId(); |
|
|
|
|
switch (roleInfo.getRoleName()) { |
|
|
|
|
case AdminAuthServiceImpl.RoleConstants.ROLE_SELF: |
|
|
|
|
homeSelectVO.setDeptId(roleInfo.getDeptId()); |
|
|
|
|
break; |
|
|
|
|
case AdminAuthServiceImpl.RoleConstants.ROLE_QUEUE: |
|
|
|
|
homeSelectVO.setDeptId(roleInfo.getValue()); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
// 其他角色不需要设置部门ID
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//任务总数
|
|
|
|
|
homeCountResVO.setTaskCount(homeExecFinishVOS.size()); |
|
|
|
|
// 任务统计处理方法
|
|
|
|
|
private void processTaskStatistics(HomeCountResVO result, HomeSelectVO query) { |
|
|
|
|
List<HomeExecFinishVO> taskData = Optional.ofNullable(taskInfoMapper.selectHomeExecFinish(query)) |
|
|
|
|
.orElse(Collections.emptyList()); |
|
|
|
|
|
|
|
|
|
//总数
|
|
|
|
|
final Integer taskExec = taskExecList.stream().reduce(Integer::sum).orElse(0); |
|
|
|
|
homeCountResVO.setInspectionsCount(taskExec); |
|
|
|
|
result.setTaskCount(taskData.size()); |
|
|
|
|
|
|
|
|
|
//完成数
|
|
|
|
|
final Integer taskFinish = taskFinishList.stream().reduce(Integer::sum).orElse(0); |
|
|
|
|
int totalExec = taskData.stream() |
|
|
|
|
.mapToInt(HomeExecFinishVO::getExecCount) |
|
|
|
|
.sum(); |
|
|
|
|
result.setInspectionsCount(totalExec); |
|
|
|
|
|
|
|
|
|
if (taskFinish != null && taskFinish != 0) { |
|
|
|
|
double taskCompletionRate = (double) taskFinish/taskExec*100; |
|
|
|
|
homeCountResVO.setTaskCompletionRate(String.format("%.1f", taskCompletionRate)); |
|
|
|
|
} else { |
|
|
|
|
homeCountResVO.setTaskCompletionRate("0.0"); |
|
|
|
|
} |
|
|
|
|
int totalFinish = taskData.stream() |
|
|
|
|
.mapToInt(HomeExecFinishVO::getFinishCount) |
|
|
|
|
.sum(); |
|
|
|
|
result.setTaskCompletionRate(calculateCompletionRate(totalFinish, totalExec)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//根据不同的身份查询
|
|
|
|
|
final List<HomeGroupCountVO> homeGroupCountVOS = taskInfoMapper.selectHomeGroupCount(homeSelectVO); |
|
|
|
|
List<HomeListVO> homeGroupCountVOS1 = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
if (homeGroupCountVOS != null && homeGroupCountVOS.size() > 0) { |
|
|
|
|
homeGroupCountVOS.forEach(item->{ |
|
|
|
|
HomeListVO homeListVO = new HomeListVO(); |
|
|
|
|
homeListVO.setName(item.getName()); |
|
|
|
|
homeListVO.setValue(item.getCompletionRate()); |
|
|
|
|
// double rate = (double) item.getFinishCount() /taskExec * 100;
|
|
|
|
|
// homeListVO.setPieValue(String.format("%.1f", rate));
|
|
|
|
|
homeGroupCountVOS1.add(homeListVO); |
|
|
|
|
}); |
|
|
|
|
// 完成率计算方法
|
|
|
|
|
private String calculateCompletionRate(int finish, int total) { |
|
|
|
|
return total > 0 ? String.format(Locale.US, "%.1f", (finish * 100.0) / total) : "0.0"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//循环饼图占比数据
|
|
|
|
|
|
|
|
|
|
final List<Double> collect = homeGroupCountVOS1.stream().filter(i -> !i.getValue().equals("0.0")). |
|
|
|
|
map(i -> Double.parseDouble(i.getValue())).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
double total = collect.stream() |
|
|
|
|
.reduce(0.0, Double::sum); |
|
|
|
|
|
|
|
|
|
homeGroupCountVOS1.forEach(item->{ |
|
|
|
|
if (item != null && item.getValue() != null) { |
|
|
|
|
final double value = Double.parseDouble(item.getValue()); |
|
|
|
|
if (total != 0 && value != 0) { |
|
|
|
|
final double pieRate = value / total * 100; |
|
|
|
|
// 如果 TaskCompletionRate 不为空,则乘以该值
|
|
|
|
|
String taskCompletionRateStr = homeCountResVO.getTaskCompletionRate(); |
|
|
|
|
double taskCompletionRate = "0.0".equals(taskCompletionRateStr) ? 0.0 : Double.parseDouble(taskCompletionRateStr); |
|
|
|
|
final double pie = pieRate * taskCompletionRate / 100; |
|
|
|
|
item.setPieValue(String.format("%.1f", pie)); |
|
|
|
|
} else { |
|
|
|
|
item.setPieValue(String.format("%.1f", 0.0)); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
item.setPieValue(String.format("%.1f", 0.0)); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
// 分组统计处理方法
|
|
|
|
|
private void processGroupStatistics(HomeCountResVO result, HomeSelectVO query) { |
|
|
|
|
List<HomeGroupCountVO> groupData = Optional.ofNullable(taskInfoMapper.selectHomeGroupCount(query)) |
|
|
|
|
.orElse(Collections.emptyList()); |
|
|
|
|
|
|
|
|
|
List<HomeListVO> pieData = groupData.stream() |
|
|
|
|
.map(this::convertToPieItem) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
calculatePieValues(pieData, result.getTaskCompletionRate()); |
|
|
|
|
result.setCompletionRate(pieData); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 数据转换方法
|
|
|
|
|
private HomeListVO convertToPieItem(HomeGroupCountVO item) { |
|
|
|
|
HomeListVO vo = new HomeListVO(); |
|
|
|
|
vo.setName(item.getName()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
// 将字符串解析为浮点数
|
|
|
|
|
float rate = Float.parseFloat(item.getCompletionRate()); |
|
|
|
|
// 格式化为保留一位小数的字符串
|
|
|
|
|
String formattedRate = String.format(Locale.US, "%.1f", rate); |
|
|
|
|
// 传递给 VO
|
|
|
|
|
vo.setValue(formattedRate); |
|
|
|
|
} catch (NumberFormatException e) { |
|
|
|
|
// 处理无效字符串(例如赋默认值或记录错误)
|
|
|
|
|
vo.setValue("0.0"); |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return vo; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//排序
|
|
|
|
|
final List<HomeListVO> sortedList = homeGroupCountVOS1.stream() |
|
|
|
|
.filter(item -> item.getValue() != null && !item.getValue().isEmpty()) // 过滤掉 null 或空字符串
|
|
|
|
|
.sorted(Comparator.comparing( |
|
|
|
|
item -> { |
|
|
|
|
try { |
|
|
|
|
return Double.parseDouble(item.getValue()); // 将字符串转为 double
|
|
|
|
|
} catch (NumberFormatException e) { |
|
|
|
|
return Double.MIN_VALUE; // 如果解析失败,视为最小值
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
)) // 升序排序
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
// 饼图数值计算方法
|
|
|
|
|
private void calculatePieValues(List<HomeListVO> items, String baseRate) { |
|
|
|
|
double baseRateValue = parseDoubleSafely(baseRate); |
|
|
|
|
double total = items.stream() |
|
|
|
|
.mapToDouble(i -> parseDoubleSafely(i.getValue())) |
|
|
|
|
.sum(); |
|
|
|
|
|
|
|
|
|
items.forEach(item -> { |
|
|
|
|
double itemValue = parseDoubleSafely(item.getValue()); |
|
|
|
|
double pieValue = total > 0 ? (itemValue / total) * baseRateValue : 0.0; |
|
|
|
|
item.setPieValue(String.format(Locale.US, "%.1f", pieValue)); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (sortedList != null && sortedList.size() > 0) { |
|
|
|
|
List<HomeListVO> reversedList = new ArrayList<>(); |
|
|
|
|
for (int i = sortedList.size() - 1; i >= 0; i--) { |
|
|
|
|
reversedList.add(sortedList.get(i)); |
|
|
|
|
} |
|
|
|
|
homeCountResVO.setCompletionRate(reversedList); |
|
|
|
|
// 安全转换方法
|
|
|
|
|
private double parseDoubleSafely(String value) { |
|
|
|
|
try { |
|
|
|
|
return Double.parseDouble(value); |
|
|
|
|
} catch (NumberFormatException e) { |
|
|
|
|
return 0.0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return homeCountResVO; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public LocalDateTime[] getWeekDate(Integer selectWeek) { |
|
|
|
|
//按时间查询
|
|
|
|
|
LocalDateTime now = LocalDateTime.now(); |
|
|
|
|
LocalDateTime[] dateList = new LocalDateTime[2]; |
|
|
|
|
|
|
|
|
|
switch (selectWeek) { |
|
|
|
|
case 4: |
|
|
|
|
dateList[0] = now.minusDays(3); // 三天前
|
|
|
|
|
break; |
|
|
|
|
case 3: |
|
|
|
|
dateList[0] = now.minusWeeks(1); // 一周前
|
|
|
|
|
break; |
|
|
|
|
case 2: |
|
|
|
|
dateList[0] = now.minusMonths(1); // 一月前
|
|
|
|
|
break; |
|
|
|
|
case 1: |
|
|
|
|
dateList[0] = now.minusYears(1); // 一年前
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
dateList[1] = now; |
|
|
|
|
LocalDateTime now = LocalDateTime.now(); |
|
|
|
|
LocalDateTime[] dateList = new LocalDateTime[2]; |
|
|
|
|
|
|
|
|
|
switch (selectWeek) { |
|
|
|
|
case 4: |
|
|
|
|
dateList[0] = now.minusDays(3); // 三天前
|
|
|
|
|
break; |
|
|
|
|
case 3: |
|
|
|
|
dateList[0] = now.minusWeeks(1); // 一周前
|
|
|
|
|
break; |
|
|
|
|
case 2: |
|
|
|
|
dateList[0] = now.minusMonths(1); // 一月前
|
|
|
|
|
break; |
|
|
|
|
case 1: |
|
|
|
|
dateList[0] = now.minusYears(1); // 一年前
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
dateList[1] = now; |
|
|
|
|
|
|
|
|
|
return dateList; |
|
|
|
|
return dateList; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -205,6 +214,53 @@ public class HomeServiceImpl implements HomeService{
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<LabelValueVO> getUserArea() { |
|
|
|
|
|
|
|
|
|
List<LabelValueVO> labelValueVOS = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
RoleNameAndSelectTypeVO typeVO = authService.roleTypeByUserId(); |
|
|
|
|
if ("director".equals(typeVO.getRoleName())) { |
|
|
|
|
//局长返回整个字典
|
|
|
|
|
final List<DictDataDO> enterprisesArea = dictDataService.getDictDataList(0, "enterprises_area"); |
|
|
|
|
enterprisesArea.forEach(item-> { |
|
|
|
|
LabelValueVO labelValueVO = new LabelValueVO(); |
|
|
|
|
labelValueVO.setLabel(item.getLabel()); |
|
|
|
|
labelValueVO.setValue(Integer.valueOf(item.getValue())); |
|
|
|
|
labelValueVOS.add(labelValueVO); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
// LambdaQueryWrapper<UserAreaDO> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
// wrapper.eq(UserAreaDO::getUserId, getLoginUserId());
|
|
|
|
|
// final List<UserAreaDO> userAreaDOS = userAreaMapper.selectList(wrapper);
|
|
|
|
|
// if (userAreaDOS != null && userAreaDOS.size() > 0) {
|
|
|
|
|
// userAreaDOS.forEach(item->{
|
|
|
|
|
// LabelValueVO labelValueVO = new LabelValueVO();
|
|
|
|
|
// final DictDataDO enterprisesArea = dictDataService.getDictData("enterprises_area", item.getArea().toString());
|
|
|
|
|
// labelValueVO.setLabel(enterprisesArea.getLabel());
|
|
|
|
|
// labelValueVO.setValue(Integer.valueOf(item.getArea()));
|
|
|
|
|
// labelValueVOS.add(labelValueVO);
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
LambdaQueryWrapper<EnterpriseDO> enterpriseDOLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
enterpriseDOLambdaQueryWrapper.eq(EnterpriseDO::getUserId, getLoginUserId()); |
|
|
|
|
final List<EnterpriseDO> enterpriseDOS = enterpriseMapper.selectList(enterpriseDOLambdaQueryWrapper); |
|
|
|
|
final List<String> collect = enterpriseDOS.stream().map(item -> item.getRegion()).distinct().collect(Collectors.toList()); |
|
|
|
|
if (collect != null && collect.size() > 0) { |
|
|
|
|
collect.forEach(item->{ |
|
|
|
|
final DictDataDO enterprisesArea = dictDataService.getDictData("enterprises_area", item); |
|
|
|
|
LabelValueVO labelValueVO = new LabelValueVO(); |
|
|
|
|
labelValueVO.setLabel(enterprisesArea.getLabel()); |
|
|
|
|
labelValueVO.setValue(Integer.valueOf(item)); |
|
|
|
|
labelValueVOS.add(labelValueVO); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return labelValueVOS; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//查企业
|
|
|
|
|
public Integer getEnterpriseCount(HomeSelectVO homeSelectVO) { |
|
|
|
|
LambdaQueryWrapper<EnterpriseDO> enterpriseDOLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
@ -213,10 +269,11 @@ public class HomeServiceImpl implements HomeService{
|
|
|
|
|
final LocalDateTime[] weekDate = this.getWeekDate(homeSelectVO.getSelectWeek()); |
|
|
|
|
enterpriseDOLambdaQueryWrapper.between(EnterpriseDO::getCreateTime, weekDate[0], weekDate[1]); |
|
|
|
|
} |
|
|
|
|
enterpriseDOLambdaQueryWrapper.eq(homeSelectVO.getDeptId() != null, EnterpriseDO::getDepartmentId, homeSelectVO.getDeptId()); |
|
|
|
|
enterpriseDOLambdaQueryWrapper.eq(homeSelectVO.getRegion() != null, EnterpriseDO::getRegion, homeSelectVO.getRegion()); |
|
|
|
|
final Long enterpriseCount = enterpriseMapper.selectCount(enterpriseDOLambdaQueryWrapper); |
|
|
|
|
return enterpriseCount.intValue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|