feat(ai): 新增AI产品依赖管理功能
- 实现AI产品依赖关系的增删查功能
- 支持通过产品分类筛选前置产品和目标产品
- 添加产品依赖关系验证,防止前置与目标产品重复
- 前端页面集成xmSelect组件实现分类选择
- 后端接口支持按分类查询产品列表及依赖管理
- 页面操作栏新增删除功能,移除原有审核流程
- 优化表格展示字段,显示分类及产品名称信息
- 提供新增依赖关系表单页面及交互逻辑
9 files modified
2 files added
| | |
| | | |
| | | return aiProductService.delete(id); |
| | | } |
| | | |
| | | @PostMapping("listByCategory") |
| | | public FebsResponse listByCategory(@RequestBody @Valid AiProduct dto) { |
| | | String companyId = getCurrentUserCompanyId(); |
| | | String productCategoryId = dto.getProductCategoryId(); |
| | | dto.setCompanyId(companyId); |
| | | dto.setProductCategoryId(productCategoryId); |
| | | return new FebsResponse().success().data(aiProductService.listByCategory(dto)); |
| | | } |
| | | |
| | | |
| | | @PostMapping("pointSet") |
| | |
| | | package cc.mrbird.febs.ai.controller.productDependency; |
| | | |
| | | import cc.mrbird.febs.ai.entity.AiCompanyMemberApply; |
| | | import cc.mrbird.febs.ai.entity.AiProduct; |
| | | import cc.mrbird.febs.ai.entity.AiProductDependency; |
| | | import cc.mrbird.febs.ai.service.AiCompanyMemberApplyService; |
| | | import cc.mrbird.febs.ai.service.AiProductDependencyService; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.validation.Valid; |
| | | import javax.validation.constraints.NotNull; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | return new FebsResponse().success().data(data); |
| | | } |
| | | |
| | | @PostMapping("add") |
| | | @ControllerEndpoint(operation = "新增", exceptionMessage = "操作失败") |
| | | public FebsResponse add(@RequestBody @Valid AiProductDependency dto) { |
| | | |
| | | String companyId = getCurrentUserCompanyId(); |
| | | dto.setCompanyId(companyId); |
| | | return service.add(dto); |
| | | } |
| | | |
| | | @GetMapping("delete/{id}") |
| | | @ControllerEndpoint(operation = "删除", exceptionMessage = "操作失败") |
| | | public FebsResponse delete( |
| | | @NotNull(message = "{required}") @PathVariable String id |
| | | ) { |
| | | |
| | | return service.delete(id); |
| | | } |
| | | |
| | | } |
| | |
| | | /** |
| | | * @author Administrator |
| | | */ |
| | | @Controller("AiCompanyApply") |
| | | @Controller("aiDependency") |
| | | @RequestMapping(FebsConstant.VIEW_PREFIX + "modules/ai/aiDependency") |
| | | @RequiredArgsConstructor |
| | | public class ViewController { |
| | |
| | | return FebsUtil.view("modules/ai/aiDependency/list"); |
| | | } |
| | | |
| | | @GetMapping(value = "/add") |
| | | @RequiresPermissions("aiDependencyList:add") |
| | | public String artAdd() { |
| | | |
| | | return FebsUtil.view("modules/ai/aiDependency/add"); |
| | | } |
| | | |
| | | } |
| | |
| | | package cc.mrbird.febs.ai.entity; |
| | | |
| | | import cc.mrbird.febs.common.entity.AiBaseEntity; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.Data; |
| | | |
| | |
| | | public class AiProductDependency extends AiBaseEntity { |
| | | |
| | | private String companyId; // 公司ID |
| | | |
| | | private String productCategoryId; // AI产品类别ID (UUID) |
| | | @TableField(exist = false) |
| | | private String productCategoryName; |
| | | |
| | | private String prerequisiteProductId; // 前置产品ID |
| | | @TableField(exist = false) |
| | | private String prerequisiteProductName; |
| | | |
| | | private String targetProductId; // 目标产品ID |
| | | @TableField(exist = false) |
| | | private String targetProductName; |
| | | |
| | | private Integer requiredScore; //解锁分数 |
| | | } |
| | |
| | | package cc.mrbird.febs.ai.service; |
| | | |
| | | import cc.mrbird.febs.ai.entity.AiProductDependency; |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.entity.QueryRequest; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | |
| | | */ |
| | | IPage<AiProductDependency> listInPage(AiProductDependency dto, QueryRequest request); |
| | | |
| | | FebsResponse add(AiProductDependency dto); |
| | | |
| | | FebsResponse delete(String id); |
| | | } |
| | |
| | | FebsResponse productRoleSet(AdminMoveChooseInfoDto dto); |
| | | |
| | | FebsResponse productQuestionSet(AdminMoveChooseInfoDto dto); |
| | | |
| | | List<AiProduct> listByCategory(AiProduct dto); |
| | | } |
| | |
| | | package cc.mrbird.febs.ai.service.impl; |
| | | |
| | | import cc.mrbird.febs.ai.entity.AiProduct; |
| | | import cc.mrbird.febs.ai.entity.AiProductCategory; |
| | | import cc.mrbird.febs.ai.entity.AiProductDependency; |
| | | import cc.mrbird.febs.ai.entity.AiProductPoint; |
| | | import cc.mrbird.febs.ai.mapper.AiProductCategoryMapper; |
| | | import cc.mrbird.febs.ai.mapper.AiProductDependencyMapper; |
| | | import cc.mrbird.febs.ai.mapper.AiProductMapper; |
| | | import cc.mrbird.febs.ai.service.AiProductDependencyService; |
| | | import cc.mrbird.febs.ai.util.UUID; |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.entity.QueryRequest; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | 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.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class AiProductDependencyServiceImpl extends ServiceImpl<AiProductDependencyMapper, AiProductDependency> implements AiProductDependencyService { |
| | | |
| | | private final AiProductDependencyMapper aiProductDependencyMapper; |
| | | private final AiProductMapper aiProductMapper; |
| | | private final AiProductCategoryMapper aiProductCategoryMapper; |
| | | |
| | | @Override |
| | | public IPage<AiProductDependency> listInPage(AiProductDependency dto, QueryRequest request) { |
| | | return null; |
| | | |
| | | Page<AiProductDependency> page = new Page<>(request.getPageNum(), request.getPageSize()); |
| | | LambdaQueryWrapper<AiProductDependency> query = Wrappers.lambdaQuery(AiProductDependency.class); |
| | | if (StrUtil.isNotEmpty(dto.getCompanyId())){ |
| | | query.eq(AiProductDependency::getCompanyId, dto.getCompanyId()); |
| | | } |
| | | Page<AiProductDependency> pages = aiProductDependencyMapper.selectPage(page, query); |
| | | List<AiProductDependency> records = pages.getRecords(); |
| | | if (CollUtil.isNotEmpty(records)){ |
| | | //stream获取全部的productId |
| | | Set<String> collectCategoryIdList = records.stream().map(AiProductDependency::getProductCategoryId).collect(Collectors.toSet()); |
| | | List<AiProductCategory> aiProductCategories = aiProductCategoryMapper.selectList( |
| | | Wrappers.lambdaQuery(AiProductCategory.class) |
| | | .select(AiProductCategory::getId, AiProductCategory::getName) |
| | | .in(AiProductCategory::getId, collectCategoryIdList) |
| | | ); |
| | | Map<String, AiProductCategory> aiProductCategoryMap = |
| | | aiProductCategories.stream().collect(Collectors.toMap(AiProductCategory::getId, aiProductCategory -> aiProductCategory)); |
| | | |
| | | Set<String> collectPrerequisiteProductIdList = records.stream().map(AiProductDependency::getPrerequisiteProductId).collect(Collectors.toSet()); |
| | | List<AiProduct> aiProductPoints = aiProductMapper.selectList( |
| | | Wrappers.lambdaQuery(AiProduct.class) |
| | | .select(AiProduct::getId, AiProduct::getName) |
| | | .in(AiProduct::getId, collectPrerequisiteProductIdList) |
| | | ); |
| | | Map<String, AiProduct> aiProductPointMap = |
| | | aiProductPoints.stream().collect(Collectors.toMap(AiProduct::getId, aiProduct -> aiProduct)); |
| | | |
| | | Set<String> collectTargetProductIdList = records.stream().map(AiProductDependency::getTargetProductId).collect(Collectors.toSet()); |
| | | List<AiProduct> aiProductTargets = aiProductMapper.selectList( |
| | | Wrappers.lambdaQuery(AiProduct.class) |
| | | .select(AiProduct::getId, AiProduct::getName) |
| | | .in(AiProduct::getId, collectTargetProductIdList) |
| | | ); |
| | | Map<String, AiProduct> aiProductTargetMap = |
| | | aiProductTargets.stream().collect(Collectors.toMap(AiProduct::getId, aiProduct -> aiProduct)); |
| | | |
| | | for (AiProductDependency record : records){ |
| | | record.setProductCategoryName(aiProductCategoryMap.get(record.getProductCategoryId()).getName()); |
| | | record.setPrerequisiteProductName(aiProductPointMap.get(record.getPrerequisiteProductId()).getName()); |
| | | record.setTargetProductName(aiProductTargetMap.get(record.getTargetProductId()).getName()); |
| | | } |
| | | } |
| | | return pages; |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse add(AiProductDependency dto) { |
| | | dto.setId(UUID.getSimpleUUIDString()); |
| | | dto.setCreatedTime(new Date()); |
| | | aiProductDependencyMapper.insert(dto); |
| | | return new FebsResponse().success(); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse delete(String id) { |
| | | |
| | | AiProductDependency aiProductDependency = aiProductDependencyMapper.selectById(id); |
| | | if (aiProductDependency != null){ |
| | | aiProductDependencyMapper.deleteById(id); |
| | | } |
| | | return new FebsResponse().success(); |
| | | } |
| | | } |
| | |
| | | } |
| | | return new FebsResponse().success().message("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProduct> listByCategory(AiProduct dto) { |
| | | LambdaQueryWrapper<AiProduct> query = Wrappers.lambdaQuery(AiProduct.class); |
| | | if (StrUtil.isNotEmpty(dto.getProductCategoryId())){ |
| | | query.eq(AiProduct::getProductCategoryId, dto.getProductCategoryId()); |
| | | } |
| | | if (StrUtil.isNotEmpty(dto.getCompanyId())){ |
| | | query.eq(AiProduct::getCompanyId, dto.getCompanyId()); |
| | | } |
| | | query.ne(AiProduct::getState, 2); |
| | | query.orderByAsc(AiProduct::getSort); |
| | | return aiProductMapper.selectList(query); |
| | | } |
| | | } |
| New file |
| | |
| | | <div class="layui-fluid layui-anim febs-anim" id="febs-aiDependency-add" lay-title="新增"> |
| | | <div class="layui-row febs-container"> |
| | | <div class="layui-col-md12"> |
| | | <div class="layui-fluid" id="aiDependency-add"> |
| | | <form class="layui-form" action="" lay-filter="aiDependency-add-form"> |
| | | <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief"> |
| | | <ul class="layui-tab-title"> |
| | | <li class="layui-this">基础信息</li> |
| | | </ul> |
| | | <div class="layui-tab-content"> |
| | | <div class="layui-tab-item layui-show"> |
| | | <div class="layui-row layui-col-space10 layui-form-item"> |
| | | <div class="layui-col-lg6"> |
| | | <label class="layui-form-label febs-form-item-require">分类:</label> |
| | | <div class="layui-input-block"> |
| | | <div id="product-category"></div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | <!-- 调试按钮 --> |
| | | <div class="layui-row layui-col-space10 layui-form-item"> |
| | | <div class="layui-col-lg6"> |
| | | <div class="layui-input-block"> |
| | | <button type="button" class="layui-btn layui-btn-primary" id="debug-category">获取选中分类信息</button> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | <div class="layui-row layui-col-space10 layui-form-item"> |
| | | <div class="layui-col-lg6"> |
| | | <label class="layui-form-label febs-form-item-require">前置产品:</label> |
| | | <div class="layui-input-block"> |
| | | <select name="prerequisiteProductId" id="prerequisiteProductId" lay-verify="required" lay-filter="prerequisiteProductId"> |
| | | <option value="">请先选择产品分类</option> |
| | | </select> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | <div class="layui-row layui-col-space10 layui-form-item"> |
| | | <div class="layui-col-lg6"> |
| | | <label class="layui-form-label febs-form-item-require">目标产品:</label> |
| | | <div class="layui-input-block"> |
| | | <select name="targetProductId" id="targetProductId" lay-verify="required" lay-filter="targetProductId" > |
| | | <option value="">请先选择产品分类</option> |
| | | </select> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | <div class="layui-row layui-col-space10 layui-form-item"> |
| | | <div class="layui-col-lg6"> |
| | | <label class="layui-form-label febs-form-item-require">解锁分数:</label> |
| | | <div class="layui-input-block"> |
| | | <input type="number" name="requiredScore" lay-verify="required" min="0" |
| | | placeholder="请输入解锁分数" autocomplete="off" class="layui-input"> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | |
| | | <div class="layui-form-item febs-hide"> |
| | | <button class="layui-btn" lay-submit="" lay-filter="aiDependency-add-form-submit" id="submit">保存</button> |
| | | </div> |
| | | </form> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | |
| | | <!-- 表格操作栏 end --> |
| | | <script data-th-inline="javascript"> |
| | | layui.use(['febs', 'form', 'formSelects', 'validate', 'treeSelect', 'eleTree','dropdown', 'laydate', 'layedit', 'upload', 'element', 'table', 'xmSelect','jquery'], function () { |
| | | var $ = layui.jquery, |
| | | febs = layui.febs, |
| | | layer = layui.layer, |
| | | table = layui.table, |
| | | formSelects = layui.formSelects, |
| | | treeSelect = layui.treeSelect, |
| | | form = layui.form, |
| | | laydate = layui.laydate, |
| | | eleTree = layui.eleTree, |
| | | $view = $('#aiDependency-add'), |
| | | layedit = layui.layedit, |
| | | upload = layui.upload, |
| | | validate = layui.validate, |
| | | element = layui.element; |
| | | |
| | | // 初始化产品分类 - 使用xmSelect组件 |
| | | var category = xmSelect.render({ |
| | | el: '#product-category', |
| | | language: 'zn', |
| | | prop : { |
| | | value : 'id', |
| | | children : 'child' |
| | | }, |
| | | iconfont: { |
| | | parent: 'hidden', |
| | | }, |
| | | tips: '请选择', |
| | | filterable: true, |
| | | radio: true, |
| | | clickClose: true, |
| | | tree: { |
| | | show: true, |
| | | //非严格模式 |
| | | strict: false, |
| | | }, |
| | | data: [], |
| | | on: function(data) { |
| | | console.log('xmSelect内置on事件触发:', data); |
| | | console.log('xmSelect内置on事件触发:', category.getValue('valueStr')); |
| | | handleCategorySelect(data); |
| | | } |
| | | }); |
| | | |
| | | // 加载分类数据 |
| | | febs.get(ctx + 'admin/productCategory/categoryTree', null, function(res) { |
| | | if (res.code === 200 && res.data) { |
| | | category.update({ |
| | | data: res.data, |
| | | autoRow: true, |
| | | }); |
| | | } else { |
| | | febs.alert.error('加载分类数据失败'); |
| | | } |
| | | handleCategorySelect(); |
| | | }); |
| | | |
| | | // 统一的分类选择处理函数 |
| | | function handleCategorySelect(data) { |
| | | try { |
| | | console.log('===== handleCategorySelect函数开始执行 ====='); |
| | | console.log('传入的data参数:', data); |
| | | |
| | | // 方法1:获取完整的选中数据对象 |
| | | var selectedData = category.getValue(); |
| | | console.log('1. 完整选中数据:', selectedData); |
| | | console.log('完整数据类型:', Array.isArray(selectedData) ? '数组' : typeof selectedData); |
| | | |
| | | // 方法2:尝试直接从data参数中获取选中值 |
| | | var dataValue = data && data.arr && data.arr[0] ? data.arr[0].id : null; |
| | | console.log('2. 从data参数获取值:', dataValue); |
| | | |
| | | // 方法3:检查DOM元素是否显示了选中的值 |
| | | var domContent = $('#product-category').value; |
| | | console.log('3. DOM显示的选中内容:', domContent); |
| | | |
| | | // 确定分类ID - 优先从selectedData数组中获取 |
| | | var categoryId = null; |
| | | if (Array.isArray(selectedData) && selectedData.length > 0 && selectedData[0]) { |
| | | // xmSelect通常返回对象数组,每个对象包含value和name属性 |
| | | categoryId = selectedData[0].value; |
| | | console.log('从selectedData数组中提取到分类ID:', categoryId); |
| | | } else if (dataValue) { |
| | | categoryId = dataValue; |
| | | console.log('从data参数中提取到分类ID:', categoryId); |
| | | } |
| | | |
| | | console.log('最终确定的分类ID:', categoryId); |
| | | |
| | | // 清空之前的选项 |
| | | $('#prerequisiteProductId').html('<option value="">请选择前置产品</option>'); |
| | | $('#targetProductId').html('<option value="">请选择目标产品</option>'); |
| | | |
| | | // 只有当categoryId有效时才加载产品列表 |
| | | if (categoryId !== undefined && categoryId !== null && String(categoryId).trim() !== '') { |
| | | console.log('分类ID有效,开始加载产品列表'); |
| | | loadProductList(categoryId); |
| | | } else { |
| | | // 未选择分类时的处理 |
| | | console.log('未选择有效分类ID'); |
| | | $('#prerequisiteProductId').html('<option value="">请先选择分类</option>'); |
| | | $('#targetProductId').html('<option value="">请先选择分类</option>'); |
| | | } |
| | | |
| | | form.render('select'); |
| | | console.log('===== handleCategorySelect函数执行结束 ====='); |
| | | } catch (e) { |
| | | console.error('处理分类选择时出错:', e); |
| | | console.error('错误堆栈:', e.stack); |
| | | } |
| | | } |
| | | |
| | | // 前置产品选择事件 |
| | | form.on('select(prerequisiteProductId)', function(data) { |
| | | validateProductSelection(); |
| | | }); |
| | | |
| | | // 目标产品选择事件 |
| | | form.on('select(targetProductId)', function(data) { |
| | | validateProductSelection(); |
| | | }); |
| | | |
| | | // 验证前置产品和目标产品不能相同 |
| | | function validateProductSelection() { |
| | | var prerequisiteProductId = $('#prerequisiteProductId').val(); |
| | | var targetProductId = $('#targetProductId').val(); |
| | | console.log('===== validateProductSelection函数执行 =====', prerequisiteProductId, targetProductId); |
| | | |
| | | if (prerequisiteProductId && targetProductId && prerequisiteProductId === targetProductId) { |
| | | febs.alert.warn('前置产品和目标产品不能相同'); |
| | | $('#targetProductId').val(''); |
| | | form.render('select'); |
| | | } |
| | | } |
| | | |
| | | // 根据分类加载产品列表 |
| | | function loadProductList(categoryId) { |
| | | console.log('===== 开始加载产品列表 ====='); |
| | | console.log('传入的分类ID:', categoryId); |
| | | console.log('分类ID类型:', typeof categoryId); |
| | | |
| | | // 确保categoryId为字符串类型 |
| | | var safeCategoryId = String(categoryId || '').trim(); |
| | | console.log('处理后的安全分类ID:', safeCategoryId); |
| | | |
| | | // 构建请求数据 |
| | | var requestData = {productCategoryId: safeCategoryId}; |
| | | console.log('发送的请求数据:', requestData); |
| | | |
| | | $.ajax({ |
| | | url: ctx + 'admin/product/listByCategory', |
| | | type: 'post', |
| | | dataType: 'json', |
| | | contentType: 'application/json;charset=utf-8', |
| | | data: JSON.stringify(requestData), |
| | | beforeSend: function(xhr) { |
| | | console.log('准备发送AJAX请求到:', ctx + 'admin/product/listByCategory'); |
| | | console.log('请求头设置为application/json'); |
| | | }, |
| | | success: function(res) { |
| | | console.log('===== 产品列表加载响应 ====='); |
| | | console.log('响应状态:', res ? '有数据' : '空数据'); |
| | | if (res) { |
| | | console.log('响应状态码:', res.code); |
| | | console.log('响应数据:', res.data); |
| | | } |
| | | |
| | | var preProductSelect = $('#prerequisiteProductId'); |
| | | var targetProductSelect = $('#targetProductId'); |
| | | |
| | | // 清空现有选项 |
| | | preProductSelect.html('<option value="">请选择前置产品</option>'); |
| | | targetProductSelect.html('<option value="">请选择目标产品</option>'); |
| | | |
| | | if (res && res.code === 200 && res.data) { |
| | | // 检查数据类型,适配不同的数据结构 |
| | | var products = Array.isArray(res.data) ? res.data : (res.data.records || []); |
| | | |
| | | console.log('处理后产品数据数组:', products); |
| | | console.log('产品数量:', products.length); |
| | | |
| | | if (products.length > 0) { |
| | | console.log('开始构建产品选项...'); |
| | | $.each(products, function(index, item) { |
| | | if (item && item.id !== undefined && item.name !== undefined) { |
| | | console.log('添加产品选项:', item.id, '-', item.name); |
| | | preProductSelect.append('<option value="' + item.id + '">' + item.name + '</option>'); |
| | | targetProductSelect.append('<option value="' + item.id + '">' + item.name + '</option>'); |
| | | } else { |
| | | console.log('跳过无效产品项:', item); |
| | | } |
| | | }); |
| | | console.log('重新渲染选择框'); |
| | | form.render('select'); |
| | | } else { |
| | | console.log('该分类下暂无产品'); |
| | | preProductSelect.html('<option value="">该分类下暂无产品</option>'); |
| | | targetProductSelect.html('<option value="">该分类下暂无产品</option>'); |
| | | } |
| | | } else { |
| | | console.log('接口返回异常或无数据'); |
| | | preProductSelect.html('<option value="">加载失败,请重试</option>'); |
| | | targetProductSelect.html('<option value="">加载失败,请重试</option>'); |
| | | } |
| | | }, |
| | | error: function(xhr, status, error) { |
| | | console.error('===== 加载产品列表失败 ====='); |
| | | console.error('HTTP状态:', xhr.status); |
| | | console.error('状态文本:', status); |
| | | console.error('错误信息:', error); |
| | | console.error('响应文本:', xhr.responseText); |
| | | |
| | | $('#prerequisiteProductId').html('<option value="">加载失败,请重试</option>'); |
| | | $('#targetProductId').html('<option value="">加载失败,请重试</option>'); |
| | | form.render('select'); |
| | | }, |
| | | complete: function() { |
| | | console.log('===== AJAX请求完成 ====='); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | form.on('submit(aiDependency-add-form-submit)', function (data) { |
| | | data.field.productCategoryId = category.getValue('valueStr'); |
| | | $.ajax({ |
| | | 'url':ctx + 'admin/aiDependency/add', |
| | | 'type':'post', |
| | | 'dataType':'json', |
| | | 'headers' : {'Content-Type' : 'application/json;charset=utf-8'}, //接口json格式 |
| | | 'traditional': true,//ajax传递数组必须添加属性 |
| | | 'data':JSON.stringify(data.field), |
| | | 'success':function (data) { |
| | | if(data.code==200){ |
| | | layer.closeAll(); |
| | | febs.alert.success(data.message); |
| | | $('#febs-aiDependency').find('#query').click(); |
| | | }else{ |
| | | febs.alert.warn(data.message); |
| | | } |
| | | }, |
| | | 'error':function () { |
| | | febs.alert.warn('服务器繁忙'); |
| | | } |
| | | }) |
| | | return false; |
| | | }); |
| | | |
| | | }); |
| | | </script> |
| New file |
| | |
| | | <div class="layui-fluid layui-anim febs-anim" id="febs-aiDependency" lay-title="产品升级策略管理"> |
| | | <div class="layui-row febs-container"> |
| | | <div class="layui-col-md12"> |
| | | <div class="layui-card"> |
| | | <div class="layui-card-body febs-table-full"> |
| | | <form class="layui-form layui-table-form" lay-filter="aiDependency-table-form"> |
| | | <div class="layui-row"> |
| | | <div class="layui-col-md10"> |
| | | <div class="layui-form-item"> |
| | | </div> |
| | | </div> |
| | | <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area"> |
| | | <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="query"> |
| | | <i class="layui-icon"></i> |
| | | </div> |
| | | <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action" id="reset"> |
| | | <i class="layui-icon"></i> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </form> |
| | | <table lay-filter="aiDependencyTable" lay-data="{id: 'aiDependencyTable'}"></table> |
| | | |
| | | <style type="text/css"> |
| | | .layui-table-cell{ |
| | | text-align:center; |
| | | height: auto; |
| | | white-space: nowrap; /*文本不会换行,在同一行显示*/ |
| | | overflow: hidden; /*超出隐藏*/ |
| | | text-overflow: ellipsis; /*省略号显示*/ |
| | | } |
| | | .layui-table img{ |
| | | max-width:100px |
| | | } |
| | | ::-webkit-scrollbar { |
| | | height: 20px !important; |
| | | background-color: #f4f4f4; |
| | | } |
| | | </style> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | |
| | | <!--<script type="text/html" id="aiDependencyToolbar">--> |
| | | <!-- <div class="layui-btn-container">--> |
| | | <!-- <button class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain" shiro:hasPermission="companyList:add" lay-event="aiDependencyAdd">新增</button>--> |
| | | <!-- </div>--> |
| | | <!--</script>--> |
| | | |
| | | <script type="text/html" id="aiDependencyOption"> |
| | | {{# if(d.state == 0){ }} |
| | | <button class="layui-btn layui-btn-sm layui-btn-success" type="button" shiro:hasPermission="aiDependencyList:view" lay-event="aiDependencyInfoAgreeEvent">同意</button> |
| | | <button class="layui-btn layui-btn-sm layui-btn-danger" type="button" shiro:hasPermission="aiDependencyList:view" lay-event="aiDependencyInfoDisagreeEvent">拒绝</button> |
| | | {{# } }} |
| | | {{# if(d.state == 1){ }} |
| | | <button class="layui-btn layui-btn-sm layui-btn-warm" type="button" shiro:hasPermission="aiDependencyList:view" lay-event="aiDependencyInfoUnbindEvent">解绑</button> |
| | | {{# } }} |
| | | </script> |
| | | |
| | | |
| | | <style> |
| | | .layui-form-onswitch { |
| | | background-color: #5FB878 !important; |
| | | } |
| | | </style> |
| | | <!-- 表格操作栏 end --> |
| | | <script data-th-inline="none" type="text/javascript"> |
| | | // 引入组件并初始化 |
| | | layui.use([ 'jquery', 'form', 'table', 'febs'], function () { |
| | | var $ = layui.jquery, |
| | | febs = layui.febs, |
| | | form = layui.form, |
| | | table = layui.table, |
| | | $view = $('#febs-aiDependency'), |
| | | $query = $view.find('#query'), |
| | | $reset = $view.find('#reset'), |
| | | $searchForm = $view.find('form'), |
| | | sortObject = {field: 'orderNum', type: null}, |
| | | tableIns; |
| | | |
| | | form.render(); |
| | | |
| | | // 表格初始化 |
| | | initaiDependencyTable(); |
| | | |
| | | // 初始化表格操作栏各个按钮功能 |
| | | table.on('tool(aiDependencyTable)', function (obj) { |
| | | console.log("触发事件:", obj.event); // 调试信息 |
| | | var data = obj.data, |
| | | layEvent = obj.event; |
| | | |
| | | if (layEvent === 'aiDependencyInfoEvent') { |
| | | if (data.state == 1){ |
| | | febs.alert.warn('请先禁用这行数据'); |
| | | return; |
| | | } |
| | | febs.modal.open('编辑','modules/ai/aiDependency/info/' + data.id, { |
| | | btn: ['提交', '取消'], |
| | | area: ['100%', '100%'], |
| | | yes: function (index, layero) { |
| | | $('#febs-aiDependency-Info').find('#submit').trigger('click'); |
| | | }, |
| | | btn2: function () { |
| | | layer.closeAll(); |
| | | } |
| | | }); |
| | | } else if (layEvent === 'aiDependencyInfoAgreeEvent') { |
| | | febs.modal.confirm('删除', '确认删除?', function () { |
| | | memberRoleDeleteEvent(data.id); |
| | | }); |
| | | // 同意操作 |
| | | febs.modal.confirm('审核','确定要同意该申请吗?', function () { |
| | | handleApplyAction(data.id, 'agree'); |
| | | }); |
| | | } else if (layEvent === 'aiDependencyInfoDisagreeEvent') { |
| | | // 拒绝操作 |
| | | febs.modal.confirm('审核','确定要拒绝该申请吗?', function () { |
| | | handleApplyAction(data.id, 'disagree'); |
| | | }); |
| | | } else if (layEvent === 'aiDependencyInfoUnbindEvent') { |
| | | // 解绑操作 |
| | | febs.modal.confirm('审核','确定要解除绑定吗?此操作不可撤销!', function () { |
| | | handleApplyAction(data.id, 'unbind'); |
| | | }); |
| | | } |
| | | |
| | | }); |
| | | |
| | | // 处理申请操作的通用方法 |
| | | function handleApplyAction(id, action) { |
| | | var actionName = { 'agree': '同意', 'disagree': '拒绝', 'unbind': '解绑' }[action]; |
| | | var url = ctx + 'admin/aiDependency/' + action; |
| | | |
| | | $.ajax({ |
| | | url: url, |
| | | type: 'post', |
| | | data: JSON.stringify({id: id}), |
| | | dataType: 'json', |
| | | headers: {'Content-Type': 'application/json;charset=utf-8'}, |
| | | success: function(res) { |
| | | if (res.code === 200) { |
| | | febs.alert.success(actionName + '成功'); |
| | | // 刷新表格数据 |
| | | tableIns.reload({where: getQueryParams(), page: {curr: 1}}); |
| | | } else { |
| | | febs.alert.error(res.msg || actionName + '失败'); |
| | | } |
| | | }, |
| | | error: function() { |
| | | febs.alert.error('服务器错误,请稍后重试'); |
| | | }, |
| | | complete: function() { |
| | | } |
| | | }); |
| | | } |
| | | |
| | | function initaiDependencyTable() { |
| | | tableIns = febs.table.init({ |
| | | elem: $view.find('table'), |
| | | id: 'aiDependencyTable', |
| | | url: ctx + 'admin/aiDependency/list', |
| | | toolbar:"#aiDependencyToolbar", |
| | | defaultToolbar:[], |
| | | cols: [[ |
| | | {type: 'checkbox'}, |
| | | {type: 'numbers', title: '', width: 80}, |
| | | {title: '操作', toolbar: '#aiDependencyOption', minWidth: 200, align: 'center'}, |
| | | {field: 'id', title: 'ID', minWidth: 100,align:'center'}, |
| | | {field: 'productCategoryName', title: '分类', minWidth: 100,align:'center'}, |
| | | {field: 'prerequisiteProductName', title: '前置产品', minWidth: 100,align:'center'}, |
| | | {field: 'targetProductName', title: '目标产品', minWidth: 100,align:'center'}, |
| | | {field: 'requiredScore', title: '解锁分数', minWidth: 100,align:'center'}, |
| | | {field: 'companyName', title: '公司', minWidth: 100,align:'center'}, |
| | | {field: 'createdTime', title: '时间', minWidth: 100,align:'center'}, |
| | | ]] |
| | | }); |
| | | } |
| | | |
| | | |
| | | // 查询按钮 |
| | | $query.on('click', function () { |
| | | var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type}); |
| | | tableIns.reload({where: params, page: {curr: 1}}); |
| | | }); |
| | | |
| | | // 刷新按钮 |
| | | $reset.on('click', function () { |
| | | $searchForm[0].reset(); |
| | | sortObject.type = 'null'; |
| | | tableIns.reload({where: getQueryParams(), page: {curr: 1}, initSort: sortObject}); |
| | | }); |
| | | // 获取查询参数 |
| | | function getQueryParams() { |
| | | return { |
| | | }; |
| | | } |
| | | |
| | | }) |
| | | </script> |
| | |
| | | </div> |
| | | </div> |
| | | |
| | | <!--<script type="text/html" id="aiDependencyToolbar">--> |
| | | <!-- <div class="layui-btn-container">--> |
| | | <!-- <button class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain" shiro:hasPermission="companyList:add" lay-event="aiDependencyAdd">新增</button>--> |
| | | <!-- </div>--> |
| | | <!--</script>--> |
| | | <script type="text/html" id="aiDependencyToolbar"> |
| | | <div class="layui-btn-container"> |
| | | <button class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain" shiro:hasPermission="aiDependencyList:add" lay-event="aiDependencyAdd">新增</button> |
| | | </div> |
| | | </script> |
| | | |
| | | <script type="text/html" id="aiDependencyOption"> |
| | | {{# if(d.state == 0){ }} |
| | | <button class="layui-btn layui-btn-sm layui-btn-success" type="button" shiro:hasPermission="aiDependencyList:view" lay-event="aiDependencyInfoAgreeEvent">同意</button> |
| | | <button class="layui-btn layui-btn-sm layui-btn-danger" type="button" shiro:hasPermission="aiDependencyList:view" lay-event="aiDependencyInfoDisagreeEvent">拒绝</button> |
| | | {{# } }} |
| | | {{# if(d.state == 1){ }} |
| | | <button class="layui-btn layui-btn-sm layui-btn-warm" type="button" shiro:hasPermission="aiDependencyList:view" lay-event="aiDependencyInfoUnbindEvent">解绑</button> |
| | | {{# } }} |
| | | <button class="layui-btn layui-btn-danger layui-btn-sm" type="button" shiro:hasPermission="aiDependencyList:add" lay-event="aiDependencyDeleteEvent">删除</button> |
| | | </script> |
| | | |
| | | |
| | |
| | | layer.closeAll(); |
| | | } |
| | | }); |
| | | } else if (layEvent === 'aiDependencyInfoAgreeEvent') { |
| | | } |
| | | if (layEvent === 'aiDependencyDeleteEvent') { |
| | | febs.modal.confirm('删除', '确认删除?', function () { |
| | | memberRoleDeleteEvent(data.id); |
| | | }); |
| | | // 同意操作 |
| | | febs.modal.confirm('审核','确定要同意该申请吗?', function () { |
| | | handleApplyAction(data.id, 'agree'); |
| | | }); |
| | | } else if (layEvent === 'aiDependencyInfoDisagreeEvent') { |
| | | // 拒绝操作 |
| | | febs.modal.confirm('审核','确定要拒绝该申请吗?', function () { |
| | | handleApplyAction(data.id, 'disagree'); |
| | | }); |
| | | } else if (layEvent === 'aiDependencyInfoUnbindEvent') { |
| | | // 解绑操作 |
| | | febs.modal.confirm('审核','确定要解除绑定吗?此操作不可撤销!', function () { |
| | | handleApplyAction(data.id, 'unbind'); |
| | | aiDependencyDeleteEvent(data.id); |
| | | }); |
| | | } |
| | | |
| | | }); |
| | | |
| | | // 处理申请操作的通用方法 |
| | | function handleApplyAction(id, action) { |
| | | var actionName = { 'agree': '同意', 'disagree': '拒绝', 'unbind': '解绑' }[action]; |
| | | var url = ctx + 'admin/aiDependency/' + action; |
| | | |
| | | $.ajax({ |
| | | url: url, |
| | | type: 'post', |
| | | data: JSON.stringify({id: id}), |
| | | dataType: 'json', |
| | | headers: {'Content-Type': 'application/json;charset=utf-8'}, |
| | | success: function(res) { |
| | | if (res.code === 200) { |
| | | febs.alert.success(actionName + '成功'); |
| | | // 刷新表格数据 |
| | | tableIns.reload({where: getQueryParams(), page: {curr: 1}}); |
| | | } else { |
| | | febs.alert.error(res.msg || actionName + '失败'); |
| | | function aiDependencyDeleteEvent(id) { |
| | | febs.get(ctx + 'admin/aiDependency/delete/' + id, null, function (data) { |
| | | febs.alert.success(data.message); |
| | | $query.click(); |
| | | }); |
| | | } |
| | | |
| | | // 初始化表格操作栏各个按钮功能 |
| | | table.on('toolbar(aiDependencyTable)', function (obj) { |
| | | let data = obj.data, |
| | | layEvent = obj.event; |
| | | if(layEvent === 'aiDependencyAdd'){ |
| | | febs.modal.open('新增', 'modules/ai/aiDependency/add/', { |
| | | btn: ['提交', '取消'], |
| | | area:['100%','100%'], |
| | | yes: function (index, layero) { |
| | | $('#febs-aiDependency-add').find('#submit').trigger('click'); |
| | | }, |
| | | error: function() { |
| | | febs.alert.error('服务器错误,请稍后重试'); |
| | | }, |
| | | complete: function() { |
| | | btn2: function () { |
| | | layer.closeAll(); |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | |
| | | function initaiDependencyTable() { |
| | | tableIns = febs.table.init({ |
| | |
| | | {type: 'numbers', title: '', width: 80}, |
| | | {title: '操作', toolbar: '#aiDependencyOption', minWidth: 200, align: 'center'}, |
| | | {field: 'id', title: 'ID', minWidth: 100,align:'center'}, |
| | | {field: 'name', title: '昵称', minWidth: 100,align:'center'}, |
| | | {field: 'realName', title: '姓名', minWidth: 100,align:'center'}, |
| | | {field: 'companyName', title: '公司', minWidth: 100,align:'center'}, |
| | | {field: 'productCategoryName', title: '分类', minWidth: 100,align:'center'}, |
| | | {field: 'prerequisiteProductName', title: '前置产品', minWidth: 100,align:'center'}, |
| | | {field: 'targetProductName', title: '目标产品', minWidth: 100,align:'center'}, |
| | | {field: 'requiredScore', title: '解锁分数', minWidth: 100,align:'center'}, |
| | | {field: 'createdTime', title: '时间', minWidth: 100,align:'center'}, |
| | | ]] |
| | | }); |