厂区看板接口开发

This commit is contained in:
zhangjunwen 2024-07-15 14:53:02 +08:00
parent 6b9bf6cf64
commit a6851ff16a
23 changed files with 378 additions and 43 deletions

View File

@ -39,4 +39,24 @@ public class FactoryDashboardController {
public AjaxResult countWeeklyAlarmNumByLineDeptId(@PathVariable Long deptId) {
return AjaxResult.success(factoryDashboardService.countAlarmNumByProductionLine(deptId));
}
@GetMapping("/countWeeklyEquipRunningNumByLineDeptId/{deptId}")
public AjaxResult countWeeklyEquipRunningNumByLineDeptId(@PathVariable Long deptId) {
return AjaxResult.success(factoryDashboardService.countWeeklyEquipRunningNumByLineDeptId(deptId));
}
@GetMapping("/countMaintenanceRecordNumByProductionLine/{deptId}")
public AjaxResult countMaintenanceRecordNumByProductionLine(@PathVariable Long deptId) {
return AjaxResult.success(factoryDashboardService.countMaintenanceRecordNumByProductionLine(deptId));
}
@GetMapping("/countUpkeepRecordNumByProductionLine/{deptId}")
public AjaxResult countUpkeepRecordNumByProductionLine(@PathVariable Long deptId) {
return AjaxResult.success(factoryDashboardService.countUpkeepRecordNumByProductionLine(deptId));
}
@GetMapping("/listLatestAlarmRecord/{deptId}")
public AjaxResult listLatestAlarmRecord(@PathVariable Long deptId) {
return AjaxResult.success(factoryDashboardService.selectLatestIpcAlarmRecordByFactoryId(deptId));
}
}

View File

@ -1,6 +1,7 @@
package com.inspur.bigscreen.dto;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.List;

View File

@ -1,8 +1,11 @@
package com.inspur.bigscreen.mapper;
import com.inspur.bigscreen.dto.FactoryDashboardDTO;
import net.sf.jsqlparser.expression.DateTimeLiteralExpression;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -35,5 +38,18 @@ public interface FactoryDashboardMapper {
/**
* 近一周产线各设备正常运行数量
*/
public List<FactoryDashboardDTO> countWeeklyEquipRunningNumByLineDeptId(Long deptId);
public List<FactoryDashboardDTO> countWeeklyEquipRunningNumByLineDeptId(@Param("deptId") Long deptId,
@Param("status") Integer status);
/**
* 统计近半年的维修记录数量
*/
public FactoryDashboardDTO countMaintenanceRecordNumByProductionLine(@Param("date") Date date,
@Param("deptId")Long deptId);
/**
* 统计近半年的保养记录数量
*/
public FactoryDashboardDTO countUpkeepRecordNumByProductionLine(@Param("date") Date date,
@Param("deptId")Long deptId);
}

View File

@ -1,6 +1,7 @@
package com.inspur.bigscreen.service;
import com.inspur.bigscreen.dto.FactoryDashboardDTO;
import com.inspur.industrial.domain.IpcAlarmRecord;
import java.util.List;
import java.util.Map;
@ -31,4 +32,24 @@ public interface IFactoryDashboardService {
* 根据厂区部门id查询各个产线报警数量
*/
public List<FactoryDashboardDTO> countAlarmNumByProductionLine(Long deptId);
/**
* 近一周各个产线的运行情况
*/
public List<FactoryDashboardDTO> countWeeklyEquipRunningNumByLineDeptId(Long deptId);
/**
* 根据厂区id统计近半年各个产线的维修记录数
*/
public List<FactoryDashboardDTO> countMaintenanceRecordNumByProductionLine(Long deptId);
/**
* 根据厂区id统计近半年各个产线的保养记录数
*/
public List<FactoryDashboardDTO> countUpkeepRecordNumByProductionLine(Long deptId);
/**
* 根据厂区id查询最新的报警信息
*/
public List<IpcAlarmRecord> selectLatestIpcAlarmRecordByFactoryId(Long deptId);
}

View File

@ -4,14 +4,15 @@ import com.inspur.bigscreen.dto.FactoryDashboardDTO;
import com.inspur.bigscreen.mapper.FactoryDashboardMapper;
import com.inspur.bigscreen.service.IFactoryDashboardService;
import com.inspur.common.core.domain.entity.SysDept;
import com.inspur.industrial.domain.IpcAlarmRecord;
import com.inspur.industrial.service.IIpcAlarmRecordService;
import com.inspur.system.mapper.SysDeptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -27,6 +28,9 @@ public class FactoryDashboardService implements IFactoryDashboardService {
@Autowired
private SysDeptMapper sysDeptMapper;
@Autowired
private IIpcAlarmRecordService ipcAlarmRecordService;
/**
* @param deptId 厂区的部门id
*根据厂区id查询厂区下所有产线设备数量
@ -71,15 +75,135 @@ public class FactoryDashboardService implements IFactoryDashboardService {
List<FactoryDashboardDTO> resultList = new ArrayList<>();
List<SysDept> childDeptList = sysDeptMapper.selectChildrenDeptById(deptId);
for (SysDept sysDept : childDeptList) {
FactoryDashboardDTO data = new FactoryDashboardDTO();
data.setDeptName(sysDept.getDeptName());
List<FactoryDashboardDTO> factoryDashboardDTOList = factoryDashboardMapper.countWeeklyAlarmNumByLineDeptId(sysDept.getDeptId());
List<String> timeList = factoryDashboardDTOList.stream().map(FactoryDashboardDTO::getTime).collect(Collectors.toList());
List<Object> dataList = factoryDashboardDTOList.stream().map(FactoryDashboardDTO::getData).collect(Collectors.toList());
data.setX(timeList);
data.setY(dataList);
resultList.add(getResultData(sysDept,factoryDashboardDTOList));
}
return resultList;
}
/**
* 近一周各个产线的运行情况
* @param deptId 厂区id
*/
@Override
public List<FactoryDashboardDTO> countWeeklyEquipRunningNumByLineDeptId(Long deptId){
//根据厂区id查询厂区产线id
List<FactoryDashboardDTO> resultList = new ArrayList<>();
List<SysDept> childDeptList = sysDeptMapper.selectChildrenDeptById(deptId);
for (SysDept sysDept : childDeptList) {
List<FactoryDashboardDTO> factoryDashboardDTOList = factoryDashboardMapper.countWeeklyEquipRunningNumByLineDeptId(sysDept.getDeptId(),0);
resultList.add(getResultData(sysDept,factoryDashboardDTOList));
}
return resultList;
}
/**
* 根据厂区id统计近半年各个产线的维修记录数
*/
@Override
public List<FactoryDashboardDTO> countMaintenanceRecordNumByProductionLine(Long deptId){
List<FactoryDashboardDTO> resultList = new ArrayList<>();
List<SysDept> childDeptList = sysDeptMapper.selectChildrenDeptById(deptId);
for (SysDept sysDept : childDeptList) {
FactoryDashboardDTO data = getMatenanceDataByHalfYear(sysDept.getDeptId());
data.setDeptName(sysDept.getDeptName());
resultList.add(data);
}
return resultList;
}
/**
* 根据厂区id统计近半年各个产线的保养记录数
*/
@Override
public List<FactoryDashboardDTO> countUpkeepRecordNumByProductionLine(Long deptId){
List<FactoryDashboardDTO> resultList = new ArrayList<>();
List<SysDept> childDeptList = sysDeptMapper.selectChildrenDeptById(deptId);
for (SysDept sysDept : childDeptList) {
FactoryDashboardDTO data = getUpkeepDataByHalfYear(sysDept.getDeptId());
data.setDeptName(sysDept.getDeptName());
resultList.add(data);
}
return resultList;
}
/**
* 根据厂区id查询最新的报警信息
*/
@Override
public List<IpcAlarmRecord> selectLatestIpcAlarmRecordByFactoryId(Long deptId){
return ipcAlarmRecordService.selectLatestIpcAlarmRecordByFactoryId(deptId);
}
private FactoryDashboardDTO getResultData(SysDept sysDept, List<FactoryDashboardDTO> factoryDashboardDTOList){
FactoryDashboardDTO data = new FactoryDashboardDTO();
data.setDeptName(sysDept.getDeptName());
List<String> timeList = factoryDashboardDTOList.stream().map(FactoryDashboardDTO::getTime).collect(Collectors.toList());
List<Object> dataList = factoryDashboardDTOList.stream().map(FactoryDashboardDTO::getData).collect(Collectors.toList());
data.setX(timeList);
data.setY(dataList);
return data;
}
/**
* 获取当前时间半年内的保养数据
*/
private FactoryDashboardDTO getUpkeepDataByHalfYear(Long deptId){
FactoryDashboardDTO returnData = new FactoryDashboardDTO();
List<String> timeList = new ArrayList<>();
List<Object> dataList = new ArrayList<>();
List<Date> halfYearDate = getHalfYearDate();
//修改日期年月日
for (Date date : halfYearDate) {
FactoryDashboardDTO factoryData = factoryDashboardMapper.countUpkeepRecordNumByProductionLine(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 FactoryDashboardDTO getMatenanceDataByHalfYear(Long deptId){
FactoryDashboardDTO returnData = new FactoryDashboardDTO();
List<String> timeList = new ArrayList<>();
List<Object> dataList = new ArrayList<>();
List<Date> halfYearDate = getHalfYearDate();
//修改日期年月日
for (Date date : halfYearDate) {
FactoryDashboardDTO factoryData = factoryDashboardMapper.countMaintenanceRecordNumByProductionLine(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<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

@ -1,6 +1,22 @@
package com.inspur.bigscreen.task;
import com.inspur.bigscreen.domain.IpcDailyEquipNumByStatus;
import com.inspur.bigscreen.mapper.IpcDailyEquipNumByStatusMapper;
import com.inspur.common.core.domain.entity.SysDept;
import com.inspur.common.utils.spring.SpringUtils;
import com.inspur.equip.mapper.IpcEquipInfoMapper;
import com.inspur.system.mapper.SysDeptMapper;
import com.inspur.system.service.ISysDeptService;
import com.inspur.system.service.impl.SysDeptServiceImpl;
import org.springframework.aop.framework.AopContext;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* 大屏数据统计定时任务
@ -10,11 +26,48 @@ import org.springframework.stereotype.Component;
@Component("statsDataTask")
public class StatsDataTask {
@Resource
private ISysDeptService sysDeptService;
@Resource
private IpcDailyEquipNumByStatusMapper ipcDailyEquipNumByStatusMapper;
@Resource
private IpcEquipInfoMapper ipcEquipInfoMapper;
private static final Integer RUNNING = 0;
private static final Integer MAINTANANCE = 1;
private static final Integer STOP = 2;
/**
* 每日根据不同状态统计设备数量
*/
@Transactional
public void countDailyEquipNumByStatus(){
List<SysDept> deptList = sysDeptService.selectDeptAll();
List<SysDept> factoryList = deptList.stream().filter(dept -> dept.getAncestors().split(",").length == 4).collect(Collectors.toList());
for (SysDept sysDept : factoryList) {
int nums = 0;
//运行状态
insertIpcDailyEquipNumByStatusAndDeptId(RUNNING,sysDept.getDeptId());
//维修状态
insertIpcDailyEquipNumByStatusAndDeptId(MAINTANANCE,sysDept.getDeptId());
//停机状态
insertIpcDailyEquipNumByStatusAndDeptId(STOP,sysDept.getDeptId());
}
}
private int insertIpcDailyEquipNumByStatusAndDeptId(Integer status,Long deptId){
IpcDailyEquipNumByStatus ipcDailyEquipNumByStatus = new IpcDailyEquipNumByStatus();
ipcDailyEquipNumByStatus.setStatus(status);
int nums = ipcEquipInfoMapper.selectIpcEquipInfoNumByStatusAndDeptId(status,deptId);
ipcDailyEquipNumByStatus.setNums(nums);
ipcDailyEquipNumByStatus.setDeptId(deptId);
ipcDailyEquipNumByStatus.setCreateDate(new Date());
return ipcDailyEquipNumByStatusMapper.insertIpcDailyEquipNumByStatus(ipcDailyEquipNumByStatus);
}
}

View File

@ -6,6 +6,7 @@ import com.inspur.common.annotation.DataSource;
import com.inspur.common.enums.DataSourceType;
import com.inspur.equip.domain.EquipTreeSelect;
import com.inspur.equip.domain.IpcEquipInfo;
import org.apache.ibatis.annotations.Param;
public interface IpcEquipInfoMapper
@ -53,6 +54,13 @@ public interface IpcEquipInfoMapper
*/
public List<IpcEquipInfo> selectRunningIpcEquipInfoListByParentId(String parentEquipId);
/**
* 根据厂区id和设备状态查询设备数量
*/
public Integer selectIpcEquipInfoNumByStatusAndDeptId(@Param("status")Integer status,
@Param("deptId")Long deptId);
/**
* 新增设备信息
*

View File

@ -14,7 +14,7 @@ import org.apache.ibatis.annotations.Param;
* @Author zhangjunwen
* @create 2024/4/10
*/
@DataSource(DataSourceType.SLAVE)
public interface IpcAlarmRecordMapper
{
/**
@ -33,6 +33,11 @@ public interface IpcAlarmRecordMapper
*/
public List<IpcAlarmRecord> selectIpcAlarmRecordList(IpcAlarmRecord ipcAlarmRecord);
/**
* 查询厂区id下最新的报警记录
*/
public List<IpcAlarmRecord> selectLatestIpcAlarmRecordByFactoryId(Long deptId);
/**
* 新增报警记录
*

View File

@ -6,13 +6,7 @@ import com.inspur.common.annotation.DataSource;
import com.inspur.common.enums.DataSourceType;
import com.inspur.industrial.domain.IpcAlarmRules;
/**
* 设备报警规则Mapper接口
*
* @Author zhangjunwen
* @create 2024/4/9
*/
@DataSource(DataSourceType.SLAVE)
public interface IpcAlarmRulesMapper
{
/**

View File

@ -6,13 +6,7 @@ import com.inspur.industrial.domain.IpcFaultTreeConfig;
import java.util.List;
/**
* 故障树配置Mapper接口
*
* @author inspur
* @date 2024-04-02
*/
@DataSource(DataSourceType.SLAVE)
public interface IpcFaultTreeConfigMapper
{
/**

View File

@ -6,13 +6,7 @@ import com.inspur.common.annotation.DataSource;
import com.inspur.common.enums.DataSourceType;
import com.inspur.industrial.domain.IpcMonitorDataInfo;
/**
* 监控数据信息Mapper接口
*
* @author inspur
* @date 2024-04-09
*/
@DataSource(DataSourceType.SLAVE)
public interface IpcMonitorDataInfoMapper
{
/**

View File

@ -6,13 +6,7 @@ import com.inspur.common.annotation.DataSource;
import com.inspur.common.enums.DataSourceType;
import com.inspur.industrial.domain.IpcSysStatus;
/**
* 系统状态Mapper接口
*
* @Author zhangjunwen
* @create 2024/4/3
*/
@DataSource(DataSourceType.SLAVE)
public interface IpcSysStatusMapper
{
/**

View File

@ -6,7 +6,6 @@ import com.inspur.industrial.domain.PhmEquAlarmRecord;
import java.util.List;
@DataSource(DataSourceType.SLAVE)
public interface PhmEquAlarmRecordMapper {
/**
* 查询超压顶缸报警记录列表

View File

@ -29,6 +29,11 @@ public interface IIpcAlarmRecordService
*/
public List<IpcAlarmRecord> selectIpcAlarmRecordList(IpcAlarmRecord ipcAlarmRecord);
/**
* 查询厂区id下最新的报警记录
*/
public List<IpcAlarmRecord> selectLatestIpcAlarmRecordByFactoryId(Long deptId);
/**
* 新增报警记录
*

View File

@ -48,6 +48,13 @@ public class IpcAlarmRecordServiceImpl implements IIpcAlarmRecordService
return ipcAlarmRecordMapper.selectIpcAlarmRecordList(ipcAlarmRecord);
}
/**
* 查询厂区id下最新的报警记录
*/
public List<IpcAlarmRecord> selectLatestIpcAlarmRecordByFactoryId(Long deptId){
return ipcAlarmRecordMapper.selectLatestIpcAlarmRecordByFactoryId(deptId);
}
/**
* 新增报警记录
*

View File

@ -19,6 +19,11 @@ public interface SysDeptMapper
*/
public List<SysDept> selectDeptList(SysDept dept);
/**
* 查询所有的部门数据
*/
public List<SysDept> selectDeptAll();
/**
* 根据角色ID查询部门树信息
*

View File

@ -19,6 +19,11 @@ public interface ISysDeptService
*/
public List<SysDept> selectDeptList(SysDept dept);
/**
* 查询所有部门数据
*/
public List<SysDept> selectDeptAll();
/**
* 查询部门树结构信息
*

View File

@ -48,6 +48,14 @@ public class SysDeptServiceImpl implements ISysDeptService
return deptMapper.selectDeptList(dept);
}
/**
* 查询所有部门数据
*/
public List<SysDept> selectDeptAll(){
return deptMapper.selectDeptAll();
}
/**
* 查询部门树结构信息
*

View File

@ -74,8 +74,38 @@
<!--近一周产线各设备正常运行数量
public List<FactoryDashboardDTO> countWeeklyEquipRunningNumByLineDeptId(Long deptId);-->
<select id="countWeeklyEquipRunningNumByLineDeptId" parameterType="Long" resultMap="factoryData">
<select id="countWeeklyEquipRunningNumByLineDeptId" resultMap="factoryData">
select a.click_date as time,ifnull(b.nums,0) as data
from
(<include refid="selectWeeklyDate"/>)
a left join
(
select nums,status,dept_id,DATE(create_date) as create_date
from `ipc_daily_equip_num_by_status`
where dept_id = #{deptId} and
create_date >= CURDATE() - INTERVAL 7 DAY
and `status` = #{status}
) b
on a.click_date = b.create_date
</select>
<!--统计近半年的维修记录数量-->
<select id="countMaintenanceRecordNumByProductionLine" resultMap="factoryData">
select #{date} as time,count(1) as data
from ipc_maintenance_record
where
MONTH(maintenance_start_time) = MONTH(#{date})
and YEAR(maintenance_start_time) = YEAR(#{date})
and dept_id = #{deptId}
</select>
<!-- 统计近半年的保养记录数量-->
<select id="countUpkeepRecordNumByProductionLine" resultMap="factoryData">
select #{date} as time,count(1) as data
from ipc_upkeep_plan
where
MONTH(plan_start_time) = MONTH(#{date})
and YEAR(plan_start_time) = YEAR(#{date})
and dept_id = #{deptId}
</select>
</mapper>

View File

@ -144,6 +144,19 @@
WHERE parent_equip_id = #{parentEquipId} and status in ('0')
</select>
<!-- 根据设备状态查询设备数量
public Integer selectIpcEquipInfoNumByStatus(String status);-->
<select id="selectIpcEquipInfoNumByStatusAndDeptId" resultType="Integer">
select count(1)
from ipc_equip_info
where status = #{status}
and dept_id
in (
select dept_id from sys_dept
where find_in_set(#{deptId}, ancestors)
)
</select>
<insert id="insertIpcEquipInfo" parameterType="IpcEquipInfo">
insert into ipc_equip_info
<trim prefix="(" suffix=")" suffixOverrides=",">

View File

@ -27,6 +27,7 @@
<result property="equipManufacturer" column="equip_manufacturer" />
<result property="equipSerialNum" column="equip_serial_num" />
<result property="equipProductionDate" column="equip_production_date" />
<result property="deptName" column="dept_name" />
<result property="remark" column="remark" />
</resultMap>
@ -92,6 +93,23 @@
where a.id = #{id}
</select>
<!--查询厂区id下最新的报警记录
public List<IpcAlarmRecord> selectLatestIpcAlarmRecordByFactoryId-->
<select id="selectLatestIpcAlarmRecordByFactoryId" parameterType="Long" resultMap="IpcAlarmRecordResult">
select a.content,a.alarm_value,a.alarm_time,a.status,a.alarm_level,b.equip_name,c.dept_name
from `ipc_alarm_record` a
left join ipc_equip_info b
on a.equip_id = b.id
left join sys_dept c
on b.dept_id = c.dept_id
where b.dept_id in (
select dept_id from sys_dept where
find_in_set(103,ancestors)
)
order by a.alarm_time desc
limit 5
</select>
<insert id="insertIpcAlarmRecord" parameterType="IpcAlarmRecord" useGeneratedKeys="true" keyProperty="id">
insert into ipc_alarm_record
<trim prefix="(" suffix=")" suffixOverrides=",">

View File

@ -48,6 +48,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by d.parent_id, d.order_num
</select>
<select id="selectDeptAll" resultMap="SysDeptResult">
<include refid="selectDeptVo"/>
</select>
<select id="selectDeptListByRoleId" resultType="Long">
select d.dept_id
from sys_dept d

View File

@ -446,6 +446,16 @@ import { getToken } from "@/utils/auth";
import { Loading } from "element-ui";
import ElImageViewer from "element-ui/packages/image/src/image-viewer";
import { deptTreeSelect } from "@/api/system/user";
import {
getEquipNumByProductionLine,
getEquipNumByStatusAndProductionLine,
getSensorNumByProductionLine,
getWeeklyAlarmNumByProductionLine,
getWeeklyEquipRunningNum,
getHYMaintenanceRecordNumByProductionLine,
getHYUpkeepRecordNumByProductionLine,
getLatestAlarmRecord,
} from "@/api/bigscreen/factory";
export default {
name: "Category",
components: {
@ -572,6 +582,13 @@ export default {
created() {
this.getList();
this.getDeptTree();
//
// getEquipNumByProductionLine(103);
// getEquipNumByStatusAndProductionLine(103);
// getSensorNumByProductionLine(103);
getLatestAlarmRecord(103).then((response) => {
console.log("data:", response.data);
});
},
methods: {
/** 查询部门下拉树结构 */