Commit 1f4383c6 authored by maoying's avatar maoying

Merge branch 'dev_upgrade_rule' of 172.16.10.76:station/YeeAmosFireAutoSysRoot…

Merge branch 'dev_upgrade_rule' of 172.16.10.76:station/YeeAmosFireAutoSysRoot into dev_upgrade_rule
parents 0429bf5a afee2bfe
......@@ -13,7 +13,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -31,13 +32,17 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.yeejoin.amos.component.rule.MethodParam;
import com.yeejoin.amos.component.rule.RuleActionBean;
import com.yeejoin.amos.component.rule.RuleMethod;
import com.yeejoin.amos.fas.business.action.el.ELEvaluationContext;
import com.yeejoin.amos.fas.business.action.model.ContingencyEvent;
import com.yeejoin.amos.fas.business.action.model.ContingencyRo;
import com.yeejoin.amos.fas.business.action.model.DeviceRo;
import com.yeejoin.amos.fas.business.action.model.SetpEnum;
import com.yeejoin.amos.fas.business.action.mq.StationEnum;
import com.yeejoin.amos.fas.business.action.mq.WebMqttComponent;
import com.yeejoin.amos.fas.business.action.result.ActionResult;
import com.yeejoin.amos.fas.business.action.result.SafteyPlanResult;
import com.yeejoin.amos.fas.business.action.result.message.AbstractActionResultMessage;
import com.yeejoin.amos.fas.business.action.util.ContingencyLogPublisher;
import com.yeejoin.amos.fas.business.action.util.StepComparator;
import com.yeejoin.amos.fas.business.feign.IDutyModeServer;
import com.yeejoin.amos.fas.business.feign.RemoteSecurityService;
......@@ -75,7 +80,8 @@ public class ContingencyAction implements CustomerAction {
@Autowired
private FireStengthService fireStrengthService;
@Autowired
private ContingencyLogPublisher contingencyLogPublisher;
// private RestTemplate restTemplate = new RestTemplate();
// @Value("${bussunis.domain}")
......@@ -167,12 +173,20 @@ public class ContingencyAction implements CustomerAction {
AbstractActionResultMessage<?> action = (AbstractActionResultMessage<?>) constructor.newInstance(result);
if ("mqtt".equals(pushType.toLowerCase())) {
ToipResponse toipResponse = action.buildResponse(msgType, contingency, result.toJson());
String topic = String.format("/%s/%s/%s", serviceName, "yinan","plan");
String topic = String.format("/%s/%s/%s", serviceName, StationEnum.YINAN.getCode(),"plan");
log.info(String.format("mqtt[%s]:【 %s 】", topic, toipResponse.toJsonStr()));
webMqttComponent.publish(topic, toipResponse.toJsonStr());
ContingencyEvent event = new ContingencyEvent(this);
event.setMsgBody(toipResponse.toJsonStr());
event.setTopic(topic);
event.setMsgType(msgType);
event.setContingency(contingency);
contingencyLogPublisher.publish(event);
} else if ("websocket".equals(pushType.toLowerCase())){
action.execute(msgType, contingency);
}
} catch (Exception e) {
e.printStackTrace();
}
......@@ -373,14 +387,31 @@ public class ContingencyAction implements CustomerAction {
content = content.replaceAll("\\$\\{" + field.getName() + "}", value);
}
content = content.replaceAll("\\$\\{", "");
content = content.replaceAll("}", "");
content = getNative(content);
// content = content.replaceAll("\\$\\{", "");
// content = content.replaceAll("}", "");
} catch (Exception e) {
e.printStackTrace();
}
return content;
}
public String getNative(String str)
{
Pattern p = Pattern.compile("\\$\\{(.*?)\\}");
Matcher m = p.matcher(str);
while (m.find())
{
String parameter = m.group();
Object parametervalue = ELEvaluationContext
.getValue(parameter.substring(1, parameter.length() - 1));
if(parametervalue != null)
str = str.replace(parameter,
parametervalue != null ? parametervalue.toString() : null);
}
return str;
}
/**
* 交互动作
......@@ -532,7 +563,7 @@ public class ContingencyAction implements CustomerAction {
/**
* 地图动作推送
* 地图动作推送
*
* @param actionName 动作名称标识
* @param paramObj 预案对象
......@@ -544,7 +575,6 @@ public class ContingencyAction implements CustomerAction {
log.error("=======================================================================================");
stopSnapshop(contingencyRo);
SafteyPlanResult result = new SafteyPlanResult();
Map<String, Object> tempmap1 = new HashMap<>();
......@@ -554,6 +584,27 @@ public class ContingencyAction implements CustomerAction {
this.sendcmd("maparea", paramObj, result);
}
@RuleMethod(methodLabel = "地图动画", project = "青海换流站消防预案")
public void mapCartoonAction(
@MethodParam(paramLabel = "动作名称标识") String actionName,
@MethodParam(paramLabel = "动作类型") String actionType,
@MethodParam(paramLabel = "动作类型参数") String paramJSON,
@MethodParam(paramLabel = "对象") Object paramObj) {
ContingencyRo contingencyRo = (ContingencyRo) paramObj;
log.error("=======================================================================================");
stopSnapshop(contingencyRo);
String parameter = instedParams(paramJSON, contingencyRo);
SafteyPlanResult result = new SafteyPlanResult();
Map<String, Object> tempmap1 = new HashMap<>();
tempmap1.put("key", actionName);
tempmap1.put("content",actionType);
tempmap1.put("parameter",parameter);
result.add(tempmap1);
this.sendcmd("maparea", paramObj, result);
}
/**
* 顶部消息提示
......@@ -738,9 +789,16 @@ public class ContingencyAction implements CustomerAction {
AbstractActionResultMessage<?> action = (AbstractActionResultMessage<?>) constructor.newInstance(result);
if ("mqtt".equals(pushType.toLowerCase())) {
ToipResponse toipResponse = action.buildResponse(msgType, deviceRo, result.toJson());
String topic = String.format("/%s/%s/%s", serviceName, "yinan","plan");
String topic = String.format("/%s/%s/%s", serviceName, StationEnum.YINAN.getCode(),"plan");
log.info(String.format("mqtt[%s]:【 %s 】", topic, toipResponse.toJsonStr()));
webMqttComponent.publish(topic, toipResponse.toJsonStr());
ContingencyEvent event = new ContingencyEvent(this);
event.setMsgBody(toipResponse.toJsonStr());
event.setTopic(topic);
event.setMsgType(msgType);
event.setContingency(deviceRo);
contingencyLogPublisher.publish(event);
} else if ("websocket".equals(pushType.toLowerCase())){
action.execute(msgType, deviceRo);
}
......
package com.yeejoin.amos.fas.business.action;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import com.yeejoin.amos.fas.business.action.model.ContingencyEvent;
import com.yeejoin.amos.fas.business.service.intfc.IRuleRunningSnapshotService;
@Component
public class ContingencyLogListener implements ApplicationListener<ContingencyEvent>{
@Autowired
IRuleRunningSnapshotService ruleRunningSnapshotService;
@Override
public void onApplicationEvent(ContingencyEvent event) {
ruleRunningSnapshotService.reacordPlan(event.getTopic(), event.getMsgType(), event.getMsgBody(), event.getContingency());
}
}
......@@ -11,6 +11,7 @@ import org.springframework.stereotype.Component;
import com.yeejoin.amos.component.rule.MethodParam;
import com.yeejoin.amos.component.rule.RuleActionBean;
import com.yeejoin.amos.component.rule.RuleMethod;
import com.yeejoin.amos.fas.business.action.mq.StationEnum;
import com.yeejoin.amos.fas.business.action.mq.WebMqttComponent;
import com.yeejoin.amos.fas.business.action.result.ActionResult;
import com.yeejoin.amos.fas.business.action.result.BubbleTipResult;
......@@ -69,7 +70,7 @@ public class RiskSituationAction implements CustomerAction
String msgType = "bubbleTip";
if ("mqtt".equals(pushType.toLowerCase())) {
ToipResponse toipResponse = action.buildResponse(msgType, bizobj, result);
String topic = String.format("/%s/%s/%s", serviceName, "yinan","rule");
String topic = String.format("/%s/%s/%s", serviceName, StationEnum.YINAN.getCode(),"rule");
webMqttComponent.publish(topic, toipResponse.toJsonStr());
} else {
Object obj = action.execute(msgType, bizobj);
......
......@@ -12,6 +12,7 @@ import org.springframework.stereotype.Component;
import com.yeejoin.amos.fas.business.action.el.ELEvaluationContext;
import com.yeejoin.amos.fas.business.action.model.RiskSourceRuleRo;
import com.yeejoin.amos.fas.business.action.mq.StationEnum;
import com.yeejoin.amos.fas.business.action.mq.WebMqttComponent;
import com.yeejoin.amos.fas.business.action.result.AbstractActionResult;
import com.yeejoin.amos.fas.business.action.result.ActionResult;
......@@ -77,7 +78,7 @@ public class SimpleTipAction implements CustomerAction
String msgType = "message";
if ("mqtt".equals(pushType.toLowerCase())) {
ToipResponse toipResponse = action.buildResponse(msgType, bizobj, result);
String topic = String.format("/%s/%s/%s", serviceName, "yinan","rule");
String topic = String.format("/%s/%s/%s", serviceName, StationEnum.YINAN.getCode(),"rule");
webMqttComponent.publish(topic, toipResponse.toJsonStr());
} else {
action.execute(msgType, bizobj);
......
package com.yeejoin.amos.fas.business.action.model;
import org.springframework.context.ApplicationEvent;
import lombok.Data;
@Data
public class ContingencyEvent extends ApplicationEvent{
public ContingencyEvent(Object source) {
super(source);
}
/**
*
*/
private static final long serialVersionUID = -5239150129698935970L;
private String topic;
private String msgType;
private String msgBody;
private Object contingency;
}
package com.yeejoin.amos.fas.business.action.mq;
public enum StationEnum {
YINAN("yinan", "沂南站");
String code;
String desc;
private StationEnum(String code, String desc) {
this.desc = desc;
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}
package com.yeejoin.amos.fas.business.action.util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import com.yeejoin.amos.fas.business.action.model.ContingencyEvent;
@Component
public class ContingencyLogPublisher {
@Autowired
//注入ApplicationContext用来发布事件
ApplicationContext applicationContext;
//使用ApplicationContext的publishEvent方法来发布
public void publish(ContingencyEvent msg){
applicationContext.publishEvent(msg);
}
}
......@@ -5,10 +5,12 @@ import com.google.common.collect.Maps;
import com.yeejoin.amos.fas.business.param.PointListParam;
import com.yeejoin.amos.fas.business.param.QueryParamUtil;
import com.yeejoin.amos.fas.business.service.intfc.ICommonService;
import com.yeejoin.amos.fas.business.service.intfc.IRiskSourceService;
import com.yeejoin.amos.fas.business.vo.ReginParams;
import com.yeejoin.amos.fas.config.Permission;
import com.yeejoin.amos.fas.core.common.request.CommonPageable;
import com.yeejoin.amos.fas.core.common.request.CommonRequest;
import com.yeejoin.amos.fas.core.common.response.RiskSourceTreeResponse;
import com.yeejoin.amos.fas.core.util.CommonResponse;
import com.yeejoin.amos.fas.core.util.CommonResponseUtil;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
......@@ -21,6 +23,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.data.domain.Page;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
......@@ -31,11 +34,13 @@ import java.util.Map;
@RequestMapping(value = "/api/common")
@Api(tags = "公共资源api")
public class CommonController extends BaseController {
private final Logger log = LoggerFactory.getLogger(CommonController.class);
@Autowired
private ICommonService commonService;
@Autowired
private IRiskSourceService iRiskSourceService;
private final Logger log = LoggerFactory.getLogger(CommonController.class);
/**
......@@ -53,19 +58,11 @@ public class CommonController extends BaseController {
return CommonResponseUtil.failure("公司信息获取失败!");
}
List<DepartmentModel> deps = commonService.getDepartment(getToken(),getProduct(),getAppKey(), companyId);
return CommonResponseUtil.success(objectsToMaps(deps));
}
public static <T> Map<String, Object> beanToMap(T bean) {
Map<String, Object> map = Maps.newHashMap();
if (bean != null) {
......@@ -95,14 +92,7 @@ public class CommonController extends BaseController {
}
}
return list;
}
}
/**
* 查询巡检点信息
......@@ -116,7 +106,6 @@ public class CommonController extends BaseController {
public CommonResponse getPoints(
@ApiParam(value = "查询条件", required = false) @RequestBody(required = false) List<CommonRequest> queryRequests,
@ApiParam(value = "分页参数", required = true, defaultValue = "pageNumber=0&pageSize=10") CommonPageable commonPageable) {
try {
PointListParam params = new PointListParam();
QueryParamUtil.fillPointListParam(queryRequests, commonPageable, params);
......@@ -180,4 +169,10 @@ public class CommonController extends BaseController {
List<AgencyUserModel> users = commonService.getAllUser(getToken(),getProduct(),getAppKey(), compCode);
return CommonResponseUtil.success(users);
}
@ApiOperation(value = "查询公司下的风险模型(厂区、区域、风险点)")
@GetMapping(value = "/riskSource/list/{orgCode}",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public CommonResponse getRiskSourceList(@PathVariable String orgCode){
return CommonResponseUtil.success(iRiskSourceService.findRiskSourceTrees(orgCode));
}
}
......@@ -26,7 +26,8 @@ public class CurCompanyController extends BaseController {
map.put("nickName", getUserInfo().getRealName());
map.put("company", getSelectedOrgInfo().getCompany());
map.put("department", getSelectedOrgInfo().getDepartment());
map.put("role", getSelectedOrgInfo().getRole());
return CommonResponseUtil.success(map);
}
}
package com.yeejoin.amos.fas.business.controller;
import java.util.HashMap;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
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 com.yeejoin.amos.fas.business.param.CommonPageInfoParam;
import com.yeejoin.amos.fas.business.param.RiskFmeaParam;
import com.yeejoin.amos.fas.business.service.intfc.IFmeaService;
......@@ -15,18 +31,10 @@ import com.yeejoin.amos.fas.core.util.CommonResponseUtil;
import com.yeejoin.amos.fas.dao.entity.Fmea;
import com.yeejoin.amos.fas.dao.entity.RiskSource;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
@RestController
@RequestMapping("/api/riskModel")
......@@ -37,7 +45,7 @@ public class RiskModelController extends BaseController {
@Autowired
private IRiskSourceService riskSourceService;
@Autowired
private IFmeaService fmeaService;
......@@ -71,6 +79,20 @@ public class RiskModelController extends BaseController {
if (type.equals(2) && isRegion.equals("TRUE")) {
return CommonResponseUtil.failure("该区域下只能添加风险点");
}
Long id = param.getId();
if (id == 0) {//新增
} else {
// 更新的话,就放到前面,更新失败直接阻止本地
// 如果对于新增修改有什么约束,请添加到远程同步之前
String synMsg = riskSourceService.saveToEquipManage(getAppKey(), getProduct(), getToken(), SUCCESS,
param.getId(), param.getCode(), param.getName(), param.getParentId());
if (synMsg != null) {
return CommonResponseUtil.failure(synMsg);
}
}
AgencyUserModel user = getUserInfo();
ReginParams reginParams =getSelectedOrgInfo();
String compCode=getOrgCode(reginParams);
......@@ -78,13 +100,27 @@ public class RiskModelController extends BaseController {
map.put("org_code", compCode);
map.put("user_id", user.getUserId());
map.put("param", param);
return CommonResponseUtil.success(riskSourceService.editRiskSource(map));
CommonResponse cr = CommonResponseUtil.success(riskSourceService.editRiskSource(map));
if (id == 0) {//新增 新增的话,只能放到本地之后,因为必须拿到新增之后的ID才行
// 如果对于新增修改有什么约束,请添加到远程同步之前
String synMsg = riskSourceService.saveToEquipManage(getAppKey(), getProduct(), getToken(), SUCCESS,
param.getId(), param.getCode(), param.getName(), param.getParentId());
if (synMsg != null) {
//远程新增失败,就把本地删了,有点绕,但是没办法
//由于是刚刚新建的,就直接删除,不做任何不能删校验。
riskSourceService.deleteById(param.getId());
return CommonResponseUtil.failure(synMsg);
}
}
return cr;
} catch (Exception e) {
log.error(e.getMessage(), e);
return CommonResponseUtil.failure("风险模型新增及维护失败:" + e.getMessage());
}
}
/**
* 风险模型删除
*/
......@@ -93,7 +129,7 @@ public class RiskModelController extends BaseController {
@RequestMapping(value = "/riskSource/deleteRiskSource", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
public CommonResponse deleteRiskSource(@ApiParam(value = "风险模型id", required = true) @RequestBody Long[] riskSourceId) {
try {
riskSourceService.deleteRiskSource(riskSourceId);
riskSourceService.deleteRiskSource(getAppKey(), getProduct(), getToken(), SUCCESS, riskSourceId);
return CommonResponseUtil.success();
} catch (Exception e) {
log.error(e.getMessage(), e);
......
......@@ -15,6 +15,7 @@ import org.springframework.util.ObjectUtils;
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.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
......@@ -121,6 +122,23 @@ public class RiskSourceController extends BaseController {
return CommonResponseUtil.success(getRiskSourcesTree(riskSources));
}
@Permission
@ApiOperation(value = "远程同步", notes = "将本地 风险模型推送到远程同步")
@PutMapping(value = "/synToEquipManage")
public CommonResponse synToEquipManage() {
ReginParams reginParams =getSelectedOrgInfo();
String compCode=getOrgCode(reginParams);
if(!riskSourceService.isSynEquipManage()) {
return CommonResponseUtil.failure("同步功能未开启");
}
List<RiskSourceTreeResponse> riskSources = riskSourceService.findRiskSourceTrees(compCode);
String synMsg = riskSourceService.synToEquipManage(getAppKey(), getProduct(), getToken(), SUCCESS, getRiskSourcesTree(riskSources));
if (synMsg != null) {
return CommonResponseUtil.failure(synMsg);
}
return CommonResponseUtil.success();
}
/**
* 获取区域树型结构
*
......@@ -599,7 +617,7 @@ public class RiskSourceController extends BaseController {
return CommonResponseUtil.success(riskSourceService.processFireEqumtData(deviceData));
}
@Permission
// @Permission
@ApiOperation(httpMethod = "POST", value = "上传消防设备数据", notes = "上传消防设备数据")
@RequestMapping(value = "/data/fireqeuiment/soe", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
public CommonResponse postFireEqumentData(@RequestBody AlarmParam alarm) throws Exception {
......@@ -608,7 +626,7 @@ public class RiskSourceController extends BaseController {
return CommonResponseUtil.success();
}
@Permission
// @Permission
@ApiOperation(httpMethod = "POST", value = "上传消防设备数据", notes = "上传消防设备数据")
@RequestMapping(value = "/data/fireqeuiment/all", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
public CommonResponse postFireEqumentData(@RequestBody List<AlarmParam> deviceDatas) throws Exception {
......@@ -622,7 +640,9 @@ public class RiskSourceController extends BaseController {
@RequestMapping(value = "/data/patroldata", produces = "application/json;charset=UTF-8", method = RequestMethod.PUT)
public CommonResponse postPatrolData(@RequestBody ProtalDataRo protalData) throws Exception {
log.info("上传巡检数据" + JSONObject.toJSONString(protalData));
riskSourceService.processProtalData(getToken(),getProduct(),getAppKey(),protalData);
ReginParams reginParams =getSelectedOrgInfo();
String compCode=getOrgCode(reginParams);
riskSourceService.processProtalData(getToken(),getProduct(),getAppKey(),protalData, compCode);
return CommonResponseUtil.success();
}
......
......@@ -46,7 +46,9 @@ public class TimeLineController extends BaseController{
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private IRuleRunningSnapshotService ruleRunningSnapshotService;
@Permission
//@Authorization(ingore = true)
@ApiOperation(httpMethod = "GET",value = "根据批次号查询时间轴", notes = "根据批次号查询时间轴")
......@@ -96,6 +98,23 @@ public class TimeLineController extends BaseController{
return CommonResponseUtil.success("SUCCESS");
}
@Permission
@ApiOperation(httpMethod = "get",value = "预案回放", notes = "预案回放")
@RequestMapping(value = "/fire/replay", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
public CommonResponse replay(@RequestParam("batchNo") String batchNo,
@RequestParam("randomNumber") String randomNumber) throws Exception{
ruleRunningSnapshotService.replayPlan(batchNo, randomNumber);
return CommonResponseUtil.success("SUCCESS");
}
@Permission
@ApiOperation(httpMethod = "get",value = "预案回放退出", notes = "预案回放退出")
@RequestMapping(value = "/fire/replay/exit", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
public CommonResponse replayExit(@RequestParam("batchNo") String batchNo,
@RequestParam("randomNumber") String randomNumber) throws Exception{
ruleRunningSnapshotService.exitReplayPlan(batchNo, randomNumber);
return CommonResponseUtil.success("SUCCESS");
}
@Scheduled(cron = "*/2 * * * * ?")
public void runFireQueue() throws Exception
......@@ -169,15 +188,6 @@ public class TimeLineController extends BaseController{
}
String operate = "{" +
" \"type\": \"button\"," +
" \"operate\": [" +
......
......@@ -170,7 +170,7 @@ public class View3dController extends BaseController {
product = getProduct();
staticOrgCode = orgCode;
token = getToken();
return view3dService.getStatisticsDuty(getAppKey(),getProduct(),orgCode);
return view3dService.getStatisticsDuty(getAppKey(),getProduct(),token,orgCode);
}
@Permission
......@@ -254,6 +254,7 @@ public class View3dController extends BaseController {
String product = this.getProduct();
return view3dService.retrieveAll(params.getType(),
params.getRiskSourceId(),
params.getInputText(),
params.getCurrent(),
params.getPageSize(),
......
......@@ -145,9 +145,9 @@ public interface View3dMapper extends BaseMapper{
List<Node3DVoResponse> findViewDataByType(@Param("type")String type,@Param("riskSourceId")Long riskSourceId,@Param("orgCode")String orgCode,@Param("abnormalStatus")Boolean abnormalStatus);
Long retrieveAllCount(String type, String inputText,String orgCode,String dataLevel,String protectObjName);
Long retrieveAllCount(String type, Long riskSourceId, String inputText,String orgCode,String dataLevel,String protectObjName);
List<HashMap<String, Object>> retrieveAll(String type, String inputText, long start, int length,String orgCode,String dataLevel,String protectObjName);
List<HashMap<String, Object>> retrieveAll(String type, Long riskSourceId, String inputText, long start, int length,String orgCode,String dataLevel,String protectObjName);
/**
* 查询区域下点
......
package com.yeejoin.amos.fas.business.dao.repository;
import org.springframework.stereotype.Repository;
import com.yeejoin.amos.fas.business.service.model.RuleRuningSnapshot;
@Repository
public interface IRuleRuningSnapshotDao extends BaseDao<RuleRuningSnapshot, String>{
}
......@@ -6,7 +6,7 @@ import com.yeejoin.amos.fas.core.util.CommonResponseUtil;
public class DutyModeServerFallback implements IDutyModeServer{
@Override
public CommonResponse dutyListByDay(String appKey,String product,String orgCode,String dutyDate) {
public CommonResponse dutyListByDay(String appKey,String product, String token,String orgCode,String dutyDate) {
return CommonResponseUtil.failure("fegin调用失败!!!");
}
......
package com.yeejoin.amos.fas.business.feign;
import com.yeejoin.amos.fas.core.util.CommonResponse;
public class EquipManageFeignFallback implements IEquipManageFeign{
@Override
public CommonResponse saveWarehouse(String appKey, String product, String token, String param) {
return null;
}
@Override
public CommonResponse delWarehouse(String appKey, String product, String token, String param) {
return null;
}
}
......@@ -13,6 +13,7 @@ public interface IDutyModeServer {
public CommonResponse dutyListByDay(
@RequestHeader(name="appKey",required = true) String appKey,
@RequestHeader(name="product",required = true) String product,
@RequestHeader(name="token",required = true) String token,
@RequestHeader(name="orgCode",required = true) String orgCode,
@RequestBody String param);
......
package com.yeejoin.amos.fas.business.feign;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.yeejoin.amos.fas.core.util.CommonResponse;
@FeignClient(name="${equipManage.fegin.name}", fallback=MassVisualFallback.class, configuration=FeignConfiguration.class)
public interface IEquipManageFeign {
/**
*
* 远程保存仓库,如果id存在就更新,不存在就新增。
*
* @param appKey
* @param product
* @param token
* @param param
* @return CommonResponse
* @throws <br>
* @author 张展弋
* @date 2020-9-8 15:15:18
*/
@RequestMapping(value = "/equip/warehouse/saveAutoSysSyn", method = RequestMethod.POST,consumes = "application/json")
public CommonResponse saveWarehouse(
@RequestHeader(name="appKey",required = true) String appKey,
@RequestHeader(name="product",required = true) String product,
@RequestHeader(name="token",required = true) String token,
@RequestBody String param);
/**
*
* 远程删除仓库
*
* @param appKey
* @param product
* @param token
* @param riskSourceId 网络传输不支持long这边传string那边long接
* @return CommonResponse
* @throws <br>
* @author 张展弋
* @date 2020-9-8 17:43:11
*/
@RequestMapping(value = "/equip/warehouse/deleteAutoSysSyn", method = RequestMethod.POST,consumes = "application/json")
public CommonResponse delWarehouse(
@RequestHeader(name="appKey",required = true) String appKey,
@RequestHeader(name="product",required = true) String product,
@RequestHeader(name="token",required = true) String token,
@RequestBody String riskSourceId);
}
......@@ -8,6 +8,16 @@ public class RetrieveParams {
private Integer pageSize;
private String dataLevel;
private String protectObjName;
private String riskSourceId;
public String getRiskSourceId() {
return riskSourceId;
}
public void setRiskSourceId(String riskSourceId) {
this.riskSourceId = riskSourceId;
}
public String getType() {
return type;
}
......
......@@ -22,7 +22,7 @@ public class BizMessageServiceImpl implements IBizMessageService {
public Page queryForPage(String time, String type, String title, String orgCode, CommonPageable pageable)
public Page queryForPage(String time, String type, String title, String orgCode, CommonPageable pageable)
{
Long total = bizMessageMapper.queryCountForPage(time, type, title, orgCode);
List<NodeMessageView> content = bizMessageMapper.queryForPage(time, type, title, orgCode,pageable.getOffset(),pageable.getPageSize());
......
......@@ -21,12 +21,16 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.client.RestTemplate;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.component.rule.RuleTrigger;
import com.yeejoin.amos.fas.business.action.ContingencyAction;
import com.yeejoin.amos.fas.business.action.model.ContingencyEvent;
import com.yeejoin.amos.fas.business.action.model.ContingencyRo;
import com.yeejoin.amos.fas.business.action.model.SetpEnum;
import com.yeejoin.amos.fas.business.action.mq.StationEnum;
import com.yeejoin.amos.fas.business.action.result.BubbleTipResult;
import com.yeejoin.amos.fas.business.action.result.SafteyPlanResult;
import com.yeejoin.amos.fas.business.action.util.ContingencyLogPublisher;
import com.yeejoin.amos.fas.business.dao.mapper.FireEquipPointMapper;
import com.yeejoin.amos.fas.business.dao.mapper.ImpAndFireEquipMapper;
import com.yeejoin.amos.fas.business.dao.repository.IContingencyOriginalDataDao;
......@@ -76,6 +80,9 @@ public class ContingencyInstanceImpl /*extends GenericManagerImpl<ContingencyPla
@Autowired
private RuleTrigger ruleTrigger;
@Value("${spring.application.name}")
private String serviceName;
/* public ContingencyInstanceImpl(IContingencyPlanInstanceRepository repository) {
super(repository);
......@@ -83,6 +90,9 @@ public class ContingencyInstanceImpl /*extends GenericManagerImpl<ContingencyPla
}*/
@Autowired
ContingencyAction contingencyAction;
@Autowired
private ContingencyLogPublisher contingencyLogPublisher;
/**
* 创建预案执行记录
*
......@@ -193,27 +203,30 @@ public class ContingencyInstanceImpl /*extends GenericManagerImpl<ContingencyPla
ruleTrigger.publish(contingencyRo, equipment.getReservePlan(), ArrayUtils.toArray(equipment.getName()));
// 刷新记录区
// SimpleDateFormat sdf = new SimpleDateFormat("YYYY/MM/DD HH:mm:ss");
// List<ContingencyPlanInstance> list = iContingencyInstance.queryForTimeLine(contingencyRo.getBatchNo(), "MESSAGE");
// SafteyPlanResult result1 = new SafteyPlanResult();
// Map<String, Object> tempmap2 = new HashMap<>();
// ArrayList records = new ArrayList<>();
// if (ObjectUtils.isEmpty(list)) {
// list.forEach(action -> {
// HashMap map = new HashMap();
// map.put("time", sdf.format(action.getCreateDate()));
// map.put("stepName", action.getContent());
// });
// }
// tempmap2.put("content", records);
// result1.add(tempmap2);
// contingencyAction.sendcmd("recordarea", contingencyRo, result1);
publisherPlanLog(stepCode, buttonCode, batchNo);
} else {
throw new Exception("数据异常,请联系管理员.");
}
}
private void publisherPlanLog(String stepCode, String buttonCode, String batchNo) {
ContingencyEvent event = new ContingencyEvent(this);
JSONObject json = new JSONObject();
JSONObject msgContext = new JSONObject();
JSONObject content = new JSONObject();
content.put("stepCode", stepCode);
content.put("buttonCode", buttonCode);
msgContext.put("type", "clickEvent");
msgContext.put("content", content);
json.put("msgType", "message");
json.put("msgContext", msgContext);
event.setMsgBody(json.toJSONString());
String topic = String.format("/%s/%s/%s", serviceName, StationEnum.YINAN.getCode(),"plan");
event.setTopic(topic);
event.setMsgType("clickEvent");
event.setContingency(batchNo);
contingencyLogPublisher.publish(event);
}
public void setButtonExecuted(String batchNo, String contingencyPlanId, String code, String buttonState) throws Exception {
......@@ -237,7 +250,7 @@ public class ContingencyInstanceImpl /*extends GenericManagerImpl<ContingencyPla
}
throw new Exception("请勿重复操作.");
}
if ("CONFIRM".equals(buttonState)) {
if (code.equals(operate.getCode())) {
......
package com.yeejoin.amos.fas.business.service.impl;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.typroject.tyboot.core.foundation.context.SpringContextHelper;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yeejoin.amos.fas.business.action.CustomerAction;
import com.yeejoin.amos.fas.business.action.model.BasicsRo;
import com.yeejoin.amos.fas.business.action.model.ContingencyRo;
import com.yeejoin.amos.fas.business.action.mq.WebMqttComponent;
import com.yeejoin.amos.fas.business.action.result.ActionResult;
import com.yeejoin.amos.fas.business.action.result.SafteyPlanResult;
import com.yeejoin.amos.fas.business.action.result.message.AbstractActionResultMessage;
import com.yeejoin.amos.fas.business.dao.mapper.RuleRuningSnapshotMapper;
import com.yeejoin.amos.fas.business.dao.repository.IRuleRuningSnapshotDao;
import com.yeejoin.amos.fas.business.service.intfc.IRuleRunningSnapshotService;
import com.yeejoin.amos.fas.business.service.model.RuleRuningSnapshot;
import com.yeejoin.amos.fas.business.service.model.ToipResponse;
/**
*
......@@ -39,15 +52,26 @@ public class RuleRunigSnapshotServiceImpl
{
//IRuleRuningSnapshotRepository repository;
@Autowired
private RuleRuningSnapshotMapper ruleRuningSnapshotMapper;
@Resource
IRuleRuningSnapshotDao ruleRuningSnapshotDao;
private static String replayBatchNo = null;
static ObjectMapper objectMapper;
private final Logger logger = LoggerFactory.getLogger(RuleRunigSnapshotServiceImpl.class);
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private WebMqttComponent webMqttComponent;
private static String PACKAGEURL = "com.yeejoin.amos.fas.business.action.result.message.";
static {
objectMapper = new ObjectMapper();
}
......@@ -67,20 +91,20 @@ public class RuleRunigSnapshotServiceImpl
* @param paramsAndTypes
* @param matchedObj
*/
public void process(Object bean,String methodName,String paramsAndTypes,Object matchedObj)
public void process(Object bean,String methodName,String paramsAndTypes,String batchNo)
{
if(bean instanceof CustomerAction)
{
Set set = (Set) matchedObj;
BasicsRo fireEquimentDataRo = (BasicsRo) set.iterator().next();
// Set set = (Set) matchedObj;
// BasicsRo fireEquimentDataRo = (BasicsRo) set.iterator().next();
RuleRuningSnapshot ruleRuningSnapshot = new RuleRuningSnapshot();
ruleRuningSnapshot.setId(UUID.randomUUID().toString());
ruleRuningSnapshot.setMethodClass(bean.getClass().getName());
ruleRuningSnapshot.setMethodName(methodName);
ruleRuningSnapshot.setMethodParam(paramsAndTypes);
ruleRuningSnapshot.setBatchNo(fireEquimentDataRo.getBatchNo());
ruleRuningSnapshot.setBatchNo(batchNo);
//ruleRuningSnapshot.setPackageId(fireEquimentDataRo.getPackageId());
//ruleRuningSnapshot.setEquipmentId(String.valueOf(fireEquimentDataRo.getId()));
......@@ -88,16 +112,112 @@ public class RuleRunigSnapshotServiceImpl
ruleRuningSnapshot.setCreateTime(now);
ruleRuningSnapshot.setCreateMillisecond(String.valueOf(now.getTime()));
ruleRuningSnapshot.setPreviousInterval(0L);
RuleRuningSnapshot oldEntity = ruleRuningSnapshotMapper.querForObject(fireEquimentDataRo.getBatchNo());
RuleRuningSnapshot oldEntity = ruleRuningSnapshotMapper.querForObject(batchNo);
if(oldEntity != null)
ruleRuningSnapshot.setPreviousInterval(now.getTime() - Long.parseLong(oldEntity.getCreateMillisecond()));
//repository.save(ruleRuningSnapshot);
ruleRuningSnapshotMapper.save(ruleRuningSnapshot);
ruleRuningSnapshotDao.save(ruleRuningSnapshot);
}
}
@Transactional
public void reacordPlan(String topic, String msgType, String msgBody, Object contingency)
{
String batchNo = null;
if (contingency instanceof ContingencyRo) {
batchNo = ((ContingencyRo) contingency).getBatchNo();
} else if (contingency instanceof String) {
batchNo = contingency.toString();
} else {
batchNo = (String) redisTemplate.opsForValue().get(RiskSourceServiceImpl.cacheKeyForCanBeRunning());
}
RuleRuningSnapshot ruleRuningSnapshot = new RuleRuningSnapshot();
ruleRuningSnapshot.setId(UUID.randomUUID().toString());
ruleRuningSnapshot.setMethodClass("com.yeejoin.amos.fas.business.action.ContingencyAction");
ruleRuningSnapshot.setPackageId(topic);
ruleRuningSnapshot.setMethodName(msgType);
ruleRuningSnapshot.setMethodParam(msgBody);
ruleRuningSnapshot.setBatchNo(batchNo);
Date now = new Date();
ruleRuningSnapshot.setCreateTime(now);
ruleRuningSnapshot.setCreateMillisecond(String.valueOf(now.getTime()));
ruleRuningSnapshot.setPreviousInterval(0L);
RuleRuningSnapshot oldEntity = ruleRuningSnapshotMapper.querForObject(batchNo);
if(oldEntity != null)
ruleRuningSnapshot.setPreviousInterval(now.getTime() - Long.parseLong(oldEntity.getCreateMillisecond()));
ruleRuningSnapshotDao.save(ruleRuningSnapshot);
}
@Async
public void replayPlan(String batchNo, String randomNumber) throws Exception
{
try
{
List<RuleRuningSnapshot> oldEntityList=ruleRuningSnapshotMapper.querForObjectList(batchNo);
if(!CollectionUtils.isEmpty(oldEntityList))
{
logger.info("开始回放:batchNo="+batchNo);
logger.info("获取到动作记录个数:"+oldEntityList.size());
redisTemplate.opsForValue().set("replay:" + batchNo +":" + randomNumber, true);
int count = 0;
for(RuleRuningSnapshot snapshot : oldEntityList)
{
if(batchNo == null)
return ;
Object play = redisTemplate.opsForValue().get("replay:" + batchNo +":" + randomNumber);
if (ObjectUtils.isEmpty(play)) {
SafteyPlanResult result = new SafteyPlanResult();
Map<String, Object> tempmap1 = new HashMap<>();
tempmap1.put("type", "event");
tempmap1.put("content", "stopPlan");
result.add(tempmap1);
Constructor<?> constructor = Class.forName(
PACKAGEURL + result.getClass().getSimpleName() + "Message")
.getConstructor(ActionResult.class);
AbstractActionResultMessage<?> action = (AbstractActionResultMessage<?>) constructor.newInstance(result);
ToipResponse toipResponse = action.buildResponse("message", batchNo, result.toJson());
webMqttComponent.publish(String.format("%s/%s/%s", snapshot.getPackageId(), "replay", randomNumber), toipResponse.toJsonStr());
return;
}
//延迟
logger.info("开始执行第"+(++count)+"个动作.");
logger.info("方法名:"+snapshot.getMethodClass()+"."+snapshot.getMethodName());
logger.info("需要延迟"+snapshot.getPreviousInterval()+"毫秒.......");
Thread.sleep(snapshot.getPreviousInterval());
try
{
webMqttComponent.publish(String.format("%s/%s/%s", snapshot.getPackageId(), "replay", randomNumber) , snapshot.getMethodParam());
logger.info("第"+(count)+"个动作执行成功.");
}catch (Exception e)
{
logger.info("第"+(count)+"个动作执行失败.");
e.printStackTrace();
logger.error(e.getMessage(),e);
}
}
}
}catch (Exception e)
{
logger.info("回放失败.");
logger.error(e.getMessage(),e);
} finally {
redisTemplate.delete("replay:" + batchNo +":" + randomNumber);
}
}
@Override
public void exitReplayPlan(String batchNo, String randomNumber) {
redisTemplate.delete("replay:" + batchNo +":" + randomNumber);
}
@Async
public void replay(String batchNo) throws Exception
{
......@@ -194,4 +314,6 @@ public class RuleRunigSnapshotServiceImpl
public static void setReplayBatchNoToNull() {
RuleRunigSnapshotServiceImpl.replayBatchNo = null;
}
}
\ No newline at end of file
......@@ -492,12 +492,12 @@ public class View3dServiceImpl implements IView3dService {
}
@Override
public CommonResponse getStatisticsDuty(String appKey,String product,String orgCode) {
public CommonResponse getStatisticsDuty(String appKey,String product,String token, String orgCode) {
Date curDate = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
JSONObject param = new JSONObject();
param.put("dutyDate", curDate);
return dutyModeServer.dutyListByDay(appKey,product,orgCode,param.toJSONString());
return dutyModeServer.dutyListByDay(appKey,product,token,orgCode,param.toJSONString());
}
@Override
......@@ -570,10 +570,11 @@ public class View3dServiceImpl implements IView3dService {
}
@Override
public CommonResponse retrieveAll(String type, String inputText, int current, int pageSize,String orgCode,String dataLevel,String protectObjName,String token,String appKey,String product) {
public CommonResponse retrieveAll(String type, String riskSourceId, String inputText, int current, int pageSize,String orgCode,String dataLevel,String protectObjName,String token,String appKey,String product) {
CommonPageable pageable = new CommonPageable( current, pageSize);
Long count = view3dMapper.retrieveAllCount(type,inputText,orgCode,dataLevel,protectObjName);
List<HashMap<String, Object>> retrieveAll = view3dMapper.retrieveAll(type, inputText,pageable.getOffset(),pageable.getPageSize(),orgCode,dataLevel,protectObjName);
Long riskSource = StringUtils.isEmpty(riskSourceId) ? null : Long.parseLong(riskSourceId);
Long count = view3dMapper.retrieveAllCount(type,riskSource,inputText,orgCode,dataLevel,protectObjName);
List<HashMap<String, Object>> retrieveAll = view3dMapper.retrieveAll(type, riskSource,inputText,pageable.getOffset(),pageable.getPageSize(),orgCode,dataLevel,protectObjName);
Set<Object> userIds = new HashSet<>();
retrieveAll.forEach(action->{
if(!ObjectUtils.isEmpty(action.get("person"))){
......
package com.yeejoin.amos.fas.business.service.intfc;
import com.yeejoin.amos.fas.business.action.model.FireEquimentDataRo;
import com.yeejoin.amos.fas.business.action.model.ProtalDataRo;
import com.yeejoin.amos.fas.business.bo.BindRegionBo;
......@@ -19,7 +20,6 @@ import org.springframework.data.domain.Page;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
public interface IRiskSourceService {
......@@ -27,11 +27,55 @@ public interface IRiskSourceService {
* 新增及维护风险点
*/
RiskSource editRiskSource(HashMap<String, Object> map) throws Exception;
/**
* 风险模型新增及维护时远程同步
*
* @param appKey
* @param product
* @param token
* @param success contoler中的系统通用failed标识和这里返回前台的不一样。
* @param id
* @param code
* @param name
* @param parentId
* @return CommonResponse
* @throws <br>
* @author 张展弋
* @date 2020-9-8 17:39:32
*/
String saveToEquipManage(String appKey, String product, String token, String success, long id,
String code, String name, Long parentId);
/**
* 将本地 风险模型推送到远程同步
*
* @param appKey
* @param product
* @param token
* @param success
* @param riskSourcesTree
* @return String
* @throws <br>
* @author 张展弋
* @date 2020-9-9 15:40:18
*/
String synToEquipManage(String appKey, String product, String token, String success, List<RiskSourceTreeResponse> riskSourcesTree);
/**
*
* 是否同步到对站系统
*
* @return boolean
* @throws <br>
* @author 张展弋
* @date 2020-9-8 15:45:34
*/
boolean isSynEquipManage();
/**
* 删除风险点
*/
void deleteRiskSource(Long[] riskSourceId) throws Exception;
void deleteRiskSource(String appKey,String product,String token,String failed,Long[] riskSourceId) throws Exception;
/**
* 根据参数分页查询风险点信息
......@@ -76,7 +120,7 @@ public interface IRiskSourceService {
boolean processTaskData(ProtalDataRo taskData) throws Exception;
void processProtalData(String toke,String product,String appKey,ProtalDataRo protalData) throws Exception;
void processProtalData(String toke,String product,String appKey,ProtalDataRo protalData, String orgCode) throws Exception;
RiskSourceTreeResponse queryRiskSourceDetailById(Long id);
......@@ -134,9 +178,20 @@ public interface IRiskSourceService {
*/
void batchSaveRegionUe4(List<BindRegionBo> regionBoList);
void notifyRiskSource(Long fmeaId, Long riskSourceId, String notifyType, JpushMsgBo jpushMsgBo);
void notifyRiskSource(String orgCode, Long fmeaId, Long riskSourceId, String notifyType, JpushMsgBo jpushMsgBo);
void notifyFmeaFromDelete(Long handId, String from);
void notifyRiskSourceDelete(Long handId);
/**
*
* 不做任何不能删校验,直接删除,慎用
*
* @param id void
* @throws <br>
* @author 张展弋
* @date 2020-9-9 11:53:36
*/
void deleteById(Long id);
}
......@@ -14,5 +14,9 @@ public interface IRuleRunningSnapshotService
void replay(String batchNo) throws Exception;
public void reacordPlan(String topic, String msgType, String msgBody, Object contingency);
public void replayPlan(String batchNo, String randomNumber) throws Exception;
void exitReplayPlan(String batchNo, String randomNumber);
}
......@@ -104,7 +104,7 @@ public interface IView3dService {
* 今日值班统计
* @return
*/
CommonResponse getStatisticsDuty(String appKey, String product, String orgCode);
CommonResponse getStatisticsDuty(String appKey, String product, String token, String orgCode);
/**
* 设备状态消息最新5条
......@@ -148,6 +148,7 @@ public interface IView3dService {
/**
* 检索
* @param type类型
* @param riskRourceId
* @param inputText关键字
* @param dataLevel风险等级
* @param protectObjName设备名称
......@@ -156,7 +157,7 @@ public interface IView3dService {
* @param orgCode
* @return
*/
CommonResponse retrieveAll(String type, String inputText, int current, int pageSize,String orgCode,String dataLevel,String protectObjName,String token,String appKey,String product);
CommonResponse retrieveAll(String type, String riskRourceId, String inputText, int current, int pageSize,String orgCode,String dataLevel,String protectObjName,String token,String appKey,String product);
/**
* 等级查询
......
package com.yeejoin.amos.fas.config;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ResponseBody;
......@@ -20,8 +23,9 @@ public class ExceptionHandler {
@org.springframework.web.bind.annotation.ExceptionHandler(PermissionException.class)
@ResponseBody
public CommonResponse handlePermissionException(HttpServletRequest request, PermissionException ex) {
return CommonResponseUtil.failure(ex.getMessage());
public CommonResponse handlePermissionException(HttpServletRequest request, HttpServletResponse resp, PermissionException ex) {
resp.setStatus(HttpStatus.UNAUTHORIZED.value());
return CommonResponseUtil.failure(ex.getMessage());
}
@org.springframework.web.bind.annotation.ExceptionHandler(YeeException.class)
......
......@@ -3,6 +3,12 @@ package com.yeejoin.amos.fas.config;
import javax.servlet.http.HttpServletRequest;
import com.yeejoin.amos.component.feign.config.InnerInvokException;
import com.yeejoin.amos.fas.business.feign.RemoteSecurityService;
import com.yeejoin.amos.fas.business.vo.DepartmentBo;
import com.yeejoin.amos.fas.business.vo.RoleBo;
import com.yeejoin.amos.feign.privilege.model.DepartmentModel;
import com.yeejoin.amos.feign.privilege.model.RoleModel;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
......@@ -29,6 +35,11 @@ import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import com.yeejoin.amos.feign.privilege.model.CompanyModel;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Aspect
@Component
@ResponseBody
......@@ -37,6 +48,9 @@ public class PermissionAspect {
@Autowired
private RedisTemplate<String, String> redisTemplate;
@Autowired
private RemoteSecurityService remoteSecurityService;
// 前置通知,在方法执行之前
@Before(value = "@annotation(Permission)")
......@@ -46,16 +60,111 @@ public class PermissionAspect {
logger.info("======开始权限校验======");
// 用户token
String token = (String) request.getHeader("token");
token = ObjectUtils.isEmpty(token) ? (String) request.getHeader("X-Access-Token") : token;
String product = (String) request.getHeader("product");
String appKey = (String) request.getHeader("appKey");
logger.info("用户token:" + token);
RequestContext.setToken(token);
RequestContext.setProduct(product);
RequestContext.setAppKey(appKey);
if (!TokenOperation.refresh(token)) {
throw new PermissionException("登录信息失效,请重新登录");
}
String token = (String) request.getHeader("token");
token = ObjectUtils.isEmpty(token) ? (String) request.getHeader("X-Access-Token") : token;
String product = (String) request.getHeader("product");
String appKey = (String) request.getHeader("appKey");
logger.info("用户token:" + token);
RequestContext.setToken(token);
RequestContext.setProduct(product);
RequestContext.setAppKey(appKey);
if (!TokenOperation.refresh(token)) {
throw new PermissionException("登录信息失效,请重新登录");
}
if (joinPoint.getSignature().getName().equals("saveCurCompany")) {
return;
}
FeignClientResult feignClientResult;
AgencyUserModel userModel=null;
try {
feignClientResult = Privilege.agencyUserClient.getme();
userModel = (AgencyUserModel) feignClientResult.getResult();
} catch (InnerInvokException e) {
e.printStackTrace();
}
String userId = null;
ReginParams regionParam = new ReginParams();
if(userModel != null){
userId = userModel.getUserId();
Map<Long, List<RoleModel>> orgRoles = userModel.getOrgRoles();
List<RoleModel> roleModels = null;
if(!ObjectUtils.isEmpty(orgRoles)) {
for (Map.Entry<Long, List<RoleModel>> entry : orgRoles.entrySet()) {
roleModels = entry.getValue();
break;
}
}
ReginParams reginParams = JSON.parseObject(redisTemplate.opsForValue().get(buildKey(userModel.getUserId(), token)), ReginParams.class);
if(reginParams == null && userModel.getCompanys().size() > 0){
CompanyModel companyModel = userModel.getCompanys().get(0);
List<DepartmentModel> deptList = remoteSecurityService.getDepartmentTreeByCompanyId(token, product, appKey, companyModel.getSequenceNbr().toString());
if(deptList.size() > 0){
CompanyBo companyBo = convertCompanyModelToBo(companyModel);
DepartmentBo departmentBo = convertDepartmentModelToBo(deptList.get(0));
regionParam.setCompany(companyBo);
regionParam.setDepartment(departmentBo);
}
if(!ObjectUtils.isEmpty(roleModels)){
regionParam.setRole(convertRoleModelToBo(roleModels.get(0)));
}
redisTemplate.opsForValue().set(buildKey(userId, token), JSONObject.toJSONString(regionParam));
}
}
}
private DepartmentBo convertDepartmentModelToBo(DepartmentModel departmentModel){
DepartmentBo departmentBo = new DepartmentBo();
if(departmentModel != null) {
departmentBo.setCompanySeq(departmentModel.getCompanySeq().toString());
departmentBo.setDepartmentDesc(departmentModel.getDepartmentDesc());
departmentBo.setDepartmentName(departmentModel.getDepartmentName());
departmentBo.setLevel(departmentModel.getLevel());
departmentBo.setOrgCode(departmentModel.getOrgCode());
departmentBo.setParentId(departmentModel.getParentId().toString());
departmentBo.setDeptOrgCode(departmentModel.getDeptOrgCode().toString());
departmentBo.setSequenceNbr(departmentModel.getSequenceNbr().toString());
}
return departmentBo;
}
/**
* Model 转 Bo
*/
private CompanyBo convertCompanyModelToBo(CompanyModel companyModel){
CompanyBo companyBo = new CompanyBo();
if(companyModel != null) {
companyBo.setAddress(companyModel.getAddress());
companyBo.setCompanyName(companyModel.getCompanyName());
companyBo.setCompanyOrgCode(Long.parseLong(companyModel.getCompanyOrgCode().toString()));
companyBo.setEmail(companyModel.getEmail());
companyBo.setLandlinePhone(companyModel.getLandlinePhone());
companyBo.setLongitude(companyModel.getLongitude());
companyBo.setLatitude(companyModel.getLatitude());
companyBo.setLevel(companyModel.getLevel());
companyBo.setOrgCode(companyModel.getOrgCode());
companyBo.setSequenceNbr(companyModel.getSequenceNbr().toString());
companyBo.setParentId(companyModel.getParentId().toString());
}
return companyBo;
}
private RoleBo convertRoleModelToBo(RoleModel roleModel) {
RoleBo roleBo = new RoleBo();
if(roleModel != null){
roleBo.setRoleName(roleModel.getRoleName());
roleBo.setRoleType(roleModel.getRoleType());
roleBo.setSequenceNbr(roleModel.getSequenceNbr().toString());
}
return roleBo;
}
//redi缓存选择的用户信息
private String buildKey(String userId, String token) {
return "region_" + userId + "_" + token;
}
}
......@@ -15,6 +15,6 @@ public class PermissionException extends RuntimeException{
}
public HttpStatus getStatus() {
return HttpStatus.FORBIDDEN; // 403
return HttpStatus.UNAUTHORIZED; // 401
}
}
security.password=a1234560
security.loginId=shg
security.loginId=fas_autosys
security.productWeb=CONVERTER_STATION_WEB
security.appKeyWeb=CONVERTER_STATION
#environment
#spring.profiles.active = dev
eureka.client.serviceUrl.defaultZone=http://172.16.3.75:10001/eureka/
eureka.client.serviceUrl.defaultZone=http://172.16.10.72:10001/eureka/
eureka.client.register-with-eureka = true
eureka.client.fetch-registry = true
eureka.client.healthcheck.enabled = true
eureka.client.fetchRegistry = true
eureka.instance.prefer-ip-address=true
#DB properties:
spring.datasource.url=jdbc:mysql://172.16.11.33:3306/v2.0_zmd_yeejoin_safety_business?allowMultiQueries=true&serverTimezone=GMT%2B8&characterEncoding=utf8
spring.datasource.url=jdbc:mysql://172.16.11.33:3306/safety-business-2.0-36?allowMultiQueries=true&serverTimezone=GMT%2B8&characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=admin_1234
spring.datasource.driver-class-name = com.mysql.jdbc.Driver
......@@ -63,11 +63,8 @@ rule.definition.load=true
rule.definition.model-package=com.yeejoin.amos.fas.business.action.model
rule.definition.default-agency=STATE_GRID
amos.feign.gennerator.use-gateway=true
autoSys.push.type=mqtt
amos.feign.gennerator.use-gateway=true
#�����
file.downLoad.url=http://172.16.10.175:8888/
......@@ -46,6 +46,10 @@ spring.servlet.multipart.max-request-size=20MB
#feginName
visual.fegin.name=maas-visual
dutyMode.fegin.name=AMOSDUTYMODE
#队站装备管理名称,主要用于风险区域同步至仓库货位
equipManage.fegin.name=AMOS-EQUIPMANAGE-ZZY
#是否开启将风险区域同步至仓库货位true开启,false关闭。默认关闭。
equipManage.fegin.isSyn=false
spring.http.multipart.maxFileSize = 10480000
spring.http.multipart.MaxRequestSize = 50480000
......
......@@ -5,49 +5,57 @@
<select id="queryForPage" resultType="map">
SELECT
DATE_FORMAT(create_date,'%Y-%m-%d %H:%i:%s') create_time,
SELECT * FROM(
SELECT
DATE_FORMAT(create_date,'%Y-%m-%d %H:%i:%s') create_time,
t.*
FROM
contingency_original_data t
WHERE
1 = 1
t.*
FROM
contingency_original_data t
WHERE
1 = 1
<if test="equipmentId!=null">
AND t.equipment_Id = #{equipmentId}
</if>
<if test="equipmentId!=null">
AND t.equipment_Id = #{equipmentId}
</if>
<if test="createTime!=null">
AND TO_DAYS(t.create_date) = TO_DAYS(#{createTime})
</if>
<if test="createTime!=null">
AND TO_DAYS(t.create_date) = TO_DAYS(#{createTime})
</if>
) m
WHERE
1 = 1
<if test="contingencyName!=null and contingencyName!=''">
AND t.fire_Equipment_Name like concat('%',#{contingencyName},'%')
OR t.equipment_Name like concat('%',#{contingencyName},'%')
OR m.fire_Equipment_Name like concat('%',#{contingencyName},'%')
OR m.equipment_Name like concat('%',#{contingencyName},'%')
</if>
order by t.create_date desc
order by m.create_date desc
LIMIT #{start},#{length} ;
</select>
<select id="queryCountForPage" resultType="long">
SELECT
count(1)
FROM
contingency_original_data t
WHERE
1 = 1
SELECT count(1) FROM (
SELECT
*
FROM
contingency_original_data t
WHERE
1 = 1
<if test="equipmentId!=null">
AND t.equipment_Id = #{equipmentId}
</if>
<if test="equipmentId!=null">
AND t.equipment_Id = #{equipmentId}
</if>
<if test="createTime!=null">
AND TO_DAYS(t.create_date) = TO_DAYS(#{createTime})
</if>
<if test="createTime!=null">
AND TO_DAYS(t.create_date) = TO_DAYS(#{createTime})
</if>
) m
WHERE
1=1
<if test="contingencyName!=null and contingencyName!=''">
AND t.fire_Equipment_Name like concat('%',#{contingencyName},'%')
OR t.equipment_Name like concat('%',#{contingencyName},'%')
OR m.fire_Equipment_Name like concat('%',#{contingencyName},'%')
OR m.equipment_Name like concat('%',#{contingencyName},'%')
</if>
</select>
......
......@@ -1178,7 +1178,7 @@
<select id="retrieveAllCount" resultType="long">
select count(1)
from (
select r.name,r.code,'riskSource' as typeCode,r.org_code as orgCode
select r.name,r.code,'riskSource' as typeCode,r.org_code as orgCode, r.id as riskSourceId
from f_risk_source r
left join f_risk_level rl ON rl.id = r.risk_level_id
where r.is_region = 'FALSE'
......@@ -1186,14 +1186,14 @@
AND rl.level = #{dataLevel}
</if>
UNION all
select p.name,p.point_no as code,'patrol' as typeCode,p.org_code as orgCode
select p.name,p.point_no as code,'patrol' as typeCode,p.org_code as orgCode, p.risk_source_id as riskSourceId
from p_point p
WHERE is_delete = FALSE
UNION all
select name,code,'impEquipment' as typeCode,org_code as orgCode
select name,code,'impEquipment' as typeCode,org_code as orgCode, e.risk_source_id as riskSourceId
from f_equipment e
UNION all
select m.name,m.code,'monitorEquipment' as typeCode,m.org_code as orgCode
select m.name,m.code,'monitorEquipment' as typeCode,m.org_code as orgCode, m.risk_source_id as riskSourceId
from f_fire_equipment m
left join f_equipment_fire_equipment fe on fe.fire_equipment_id = m.id
left join f_equipment f on f.id = fe.equipment_id
......@@ -1202,29 +1202,29 @@
AND f.name = #{protectObjName}
</if>
UNION all
select name,code,'video' as typeCode,org_code as orgCode
select name,code,'video' as typeCode,org_code as orgCode, risk_source_id as riskSourceId
from f_fire_equipment where equip_classify = 2
UNION all
select name,code,'fireEquipment' as typeCode,org_code as orgCode
select name,code,'fireEquipment' as typeCode,org_code as orgCode, risk_source_id as riskSourceId
from f_water_resource where type = 1
UNION all
select name,code,'fireEquipment' as typeCode,org_code as orgCode
select name,code,'fireEquipment' as typeCode,org_code as orgCode, risk_source_id as riskSourceId
from f_water_resource where type = 2
UNION all
select name,car_num as code,'fireEquipment' as typeCode,org_code as orgCode
select name,car_num as code,'fireEquipment' as typeCode,org_code as orgCode, risk_source_id as riskSourceId
from f_fire_car
UNION all
select name,code,'fireEquipment' as typeCode,org_code as orgCode
select name,code,'fireEquipment' as typeCode,org_code as orgCode, risk_source_id as riskSourceId
from f_fire_equipment where equip_classify = 3
UNION all
select name,code,'fireEquipment' as typeCode,org_code as orgCode
select name,code,'fireEquipment' as typeCode,org_code as orgCode, risk_source_id as riskSourceId
from f_fire_station where type = 2
UNION all
select name,code,'fireEquipment' as typeCode,org_code as orgCode
select name,code,'fireEquipment' as typeCode,org_code as orgCode, risk_source_id as riskSourceId
from f_fire_station where type = 1
) as tmp
where 1=1
<if test="inputText!=null" >
<if test="inputText!=null and inputText != ''" >
AND (
tmp.code LIKE '%${inputText}%'
OR tmp.name LIKE '%${inputText}%'
......@@ -1233,6 +1233,9 @@
<if test="type!=null and type!=''">
AND tmp.typeCode = #{type}
</if>
<if test="riskSourceId != null">
AND tmp.riskSourceId = #{riskSourceId}
</if>
<if test="orgCode!=null">
AND (tmp.orgCode = #{orgCode} OR tmp.orgCode like CONCAT(#{orgCode},'-%') )
</if>
......@@ -1267,7 +1270,8 @@ from (select concat('riskSource',r.id) as id,r.id as originId,r.name,r.code,r.ue
'' as routeName,
'' as person,
r.rpn as title,
CONCAT('riskSource-',r.id) as `key`
CONCAT('riskSource-',r.id) as `key`,
r.id as riskSourceId
from f_risk_source r
left join f_risk_level rl ON rl.id = r.risk_level_id
where r.is_region = 'FALSE'
......@@ -1307,7 +1311,8 @@ from (select concat('riskSource',r.id) as id,r.id as originId,r.name,r.code,r.ue
when p.status = '2' then '不合格'
when p.status = '3' then '漏检'
end as title,
concat('patrol-',p.id) as `key`
concat('patrol-',p.id) as `key`,
p.risk_source_id as riskSourceId
from p_point p
WHERE is_delete = FALSE
UNION all
......@@ -1338,7 +1343,8 @@ from (select concat('riskSource',r.id) as id,r.id as originId,r.name,r.code,r.ue
'' as routeName,
'' as person,
name as title,
concat('impEquipment-',e.id) as `key`
concat('impEquipment-',e.id) as `key`,
e.risk_source_id as riskSourceId
from f_equipment e
UNION all
select concat('monitorEquipment-',m.id) as id,m.id as originId,m.name,m.code,m.ue4_location as ue4Location,m.ue4_rotation as ue4Rotation ,'monitorEquipment' as type,m.org_code as orgCode,
......@@ -1368,7 +1374,8 @@ from (select concat('riskSource',r.id) as id,r.id as originId,r.name,r.code,r.ue
'' as routeName,
'' as person,
m.name as title,
concat('monitorEquipment-',m.id) as `key`
concat('monitorEquipment-',m.id) as `key`,
m.risk_source_id as riskSourceId
from f_fire_equipment m
left join f_equipment_fire_equipment fe on fe.fire_equipment_id = m.id
left join f_equipment f on f.id = fe.equipment_id
......@@ -1405,7 +1412,8 @@ from (select concat('riskSource',r.id) as id,r.id as originId,r.name,r.code,r.ue
'' as routeName,
'' as person,
m.name as title,
concat('video-',m.id) as `key`
concat('video-',m.id) as `key`,
m.risk_source_id as riskSourceId
from f_fire_equipment m
left join f_equipment_fire_equipment fe on fe.fire_equipment_id = m.id
left join f_equipment f on f.id = fe.equipment_id
......@@ -1439,7 +1447,8 @@ from (select concat('riskSource',r.id) as id,r.id as originId,r.name,r.code,r.ue
'' as routeName,
'' as person,
name as title,
concat('hydrant-',id) as `key`
concat('hydrant-',id) as `key`,
risk_source_id as riskSourceId
from f_water_resource where type = 1
UNION all
select concat('pool-',id) as id,id as originId,name,code,ue4_location as ue4Location,ue4_rotation as ue4Rotation,'pool' as type,org_code as orgCode,
......@@ -1469,7 +1478,8 @@ from (select concat('riskSource',r.id) as id,r.id as originId,r.name,r.code,r.ue
'' as routeName,
'' as person,
name as title,
concat('pool-',id) as `key`
concat('pool-',id) as `key`,
risk_source_id as riskSourceId
from f_water_resource where type = 2
UNION all
select concat('fireCar-',id) as id,id as originId,name,car_num as code,ue4_location as ue4Location,ue4_rotation as ue4Rotation, 'fireCar' as type,org_code as orgCode,
......@@ -1499,7 +1509,8 @@ from (select concat('riskSource',r.id) as id,r.id as originId,r.name,r.code,r.ue
'' as routeName,
'' as person,
name as title,
concat('fireCar-',id) as `key`
concat('fireCar-',id) as `key`,
risk_source_id as riskSourceId
from f_fire_car
UNION all
select concat('fireEquipment-',id) as id,id as originId,name,code,ue4_location as ue4Location,ue4_rotation as ue4Rotation,'fireEquipment' as type,org_code as orgCode,
......@@ -1529,7 +1540,8 @@ from (select concat('riskSource',r.id) as id,r.id as originId,r.name,r.code,r.ue
'' as routeName,
'' as person,
name as title,
concat('fireEquipment-',id) as `key`
concat('fireEquipment-',id) as `key`,
risk_source_id as riskSourceId
from f_fire_equipment where equip_classify = 3
UNION all
select concat('fireChamber-',id) as id,id as originId,name,code,ue4_location as ue4Location,ue4_rotation as ue4Rotation , 'fireChamber' as type,org_code as orgCode,
......@@ -1559,7 +1571,8 @@ from (select concat('riskSource',r.id) as id,r.id as originId,r.name,r.code,r.ue
'' as routeName,
'' as person,
name as title,
concat('fireChamber-',id) as `key`
concat('fireChamber-',id) as `key`,
risk_source_id as riskSourceId
from f_fire_station where type = 2
UNION all
select concat('fireFoamRoom-',id) as id,id as originId,name,code,ue4_location as ue4Location,ue4_rotation as ue4Rotation ,'fireFoamRoom' as type,org_code as orgCode,
......@@ -1589,11 +1602,12 @@ from (select concat('riskSource',r.id) as id,r.id as originId,r.name,r.code,r.ue
'' as routeName,
'' as person,
name as title,
concat('fireFoamRoom-',id) as `key`
concat('fireFoamRoom-',id) as `key`,
risk_source_id as riskSourceId
from f_fire_station where type = 1
) as tmp
<where>
<if test="inputText!=null" >
<if test="inputText!=null and inputText != ''" >
AND (
tmp.code LIKE '%${inputText}%'
OR tmp.name LIKE '%${inputText}%'
......@@ -1602,6 +1616,9 @@ from (select concat('riskSource',r.id) as id,r.id as originId,r.name,r.code,r.ue
<if test="type!=null and type!=''">
AND tmp.typeCode = #{type}
</if>
<if test="riskSourceId != null">
AND tmp.riskSourceId = #{riskSourceId}
</if>
<if test="orgCode!=null">
AND (tmp.orgCode = #{orgCode} OR tmp.orgCode like CONCAT(#{orgCode},'-%') )
</if>
......
......@@ -35,7 +35,7 @@
<groupId>com.yeejoin</groupId>
<artifactId>amos-component-rule</artifactId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
......
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