add upload phone number
This commit is contained in:
parent
07b91b2a0d
commit
426bfc3b62
@ -10,9 +10,11 @@ import com.pudonghot.yo.model.domain.PhoneList;
|
||||
import com.wacai.tigon.web.controller.ArgQuery;
|
||||
import com.pudonghot.yo.cms.form.BaseUpdateForm;
|
||||
import com.pudonghot.yo.basic.model.PrivacyLevel;
|
||||
import com.pudonghot.yo.cms.service.PhoneListService;
|
||||
import com.pudonghot.yo.cms.annotation.TenantResource;
|
||||
import com.wacai.tigon.web.controller.BaseCrudController;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import com.pudonghot.yo.cms.form.FormCreateUploadPhoneList;
|
||||
import com.pudonghot.yo.cms.form.create.FormCreatePhoneList;
|
||||
import com.pudonghot.yo.cellphone.privacy.NumberPrivacyUtils;
|
||||
|
||||
@ -57,4 +59,9 @@ public class PhoneListController<M extends PhoneList,
|
||||
public int deleteAll() {
|
||||
return crudService.delete(new Search());
|
||||
}
|
||||
|
||||
@PostMapping("/upload")
|
||||
public int upload(final FormCreateUploadPhoneList form) {
|
||||
return ((PhoneListService<M, FC, FU>) crudService).upload(form);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
package com.pudonghot.yo.cms.form;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* @author Donghuang
|
||||
* @date Nov 28, 2020 22:58:33
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString(callSuper = true)
|
||||
public class FormCreateUploadPhoneList extends BaseCreateForm {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNull
|
||||
private MultipartFile file;
|
||||
}
|
@ -3,6 +3,7 @@ package com.pudonghot.yo.cms.service;
|
||||
import com.pudonghot.yo.model.domain.PhoneList;
|
||||
import com.pudonghot.yo.cms.form.BaseUpdateForm;
|
||||
import com.wacai.tigon.service.BaseCrudByFormService;
|
||||
import com.pudonghot.yo.cms.form.FormCreateUploadPhoneList;
|
||||
import com.pudonghot.yo.cms.form.create.FormCreatePhoneList;
|
||||
|
||||
/**
|
||||
@ -13,4 +14,12 @@ public interface PhoneListService<M extends PhoneList,
|
||||
FC extends FormCreatePhoneList,
|
||||
FU extends BaseUpdateForm>
|
||||
extends BaseCrudByFormService<Integer, M, FC, FU> {
|
||||
|
||||
/**
|
||||
* upload phone list
|
||||
*
|
||||
* @param form form
|
||||
* @return uploaded rows
|
||||
*/
|
||||
int upload(FormCreateUploadPhoneList form);
|
||||
}
|
||||
|
@ -2,18 +2,23 @@ package com.pudonghot.yo.cms.service.impl;
|
||||
|
||||
import lombok.val;
|
||||
import java.util.List;
|
||||
import lombok.SneakyThrows;
|
||||
import java.util.ArrayList;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chyxion.tigon.mybatis.Search;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.util.Assert;
|
||||
import com.wacai.tigon.model.ViewModel;
|
||||
import me.chyxion.tigon.mybatis.Search;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import me.chyxion.tigon.mybatis.BaseMapper;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.pudonghot.yo.model.domain.PhoneList;
|
||||
import com.pudonghot.yo.cms.form.BaseUpdateForm;
|
||||
import com.pudonghot.yo.cms.form.BaseCreateForm;
|
||||
import com.pudonghot.yo.cms.service.PhoneListService;
|
||||
import com.pudonghot.yo.mapper.CallDetailRecordMapper;
|
||||
import com.pudonghot.yo.model.domain.CallDetailRecord;
|
||||
import com.pudonghot.yo.cms.form.FormCreateUploadPhoneList;
|
||||
import com.pudonghot.yo.cms.form.create.FormCreatePhoneList;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -85,9 +90,74 @@ public class PhoneListServiceImpl<M extends PhoneList,
|
||||
return phoneListList;
|
||||
}
|
||||
|
||||
private M createModel(final FormCreatePhoneList form, final String phone) {
|
||||
private M createModel(final BaseCreateForm form, final String phone) {
|
||||
val model = form.copy(modelType);
|
||||
model.setPhone(phone);
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public int upload(final FormCreateUploadPhoneList form) {
|
||||
|
||||
int count = 0;
|
||||
try(val inputStream = form.getFile().getInputStream();
|
||||
val li = IOUtils.lineIterator(
|
||||
inputStream, StandardCharsets.UTF_8)) {
|
||||
|
||||
val phoneListList = new ArrayList<M>(256);
|
||||
val tenantId = form.getTenantId();
|
||||
|
||||
while (li.hasNext()) {
|
||||
val line = StringUtils.trim(li.nextLine());
|
||||
if (StringUtils.isBlank(line)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
val phones = line.split("[^\\w]+");
|
||||
|
||||
for (val phone : phones) {
|
||||
String phoneClean;
|
||||
if (!StringUtils.isNumeric(phone)) {
|
||||
val phone2 = findByConnId(phone);
|
||||
if (StringUtils.isNotBlank(phone2)) {
|
||||
phoneClean = phone2;
|
||||
}
|
||||
else {
|
||||
log.warn("Invalid phone list [{}].", phone);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else {
|
||||
phoneClean = phone;
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(phoneClean)) {
|
||||
if (!mapper.exists(
|
||||
new Search(PhoneList.TENANT_ID, tenantId)
|
||||
.eq(PhoneList.PHONE, phoneClean))) {
|
||||
phoneListList.add(createModel(form, phoneClean));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (phoneListList.size() > 128) {
|
||||
count += phoneListList.size();
|
||||
mapper.insert(phoneListList);
|
||||
phoneListList.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (!phoneListList.isEmpty()) {
|
||||
count += phoneListList.size();
|
||||
mapper.insert(phoneListList);
|
||||
phoneListList.clear();
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,10 @@
|
||||
import BaseListRoute from '../base-list';
|
||||
import ActionDeleteAll from '../phone-list/action-delete-all';
|
||||
|
||||
export default BaseListRoute.extend({
|
||||
perm: 'PERM_VIEW_PHONE_BLACKLIST_LIST',
|
||||
breadcrumbs: [{text: '黑名单列表'}],
|
||||
actions: {
|
||||
deleteAll() {
|
||||
const me = this;
|
||||
me.get('dialog').confirm('确认要清空全部黑名单吗?', () => {
|
||||
me.get('service').ajaxPost('delete-all').then(r => {
|
||||
me.get('message').alert('清空成功,移除:' + r);
|
||||
me.refresh();
|
||||
});
|
||||
});
|
||||
}
|
||||
deleteAll: ActionDeleteAll
|
||||
}
|
||||
});
|
||||
|
@ -1,17 +1,10 @@
|
||||
import BaseListRoute from '../base-list';
|
||||
import ActionDeleteAll from '../phone-list/action-delete-all';
|
||||
|
||||
export default BaseListRoute.extend({
|
||||
perm: 'PERM_VIEW_PHONE_GREYLIST_LIST',
|
||||
breadcrumbs: [{text: '灰名单列表'}],
|
||||
actions: {
|
||||
deleteAll() {
|
||||
const me = this;
|
||||
me.get('dialog').confirm('确认要清空全部灰名单吗?', () => {
|
||||
me.get('service').ajaxPost('delete-all').then(r => {
|
||||
me.get('message').alert('清空成功,移除:' + r);
|
||||
me.refresh();
|
||||
});
|
||||
});
|
||||
}
|
||||
deleteAll: ActionDeleteAll
|
||||
}
|
||||
});
|
||||
|
9
web/cms/app/routes/phone-list/action-delete-all.js
Normal file
9
web/cms/app/routes/phone-list/action-delete-all.js
Normal file
@ -0,0 +1,9 @@
|
||||
export default function() {
|
||||
const me = this;
|
||||
me.get('dialog').confirm('确认要清空全部名单吗?', () => {
|
||||
me.get('service').ajaxPost('delete-all').then(r => {
|
||||
me.get('message').alert('清空成功,移除:' + r);
|
||||
me.refresh();
|
||||
});
|
||||
});
|
||||
}
|
@ -1,17 +1,10 @@
|
||||
import BaseListRoute from '../base-list';
|
||||
import ActionDeleteAll from '../phone-list/action-delete-all';
|
||||
|
||||
export default BaseListRoute.extend({
|
||||
perm: 'PERM_VIEW_PHONE_WHITELIST_LIST',
|
||||
breadcrumbs: [{text: '白名单列表'}],
|
||||
actions: {
|
||||
deleteAll() {
|
||||
const me = this;
|
||||
me.get('dialog').confirm('确认要清空全部白名单吗?', () => {
|
||||
me.get('service').ajaxPost('delete-all').then(r => {
|
||||
me.get('message').alert('清空成功,移除:' + r);
|
||||
me.refresh();
|
||||
});
|
||||
});
|
||||
}
|
||||
deleteAll: ActionDeleteAll
|
||||
}
|
||||
});
|
||||
|
@ -10,5 +10,10 @@ export default Service.extend({
|
||||
maximum: 36
|
||||
}
|
||||
}
|
||||
},
|
||||
uploadConstraints: {
|
||||
file: {
|
||||
presence: true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -19,5 +19,10 @@ export default Service.extend({
|
||||
credit: {
|
||||
presence: true
|
||||
},
|
||||
},
|
||||
uploadConstraints: {
|
||||
file: {
|
||||
presence: true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -10,5 +10,10 @@ export default Service.extend({
|
||||
maximum: 36
|
||||
}
|
||||
}
|
||||
},
|
||||
uploadConstraints: {
|
||||
file: {
|
||||
presence: true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -1,9 +1,17 @@
|
||||
{{#form-content}}
|
||||
<hr />
|
||||
{{form-input type='textarea' name='phone' label='号码' placeholder='手机号/通话ID'}}
|
||||
{{form-input-checkbox name='upload' label='输入/文件'}}
|
||||
|
||||
{{#if model.upload}}
|
||||
{{form-input type='file' name='file' label='文件' placeholder='名单文本文件'}}
|
||||
{{else}}
|
||||
{{form-input type='textarea' name='phone' label='号码' placeholder='手机号/通话ID'}}
|
||||
{{/if}}
|
||||
|
||||
{{form-input name='note' label='备注'}}
|
||||
<hr />
|
||||
{{form-footer-buttons type='create'}}
|
||||
{{form-footer-buttons type=(if model.upload 'upload' 'create')
|
||||
post-url=(if model.upload 'phone-blacklist/upload')
|
||||
success-message='添加成功'}}
|
||||
{{/form-content}}
|
||||
{{outlet}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user