¶Ô±ÈÐÂÎļþ |
| | |
| | | using Tiger.Model; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq.Expressions; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using Rhea.Common; |
| | | using System.Net; |
| | | using System.Linq; |
| | | using Newtonsoft.Json; |
| | | using Tiger.IBusiness; |
| | | using Microsoft.AspNetCore.Http; |
| | | using Tiger.Model.Entitys.MES.BasLabelTemp; |
| | | using System.Security.Cryptography; |
| | | |
| | | namespace Tiger.Business.MES |
| | | { |
| | | public partial class BasLabelTemp : ILabelTemplate |
| | | { |
| | | public async Task<ApiAction> DeleteLabelTemplate(string Id) |
| | | { |
| | | var result = new ApiAction(); |
| | | try |
| | | { |
| | | var _label = await Biz.Db.Queryable<BAS_LABEL_TEMP>().Where(x => x.ID == Id).FirstAsync(); |
| | | if (_label == null) |
| | | { |
| | | result.IsSuccessed = false; |
| | | result.LocaleMsg = new($"æ ç¾æ¨¡æ¿ä¸åå¨ï¼ä¸è½å é¤ï¼"); |
| | | return result; |
| | | } |
| | | if (Biz.Db.Queryable<MES_PROD_ACTION>().Any(x => x.LABEL_CODE == _label.LABEL_CODE)) |
| | | { |
| | | result.IsSuccessed = false; |
| | | result.LocaleMsg = new($"æ ç¾æ¨¡æ¿å·²ç»ç»å®å°è¡ä¸ºï¼ä¸è½å é¤ï¼"); |
| | | return result; |
| | | } |
| | | if (Biz.Db.Queryable<MES_WO_ACTION>().Any(x => x.LABEL_CODE == _label.LABEL_CODE)) |
| | | { |
| | | result.IsSuccessed = false; |
| | | result.LocaleMsg = new($"æ ç¾æ¨¡æ¿å·²ç»ç»å®å°è¡ä¸ºï¼ä¸è½å é¤ï¼"); |
| | | return result; |
| | | } |
| | | var db = Biz.Db; |
| | | var dbTran = db.UseTran(() => |
| | | { |
| | | db.Deleteable<BAS_LABEL_TEMP>().Where(x => x.ID == Id).ExecuteCommand(); |
| | | }); |
| | | if (!dbTran.IsSuccess) |
| | | { |
| | | result.IsSuccessed = false; |
| | | result.LocaleMsg = new($"å 餿 ç¾æ¨¡æ¿å¼å¸¸"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | result.CatchExceptionWithLog(ex, "å 餿 ç¾æ¨¡æ¿å¼å¸¸"); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ä¿åæ ç¾æ¨¡æ¿ |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="NotImplementedException"></exception> |
| | | public async Task<ApiAction> SaveLabelTemplate(BasLabelTempInput input) |
| | | { |
| | | var result = new ApiAction(); |
| | | try |
| | | { |
| | | BAS_LABEL_TEMP? prodTemp = null; |
| | | BAS_LABEL_TEMP? prodCustTemp = null; |
| | | //å¦æä¼ å
¥çæ ç¾å®¢æ·ç¼ç ä¸ä¸ºç©º |
| | | if (!input.Label.CUST_CODE.IsNullOrEmpty()) |
| | | { |
| | | //妿æ¥ä¸å°æ ç¾å¹¶ä¸å®¢æ·ç¼ç ä¸ä¸ºç©º |
| | | if (!Biz.Db.Queryable<BAS_LABEL_TEMP>().Any(x => x.LABEL_CODE == input.Label.LABEL_CODE)) |
| | | { |
| | | prodCustTemp = input.Label; |
| | | prodTemp = input.Label.Clone(); |
| | | prodTemp.CUST_CODE = ""; |
| | | prodTemp.LABEL_CODE = $"{input.Label.LABEL_CODE}_{DateTime.Now.ToString("yyyyMMddhhmmss")}"; |
| | | } |
| | | else |
| | | { |
| | | prodCustTemp = input.Label; |
| | | prodCustTemp.LABEL_CODE = $"{input.Label.LABEL_CODE}_{DateTime.Now.ToString("yyyyMMddhhmmss")}"; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //妿客æ·ç¼ç 为空 |
| | | prodTemp = input.Label; |
| | | if (Biz.Db.Queryable<BAS_LABEL_TEMP>().Any(x => x.LABEL_CODE == input.Label.LABEL_CODE && x.PROD_CODE != input.Label.PROD_CODE)) |
| | | { |
| | | prodTemp.LABEL_CODE = $"{input.Label.LABEL_CODE}_{DateTime.Now.ToString("yyyyMMddhhmmss")}"; |
| | | } |
| | | } |
| | | var db = Biz.Db; |
| | | var dbTran = db.UseTran(() => |
| | | { |
| | | if (prodTemp != null) |
| | | { |
| | | var x = db.Storageable(prodTemp) |
| | | .WhereColumns(t => new { t.LABEL_CODE, t.PROD_CODE, t.CUST_CODE, t.GHOST_ROW }) |
| | | .ToStorage(); |
| | | x.AsInsertable.ExecuteCommand(); |
| | | x.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); |
| | | } |
| | | if (prodCustTemp != null) |
| | | { |
| | | var y = db.Storageable(prodCustTemp) |
| | | .WhereColumns(t => new { t.LABEL_CODE, t.PROD_CODE, t.CUST_CODE, t.GHOST_ROW }) |
| | | .ToStorage(); |
| | | y.AsInsertable.ExecuteCommand(); |
| | | y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); |
| | | } |
| | | var temp = db.Queryable<BAS_LABEL_TEMP>().Where(x => |
| | | x.LABEL_CODE == input.Label.LABEL_CODE && |
| | | x.PROD_CODE == input.Label.PROD_CODE && |
| | | x.CUST_CODE == input.Label.CUST_CODE).First(); |
| | | if (input.LabelVars != null && input.LabelVars.Count > 0) |
| | | { |
| | | if (temp != null && temp.ID != input.LabelVars[0].LABEL_ID) |
| | | { |
| | | foreach (var item in input.LabelVars) |
| | | { |
| | | item.LABEL_ID = temp.ID; |
| | | } |
| | | } |
| | | var z = db.Storageable(input.LabelVars) |
| | | .WhereColumns(t => new { t.LABEL_ID, t.VAR_NAME, t.GHOST_ROW }) |
| | | .ToStorage(); |
| | | z.AsInsertable.ExecuteCommand(); |
| | | z.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); |
| | | } |
| | | if (input.LabelVarWos != null && input.LabelVarWos.Count > 0) |
| | | { |
| | | if (temp != null && temp.ID != input.LabelVarWos[0].LABEL_ID) |
| | | { |
| | | foreach (var item in input.LabelVarWos) |
| | | { |
| | | item.LABEL_ID = temp.ID; |
| | | } |
| | | } |
| | | var o = db.Storageable(input.LabelVarWos) |
| | | .WhereColumns(t => new { t.LABEL_ID, t.VAR_NAME, t.GHOST_ROW }) |
| | | .ToStorage(); |
| | | o.AsInsertable.ExecuteCommand(); |
| | | o.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); |
| | | } |
| | | } |
| | | } |