339 lines
12 KiB
C#
339 lines
12 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Yh.Platform.Abstractions;
|
|
using YhCore.Entity;
|
|
using YhCore.Model.Dto;
|
|
using YhCore.Repository;
|
|
using YhCore.Service.Interfaces;
|
|
|
|
namespace YhCore.Service.Impl
|
|
{
|
|
/// <summary>
|
|
/// 文印分类 / 印制版面 / 公共类别服务实现
|
|
/// (移植旧 BestSchool.DocPrint.WY_list 分类部分 + WY_Classify)。
|
|
/// </summary>
|
|
public class DocPrintClassifyService : IDocPrintClassifyService
|
|
{
|
|
private readonly IRepository<Common_Dictionary> _dic;
|
|
private readonly IRepository<Common_DictionaryOrd> _ord;
|
|
private readonly IRepository<WY_DocPrint> _doc;
|
|
private readonly IRepository<Common_Groupuser> _groupuser;
|
|
private readonly IRepository<Common_freeGroupuser> _freegroup;
|
|
private readonly IRepository<WY_SchZyBit> _zybit;
|
|
|
|
public DocPrintClassifyService(
|
|
IRepository<Common_Dictionary> dic,
|
|
IRepository<Common_DictionaryOrd> ord,
|
|
IRepository<WY_DocPrint> doc,
|
|
IRepository<Common_Groupuser> groupuser,
|
|
IRepository<Common_freeGroupuser> freegroup,
|
|
IRepository<WY_SchZyBit> zybit)
|
|
{
|
|
_dic = dic;
|
|
_ord = ord;
|
|
_doc = doc;
|
|
_groupuser = groupuser;
|
|
_freegroup = freegroup;
|
|
_zybit = zybit;
|
|
}
|
|
|
|
#region 文印分类 / 印制版面
|
|
|
|
public async Task AddDicAsync(Common_Dictionary model)
|
|
{
|
|
if (model == null) throw new DException("参数错误!");
|
|
|
|
var listed = await _dic.AnyAsync(b =>
|
|
b.typeID == model.typeID && b.Name == model.Name && b.Schserid == model.Schserid);
|
|
if (listed) throw new DException("该分类已经存在!");
|
|
|
|
var max = (await _dic.FindAsync(x => x.typeID == model.typeID))
|
|
.OrderByDescending(x => x.SerID).FirstOrDefault();
|
|
model.Sort = max != null ? (max.Sort ?? 0) + 1 : 1;
|
|
model.Enable = 1;
|
|
model.CodeID = model.typeID + model.Sort;
|
|
model.typeName = "印制分类";
|
|
|
|
await _dic.AddAsync(model);
|
|
await _dic.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task AddYZBMAsync(Common_Dictionary model)
|
|
{
|
|
if (model == null) throw new DException("参数错误!");
|
|
|
|
var listed = await _dic.AnyAsync(b =>
|
|
b.typeID == model.typeID && b.Name == model.Name && b.Schserid == model.Schserid);
|
|
if (listed) throw new DException("该版面已经存在!");
|
|
|
|
var max = (await _dic.FindAsync(x => x.typeID == model.typeID))
|
|
.OrderByDescending(x => x.SerID).FirstOrDefault();
|
|
model.Sort = max != null ? (max.Sort ?? 0) + 1 : 1;
|
|
model.Enable = 1;
|
|
model.CodeID = model.typeID + model.Sort;
|
|
model.typeName = "印制版面";
|
|
|
|
await _dic.AddAsync(model);
|
|
await _dic.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task<List<CategoryItem>> CategoryListAsync(string schSerId, string name)
|
|
=> await QueryClassifyListAsync("印制分类", schSerId, name);
|
|
|
|
public async Task<List<CategoryItem>> YZBMListAsync(string schSerId, string name)
|
|
=> await QueryClassifyListAsync("印制版面", schSerId, name);
|
|
|
|
private async Task<List<CategoryItem>> QueryClassifyListAsync(string typeName, string schSerId, string name)
|
|
{
|
|
var query = await _dic.FindAsync(m => m.typeName == typeName);
|
|
|
|
if (!string.IsNullOrEmpty(schSerId))
|
|
{
|
|
query = query.Where(m => m.Schserid == schSerId || m.Schserid == null || m.Schserid == "").ToList();
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(name))
|
|
{
|
|
query = query.Where(m => m.Name != null && m.Name.IndexOf(name) >= 0).ToList();
|
|
}
|
|
|
|
return query
|
|
.OrderBy(x => string.IsNullOrEmpty(x.Des) ? 999 : DictionaryTypeHelper.ParseSort(x.Des))
|
|
.Select(item => new CategoryItem
|
|
{
|
|
SerID = item.SerID,
|
|
CodeID = item.CodeID,
|
|
Name = item.Name,
|
|
Des = item.Des,
|
|
Enable = item.Enable,
|
|
Sort = item.Sort,
|
|
SchSerID = item.Schserid,
|
|
UserSchSerID = schSerId,
|
|
_disabled = string.IsNullOrEmpty(item.Schserid)
|
|
})
|
|
.ToList();
|
|
}
|
|
|
|
public async Task DeleteDicAsync(decimal[] ids)
|
|
{
|
|
if (ids == null || ids.Length == 0) throw new DException("ids is not null");
|
|
|
|
var items = await _dic.FindAsync(m => ids.Contains(m.SerID));
|
|
if (items.Count == 0) throw new DException("未找到要删除的分类!");
|
|
|
|
foreach (var item in items)
|
|
{
|
|
var used = await _doc.AnyAsync(m => m.DPType == item.CodeID);
|
|
if (used) throw new DException("该类别下有使用记录无法删除!");
|
|
}
|
|
|
|
foreach (var item in items)
|
|
{
|
|
await _dic.RemoveAsync(item);
|
|
}
|
|
|
|
await _dic.SaveChangesAsync();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 公共类别
|
|
|
|
public async Task<List<DictionaryTypeItem>> DictionaryTypeListAsync(string schSerId, string name, bool showAll, string typeId)
|
|
{
|
|
var resultList = await _dic.FindAsync(m => m.typeID == typeId && m.Enable == 1);
|
|
|
|
if (!string.IsNullOrEmpty(schSerId))
|
|
{
|
|
resultList = resultList.Where(m => m.Schserid == schSerId || m.Schserid == null || m.Schserid == "").ToList();
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(name))
|
|
{
|
|
resultList = resultList.Where(m => m.Name != null && m.Name.IndexOf(name) >= 0).ToList();
|
|
}
|
|
|
|
var ordList = await _ord.FindAsync(a => a.SchSerID == schSerId);
|
|
|
|
var items = resultList.Select(item => new DictionaryTypeItem
|
|
{
|
|
Code = item.Code,
|
|
SerID = item.SerID,
|
|
CodeID = item.CodeID,
|
|
Name = item.Name,
|
|
Des = item.Des,
|
|
Enable = item.Enable,
|
|
Sort = item.Sort,
|
|
SchSerID = item.Schserid,
|
|
UserSchSerID = schSerId,
|
|
_disabled = string.IsNullOrEmpty(item.Schserid),
|
|
Status = false,
|
|
Open = ordList.FirstOrDefault(a => a.DicSerID == (int)item.SerID)?.Open ?? true,
|
|
Ord = ordList.FirstOrDefault(a => a.DicSerID == (int)item.SerID)?.Ord
|
|
?? (string.IsNullOrEmpty(item.Des) ? 999 : DictionaryTypeHelper.ParseSort(item.Des)),
|
|
Path = item.Path
|
|
})
|
|
.OrderBy(a => a.Ord)
|
|
.ToList();
|
|
|
|
if (!showAll)
|
|
{
|
|
items = items.Where(a => a.Open).ToList();
|
|
}
|
|
|
|
return items;
|
|
}
|
|
|
|
public async Task DeleteDictionaryTypeAsync(string[] ids)
|
|
{
|
|
if (ids == null || ids.Length == 0) throw new DException("ids is not null");
|
|
|
|
var items = await _dic.FindAsync(m => ids.Contains(m.SerID.ToString()));
|
|
foreach (var item in items)
|
|
{
|
|
item.Enable = 3;
|
|
}
|
|
|
|
await _dic.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task SetDictionaryOrdAsync(string schSerId, int dicSerId, bool show)
|
|
{
|
|
var obj = await _ord.FirstOrDefaultAsync(m => m.DicSerID == dicSerId && m.SchSerID == schSerId);
|
|
if (obj == null)
|
|
{
|
|
await _ord.AddAsync(new Common_DictionaryOrd
|
|
{
|
|
DicSerID = dicSerId,
|
|
Open = show,
|
|
SchSerID = schSerId
|
|
});
|
|
}
|
|
else
|
|
{
|
|
obj.Open = show;
|
|
await _ord.UpdateAsync(obj);
|
|
}
|
|
|
|
await _ord.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task OrderDicAsync(string ids, string schSerId)
|
|
{
|
|
if (string.IsNullOrEmpty(ids)) throw new DException("ids is not null");
|
|
|
|
var ssids = ids.Split(',').Select(a => int.Parse(a)).ToArray();
|
|
var list = await _ord.FindAsync(m => m.SchSerID == schSerId);
|
|
|
|
var i = 0;
|
|
foreach (var id in ssids)
|
|
{
|
|
var obj = list.FirstOrDefault(a => a.DicSerID == id && a.SchSerID == schSerId);
|
|
if (obj == null)
|
|
{
|
|
await _ord.AddAsync(new Common_DictionaryOrd
|
|
{
|
|
DicSerID = id,
|
|
Open = true,
|
|
SchSerID = schSerId,
|
|
Ord = i
|
|
});
|
|
}
|
|
else
|
|
{
|
|
obj.Ord = i;
|
|
await _ord.UpdateAsync(obj);
|
|
}
|
|
|
|
i++;
|
|
}
|
|
|
|
await _ord.SaveChangesAsync();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 文印资源开关 / 结果链接 / 待审角标
|
|
|
|
/// <summary>
|
|
/// 结果链接:旧实现调用资源平台 ziyuan 的 /SaveResource/Batch 生成分享链接,
|
|
/// 新项目未接入资源平台,按「未配置 ziyuan」的旧分支降级返回 false。
|
|
/// </summary>
|
|
public Task<object> GetResultUrlAsync(int dataId, int uid, int schId, string schSerId)
|
|
{
|
|
return Task.FromResult<object>(false);
|
|
}
|
|
|
|
public async Task<bool> GetSchZyBitAsync(string schSerId)
|
|
{
|
|
// 旧实现仅在 ziyuan 配置存在时返回库值、否则 false;新项目未接入 ziyuan,直接返回库内开关值。
|
|
var bit = await _zybit.FirstOrDefaultAsync(a => a.SchSerID == schSerId);
|
|
return bit?.ziyuanbit ?? true;
|
|
}
|
|
|
|
public async Task SetSchZyBitAsync(string schSerId, bool zyBit)
|
|
{
|
|
var obj = await _zybit.FirstOrDefaultAsync(a => a.SchSerID == schSerId);
|
|
if (obj == null)
|
|
{
|
|
await _zybit.AddAsync(new WY_SchZyBit { SchSerID = schSerId, ziyuanbit = zyBit });
|
|
}
|
|
else
|
|
{
|
|
obj.ziyuanbit = zyBit;
|
|
await _zybit.UpdateAsync(obj);
|
|
}
|
|
|
|
await _zybit.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task<int> GetShnheCountAsync(string userId, string schSerId)
|
|
{
|
|
if (!int.TryParse(userId, out var userid))
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
var docs = await _doc.FindAsync(a => a.SchSerID == schSerId && a.DocStatus == "0");
|
|
var fixedGroupIds = (await _groupuser.FindAsync(b => b.userid == userid))
|
|
.Select(b => b.usergroup).Where(g => g.HasValue).Select(g => g.Value).ToList();
|
|
var freeGroupIds = (await _freegroup.FindAsync(b => b.userid == userid))
|
|
.Select(b => b.usergroup).Where(g => g.HasValue).Select(g => g.Value).ToList();
|
|
|
|
var result = new HashSet<decimal>();
|
|
foreach (var a in docs)
|
|
{
|
|
bool match = false;
|
|
|
|
// 固定流程:DocStep 命中本人组
|
|
if (a.flowid != null && a.zhipai == null && a.DocStep.HasValue && fixedGroupIds.Contains(a.DocStep.Value))
|
|
{
|
|
match = true;
|
|
}
|
|
|
|
// 指派:zhipai 含本人
|
|
if (!match && a.zhipai != null && a.flowid != null && a.zhipai.Contains(userId))
|
|
{
|
|
match = true;
|
|
}
|
|
|
|
// 自由流程:freestepid 命中本人自由组
|
|
if (!match && a.freestepid.HasValue && a.freestepid.Value > 0 && freeGroupIds.Contains(a.freestepid.Value))
|
|
{
|
|
match = true;
|
|
}
|
|
|
|
if (match)
|
|
{
|
|
result.Add(a.SerID);
|
|
}
|
|
}
|
|
|
|
return result.Count;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|