Commit 487b8cfc authored by doc@bgerp.org's avatar doc@bgerp.org

p11360 Automatic process creation from E-Mail.

parent d03ddfe5
A: Auto creation processes from E-Mails, https://bgerp.ru/doc/3.0/manual/kernel/message.html#ac
package ru.bgcrm.dao.message;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
......@@ -9,28 +10,20 @@ import ru.bgcrm.model.message.Message;
import ru.bgcrm.model.process.Process;
import ru.bgcrm.struts.form.DynActionForm;
import ru.bgcrm.util.ParameterMap;
import ru.bgcrm.util.sql.ConnectionSet;
public abstract class MessageTypeContactSaver
{
private static final List<IdTitle> STANDARD_MODE_LIST = new ArrayList<IdTitle>();
static
{
STANDARD_MODE_LIST.add( new IdTitle( 0, "Не сохранять" ) );
STANDARD_MODE_LIST.add( new IdTitle( 1, "Cохранить" ) );
}
public MessageTypeContactSaver( ParameterMap config )
throws BGException
{}
// разные режимы сохранения, например домен либо EMail
public List<IdTitle> getSaveModeList()
{
return STANDARD_MODE_LIST;
}
public abstract void saveContact( DynActionForm form, ConnectionSet conSet,
Message message, Process process, int saveMode )
throws BGException;
public abstract class MessageTypeContactSaver {
private static final List<IdTitle> STANDARD_MODE_LIST = new ArrayList<IdTitle>();
static {
STANDARD_MODE_LIST.add(new IdTitle(0, "Не сохранять"));
STANDARD_MODE_LIST.add(new IdTitle(1, "Cохранить"));
}
public MessageTypeContactSaver(ParameterMap config) throws BGException {}
// разные режимы сохранения, например домен либо EMail
public List<IdTitle> getSaveModeList() {
return STANDARD_MODE_LIST;
}
public abstract void saveContact(DynActionForm form, Connection con, Message message, Process process, int saveMode) throws BGException;
}
package ru.bgcrm.dao.message;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.SortedMap;
......@@ -19,69 +20,55 @@ import ru.bgcrm.model.process.Process;
import ru.bgcrm.struts.form.DynActionForm;
import ru.bgcrm.util.ParameterMap;
import ru.bgcrm.util.Utils;
import ru.bgcrm.util.sql.ConnectionSet;
public class MessageTypeContactSaverEmail
extends MessageTypeContactSaver
{
private static final List<IdTitle> MODE_LIST = new ArrayList<IdTitle>();
static
{
MODE_LIST.add( new IdTitle( 0, "Не сохранять" ) );
MODE_LIST.add( new IdTitle( 1, "Cохранить EMail" ) );
MODE_LIST.add( new IdTitle( 2, "Cохранить EMail домен" ) );
}
private int paramId;
public MessageTypeContactSaverEmail( ParameterMap config )
throws BGException
{
super( config );
this.paramId = config.getInt( "paramId", -1 );
if( paramId <= 0 )
{
throw new BGMessageException( "paramId not defined!" );
}
public class MessageTypeContactSaverEmail extends MessageTypeContactSaver {
private static final List<IdTitle> MODE_LIST = new ArrayList<IdTitle>();
static {
MODE_LIST.add(new IdTitle(0, "Не сохранять"));
MODE_LIST.add(new IdTitle(1, "Cохранить EMail"));
MODE_LIST.add(new IdTitle(2, "Cохранить EMail домен"));
}
private int paramId;
public MessageTypeContactSaverEmail(ParameterMap config) throws BGException {
super(config);
this.paramId = config.getInt("paramId", -1);
if (paramId <= 0) {
throw new BGMessageException("paramId not defined!");
}
}
@Override
public List<IdTitle> getSaveModeList() {
return MODE_LIST;
}
@Override
public void saveContact(DynActionForm form, Connection con, Message message, Process process, int saveMode) throws BGException {
CommonObjectLink customerLink = Utils.getFirst(new ProcessLinkDAO(con).getObjectLinksWithType(process.getId(), Customer.OBJECT_TYPE));
if (customerLink == null) {
return;
}
String email = message.getFrom();
String domainName = StringUtils.substringAfter(email, "@");
ParamValueDAO paramDao = new ParamValueDAO(con);
SortedMap<Integer, ParameterEmailValue> currentValue = paramDao.getParamEmail(customerLink.getLinkedObjectId(), paramId);
boolean exists = false;
for (ParameterEmailValue value : currentValue.values()) {
if (exists = value.getValue().equals(email) || value.getValue().equals(domainName)) {
break;
}
}
if (!exists) {
paramDao.updateParamEmail(customerLink.getLinkedObjectId(), paramId, 0, new ParameterEmailValue(saveMode == 1 ? email : domainName));
}
}
@Override
public List<IdTitle> getSaveModeList()
{
return MODE_LIST;
}
@Override
public void saveContact( DynActionForm form, ConnectionSet conSet, Message message, Process process, int saveMode )
throws BGException
{
CommonObjectLink customerLink = Utils.getFirst( new ProcessLinkDAO( conSet.getConnection() ).getObjectLinksWithType( process.getId(), Customer.OBJECT_TYPE ) );
if( customerLink == null )
{
return;
}
String email = message.getFrom();
String domainName = StringUtils.substringAfter( email, "@" );
ParamValueDAO paramDao = new ParamValueDAO( conSet.getConnection() );
SortedMap<Integer, ParameterEmailValue> currentValue = paramDao.getParamEmail( customerLink.getLinkedObjectId(), paramId );
boolean exists = false;
for( ParameterEmailValue value : currentValue.values() )
{
if( exists = value.getValue().equals( email ) || value.getValue().equals( domainName ) )
{
break;
}
}
if( !exists )
{
paramDao.updateParamEmail( customerLink.getLinkedObjectId(), paramId, 0, new ParameterEmailValue( saveMode == 1 ? email : domainName ) );
}
}
}
package ru.bgcrm.dao.message;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
......@@ -15,64 +16,51 @@ import ru.bgcrm.model.process.Process;
import ru.bgcrm.struts.form.DynActionForm;
import ru.bgcrm.util.ParameterMap;
import ru.bgcrm.util.Utils;
import ru.bgcrm.util.sql.ConnectionSet;
public class MessageTypeContactSaverPhone
extends ru.bgcrm.dao.message.MessageTypeContactSaver
{
private final int paramId;
private final String format;
public MessageTypeContactSaverPhone( ParameterMap config )
throws BGException
{
super( config );
this.paramId = config.getInt( "paramId", -1 );
this.format = config.get( "format", "13" );
if( paramId <= 0 )
{
throw new BGException( "paramId incorrect" );
}
}
public class MessageTypeContactSaverPhone extends ru.bgcrm.dao.message.MessageTypeContactSaver {
private final int paramId;
private final String format;
@Override
public void saveContact( DynActionForm form, ConnectionSet conSet, Message message,
Process process, int saveMode )
throws BGException
{
CommonObjectLink customerLink = Utils.getFirst( new ProcessLinkDAO( conSet.getConnection() ).getObjectLinksWithType( process.getId(), Customer.OBJECT_TYPE ) );
if( customerLink == null )
{
return;
}
String phone = message.getFrom();
ParamValueDAO paramDao = new ParamValueDAO( conSet.getConnection() );
List<ParameterPhoneValueItem> values = new ArrayList<ParameterPhoneValueItem>();
ParameterPhoneValue currentValue = paramDao.getParamPhone( customerLink.getLinkedObjectId(), paramId );
values = currentValue.getItemList();
boolean exists = false;
for( ParameterPhoneValueItem value : values )
{
if( exists = phone.equals( value.getPhone() ) )
{
break;
}
}
if( !exists )
{
ParameterPhoneValueItem item = new ParameterPhoneValueItem();
item.setPhone( phone );
item.setFormat( format );
values.add(item );
paramDao.updateParamPhone( customerLink.getLinkedObjectId(), paramId, currentValue );
}
}
public MessageTypeContactSaverPhone(ParameterMap config) throws BGException {
super(config);
this.paramId = config.getInt("paramId", -1);
this.format = config.get("format", "13");
if (paramId <= 0) {
throw new BGException("paramId incorrect");
}
}
@Override
public void saveContact(DynActionForm form, Connection con, Message message, Process process, int saveMode) throws BGException {
CommonObjectLink customerLink = Utils.getFirst(new ProcessLinkDAO(con).getObjectLinksWithType(process.getId(), Customer.OBJECT_TYPE));
if (customerLink == null) {
return;
}
String phone = message.getFrom();
ParamValueDAO paramDao = new ParamValueDAO(con);
List<ParameterPhoneValueItem> values = new ArrayList<ParameterPhoneValueItem>();
ParameterPhoneValue currentValue = paramDao.getParamPhone(customerLink.getLinkedObjectId(), paramId);
values = currentValue.getItemList();
boolean exists = false;
for (ParameterPhoneValueItem value : values) {
if (exists = phone.equals(value.getPhone())) {
break;
}
}
if (!exists) {
ParameterPhoneValueItem item = new ParameterPhoneValueItem();
item.setPhone(phone);
item.setFormat(format);
values.add(item);
paramDao.updateParamPhone(customerLink.getLinkedObjectId(), paramId, currentValue);
}
}
}
\ No newline at end of file
package ru.bgcrm.plugin.bgbilling.dao;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
......@@ -17,7 +18,6 @@ import ru.bgcrm.plugin.bgbilling.proto.model.Contract;
import ru.bgcrm.struts.form.DynActionForm;
import ru.bgcrm.util.ParameterMap;
import ru.bgcrm.util.Utils;
import ru.bgcrm.util.sql.ConnectionSet;
public class MessageTypeContactSaverPhone
extends ru.bgcrm.dao.message.MessageTypeContactSaver
......@@ -38,11 +38,11 @@ public class MessageTypeContactSaverPhone
}
@Override
public void saveContact( DynActionForm form, ConnectionSet conSet, Message message,
public void saveContact( DynActionForm form, Connection con, Message message,
Process process, int saveMode )
throws BGException
{
CommonObjectLink contractLink = Utils.getFirst( new ProcessLinkDAO( conSet.getConnection() ).getObjectLinksWithType( process.getId(), Contract.OBJECT_TYPE + "%" ) );
CommonObjectLink contractLink = Utils.getFirst( new ProcessLinkDAO( con ).getObjectLinksWithType( process.getId(), Contract.OBJECT_TYPE + "%" ) );
if( contractLink == null )
{
return;
......
......@@ -50,6 +50,7 @@ import ru.bgcrm.model.message.Message;
import ru.bgcrm.model.process.Process;
import ru.bgcrm.struts.form.DynActionForm;
import ru.bgcrm.util.Preferences;
import ru.bgcrm.util.Setup;
import ru.bgcrm.util.Utils;
import ru.bgcrm.util.sql.ConnectionSet;
......@@ -110,9 +111,13 @@ public class MessageAction extends BaseAction {
}
public ActionForward messageUpdateProcess(ActionMapping mapping, DynActionForm form, ConnectionSet conSet) throws BGException {
MessageTypeConfig config = setup.getConfig(MessageTypeConfig.class);
Connection con = conSet.getConnection();
MessageAction.messageUpdateProcess(form, con);
return processJsonForward(conSet, form);
}
static public void messageUpdateProcess(DynActionForm form, Connection con) throws BGException {
MessageTypeConfig config = Setup.getSetup().getConfig(MessageTypeConfig.class);
MessageDAO messageDao = new MessageDAO(con);
......@@ -151,16 +156,17 @@ public class MessageAction extends BaseAction {
if (form.getParamBoolean("notification", false))
messageDao.updateMessage(type.messageLinkedToProcess(message));
else if (contactSaveMode > 0)
type.getContactSaver().saveContact(form, conSet, message, process, contactSaveMode);
type.getContactSaver().saveContact(form, con, message, process, contactSaveMode);
}
}
messageDao.updateMessageProcess(message);
return processJsonForward(conSet, form);
}
public ActionForward messageUpdateTags(ActionMapping mapping, DynActionForm form, ConnectionSet conSet) throws BGException {
Connection con = conSet.getConnection();
MessageDAO messageDao = new MessageDAO(con);
......
......@@ -386,6 +386,17 @@ messageType.<id>.class=ru.bgcrm.dao.message.MessageTypeEmail
messageType.<id>.quickAnswerEmailParamId=21
----
[[ac]]
==== Автосоздание процесса
Полученные по E-Mail уведомления о новых сообщениях процесса могут быть использованы для автоматического создания процесса по сообщению.
Для этого в конфигурации типа сообщения добавить:
[source]
----
messageType.<id>.autoCreateProcessTypeId=<typeId>
----
Где *<typeId>* - код типа процесса.
[[type-note]]
=== Тип Note
*<messageTypeClassName>=ru.bgcrm.dao.message.MessageTypeNote*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment