初始化dify调用功能

This commit is contained in:
zhangfan
2024-12-13 10:23:42 +08:00
parent b53fe2c24e
commit 91ef35ae9e
28 changed files with 1129 additions and 7 deletions

View File

@@ -0,0 +1,6 @@
package com.volvo.ai.analytic.center.constant;
public class Constant {
public static final String rabbitMqFormQueue = "Voc-Defeat-Dcc";
}

View File

@@ -0,0 +1,10 @@
package com.volvo.ai.analytic.center.constant;
/**
* 是非
*/
public interface YesOrNoConstants {
int YES = 1;
int NO = 0;
}

View File

@@ -0,0 +1,163 @@
package com.volvo.ai.analytic.center.dto.req;
import java.util.List;
/**
* mq消息体解析对象
*/
public class RabbitMqFormData {
private String formId;
private int sinceType;
private int subSinceType;
private Data data;
// Getters and Setters
public String getFormId() {
return formId;
}
public void setFormId(String formId) {
this.formId = formId;
}
public int getSinceType() {
return sinceType;
}
public void setSinceType(int sinceType) {
this.sinceType = sinceType;
}
public int getSubSinceType() {
return subSinceType;
}
public void setSubSinceType(int subSinceType) {
this.subSinceType = subSinceType;
}
public Data getData() {
return data;
}
public void setData(Data data) {
this.data = data;
}
}
class Data {
private String businessId;
private String vdqwUserId;
private String vdqwCustomerId;
private String defeatTime;
private String approveCode;
private String approveResult;
private String approveOpinion;
private List<CallList> callList;
// Getters and Setters
public String getBusinessId() {
return businessId;
}
public void setBusinessId(String businessId) {
this.businessId = businessId;
}
public String getVdqwUserId() {
return vdqwUserId;
}
public void setVdqwUserId(String vdqwUserId) {
this.vdqwUserId = vdqwUserId;
}
public String getVdqwCustomerId() {
return vdqwCustomerId;
}
public void setVdqwCustomerId(String vdqwCustomerId) {
this.vdqwCustomerId = vdqwCustomerId;
}
public String getDefeatTime() {
return defeatTime;
}
public void setDefeatTime(String defeatTime) {
this.defeatTime = defeatTime;
}
public String getApproveCode() {
return approveCode;
}
public void setApproveCode(String approveCode) {
this.approveCode = approveCode;
}
public String getApproveResult() {
return approveResult;
}
public void setApproveResult(String approveResult) {
this.approveResult = approveResult;
}
public String getApproveOpinion() {
return approveOpinion;
}
public void setApproveOpinion(String approveOpinion) {
this.approveOpinion = approveOpinion;
}
public List<CallList> getCallList() {
return callList;
}
public void setCallList(List<CallList> callList) {
this.callList = callList;
}
}
class CallList {
private String sessionId;
private String sourceId;
private String audioTime;
private int audioBillsec;
// Getters and Setters
public String getSessionId() {
return sessionId;
}
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
public String getSourceId() {
return sourceId;
}
public void setSourceId(String sourceId) {
this.sourceId = sourceId;
}
public String getAudioTime() {
return audioTime;
}
public void setAudioTime(String audioTime) {
this.audioTime = audioTime;
}
public int getAudioBillsec() {
return audioBillsec;
}
public void setAudioBillsec(int audioBillsec) {
this.audioBillsec = audioBillsec;
}
}

View File

@@ -0,0 +1,14 @@
package com.volvo.ai.analytic.center.dto.req;
import com.volvo.ai.analytic.center.entity.DataMaskingRule;
import lombok.Data;
import java.util.List;
@Data
public class RunMaskingRuleInput {
private String oldStr;
private List<DataMaskingRule> dataMaskingRules;
private String opinionId;
}

View File

@@ -0,0 +1,94 @@
package com.volvo.ai.analytic.center.dto.resp;
import java.util.List;
/**
* mq消息体解析对象
*/
public class RabbitMqToData {
private String formId;
private int sinceType;
private int subSinceType;
private Data data;
// Getters and Setters
public String getFormId() {
return formId;
}
public void setFormId(String formId) {
this.formId = formId;
}
public int getSinceType() {
return sinceType;
}
public void setSinceType(int sinceType) {
this.sinceType = sinceType;
}
public int getSubSinceType() {
return subSinceType;
}
public void setSubSinceType(int subSinceType) {
this.subSinceType = subSinceType;
}
public Data getData() {
return data;
}
public void setData(Data data) {
this.data = data;
}
}
class Data {
private String businessId;
private String responseCode;
private String responseMsg;
private String label;
private String describe;
public String getBusinessId() {
return businessId;
}
public void setBusinessId(String businessId) {
this.businessId = businessId;
}
public String getResponseCode() {
return responseCode;
}
public void setResponseCode(String responseCode) {
this.responseCode = responseCode;
}
public String getResponseMsg() {
return responseMsg;
}
public void setResponseMsg(String responseMsg) {
this.responseMsg = responseMsg;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getDescribe() {
return describe;
}
public void setDescribe(String describe) {
this.describe = describe;
}
}

View File

@@ -0,0 +1,121 @@
package com.volvo.ai.analytic.center.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.volvo.common.core.base.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* 数据脱敏规则表
*/
@Data
@Accessors
@EqualsAndHashCode(callSuper = true)
@TableName("tm_datamaskingrule")
public class DataMaskingRule extends BaseEntity {
/**
* 主键
*/
@TableId(type = IdType.AUTO)
private Integer id;
/**
* 删除标识0-未删除1-已删除)
*/
@TableField("is_deleted")
private Integer isDeleted;
/**
* 创建时间
*/
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
/**
* 更新时间
*/
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
/**
* 创建人
*/
@TableField("create_by")
private String createBy;
/**
* 更新人
*/
@TableField("update_by")
private String updateBy;
/**
* 创建sql人
*/
@TableField("create_sqlby")
private String createSqlby;
/**
* 更新sql人
*/
@TableField("update_sqlby")
private String updateSqlby;
/**
* 乐观锁
*/
@TableField("versions")
private Integer versions;
/**
* 脱敏规则名称
*/
@TableField("rule_name")
private String ruleName;
/**
* 规则类型(文本、正则)
*/
@TableField("category_name")
private String categoryName;
/**
* 规则文本(要替换的文本、正则表达式匹配文本)
*/
@TableField("rule_text")
private String ruleText;
/**
* 规则映射值
*/
@TableField("rule_mapping_text")
private String ruleMappingText;
/**
* 优先级
*/
@TableField("rule_priority")
private Integer rulePriority;
/**
* 适用渠道
*/
@TableField("application_channel")
private String applicationChannel;
/**
* 状态(启用、禁用)
*/
@TableField("rule_status")
private Integer ruleStatus;
/**
* 规则备注
*/
@TableField("rule_remarks")
private String ruleRemarks;
}

View File

@@ -0,0 +1,124 @@
package com.volvo.ai.analytic.center.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.volvo.common.core.base.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.util.Date;
@Data
@Accessors
@EqualsAndHashCode(callSuper = true)
@TableName("tt_diffdefeat_approve")
public class DiffdefeatApprove extends BaseEntity {
/**
* 主键
*/
@TableId(type = IdType.AUTO)
private Integer id;
/**
* 删除标识0-未删除1-已删除)
*/
@TableField("is_deleted")
private Integer isDeleted;
/**
* 创建时间
*/
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
/**
* 更新时间
*/
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
/**
* 创建人
*/
@TableField("create_by")
private String createBy;
/**
* 更新人
*/
@TableField("update_by")
private String updateBy;
/**
* 创建sql人
*/
@TableField("create_sqlby")
private String createSqlby;
/**
* 更新sql人
*/
@TableField("update_sqlby")
private String updateSqlby;
/**
* 乐观锁
*/
@TableField("versions")
private Integer versions;
/**
* 请求入参
*/
@TableField("input_str")
private String inputStr;
/**
* 业务Id
*/
@TableField("form_id")
private String formId;
/**
* 商机Id
*/
@TableField("business_id")
private String businessId;
/**
* 业务时间
*/
@TableField("defeat_time")
private Date defeatTime;
/**
* 用户状态
*/
@TableField("user_status")
private String userStatus;
/**
* 真假战败文本信息
*/
@TableField("appointment_result")
private String appointmentResult;
/**
* 审批结果编码
*/
@TableField("approve_code")
private String approveCode;
/**
* 审批结果文本
*/
@TableField("approve_result")
private String approveResult;
/**
* 经理审批意见
*/
@TableField("approve_opinion")
private String approveOpinion;
}

View File

@@ -0,0 +1,126 @@
package com.volvo.ai.analytic.center.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.volvo.common.core.base.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* MQ接收数据表实体类
*/
@Data
@Accessors
@EqualsAndHashCode(callSuper = true)
@TableName("tt_mq_message_record")
public class MqMessageRecord extends BaseEntity {
/**
* 主键
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* 场景类型 1质检分析
*/
@TableField("since_type")
private Integer sinceType;
/**
* 1,新车销售2二手车销售3收车销售4 首定保5延保
*/
@TableField("sub_since_type")
private Integer subSinceType;
/**
* sessionId
*/
@TableField("biz_no")
private String bizNo;
/**
* sourceId
*/
@TableField("sub_biz_no")
private String subBizNo;
/**
* 消息体小于4000直接存消息体大于存Iobs key
*/
@TableField("message_content")
private String messageContent;
/**
* mq消息体Iobs key
*/
@TableField("message_iobs_key")
private String messageIobsKey;
/**
* mq message key
*/
@TableField("message_key")
private String messageKey;
/**
* 批处理重试次数,默认3次
*/
@TableField("retry_count")
private Integer retryCount;
/**
* 最后一次重试时间
*/
@TableField("last_retry_time")
private Date lastRetryTime;
/**
* 响应码
*/
@TableField("resp_code")
private String respCode;
/**
* 错误消息 截取200长度字符
*/
@TableField("resp_content")
private String respContent;
/**
* 任务状态: 0:待分析,1.分析中, 2.分析完成, 3.分析失败
*/
@TableField("task_status")
private Integer taskStatus;
/**
* 删除标识0-未删除1-已删除)
*/
@TableField("is_deleted")
private Integer isDeleted;
/**
* 创建时间
*/
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
/**
* 更新时间
*/
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
/**
* 创建人
*/
@TableField("create_by")
private String createBy;
/**
* 更新人
*/
@TableField("update_by")
private String updateBy;
}

View File

@@ -0,0 +1,51 @@
package com.volvo.ai.analytic.center.enums;
import lombok.Getter;
import lombok.ToString;
import java.util.Objects;
/**
* @author: zhangfan
* @date: 2024/12/12 13:32
* @description:
*/
@Getter
@ToString
public enum BizEnum {
BAD_REQUEST(4000, "参数不合法"),
METHOD_NOT_ALLOWED(4001, "方法不允许"),
MISS_PARAM(4002, "参数缺失"),
QUERY_FAILED(4003, "查询失败"),
;
private Integer code;
private String msg;
BizEnum(Integer code, String msg){
this.code = code;
this.msg = msg;
}
/**
* 通过状态码获取枚举对象
* @param code 状态码
* @return 枚举对象
*/
public static BizEnum getByCode(String code) {
for (BizEnum resultCode : BizEnum.values()) {
if (Objects.equals(resultCode.getCode(),code)) {
return resultCode;
}
}
return null;
}
}

View File

@@ -0,0 +1,60 @@
package com.volvo.ai.analytic.center.exception;
import com.volvo.ai.analytic.center.enums.BizEnum;
import com.volvo.common.core.util.ResultMsg;
public class BizException extends CoreException {
private static final long serialVersionUID = 1L;
private Integer code;
public BizException() {
super();
}
/**
* 自定义异常
*
* @param resultEnum 返回枚举对象
*/
public BizException(BizEnum resultEnum) {
super(resultEnum.getMsg());
this.code = resultEnum.getCode();
}
public BizException(String msg) {
super(msg);
}
public BizException(String msg, Throwable e) {
super(msg, e);
}
public BizException(Integer code, String msg) {
super(msg);
this.code = code;
}
public BizException(Integer code, String msg, Throwable e) {
super(msg, e);
this.code = code;
}
public BizException(ResultMsg result) {
this(result.getCode(), result.getMsg());
}
public BizException(ResultMsg result, Throwable e) {
this(result.getCode(), result.getMsg(), e);
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
}

View File

@@ -0,0 +1,54 @@
package com.volvo.ai.analytic.center.exception;
import com.volvo.common.core.util.ResultMsg;
/**
* @author: zhangfan
* @date: 2024/12/12 13:27
* @description:通用业务异常
*/
public class BusinessException extends CoreException {
private static final long serialVersionUID = 1L;
private Integer code;
public BusinessException() {
super();
}
public BusinessException(String msg) {
super(msg);
}
public BusinessException(String msg, Throwable e) {
super(msg, e);
}
public BusinessException(Integer code, String msg) {
super(msg);
this.code = code;
}
public BusinessException(Integer code, String msg, Throwable e) {
super(msg, e);
this.code = code;
}
public BusinessException(ResultMsg result) {
this(result.getCode(), result.getMsg());
}
public BusinessException(ResultMsg result, Throwable e) {
this(result.getCode(), result.getMsg(), e);
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
}

View File

@@ -0,0 +1,24 @@
package com.volvo.ai.analytic.center.exception;
/**
* @author: zhangfan
* @date: 2024/12/12 13:27
* @description:
*/
public class CoreException extends RuntimeException {
public CoreException() {
}
public CoreException(String message) {
super(message);
}
public CoreException(String message, Throwable cause) {
super(message, cause);
}
public CoreException(Throwable cause) {
super(cause);
}
}

View File

@@ -0,0 +1,17 @@
package com.volvo.ai.analytic.center.feign;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@FeignClient(name = "difyClient", url = "${service.dify.url}")
public interface DiFyFeign {
@PostMapping(value = "v1/workflows/run"
, consumes = MediaType.APPLICATION_JSON_VALUE
, produces = MediaType.APPLICATION_JSON_VALUE)
Object runWorkflows(@RequestHeader(value = "Authorization") String authorization, @RequestBody Map<String, Object> map);
}

View File

@@ -13,10 +13,9 @@
<description>ai project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<java.encoding>UTF-8</java.encoding>
</properties>
<dependencies>
<!--API依赖-->
<dependency>
<groupId>com.volvo.aicenter</groupId>
@@ -30,22 +29,38 @@
</dependency>
<!--注册中心客户端-->
<dependency>
<!--<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
</dependency>-->
<!--配置中心客户端-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
@@ -100,6 +115,11 @@
<artifactId>pagehelper</artifactId>
<version>5.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
</dependencies>
<build>

View File

@@ -1,6 +1,7 @@
package com.volvo.ai.analytic.center;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@@ -12,6 +13,7 @@ import com.volvo.common.feign.annotation.EnableVolvoFeignClients;
@SpringBootApplication(scanBasePackages = {"com.volvo"})
@EnableVolvoFeignClients
@EnableScheduling
@MapperScan({"com.volvo.ai.analytic.center.mapper"})
public class AiAnalyticCenterServiceApplication {
public static void main(String[] args) {

View File

@@ -0,0 +1,9 @@
package com.volvo.ai.analytic.center.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.volvo.ai.analytic.center.entity.DataMaskingRule;
import org.springframework.stereotype.Repository;
@Repository
public interface DataMaskingRuleMapper extends BaseMapper<DataMaskingRule> {
}

View File

@@ -0,0 +1,9 @@
package com.volvo.ai.analytic.center.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.volvo.ai.analytic.center.entity.DiffdefeatApprove;
import org.springframework.stereotype.Repository;
@Repository
public interface DiffdefeatApproveMapper extends BaseMapper<DiffdefeatApprove> {
}

View File

@@ -0,0 +1,9 @@
package com.volvo.ai.analytic.center.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.volvo.ai.analytic.center.entity.MqMessageRecord;
import org.springframework.stereotype.Repository;
@Repository
public interface MqMessageRecordMapper extends BaseMapper<MqMessageRecord> {
}

View File

@@ -0,0 +1,19 @@
package com.volvo.ai.analytic.center.rabbitMq;
import com.volvo.ai.analytic.center.constant.Constant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class MessageListener {
//默认情况下,当使用@RabbitListener注解时消息确认模式通常是自动的AcknowledgeMode.AUTO可以在yaml文件中更改
// 消息一旦被消费者接收并处理完成即方法执行完成就会自动发送ack确认给RabbitMQ。
@RabbitListener(queues = Constant.rabbitMqFormQueue)
public void onMessage(String message) {
log.info("Received message: " + message);
}
}

View File

@@ -0,0 +1,18 @@
package com.volvo.ai.analytic.center.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.volvo.ai.analytic.center.dto.req.RunMaskingRuleInput;
import com.volvo.ai.analytic.center.entity.DataMaskingRule;
import java.util.List;
public interface DataMaskingRuleService extends IService<DataMaskingRule> {
//根据适用渠道applicationChannel获取数据脱敏规则List
List<DataMaskingRule> getDataMaskingRuleListByApplicationChannel(String applicationChannel);
//脱敏规则执行
String runMaskingRule(RunMaskingRuleInput input);
}

View File

@@ -0,0 +1,7 @@
package com.volvo.ai.analytic.center.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.volvo.ai.analytic.center.entity.DiffdefeatApprove;
public interface DiffdefeatApproveService extends IService<DiffdefeatApprove> {
}

View File

@@ -0,0 +1,7 @@
package com.volvo.ai.analytic.center.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.volvo.ai.analytic.center.entity.MqMessageRecord;
public interface MqMessageRecordService extends IService<MqMessageRecord> {
}

View File

@@ -0,0 +1,33 @@
package com.volvo.ai.analytic.center.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.volvo.ai.analytic.center.constant.YesOrNoConstants;
import com.volvo.ai.analytic.center.dto.req.RunMaskingRuleInput;
import com.volvo.ai.analytic.center.entity.DataMaskingRule;
import com.volvo.ai.analytic.center.mapper.DataMaskingRuleMapper;
import com.volvo.ai.analytic.center.service.DataMaskingRuleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
@Slf4j
@Service
public class DataMaskingRuleServiceImpl extends ServiceImpl<DataMaskingRuleMapper, DataMaskingRule> implements DataMaskingRuleService {
@Override
public List<DataMaskingRule> getDataMaskingRuleListByApplicationChannel(String applicationChannel) {
//根据适用渠道applicationChannel获取数据脱敏规则List
log.info("getDataMaskingRuleListByApplicationChannel applicationChannel:{}", applicationChannel);
List<DataMaskingRule> dataMaskingRuleList = this.lambdaQuery()
.eq(DataMaskingRule::getApplicationChannel, applicationChannel)
.eq(DataMaskingRule::getRuleStatus, YesOrNoConstants.YES)
.eq(DataMaskingRule::getIsDeleted, YesOrNoConstants.NO)
.list();
return dataMaskingRuleList;
}
@Override
public String runMaskingRule(RunMaskingRuleInput input) {
return "";
}
}

View File

@@ -0,0 +1,13 @@
package com.volvo.ai.analytic.center.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.volvo.ai.analytic.center.entity.DiffdefeatApprove;
import com.volvo.ai.analytic.center.mapper.DiffdefeatApproveMapper;
import com.volvo.ai.analytic.center.service.DiffdefeatApproveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class DiffdefeatApproveServiceImpl extends ServiceImpl<DiffdefeatApproveMapper, DiffdefeatApprove> implements DiffdefeatApproveService {
}

View File

@@ -0,0 +1,13 @@
package com.volvo.ai.analytic.center.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.volvo.ai.analytic.center.entity.MqMessageRecord;
import com.volvo.ai.analytic.center.mapper.MqMessageRecordMapper;
import com.volvo.ai.analytic.center.service.MqMessageRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class MqMessageRecordServiceImpl extends ServiceImpl<MqMessageRecordMapper, MqMessageRecord> implements MqMessageRecordService {
}

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds">
<!--为了防止进程退出时,内存中的数据丢失,请加上此选项-->
<shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/>
<property resource="bootstrap.yml"/>
<springProperty scope="context" name="appName" source="spring.application.name" defaultValue="app-default-center"/>
<!-- 文件输出格式 -->
<property name="PATTERN"
value="%-12(%d{yyyy-MM-dd HH:mm:ss.SSS}) | [${appName}] | gtraceid: %X{apm-gtraceid} | traceid: %X{apm-traceid} | spanId: %X{apm-spanid} | [%level] | [%thread] %c#%L | %msg%n"/>
<!-- Console output -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoder defaults to ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
<encoder>
<pattern>%red(%d{yyyy-MM-dd HH:mm:ss.SSS}) | [${appName}] | gtraceid: %X{apm-gtraceid} | traceid: %X{apm-traceid} | spanId: %X{apm-spanid} | %-5level | %blue(${PID:-}) --- [%t] %logger{50} %L- %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</configuration>

View File

@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds">
<property resource="bootstrap.yml" />
<springProperty scope="context" name="appName" source="spring.application.name" defaultValue="2c-community-service"/>
<!--统一引入apollo中Logback Appender的参数配置-->
<springProperty scope="context" name="endPoint" source="spring.log-back.endpoint"/>
<springProperty scope="context" name="accessKeyId" source="spring.log-back.accessKeyId"/>
<springProperty scope="context" name="accessKeySecret" source="spring.log-back.accessKeySecret"/>
<springProperty scope="context" name="project" source="spring.log-back.project"/>
<springProperty scope="context" name="logStore" source="spring.log-back.logStore"/>
<!-- 文件输出格式 -->
<property name="PATTERN" value="%-12(%d{yyyy-MM-dd HH:mm:ss.SSS}) [${appName}] [%tid] [%level] [%thread] %c#%L | %msg%n" />
<!-- Console output -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoder defaults to ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
<Pattern>${PATTERN}</Pattern>
</layout>
</encoder>
</appender>
<!--阿里云日志服务配置 测试环境-->
<!--为了防止进程退出时,内存中的数据丢失,请加上此选项-->
<shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/>
<appender name="ALIYUN_DEV" class="com.aliyun.openservices.log.logback.LoghubAppender">
<!--必选项-->
<!-- 账号及网络配置 -->
<endpoint>${endPoint}</endpoint>
<accessKeyId>${accessKeyId}</accessKeyId>
<accessKeySecret>${accessKeySecret}</accessKeySecret>
<!-- sls 项目配置 -->
<project>${project}</project>
<logStore>${logStore}</logStore>
<!--必选项 (end)-->
<!-- 可选项 -->
<topic>${appName}-log</topic>
<!-- 可选项 详见 '参数说明'-->
<totalSizeInBytes>104857600</totalSizeInBytes>
<maxBlockMs>0</maxBlockMs>
<ioThreadCount>8</ioThreadCount>
<batchSizeThresholdInBytes>524288</batchSizeThresholdInBytes>
<batchCountThreshold>4096</batchCountThreshold>
<lingerMs>2000</lingerMs>
<retries>10</retries>
<baseRetryBackoffMs>100</baseRetryBackoffMs>
<maxRetryBackoffMs>50000</maxRetryBackoffMs>
<!-- 可选项 通过配置 encoder 的 pattern 自定义 log 的格式 -->
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
<Pattern>${PATTERN}</Pattern>
</layout>
</encoder>
<!-- 可选项 设置 time 字段呈现的格式 -->
<timeFormat>yyyy-MM-dd'T'HH:mmZ</timeFormat>
<!-- 可选项 设置 time 字段呈现的时区 -->
<timeZone>Asia/Shanghai</timeZone>
</appender>
<root level="INFO">
<appender-ref ref="CONSOLE" />
<appender-ref ref="ALIYUN_DEV" />
</root>
</configuration>

View File

@@ -63,6 +63,10 @@
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<dependencyManagement>