从山证v2.3.0拷贝
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
namespace YLErp.Modules.ClientModule
|
||||
{
|
||||
public class ClientConfirmTemplateService : ClientBaseService
|
||||
{
|
||||
public ClientConfirmTemplateService(OptUserInfo userInfo) : base(userInfo)
|
||||
{
|
||||
}
|
||||
|
||||
public List<ConfirmsTemplate> GetClientTemplates()
|
||||
{
|
||||
var templateSettings = new List<ConfirmsTemplate>();
|
||||
var metas = DbContext.ClientMeta.Where(o => o.MetaKey.Contains("确认书") || o.MetaKey == "邮件模板");
|
||||
foreach (var item in metas)
|
||||
{
|
||||
var client = DataCacheProvider.GetClientDataSource().GetData(item.ClientId);
|
||||
templateSettings.Add(new ConfirmsTemplate
|
||||
{
|
||||
meta_id = item.id,
|
||||
ClientId = item.ClientId,
|
||||
ClientName = client.Name,
|
||||
fileType = item.MetaKey,
|
||||
fileName = item.MetaValue
|
||||
});
|
||||
}
|
||||
return templateSettings;
|
||||
}
|
||||
|
||||
public void SaveConfirmTemplates(ConfirmsTemplate template)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (template.Clients == null || template.Clients.Count < 1)
|
||||
{
|
||||
if (template.ClientId < 1)
|
||||
{
|
||||
throw new ServiceException("请先设置客户");
|
||||
}
|
||||
else
|
||||
{
|
||||
SaveTemplate(template);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var item in template.Clients)
|
||||
{
|
||||
SaveTemplate(new ConfirmsTemplate
|
||||
{
|
||||
ClientId = item,
|
||||
fileType = template.fileType,
|
||||
fileName = template.fileName
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ServiceException("保存客户确认书模板出错:" + e.Message);
|
||||
}
|
||||
|
||||
}
|
||||
public void SaveTemplate(ConfirmsTemplate template)
|
||||
{
|
||||
var meta = DbContext.ClientMeta.FirstOrDefault(o => o.ClientId == template.ClientId && o.MetaKey == template.fileType);
|
||||
if (meta == null)
|
||||
{
|
||||
DbContext.ClientMeta.Add(new ClientMeta
|
||||
{
|
||||
ClientId = template.ClientId,
|
||||
MetaKey = template.fileType,
|
||||
MetaValue = template.fileName,
|
||||
OptDate = DateTime.Now,
|
||||
OptId = OptUser.UserId,
|
||||
OptName = OptUser.UserName
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
meta.MetaValue = template.fileName;
|
||||
meta.OptDate = DateTime.Now;
|
||||
meta.OptId = OptUser.UserId;
|
||||
meta.OptName = OptUser.UserName;
|
||||
}
|
||||
DbContext.SaveChanges();
|
||||
}
|
||||
public void DeleteTemplate(int id)
|
||||
{
|
||||
var r = DbContext.ClientMeta.Find(id);
|
||||
if (r == null)
|
||||
{
|
||||
throw new ServiceException("未找到记录!");
|
||||
}
|
||||
else
|
||||
{
|
||||
DbContext.ClientMeta.Remove(r);
|
||||
}
|
||||
DbContext.SaveChanges();
|
||||
}
|
||||
|
||||
public string GetTemplateName(int clientId, string metaKey)
|
||||
{
|
||||
var template = DbContext.ClientMeta.Where(o => o.ClientId == clientId && o.MetaKey == metaKey).FirstOrDefault();
|
||||
return template == null ? "" : template.MetaValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user