|
|
@@ -7,6 +7,14 @@ import { PageRequest } from '../common/dto/page-request'
|
|
|
import { Pagination, paginate } from 'nestjs-typeorm-paginate'
|
|
|
import { Response } from 'express'
|
|
|
import { Users } from '../users/entities/users.entity'
|
|
|
+import { SysConfigService } from '../sys-config/sys-config.service'
|
|
|
+import axios from 'axios'
|
|
|
+
|
|
|
+const token = 'vLp1Vl/yauWWx2bhaf+e9/VgXzUt5QRIZS4Rj+UuOv4eUpQWkJQC4zVnM3gXaqf5jc6j7lEY2Lagw/QCIf/4/ZTB4MKMfcvUmHRc9ISg4vXgIoC6SB2dyoeJxkOqJ5wQTftzPG2QSLFBSyhV3BHZGOguKSoXSlexmhl8pTqL/Fs='
|
|
|
+
|
|
|
+const axiosInstance = axios.create({
|
|
|
+ baseURL: 'http://www.dolphindata.ai/filterApi/'
|
|
|
+})
|
|
|
|
|
|
@Injectable()
|
|
|
export class PhoneListService {
|
|
|
@@ -18,7 +26,8 @@ export class PhoneListService {
|
|
|
@InjectRepository(Users)
|
|
|
private userRepository: Repository<Users>,
|
|
|
private readonly dataSource: DataSource
|
|
|
- ) {}
|
|
|
+ ) {
|
|
|
+ }
|
|
|
|
|
|
async findAllPhoneList(req: PageRequest<PhoneList>): Promise<Pagination<PhoneList>> {
|
|
|
const page = await paginate<PhoneList>(this.phoneListRepository, req.page, req.search)
|
|
|
@@ -92,10 +101,69 @@ export class PhoneListService {
|
|
|
const phones = await this.findPhoneByListId(listId)
|
|
|
const phoneList = await this.phoneListRepository.findOneBy({ id: listId })
|
|
|
const fileName = `${phoneList.name}.txt`
|
|
|
- const fileContent = phones.map((phone) => phone.number).join('\n')
|
|
|
+ const fileContent = phones.map((phone) => phone.number.replace('+', '')).join('\n')
|
|
|
res.setHeader('Content-disposition', `attachment; filename=${fileName}`)
|
|
|
res.setHeader('Content-type', 'text/plain')
|
|
|
res.write(fileContent)
|
|
|
res.end()
|
|
|
}
|
|
|
+
|
|
|
+ async screenPhoneNumber(file: Express.Multer.File): Promise<string[]> {
|
|
|
+ let phones = []
|
|
|
+ let formData = new FormData()
|
|
|
+ const blob = new Blob([file.buffer], { type: file.mimetype || 'application/octet-stream' })
|
|
|
+ formData.append('file', blob, file.originalname)
|
|
|
+ formData.append('filterType', 'rcsValid')
|
|
|
+ const config = {
|
|
|
+ headers: {
|
|
|
+ token
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 创建任务
|
|
|
+ const addRes = await axiosInstance.post('filter_add', formData, config)
|
|
|
+ const addData = addRes.data
|
|
|
+ if (addData.code === 200) {
|
|
|
+ const taskNo = addData.result.taskNo
|
|
|
+ let check = true
|
|
|
+ while (check) {
|
|
|
+ console.log('Wait for the screen number to complete...')
|
|
|
+ // 等待5s
|
|
|
+ await new Promise((resolve) => setTimeout(resolve, 5000))
|
|
|
+ // 查询任务状态
|
|
|
+ const searchRes = await axiosInstance.get('filter_search', {
|
|
|
+ params: {
|
|
|
+ taskNo
|
|
|
+ },
|
|
|
+ headers: {
|
|
|
+ token
|
|
|
+ }
|
|
|
+ })
|
|
|
+ const searchData = searchRes.data
|
|
|
+ if (searchData.code === 200 && searchData.result.taskStatus === 'Finish') {
|
|
|
+ console.log('The sieve number is complete.')
|
|
|
+ check = false
|
|
|
+ // 获取筛号后手机号
|
|
|
+ const resultRes = await axiosInstance.get('get_result', {
|
|
|
+ params: {
|
|
|
+ taskNo
|
|
|
+ },
|
|
|
+ headers: {
|
|
|
+ token
|
|
|
+ }
|
|
|
+ })
|
|
|
+ const resultData = resultRes.data
|
|
|
+ if (resultData.code === 200) {
|
|
|
+ phones = resultData.result.phone
|
|
|
+ } else {
|
|
|
+ throw new Error('result:', resultData.message)
|
|
|
+ }
|
|
|
+ } else if (searchData.code === 200 && searchData.result.taskStatus === 'Close') {
|
|
|
+ return phones
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new Error('add:', addData.message)
|
|
|
+ }
|
|
|
+ return phones
|
|
|
+ }
|
|
|
}
|