| | |
| | | using Tiger.Model.Entitys.MES.BizMesWoBatch; |
| | | using Tiger.Model.Entitys.MES.BizMesWo; |
| | | using Tiger.Model.Entitys.MES.Position; |
| | | using Microsoft.AspNetCore.Mvc.RazorPages; |
| | | using System.Drawing.Printing; |
| | | |
| | | namespace Tiger.Business.MES |
| | | { |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 工单模板变量修改 |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | public async Task<ApiAction> AddOrEditLabelVarByWorkOrder(BAS_LABEL_VAR_WO input) |
| | | { |
| | | var result = new ApiAction(); |
| | | try |
| | | { |
| | | //保存前的判断 |
| | | if (input.WORK_ORDER.IsNullOrEmpty()) |
| | | { |
| | | result.IsSuccessed = false; |
| | | result.LocaleMsg = new($"工单号不能为空!"); |
| | | return result; |
| | | } |
| | | |
| | | var db = Biz.Db; |
| | | var dbTran = db.UseTran(() => |
| | | { |
| | | var y = db.Storageable(input) |
| | | .WhereColumns(t => new { t.LABEL_ID, t.WORK_ORDER, t.VAR_NAME, t.GHOST_ROW }) |
| | | .ToStorage(); |
| | | y.AsInsertable.ExecuteCommand(); |
| | | y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); |
| | | }); |
| | | if (!dbTran.IsSuccess) |
| | | { |
| | | result.IsSuccessed = false; |
| | | result.LocaleMsg = new($"更新工单模板变量异常"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | result.CatchExceptionWithLog(ex, "更新工单模板变量异常"); |
| | | } |
| | | return await Task.FromResult(result); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取工单模板变量 |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | public async Task<ApiAction<QueryAble<BAS_LABEL_VAR_WO>>> GetLabelVarByWorkOrder(BizLabelVarWoInput input) |
| | | { |
| | | var result = new ApiAction<QueryAble<BAS_LABEL_VAR_WO>>(); |
| | | try |
| | | { |
| | | QueryAble<BAS_LABEL_VAR_WO> query = new(); |
| | | if (input.WorkOrder.IsNullOrEmpty()) |
| | | { |
| | | result.IsSuccessed = false; |
| | | result.LocaleMsg = new($"工单号不能为空!"); |
| | | return result; |
| | | } |
| | | var labeltemp = Biz.Db.Queryable<BAS_LABEL_TEMP>().Where(q => q.LABEL_CODE.Equals(input.LabelId) || q.ID.Equals(input.LabelId)).First(); |
| | | if (labeltemp == null) { |
| | | result.IsSuccessed = false; |
| | | result.LocaleMsg = new($"模板不存在!"); |
| | | return result; |
| | | } |
| | | var lableVars = await Biz.Db.Queryable<BAS_LABEL_VAR_WO>().Where(q => SqlFunc.IsNullOrEmpty(q.WORK_ORDER) && q.LABEL_ID.Equals(labeltemp.ID)).ToListAsync(); |
| | | var queryable = Biz.Db.Queryable<BAS_LABEL_VAR_WO>().Where(q => q.WORK_ORDER.Equals(input.WorkOrder) && q.LABEL_ID.Equals(labeltemp.ID)); |
| | | query.page = await queryable.ToPageAsync(input.pageIndex, input.pageSize); |
| | | //如果不存在,则返回初始数据 |
| | | if (query.page.totals == 0) |
| | | { |
| | | query.page = await Biz.Db.Queryable<BAS_LABEL_VAR_WO>().Where(q => SqlFunc.IsNullOrEmpty(q.WORK_ORDER) && q.LABEL_ID.Equals(labeltemp.ID)).ToPageAsync(input.pageIndex, input.pageSize); |
| | | query.Items = query.page.data; |
| | | } |
| | | //如果初始变量数大于工单设置的变量数 |
| | | if (lableVars.Count > query.page.totals) |
| | | { |
| | | foreach (var item in lableVars) |
| | | { |
| | | if (queryable.ToList().Any(q => q.VAR_NAME == item.VAR_NAME)) |
| | | { |
| | | item.WORK_ORDER = input.WorkOrder; |
| | | item.VAR_VALUE = queryable.ToList().Where(q => q.VAR_NAME == item.VAR_NAME).First()?.VAR_VALUE; |
| | | } |
| | | } |
| | | query.Items = lableVars.Skip((input.pageIndex - 1) * input.pageSize).Take(input.pageSize).ToList(); |
| | | query.page.totals = lableVars.Count; |
| | | query.page.data = query.Items; |
| | | } |
| | | result.Data = query; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | result.CatchExceptionWithLog(ex, "获取工单模板变量异常"); |
| | | } |
| | | return result; |
| | | } |
| | | } |
| | | } |