Commit c7f385f5 authored by 高建强's avatar 高建强

item:巡查数据-站端与中心级数据同步

parent 6eaec4dc
package com.yeejoin.amos.patrol.common.enums;
public enum PatrolDataSyncTopicEnum {
CHECK("check", "patrol/sync/check"),
CHECK_INPUT("checkInput", "patrol/sync/checkInput"),
CHECK_SHOT("checkShot", "patrol/sync/checkShot"),
PLAN_TASK_DETAIL("planTaskDetail", "patrol/sync/planTaskDetail");
private String type;
private String topic;
PatrolDataSyncTopicEnum(String type, String topic) {
this.type = type;
this.topic = topic;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getTopic() {
return topic;
}
public void setTopic(String topic) {
this.topic = topic;
}
}
...@@ -42,4 +42,7 @@ public interface IPlanTaskDetailDao extends BaseDao<PlanTaskDetail, Long> { ...@@ -42,4 +42,7 @@ public interface IPlanTaskDetailDao extends BaseDao<PlanTaskDetail, Long> {
@Query(value = "select * FROM p_plan_task_detail WHERE point_id IN (?1)", nativeQuery = true) @Query(value = "select * FROM p_plan_task_detail WHERE point_id IN (?1)", nativeQuery = true)
List<PlanTaskDetail> findALLByPointId(Long pointId); List<PlanTaskDetail> findALLByPointId(Long pointId);
@Query(value = "select * FROM p_plan_task_detail WHERE id = ?1 AND `status` = ?2", nativeQuery = true)
List<PlanTaskDetail> findAllByIdAndStatus(long id, String status);
} }
...@@ -20,6 +20,7 @@ import com.yeejoin.amos.component.feign.model.FeignClientResult; ...@@ -20,6 +20,7 @@ import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.feign.systemctl.Systemctl; import com.yeejoin.amos.feign.systemctl.Systemctl;
import com.yeejoin.amos.feign.systemctl.model.MessageModel; import com.yeejoin.amos.feign.systemctl.model.MessageModel;
import com.yeejoin.amos.patrol.business.feign.JcsFeignClient; import com.yeejoin.amos.patrol.business.feign.JcsFeignClient;
import com.yeejoin.amos.patrol.business.service.intfc.IPatrolDataSyncService;
import com.yeejoin.amos.patrol.dao.entity.Plan; import com.yeejoin.amos.patrol.dao.entity.Plan;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -30,6 +31,8 @@ import org.springframework.cglib.beans.BeanMap; ...@@ -30,6 +31,8 @@ import org.springframework.cglib.beans.BeanMap;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageImpl;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
...@@ -148,6 +151,9 @@ public class CheckServiceImpl implements ICheckService { ...@@ -148,6 +151,9 @@ public class CheckServiceImpl implements ICheckService {
@Autowired @Autowired
private PlanServiceImpl planService; private PlanServiceImpl planService;
@Autowired
private IPatrolDataSyncService patrolDataSyncService;
// @Value("${file.ip}") // @Value("${file.ip}")
// private String fileIp; // private String fileIp;
// //
...@@ -213,6 +219,15 @@ public class CheckServiceImpl implements ICheckService { ...@@ -213,6 +219,15 @@ public class CheckServiceImpl implements ICheckService {
check.setShotNumber(check.getShotNumber() + imgList.size()); check.setShotNumber(check.getShotNumber() + imgList.size());
checkDao.save(check); checkDao.save(check);
checkShotDao.saveAll(imgList); checkShotDao.saveAll(imgList);
// 巡检站端与中心级数据同步
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
@Override
public void afterCommit() {
// 事物提交后业务逻辑
patrolDataSyncService.checkDataSync(check);
patrolDataSyncService.checkShotDataSync(imgList);
}
});
} }
@Override @Override
...@@ -666,6 +681,18 @@ public class CheckServiceImpl implements ICheckService { ...@@ -666,6 +681,18 @@ public class CheckServiceImpl implements ICheckService {
} }
} }
CheckDto checkDto= new CheckDto(check.getId(), unqualifiedcheckItemList); CheckDto checkDto= new CheckDto(check.getId(), unqualifiedcheckItemList);
// 巡检站端与中心级数据同步
Check finalCheck = check;
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
@Override
public void afterCommit() {
// 事物提交后业务逻辑
patrolDataSyncService.checkDataSync(finalCheck);
patrolDataSyncService.checkInputDataSync(checkInputList);
}
});
return checkDto; return checkDto;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
......
package com.yeejoin.amos.patrol.business.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.patrol.business.dao.repository.IPlanTaskDetailDao;
import com.yeejoin.amos.patrol.business.service.intfc.IPatrolDataSyncService;
import com.yeejoin.amos.patrol.common.enums.PatrolDataSyncTopicEnum;
import com.yeejoin.amos.patrol.dao.entity.Check;
import com.yeejoin.amos.patrol.dao.entity.CheckInput;
import com.yeejoin.amos.patrol.dao.entity.CheckShot;
import com.yeejoin.amos.patrol.dao.entity.PlanTaskDetail;
import com.yeejoin.amos.patrol.mqtt.WebMqttComponent;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
@Async
@Slf4j
public class PatrolDataSyncServiceImpl implements IPatrolDataSyncService {
@Autowired
private WebMqttComponent webMqttComponent;
@Autowired
private IPlanTaskDetailDao planTaskDetailDao;
@Override
public void checkDataSync(Check check) {
if (check != null) {
try {
webMqttComponent.publish(PatrolDataSyncTopicEnum.CHECK.getTopic(), JSONObject.toJSONString(check));
String isOk = check.getIsOk();
long taskDetailId = check.getPlanTaskDetailId();
List<PlanTaskDetail> planTaskDetailList = planTaskDetailDao.findAllByIdAndStatus(taskDetailId, isOk);
if (CollectionUtils.isNotEmpty(planTaskDetailList)) {
planTaskDetailList.forEach(x -> webMqttComponent.publish(PatrolDataSyncTopicEnum.PLAN_TASK_DETAIL.getTopic(), JSONObject.toJSONString(x)));
}
} catch (Exception e) {
log.error("站端与中心级巡检数据【check或planTaskDetail】同步推送失败-----------" + e.getMessage());
}
}
}
@Override
public void checkInputDataSync(List<CheckInput> checkInputList) {
try {
if (CollectionUtils.isNotEmpty(checkInputList)) {
checkInputList.forEach(x -> webMqttComponent.publish(PatrolDataSyncTopicEnum.CHECK_INPUT.getTopic(), JSONObject.toJSONString(x)));
}
} catch (Exception e) {
log.error("站端与中心级巡检数据【checkInput】同步推送失败-----------" + e.getMessage());
}
}
@Override
public void checkShotDataSync(List<CheckShot> checkShotList) {
try {
if (CollectionUtils.isNotEmpty(checkShotList)) {
checkShotList.forEach(x -> webMqttComponent.publish(PatrolDataSyncTopicEnum.CHECK_SHOT.getTopic(), JSONObject.toJSONString(x)));
}
} catch (Exception e) {
log.error("站端与中心级巡检数据【checkShot】同步推送失败-----------" + e.getMessage());
}
}
}
package com.yeejoin.amos.patrol.business.service.intfc;
import com.yeejoin.amos.patrol.dao.entity.Check;
import com.yeejoin.amos.patrol.dao.entity.CheckInput;
import com.yeejoin.amos.patrol.dao.entity.CheckShot;
import java.util.List;
/**
* <h1></h1>
*
* @Author Jianqiang Gao
* @Date 2021-04-01 14:27
*/
public interface IPatrolDataSyncService {
void checkDataSync(Check check);
void checkInputDataSync(List<CheckInput> checkInputList);
void checkShotDataSync(List<CheckShot> checkShotList);
}
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