全局看板接口功能

This commit is contained in:
zhangjunwen 2024-07-17 17:30:03 +08:00
parent b729be796c
commit d6d2814fb5
12 changed files with 593 additions and 9 deletions

View File

@ -0,0 +1,55 @@
package com.inspur.web.controller.bigscreen;
import com.inspur.bigscreen.service.IOverallDashboardService;
import com.inspur.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Author zhangjunwen
* @create 2024/7/17
*/
@RestController
@RequestMapping("/bigscreen/overall")
public class OverallDashboardController {
@Autowired
private IOverallDashboardService overallDashboardService;
@GetMapping("/countCompanyEquipNum")
public AjaxResult countCompanyEquipNum() {
return AjaxResult.success(overallDashboardService.countCompanyEquipNum());
}
@GetMapping("/countWeeklyEquipNum")
public AjaxResult countWeeklyEquipNum() {
return AjaxResult.success(overallDashboardService.countWeeklyEquipNum());
}
@GetMapping("/countMaintenanceNum")
public AjaxResult countMaintenanceNum() {
return AjaxResult.success(overallDashboardService.countMaintenanceNum());
}
@GetMapping("/countWeeklyMaintenanceNum")
public AjaxResult countWeeklyMaintenanceNum() {
return AjaxResult.success(overallDashboardService.countWeeklyMaintenanceNum());
}
@GetMapping("/countCompanyDeptNumByIndustry")
public AjaxResult countCompanyDeptNumByIndustry() {
return AjaxResult.success(overallDashboardService.countCompanyDeptNumByIndustry());
}
@GetMapping("/countEquipNumByStatus")
public AjaxResult countEquipNumByStatus() {
return AjaxResult.success(overallDashboardService.countEquipNumByStatus());
}
@GetMapping("/countCompanyDetails")
public AjaxResult countCompanyDetails() {
return AjaxResult.success(overallDashboardService.countCompanyDetails());
}
}

View File

@ -0,0 +1,24 @@
package com.inspur.bigscreen.constant;
/**
* @Author zhangjunwen
* @create 2024/7/17
*/
public class DeptIndustryCode {
/**
* 造纸
*/
public static final String PAPER = "0";
/**
* 炼金
*/
public static final String ALCHEMY = "1";
/**
* 其他
*/
public static final String OTHER = "2";
}

View File

@ -0,0 +1,46 @@
package com.inspur.bigscreen.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.ibatis.annotations.ConstructorArgs;
import java.util.List;
/**
* @Author zhangjunwen
* @create 2024/7/17
*/
@Data
@AllArgsConstructor
public class OverallDashboardDTO {
private Long deptId;
private String deptName;
private Integer type;
private Integer data;
private Integer status;
private String time;
private List<String> x;
private List<Object> y;
private Integer lineNum;
private Integer equipNum;
private Integer alarmNum;
public OverallDashboardDTO() {}
public OverallDashboardDTO(Integer status, Integer data) {
this.status = status;
this.data = data;
}
}

View File

@ -0,0 +1,20 @@
package com.inspur.bigscreen.mapper;
import com.inspur.bigscreen.dto.OverallDashboardDTO;
/**
* @Author zhangjunwen
* @create 2024/7/17
*/
public interface OverallDashboardMapper {
/**
* 统计各个公司设备总数
*/
public OverallDashboardDTO countCompanyEquipNum(Long deptId);
/**
* 根据公司id统计维修单数量
*/
public OverallDashboardDTO countMaintenanceNum(Long deptId);
}

View File

@ -0,0 +1,47 @@
package com.inspur.bigscreen.service;
import com.inspur.bigscreen.dto.OverallDashboardDTO;
import java.util.List;
/**
* @Author zhangjunwen
* @create 2024/7/17
*/
public interface IOverallDashboardService {
/**
* 查询各个公司的设备轴承数量
*/
public List<OverallDashboardDTO> countCompanyEquipNum();
/**
* 查询一周内总共的各个状态设备数及故障率
*/
public List<OverallDashboardDTO> countWeeklyEquipNum();
/**
* 查询各个公司维修单数量
*/
public List<OverallDashboardDTO> countMaintenanceNum();
/**
* 统计半年各个公司维修单数量
*/
public List<OverallDashboardDTO> countWeeklyMaintenanceNum();
/**
* 统计各个行业公司数量
*/
public List<OverallDashboardDTO> countCompanyDeptNumByIndustry();
/**
* 统计该公司各个状态设备数量
*/
public List<OverallDashboardDTO> countEquipNumByStatus();
/**
* 查询各个企业相关展示信息产线数设备数告警数量
*/
public List<OverallDashboardDTO> countCompanyDetails();
}

View File

@ -2,11 +2,8 @@ package com.inspur.bigscreen.service.impl;
import com.inspur.bigscreen.constant.EquipInfoStatus; import com.inspur.bigscreen.constant.EquipInfoStatus;
import com.inspur.bigscreen.dto.CompanyDashboardDTO; import com.inspur.bigscreen.dto.CompanyDashboardDTO;
import com.inspur.bigscreen.dto.CompanyDashboardDTO;
import com.inspur.bigscreen.dto.CompanyDashboardDTO;
import com.inspur.bigscreen.mapper.CompanyDashboardMapper; import com.inspur.bigscreen.mapper.CompanyDashboardMapper;
import com.inspur.bigscreen.service.ICompanyDashboardService; import com.inspur.bigscreen.service.ICompanyDashboardService;
import com.inspur.bigscreen.service.IFactoryDashboardService;
import com.inspur.common.core.domain.entity.SysDept; import com.inspur.common.core.domain.entity.SysDept;
import com.inspur.industrial.domain.IpcAlarmRecord; import com.inspur.industrial.domain.IpcAlarmRecord;
import com.inspur.industrial.service.IIpcAlarmRecordService; import com.inspur.industrial.service.IIpcAlarmRecordService;
@ -14,7 +11,6 @@ import com.inspur.spareparts.mapper.IpcSparePartsInboundMapper;
import com.inspur.spareparts.mapper.IpcSparePartsInfoMapper; import com.inspur.spareparts.mapper.IpcSparePartsInfoMapper;
import com.inspur.spareparts.mapper.IpcSparePartsOutboundMapper; import com.inspur.spareparts.mapper.IpcSparePartsOutboundMapper;
import com.inspur.system.mapper.SysDeptMapper; import com.inspur.system.mapper.SysDeptMapper;
import com.inspur.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -29,7 +25,7 @@ import java.util.stream.Collectors;
* @create 2024/7/15 * @create 2024/7/15
*/ */
@Service @Service
public class CompanyDashboardService implements ICompanyDashboardService { public class CompanyDashboardServiceImpl implements ICompanyDashboardService {
@Autowired @Autowired
private CompanyDashboardMapper companyDashboardMapper; private CompanyDashboardMapper companyDashboardMapper;

View File

@ -21,7 +21,7 @@ import java.util.stream.Collectors;
* @create 2024/7/11 * @create 2024/7/11
*/ */
@Service @Service
public class FactoryDashboardService implements IFactoryDashboardService { public class FactoryDashboardServiceImpl implements IFactoryDashboardService {
@Autowired @Autowired
private FactoryDashboardMapper factoryDashboardMapper; private FactoryDashboardMapper factoryDashboardMapper;

View File

@ -0,0 +1,284 @@
package com.inspur.bigscreen.service.impl;
import com.inspur.bigscreen.constant.DeptIndustryCode;
import com.inspur.bigscreen.constant.EquipInfoStatus;
import com.inspur.bigscreen.dto.CompanyDashboardDTO;
import com.inspur.bigscreen.dto.OverallDashboardDTO;
import com.inspur.bigscreen.mapper.CompanyDashboardMapper;
import com.inspur.bigscreen.mapper.OverallDashboardMapper;
import com.inspur.bigscreen.service.ICompanyDashboardService;
import com.inspur.bigscreen.service.IOverallDashboardService;
import com.inspur.common.core.domain.entity.SysDept;
import com.inspur.system.mapper.SysDeptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Author zhangjunwen
* @create 2024/7/17
*/
@Service
public class OverallDashboardServiceImpl implements IOverallDashboardService {
@Autowired
private SysDeptMapper sysDeptMapper;
@Autowired
private ICompanyDashboardService companyDashboardService;
@Autowired
private OverallDashboardMapper overallDashboardMapper;
@Autowired
private CompanyDashboardMapper companyDashboardMapper;
/**
* 查询各个公司的设备轴承数量
*/
@Override
public List<OverallDashboardDTO> countCompanyEquipNum(){
List<SysDept> companyDepts = getCompanyDept();
List<OverallDashboardDTO> resultList = new ArrayList<>();
for (SysDept companyDept : companyDepts) {
OverallDashboardDTO data = overallDashboardMapper.countCompanyEquipNum(companyDept.getDeptId());
data.setDeptId(companyDept.getDeptId());
data.setDeptName(companyDept.getDeptName());
resultList.add(data);
}
return resultList;
}
/**
* 查询一周内总共的各个状态设备数及故障率
*/
@Override
public List<OverallDashboardDTO> countWeeklyEquipNum(){
List<OverallDashboardDTO> resultList = new ArrayList<>();
List<CompanyDashboardDTO> companyDashboardDTOList1 = companyDashboardMapper.countWeeklyEquipRunningNumByCompanyDeptId(100L, EquipInfoStatus.RUNNING);
List<CompanyDashboardDTO> companyDashboardDTOList2 = companyDashboardMapper.countWeeklyEquipRunningNumByCompanyDeptId(100L,EquipInfoStatus.MAINTENANCE);
List<CompanyDashboardDTO> companyDashboardDTOList3 = companyDashboardMapper.countWeeklyEquipRunningNumByCompanyDeptId(100L,EquipInfoStatus.STOP);
resultList.add(convertCompanyData(companyDashboardDTOList1,EquipInfoStatus.RUNNING));
resultList.add(convertCompanyData(companyDashboardDTOList2,EquipInfoStatus.MAINTENANCE));
resultList.add(convertCompanyData(companyDashboardDTOList3,EquipInfoStatus.STOP));
return resultList;
}
/**
* 查询各个公司维修单数量
*/
@Override
public List<OverallDashboardDTO> countMaintenanceNum(){
List<SysDept> companyDepts = getCompanyDept();
List<OverallDashboardDTO> resultList = new ArrayList<>();
for (SysDept companyDept : companyDepts) {
OverallDashboardDTO data = overallDashboardMapper.countMaintenanceNum(companyDept.getDeptId());
data.setDeptId(companyDept.getDeptId());
data.setDeptName(companyDept.getDeptName());
resultList.add(data);
}
return resultList;
}
/**
* 统计半年各个公司维修单数量
*/
@Override
public List<OverallDashboardDTO> countWeeklyMaintenanceNum(){
List<SysDept> companyDepts = getCompanyDept();
List<OverallDashboardDTO> resultList = new ArrayList<>();
for (SysDept companyDept : companyDepts) {
OverallDashboardDTO data = getMatenanceDataByHalfYear(companyDept.getDeptId());
data.setDeptId(companyDept.getDeptId());
data.setDeptName(companyDept.getDeptName());
resultList.add(data);
}
return resultList;
}
/**
* 统计各个行业公司数量
*/
public List<OverallDashboardDTO> countCompanyDeptNumByIndustry(){
List<SysDept> companyDepts = getCompanyDept();
long paperNum = companyDepts.stream().filter(dept -> dept.getIndustryCode().equals(DeptIndustryCode.PAPER)).count();
long alchemyNum = companyDepts.stream().filter(dept -> dept.getIndustryCode().equals(DeptIndustryCode.ALCHEMY)).count();
long otherNum = companyDepts.stream().filter(dept -> dept.getIndustryCode().equals(DeptIndustryCode.OTHER)).count();
return Arrays.asList(
new OverallDashboardDTO(Integer.valueOf(DeptIndustryCode.PAPER),(int)paperNum),
new OverallDashboardDTO(Integer.valueOf(DeptIndustryCode.ALCHEMY),(int)alchemyNum),
new OverallDashboardDTO(Integer.valueOf(DeptIndustryCode.OTHER),(int)otherNum)
);
}
/**
* 统计该公司各个状态设备数量
*/
public List<OverallDashboardDTO> countEquipNumByStatus(){
List<CompanyDashboardDTO> companyDashboardDTOList =companyDashboardService.countEquipNumByStatus(100L);
return companyDashboardDTOList.stream().map(companyDashboardDTO -> {
OverallDashboardDTO data = new OverallDashboardDTO();
data.setStatus(companyDashboardDTO.getStatus());
data.setData(companyDashboardDTO.getData());
return data;
}).collect(Collectors.toList());
}
/**
* 查询各个企业相关展示信息产线数设备数告警数量
*/
public List<OverallDashboardDTO> countCompanyDetails(){
List<SysDept> companyDepts = getCompanyDept();
List<OverallDashboardDTO> resultList = new ArrayList<>();
for (SysDept companyDept : companyDepts) {
OverallDashboardDTO data = new OverallDashboardDTO();
//查询该公司产线数
List<SysDept> childDepts = sysDeptMapper.selectChildrenDeptById(companyDept.getDeptId());
List<SysDept> lineDepts = childDepts.stream().filter(dept -> dept.getAncestors().split(",").length == 4).collect(Collectors.toList());
int lineNum = lineDepts.size();
//查询设备数
int equipNum = overallDashboardMapper.countCompanyEquipNum(companyDept.getDeptId()).getData();
//查询报警数
List<CompanyDashboardDTO> alarmList = companyDashboardService.countAlarmNumByCompanyId(companyDept.getDeptId());
int alarmNum = alarmList.stream().mapToInt(CompanyDashboardDTO::getData).sum();
data.setDeptId(companyDept.getDeptId());
data.setDeptName(companyDept.getDeptName());
data.setLineNum(lineNum);
data.setEquipNum(equipNum);
data.setAlarmNum(alarmNum);
resultList.add(data);
}
return resultList;
}
/**
* 查询系统重公司部门
*/
private List<SysDept> getCompanyDept(){
SysDept query = new SysDept();
query.setParentId(100L);
return sysDeptMapper.selectDeptList(query);
}
/**
* 将查询的公司数据转全局数据
*/
private OverallDashboardDTO convertCompanyData(List<CompanyDashboardDTO> companyList,Integer status){
OverallDashboardDTO result = new OverallDashboardDTO();
List<String> timeList = new ArrayList<>();
List<Object> dataList = new ArrayList<>();
for (CompanyDashboardDTO companyDashboardDTO : companyList) {
timeList.add(companyDashboardDTO.getTime());
dataList.add(companyDashboardDTO.getData());
}
Collections.reverse(timeList);
Collections.reverse(dataList);
result.setStatus(status);
result.setX(timeList);
result.setY(dataList);
return result;
}
/**
* 获取当前时间半年内的时间并查询数据
*/
private OverallDashboardDTO getMatenanceDataByHalfYear(Long deptId){
OverallDashboardDTO returnData = new OverallDashboardDTO();
List<String> timeList = new ArrayList<>();
List<Object> dataList = new ArrayList<>();
List<Date> halfYearDate = getHalfYearDate();
//修改日期年月日
for (Date date : halfYearDate) {
CompanyDashboardDTO factoryData = companyDashboardMapper.countMaintenanceRecordNumByCompanyDeptId(date,deptId);
String time = factoryData.getTime();
timeList.add(time.substring(0,time.lastIndexOf("-")));
dataList.add(factoryData.getData());
}
Collections.reverse(timeList);
Collections.reverse(dataList);
returnData.setX(timeList);
returnData.setY(dataList);
return returnData;
}
// /**
// * 获取当前时间半年内的保养数据
// */
// private CompanyDashboardDTO getUpkeepDataByHalfYear(Long deptId){
// CompanyDashboardDTO returnData = new CompanyDashboardDTO();
// List<String> timeList = new ArrayList<>();
// List<Object> dataList = new ArrayList<>();
// List<Date> halfYearDate = getHalfYearDate();
// //修改日期年月日
// for (Date date : halfYearDate) {
// CompanyDashboardDTO factoryData = companyDashboardMapper.countUpkeepRecordNumByCompanyDeptId(date,deptId);
// String time = factoryData.getTime();
// timeList.add(time.substring(0,time.lastIndexOf("-")));
// dataList.add(factoryData.getData());
// }
// Collections.reverse(timeList);
// Collections.reverse(dataList);
// returnData.setX(timeList);
// returnData.setY(dataList);
// return returnData;
// }
//
// /**
// * 获取半年内巡检工单数量
// */
// private List<CompanyDashboardDTO> getPatrolRecordNumByHalfYear(Long deptId){
// CompanyDashboardDTO returnData1 = new CompanyDashboardDTO();
// CompanyDashboardDTO returnData2 = new CompanyDashboardDTO();
// List<String> timeList1 = new ArrayList<>();
// List<String> timeList2 = new ArrayList<>();
// List<Object> dataList1 = new ArrayList<>();
// List<Object> dataList2 = new ArrayList<>();
// List<Date> halfYearDate = getHalfYearDate();
// //修改日期年月日
// for (Date date : halfYearDate) {
// List<CompanyDashboardDTO> factoryData = companyDashboardMapper.countPatrolRecordNumByCompanyDeptId(date,deptId);
// returnData1.setType(factoryData.get(0).getType());
// String time1 = factoryData.get(0).getTime();
// timeList1.add(time1.substring(0,time1.lastIndexOf("-")));
// dataList1.add(factoryData.get(0).getData());
// returnData2.setType(factoryData.get(1).getType());
// String time2 = factoryData.get(1).getTime();
// timeList2.add(time2.substring(0,time2.lastIndexOf("-")));
// dataList2.add(factoryData.get(1).getData());
// }
// Collections.reverse(timeList1);
// Collections.reverse(timeList2);
// Collections.reverse(dataList1);
// Collections.reverse(dataList2);
// returnData1.setX(timeList1);
// returnData1.setY(dataList1);
// returnData2.setX(timeList2);
// returnData2.setY(dataList2);
// return Arrays.asList(returnData1,returnData2);
// }
/**
* 获取当前时间内半年月份
*/
private List<Date> getHalfYearDate(){
LocalDate currentDate = LocalDate.now();
List<Date> halfYearDate = new ArrayList<>();
// 遍历当前日期之后的6个月包括当前月份
for (int i = 0; i < 6; i++) {
LocalDate firstDayOfMonth = currentDate.withDayOfMonth(1);
Date date = Date.from(firstDayOfMonth.atStartOfDay(ZoneId.systemDefault()).toInstant());
halfYearDate.add(date);
currentDate = currentDate.minusMonths(1L);
}
return halfYearDate;
}
}

View File

@ -39,7 +39,7 @@
ipc_equip_info ipc_equip_info
where where
dept_id in dept_id in
(select dept_id from sys_dept where FIND_IN_SET(#{deptId}, ancestors)) (select dept_id from sys_dept where FIND_IN_SET(#{deptId}, ancestors) or dept_id = #{deptId})
and status = #{status} and status = #{status}
</select> </select>
@ -129,7 +129,7 @@
<!-- 统计公司内设备报警数量countAlarmNumByCompanyId--> <!-- 统计公司内设备报警数量countAlarmNumByCompanyId-->
<select id="countAlarmNumByCompanyId" parameterType="Long" resultMap="companyData"> <select id="countAlarmNumByCompanyId" parameterType="Long" resultMap="companyData">
select m.status,n.data select m.status,ifnull(n.data,0) as data
from from
( (
select 0 as status select 0 as status

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.inspur.bigscreen.mapper.OverallDashboardMapper">
<resultMap type="com.inspur.bigscreen.dto.OverallDashboardDTO" id="overallData">
<result property="deptId" column="dept_id"/>
<result property="deptName" column="dept_name"/>
<result property="data" column="data"/>
<result property="type" column="type"/>
<result property="status" column="status"/>
<result property="time" column="time"/>
</resultMap>
<sql id="selectWeeklyDate">
select curdate() as click_date
union all
select date_sub(curdate(), interval 1 day) as click_date
union all
select date_sub(curdate(), interval 2 day) as click_date
union all
select date_sub(curdate(), interval 3 day) as click_date
union all
select date_sub(curdate(), interval 4 day) as click_date
union all
select date_sub(curdate(), interval 5 day) as click_date
union all
select date_sub(curdate(), interval 6 day) as click_date
</sql>
<select id="countCompanyEquipNum" parameterType="Long" resultMap="overallData">
select count(1) as data
from ipc_equip_info
where dept_id in
(select dept_id from sys_dept where FIND_IN_SET(#{deptId}, ancestors) or dept_id = #{deptId})
</select>
<!--根据公司id统计维修单数量countMaintenanceNum(Long deptId);-->
<select id="countMaintenanceNum" parameterType="Long" resultMap="overallData">
select count(1) as data
from ipc_maintenance_record
where dept_id in
(select dept_id from sys_dept where FIND_IN_SET(#{deptId}, ancestors) or dept_id = #{deptId})
</select>
</mapper>

View File

@ -0,0 +1,57 @@
import request from "@/utils/request";
// 统计各个公司的设备数
export function getCompanyEquipNum() {
return request({
url: "/bigscreen/overall/countCompanyEquipNum",
method: "get",
});
}
// 统计各个设备数量
export function getWeeklyEquipNum() {
return request({
url: "/bigscreen/overall/countWeeklyEquipNum",
method: "get",
});
}
// 统计各个公司维修数量
export function getMaintenanceNum() {
return request({
url: "/bigscreen/overall/countMaintenanceNum",
method: "get",
});
}
// 统计半年内各个公司维修数量
export function getWeeklyMaintenanceNum() {
return request({
url: "/bigscreen/overall/countWeeklyMaintenanceNum",
method: "get",
});
}
// 统计各个行业接入企业数量
export function getCompanyDeptNumByIndustry() {
return request({
url: "/bigscreen/overall/countCompanyDeptNumByIndustry",
method: "get",
});
}
// 统计各个不同状态设备数量
export function getEquipNumByStatus() {
return request({
url: "/bigscreen/overall/countEquipNumByStatus",
method: "get",
});
}
// 统计各个公司相关统计信息
export function getCompanyDetails() {
return request({
url: "/bigscreen/overall/countCompanyDetails",
method: "get",
});
}

View File

@ -468,6 +468,15 @@ import {
getWeeklyAlarmNumByCompany, getWeeklyAlarmNumByCompany,
getSparePartsNumByCompany, getSparePartsNumByCompany,
} from "@/api/bigscreen/company"; } from "@/api/bigscreen/company";
import {
getCompanyEquipNum,
getWeeklyEquipNum,
getMaintenanceNum,
getWeeklyMaintenanceNum,
getCompanyDeptNumByIndustry,
getEquipNumByStatus,
getCompanyDetails,
} from "@/api/bigscreen/overall";
export default { export default {
name: "Category", name: "Category",
components: { components: {
@ -595,7 +604,7 @@ export default {
this.getList(); this.getList();
this.getDeptTree(); this.getDeptTree();
// //
getSparePartsNumByCompany(101).then((response) => { getCompanyDetails().then((response) => {
console.log("data:", response.data); console.log("data:", response.data);
}); });
}, },