using System.Collections; using DS.Module.Core; using DS.Module.Core.Extensions; using DS.Module.User; using DS.WMS.Common.Enum; using DS.WMS.Core.System.Dtos; using DS.WMS.Core.System.Entity; using DS.WMS.Core.System.Interface; using Microsoft.Extensions.DependencyInjection; using SqlSugar; namespace DS.WMS.Core.System.Method; /// /// /// public class CompanyService : ICompanyService { private readonly IServiceProvider _serviceProvider; private readonly ISqlSugarClient db; private readonly IUser user; /// /// /// /// public CompanyService(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; db = _serviceProvider.GetRequiredService(); user = _serviceProvider.GetRequiredService(); } /// /// 获取客户信息 /// /// public DataResult GetClientInfo() { var userId = user.UserId; var companyId = db.Queryable().First(x => x.Gid == Guid.Parse(userId)).CompanyId; var licenseFiles = db.Queryable().Where(x => x.PID == companyId && x.FILETYPE == "营业执照") .Select(it => new fileinfo { FileName = it.FILENAME, FilePath = it.IMGPATH }).ToArray(); var cardFiles = db.Queryable().Where(x => x.PID == companyId && x.FILETYPE == "法人身份证") .Select(it => new fileinfo { FileName = it.FILENAME, FilePath = it.IMGPATH }).ToArray(); var data = db.Queryable() .Where(x => x.GID == companyId) .Select() .Mapper(it => { //只能写在Select后面 it.licensefiles = licenseFiles; it.cardfiles = cardFiles; }) .First(); return DataResult.Successed("获取数据成功", data); } /// /// 维护客户公司信息 /// /// /// public DataResult EditClientCompany(CompanyInput model) { var exitCompany = db.Queryable().First(x=>x.GID == model.GID); if (exitCompany.AuditStatus == AuditStatus.Approve.ToEnumInt() || exitCompany.AuditStatus == AuditStatus.Auditing.ToEnumInt()) { return DataResult.Failed("审核通过或待审批状态不能提交!"); } try { //开启事务 db.Ado.BeginTran(); var company = model.MapTo(); db.Updateable(company).IgnoreColumns(x=>x.LOGINPASSWORD).ExecuteCommand(); var gid = model.GID; //写入 #region 处理文件 #region 处理法人身份证 //先删除 法人身份证 var existCards = db.Queryable().Where(x => x.PID == gid && x.FILETYPE == "法人身份证").Select(n=>n.IMGPATH).ToArray(); var cardFiles = model.cardfiles.Select(x => x.FilePath).ToArray(); IEnumerable delCards = existCards.AsQueryable().Except(cardFiles); if (delCards.Count()>0) { foreach (var item in delCards) { var existInfo = db.Queryable() .Where(x => x.PID == gid && x.IMGPATH == item).First(); db.Deleteable(existInfo).ExecuteCommand(); } } //2.添加新的法人身份证 IEnumerable addCards = cardFiles.AsQueryable().Except(existCards); if (addCards.Count()>0) { foreach (var item in addCards) { var infoFile = new INFO_FILES { GID = Guid.NewGuid(), PID = gid, FILENAME = model.cardfiles.Where(x=>x.FilePath ==item).Select(x=>x.FileName).First(), IMGPATH = item, FILETYPE = "法人身份证", CORPID = gid.ToString(), CreateDate = DateTime.Now, ModifyDate = DateTime.Now, UPLOADEMPLY = "" }; db.Insertable(infoFile).ExecuteCommand(); } } #endregion #region 处理营业执照 //先删除 营业执照 var existLicenses = db.Queryable().Where(x => x.PID == gid && x.FILETYPE == "营业执照").Select(n=>n.IMGPATH).ToArray(); var licenseFiles = model.licensefiles.Select(x => x.FilePath).ToArray(); IEnumerable delLicenses = existLicenses.AsQueryable().Except(licenseFiles); if (delLicenses.Count()>0) { foreach (var item in delLicenses) { var existInfo = db.Queryable() .Where(x => x.PID == gid && x.IMGPATH == item).First(); db.Deleteable(existInfo).ExecuteCommand(); } } //2.添加新的营业执照 IEnumerable addLicenses = licenseFiles.AsQueryable().Except(existLicenses); if (addLicenses.Count()>0) { foreach (var item in addLicenses) { var infoFile = new INFO_FILES { GID = Guid.NewGuid(), PID = gid, FILENAME = model.licensefiles.Where(x=>x.FilePath ==item).Select(x=>x.FileName).First(), IMGPATH = item, FILETYPE = "营业执照", CORPID = gid.ToString(), CreateDate = DateTime.Now, ModifyDate = DateTime.Now, UPLOADEMPLY = "" }; db.Insertable(infoFile).ExecuteCommand(); } } #endregion #endregion db.Ado.CommitTran(); return DataResult.Successed("更新成功!"); } catch (Exception ex) { db.Ado.RollbackTran(); return DataResult.Failed("更新失败!" + ex); } } /// /// 提交审核 /// /// /// public DataResult SubmitCompany(string id) { var gid = Guid.Parse(id); //写入 var exitCompany = db.Queryable().First(x=>x.GID == gid); if (exitCompany == null) { return DataResult.Failed("公司信息不存在,请先保存再提交!"); } if (exitCompany.AuditStatus == AuditStatus.Approve.ToEnumInt() || exitCompany.AuditStatus == AuditStatus.Auditing.ToEnumInt()) { return DataResult.Failed("审核通过或待审批状态不能提交!"); } var licensefiles = db.Queryable().Where(x => x.PID == gid && x.FILETYPE =="营业执照").ToList(); if (licensefiles.Count() == 0) { return DataResult.Failed("营业执照认证资料未上传不能提交!"); } var cardfiles = db.Queryable().Where(x => x.PID == gid && x.FILETYPE =="法人身份证").ToList(); if (cardfiles.Count() == 0) { return DataResult.Failed("营业执照认证资料未上传不能提交!"); } //更新状态为待审批 exitCompany.AuditStatus = AuditStatus.Auditing.ToEnumInt(); db.Updateable(exitCompany).ExecuteCommand(); return DataResult.Successed("提交成功"); } }