using Mapster; using Masuit.Tools; using System.CodeDom; using System.ComponentModel.DataAnnotations; using System.Reflection.Emit; using WIDESEA_Common; namespace WIDESEA_StorageBasicService; public class Dt_CacheInfoService : ServiceBase, IDt_CacheInfoService { private readonly IDt_CacheInfo_htyRepository _cacheInfo_htyRepository; public Dt_CacheInfoService(IDt_CacheInfoRepository BaseDal, IDt_CacheInfo_htyRepository cacheInfo_htyRepository) : base(BaseDal) { _cacheInfo_htyRepository = cacheInfo_htyRepository; } public WebResponseContent AddCacheInfoByAPP(SaveModel input) { WebResponseContent content = new WebResponseContent(); try { string operateType = input.MainData["operateType"].ToString(); string cztm = input.MainData["cztm"].ToString(); if (string.IsNullOrEmpty(cztm)) throw new Exception("车轴条码不能为空"); string machine = input.MainData["machine"].ToString(); if (operateType.Equals("1")) { if (BaseDal.QueryFirst(x => x.cacheNo == machine) != null) throw new Exception($"{machine}缓存架存在车轴数据,请核实后重试"); Dt_CacheInfo cacheInfo = new Dt_CacheInfo { cacheNo = machine, cacheName = machine == "1000" ? "1号压装位" : "2号压装位", targetAddress = machine == "1000" ? "2032" : "2042", CreateDate = DateTime.Now, Creater = "admin", createType = 2, //1-自动创建 2-手动创建 czh = cztm, }; if (BaseDal.AddData(cacheInfo) > 0) { content.OK("保存成功"); } else { content.Error("保存失败"); } } else { var cacheInfo = BaseDal.QueryFirst(x => x.cacheNo == machine && x.czh == cztm); if (cacheInfo == null) throw new Exception($"未找到{machine}缓存架车轴{cztm}数据,请核实后重试"); Dt_CacheInfo_hty cacheInfo_hty = new Dt_CacheInfo_hty(); cacheInfo.Adapt(cacheInfo_hty); cacheInfo_hty.FinishDate = DateTime.Now; cacheInfo_hty.OperateType = 4; if (_cacheInfo_htyRepository.AddData(cacheInfo_hty) > 0 && BaseDal.DeleteData(cacheInfo)) { content.OK("保存成功"); } else { content.Error("保存失败"); } } } catch (Exception ex) { content.Error($"添加异常:{ex.Message}"); } return content; } }