123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- using AutoMapper;
- using OASystem.Domain;
- using OASystem.Domain.Dtos.Groups;
- using OASystem.Domain.Entities.Groups;
- using OASystem.Domain.ViewModels.Groups;
- using OASystem.Infrastructure.Tools;
- namespace OASystem.Infrastructure.Repositories.Groups
- {
- /// <summary>
- /// 签证流程步骤仓储
- /// </summary>
- public class VisaProcessRepository : BaseRepository<Grp_VisaProcessSteps, Grp_VisaProcessSteps>
- {
- private readonly IMapper _mapper;
- public VisaProcessRepository(SqlSugarClient sqlSugar, IMapper mapper)
- : base(sqlSugar)
- {
- _mapper = mapper;
- }
- /// <summary>
- /// 创建签证流程步骤
- /// </summary>
- /// <param name="groupId"></param>
- /// <param name="createUderId"></param>
- /// <returns></returns>
- public async Task<Result> Create(int createUderId,int groupId)
- {
- //团组有效验证
- var groupIsValid = await _sqlSugar.Queryable<Grp_DelegationInfo>()
- .Where(g => g.Id == groupId && g.IsDel == 0)
- .AnyAsync();
- if (!groupIsValid)
- {
- return new Result(400, "团组无效,无法创建签证流程步骤。");
- }
- var existingSteps = await _sqlSugar.Queryable<Grp_VisaProcessSteps>()
- .Where(s => s.GroupId == groupId && s.IsDel == 0)
- .AnyAsync();
- if (existingSteps)
- {
- return new Result(400, "该团组的签证流程步骤已存在,无法重复创建。");
- }
- var steps = Grp_VisaProcessSteps.StepsInit(groupId, createUderId);
- var add = await _sqlSugar.Insertable(steps).ExecuteCommandAsync();
- if (add < 1) return new Result(400, "签证流程步骤创建失败。");
- return new Result(200,"Success");
- }
- /// <summary>
- /// 签证流程 Info
- /// </summary>
- /// <param name="dto"></param>
- /// <param name="createUderId"></param>
- /// <returns></returns>
- public async Task<Result> Info(VisaProcessInfoByGroupIdDto dto)
- {
- //团组有效验证
- //var groupIsValid = await _sqlSugar.Queryable<Grp_DelegationInfo>()
- // .Where(g => g.Id == dto.GroupId && g.IsDel == 0)
- // .AnyAsync();
- //if (!groupIsValid)
- //{
- // return new Result(400, "团组无效,无法查询签证流程步骤。");
- //}
- var query = await _sqlSugar.Queryable<Grp_VisaProcessSteps>()
- .Where(s => s.GroupId == dto.GroupId && s.IsDel == 0)
- .OrderBy(s => s.Step)
- .ToListAsync();
- var infos = query.Select(s => new
- {
- s.Id,
- s.GroupId,
- s.Step,
- s.DataType,
- s.TypedValue,
- //s.StoreVal,
- s.IsCompleted,
- s.AttachUrl,
- s.TypedFileNameValue,
- s.Remark
- }).ToList();
- string msg = "Success";
- //如果不存在,则返回默认数据
- if (infos == null || infos.Count < 1)
- {
- infos = Grp_VisaProcessSteps.StepsInit(dto.GroupId, 208).Select(s => new {
- s.Id,
- s.GroupId,
- s.Step,
- s.DataType,
- s.TypedValue,
- //s.StoreVal,
- s.IsCompleted,
- s.AttachUrl,
- s.TypedFileNameValue,
- s.Remark
- }).ToList();
- msg = "签证流程步骤信息不存在,展示默认数据。";
- }
- //数据按照类型处理
- var datas = new List<object>();
- var view = new VisaProcessStepsInfoView();
- foreach (var item in infos)
- {
- if (item.DataType == "string")
- {
- var info = new VisaProcessStepsInfoByStringView
- {
- Id = item.Id,
- GroupId = item.GroupId,
- Step = item.Step,
- DataType = item.DataType,
- TypedValue = item.TypedValue == null ? "" : item.TypedValue.ToString(),
- //StoreVal = item.StoreVal,
- IsCompleted = item.IsCompleted,
- AttachUrl = item.TypedFileNameValue,
- Remark = item.Remark
- };
- if (item.Step == 1) view.Step1 = info;
- else if (item.Step == 2) view.Step2 = info;
- else if (item.Step == 3) view.Step3 = info;
- else if (item.Step == 4) view.Step4 = info;
- else if (item.Step == 5) view.Step5 = info;
- else if (item.Step == 8) view.Step8 = info;
- datas.Add(info);
- }
- else if (item.DataType == "bool")
- {
- bool boolVal = false;
- if (item.TypedValue != null)
- {
- boolVal = (bool)item.TypedValue;
- }
- var info = new VisaProcessStepsInfoByBoolView
- {
- Id = item.Id,
- GroupId = item.GroupId,
- Step = item.Step,
- DataType = item.DataType,
- TypedValue = boolVal,
- IsCompleted = item.IsCompleted,
- AttachUrl = item.TypedFileNameValue,
- Remark = item.Remark
- };
- if (item.Step == 6) view.Step6 = info;
- datas.Add(info);
- }
- else if (item.DataType == "string[]")
- {
- var listVal = new List<string>();
- var contnet = new VisaProcessSteps7Content() { IsSelected = false };
- if (item.TypedValue != null)
- {
- listVal = item.TypedValue switch
- {
- List<string> stringList => stringList,
- IEnumerable<string> stringEnumerable => stringEnumerable.ToList(),
- string str => new List<string> { str },
- IEnumerable<object> objectEnumerable => objectEnumerable.Select(x => x?.ToString() ?? "").ToList(),
- _ => new List<string> { item.TypedValue.ToString() ?? "" }
- };
- if (listVal != null && listVal.Count > 0)
- {
- contnet.IsSelected = bool.TryParse(CommonFun.GetValueOrDefault(listVal,0), out _);
- contnet.ProjectedDate = CommonFun.GetValueOrDefault(listVal, 1);
- }
- }
- var info = new VisaProcessStepsInfoByListView
- {
- Id = item.Id,
- GroupId = item.GroupId,
- Step = item.Step,
- DataType = item.DataType,
- TypedValue = contnet,
- IsCompleted = item.IsCompleted,
- AttachUrl = item.TypedFileNameValue,
- Remark = item.Remark
- };
- if (item.Step == 7) view.Step7 = info;
- datas.Add(info);
- }
- }
- return new Result(200, msg, view);
- }
- /// <summary>
- /// 修改签证流程步骤
- /// </summary>
- /// <param name="groupId"></param>
- /// <param name="createUderId"></param>
- /// <returns></returns>
- public async Task<Result> Update(Grp_VisaProcessSteps info)
- {
- var update = await _sqlSugar.Updateable<Grp_VisaProcessSteps>()
- .SetColumns(s => new Grp_VisaProcessSteps
- {
- StoreVal = info.StoreVal,
- //AttachUrl = info.AttachUrl,
- //IsCompleted = info.IsCompleted,
- LastUpdateUserId = info.LastUpdateUserId,
- LastUpdateTime = DateTime.Now,
- Remark = info.Remark
- })
- .Where(s => s.Id == info.Id && s.IsDel == 0)
- .ExecuteCommandAsync();
- if (update < 1) return new Result(400, "更新失败!");
- return new Result(200, "Success");
- }
- /// <summary>
- /// 批量修改top4Steps
- /// </summary>
- /// <param name="infos"></param>
- /// <returns></returns>
- public async Task<Result> UpdateBatchTop4Step(int groupId,int currUserId)
- {
- var steps = new List<int>() {
- 1, //签证启动日
- 2, //分配工作
- 3, //送外办时间
- 4, //预计出签时间
- };
- var visaSteps = await _sqlSugar.Queryable<Grp_VisaProcessSteps>()
- .Where(s => s.GroupId == groupId && s.IsDel == 0 && steps.Contains(s.Step))
- .ToListAsync();
- if (visaSteps.Count < 1) return new Result(400, "签证流程信息不存在。");
- //倒推表信息
- var invertedInfo = await _sqlSugar.Queryable<Grp_InvertedList>()
- .Where(i => i.DiId == groupId && i.IsDel == 0)
- .FirstAsync();
- if (invertedInfo == null) return new Result(400, "倒推表信息不存在。");
- //设置操作人和时间
- foreach (var item in visaSteps)
- {
- //默认确认完成
- item.IsCompleted = true;
- item.LastUpdateUserId = currUserId;
- item.LastUpdateTime = DateTime.Now;
- }
- //step=1 设置启动日值
- visaSteps.FirstOrDefault(x => x.Step == 1).TypedValue = DateTime.Now.ToString("yyyy-MM-dd");
- //step=2 分配工作
- visaSteps.FirstOrDefault(x => x.Step == 2).TypedValue = invertedInfo.IssueApprovalDt;
- //step=3 送外办时间
- visaSteps.FirstOrDefault(x => x.Step == 3).TypedValue = invertedInfo.SendVisaDt;
- //step=4 预计出签时间
- visaSteps.FirstOrDefault(x => x.Step == 4).TypedValue = invertedInfo.IssueVisaDt;
-
- var update = await _sqlSugar.Updateable(visaSteps)
- .UpdateColumns(it => new { it.StoreVal, it.LastUpdateUserId,it.LastUpdateTime })
- .ExecuteCommandAsync();
- if (update < 1) return new Result(400, "更新失败!");
- return new Result(200, "Success");
- }
- /// <summary>
- /// 设置已完成的步骤
- /// </summary>
- /// <param name="groupId"></param>
- /// <returns></returns>
- public async Task<Result> SetCompleted(int id,int currUserId)
- {
- //步骤信息验证
- var stepInfo = await _sqlSugar.Queryable<Grp_VisaProcessSteps>()
- .Where(s => s.Id == id && s.IsDel == 0 && s.IsCompleted)
- .FirstAsync();
- if (stepInfo != null) return new Result(400, "步骤信息已完成,无法重复设置。");
- var update = await _sqlSugar.Updateable<Grp_VisaProcessSteps>()
- .SetColumns(s => new Grp_VisaProcessSteps
- {
- IsCompleted = true,
- LastUpdateUserId = currUserId,
- LastUpdateTime = DateTime.Now
- })
- .Where(s => s.Id == id && s.IsDel == 0 && !s.IsCompleted)
- .ExecuteCommandAsync();
- if (update < 1) return new Result(400, "状态设置失败!");
- return new Result(200, "Success");
- }
- }
- }
|