翼度科技»论坛 编程开发 .net 查看内容

C#TMS系统学习(ShippingNotice页面)

3

主题

3

帖子

9

积分

新手上路

Rank: 1

积分
9
C#TMS系统代码-业务页面ShippingNotice学习

学一个业务页面,ok,领导开完会就被裁掉了,很突然啊,他收拾东西的时候我还以为他要旅游提前请假了,还在寻思为什么回家连自己买的几箱饮料都要叫跑腿带走,怕被偷吗?还好我在他开会之前拿了两瓶芬达
感觉感觉前面的BaseCity差不太多,这边的分页查询复杂一点,其他的当个加强记忆了
Service页面
  1. //跟BaseCity页面的差不多
  2. [ApiDescriptionSettings(Tag = "Business", Name = "ShippingNotice", Order = 200)]
  3. [Route("api/TMS/Business/[controller]")]
  4. public class TmsBusiShippingNoticeService : ITmsBusiShippingNoticeService, IDynamicApiController, ITransient
  5. {
  6.     private readonly ISqlSugarRepository<TmsBusiShippingNoticeEntity> _repository;
  7.     private readonly IDataInterfaceService _dataInterfaceService;
  8.     private readonly IUserManager _userManager;
  9.     public TmsBusiShippingNoticeService(
  10.         ISqlSugarRepository<TmsBusiShippingNoticeEntity> tmsBusiShippingNoticeRepository,
  11.         IDataInterfaceService dataInterfaceService,
  12.         ISqlSugarClient context,
  13.         IUserManager userManager)
  14.     {
  15.         _repository = tmsBusiShippingNoticeRepository;
  16.         _dataInterfaceService = dataInterfaceService;
  17.         _userManager = userManager;
  18.     }
  19.     //各种方法
  20.     ......
  21. }
复制代码
获取单个ShippingNotice
  1. [HttpGet("{id}")]
  2. public async Task<dynamic> GetInfo(string id)
  3. {
  4.     //BaseCity那边更简单一点_repository.FirstOrDefaultAsync(x => x.Id == id)).Adapt<TmsBaseCityInfoOutput>();
  5.     return await _repository.Context.Queryable<TmsBusiShippingNoticeEntity>()
  6.         .Where(it => it.Id == id)
  7.         .Select(it => new TmsBusiShippingNoticeInfoOutput
  8.         {
  9.             //需要处理数据
  10.             id = it.Id,
  11.             ......
  12.         }).FirstAsync();
  13. }
复制代码
查询ShippingNotice分页List
  1. [HttpGet("")]
  2. public async Task<dynamic> GetList([FromQuery] TmsBusiShippingNoticeListQueryInput input)
  3. {   
  4.     //获取时间参数
  5.     List<DateTime> PlanDateList = input.planDate?.Split(',').ToObject<List<DateTime>>();
  6.     DateTime? SPlanDate = PlanDateList?.First();
  7.     DateTime? EPlanDate = PlanDateList?.Last();
  8.     //数据权限
  9.     //522839 这个id是直接数据库查了之后放在这里的?
  10.     //id为表的主键
  11.     var authorizeWhere = new List<IConditionalModel>();
  12.     authorizeWhere = await _userManager.GetConditionAsync<TmsBusiShippingNoticeListOutput>("522839", "it.F_Id");
  13.         //获取登录人CompanyCode 类型List<string>,管理员可以看全部
  14.     var loginUserCompany = new List<string>();
  15.     if (!_userManager.IsAdministrator)
  16.     {
  17.         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();
  18.     }
  19.         //查询主表然后左连接明细,我猜应该有(1+n)条数据
  20.     var querywherr = _repository.Context.Queryable<TmsBusiShippingNoticeEntity, TmsBusiShippingNoticeDetailEntity>((it, b) => new object[]{ JoinType.Left,it.CRMNo==b.CRMNo })
  21.         .Where(it => it.DeleteMark == null)
  22.         //添加数据权限
  23.         .Where(authorizeWhere)
  24.         //只查询当前登录人绑定的公司编码数据
  25.         .WhereIF(!_userManager.IsAdministrator, it => loginUserCompany.Contains(it.CompanyNo))
  26.         //添加时间查询
  27.         .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")))
  28.         //一大堆查询条件
  29.         ......
  30.         .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));
  31.        
  32.     //返回由SqlSugar生成的SQL语句字符串
  33.     var sd = querywherr.ToSql().Key;
  34.     //groupby成主表数据
  35.     var query = querywherr.GroupBy((it, b) => new
  36.     {
  37.         it.Id,
  38.         ......
  39.     })
  40.     //转成输出类
  41.     .Select((it, b) => new TmsBusiShippingNoticeListOutput
  42.     {
  43.         id = it.Id,
  44.         //返回明细的F_ShippingNo用'/'做分隔符, xxx1/xxx2/xxx3
  45.         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,'')"),
  46.         //运货方式,取数据字典
  47.         transportMethod = SqlFunc.Subqueryable<DictionaryDataEntity>().Where(w => it.TransportMethod == w.EnCode && w.DictionaryTypeId == "501598831910").Select(w => w.FullName),
  48.         //转中文前端显示 '是' '否'
  49.         isShd = SqlFunc.IF(it.IsSHD == 1).Return("Y").End("N"),
  50.         .......
  51.         //汇总明细数量、金额
  52.         qty = SqlFunc.AggregateSum(b.Qty),
  53.         amount = SqlFunc.AggregateSum(b.Amount)
  54.     })
  55.     .MergeTable();
  56.         //聚合数据的查询
  57.     query.WhereIF(!string.IsNullOrEmpty(input.shippingNo), it => it.shippingNo.Contains(input.shippingNo))
  58.         .WhereIF(!string.IsNullOrEmpty(input.qtyMin) && !string.IsNullOrEmpty(input.qtyMax), it => SqlFunc.Between(it.qty, input.qtyMin, input.qtyMax))
  59.         .WhereIF(!string.IsNullOrEmpty(input.amountMin) && !string.IsNullOrEmpty(input.amountMax), it => SqlFunc.Between(it.amount, input.amountMin, input.amountMax));
  60.     //添加排序
  61.     if (!string.IsNullOrEmpty(input.sidx))
  62.     {
  63.         query.OrderBy(input.sidx + " " + input.sort);
  64.     }
  65.     else
  66.     {
  67.         query.OrderBy(it => it.creatorTime, OrderByType.Desc);
  68.     }
  69.     //转成PageResult
  70.     var data = await query.ToPagedListAsync(input.currentPage, input.pageSize);
  71.     return PageResult<TmsBusiShippingNoticeListOutput>.SqlSugarPageResult(data);
  72. }
复制代码
ShippingNotice新增

没有新增,这边的发货通知单都是从SAP上传过来,后面去了解一下传递接口
同理也没有删除功能
ShippingNotice修改
  1. [HttpPut("{id}")]
  2. public async Task Update(string id, [FromBody] TmsBusiShippingNoticeUpInput input)
  3. {
  4.     //转一下类型
  5.     var entity = input.Adapt<TmsBusiShippingNoticeEntity>();
  6.     //Updateable(修改对象) -> UpdateColumns(it => new {it.数据列}) -> ExecuteCommandAsync()
  7.     var isOk = await _repository.Context.Updateable(entity).UpdateColumns(it => new
  8.     {
  9.         it.CRMNo,
  10.                 ......
  11.         it.CostCenterName,
  12.     }).ExecuteCommandAsync();
  13.     if (!(isOk > 0)) throw Oops.Oh(ErrorCode.COM1001);
  14. }
复制代码
批量修改ShippingNotice(锁定)
  1. //指示方法不应被视为可通过URL访问的操作方法
  2. [NonAction]
  3. public async Task LockOrReleaseShippingNotice(List<string> shippingNoArray, int lockFlag)
  4. {
  5.     //获取要修改的List
  6.     var entity = await _repository.Context.Queryable<TmsBusiShippingNoticeEntity>().Where(x => shippingNoArray.Contains(x.CRMNo)).ToListAsync();
  7.     if (entity.Count > 0)
  8.     {
  9.         //批量修改
  10.         entity.ForEach(x =>
  11.         {
  12.             x.LockFlag = lockFlag;
  13.             x.LastModifyTime = DateTime.Now;
  14.             x.LastModifyUserId = _userManager.UserId;
  15.         });
  16.         var isOk = await _repository.Context.Updateable(entity).UpdateColumns(x => new { x.LockFlag, x.LastModifyTime, x.LastModifyUserId }).ExecuteCommandAsync();
  17.     }
  18. }
复制代码
导出
  1. //和BaseCity几乎一摸一样的代码,除了转pararmList的字符串不一样,为什么不直接写个通用方法算了???
  2. [HttpGet("Actions/Export")]
  3. public async Task<dynamic> Export([FromQuery] TmsBusiShippingNoticeListQueryInput input)
  4. {
  5.     var exportData = new List<TmsBusiShippingNoticeListOutput>();
  6.     if (input.dataType == 0)
  7.         exportData = Clay.Object(await GetList(input)).Solidify<PageResult<TmsBusiShippingNoticeListOutput>>().list;
  8.     else
  9.         exportData = await GetNoPagingList(input);
  10.     List<ParamsModel> paramList = "[{"value":"SAP单号","field":"shippingNo"},{"value":"发货通知单单号","field":"cRMNo"},{"value":"业务类型","field":"sysType"}, ....... {"value":"发货数量","field":"qty"},{"value":"发货总金额","field":"amount"}]".ToList<ParamsModel>();
  11.     ExcelConfig excelconfig = new ExcelConfig();
  12.     excelconfig.FileName = "发货通知单.xls";
  13.     excelconfig.HeadFont = "微软雅黑";
  14.     excelconfig.HeadPoint = 10;
  15.     excelconfig.IsAllSizeColumn = true;
  16.     excelconfig.ColumnModel = new List<ExcelColumnModel>();
  17.     foreach (var item in input.selectKey.Split(',').ToList())
  18.     {
  19.         var isExist = paramList.Find(p => p.field == item);
  20.         if (isExist != null)
  21.             excelconfig.ColumnModel.Add(new ExcelColumnModel() { Column = isExist.field, ExcelColumn = isExist.value });
  22.     }
  23.     var addPath = FileVariable.TemporaryFilePath + excelconfig.FileName;
  24.     ExcelExportHelper<TmsBusiShippingNoticeListOutput>.Export(exportData, excelconfig, addPath);
  25.     var fileName = _userManager.UserId + "|" + addPath + "|xls";
  26.     return new
  27.     {
  28.         name = excelconfig.FileName,
  29.         url = "/api/File/Download?encryption=" + DESCEncryption.Encrypt(fileName, "SHZY")
  30.     };
  31. }
复制代码
来源:https://www.cnblogs.com/fanwenkeer/p/18183472
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!

举报 回复 使用道具