- A+
所属分类:.NET技术
C#TMS系统代码-业务页面ShippingNotice学习
学一个业务页面,ok,领导开完会就被裁掉了,很突然啊,他收拾东西的时候我还以为他要旅游提前请假了,还在寻思为什么回家连自己买的几箱饮料都要叫跑腿带走,怕被偷吗?还好我在他开会之前拿了两瓶芬达
感觉感觉前面的BaseCity差不太多,这边的分页查询复杂一点,其他的当个加强记忆了
Service页面
//跟BaseCity页面的差不多 [ApiDescriptionSettings(Tag = "Business", Name = "ShippingNotice", Order = 200)] [Route("api/TMS/Business/[controller]")] public class TmsBusiShippingNoticeService : ITmsBusiShippingNoticeService, IDynamicApiController, ITransient { private readonly ISqlSugarRepository<TmsBusiShippingNoticeEntity> _repository; private readonly IDataInterfaceService _dataInterfaceService; private readonly IUserManager _userManager; public TmsBusiShippingNoticeService( ISqlSugarRepository<TmsBusiShippingNoticeEntity> tmsBusiShippingNoticeRepository, IDataInterfaceService dataInterfaceService, ISqlSugarClient context, IUserManager userManager) { _repository = tmsBusiShippingNoticeRepository; _dataInterfaceService = dataInterfaceService; _userManager = userManager; } //各种方法 ...... }
获取单个ShippingNotice
[HttpGet("{id}")] public async Task<dynamic> GetInfo(string id) { //BaseCity那边更简单一点_repository.FirstOrDefaultAsync(x => x.Id == id)).Adapt<TmsBaseCityInfoOutput>(); return await _repository.Context.Queryable<TmsBusiShippingNoticeEntity>() .Where(it => it.Id == id) .Select(it => new TmsBusiShippingNoticeInfoOutput { //需要处理数据 id = it.Id, ...... }).FirstAsync(); }
查询ShippingNotice分页List
[HttpGet("")] public async Task<dynamic> GetList([FromQuery] TmsBusiShippingNoticeListQueryInput input) { //获取时间参数 List<DateTime> PlanDateList = input.planDate?.Split(',').ToObject<List<DateTime>>(); DateTime? SPlanDate = PlanDateList?.First(); DateTime? EPlanDate = PlanDateList?.Last(); //数据权限 //522839 这个id是直接数据库查了之后放在这里的? //id为表的主键 var authorizeWhere = new List<IConditionalModel>(); authorizeWhere = await _userManager.GetConditionAsync<TmsBusiShippingNoticeListOutput>("522839", "it.F_Id"); //获取登录人CompanyCode 类型List<string>,管理员可以看全部 var loginUserCompany = new List<string>(); if (!_userManager.IsAdministrator) { loginUserCompany = await _repository.Context.Queryable<TmsBaseCompanyEmployeeEntity>().Where(x => x.DeleteMark == null && x.EnabledMark == 1 && x.UserId == _userManager.UserId).GroupBy(x => x.CompanyCode).Select(x => x.CompanyCode).ToListAsync(); } //查询主表然后左连接明细,我猜应该有(1+n)条数据 var querywherr = _repository.Context.Queryable<TmsBusiShippingNoticeEntity, TmsBusiShippingNoticeDetailEntity>((it, b) => new object[]{ JoinType.Left,it.CRMNo==b.CRMNo }) .Where(it => it.DeleteMark == null) //添加数据权限 .Where(authorizeWhere) //只查询当前登录人绑定的公司编码数据 .WhereIF(!_userManager.IsAdministrator, it => loginUserCompany.Contains(it.CompanyNo)) //添加时间查询 .WhereIF(!string.IsNullOrEmpty(input.planDate), it => SqlFunc.Between(it.PlanDate, SPlanDate.ParseToDateTime("yyyy-MM-dd 00:00:00"), EPlanDate.ParseToDateTime("yyyy-MM-dd 23:59:59"))) //一大堆查询条件 ...... .WhereIF(!string.IsNullOrEmpty(input.keyword), it => it.CRMNo.Contains(input.keyword) || it.SysType.Contains(input.keyword) || it.CustomerCode.Contains(input.keyword) || it.CustomerName.Contains(input.keyword) || it.Status.ToString().Contains(input.keyword)); //返回由SqlSugar生成的SQL语句字符串 var sd = querywherr.ToSql().Key; //groupby成主表数据 var query = querywherr.GroupBy((it, b) => new { it.Id, ...... }) //转成输出类 .Select((it, b) => new TmsBusiShippingNoticeListOutput { id = it.Id, //返回明细的F_ShippingNo用'/'做分隔符, xxx1/xxx2/xxx3 shippingNo = SqlFunc.MappingColumn(default(string), $@"STUFF((select '/'+F_ShippingNo from tms_busi_shipping_notice_detail where F_CRMNo =it.F_CRMNo AND F_DeleteMark is null group by F_ShippingNo FOR xml path('')),1,1,'')"), //运货方式,取数据字典 transportMethod = SqlFunc.Subqueryable<DictionaryDataEntity>().Where(w => it.TransportMethod == w.EnCode && w.DictionaryTypeId == "501598831910").Select(w => w.FullName), //转中文前端显示 '是' '否' isShd = SqlFunc.IF(it.IsSHD == 1).Return("Y").End("N"), ....... //汇总明细数量、金额 qty = SqlFunc.AggregateSum(b.Qty), amount = SqlFunc.AggregateSum(b.Amount) }) .MergeTable(); //聚合数据的查询 query.WhereIF(!string.IsNullOrEmpty(input.shippingNo), it => it.shippingNo.Contains(input.shippingNo)) .WhereIF(!string.IsNullOrEmpty(input.qtyMin) && !string.IsNullOrEmpty(input.qtyMax), it => SqlFunc.Between(it.qty, input.qtyMin, input.qtyMax)) .WhereIF(!string.IsNullOrEmpty(input.amountMin) && !string.IsNullOrEmpty(input.amountMax), it => SqlFunc.Between(it.amount, input.amountMin, input.amountMax)); //添加排序 if (!string.IsNullOrEmpty(input.sidx)) { query.OrderBy(input.sidx + " " + input.sort); } else { query.OrderBy(it => it.creatorTime, OrderByType.Desc); } //转成PageResult var data = await query.ToPagedListAsync(input.currentPage, input.pageSize); return PageResult<TmsBusiShippingNoticeListOutput>.SqlSugarPageResult(data); }
ShippingNotice新增
没有新增,这边的发货通知单都是从SAP上传过来,后面去了解一下传递接口
同理也没有删除功能
ShippingNotice修改
[HttpPut("{id}")] public async Task Update(string id, [FromBody] TmsBusiShippingNoticeUpInput input) { //转一下类型 var entity = input.Adapt<TmsBusiShippingNoticeEntity>(); //Updateable(修改对象) -> UpdateColumns(it => new {it.数据列}) -> ExecuteCommandAsync() var isOk = await _repository.Context.Updateable(entity).UpdateColumns(it => new { it.CRMNo, ...... it.CostCenterName, }).ExecuteCommandAsync(); if (!(isOk > 0)) throw Oops.Oh(ErrorCode.COM1001); }
批量修改ShippingNotice(锁定)
//指示方法不应被视为可通过URL访问的操作方法 [NonAction] public async Task LockOrReleaseShippingNotice(List<string> shippingNoArray, int lockFlag) { //获取要修改的List var entity = await _repository.Context.Queryable<TmsBusiShippingNoticeEntity>().Where(x => shippingNoArray.Contains(x.CRMNo)).ToListAsync(); if (entity.Count > 0) { //批量修改 entity.ForEach(x => { x.LockFlag = lockFlag; x.LastModifyTime = DateTime.Now; x.LastModifyUserId = _userManager.UserId; }); var isOk = await _repository.Context.Updateable(entity).UpdateColumns(x => new { x.LockFlag, x.LastModifyTime, x.LastModifyUserId }).ExecuteCommandAsync(); } }
导出
//和BaseCity几乎一摸一样的代码,除了转pararmList的字符串不一样,为什么不直接写个通用方法算了??? [HttpGet("Actions/Export")] public async Task<dynamic> Export([FromQuery] TmsBusiShippingNoticeListQueryInput input) { var exportData = new List<TmsBusiShippingNoticeListOutput>(); if (input.dataType == 0) exportData = Clay.Object(await GetList(input)).Solidify<PageResult<TmsBusiShippingNoticeListOutput>>().list; else exportData = await GetNoPagingList(input); List<ParamsModel> paramList = "[{"value":"SAP单号","field":"shippingNo"},{"value":"发货通知单单号","field":"cRMNo"},{"value":"业务类型","field":"sysType"}, ....... {"value":"发货数量","field":"qty"},{"value":"发货总金额","field":"amount"}]".ToList<ParamsModel>(); ExcelConfig excelconfig = new ExcelConfig(); excelconfig.FileName = "发货通知单.xls"; excelconfig.HeadFont = "微软雅黑"; excelconfig.HeadPoint = 10; excelconfig.IsAllSizeColumn = true; excelconfig.ColumnModel = new List<ExcelColumnModel>(); foreach (var item in input.selectKey.Split(',').ToList()) { var isExist = paramList.Find(p => p.field == item); if (isExist != null) excelconfig.ColumnModel.Add(new ExcelColumnModel() { Column = isExist.field, ExcelColumn = isExist.value }); } var addPath = FileVariable.TemporaryFilePath + excelconfig.FileName; ExcelExportHelper<TmsBusiShippingNoticeListOutput>.Export(exportData, excelconfig, addPath); var fileName = _userManager.UserId + "|" + addPath + "|xls"; return new { name = excelconfig.FileName, url = "/api/File/Download?encryption=" + DESCEncryption.Encrypt(fileName, "SHZY") }; }