mirror of
https://github.com/1Panel-dev/CordysCRM.git
synced 2026-05-23 02:49:53 +08:00
refactor: refactor log
This commit is contained in:
@@ -38,7 +38,7 @@ public class MessageTaskController {
|
||||
@Operation(summary = "项目管理-消息管理-消息设置-批量编辑")
|
||||
@RequiresPermissions(PermissionConstants.SYSTEM_NOTICE_UPDATE)
|
||||
public void batchSaveMessage(@Validated({Created.class, Updated.class}) @RequestBody MessageTaskBatchRequest messageTaskBatchRequest) {
|
||||
messageTaskService.batchSaveMessageTask(messageTaskBatchRequest, OrganizationContext.getOrganizationId());
|
||||
messageTaskService.batchSaveMessageTask(messageTaskBatchRequest, OrganizationContext.getOrganizationId(), SessionUtils.getUserId());
|
||||
}
|
||||
|
||||
@GetMapping("get")
|
||||
|
||||
@@ -130,7 +130,7 @@ public class LogService implements OperationLogHandler {
|
||||
|
||||
OperationLogBlob blob = getBlob(log);
|
||||
if (blob.getOriginalValue() != null || blob.getModifiedValue() != null) {
|
||||
operationLogBlobMapper.insert(getBlob(log));
|
||||
operationLogBlobMapper.insert(blob);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package io.cordys.crm.system.service;
|
||||
|
||||
|
||||
import io.cordys.aspectj.annotation.OperationLog;
|
||||
import io.cordys.aspectj.constants.LogModule;
|
||||
import io.cordys.aspectj.constants.LogType;
|
||||
import io.cordys.aspectj.context.OperationLogContext;
|
||||
import io.cordys.aspectj.dto.LogContextInfo;
|
||||
import io.cordys.aspectj.dto.LogDTO;
|
||||
import io.cordys.common.uid.IDGenerator;
|
||||
import io.cordys.common.util.JSON;
|
||||
import io.cordys.common.util.Translator;
|
||||
@@ -29,6 +27,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -43,7 +42,9 @@ public class MessageTaskService {
|
||||
@Resource
|
||||
private BaseMapper<MessageTask> messageTaskMapper;
|
||||
|
||||
@OperationLog(module = LogModule.SYSTEM_MESSAGE_MESSAGE, type = LogType.ADD, operator = "{#userId}")
|
||||
@Resource
|
||||
private LogService logService;
|
||||
|
||||
public MessageTask saveMessageTask(MessageTaskRequest messageTaskRequest, String userId, String organizationId) {
|
||||
//检查设置的通知是否存在,如果存在则更新
|
||||
MessageTask messageTask = new MessageTask();
|
||||
@@ -67,14 +68,12 @@ public class MessageTaskService {
|
||||
messageTask.setTemplate(template.getBytes(StandardCharsets.UTF_8));
|
||||
messageTaskMapper.insert(messageTask);
|
||||
// 添加日志上下文
|
||||
|
||||
MessageTaskLogDTO newDTO = buildLogDTO(messageTask, messageTaskRequest.isEmailEnable(), messageTaskRequest.isSysEnable(), eventMap);
|
||||
OperationLogContext.setContext(LogContextInfo.builder()
|
||||
.originalValue(null)
|
||||
.resourceId(messageTask.getId())
|
||||
.resourceName(eventMap.get(messageTask.getEvent()))
|
||||
.modifiedValue(newDTO)
|
||||
.build());
|
||||
LogDTO logDTO = new LogDTO(organizationId, messageTask.getId(), userId, LogType.UPDATE, LogModule.SYSTEM_MESSAGE_MESSAGE, eventMap.get(messageTask.getEvent()));
|
||||
logDTO.setOriginalValue(null);
|
||||
logDTO.setModifiedValue(newDTO);
|
||||
logService.add(logDTO);
|
||||
|
||||
}
|
||||
return messageTask;
|
||||
}
|
||||
@@ -85,7 +84,6 @@ public class MessageTaskService {
|
||||
* @param messageTaskRequest 入参
|
||||
* @param userId 当前用户ID
|
||||
*/
|
||||
@OperationLog(module = LogModule.SYSTEM_MESSAGE_MESSAGE, type = LogType.UPDATE, operator = "{{#userId}}")
|
||||
public MessageTask updateMessageTasks(MessageTaskRequest messageTaskRequest, String userId, MessageTask oldMessageTask, Map<String, String> eventMap) {
|
||||
MessageTask messageTask = new MessageTask();
|
||||
messageTask.setId(oldMessageTask.getId());
|
||||
@@ -97,12 +95,10 @@ public class MessageTaskService {
|
||||
// 添加日志上下文
|
||||
MessageTaskLogDTO oldDTO = buildLogDTO(oldMessageTask, oldMessageTask.getEmailEnable(), oldMessageTask.getSysEnable(), eventMap);
|
||||
MessageTaskLogDTO newDTO = buildLogDTO(oldMessageTask, messageTaskRequest.isEmailEnable(), messageTaskRequest.isSysEnable(), eventMap);
|
||||
OperationLogContext.setContext(LogContextInfo.builder()
|
||||
.resourceId(messageTask.getId())
|
||||
.resourceName(eventMap.get(oldMessageTask.getEvent()))
|
||||
.originalValue(oldDTO)
|
||||
.modifiedValue(newDTO)
|
||||
.build());
|
||||
LogDTO logDTO = new LogDTO(oldMessageTask.getOrganizationId(), messageTask.getId(), userId, LogType.UPDATE, LogModule.SYSTEM_MESSAGE_MESSAGE, eventMap.get(messageTask.getEvent()));
|
||||
logDTO.setOriginalValue(oldDTO);
|
||||
logDTO.setModifiedValue(newDTO);
|
||||
logService.add(logDTO);
|
||||
|
||||
return messageTask;
|
||||
}
|
||||
@@ -111,8 +107,16 @@ public class MessageTaskService {
|
||||
private static MessageTaskLogDTO buildLogDTO(MessageTask oldMessageTask, Boolean emailEnable, Boolean sysEnable, Map<String, String> eventMap) {
|
||||
MessageTaskLogDTO newDTO = new MessageTaskLogDTO();
|
||||
newDTO.setEvent(eventMap.get(oldMessageTask.getEvent()));
|
||||
newDTO.setEmailEnable(emailEnable ? Translator.get("log.enable.true") : Translator.get("log.enable.false"));
|
||||
newDTO.setSysEnable(sysEnable ? Translator.get("log.enable.true") : Translator.get("log.enable.false"));
|
||||
if (emailEnable != null) {
|
||||
newDTO.setEmailEnable(emailEnable ? Translator.get("log.enable.true") : Translator.get("log.enable.false"));
|
||||
} else {
|
||||
newDTO.setEmailEnable(oldMessageTask.getEmailEnable() ? Translator.get("log.enable.true") : Translator.get("log.enable.false"));
|
||||
}
|
||||
if (sysEnable != null) {
|
||||
newDTO.setSysEnable(sysEnable ? Translator.get("log.enable.true") : Translator.get("log.enable.false"));
|
||||
} else {
|
||||
newDTO.setSysEnable(oldMessageTask.getSysEnable() ? Translator.get("log.enable.true") : Translator.get("log.enable.false"));
|
||||
}
|
||||
return newDTO;
|
||||
}
|
||||
|
||||
@@ -163,7 +167,20 @@ public class MessageTaskService {
|
||||
}
|
||||
|
||||
|
||||
public void batchSaveMessageTask(MessageTaskBatchRequest messageTaskBatchRequest, String organizationId) {
|
||||
public void batchSaveMessageTask(MessageTaskBatchRequest messageTaskBatchRequest, String organizationId, String userId) {
|
||||
List<MessageTask> oldMessageList = extMessageTaskMapper.getMessageTaskList(organizationId);
|
||||
extMessageTaskMapper.updateMessageTask(messageTaskBatchRequest, organizationId);
|
||||
// 添加日志上下文
|
||||
Map<String, String> eventMap = MessageTemplateUtils.getEventMap();
|
||||
List<LogDTO>logDTOList=new ArrayList<>();
|
||||
for (MessageTask messageTask : oldMessageList) {
|
||||
MessageTaskLogDTO oldDTO = buildLogDTO(messageTask, messageTask.getEmailEnable(), messageTask.getSysEnable(), eventMap);
|
||||
MessageTaskLogDTO newDTO = buildLogDTO(messageTask, messageTaskBatchRequest.getEmailEnable(), messageTaskBatchRequest.getSysEnable(), eventMap);
|
||||
LogDTO logDTO = new LogDTO(organizationId, messageTask.getId(), userId, LogType.UPDATE, LogModule.SYSTEM_MESSAGE_MESSAGE, eventMap.get(messageTask.getEvent()));
|
||||
logDTO.setOriginalValue(oldDTO);
|
||||
logDTO.setModifiedValue(newDTO);
|
||||
logDTOList.add(logDTO);
|
||||
}
|
||||
logService.batchAdd(logDTOList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class ModuleLogServiceFactory {
|
||||
logServiceMap.put(LogModule.CUSTOMER_CONTACT, CommonBeanFactory.getBean(CustomerContactLogService.class));
|
||||
logServiceMap.put(LogModule.OPPORTUNITY, CommonBeanFactory.getBean(OpportunityLogService.class));
|
||||
logServiceMap.put(LogModule.SYSTEM_ORGANIZATION, CommonBeanFactory.getBean(OrganizationLogService.class));
|
||||
logServiceMap.put(LogModule.PRODUCT, CommonBeanFactory.getBean(ProductLogService.class));
|
||||
logServiceMap.put(LogModule.PRODUCT_MANAGEMENT, CommonBeanFactory.getBean(ProductLogService.class));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,12 @@ public class ProductLogService extends BaseModuleLogService {
|
||||
private void setProductFieldName(JsonDifferenceDTO differ) {
|
||||
if (StringUtils.equalsIgnoreCase(differ.getOldValue().toString(), "1")){
|
||||
differ.setOldValueName(Translator.get("product.shelves"));
|
||||
}else if (StringUtils.equalsIgnoreCase(differ.getOldValue().toString(), "2")){
|
||||
}else{
|
||||
differ.setOldValueName(Translator.get("product.unShelves"));
|
||||
}
|
||||
if (StringUtils.equalsIgnoreCase(differ.getNewValue().toString(), "1")){
|
||||
differ.setOldValueName(Translator.get("product.shelves"));
|
||||
}else{
|
||||
differ.setOldValueName(Translator.get("product.unShelves"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -101,7 +102,7 @@ public class ProductService {
|
||||
return baseService.setCreateAndUpdateUserName(productGetResponse);
|
||||
}
|
||||
|
||||
@OperationLog(module = LogModule.PRODUCT, type = LogType.ADD, operator = "{#userId}")
|
||||
@OperationLog(module = LogModule.PRODUCT_MANAGEMENT, type = LogType.ADD, operator = "{#userId}")
|
||||
public Product add(ProductEditRequest request, String userId, String orgId) {
|
||||
Product product = BeanUtils.copyBean(new Product(), request);
|
||||
product.setName(request.getName());
|
||||
@@ -134,7 +135,7 @@ public class ProductService {
|
||||
return product;
|
||||
}
|
||||
|
||||
@OperationLog(module = LogModule.PRODUCT, type = LogType.UPDATE, operator = "{#userId}")
|
||||
@OperationLog(module = LogModule.PRODUCT_MANAGEMENT, type = LogType.UPDATE, operator = "{#userId}")
|
||||
public Product update(ProductEditRequest request, String userId, String orgId) {
|
||||
if (StringUtils.isBlank(request.getId())) {
|
||||
throw new GenericException(Translator.get("product.id.empty"));
|
||||
@@ -199,7 +200,7 @@ public class ProductService {
|
||||
productFieldService.saveModuleFieldByResourceIds(productIds, moduleFields);
|
||||
}
|
||||
|
||||
@OperationLog(module = LogModule.PRODUCT, type = LogType.DELETE, resourceId = "{#id}")
|
||||
@OperationLog(module = LogModule.PRODUCT_MANAGEMENT, type = LogType.DELETE, resourceId = "{#id}")
|
||||
public void delete(String id) {
|
||||
Product product = productBaseMapper.selectByPrimaryKey(id);
|
||||
// 删除产品
|
||||
@@ -222,14 +223,20 @@ public class ProductService {
|
||||
product.setOrganizationId(orgId);
|
||||
extProductMapper.updateProduct(request.getIds(),product);
|
||||
batchUpdateModuleField(request.getIds(),request.getModuleFields());
|
||||
List<LogDTO>logDTOList = new ArrayList<>();
|
||||
for (Product oldProduct : products) {
|
||||
LogDTO logDTO = new LogDTO(oldProduct.getOrganizationId(), oldProduct.getId(), userId, LogType.UPDATE, LogModule.PRODUCT, oldProduct.getName());
|
||||
LogDTO logDTO = new LogDTO(oldProduct.getOrganizationId(), oldProduct.getId(), userId, LogType.UPDATE, LogModule.PRODUCT_MANAGEMENT, oldProduct.getName());
|
||||
String oldStatus = getProductStatusName(oldProduct.getStatus());
|
||||
String newStatus = getProductStatusName(request.getStatus());
|
||||
logDTO.setOriginalValue(oldStatus);
|
||||
logDTO.setModifiedValue(newStatus);
|
||||
logService.add(logDTO);
|
||||
Map<String, String> oldMap = new HashMap<>();
|
||||
oldMap.put("status", oldStatus);
|
||||
Map<String, String> newMap = new HashMap<>();
|
||||
newMap.put("status", newStatus);
|
||||
logDTO.setOriginalValue(oldMap);
|
||||
logDTO.setModifiedValue(newMap);
|
||||
logDTOList.add(logDTO);
|
||||
}
|
||||
logService.batchAdd(logDTOList);
|
||||
}
|
||||
|
||||
private String getProductStatusName(String status) {
|
||||
@@ -256,7 +263,7 @@ public class ProductService {
|
||||
productFieldService.deleteByResourceIds(ids);
|
||||
List<LogDTO> logs = new ArrayList<>();
|
||||
products.forEach(product -> {
|
||||
LogDTO logDTO = new LogDTO(product.getOrganizationId(), product.getId(), userId, LogType.DELETE, LogModule.PRODUCT, product.getName());
|
||||
LogDTO logDTO = new LogDTO(product.getOrganizationId(), product.getId(), userId, LogType.DELETE, LogModule.PRODUCT_MANAGEMENT, product.getName());
|
||||
logDTO.setOriginalValue(product.getName());
|
||||
logs.add(logDTO);
|
||||
});
|
||||
|
||||
@@ -374,4 +374,27 @@ log.receiver=Receiver
|
||||
#message
|
||||
log.event=Notification event type
|
||||
log.emailEnable=Email sending switch
|
||||
log.sysEnable=System sending switch
|
||||
log.sysEnable=System sending switch
|
||||
#system log
|
||||
#email
|
||||
log.host=Host
|
||||
log.port=Port
|
||||
log.account=SMTP Account
|
||||
log.password=SMTP Password
|
||||
log.ssl=SSL
|
||||
log.tls=TLS
|
||||
log.from=From
|
||||
log.recipient=Recipient
|
||||
#third
|
||||
log.type=Agent type
|
||||
log.corpId=CorpId
|
||||
log.agentId=AgentId
|
||||
log.appKey=AppKey
|
||||
log.appSecret=AppSecret
|
||||
log.syncEnable=Sync switch
|
||||
log.qrcodeEnable=Scan code login switch
|
||||
log.verify=Verify switch
|
||||
log.redirectUrl=RedirectUrl
|
||||
#product
|
||||
log.price=Product price
|
||||
log.status=Product status
|
||||
@@ -400,6 +400,9 @@ log.syncEnable=同步开关
|
||||
log.qrcodeEnable=扫码登录开关
|
||||
log.verify=验证通过开关
|
||||
log.redirectUrl=回调地址
|
||||
#product
|
||||
log.price=产品价格
|
||||
log.status=产品状态
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ public class LogModule {
|
||||
/**
|
||||
* 产品
|
||||
*/
|
||||
public static final String PRODUCT = "PRODUCT";
|
||||
public static final String PRODUCT_MANAGEMENT = "PRODUCT_MANAGEMENT";
|
||||
|
||||
/**
|
||||
* 客户
|
||||
|
||||
Reference in New Issue
Block a user