Commit 38dbb579 authored by 单奇雲's avatar 单奇雲

新增定时更新数据,推送数据

parent d8726fc5
package com.yeejoin.amos.fas.dao.entity;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
/**
* The persistent class for the fire_car database table.
*
*/
@Entity
@Table(name="f_safety_index_change_log")
@NamedQuery(name="SafetyIndexChangeLog.findAll", query="SELECT s FROM SafetyIndexChangeLog s")
public class SafetyIndexChangeLog implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "ID",nullable=false,unique=true)
private Long id;
@Column(name="safety_index")
private BigDecimal safetyIndex;
@Column(name="collect_date")
private Date collectDate;
@Column(name="org_code")
private String orgCode;
@Column(name="remark")
private String remark;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public BigDecimal getSafetyIndex() {
return safetyIndex;
}
public void setSafetyIndex(BigDecimal safetyIndex) {
this.safetyIndex = safetyIndex;
}
public Date getCollectDate() {
return collectDate;
}
public void setCollectDate(Date collectDate) {
this.collectDate = collectDate;
}
public String getOrgCode() {
return orgCode;
}
public void setOrgCode(String orgCode) {
this.orgCode = orgCode;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}
\ No newline at end of file
package com.yeejoin.amos.fas.business.controller;
import java.util.HashMap;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.yeejoin.amos.fas.business.bo.BindPointBo;
import com.yeejoin.amos.fas.business.bo.BindRegionBo;
import com.yeejoin.amos.fas.business.service.intfc.IRiskSourceService;
import com.yeejoin.amos.fas.business.service.intfc.IView3dService;
import com.yeejoin.amos.fas.business.vo.ExceptionRegionVo;
import com.yeejoin.amos.fas.core.util.CommonResponse;
import com.yeejoin.amos.fas.core.util.CommonResponseUtil;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.yeejoin.amos.fas.business.service.intfc.IRiskSourceService;
import com.yeejoin.amos.fas.business.vo.ReginParams;
import com.yeejoin.amos.fas.common.enums.ResourceTypeDefEnum;
import com.yeejoin.amos.fas.core.util.CommonResponse;
import com.yeejoin.amos.fas.core.util.CommonResponseUtil;
import io.swagger.annotations.Api;
import java.util.HashMap;
import java.util.List;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@RestController
@RequestMapping("/api/view3d")
......@@ -114,6 +121,7 @@ public class View3dController extends BaseController {
public CommonResponse getSafetyIndexDetail(@ApiParam(value = "risk-风险异常,check-巡检异常,equip-设备故障") @PathVariable String type){
ReginParams reginParams =getSelectedOrgInfo();
String orgCode = this.getOrgCode(reginParams);
orgCode = "1*2";
return CommonResponseUtil.success(view3dService.getSafetyIndexDetail(type,orgCode));
}
......@@ -183,5 +191,13 @@ public class View3dController extends BaseController {
List<HashMap<String,Object>> pointList = view3dService.get3dPointsByType(orgCode,type);
return CommonResponseUtil.success(pointList);
}
@Scheduled(cron = "${param.safetyIndexchange.cron}")
@ApiOperation(value = "更新安全指数",notes = "更新安全指数")
@GetMapping(value = "safetyIndex/refresh")
public CommonResponse safetyIndexRefresh(){
view3dService.safetyIndexRefresh();
return CommonResponseUtil.success();
}
}
......@@ -95,4 +95,6 @@ public interface View3dMapper extends BaseMapper{
* @return 列表
*/
List<HashMap<String, Object>> getPintsByType(Map<String, Object> params);
void safetyIndexRefresh();
}
package com.yeejoin.amos.fas.business.dao.repository;
import org.springframework.stereotype.Repository;
import com.yeejoin.amos.fas.dao.entity.SafetyIndexChangeLog;
@Repository("iSafetyIndexChangeLogDao")
public interface ISafetyIndexChangeLogDao extends BaseDao<SafetyIndexChangeLog, Long>{
}
......@@ -28,6 +28,7 @@ import com.yeejoin.amos.fas.business.constants.FasConstant;
import com.yeejoin.amos.fas.business.dao.mapper.PatrolMapper;
import com.yeejoin.amos.fas.business.dao.mapper.View3dMapper;
import com.yeejoin.amos.fas.business.dao.repository.*;
import com.yeejoin.amos.fas.business.feign.RemoteWebSocketServer;
import com.yeejoin.amos.fas.business.service.intfc.IView3dService;
import com.yeejoin.amos.fas.business.vo.ErrorContentVo;
import com.yeejoin.amos.fas.business.vo.ExceptionRegionVo;
......@@ -85,6 +86,12 @@ public class View3dServiceImpl implements IView3dService {
private PatrolMapper patrolMapper;
@Autowired
private IRiskLevelDao iRiskLevelDao;
@Autowired
private ISafetyIndexChangeLogDao iSafetyIndexChangeLogDao;
@Autowired
private RemoteWebSocketServer remoteWebSocketServer;
@Value("${param.system.online.date}")
private String onLineDate;
......@@ -490,4 +497,39 @@ public class View3dServiceImpl implements IView3dService {
});
return points;
}
@Override
public void safetyIndexRefresh() {
try {
List<RiskSource> riskSources = iRiskSourceDao.findByParentId(0l);
List<SafetyIndexChangeLog> sageTyIndexs = new ArrayList<>();
sageTyIndexs = riskSources.stream().map(riskSource -> {
SafetyIndexChangeLog safetyIndexChangeLog = new SafetyIndexChangeLog();
safetyIndexChangeLog.setOrgCode(riskSource.getOrgCode());
double changeRpnToSafetyIndex = this.changeRpnToSafetyIndex(riskSource.getRpn());
safetyIndexChangeLog.setSafetyIndex(BigDecimal.valueOf(changeRpnToSafetyIndex));
safetyIndexChangeLog.setCollectDate(new Date());
return safetyIndexChangeLog;
}).collect(Collectors.toList());;
iSafetyIndexChangeLogDao.saveAll(sageTyIndexs);
} catch (Exception e) {
log.error("更新失败: " + e.getMessage());
e.printStackTrace();
}
this.sendRefreshDate();
}
//推送刷新数据消息
private void sendRefreshDate() {
HashMap<String, String> message = new HashMap<>();
message.put("refreshType", View3dRefreshAreaEum.all.getCode());
try {
remoteWebSocketServer.sendMessage("refreshDate", JSON.toJSONString(message));
} catch (Exception e) {
log.error("推送消息失败!!!");
e.printStackTrace();
}
}
}
......@@ -91,12 +91,33 @@ public interface IView3dService {
*/
List<Map<String, Object>> getStatisticsCheck(String orgCode);
/**
* 最新五条异常
* @param type
* @param orgCode
* @return
*/
List<SafetyExecuteBo> getSafetyExecuteListTop5(String type, String orgCode);
/**
* 今日值班统计
* @return
*/
Object getStatisticsDuty();
/**
* 设备状态消息最新5条
* @param orgCode
* @return
*/
Object getEquipStatusList(String orgCode);
/**
* 左侧菜单
* @param type
* @param orgCode
* @return
*/
List<View3dNodeVo> initViewNode(String type, String orgCode);
/**
* 查询类型的点
......@@ -105,4 +126,9 @@ public interface IView3dService {
* @return list
*/
List<HashMap<String, Object>> get3dPointsByType(String orgCode,String type);
/**
* 刷新安全指数
*/
void safetyIndexRefresh();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment