Jelajahi Sumber

Merge remote-tracking branch 'origin/master'

1811872455@163.com 3 minggu lalu
induk
melakukan
f01e9cd6e3

+ 93 - 0
java/storlead-sasa/storlead-trade/src/main/java/com/storlead/trade/controller/CustomerAiAnalysisController.java

@@ -1,14 +1,25 @@
 package com.storlead.trade.controller;
 
+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.storlead.framework.common.result.Result;
+import com.storlead.trade.dto.CustomerAnalysisResultDTO;
 import com.storlead.trade.dto.CustomerSingleAnalysisRequestDTO;
 import com.storlead.trade.entity.CustomerAnalysisResultEntity;
+import com.storlead.trade.entity.SopEntity;
 import com.storlead.trade.service.CustomerAiAnalysisService;
+import com.storlead.trade.service.CustomerAnalysisResultEntityService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.BeanUtils;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.ObjectUtils;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import java.util.List;
 
 @RestController
 @RequestMapping("/customer/analysis")
@@ -18,6 +29,9 @@ public class CustomerAiAnalysisController {
     @Resource
     private CustomerAiAnalysisService customerAiAnalysisService;
 
+    @Resource
+    private CustomerAnalysisResultEntityService customerAnalysisResultEntityService;
+
     @PostMapping("/single")
     @ApiOperation("单营销: 客户AI分析并保存结果")
     public Result<Object> analyzeSingle(@RequestBody CustomerSingleAnalysisRequestDTO request) {
@@ -29,4 +43,83 @@ public class CustomerAiAnalysisController {
         return Result.ok(result);
     }
 
+    @RequestMapping("/list")
+    @ApiOperation("客户AI分析结果列表")
+    public Result<Object> list(@RequestBody CustomerAnalysisResultDTO dto) {
+        Page<CustomerAnalysisResultEntity> page = new Page<>(dto.getPageIndex(), dto.getPageSize());
+        LambdaQueryWrapper<CustomerAnalysisResultEntity> wrapper = new LambdaQueryWrapper<>();
+        // 按客户ID筛选
+        if (!ObjectUtils.isEmpty(dto.getCustomerId())) {
+            wrapper.eq(CustomerAnalysisResultEntity::getCustomerId, dto.getCustomerId());
+        }
+        // 按分析场景筛选
+        if (!ObjectUtils.isEmpty(dto.getAnalysisScene())) {
+            wrapper.eq(CustomerAnalysisResultEntity::getAnalysisScene, dto.getAnalysisScene());
+        }
+        // 按客户等级筛选
+        if (!ObjectUtils.isEmpty(dto.getCustomerLevel())) {
+            wrapper.eq(CustomerAnalysisResultEntity::getCustomerLevel, dto.getCustomerLevel());
+        }
+        // 按分析状态筛选
+        if (!ObjectUtils.isEmpty(dto.getAnalysisStatus())) {
+            wrapper.eq(CustomerAnalysisResultEntity::getAnalysisStatus, dto.getAnalysisStatus());
+        }
+        // 按优先级筛选
+        if (!ObjectUtils.isEmpty(dto.getPriority())) {
+            wrapper.eq(CustomerAnalysisResultEntity::getPriority, dto.getPriority());
+        }
+        // 按分析时间倒序
+        wrapper.orderByDesc(CustomerAnalysisResultEntity::getAnalysisTime);
+        // 分页查询
+        IPage<CustomerAnalysisResultEntity> iPage = customerAnalysisResultEntityService.page(page, wrapper);
+        return Result.ok(page);
+    }
+
+    @PostMapping(value = "/add")
+    @ApiOperation(value = "客户AI分析结果添加", notes = "客户AI分析结果添加")
+    @Transactional(rollbackFor = Throwable.class)
+    public Result<?> add(@RequestBody CustomerAnalysisResultDTO dto) {
+        CustomerAnalysisResultEntity entity = new CustomerAnalysisResultEntity();
+        BeanUtils.copyProperties(dto, entity);
+        boolean isOk = customerAnalysisResultEntityService.save(entity);
+        if (!isOk) {
+            return Result.error("添加失败");
+        }
+        return Result.ok(entity);
+    }
+
+    @PostMapping(value = "/edit")
+    @ApiOperation(value = "客户AI分析结果修改", notes = "客户AI分析结果修改")
+    @Transactional(rollbackFor = Throwable.class)
+    public Result<?> edit(@RequestBody CustomerAnalysisResultDTO dto) {
+        if (ObjectUtils.isEmpty(dto.getId())) {
+            return Result.error("id不能为空");
+        }
+        CustomerAnalysisResultEntity entity = new CustomerAnalysisResultEntity();
+        BeanUtils.copyProperties(dto, entity);
+        boolean isOk = customerAnalysisResultEntityService.updateById(entity);
+        if (!isOk) {
+            return Result.error("修改失败");
+        }
+        return Result.ok(entity);
+    }
+
+    @PostMapping(value = "/delete")
+    @ApiOperation(value = "客户AI分析结果删除", notes = "客户AI分析结果删除")
+    @Transactional(rollbackFor = Throwable.class)
+    public Result<?> delete(@RequestBody CustomerAnalysisResultDTO dto) {
+        boolean isOk = false;
+        Long id = dto.getId();
+        if (!ObjectUtils.isEmpty(id)) {
+            isOk = customerAnalysisResultEntityService.removeById(id);
+        }
+        List<Long> idList = dto.getIdList();
+        if (!CollectionUtils.isEmpty(idList)) {
+            isOk = customerAnalysisResultEntityService.removeByIds(idList);
+        }
+        if (!isOk) {
+            return Result.error("删除失败");
+        }
+        return Result.ok();
+    }
 }

+ 108 - 0
java/storlead-sasa/storlead-trade/src/main/java/com/storlead/trade/dto/CustomerAnalysisResultDTO.java

@@ -0,0 +1,108 @@
+package com.storlead.trade.dto;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.storlead.framework.mybatis.page.Page;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
+import java.util.List;
+
+@Data
+public class CustomerAnalysisResultDTO extends Page {
+
+    @TableId(type = IdType.AUTO)
+    @ApiModelProperty(value = "主键ID")
+    private Long id;
+
+    @ApiModelProperty(value = "客户ID")
+    @TableField("customer_id")
+    private Long customerId;
+
+    @ApiModelProperty(value = "分析批次号")
+    @TableField("analysis_batch_no")
+    private String analysisBatchNo;
+
+    @ApiModelProperty(value = "分析场景")
+    @TableField("analysis_scene")
+    private String analysisScene;
+
+    @ApiModelProperty(value = "分析状态")
+    @TableField("analysis_status")
+    private Integer analysisStatus;
+
+    @ApiModelProperty(value = "潜力分")
+    @TableField("potential_score")
+    private Double potentialScore;
+
+    @ApiModelProperty(value = "客户等级")
+    @TableField("customer_level")
+    private String customerLevel;
+
+    @ApiModelProperty(value = "置信度")
+    @TableField("confidence")
+    private Double confidence;
+
+    @ApiModelProperty(value = "优先级")
+    @TableField("priority")
+    private Integer priority;
+
+    @ApiModelProperty(value = "核心标签")
+    @TableField("core_tags")
+    private String coreTags;
+
+    @ApiModelProperty(value = "分析摘要")
+    @TableField("reason_summary")
+    private String reasonSummary;
+
+    @ApiModelProperty(value = "建议动作")
+    @TableField("suggested_actions")
+    private String suggestedActions;
+
+    @ApiModelProperty(value = "风险信号")
+    @TableField("risk_signals")
+    private String riskSignals;
+
+    @ApiModelProperty(value = "特征快照")
+    @TableField("feature_snapshot")
+    private String featureSnapshot;
+
+    @ApiModelProperty(value = "模型名称")
+    @TableField("model_name")
+    private String modelName;
+
+    @ApiModelProperty(value = "模型版本")
+    @TableField("model_version")
+    private String modelVersion;
+
+    @ApiModelProperty(value = "提示词版本")
+    @TableField("prompt_version")
+    private String promptVersion;
+
+    @ApiModelProperty(value = "错误码")
+    @TableField("error_code")
+    private String errorCode;
+
+    @ApiModelProperty(value = "错误信息")
+    @TableField("error_message")
+    private String errorMessage;
+
+    @ApiModelProperty(value = "建议下次跟进时间")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @TableField("next_follow_up_at")
+    private Date nextFollowUpAt;
+
+    @ApiModelProperty(value = "分析时间")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @TableField("analysis_time")
+    private Date analysisTime;
+
+    @ApiModelProperty(value = "idList")
+    private List<Long> idList;
+}

+ 1 - 1
java/storlead-sasa/storlead-trade/src/main/java/com/storlead/trade/dto/MarketingCampaignDTO.java

@@ -192,7 +192,7 @@ public class MarketingCampaignDTO extends Page {
     private List<Long> idList;
 
     @ApiModelProperty(value = "关联客户id")
-    private List<Long> customerIdList;
+    private List<Long> customerAnalysisIdList;
 
 
 }

+ 2 - 2
java/storlead-sasa/storlead-trade/src/main/java/com/storlead/trade/entity/CustomerBaseEntity.java

@@ -11,8 +11,8 @@ import lombok.Data;
 public class CustomerBaseEntity extends SysBaseField {
 
     @ApiModelProperty(value = "客户id")
-    @TableField("customer_id")
-    private Long customerId;
+    @TableField("customer_analysis_id")
+    private Long customerAnalysisId;
 
     @ApiModelProperty(value = "营销活动id")
     @TableField("marketing_campaign_id")

+ 22 - 6
java/storlead-sasa/storlead-trade/src/main/java/com/storlead/trade/service/impl/MarketingCampaignEntityServiceImpl.java

@@ -6,9 +6,11 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.storlead.trade.dto.MarketingCampaignDTO;
+import com.storlead.trade.entity.CustomerAnalysisResultEntity;
 import com.storlead.trade.entity.CustomerBaseEntity;
 import com.storlead.trade.entity.MarketingCampaignEntity;
 import com.storlead.trade.mapper.MarketingCampaignEntityMapper;
+import com.storlead.trade.service.CustomerAnalysisResultEntityService;
 import com.storlead.trade.service.CustomerBaseEntityService;
 import com.storlead.trade.service.MarketingCampaignEntityService;
 import com.storlead.trade.vo.MarketingCampaignVO;
@@ -33,6 +35,8 @@ public class MarketingCampaignEntityServiceImpl
 
     @Resource
     private CustomerBaseEntityService customerBaseEntityService;
+    @Resource
+    private CustomerAnalysisResultEntityService customerAnalysisResultEntityService;
     @Override
     public Result<Object> getList(MarketingCampaignDTO marketingCampaignDTO) {
         IPage<MarketingCampaignVO> pageVO = new Page<>(marketingCampaignDTO.getPageIndex(), marketingCampaignDTO.getPageSize());
@@ -47,15 +51,27 @@ public class MarketingCampaignEntityServiceImpl
             return Result.ok(pageVO);
         }
         List<MarketingCampaignVO> marketingCampaignVOList = pageVO.getRecords();
+
         List<Long> marketingCampaignIdList = marketingCampaignVOList.stream().map(MarketingCampaignVO::getId).collect(Collectors.toList());
         LambdaQueryWrapper<CustomerBaseEntity> customerBaseEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
         customerBaseEntityLambdaQueryWrapper.in(CustomerBaseEntity::getMarketingCampaignId, marketingCampaignIdList);
         customerBaseEntityLambdaQueryWrapper.eq(CustomerBaseEntity::getIsDelete, CommonConstant.DEL_FLAG_0);
         List<CustomerBaseEntity> customerBaseEntityList = customerBaseEntityService.list(customerBaseEntityLambdaQueryWrapper);
         //获取全部的关联客户id
-        List<Long> customerIdList = customerBaseEntityList.stream().map(CustomerBaseEntity::getCustomerId).collect(Collectors.toList());
-//        LambdaQueryWrapper<CustomerEntity> customerBaseEntityQueryWrapper = new LambdaQueryWrapper<>();
+        List<Long> customerAnalysisIdList = customerBaseEntityList.stream().map(CustomerBaseEntity::getCustomerAnalysisId).collect(Collectors.toList());
+        LambdaQueryWrapper<CustomerAnalysisResultEntity> customerAnalysisEntityQueryWrapper = new LambdaQueryWrapper<>();
+        customerAnalysisEntityQueryWrapper.eq(CustomerAnalysisResultEntity::getIsDelete, CommonConstant.DEL_FLAG_0);
+        customerAnalysisEntityQueryWrapper.in(CustomerAnalysisResultEntity::getId, customerAnalysisIdList);
+        List<CustomerAnalysisResultEntity> customerAnalysisResultEntityList = customerAnalysisResultEntityService.list(customerAnalysisEntityQueryWrapper);
+        //将customerAnalysisResultEntityList按照customerBaseEntityList对应的id写入pageVO的customerList中
 
+        for (int i = 0; i < marketingCampaignVOList.size(); i++) {
+            int finalI = i;
+            List<CustomerBaseEntity> customerBaseList = customerBaseEntityList.stream().filter(customerBaseEntity -> customerBaseEntity.getCustomerAnalysisId().equals(customerAnalysisResultEntityList.get(finalI).getId())).collect(Collectors.toList());
+            List<Long> customerAnalysisResultIdList = customerBaseList.stream().filter(e -> e.getMarketingCampaignId().equals(marketingCampaignVOList.get(finalI).getId())).map(CustomerBaseEntity::getCustomerAnalysisId).collect(Collectors.toList());
+            List<CustomerAnalysisResultEntity> customerAnalysisResultEntityListI = customerAnalysisResultEntityList.stream().filter(customerAnalysisResultEntity -> customerAnalysisResultIdList.contains(customerAnalysisResultEntity.getId())).collect(Collectors.toList());
+            marketingCampaignVOList.get(i).setCustomerList(customerAnalysisResultEntityListI);
+        }
 
         return Result.ok(pageVO);
     }
@@ -70,12 +86,12 @@ public class MarketingCampaignEntityServiceImpl
             return Result.error("添加失败");
         }
         //添加关联客户
-        List<Long> customerIdList = marketingCampaignDTO.getCustomerIdList();
+        List<Long> customerIdList = marketingCampaignDTO.getCustomerAnalysisIdList();
         if (!CollectionUtils.isEmpty(customerIdList)) {
             List<CustomerBaseEntity> customerBaseEntityList = new ArrayList<>();
             for (Long customerId : customerIdList) {
                 CustomerBaseEntity customerBaseEntity = new CustomerBaseEntity();
-                customerBaseEntity.setCustomerId(customerId);
+                customerBaseEntity.setCustomerAnalysisId(customerId);
                 customerBaseEntity.setMarketingCampaignId(marketingCampaignEntity.getId());
                 customerBaseEntityList.add(customerBaseEntity);
             }
@@ -96,7 +112,7 @@ public class MarketingCampaignEntityServiceImpl
             return Result.error("修改失败");
         }
         //添加关联客户
-        List<Long> customerIdList = marketingCampaignDTO.getCustomerIdList();
+        List<Long> customerIdList = marketingCampaignDTO.getCustomerAnalysisIdList();
         LambdaUpdateWrapper<CustomerBaseEntity> updateWrapper = new LambdaUpdateWrapper<>();
         updateWrapper.eq(CustomerBaseEntity::getMarketingCampaignId, marketingCampaignEntity.getId());
         customerBaseEntityService.remove(updateWrapper);
@@ -104,7 +120,7 @@ public class MarketingCampaignEntityServiceImpl
             List<CustomerBaseEntity> customerBaseEntityList = new ArrayList<>();
             for (Long customerId : customerIdList) {
                 CustomerBaseEntity customerBaseEntity = new CustomerBaseEntity();
-                customerBaseEntity.setCustomerId(customerId);
+                customerBaseEntity.setCustomerAnalysisId(customerId);
                 customerBaseEntity.setMarketingCampaignId(marketingCampaignEntity.getId());
                 customerBaseEntityList.add(customerBaseEntity);
             }

+ 2 - 1
java/storlead-sasa/storlead-trade/src/main/java/com/storlead/trade/vo/MarketingCampaignVO.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.fasterxml.jackson.annotation.JsonFormat;
+import com.storlead.trade.entity.CustomerAnalysisResultEntity;
 import com.storlead.trade.entity.CustomerBaseEntity;
 import com.storlead.framework.mybatis.entity.SysBaseField;
 import io.swagger.annotations.ApiModelProperty;
@@ -191,5 +192,5 @@ public class MarketingCampaignVO extends SysBaseField {
     private List<Long> customerIdList;
 
     @ApiModelProperty(value = "关联客户信息")
-    private List<CustomerBaseEntity> customerList;
+    private List<CustomerAnalysisResultEntity> customerList;
 }