|
@@ -1,16 +1,26 @@
|
|
|
package com.persagy.dc.define.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.persagy.dc.amqp.handler.RabbitMessageSender;
|
|
|
+import com.persagy.dc.basic.constant.DigitalMessageConstant;
|
|
|
+import com.persagy.dc.basic.model.DigitalManageMessage;
|
|
|
import com.persagy.dc.common.constant.ValidEnum;
|
|
|
+import com.persagy.dc.common.model.entity.BaseEntity;
|
|
|
import com.persagy.dc.define.dao.ObjectTypeMapper;
|
|
|
import com.persagy.dc.define.entity.ObjectType;
|
|
|
import com.persagy.dc.define.service.IObjectTypeService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 对象类型 实现类
|
|
@@ -23,6 +33,8 @@ public class ObjectTypeServiceImpl implements IObjectTypeService {
|
|
|
|
|
|
@Resource
|
|
|
private ObjectTypeMapper dao;
|
|
|
+ @Autowired
|
|
|
+ private RabbitMessageSender messageSender;
|
|
|
|
|
|
@Override
|
|
|
public List<ObjectType> queryByCondition(Wrapper<ObjectType> queryWrapper) {
|
|
@@ -35,21 +47,93 @@ public class ObjectTypeServiceImpl implements IObjectTypeService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ObjectType insert(ObjectType vo) {
|
|
|
- dao.insert(vo);
|
|
|
- return vo;
|
|
|
+ public List<ObjectType> insert(List<ObjectType> voList) {
|
|
|
+ if(CollUtil.isEmpty(voList)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ voList.forEach(vo -> {
|
|
|
+ // 新增前消息
|
|
|
+ DigitalManageMessage message = new DigitalManageMessage();
|
|
|
+ message.setOperatorType(DigitalMessageConstant.OPERATE_BEFORE_INSERT);
|
|
|
+ message.setOperatorObj(vo.getClass().getSimpleName());
|
|
|
+ message.setNewObj(vo);
|
|
|
+ sendMessage(message, true);
|
|
|
+ // 新增
|
|
|
+ dao.insert(vo);
|
|
|
+ // 新增后消息
|
|
|
+ message.setOperatorType(DigitalMessageConstant.OPERATE_AFTER_INSERT);
|
|
|
+ sendMessage(message, false);
|
|
|
+ });
|
|
|
+ return voList;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ObjectType update(ObjectType vo) {
|
|
|
- dao.updateById(vo);
|
|
|
- return vo;
|
|
|
+ public List<ObjectType> update(List<ObjectType> voList) {
|
|
|
+ if(CollUtil.isEmpty(voList)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<String> idList = CollUtil.getFieldValues(voList, BaseEntity.PROP_ID, String.class);
|
|
|
+ List<ObjectType> dbList = dao.selectBatchIds(idList);
|
|
|
+ Map<String, ObjectType> dbMap = CollectionUtil.fieldValueMap(dbList, BaseEntity.PROP_ID);
|
|
|
+ voList.forEach(vo -> {
|
|
|
+ // 修改前消息
|
|
|
+ DigitalManageMessage message = new DigitalManageMessage();
|
|
|
+ message.setOperatorType(DigitalMessageConstant.OPERATE_BEFORE_UPDATE);
|
|
|
+ message.setOperatorObj(vo.getClass().getSimpleName());
|
|
|
+ message.setOldObj(MapUtil.get(dbMap, vo.getId(), ObjectType.class));
|
|
|
+ message.setNewObj(vo);
|
|
|
+ sendMessage(message, true);
|
|
|
+ // 修改
|
|
|
+ dao.updateById(vo);
|
|
|
+ // 修改后消息
|
|
|
+ message.setOperatorType(DigitalMessageConstant.OPERATE_AFTER_UPDATE);
|
|
|
+ sendMessage(message, false);
|
|
|
+ });
|
|
|
+ return voList;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void delete(String id) {
|
|
|
- ObjectType vo = dao.selectById(id);
|
|
|
- vo.setValid(ValidEnum.FALSE.getType());
|
|
|
- dao.updateById(vo);
|
|
|
+ public void delete(List<String> idList) {
|
|
|
+ if(CollUtil.isEmpty(idList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<ObjectType> dbList = dao.selectBatchIds(idList);
|
|
|
+ Map<String, ObjectType> dbMap = CollectionUtil.fieldValueMap(dbList, BaseEntity.PROP_ID);
|
|
|
+ idList.forEach(id -> {
|
|
|
+ // 删除前消息
|
|
|
+ DigitalManageMessage message = new DigitalManageMessage();
|
|
|
+ message.setOperatorType(DigitalMessageConstant.OPERATE_BEFORE_DELETE);
|
|
|
+ message.setOperatorObj(ObjectType.class.getSimpleName());
|
|
|
+ message.setNewObj(MapUtil.get(dbMap, id, ObjectType.class));
|
|
|
+ sendMessage(message, true);
|
|
|
+ ObjectType vo = new ObjectType();
|
|
|
+ vo.setId(id);
|
|
|
+ vo.setValid(ValidEnum.FALSE.getType());
|
|
|
+ // 删除
|
|
|
+ dao.updateById(vo);
|
|
|
+ // 删除后消息
|
|
|
+ message.setOperatorType(DigitalMessageConstant.OPERATE_AFTER_DELETE);
|
|
|
+ message.getNewObj().setValid(ValidEnum.FALSE.getType());
|
|
|
+ sendMessage(message, true);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送消息
|
|
|
+ * @param message
|
|
|
+ * @param syncFlag
|
|
|
+ */
|
|
|
+ private void sendMessage(DigitalManageMessage message, boolean syncFlag) {
|
|
|
+ // 同步消息
|
|
|
+ if(syncFlag) {
|
|
|
+ messageSender.sendAndReceive(DigitalMessageConstant.MESSAGE_EXCHANGE,
|
|
|
+ DigitalMessageConstant.MESSAGE_ROUTING,
|
|
|
+ JSONUtil.toJsonStr(message));
|
|
|
+ } else {
|
|
|
+ // 异步消息
|
|
|
+ messageSender.send(DigitalMessageConstant.MESSAGE_EXCHANGE,
|
|
|
+ DigitalMessageConstant.MESSAGE_ROUTING,
|
|
|
+ JSONUtil.toJsonStr(message));
|
|
|
+ }
|
|
|
}
|
|
|
}
|