Browse Source

mq监听者 根据tag 调用不同的方法

master
jianjun 4 years ago
parent
commit
d1812d28ba
  1. 2
      epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/controller/UserPatrolRecordController.java
  2. 18
      epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/mq/listener/OpenDataPatrolChangeEventListener.java
  3. 11
      epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/UserPatrolRecordService.java
  4. 80
      epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/UserPatrolRecordServiceImpl.java

2
epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/controller/UserPatrolRecordController.java

@ -48,7 +48,7 @@ public class UserPatrolRecordController {
@PostMapping("patrol")
public Result getStaffBaseInfo(@RequestBody(required = false) UpsertPatrolRecordForm formDTO) {
ValidatorUtils.validateEntity(formDTO);
userPatrolRecordService.upsertPatrolRecord(formDTO);
userPatrolRecordService.insertPatrolRecord(formDTO);
return new Result();
}
}

18
epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/mq/listener/OpenDataPatrolChangeEventListener.java

@ -9,6 +9,7 @@ import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.redis.RedisKeys;
import com.epmet.commons.tools.redis.RedisUtils;
import com.epmet.commons.tools.utils.SpringContextUtils;
import com.epmet.constant.SystemMessageType;
import com.epmet.opendata.dto.form.UpsertPatrolRecordForm;
import com.epmet.opendata.service.UserPatrolRecordService;
import lombok.extern.slf4j.Slf4j;
@ -76,7 +77,19 @@ public class OpenDataPatrolChangeEventListener implements MessageListenerConcurr
patrolRecordForm.setCustomerId(msgObj.getCustomerId());
patrolRecordForm.setPatrolId(msgObj.getPatrolId());
patrolRecordForm.setActionType(tags);
Boolean aBoolean = SpringContextUtils.getBean(UserPatrolRecordService.class).upsertPatrolRecord(patrolRecordForm);
Boolean aBoolean = false;
switch (tags) {
case SystemMessageType.USER_PATROL_START:
aBoolean = SpringContextUtils.getBean(UserPatrolRecordService.class).insertPatrolRecord(patrolRecordForm);
break;
case SystemMessageType.USER_PATROL_STOP:
aBoolean = SpringContextUtils.getBean(UserPatrolRecordService.class).updatePatrolRecord(patrolRecordForm);
break;
default:
log.error("错误的消息类型:{}", tags);
}
} catch (RenException e) {
// 如果是我们手动抛出的异常,说明在业务可控范围内。目前不需要MQ重试
logger.error("【开放数据事件监听器】-巡查记录信息变更-失败:".concat(ExceptionUtils.getErrorStackTrace(e)));
@ -98,10 +111,9 @@ public class OpenDataPatrolChangeEventListener implements MessageListenerConcurr
}
/**
* @description
*
* @param pendingMsgLabel
* @return
* @description
* @author wxz
* @date 2021.10.14 16:32:32
*/

11
epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/UserPatrolRecordService.java

@ -30,9 +30,16 @@ import com.epmet.opendata.entity.UserPatrolRecordEntity;
public interface UserPatrolRecordService extends BaseService<UserPatrolRecordEntity> {
/**
* desc根据条件更新或者插入巡查记录
* desc根据条件插入巡查记录
* @param patrolRecordForm
* @return
*/
Boolean upsertPatrolRecord(UpsertPatrolRecordForm patrolRecordForm);
Boolean insertPatrolRecord(UpsertPatrolRecordForm patrolRecordForm);
/**
* desc根据条件更新巡查记录及轨迹
* @param patrolRecordForm
* @return
*/
Boolean updatePatrolRecord(UpsertPatrolRecordForm patrolRecordForm);
}

80
epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/UserPatrolRecordServiceImpl.java

@ -18,12 +18,12 @@
package com.epmet.opendata.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.constant.SystemMessageType;
import com.epmet.dto.user.param.MidPatrolFormDTO;
import com.epmet.dto.user.result.MidPatrolDetailResult;
import com.epmet.dto.user.result.MidPatrolRecordResult;
@ -59,48 +59,76 @@ public class UserPatrolRecordServiceImpl extends BaseServiceImpl<UserPatrolRecor
private UserPatrolDetailDao userPatrolDetailDao;
@Override
public Boolean upsertPatrolRecord(UpsertPatrolRecordForm patrolRecordForm) {
log.info("upsertPatrolRecord param:{}",JSON.toJSONString(patrolRecordForm));
public Boolean insertPatrolRecord(UpsertPatrolRecordForm patrolRecordForm) {
log.info("upsertPatrolRecord param:{}", JSON.toJSONString(patrolRecordForm));
ValidatorUtils.validateEntity(patrolRecordForm);
boolean delFlag = false;
MidPatrolFormDTO midPatrolFormDTO = buildParam(patrolRecordForm);
Result<List<MidPatrolRecordResult>> record = dataStatisticalOpenFeignClient.getPatrolRecordList(midPatrolFormDTO);
if (record == null || !record.success()){
if (record == null || !record.success()) {
log.error("获取巡查记录失败,param:{}", JSON.toJSONString(midPatrolFormDTO));
return false;
}
List<MidPatrolRecordResult> data = record.getData();
if (CollectionUtils.isEmpty(data)){
if (CollectionUtils.isEmpty(data)) {
//数据已被删除了
delFlag = true;
//暂时设置error 用于排错
log.error("获取巡查记录返回为空,param:{}", JSON.toJSONString(midPatrolFormDTO));
int effectRow = baseDao.deleteById(patrolRecordForm.getPatrolId());
log.warn("del effectRow:{}",effectRow);
log.warn("del effectRow:{}", effectRow);
return true;
}
MidPatrolRecordResult recordResult = data.get(NumConstant.ZERO);
switch (patrolRecordForm.getActionType()){
case SystemMessageType.USER_PATROL_START:
//insert
baseDao.insert(buildEntity(recordResult));
break;
case SystemMessageType.USER_PATROL_STOP:
//update
baseDao.updateById(buildEntity(recordResult));
Result<List<MidPatrolDetailResult>> detailResult = dataStatisticalOpenFeignClient.getPatrolDetailList(midPatrolFormDTO);
if (detailResult == null || !detailResult.success()){
log.error("获取巡查记录明细失败,param:{}", JSON.toJSONString(midPatrolFormDTO));
return false;
}
UserPatrolDetailEntity detailEntity = buildDetailEntity(recordResult, detailResult);
UserPatrolRecordEntity recordEntity = buildEntity(recordResult);
userPatrolDetailDao.insert(detailEntity);
break;
default:
log.info("======");
//insert
baseDao.insert(recordEntity);
return true;
}
@Override
public Boolean updatePatrolRecord(UpsertPatrolRecordForm patrolRecordForm) {
log.info("updatePatrolRecord param:{}", JSON.toJSONString(patrolRecordForm));
ValidatorUtils.validateEntity(patrolRecordForm);
boolean delFlag = false;
MidPatrolFormDTO midPatrolFormDTO = buildParam(patrolRecordForm);
Result<List<MidPatrolRecordResult>> record = dataStatisticalOpenFeignClient.getPatrolRecordList(midPatrolFormDTO);
if (record == null || !record.success()) {
log.error("获取巡查记录失败,param:{}", JSON.toJSONString(midPatrolFormDTO));
return false;
}
List<MidPatrolRecordResult> data = record.getData();
if (CollectionUtils.isEmpty(data)) {
//数据已被删除了
delFlag = true;
//暂时设置error 用于排错
log.error("获取巡查记录返回为空,param:{}", JSON.toJSONString(midPatrolFormDTO));
int effectRow = baseDao.deleteById(patrolRecordForm.getPatrolId());
log.warn("del effectRow:{}", effectRow);
return true;
}
MidPatrolRecordResult recordResult = data.get(NumConstant.ZERO);
UserPatrolRecordEntity recordEntity = buildEntity(recordResult);
//update
int effectRow = baseDao.updateById(recordEntity);
if (effectRow == 0) {
baseDao.insert(recordEntity);
}
Result<List<MidPatrolDetailResult>> detailResult = dataStatisticalOpenFeignClient.getPatrolDetailList(midPatrolFormDTO);
if (detailResult == null || !detailResult.success()) {
log.error("获取巡查记录明细失败,param:{}", JSON.toJSONString(midPatrolFormDTO));
return false;
}
UserPatrolDetailEntity detailEntity = buildDetailEntity(recordResult, detailResult);
//先删除再新增
LambdaQueryWrapper<UserPatrolDetailEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(UserPatrolDetailEntity::getStaffPatrolRecId, recordEntity.getId());
userPatrolDetailDao.delete(wrapper);
int insert = userPatrolDetailDao.insert(detailEntity);
return true;
}
@ -109,8 +137,8 @@ public class UserPatrolRecordServiceImpl extends BaseServiceImpl<UserPatrolRecor
UserPatrolDetailEntity detailEntity = new UserPatrolDetailEntity();
detailEntity.setCustomerId(recordResult.getCustomerId());
detailEntity.setStaffPatrolRecId(recordResult.getId());
StringBuilder sb =new StringBuilder();
detailResult.getData().forEach(o->{
StringBuilder sb = new StringBuilder();
detailResult.getData().forEach(o -> {
sb.append(o.getLongitude())
.append(StrConstant.COMMA)
.append(o.getLatitude())

Loading…
Cancel
Save