添加话单推送
parent
1f04d9770b
commit
fb22369e3d
@ -0,0 +1,14 @@
|
||||
package com.baiye.constant;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2024/4/30
|
||||
*/
|
||||
public class ImportExcelConstants {
|
||||
|
||||
|
||||
public static final String NAME = "姓名";
|
||||
|
||||
|
||||
public static final String NID = "电话";
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.baiye.listener;
|
||||
|
||||
import com.alibaba.excel.context.AnalysisContext;
|
||||
import com.alibaba.excel.event.AnalysisEventListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2024/4/29
|
||||
*/
|
||||
|
||||
public class ExcelListener extends AnalysisEventListener<Map<Integer, String>> {
|
||||
// Excel数据
|
||||
private List<Map<Integer, Map<Integer, String>>> list;
|
||||
// Excel列名
|
||||
private Map<Integer, String> headTitleMap = new HashMap<>();
|
||||
|
||||
public ExcelListener() {
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(Map<Integer, String> data, AnalysisContext context) {
|
||||
Map<Integer, Map<Integer, String>> map = new HashMap<>();
|
||||
map.put(context.readRowHolder().getRowIndex(), data);
|
||||
list.add(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAfterAllAnalysed(AnalysisContext context) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
|
||||
headTitleMap = headMap;
|
||||
}
|
||||
|
||||
public List<Map<Integer, Map<Integer, String>>> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<Map<Integer, Map<Integer, String>>> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
public Map<Integer, String> getHeadTitleMap() {
|
||||
return headTitleMap;
|
||||
}
|
||||
|
||||
public void setHeadTitleMap(Map<Integer, String> headTitleMap) {
|
||||
this.headTitleMap = headTitleMap;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.baiye.config.properties;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "urls")
|
||||
public class UrlsProperties {
|
||||
|
||||
/**
|
||||
* 大坝推送链接地址
|
||||
*/
|
||||
private String dbPushUrl;
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package com.baiye.modules.platform.domain;
|
||||
|
||||
import com.baiye.model.base.BaseEntity;
|
||||
import com.baiye.util.JpaConverterAes;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2024/4/27
|
||||
*/
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@Entity
|
||||
@Table(name = "tb_traffic_material")
|
||||
@ApiModel(value = "话务材料")
|
||||
public class TrafficMaterial extends BaseEntity implements Serializable {
|
||||
|
||||
|
||||
private static final long serialVersionUID = 8723232289324510063L;
|
||||
|
||||
@Id
|
||||
@ApiModelProperty(value = "id")
|
||||
@Column(name = "id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "姓名")
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "nid")
|
||||
@Column(name = "nid")
|
||||
@Convert(converter = JpaConverterAes.class)
|
||||
private String nid;
|
||||
|
||||
@ApiModelProperty(value = "线索分配人")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty(value = "线索分配人")
|
||||
private Long taskId;
|
||||
|
||||
@ApiModelProperty(value = "其他信息")
|
||||
private String otherInfo;
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.baiye.modules.platform.repository;
|
||||
|
||||
import com.baiye.modules.platform.domain.TrafficMaterial;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date 2024-4-27
|
||||
*/
|
||||
@Repository
|
||||
public interface TrafficMaterialRepository extends JpaRepository<TrafficMaterial, Long>, JpaSpecificationExecutor<TrafficMaterial> {
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package com.baiye.modules.platform.rest;
|
||||
|
||||
import com.baiye.annotation.Inner;
|
||||
import com.baiye.annotation.Log;
|
||||
import com.baiye.constant.DefaultNumberConstants;
|
||||
import com.baiye.http.CommonResponse;
|
||||
import com.baiye.http.ResponseCode;
|
||||
import com.baiye.modules.platform.service.TelephoneTrafficService;
|
||||
import com.baiye.util.SecurityUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2024/4/27
|
||||
* ai话务
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "话务资源推送")
|
||||
@RequestMapping("/api/telephone/traffic")
|
||||
public class TelephoneTrafficController {
|
||||
|
||||
private final TelephoneTrafficService telephoneTrafficService;
|
||||
|
||||
|
||||
@ApiOperation("资源文件上传")
|
||||
@PostMapping("/upload")
|
||||
@Log("资源文件上传")
|
||||
public ResponseEntity<Object> clueFileUpload(@RequestParam("file") MultipartFile[] file,
|
||||
@RequestParam(value = "taskId") Long taskId) {
|
||||
if (file.length > DefaultNumberConstants.ZERO_NUMBER) {
|
||||
return new ResponseEntity<>(telephoneTrafficService.uploadFile(file, taskId), HttpStatus.OK);
|
||||
}
|
||||
return new ResponseEntity<>(CommonResponse.createBySuccess(ResponseCode.EMPTY_ARGUMENT.getDesc()), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("修改授权")
|
||||
@GetMapping("/update")
|
||||
public ResponseEntity<Object> update(Boolean flag, Long taskId) {
|
||||
return new ResponseEntity<>(telephoneTrafficService.updateAuthorizationStatus(flag, taskId), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("获取链接地址")
|
||||
@GetMapping("/url")
|
||||
public ResponseEntity<Object> queryUrl() {
|
||||
return new ResponseEntity<>(telephoneTrafficService.queryUrlByUserId(SecurityUtils.getCurrentUserId()), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@Inner
|
||||
@ApiOperation("获取链接地址")
|
||||
@GetMapping("/detail")
|
||||
public ResponseEntity<Object> detail(@RequestParam Long sourceId) {
|
||||
return new ResponseEntity<>(telephoneTrafficService.queryById(sourceId), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.baiye.modules.platform.service;
|
||||
|
||||
import com.baiye.model.dto.TelephoneTrafficDTO;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2024/4/27
|
||||
*/
|
||||
public interface TelephoneTrafficService {
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param files
|
||||
* @param taskId
|
||||
* @return
|
||||
*/
|
||||
Boolean uploadFile(MultipartFile[] files, Long taskId);
|
||||
|
||||
|
||||
/**
|
||||
* 修改ai任务
|
||||
*
|
||||
* @param flag
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
Boolean updateAuthorizationStatus(Boolean flag, Long id);
|
||||
|
||||
|
||||
/**
|
||||
* 获取请求链接
|
||||
*
|
||||
* @param currentUserId
|
||||
* @return
|
||||
*/
|
||||
String queryUrlByUserId(Long currentUserId);
|
||||
|
||||
/**
|
||||
* id查询详细信息
|
||||
* @param sourceId
|
||||
* @return
|
||||
*/
|
||||
TelephoneTrafficDTO queryById(Long sourceId);
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.baiye.modules.platform.service.dto;
|
||||
|
||||
import cn.hutool.core.annotation.Alias;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2024/3/4
|
||||
*/
|
||||
@Data
|
||||
public class ImportExcelDTO {
|
||||
|
||||
private Long id;
|
||||
|
||||
@Alias("姓名")
|
||||
private String name;
|
||||
|
||||
@Alias("电话")
|
||||
private String nid;
|
||||
|
||||
@Alias("其他信息")
|
||||
private String otherInfo;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ImportExcelDTO dto = (ImportExcelDTO) o;
|
||||
return Objects.equals(name, dto.name) && Objects.equals(nid, dto.nid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, nid);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.baiye.modules.platform.service.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2022/10/21
|
||||
*/
|
||||
@Data
|
||||
public class ZDataDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -3271582444610218303L;
|
||||
|
||||
/**
|
||||
* This field is used for IMEI exchange in the early stage, and OAID can also be exchanged later
|
||||
* Enzo
|
||||
*/
|
||||
@ApiModelProperty(value = "zid")
|
||||
private String zid;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "tag")
|
||||
private String tag;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "time")
|
||||
private String time;
|
||||
|
||||
}
|
@ -0,0 +1,175 @@
|
||||
package com.baiye.modules.platform.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.text.csv.CsvReader;
|
||||
import cn.hutool.core.text.csv.CsvUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.poi.excel.ExcelReader;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import com.baiye.config.properties.UrlsProperties;
|
||||
import com.baiye.constant.*;
|
||||
import com.baiye.exception.BadRequestException;
|
||||
import com.baiye.http.PreTestResponse;
|
||||
import com.baiye.model.dto.TelephoneTrafficDTO;
|
||||
import com.baiye.modules.agent.entity.ChannelCustom;
|
||||
import com.baiye.modules.platform.domain.Task;
|
||||
import com.baiye.modules.platform.domain.TrafficMaterial;
|
||||
import com.baiye.modules.platform.repository.TrafficMaterialRepository;
|
||||
import com.baiye.modules.platform.service.TaskService;
|
||||
import com.baiye.modules.platform.service.TelephoneTrafficService;
|
||||
import com.baiye.modules.platform.service.dto.ImportExcelDTO;
|
||||
import com.baiye.modules.platform.service.mapstruct.TrafficMaterialMapper;
|
||||
import com.baiye.modules.telemarkting.entity.PreTestAccount;
|
||||
import com.baiye.modules.telemarkting.entity.dto.UpdateTrafficDTO;
|
||||
import com.baiye.modules.telemarkting.service.PreTestService;
|
||||
import com.baiye.timed.FileTask;
|
||||
import com.baiye.util.AESUtils;
|
||||
import com.baiye.util.FileUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @description 话务上传
|
||||
* @date 2024-4-27
|
||||
**/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TelephoneTrafficServiceImpl implements TelephoneTrafficService {
|
||||
|
||||
|
||||
private final TrafficMaterialRepository trafficMaterialRepository;
|
||||
|
||||
private final TrafficMaterialMapper trafficMaterialMapper;
|
||||
|
||||
private final UrlsProperties urlsProperties;
|
||||
|
||||
private final PreTestService preTestService;
|
||||
|
||||
private final TaskService taskService;
|
||||
|
||||
private final FileTask fileTask;
|
||||
|
||||
@Value("${snowflake.workerId}")
|
||||
private int workerId;
|
||||
|
||||
@Value("${snowflake.datacenterId}")
|
||||
private int datacenterId;
|
||||
|
||||
|
||||
@Override
|
||||
public Boolean uploadFile(MultipartFile[] files, Long taskId) {
|
||||
Set<ImportExcelDTO> dtoList = Sets.newHashSet();
|
||||
Task task = taskService.queryDetails(taskId);
|
||||
if (ObjectUtil.isNotNull(task) && task.getIsAiDelivery().equals(Boolean.TRUE)) {
|
||||
throw new BadRequestException("当前任务未关闭 请关闭后进行导入操作!");
|
||||
}
|
||||
for (MultipartFile file : files) {
|
||||
// 解析数据
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
if (StringUtils.isNotBlank(originalFilename)) {
|
||||
dtoList.addAll(parseFile(file, originalFilename));
|
||||
}
|
||||
}
|
||||
|
||||
PreTestAccount dbAccount = preTestService.accountQuery();
|
||||
if (ObjectUtil.isNull(dbAccount) || StringUtils.isBlank(dbAccount.getToken())) {
|
||||
throw new BadRequestException("未配置预测试账号!");
|
||||
}
|
||||
|
||||
// 保存数据
|
||||
fileTask.runFileAnalysisTask(dtoList, task, dbAccount.getToken());
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
|
||||
private Set<ImportExcelDTO> parseFile(MultipartFile file, String originalFilename) {
|
||||
List<ImportExcelDTO> dtoList = Lists.newArrayList();
|
||||
List<Map<String, Object>> maps = Lists.newArrayList();
|
||||
// 解析 文件
|
||||
File upload = FileUtil.multiToFile(file);
|
||||
if (ObjectUtil.isNotNull(upload)) {
|
||||
if (originalFilename.endsWith(FileConstant.XLS_FILE_SUB_NAME)
|
||||
|| originalFilename.endsWith(FileConstant.XLSX_FILE_SUB_NAME)) {
|
||||
ExcelReader reader = ExcelUtil.getReader(upload);
|
||||
maps = reader.readAll();
|
||||
}
|
||||
if (originalFilename.endsWith(FileConstant.CSV_FILE_SUB_NAME)) {
|
||||
// TODO
|
||||
CsvReader reader = CsvUtil.getReader();
|
||||
Convert.toList(Map.class, reader.readMapList(FileUtil.getReader(upload, CharsetUtil.CHARSET_UTF_8)));
|
||||
}
|
||||
for (Map<String, Object> map : maps) {
|
||||
long nextId = IdUtil.getSnowflake(workerId, datacenterId).nextId();
|
||||
ImportExcelDTO dto = new ImportExcelDTO();
|
||||
Map<String, Object> hashMap = Maps.newHashMap(map);
|
||||
dto.setId(nextId);
|
||||
Object name = hashMap.getOrDefault(ImportExcelConstants.NAME, CharSequenceUtil.EMPTY);
|
||||
dto.setName(ObjectUtil.isNotNull(name) ? name.toString() : CharSequenceUtil.EMPTY);
|
||||
hashMap.remove(ImportExcelConstants.NAME);
|
||||
Object nid = hashMap.getOrDefault(ImportExcelConstants.NID, CharSequenceUtil.EMPTY);
|
||||
dto.setNid(ObjectUtil.isNotNull(nid) ? nid.toString() : CharSequenceUtil.EMPTY);
|
||||
hashMap.remove(ImportExcelConstants.NID);
|
||||
dto.setOtherInfo(hashMap.entrySet().toString());
|
||||
dtoList.add(dto);
|
||||
}
|
||||
}
|
||||
return Sets.newHashSet(dtoList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateAuthorizationStatus(Boolean flag, Long id) {
|
||||
Task task = taskService.queryDetails(id);
|
||||
if (ObjectUtil.isNotNull(task) && !task.getIsAiDelivery().equals(flag)) {
|
||||
PreTestAccount dbAccount = preTestService.accountQuery();
|
||||
if (ObjectUtil.isNotNull(dbAccount) && StringUtils.isNotBlank(dbAccount.getToken())) {
|
||||
UpdateTrafficDTO build = UpdateTrafficDTO.builder().actId(task.getActId()).status
|
||||
(flag.equals(Boolean.TRUE) ? DefaultNumberConstants.ONE_NUMBER : DefaultNumberConstants.ZERO_NUMBER).authKey(dbAccount.getToken()).build();
|
||||
String body = HttpUtil.post(UrlConstants.UPDATE_STATUS, JSONUtil.toJsonStr(build));
|
||||
log.info("====================== the log response {} ======================", body);
|
||||
if (JSONUtil.isJson(body)) {
|
||||
PreTestResponse bean = JSONUtil.toBean(body, PreTestResponse.class);
|
||||
if (ObjectUtil.isNotNull(bean) && bean.getResult().equals(Boolean.TRUE)) {
|
||||
task.setIsAiDelivery(flag);
|
||||
taskService.updateTask(task);
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String queryUrlByUserId(Long currentUserId) {
|
||||
String baseUtl = urlsProperties.getDbPushUrl();
|
||||
String encrypt = AESUtils.encrypt(currentUserId.toString(), AdPlatFormConstants.AD_PLATFORM);
|
||||
return baseUtl.concat(ObjectUtil.isNotNull(encrypt) ? encrypt : CharSequenceUtil.EMPTY).concat("?dataType=detail&encrypt=1");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TelephoneTrafficDTO queryById(Long sourceId) {
|
||||
return trafficMaterialMapper.toDto(trafficMaterialRepository.findById(sourceId).orElse(new TrafficMaterial()));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.baiye.modules.platform.service.mapstruct;
|
||||
|
||||
import com.baiye.model.base.BaseMapper;
|
||||
import com.baiye.model.dto.TelephoneTrafficDTO;
|
||||
import com.baiye.modules.platform.domain.TrafficMaterial;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author ENZO
|
||||
*
|
||||
*/
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface TrafficMaterialMapper extends BaseMapper<TelephoneTrafficDTO, TrafficMaterial> {
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.baiye.modules.telemarkting.entity.dto;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author wjt
|
||||
* @date 2023/11/13
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
public class UpdateTrafficDTO {
|
||||
|
||||
/**
|
||||
* 身份认证 token
|
||||
*/
|
||||
private String authKey;
|
||||
|
||||
/**
|
||||
* 活动名称
|
||||
*/
|
||||
private String actId;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
package com.baiye.timed;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baiye.constant.DefaultNumberConstants;
|
||||
import com.baiye.constant.UrlConstants;
|
||||
import com.baiye.modules.platform.domain.Task;
|
||||
import com.baiye.modules.platform.domain.TrafficMaterial;
|
||||
import com.baiye.modules.platform.repository.TrafficMaterialRepository;
|
||||
import com.baiye.modules.platform.service.TaskService;
|
||||
import com.baiye.modules.platform.service.dto.ImportExcelDTO;
|
||||
import com.baiye.modules.telemarkting.entity.dto.CallImportDTO;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sun.org.apache.xalan.internal.XalanConstants;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2024/4/27
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class FileTask {
|
||||
|
||||
|
||||
@Value(value = "${inter.sendClientAddress}")
|
||||
private String sendClientAddress;
|
||||
|
||||
private final TaskService taskService;
|
||||
|
||||
private final TrafficMaterialRepository trafficMaterialRepository;
|
||||
|
||||
@Async(value = "WorkExecutor")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void runFileAnalysisTask(Set<ImportExcelDTO> dtoSet, Task task, String token) {
|
||||
log.info("================== run task begin time {} ==================", DateUtil.now());
|
||||
CallImportDTO dto = new CallImportDTO();
|
||||
Long taskId = task.getId();
|
||||
int count = DefaultNumberConstants.ZERO_NUMBER;
|
||||
// 去除空字符串
|
||||
List<ImportExcelDTO> dtoList = Lists.newArrayList(dtoSet).stream().filter(str -> StringUtils.isNotBlank(str.getNid())).collect(Collectors.toList());
|
||||
List<List<ImportExcelDTO>> partition = Lists.partition(dtoList, DefaultNumberConstants.ONE_THOUSAND);
|
||||
if (ObjectUtil.isNotNull(task) && ObjectUtil.isNotNull(task.getActId())) {
|
||||
// 调用推送地址进行推送
|
||||
for (List<ImportExcelDTO> list : partition) {
|
||||
List<CallImportDTO.Source> sendClientList = Lists.newArrayList();
|
||||
try {
|
||||
list.forEach(str -> {
|
||||
if (StringUtils.isNotBlank(str.getNid())) {
|
||||
CallImportDTO.Source client = new CallImportDTO.Source();
|
||||
client.setCellphone(str.getNid());
|
||||
List<CallImportDTO.Variable> variableList = Lists.newArrayList();
|
||||
CallImportDTO.Variable taskVariable =
|
||||
CallImportDTO.Variable.builder().field
|
||||
("taskId").value(taskId.toString()).build();
|
||||
CallImportDTO.Variable sourceVariable =
|
||||
CallImportDTO.Variable.builder().field
|
||||
("sourceId").value(str.getId().toString()).build();
|
||||
variableList.add(taskVariable);
|
||||
variableList.add(sourceVariable);
|
||||
client.setCellphone(str.getNid());
|
||||
client.setVariableList(variableList);
|
||||
sendClientList.add(client);
|
||||
}
|
||||
});
|
||||
dto.setAuthKey(token);
|
||||
dto.setActId(task.getActId());
|
||||
dto.setActName(task.getActName());
|
||||
dto.setClientList(sendClientList);
|
||||
log.info("============ the request as {} =========", JSONUtil.toJsonStr(dto));
|
||||
String post = HttpUtil.post(UrlConstants.SEND_URL, JSONUtil.toJsonStr(dto));
|
||||
if (post.contains(XalanConstants.FEATURE_TRUE)) {
|
||||
count += list.size();
|
||||
}
|
||||
log.info("============ the submit result as {} =========", JSONUtil.toJsonStr(post));
|
||||
if (count > DefaultNumberConstants.ZERO_NUMBER) {
|
||||
// 保存数据
|
||||
List<TrafficMaterial> saveList = Lists.newArrayList();
|
||||
list.forEach(tf -> {
|
||||
TrafficMaterial material = new TrafficMaterial();
|
||||
material.setTaskId(taskId);
|
||||
material.setId(tf.getId());
|
||||
material.setNid(tf.getNid());
|
||||
material.setName(tf.getName());
|
||||
material.setUserId(task.getCreateBy());
|
||||
saveList.add(material);
|
||||
});
|
||||
trafficMaterialRepository.saveAll(saveList);
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
// TODO throw new exception
|
||||
log.error("============ the request exception {} ============", exception.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
log.info("================== run task end time {} ==================", DateUtil.now());
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package com.baiye.model.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date 2023-12-6
|
||||
*/
|
||||
@Data
|
||||
public class PushClueDTO {
|
||||
|
||||
|
||||
|
||||
private String remark;
|
||||
|
||||
|
||||
/**
|
||||
* 人工审核推送手机号, mobile就不是手机号字段了
|
||||
*/
|
||||
private String called;
|
||||
|
||||
/**
|
||||
* 话单id
|
||||
*/
|
||||
private String recId;
|
||||
|
||||
/**
|
||||
* 太空猫传递的线索ID
|
||||
*/
|
||||
private Long variable;
|
||||
|
||||
/**
|
||||
* nid
|
||||
*/
|
||||
private String mobile;
|
||||
|
||||
|
||||
private String empClientTypeName;
|
||||
|
||||
|
||||
private Map<String, String> clientVariables;
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.baiye.model.dto;
|
||||
|
||||
import com.baiye.util.JpaConverterAes;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-23
|
||||
*/
|
||||
@Data
|
||||
public class TelephoneTrafficDTO implements Serializable {
|
||||
|
||||
@ApiModelProperty(value = "id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "姓名")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "nid")
|
||||
@Convert(converter = JpaConverterAes.class)
|
||||
private String nid;
|
||||
|
||||
@ApiModelProperty(value = "线索分配人")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty(value = "线索分配人")
|
||||
private Long taskId;
|
||||
|
||||
@ApiModelProperty(value = "其他信息")
|
||||
private String otherSource;
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.baiye.module.controller;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baiye.annotation.Log;
|
||||
import com.baiye.model.dto.PushClueDTO;
|
||||
import com.baiye.module.service.TrafficCallbackService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2023/3/2
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/traffic/v1/exchange")
|
||||
@RequiredArgsConstructor
|
||||
public class TrafficCallbackController {
|
||||
|
||||
private final TrafficCallbackService trafficCallbackService;
|
||||
|
||||
|
||||
@Log("推送资源")
|
||||
@PostMapping("/callback")
|
||||
public ResponseEntity<String> pushClue(@RequestBody String body) {
|
||||
log.info("=============== the push body {} ==============", JSONUtil.toJsonStr(body));
|
||||
PushClueDTO pushClueDTO = JSONUtil.toBean(body, PushClueDTO.class);
|
||||
return new ResponseEntity<>(Boolean.TRUE.equals(trafficCallbackService.callbackByAppKeyAndNid(pushClueDTO)) ? HttpStatus.OK : HttpStatus.BAD_REQUEST);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.baiye.module.service;
|
||||
|
||||
import com.baiye.model.dto.PushClueDTO;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2023/3/2
|
||||
*/
|
||||
public interface TrafficCallbackService {
|
||||
|
||||
/**
|
||||
* 接收数据
|
||||
*
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
Boolean callbackByAppKeyAndNid(PushClueDTO dto);
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package com.baiye.module.service.impl;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baiye.constant.DefaultNumberConstants;
|
||||
import com.baiye.constant.SecurityConstants;
|
||||
import com.baiye.feign.PreTestClient;
|
||||
import com.baiye.feign.TaskClient;
|
||||
import com.baiye.model.dto.PushClueDTO;
|
||||
import com.baiye.model.dto.TelephoneTrafficDTO;
|
||||
import com.baiye.module.entity.Task;
|
||||
import com.baiye.module.service.ClueService;
|
||||
import com.baiye.module.service.TrafficCallbackService;
|
||||
import com.baiye.util.DecryptPnoUtil;
|
||||
import com.baiye.util.RedisUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2022/11/24
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TrafficCallbackServiceImpl implements TrafficCallbackService {
|
||||
|
||||
|
||||
private final TaskClient taskClient;
|
||||
|
||||
private final RedisUtils redisUtils;
|
||||
|
||||
private final ClueService clueService;
|
||||
|
||||
private final PreTestClient preTestClient;
|
||||
|
||||
@Override
|
||||
public Boolean callbackByAppKeyAndNid(PushClueDTO dto) {
|
||||
|
||||
String recId = dto.getRecId();
|
||||
String called = dto.getCalled();
|
||||
String remark = dto.getRemark();
|
||||
String phone = CharSequenceUtil.EMPTY;
|
||||
String typeName = dto.getEmpClientTypeName();
|
||||
if (StringUtils.isNotBlank(dto.getMobile())) {
|
||||
phone = Base64.decodeStr(dto.getMobile());
|
||||
}
|
||||
// 格式校验
|
||||
if (StringUtils.isNotBlank(called) && StringUtils.isNotBlank(typeName)
|
||||
&& "A".equalsIgnoreCase(typeName)) {
|
||||
phone = called.length() > DefaultNumberConstants.ELEVEN_NUMBER
|
||||
? DecryptPnoUtil.decryptPno(called) : called;
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(phone)) {
|
||||
Map<String, String> clientVariables = dto.getClientVariables();
|
||||
String taskId = clientVariables.getOrDefault("taskId", CharSequenceUtil.EMPTY);
|
||||
String sourceId = clientVariables.getOrDefault("sourceId", CharSequenceUtil.EMPTY);
|
||||
if (CharSequenceUtil.isNotBlank(taskId) && CharSequenceUtil.isNotBlank(sourceId)) {
|
||||
// 已经存在的不进行操作
|
||||
if (StringUtils.isNotBlank(recId) && ObjectUtil.isNotNull(redisUtils.get(recId))) {
|
||||
// TODO Do not modify for the time being
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
Long id = Long.parseLong(taskId);
|
||||
Task task = findByTaskId(id);
|
||||
if (ObjectUtil.isNotNull(task)) {
|
||||
TelephoneTrafficDTO telephoneTrafficDTO = preTestClient.findByDetail(Long.parseLong(sourceId), SecurityConstants.FROM_IN).getBody();
|
||||
if (ObjectUtil.isNotNull(telephoneTrafficDTO)) {
|
||||
clueService.saveSingleClueTalk
|
||||
(phone, id, task.getCreateBy(), telephoneTrafficDTO.getOtherSource(), DefaultNumberConstants.NINE_NUMBER, DefaultNumberConstants.ZERO_NUMBER, remark, null);
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(recId)) {
|
||||
// 缓存三天
|
||||
redisUtils.set(recId, phone, DefaultNumberConstants.THREE_NUMBER, TimeUnit.DAYS);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
public Task findByTaskId(Long taskId) {
|
||||
Task body = taskClient.queryDetails(taskId, SecurityConstants.FROM_IN).getBody();
|
||||
if (body != null) {
|
||||
return body;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue