package com.nanometer.smartlab.service;
|
|
import java.io.IOException;
|
import java.sql.Timestamp;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.annotation.Resource;
|
|
import com.alibaba.fastjson.JSONObject;
|
import org.apache.commons.lang.StringUtils;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.entity.StringEntity;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.util.EntityUtils;
|
import org.apache.log4j.Logger;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.dao.DataAccessException;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import com.nanometer.smartlab.dao.SysWarningDao;
|
import com.nanometer.smartlab.entity.SysWarning;
|
import com.nanometer.smartlab.exception.BusinessException;
|
import com.nanometer.smartlab.exception.ExceptionEnumCode;
|
import com.nanometer.smartlab.util.MessageUtil;
|
|
|
@Service("sysWarningService")
|
public class SysWarningServiceImpl implements SysWarningService {
|
private static Logger logger = Logger.getLogger(SysWarningServiceImpl.class);
|
|
@Resource(name = "sysWarningDao")
|
SysWarningDao sysWarningDao;
|
@Value("${alarm.url}")
|
String alarmUrl;
|
|
|
@Override
|
public void insert(SysWarning sysWarning) {
|
sysWarningDao.insertWatning(sysWarning);
|
}
|
|
|
@Transactional(propagation = Propagation.REQUIRED)
|
public List<SysWarning> getSysWarningList(String code, Timestamp startTime,Timestamp endTime, Integer first, Integer pageSize) {
|
try {
|
Map<String, Object> params = new HashMap<String, Object>();
|
if (StringUtils.isNotBlank(code)) {
|
params.put("containerCode", "%" + code + "%");
|
}
|
params.put("startWarningTime", startTime);
|
params.put("endWarningTime", endTime);
|
params.put("first", first);
|
params.put("pageSize", pageSize);
|
return this.sysWarningDao.getSysWarningList(params);
|
} catch (DataAccessException e) {
|
logger.error(e.getMessage(), e);
|
throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e);
|
}
|
}
|
|
@Override
|
public SysWarning getSysWarning(String id) {
|
try {
|
return this.sysWarningDao.getSysWarning(id);
|
} catch (DataAccessException e) {
|
logger.error(e.getMessage(), e);
|
throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e);
|
}
|
}
|
|
@Override
|
public void updateSysWarning(SysWarning selectedWarning) throws IOException {
|
|
try {
|
Map<String,Object> params = new HashMap<>();
|
params.put("memo", selectedWarning.getMemo());
|
params.put("status", selectedWarning.getStatus());
|
params.put("id", selectedWarning.getId());
|
//给大屏信息发送处理信息
|
//页面只允许修改完成转台
|
if (StringUtils.isNotBlank(selectedWarning.getAlarmId()) && StringUtils.isNotBlank(alarmUrl)){
|
JSONObject json=new JSONObject();
|
json.put("dataType", "data");
|
json.put("id", selectedWarning.getAlarmId());
|
CloseableHttpClient client2 = HttpClients.createDefault();
|
HttpPost post2 = new HttpPost(alarmUrl);
|
post2.setHeader("Content-Type", "application/json;charset=UTF-8");
|
StringEntity se = new StringEntity(json.toString(), "UTF-8");
|
se.setContentEncoding("UTF-8");
|
se.setContentType("application/json");
|
post2.setEntity(se);
|
CloseableHttpResponse response2 = client2.execute(post2);
|
String resData2 = EntityUtils.toString(response2.getEntity());
|
client2.close();
|
logger.info(resData2);
|
}else{
|
logger.info("关联daping的告警id为空 ");
|
}
|
this.sysWarningDao.updateSysWarning(params);
|
|
} catch (DataAccessException e) {
|
logger.error(e.getMessage(), e);
|
throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e);
|
}
|
}
|
|
|
@Override
|
public int getSysWarningTotalCount(String code, Timestamp startTime, Timestamp endTime) {
|
try {
|
Map<String, Object> params = new HashMap<String, Object>();
|
if (StringUtils.isNotBlank(code)) {
|
params.put("containerCode", "%" + code + "%");
|
}
|
if(startTime != null)
|
{
|
params.put("startWarningTime", startTime);
|
}
|
if(endTime != null)
|
{
|
params.put("endWarningTime", endTime);
|
}
|
|
return this.sysWarningDao.getSysWarningTotalCount(params);
|
} catch (DataAccessException e) {
|
logger.error(e.getMessage(), e);
|
throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e);
|
}
|
}
|
}
|