生产型企业智能设备管理系统,能够实时监控设备情况,对设备告警停机等情况迅速做出处理,同时分析设备节拍分析出各种报表。
SaaS架构,支持多工厂,多数据源,使用 PostgreSql存储设备数值,实时看板,每个值拥有标准指标。 会对设备告警进行记录和实时展示,报警通过邮件发送至工程师。
开发MI前台和后台。\ 开发基于Python的采集程序。
目前在上海途胜汽车零部件有限公司使用。
需要针对不同协议开发支持多种协议的采集程序。
后台: Java JPA Sa-token Maven多模块\ 前台: Vue2\ 数据库: SqlServer PostgresSql \ MQTT: 阿里云MQTT服务\ 采集程序: C# Hslcommuniation Kepware
注塑机IM Controller:
package com.ciemis.api.controller.im;
import cn.hutool.json.JSONArray;
import com.aliyun.oss.OSSClient;
import com.ciemis.entity.*;
import com.ciemis.entity.postgres.OpcImData;
import com.ciemis.entity.postgres.OpcImWarningRecord;
import com.ciemis.framework.aop.CompanyInject;
import com.ciemis.framework.exception.BusinessException;
import com.ciemis.framework.exception.ServiceException;
import com.ciemis.framework.properties.AliyunOSSProperties;
import com.ciemis.framework.response.ResponseData;
import com.ciemis.framework.util.OssClient;
import com.ciemis.repository.CraftProcessRepository;
import com.ciemis.repository.CraftRepository;
import com.ciemis.repository.MachineRepository;
import com.ciemis.repository.MqAccountRepository;
import com.ciemis.service.PostgresqlService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.net.URL;
import java.sql.SQLException;
import java.util.*;
@RestController
@RequestMapping("/im")
public class IMController {
@Autowired
PostgresqlService postgresqlService;
@Autowired
CraftRepository craftRepository;
@Autowired
CraftProcessRepository craftProcessRepository;
@Autowired
MachineRepository machineRepository;
@Autowired
MqAccountRepository mqAccountRepository;
@Autowired
AliyunOSSProperties ossProperties;
@ApiOperation(value = "概览接口", notes = "")
@RequestMapping("/dashboard")
public ResponseData dashboard(@CompanyInject Company company, @RequestParam(value = "machineId", required = false)
String machineId) throws SQLException {
List<BaseMachine> machines = machineRepository.findByCompanyCode(company.getCode());
Map<String, Object> result = new HashMap<>();
result.put("machineList", machines);
result.put("warnRules", new JSONArray());
List<MqAccount> mqAccounts = mqAccountRepository.findMqAccountByIsSuper(true);
result.put("mqAccounts", mqAccounts);
List<OpcImData> data;
if (Objects.isNull(machineId) || machineId.isEmpty()) {
if (machines.isEmpty()) {
throw new BusinessException(500, "请维护注塑机数据");
} else {
BaseMachine machine = machines.get(0);
data = postgresqlService.findAllByMachineId(company, machine.getMachineId());
if (data.size() == 0) {
data.add(new OpcImData());
}
if (machine.getImage() != null) {
Date expiration = new Date(new Date().getTime() + 3600 * 1000);
OSSClient ossClient = OssClient.initOSS(ossProperties);
URL url = ossClient.generatePresignedUrl(ossProperties.getBucket(), machine.getImage(), expiration);
machine.setImage(url.toString());
}
result.put("machineCurrent", machine);
result.put("lastMachineData", data.get(0));
result.put("lastWarningRecord", postgresqlService.getLastWarningRecord(company, machine.getMachineId()));
}
} else {
BaseMachine machine = machineRepository.findByMachineIdAndCompanyCode(machineId, company.getCode());
if (Objects.isNull(machine)) {
throw new NullPointerException("未找到machineId");
}
data = postgresqlService.findAllByMachineId(company, machine.getMachineId());
if (data.size() == 0) {
data.add(new OpcImData());
}
if (machine.getImage() != null) {
Date expiration = new Date(new Date().getTime() + 3600 * 1000);
OSSClient ossClient = OssClient.initOSS(ossProperties);
URL url = ossClient.generatePresignedUrl(ossProperties.getBucket(), machine.getImage(), expiration);
machine.setImage(url.toString());
}
result.put("machineCurrent", machine);
result.put("lastMachineData", data.get(0));
result.put("lastWarningRecord", postgresqlService.getLastWarningRecord(company, machine.getMachineId()));
}
BaseCraft craft = craftRepository.findByCompanyCodeAndCraftId(company.getCode(), data.get(0).getTm_craft_id());
if (!Objects.isNull(craft)) {
List<BaseCraftProcess> craftProcesses = craftProcessRepository.findByCompanyCodeAndCraftId(company.getCode(), data.get(0).getTm_craft_id());
result.put("craft", craft);
result.put("warnRules", craftProcesses);
}
//告警
return ResponseData.success(result);
}
@ApiOperation(value = "查询告警", notes = "")
@RequestMapping(value = "/searchWarningRecord", method = RequestMethod.GET)
public ResponseData searchWarningRecord(@CompanyInject Company company,
@RequestParam(value = "machineId", required = false) String machineId,
@RequestParam(value = "alarmId", required = false) String alarmId,
@RequestParam(value = "description", required = false) String description,
@RequestParam(value = "startTime", required = false) String startTime,
@RequestParam(value = "endTime", required = false) String endTime,
@RequestParam(value = "level", required = false) Integer level) {
try {
List<OpcImWarningRecord> opcImWarningRecords = postgresqlService.searchImWarningRecord(company,
machineId, alarmId, description, startTime, endTime, level);
return ResponseData.success(opcImWarningRecords);
} catch (SQLException e) {
e.printStackTrace();
throw new ServiceException(500, e.getMessage());
}
}
@ApiOperation(value = "查询周期时间", notes = "")
@RequestMapping(value = "/searchImOpcCycleTime", method = RequestMethod.GET)
public ResponseData searchImOpcCycleTime(@CompanyInject Company company,
@RequestParam(value = "machineId", required = false) String machineId,
@RequestParam(value = "craftId", required = false) String craftId,
@RequestParam(value = "startTime", required = false) String startTime,
@RequestParam(value = "endTime", required = false) String endTime) {
try {
List<OpcImData> results = postgresqlService.searchImOpcDataTimeOfCycle(company, machineId, craftId, startTime, endTime);
return ResponseData.success(results);
} catch (SQLException e) {
e.printStackTrace();
throw new ServiceException(500, e.getMessage());
}
}
}