feat(sys): add z_mcp_feedback table and /mcp-feedback APIs for AI Agent issue reporting
This commit is contained in:
parent
541e6d58b4
commit
6edaff97b6
32
deploy/sql/20261120_add_mcp_feedback_table.sql
Normal file
32
deploy/sql/20261120_add_mcp_feedback_table.sql
Normal file
@ -0,0 +1,32 @@
|
||||
-- MCP AI feedback storage table for capturing unmet API/work-order requests reported by Agents.
|
||||
-- Target database: wip (nalinv-mes / iep-app).
|
||||
-- Policy: No foreign keys. Idempotent execution on MySQL 5.7/8.0+.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS wip.z_mcp_feedback (
|
||||
SID VARCHAR(64) NOT NULL COMMENT '主键SID',
|
||||
FEEDBACK_NO VARCHAR(32) NOT NULL COMMENT '反馈单号(MCPFB-yyyyMMdd-XXXXXXXX)',
|
||||
SITE VARCHAR(32) NOT NULL COMMENT '工厂/租户(TENANT-ID)',
|
||||
PROFILE_ID VARCHAR(32) NULL COMMENT '来源环境(tz-prd/hm-prd/tz-dev/hm-dev)',
|
||||
CATEGORY VARCHAR(32) NOT NULL COMMENT '问题分类(API_MISSING/API_ERROR/WORKORDER_UNSUPPORTED/PERMISSION_GAP/DATA_GAP/OTHER)',
|
||||
TITLE VARCHAR(200) NOT NULL COMMENT '问题简述',
|
||||
USER_GOAL TEXT NOT NULL COMMENT '用户原始业务诉求或工单目标',
|
||||
GAP_DETAIL TEXT NULL COMMENT '无法满足的具体原因、报错信息或缺失字段',
|
||||
TRIED_APIS TEXT NULL COMMENT 'Agent已尝试检索的关键词或调用的接口清单',
|
||||
SUGGESTED_SOLUTION TEXT NULL COMMENT '建议补充的接口、字段或工单能力',
|
||||
RELATED_SERVICE VARCHAR(64) NULL COMMENT '涉及微服务(iep-app/iep-qms/nlv-wms/iep-int等)',
|
||||
RELATED_BIZ_NO VARCHAR(128) NULL COMMENT '关联单号(工单号/卷号/异常单号/料号等)',
|
||||
AGENT_CLIENT VARCHAR(64) NULL COMMENT '来源Agent客户端(deepseek-harness/workbuddy/agy等)',
|
||||
MCP_VERSION VARCHAR(32) NULL COMMENT 'nalinv-mcp版本号',
|
||||
STATUS VARCHAR(24) NOT NULL DEFAULT 'OPEN' COMMENT '处理状态(OPEN/IN_PROGRESS/RESOLVED/CLOSED)',
|
||||
HANDLE_REMARK TEXT NULL COMMENT '研发处理备注/解决说明',
|
||||
REPORTER VARCHAR(64) NOT NULL COMMENT '提交人账号(服务端从Token读取)',
|
||||
CREATOR VARCHAR(64) NULL COMMENT '创建人',
|
||||
DATE_CREATE DATETIME NOT NULL COMMENT '创建时间',
|
||||
UPDATER VARCHAR(64) NULL COMMENT '更新人',
|
||||
DATE_UPDATE DATETIME NULL COMMENT '更新时间',
|
||||
PRIMARY KEY (SID),
|
||||
UNIQUE KEY uk_mcp_feedback_no (FEEDBACK_NO),
|
||||
KEY idx_mcp_feedback_site_status_time (SITE, STATUS, DATE_CREATE),
|
||||
KEY idx_mcp_feedback_cat_time (CATEGORY, DATE_CREATE),
|
||||
KEY idx_mcp_feedback_reporter (REPORTER, DATE_CREATE)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='MCP AI问题反馈记录表';
|
||||
@ -0,0 +1,47 @@
|
||||
package com.foreverwin.iep.sys.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@ApiModel(value = "MCP AI问题反馈提交请求")
|
||||
public class McpFeedbackCreateDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "来源环境ID(tz-prd/hm-prd/tz-dev/hm-dev)")
|
||||
private String profileId;
|
||||
|
||||
@ApiModelProperty(value = "问题分类(API_MISSING/API_ERROR/WORKORDER_UNSUPPORTED/PERMISSION_GAP/DATA_GAP/OTHER)", required = true)
|
||||
private String category;
|
||||
|
||||
@ApiModelProperty(value = "问题简述(200字以内)", required = true)
|
||||
private String title;
|
||||
|
||||
@ApiModelProperty(value = "用户的原始业务诉求或工单目标", required = true)
|
||||
private String userGoal;
|
||||
|
||||
@ApiModelProperty(value = "无法满足的具体原因、报错信息或缺失字段")
|
||||
private String gapDetail;
|
||||
|
||||
@ApiModelProperty(value = "Agent已尝试检索的关键词或调用的接口清单")
|
||||
private String triedApis;
|
||||
|
||||
@ApiModelProperty(value = "建议补充的接口、字段或工单能力")
|
||||
private String suggestedSolution;
|
||||
|
||||
@ApiModelProperty(value = "涉及微服务(iep-app/iep-qms/nlv-wms/iep-int等)")
|
||||
private String relatedService;
|
||||
|
||||
@ApiModelProperty(value = "关联单号(工单号/卷号/异常单号/料号等)")
|
||||
private String relatedBizNo;
|
||||
|
||||
@ApiModelProperty(value = "来源Agent客户端(deepseek-harness/workbuddy/agy等)")
|
||||
private String agentClient;
|
||||
|
||||
@ApiModelProperty(value = "nalinv-mcp客户端版本号")
|
||||
private String mcpVersion;
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package com.foreverwin.iep.sys.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@ApiModel(value = "MCP AI问题反馈查询条件")
|
||||
public class McpFeedbackQueryDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "处理状态(OPEN/IN_PROGRESS/RESOLVED/CLOSED)")
|
||||
private String status;
|
||||
|
||||
@ApiModelProperty(value = "问题分类")
|
||||
private String category;
|
||||
|
||||
@ApiModelProperty(value = "涉及微服务")
|
||||
private String relatedService;
|
||||
|
||||
@ApiModelProperty(value = "提交人账号")
|
||||
private String reporter;
|
||||
|
||||
@ApiModelProperty(value = "仅查询本人提交")
|
||||
private Boolean mineOnly;
|
||||
|
||||
@ApiModelProperty(value = "关键词(模糊匹配单号/标题/诉求/原因/关联单号)")
|
||||
private String keyword;
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package com.foreverwin.iep.sys.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@ApiModel(value = "MCP AI问题反馈状态更新请求")
|
||||
public class McpFeedbackStatusDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "目标处理状态(OPEN/IN_PROGRESS/RESOLVED/CLOSED)", required = true)
|
||||
private String status;
|
||||
|
||||
@ApiModelProperty(value = "研发处理备注/解决说明")
|
||||
private String handleRemark;
|
||||
}
|
||||
@ -0,0 +1,78 @@
|
||||
package com.foreverwin.iep.sys.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@TableName("z_mcp_feedback")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel(value = "MCP AI问题反馈记录")
|
||||
public class ZMcpFeedback extends Model<ZMcpFeedback> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(type = IdType.INPUT)
|
||||
@ApiModelProperty(value = "主键SID")
|
||||
private String sid;
|
||||
|
||||
@ApiModelProperty(value = "反馈单号")
|
||||
private String feedbackNo;
|
||||
|
||||
@ApiModelProperty(value = "工厂/租户")
|
||||
private String site;
|
||||
|
||||
@ApiModelProperty(value = "来源环境ID(tz-prd/hm-prd/tz-dev/hm-dev)")
|
||||
private String profileId;
|
||||
|
||||
@ApiModelProperty(value = "问题分类(API_MISSING/API_ERROR/WORKORDER_UNSUPPORTED/PERMISSION_GAP/DATA_GAP/OTHER)")
|
||||
private String category;
|
||||
|
||||
@ApiModelProperty(value = "问题简述")
|
||||
private String title;
|
||||
|
||||
@ApiModelProperty(value = "用户原始业务诉求或工单目标")
|
||||
private String userGoal;
|
||||
|
||||
@ApiModelProperty(value = "无法满足的具体原因、报错信息或缺失字段")
|
||||
private String gapDetail;
|
||||
|
||||
@ApiModelProperty(value = "Agent已尝试检索的关键词或调用的接口清单")
|
||||
private String triedApis;
|
||||
|
||||
@ApiModelProperty(value = "建议补充的接口、字段或工单能力")
|
||||
private String suggestedSolution;
|
||||
|
||||
@ApiModelProperty(value = "涉及微服务(iep-app/iep-qms/nlv-wms/iep-int等)")
|
||||
private String relatedService;
|
||||
|
||||
@ApiModelProperty(value = "关联单号(工单号/卷号/异常单号/料号等)")
|
||||
private String relatedBizNo;
|
||||
|
||||
@ApiModelProperty(value = "来源Agent客户端")
|
||||
private String agentClient;
|
||||
|
||||
@ApiModelProperty(value = "nalinv-mcp版本号")
|
||||
private String mcpVersion;
|
||||
|
||||
@ApiModelProperty(value = "处理状态(OPEN/IN_PROGRESS/RESOLVED/CLOSED)")
|
||||
private String status;
|
||||
|
||||
@ApiModelProperty(value = "研发处理备注")
|
||||
private String handleRemark;
|
||||
|
||||
@ApiModelProperty(value = "提交人账号")
|
||||
private String reporter;
|
||||
|
||||
private String creator;
|
||||
private LocalDateTime dateCreate;
|
||||
private String updater;
|
||||
private LocalDateTime dateUpdate;
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
package com.foreverwin.iep.sys.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.foreverwin.iep.sys.dto.McpFeedbackCreateDTO;
|
||||
import com.foreverwin.iep.sys.dto.McpFeedbackQueryDTO;
|
||||
import com.foreverwin.iep.sys.dto.McpFeedbackStatusDTO;
|
||||
import com.foreverwin.iep.sys.entity.ZMcpFeedback;
|
||||
import com.foreverwin.iep.sys.service.ZMcpFeedbackService;
|
||||
import com.foreverwin.mom.common.core.util.R;
|
||||
import com.foreverwin.mom.common.data.tenant.TenantContextHolder;
|
||||
import com.foreverwin.mom.common.log.annotation.SysLog;
|
||||
import com.foreverwin.mom.common.security.util.SecurityUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/mcp-feedback")
|
||||
@Api(value = "mcp-feedback", tags = "MCP AI问题反馈")
|
||||
public class ZMcpFeedbackController {
|
||||
|
||||
private final ZMcpFeedbackService feedbackService;
|
||||
|
||||
@ApiOperation(value = "提交AI/MCP问题反馈", notes = "当MES接口或工单能力无法满足业务需求时,由AI Agent记录缺口与建议")
|
||||
@SysLog("提交MCP问题反馈")
|
||||
@PostMapping("/submit")
|
||||
public R submit(@RequestBody McpFeedbackCreateDTO dto) {
|
||||
String site = TenantContextHolder.getTenantId();
|
||||
String reporter = SecurityUtils.getUserName();
|
||||
return R.ok(feedbackService.submit(site, reporter, dto));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "分页查询AI/MCP问题反馈", notes = "按当前工厂租户分页查询已提交的AI问题反馈记录")
|
||||
@GetMapping("/page")
|
||||
public R page(Page<ZMcpFeedback> page, McpFeedbackQueryDTO query) {
|
||||
String site = TenantContextHolder.getTenantId();
|
||||
String currentUser = SecurityUtils.getUserName();
|
||||
return R.ok(feedbackService.pageQuery(site, currentUser, page, query));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "查询单条问题反馈详情", notes = "按SID查询当前工厂租户下的问题反馈详情")
|
||||
@GetMapping("/{sid}")
|
||||
public R detail(@PathVariable("sid") String sid) {
|
||||
String site = TenantContextHolder.getTenantId();
|
||||
return R.ok(feedbackService.getDetail(site, sid));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "更新问题反馈处理状态", notes = "研发人员更新反馈处理状态与处理说明")
|
||||
@SysLog("更新MCP问题反馈状态")
|
||||
@PutMapping("/{sid}/status")
|
||||
@PreAuthorize("@pms.hasPermission('mcp_feedback_manage')")
|
||||
public R updateStatus(@PathVariable("sid") String sid, @RequestBody McpFeedbackStatusDTO dto) {
|
||||
String site = TenantContextHolder.getTenantId();
|
||||
String updater = SecurityUtils.getUserName();
|
||||
return R.ok(feedbackService.updateStatus(site, updater, sid, dto));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.foreverwin.iep.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.foreverwin.iep.sys.dto.McpFeedbackCreateDTO;
|
||||
import com.foreverwin.iep.sys.dto.McpFeedbackQueryDTO;
|
||||
import com.foreverwin.iep.sys.dto.McpFeedbackStatusDTO;
|
||||
import com.foreverwin.iep.sys.entity.ZMcpFeedback;
|
||||
|
||||
public interface ZMcpFeedbackService {
|
||||
|
||||
ZMcpFeedback submit(String site, String reporter, McpFeedbackCreateDTO dto);
|
||||
|
||||
IPage<ZMcpFeedback> pageQuery(String site, String currentUser, Page<ZMcpFeedback> page, McpFeedbackQueryDTO query);
|
||||
|
||||
ZMcpFeedback getDetail(String site, String sid);
|
||||
|
||||
ZMcpFeedback updateStatus(String site, String updater, String sid, McpFeedbackStatusDTO dto);
|
||||
}
|
||||
@ -0,0 +1,191 @@
|
||||
package com.foreverwin.iep.sys.service.impl;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.foreverwin.iep.sys.dto.McpFeedbackCreateDTO;
|
||||
import com.foreverwin.iep.sys.dto.McpFeedbackQueryDTO;
|
||||
import com.foreverwin.iep.sys.dto.McpFeedbackStatusDTO;
|
||||
import com.foreverwin.iep.sys.entity.ZMcpFeedback;
|
||||
import com.foreverwin.iep.sys.mapper.ZMcpFeedbackMapper;
|
||||
import com.foreverwin.iep.sys.service.ZMcpFeedbackService;
|
||||
import com.foreverwin.mom.common.core.exception.BusinessException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ZMcpFeedbackServiceImpl implements ZMcpFeedbackService {
|
||||
|
||||
private static final DateTimeFormatter YYYYMMDD = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||
|
||||
public static final Set<String> VALID_CATEGORIES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
|
||||
"API_MISSING",
|
||||
"API_ERROR",
|
||||
"WORKORDER_UNSUPPORTED",
|
||||
"PERMISSION_GAP",
|
||||
"DATA_GAP",
|
||||
"OTHER"
|
||||
)));
|
||||
|
||||
public static final Set<String> VALID_STATUSES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
|
||||
"OPEN",
|
||||
"IN_PROGRESS",
|
||||
"RESOLVED",
|
||||
"CLOSED"
|
||||
)));
|
||||
|
||||
private final ZMcpFeedbackMapper feedbackMapper;
|
||||
|
||||
@Override
|
||||
public ZMcpFeedback submit(String site, String reporter, McpFeedbackCreateDTO dto) {
|
||||
if (dto == null) {
|
||||
throw BusinessException.build("反馈内容不能为空");
|
||||
}
|
||||
String title = trimAndLimit(dto.getTitle(), 200);
|
||||
if (StrUtil.isBlank(title)) {
|
||||
throw BusinessException.build("问题简述(title)不能为空");
|
||||
}
|
||||
String userGoal = trimAndLimit(dto.getUserGoal(), 4000);
|
||||
if (StrUtil.isBlank(userGoal)) {
|
||||
throw BusinessException.build("用户原始业务诉求(userGoal)不能为空");
|
||||
}
|
||||
|
||||
String normalizedCategory = normalizeCategory(dto.getCategory());
|
||||
String effectiveSite = StrUtil.blankToDefault(trimAndLimit(site, 32), "*");
|
||||
String effectiveReporter = StrUtil.blankToDefault(trimAndLimit(reporter, 64), "unknown");
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
String sid = IdUtil.fastSimpleUUID();
|
||||
String feedbackNo = "MCPFB-" + now.format(YYYYMMDD) + "-" + sid.substring(0, 8).toUpperCase(Locale.ROOT);
|
||||
|
||||
ZMcpFeedback entity = new ZMcpFeedback();
|
||||
entity.setSid(sid);
|
||||
entity.setFeedbackNo(feedbackNo);
|
||||
entity.setSite(effectiveSite);
|
||||
entity.setProfileId(trimAndLimit(dto.getProfileId(), 32));
|
||||
entity.setCategory(normalizedCategory);
|
||||
entity.setTitle(title);
|
||||
entity.setUserGoal(userGoal);
|
||||
entity.setGapDetail(trimAndLimit(dto.getGapDetail(), 8000));
|
||||
entity.setTriedApis(trimAndLimit(dto.getTriedApis(), 4000));
|
||||
entity.setSuggestedSolution(trimAndLimit(dto.getSuggestedSolution(), 4000));
|
||||
entity.setRelatedService(trimAndLimit(dto.getRelatedService(), 64));
|
||||
entity.setRelatedBizNo(trimAndLimit(dto.getRelatedBizNo(), 128));
|
||||
entity.setAgentClient(trimAndLimit(dto.getAgentClient(), 64));
|
||||
entity.setMcpVersion(trimAndLimit(dto.getMcpVersion(), 32));
|
||||
entity.setStatus("OPEN");
|
||||
entity.setReporter(effectiveReporter);
|
||||
entity.setCreator(effectiveReporter);
|
||||
entity.setDateCreate(now);
|
||||
entity.setUpdater(effectiveReporter);
|
||||
entity.setDateUpdate(now);
|
||||
|
||||
feedbackMapper.insert(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<ZMcpFeedback> pageQuery(String site, String currentUser, Page<ZMcpFeedback> page, McpFeedbackQueryDTO query) {
|
||||
Page<ZMcpFeedback> effectivePage = page != null ? page : new Page<>(1, 20);
|
||||
if (effectivePage.getSize() > 100) {
|
||||
effectivePage.setSize(100);
|
||||
}
|
||||
LambdaQueryWrapper<ZMcpFeedback> wrapper = Wrappers.<ZMcpFeedback>lambdaQuery();
|
||||
if (StrUtil.isNotBlank(site) && !"*".equals(site.trim())) {
|
||||
wrapper.eq(ZMcpFeedback::getSite, site.trim());
|
||||
}
|
||||
if (query != null) {
|
||||
if (StrUtil.isNotBlank(query.getStatus())) {
|
||||
wrapper.eq(ZMcpFeedback::getStatus, query.getStatus().trim().toUpperCase(Locale.ROOT));
|
||||
}
|
||||
if (StrUtil.isNotBlank(query.getCategory())) {
|
||||
wrapper.eq(ZMcpFeedback::getCategory, query.getCategory().trim().toUpperCase(Locale.ROOT));
|
||||
}
|
||||
if (StrUtil.isNotBlank(query.getRelatedService())) {
|
||||
wrapper.eq(ZMcpFeedback::getRelatedService, query.getRelatedService().trim());
|
||||
}
|
||||
if (Boolean.TRUE.equals(query.getMineOnly()) && StrUtil.isNotBlank(currentUser)) {
|
||||
wrapper.eq(ZMcpFeedback::getReporter, currentUser.trim());
|
||||
} else if (StrUtil.isNotBlank(query.getReporter())) {
|
||||
wrapper.eq(ZMcpFeedback::getReporter, query.getReporter().trim());
|
||||
}
|
||||
if (StrUtil.isNotBlank(query.getKeyword())) {
|
||||
String kw = query.getKeyword().trim();
|
||||
wrapper.and(w -> w.like(ZMcpFeedback::getFeedbackNo, kw)
|
||||
.or().like(ZMcpFeedback::getTitle, kw)
|
||||
.or().like(ZMcpFeedback::getUserGoal, kw)
|
||||
.or().like(ZMcpFeedback::getGapDetail, kw)
|
||||
.or().like(ZMcpFeedback::getRelatedBizNo, kw));
|
||||
}
|
||||
}
|
||||
wrapper.orderByDesc(ZMcpFeedback::getDateCreate);
|
||||
return feedbackMapper.selectPage(effectivePage, wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZMcpFeedback getDetail(String site, String sid) {
|
||||
if (StrUtil.isBlank(sid)) {
|
||||
throw BusinessException.build("反馈SID不能为空");
|
||||
}
|
||||
LambdaQueryWrapper<ZMcpFeedback> wrapper = Wrappers.<ZMcpFeedback>lambdaQuery()
|
||||
.eq(ZMcpFeedback::getSid, sid.trim());
|
||||
if (StrUtil.isNotBlank(site) && !"*".equals(site.trim())) {
|
||||
wrapper.eq(ZMcpFeedback::getSite, site.trim());
|
||||
}
|
||||
ZMcpFeedback record = feedbackMapper.selectOne(wrapper);
|
||||
if (record == null) {
|
||||
throw BusinessException.build("未找到对应的问题反馈记录");
|
||||
}
|
||||
return record;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZMcpFeedback updateStatus(String site, String updater, String sid, McpFeedbackStatusDTO dto) {
|
||||
if (dto == null || StrUtil.isBlank(dto.getStatus())) {
|
||||
throw BusinessException.build("目标状态(status)不能为空");
|
||||
}
|
||||
String normalizedStatus = dto.getStatus().trim().toUpperCase(Locale.ROOT);
|
||||
if (!VALID_STATUSES.contains(normalizedStatus)) {
|
||||
throw BusinessException.build("无效的状态值: " + dto.getStatus() + ",仅支持 OPEN/IN_PROGRESS/RESOLVED/CLOSED");
|
||||
}
|
||||
ZMcpFeedback existing = getDetail(site, sid);
|
||||
existing.setStatus(normalizedStatus);
|
||||
if (dto.getHandleRemark() != null) {
|
||||
existing.setHandleRemark(trimAndLimit(dto.getHandleRemark(), 4000));
|
||||
}
|
||||
existing.setUpdater(StrUtil.blankToDefault(trimAndLimit(updater, 64), "unknown"));
|
||||
existing.setDateUpdate(LocalDateTime.now());
|
||||
feedbackMapper.updateById(existing);
|
||||
return existing;
|
||||
}
|
||||
|
||||
private String normalizeCategory(String category) {
|
||||
if (StrUtil.isBlank(category)) {
|
||||
return "OTHER";
|
||||
}
|
||||
String upper = category.trim().toUpperCase(Locale.ROOT);
|
||||
return VALID_CATEGORIES.contains(upper) ? upper : "OTHER";
|
||||
}
|
||||
|
||||
private String trimAndLimit(String value, int maxLength) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
String trimmed = value.trim();
|
||||
if (trimmed.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return trimmed.length() <= maxLength ? trimmed : trimmed.substring(0, maxLength);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,116 @@
|
||||
package com.foreverwin.iep.sys.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.foreverwin.iep.sys.dto.McpFeedbackCreateDTO;
|
||||
import com.foreverwin.iep.sys.dto.McpFeedbackQueryDTO;
|
||||
import com.foreverwin.iep.sys.dto.McpFeedbackStatusDTO;
|
||||
import com.foreverwin.iep.sys.entity.ZMcpFeedback;
|
||||
import com.foreverwin.iep.sys.mapper.ZMcpFeedbackMapper;
|
||||
import com.foreverwin.mom.common.core.exception.BusinessException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class ZMcpFeedbackServiceImplTest {
|
||||
|
||||
private ZMcpFeedbackMapper feedbackMapper;
|
||||
private ZMcpFeedbackServiceImpl service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
feedbackMapper = mock(ZMcpFeedbackMapper.class);
|
||||
service = new ZMcpFeedbackServiceImpl(feedbackMapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void submitCreatesRecordWithServerIdentityAndNormalizedFields() {
|
||||
McpFeedbackCreateDTO dto = new McpFeedbackCreateDTO();
|
||||
dto.setProfileId("tz-prd");
|
||||
dto.setCategory("workorder_unsupported");
|
||||
dto.setTitle(" 缺少按涂布辊批量查询工单接口 ");
|
||||
dto.setUserGoal("用户想按涂布辊号一次性反查近7天所有关联工单和出站米数");
|
||||
dto.setGapDetail("iep-app 仅有单工单查询,无涂布辊维度的聚合查询接口");
|
||||
dto.setTriedApis("/iep-app/shopOrder/page, /iep-app/operationOut/list");
|
||||
dto.setSuggestedSolution("新增 GET /iep-app/coating/by-roller 接口");
|
||||
dto.setRelatedService("iep-app");
|
||||
dto.setRelatedBizNo("WO-20261120-001");
|
||||
dto.setAgentClient("deepseek-harness");
|
||||
dto.setMcpVersion("1.1.0");
|
||||
|
||||
ZMcpFeedback saved = service.submit("2031", "tangyu", dto);
|
||||
|
||||
ArgumentCaptor<ZMcpFeedback> captor = ArgumentCaptor.forClass(ZMcpFeedback.class);
|
||||
verify(feedbackMapper, times(1)).insert(captor.capture());
|
||||
ZMcpFeedback inserted = captor.getValue();
|
||||
|
||||
assertNotNull(inserted.getSid());
|
||||
assertTrue(inserted.getFeedbackNo().startsWith("MCPFB-"));
|
||||
assertEquals("2031", inserted.getSite());
|
||||
assertEquals("tangyu", inserted.getReporter());
|
||||
assertEquals("tangyu", inserted.getCreator());
|
||||
assertEquals("WORKORDER_UNSUPPORTED", inserted.getCategory());
|
||||
assertEquals("OPEN", inserted.getStatus());
|
||||
assertEquals("缺少按涂布辊批量查询工单接口", inserted.getTitle());
|
||||
assertEquals(inserted.getSid(), saved.getSid());
|
||||
}
|
||||
|
||||
@Test
|
||||
void submitFallsBackToOtherForUnknownCategoryAndRejectsMissingTitle() {
|
||||
McpFeedbackCreateDTO invalid = new McpFeedbackCreateDTO();
|
||||
invalid.setUserGoal("查库存");
|
||||
assertThrows(BusinessException.class, () -> service.submit("2031", "u1", invalid));
|
||||
|
||||
McpFeedbackCreateDTO unknownCat = new McpFeedbackCreateDTO();
|
||||
unknownCat.setCategory("random_cat");
|
||||
unknownCat.setTitle("测试未知分类回退");
|
||||
unknownCat.setUserGoal("测试目标");
|
||||
ZMcpFeedback res = service.submit("3041", "u2", unknownCat);
|
||||
assertEquals("OTHER", res.getCategory());
|
||||
}
|
||||
|
||||
@Test
|
||||
void pageQueryCapsPageSizeAndCallsSelectPage() {
|
||||
Page<ZMcpFeedback> mockResult = new Page<>(1, 100);
|
||||
when(feedbackMapper.selectPage(any(Page.class), any(LambdaQueryWrapper.class))).thenReturn(mockResult);
|
||||
|
||||
Page<ZMcpFeedback> reqPage = new Page<>(1, 500);
|
||||
McpFeedbackQueryDTO query = new McpFeedbackQueryDTO();
|
||||
query.setStatus("open");
|
||||
query.setMineOnly(true);
|
||||
query.setKeyword("涂布");
|
||||
|
||||
IPage<ZMcpFeedback> page = service.pageQuery("2031", "tangyu", reqPage, query);
|
||||
assertSame(mockResult, page);
|
||||
assertEquals(100, reqPage.getSize());
|
||||
verify(feedbackMapper, times(1)).selectPage(eq(reqPage), any(LambdaQueryWrapper.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateStatusValidatesAndUpdatesRecord() {
|
||||
ZMcpFeedback existing = new ZMcpFeedback();
|
||||
existing.setSid("sid-1");
|
||||
existing.setSite("2031");
|
||||
existing.setStatus("OPEN");
|
||||
when(feedbackMapper.selectOne(any(LambdaQueryWrapper.class))).thenReturn(existing);
|
||||
|
||||
McpFeedbackStatusDTO bad = new McpFeedbackStatusDTO();
|
||||
bad.setStatus("INVALID");
|
||||
assertThrows(BusinessException.class, () -> service.updateStatus("2031", "admin", "sid-1", bad));
|
||||
|
||||
McpFeedbackStatusDTO ok = new McpFeedbackStatusDTO();
|
||||
ok.setStatus("resolved");
|
||||
ok.setHandleRemark("已在 2026.11.21 版本新增接口");
|
||||
ZMcpFeedback updated = service.updateStatus("2031", "admin", "sid-1", ok);
|
||||
|
||||
assertEquals("RESOLVED", updated.getStatus());
|
||||
assertEquals("已在 2026.11.21 版本新增接口", updated.getHandleRemark());
|
||||
assertEquals("admin", updated.getUpdater());
|
||||
verify(feedbackMapper, times(1)).updateById(existing);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package com.foreverwin.iep.sys.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.foreverwin.iep.sys.entity.ZMcpFeedback;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface ZMcpFeedbackMapper extends BaseMapper<ZMcpFeedback> {
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user