Commit e1bb3615 authored by suhuiguang's avatar suhuiguang

1.编辑功能调整,设备编辑后,通知其他业务进行更新json

parent c9e2db69
package com.yeejoin.amos.boot.module.jg.api.dto;
import com.yeejoin.amos.boot.biz.common.dto.BaseDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import com.yeejoin.amos.boot.biz.common.dto.BaseDto;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
*
*
* @author system_generator
* @date 2025-04-14
*/
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value="JgBizChangeLogDto", description="")
public class JgBizChangeLogDto extends BaseDto {
@ApiModel(value = "JgBizChangeLogDto", description = "")
public class JgBizChangeLogDto extends BaseDto {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "业务唯一标识")
......@@ -36,4 +33,8 @@ public class JgBizChangeLogDto extends BaseDto {
@ApiModelProperty(value = "变更附件")
private String changeAttachment;
@ApiModelProperty(value = "触发的id(列入使用登记变化后,安装告知数据也变化,则记录两条:使用登记的oid为空,按照告知的为使用登记的id)")
private String oId;
}
......@@ -52,4 +52,10 @@ public class JgBizChangeLog extends BaseEntity {
@TableField("change_attachment")
private String changeAttachment;
/**
* 触发的id(列入使用登记变化后,安装告知数据也变化,则记录两条:使用登记的oid为空,按照告知的为使用登记的id)
*/
@TableField("o_id")
private String oId;
}
......@@ -370,6 +370,7 @@
WHERE
n.notice_status =#{noticeStatus}
and n.is_delete=0
and ne.equip_transfer_id = n.sequence_nbr
<if test='records != null'>
and ne.equ_id in
<foreach collection="records" item="record" open="(" close=")" separator=",">
......
......@@ -204,6 +204,7 @@
WHERE
n.status = #{status}
and n.is_delete=0
and ne.equip_transfer_id = n.sequence_nbr
<if test='records != null'>
and ne.equ_id in
<foreach collection="records" item="record" open="(" close=")" separator=",">
......
package com.yeejoin.amos.boot.module.jg.biz.event.handler;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.jg.api.dto.ESDataChangeLogDto;
import com.yeejoin.amos.boot.module.jg.api.entity.JgBizChangeLog;
import com.yeejoin.amos.boot.module.jg.api.entity.JgInstallationNotice;
import com.yeejoin.amos.boot.module.jg.api.service.IJgBizChangeLogService;
import com.yeejoin.amos.boot.module.jg.biz.event.ChangeDataEvent;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.JgBizChangeLogServiceImpl;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.JgInstallationNoticeServiceImpl;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.UseRegisterDataChangeHandleImpl;
import com.yeejoin.amos.boot.module.ymt.api.enums.FlowStatusEnum;
......@@ -10,6 +17,9 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.Set;
@Component
......@@ -19,6 +29,8 @@ public class InstallNoticeUpdateUpdateHandler implements IChangeUpdateHandler<Ch
private final JgInstallationNoticeServiceImpl jgInstallationNoticeService;
private final JgBizChangeLogServiceImpl jgBizChangeLogService;
@Override
@Async
public void handle(ChangeDataEvent event) {
......@@ -29,10 +41,42 @@ public class InstallNoticeUpdateUpdateHandler implements IChangeUpdateHandler<Ch
installationNoticeIds.forEach(seq -> {
// 更新json
JgInstallationNotice installationNotice = jgInstallationNoticeService.getById(seq);
// 查询之前数据json
JSONObject beforeData = jgInstallationNoticeService.getHisData(installationNotice);
jgInstallationNoticeService.saveHisDataBeforeUpdate(installationNotice);
// 查询之后数据json
JSONObject afterData = jgInstallationNoticeService.getHisData(installationNotice);
// es记录日志
this.log2es(beforeData, afterData, installationNotice, event);
});
}
private void log2es(JSONObject beforeData, JSONObject afterData, JgInstallationNotice installationNotice, ChangeDataEvent event) {
Date date = DateUtil.date();
JgBizChangeLog changeLog = new JgBizChangeLog();
BeanUtil.copyProperties(event.getBizRelationData(), changeLog);
changeLog.setBizTable("tzs_jg_installation_notice");
changeLog.setRecDate(date);
changeLog.setBizId(installationNotice.getApplyNo());
// todo 与原始编辑进行关联
changeLog.setOId(event.getRequestContext().getTraceId());
changeLog.setBizType("installationNotice");
changeLog.setRecUserId(event.getRequestContext().getExcutedUserId());
ESDataChangeLogDto changeLogDto = new ESDataChangeLogDto();
changeLogDto.setColumnKey("changeData");
changeLogDto.setColumnKeyLabel("历史json数据");
changeLogDto.setBeforeData(beforeData.toJSONString());
changeLogDto.setAfterData(afterData.toJSONString());
changeLogDto.setUserId(event.getRequestContext().getExcutedUserId());
changeLogDto.setCreateDate(date.getTime());
changeLogDto.setRequestDate(DateUtil.formatDateTime(date));
changeLogDto.setChangeId(installationNotice.getApplyNo());
changeLogDto.setColumnFamily("tzs_jg_installation_notice");
changeLogDto.setBizType(changeLog.getBizType());
changeLogDto.setBatchId(changeLog.getSequenceNbr() + "");
jgBizChangeLogService.save2DbAndEs(changeLog, Collections.singletonList(changeLogDto));
}
private Set<Long> getRelationInstallNoticeList(ChangeDataEvent event) {
// 变化的设备
Set<String> records = event.getBizRelationData().getRecords();
......
package com.yeejoin.amos.boot.module.jg.biz.event.handler;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.jg.api.dto.ESDataChangeLogDto;
import com.yeejoin.amos.boot.module.jg.api.entity.JgBizChangeLog;
import com.yeejoin.amos.boot.module.jg.api.entity.JgInstallationNotice;
import com.yeejoin.amos.boot.module.jg.api.entity.JgMaintenanceContract;
import com.yeejoin.amos.boot.module.jg.biz.event.ChangeDataEvent;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.JgBizChangeLogServiceImpl;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.JgMaintenanceContractServiceImpl;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.UseRegisterDataChangeHandleImpl;
import com.yeejoin.amos.boot.module.ymt.api.enums.FlowStatusEnum;
......@@ -10,6 +19,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.Date;
import java.util.Set;
@Component
......@@ -19,6 +30,8 @@ public class MaintenanceContractUpdateUpdateHandler implements IChangeUpdateHand
private final JgMaintenanceContractServiceImpl jgMaintenanceContractService;
private final JgBizChangeLogServiceImpl jgBizChangeLogService;
@Override
@Async
......@@ -30,7 +43,13 @@ public class MaintenanceContractUpdateUpdateHandler implements IChangeUpdateHand
maintenanceContractList.forEach(seq -> {
// 更新json
JgMaintenanceContract maintenanceContract = jgMaintenanceContractService.getById(seq);
// 查询之前数据json
JSONArray beforeData = jgMaintenanceContractService.getHisData(maintenanceContract);
jgMaintenanceContractService.updateHisDataAfterEquipEdit(maintenanceContract);
// 查询之后数据json
JSONArray afterData = jgMaintenanceContractService.getHisData(maintenanceContract);
// es记录日志
this.log2es(beforeData, afterData, maintenanceContract, event);
});
}
......@@ -45,4 +64,30 @@ public class MaintenanceContractUpdateUpdateHandler implements IChangeUpdateHand
public Boolean supports(ChangeDataEvent event) {
return event.getBizRelationData().getBizType().equals(UseRegisterDataChangeHandleImpl.BIZ_TYPE);
}
private void log2es(JSON beforeData, JSON afterData, JgMaintenanceContract maintenanceContract, ChangeDataEvent event) {
Date date = DateUtil.date();
JgBizChangeLog changeLog = new JgBizChangeLog();
BeanUtil.copyProperties(event.getBizRelationData(), changeLog);
changeLog.setBizTable("tzs_jg_maintenance_contract");
changeLog.setRecDate(date);
changeLog.setBizId(maintenanceContract.getApplyNo());
// todo 与原始编辑进行关联
changeLog.setOId(event.getRequestContext().getTraceId());
changeLog.setBizType("maintenanceContract");
changeLog.setRecUserId(event.getRequestContext().getExcutedUserId());
ESDataChangeLogDto changeLogDto = new ESDataChangeLogDto();
changeLogDto.setColumnKey("changeData");
changeLogDto.setColumnKeyLabel("历史json数据");
changeLogDto.setBeforeData(beforeData.toJSONString());
changeLogDto.setAfterData(afterData.toJSONString());
changeLogDto.setUserId(event.getRequestContext().getExcutedUserId());
changeLogDto.setCreateDate(date.getTime());
changeLogDto.setRequestDate(DateUtil.formatDateTime(date));
changeLogDto.setChangeId(maintenanceContract.getApplyNo());
changeLogDto.setColumnFamily("tzs_jg_maintenance_contract");
changeLogDto.setBizType(changeLog.getBizType());
changeLogDto.setBatchId(changeLog.getSequenceNbr() + "");
jgBizChangeLogService.save2DbAndEs(changeLog, Collections.singletonList(changeLogDto));
}
}
......@@ -118,7 +118,9 @@ public class ChangeLogInsertListener {
changeLog.setBizTable(bizTypeTableMap.get(changeLog.getBizType()));
changeLog.setRecDate(new Date());
changeLog.setRecUserId(event.getRequestContext().getExcutedUserId());
bizChangeLogService.save(changeLog);
// todo 使用上下文这个作为id 便于其他业务和其进行关联
changeLog.setSequenceNbr(Long.parseLong(event.getRequestContext().getTraceId()));
bizChangeLogService.getBaseMapper().insert(changeLog);
return changeLog;
}
}
package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import com.yeejoin.amos.boot.module.jg.api.dto.ESDataChangeLogDto;
import com.yeejoin.amos.boot.module.jg.api.dto.JgBizChangeLogDto;
import com.yeejoin.amos.boot.module.jg.api.entity.JgBizChangeLog;
import com.yeejoin.amos.boot.module.jg.api.mapper.JgBizChangeLogMapper;
import com.yeejoin.amos.boot.module.jg.api.service.IJgBizChangeLogService;
import com.yeejoin.amos.boot.module.jg.api.dto.JgBizChangeLogDto;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import com.yeejoin.amos.boot.module.jg.biz.dao.ESDataChangeLogDao;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import java.util.List;
/**
......@@ -16,18 +19,19 @@ import java.util.List;
* @date 2025-04-14
*/
@Service
public class JgBizChangeLogServiceImpl extends BaseService<JgBizChangeLogDto,JgBizChangeLog,JgBizChangeLogMapper> implements IJgBizChangeLogService {
/**
* 分页查询
*/
public Page<JgBizChangeLogDto> queryForJgBizChangeLogPage(Page<JgBizChangeLogDto> page) {
return this.queryForPage(page, null, false);
}
@RequiredArgsConstructor
public class JgBizChangeLogServiceImpl extends BaseService<JgBizChangeLogDto, JgBizChangeLog, JgBizChangeLogMapper> implements IJgBizChangeLogService {
private final ESDataChangeLogDao esDataChangeLogDao;
/**
* 列表查询 示例
*/
public List<JgBizChangeLogDto> queryForJgBizChangeLogList() {
return this.queryForList("" , false);
public void save2DbAndEs(JgBizChangeLog changeLog, List<ESDataChangeLogDto> esDataChangeLogDtos) {
this.save(changeLog);
esDataChangeLogDtos.forEach(esDataChangeLogDto -> {
esDataChangeLogDto.setBatchId(changeLog.getSequenceNbr() + "");
});
if (!esDataChangeLogDtos.isEmpty()) {
esDataChangeLogDao.saveAll(esDataChangeLogDtos);
}
}
}
\ No newline at end of file
......@@ -1568,6 +1568,10 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
commonService.saveOrUpdateHistory(BusinessTypeEnum.JG_INSTALLATION_NOTIFICATION.getName(), new JSONObject(his), registerInfo.getRecord(), jgInstallationNotice.getSequenceNbr().toString());
}
public JSONObject getHisData(JgInstallationNotice jgInstallationNotice){
return commonService.queryHistoryData(jgInstallationNotice.getSequenceNbr());
}
private String getEquCode(IdxBizJgRegisterInfo registerInfo, String receiveCompanyCode) {
ProduceInfo produceInfo = produceInfoMapper.selectOne(new LambdaQueryWrapper<ProduceInfo>().eq(AbstractEquipBaseEntity::getRecord, registerInfo.getRecord()));
CodeGenerateDto codeGenerateDto = new CodeGenerateDto();
......
......@@ -934,4 +934,9 @@ public class JgMaintenanceContractServiceImpl extends BaseService<JgMaintenanceC
commonService.saveExecuteFlowData2Redis(jgMaintenanceContract.getInstanceId(), this.buildInstanceRuntimeData(jgMaintenanceContract));
}
public JSONArray getHisData(JgMaintenanceContract maintenanceContract){
return commonService.queryHistoryDataObj(maintenanceContract.getSequenceNbr());
}
}
\ No newline at end of file
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