| | |
| | | return "成功"; |
| | | } |
| | | |
| | | public static string InsertLocCntrCg() { |
| | | string filePath = PathHelper.GetProjDir("./debug/loc_cntr_cg.csv"); |
| | | public static string InsertLocCntrCg(LocCntrCg locCntrCg) { |
| | | var db = DbHelper.GetDbClient(); |
| | | |
| | | try { |
| | | var configuration = new CsvConfiguration(CultureInfo.InvariantCulture) { |
| | | // 配置选项 |
| | | Delimiter = ",", // 分隔符 |
| | | HasHeaderRecord = true, // 有标题行 |
| | | MissingFieldFound = null, // 忽略缺失字段 |
| | | HeaderValidated = null, // 跳过标题验证 |
| | | BadDataFound = context => { } // 处理错误数据 |
| | | }; |
| | | |
| | | var locCntrCgList = new List<LocCntrCg>(); |
| | | |
| | | using (var reader = new StreamReader(filePath)) |
| | | using (var csv = new CsvReader(reader, configuration)) { |
| | | // 读取记录 |
| | | locCntrCgList = csv.GetRecords<LocCntrCg>().ToList(); |
| | | } |
| | | |
| | | using (var tran = db.UseTran()) { |
| | | foreach (var locCntrCg in locCntrCgList) { |
| | | LogHelper.Info("LogCntrCg:" + JsonConvert.SerializeObject(locCntrCg)); |
| | | if (string.IsNullOrEmpty(locCntrCg.LocCode)) break; |
| | | LogHelper.Info("LogCntrCg:" + JsonConvert.SerializeObject(locCntrCg)); |
| | | if (string.IsNullOrEmpty(locCntrCg.LocCode)) { |
| | | return "参数非法"; |
| | | } |
| | | |
| | | var loc = db.Queryable<TN_Location>().First(a => a.S_CODE == locCntrCg.LocCode); |
| | | if (loc == null) { |
| | | var newLoc = new TN_Location { |
| | | S_CODE = locCntrCg.LocCode, |
| | | S_AREA_CODE = locCntrCg.LocArea ?? "" |
| | | }; |
| | | var loc = db.Queryable<TN_Location>().First(a => a.S_CODE == locCntrCg.LocCode); |
| | | if (loc == null) { |
| | | var newLoc = new TN_Location { |
| | | S_CODE = locCntrCg.LocCode, |
| | | S_AREA_CODE = locCntrCg.LocArea ?? "" |
| | | }; |
| | | |
| | | if (db.Insertable<TN_Location>(newLoc).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | LogHelper.Info($"插入位置{locCntrCg.LocCode}失败"); |
| | | return "插入失败"; |
| | | } |
| | | |
| | | loc = newLoc; |
| | | if (db.Insertable<TN_Location>(newLoc).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | LogHelper.Info($"插入位置{locCntrCg.LocCode}失败"); |
| | | return "插入失败"; |
| | | } |
| | | |
| | | //if (loc.N_CURRENT_NUM == 0) { |
| | | // loc.N_CURRENT_NUM = 1; |
| | | // if (db.Updateable<TN_Location>(loc).UpdateColumns( |
| | | // it => new { it.N_CURRENT_NUM, it.T_MODIFY }).ExecuteCommand() <= 0) { |
| | | // tran.RollbackTran(); |
| | | // LogHelper.Info($"修改位置{locCntrCg.LocCode}失败"); |
| | | // continue; |
| | | // } |
| | | //} |
| | | loc = newLoc; |
| | | } |
| | | |
| | | if (string.IsNullOrEmpty(locCntrCg.CntrCode)) { |
| | | LogHelper.Info("容器号为空,不再读取后面的数据"); |
| | | continue; |
| | | //if (loc.N_CURRENT_NUM == 0) { |
| | | // loc.N_CURRENT_NUM = 1; |
| | | // if (db.Updateable<TN_Location>(loc).UpdateColumns( |
| | | // it => new { it.N_CURRENT_NUM, it.T_MODIFY }).ExecuteCommand() <= 0) { |
| | | // tran.RollbackTran(); |
| | | // LogHelper.Info($"修改位置{locCntrCg.LocCode}失败"); |
| | | // continue; |
| | | // } |
| | | //} |
| | | |
| | | if (string.IsNullOrEmpty(locCntrCg.CntrCode)) { |
| | | tran.CommitTran(); |
| | | LogHelper.Info("容器号为空,不再读取后面的数据"); |
| | | return "容器号为空,不再读取后面的数据"; |
| | | } |
| | | |
| | | var locCntrRel = db.Queryable<TN_Loc_Container>().First(a => a.S_LOC_CODE == locCntrCg.LocCode |
| | | && a.S_CNTR_CODE == locCntrCg.CntrCode); |
| | | |
| | | if (locCntrRel == null) { |
| | | var newLocCntrRel = new TN_Loc_Container { |
| | | S_LOC_CODE = locCntrCg.LocCode, |
| | | S_CNTR_CODE = locCntrCg.CntrCode |
| | | }; |
| | | |
| | | loc.N_CURRENT_NUM = 1; |
| | | |
| | | if (db.Insertable<TN_Loc_Container>(newLocCntrRel).ExecuteCommand() <= 0 |
| | | && db.Updateable<TN_Location>(loc).UpdateColumns(c => c.N_CURRENT_NUM).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | LogHelper.Info($"插入位置托盘关系{locCntrCg.LocCode}-{locCntrCg.CntrCode}失败"); |
| | | return "插入失败"; |
| | | } |
| | | } |
| | | |
| | | var locCntrRel = db.Queryable<TN_Loc_Container>().First(a => a.S_LOC_CODE == locCntrCg.LocCode |
| | | && a.S_CNTR_CODE == locCntrCg.CntrCode); |
| | | if (string.IsNullOrEmpty(locCntrCg.ItemCode)) { |
| | | tran.CommitTran(); |
| | | LogHelper.Info("物料号为空,不再读取后面的数据"); |
| | | return "物料号为空,不再读取后面的数据"; |
| | | } |
| | | |
| | | if (locCntrRel == null) { |
| | | var newLocCntrRel = new TN_Loc_Container { |
| | | S_LOC_CODE = locCntrCg.LocCode, |
| | | S_CNTR_CODE = locCntrCg.CntrCode, |
| | | S_CNTR_TYPE = locCntrCg.CntrType ?? "" |
| | | }; |
| | | |
| | | loc.N_CURRENT_NUM = 1; |
| | | |
| | | if (db.Insertable<TN_Loc_Container>(newLocCntrRel).ExecuteCommand() <= 0 |
| | | && db.Updateable<TN_Location>(loc).UpdateColumns(c => c.N_CURRENT_NUM).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | LogHelper.Info($"插入位置托盘关系{locCntrCg.LocCode}-{locCntrCg.CntrCode}失败"); |
| | | return "插入失败"; |
| | | } |
| | | } |
| | | |
| | | if (string.IsNullOrEmpty(locCntrCg.ItemCode)) { |
| | | LogHelper.Info("物料号为空,不再读取后面的数据"); |
| | | continue; |
| | | } |
| | | |
| | | var cgDetail = db.Queryable<TN_CG_Detail>().First(a => a.S_CNTR_CODE == locCntrCg.CntrCode |
| | | && a.S_ITEM_CODE == locCntrCg.ItemCode); |
| | | if (cgDetail == null) { |
| | | var locList = new List<TN_CG_Detail>(); |
| | | locList.Add(new TN_CG_Detail { S_CNTR_CODE = locCntrCg.CntrCode, S_ITEM_CODE = locCntrCg.ItemCode, S_BATCH_NO = locCntrCg.BatchNo ?? "" }); |
| | | if (db.Insertable<TN_CG_Detail>(locList).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | LogHelper.Info($"插入托盘物料关系{locCntrCg.CntrCode}-{locCntrCg}失败"); |
| | | return "插入失败"; |
| | | } |
| | | var cgDetail = db.Queryable<TN_CG_Detail>().First(a => a.S_CNTR_CODE == locCntrCg.CntrCode |
| | | && a.S_ITEM_CODE == locCntrCg.ItemCode); |
| | | if (cgDetail == null) { |
| | | var locList = new List<TN_CG_Detail>(); |
| | | locList.Add(new TN_CG_Detail { S_CNTR_CODE = locCntrCg.CntrCode, S_ITEM_CODE = locCntrCg.ItemCode, S_BATCH_NO = locCntrCg.BatchNo ?? "" }); |
| | | if (db.Insertable<TN_CG_Detail>(locList).ExecuteCommand() <= 0) { |
| | | tran.RollbackTran(); |
| | | LogHelper.Info($"插入托盘物料关系{locCntrCg.CntrCode}-{locCntrCg}失败"); |
| | | return "插入失败"; |
| | | } |
| | | } |
| | | tran.CommitTran(); |
| | |
| | | return "插入数据成功"; |
| | | |
| | | } |
| | | catch (FileNotFoundException) { |
| | | return $"Error: File not found - {filePath}"; |
| | | catch (Exception ex) { |
| | | return $"{ex.Message}"; |
| | | } |
| | | } |
| | | |
| | | public static string SetTaskWeight(SetTaskWeightInfo model) { |
| | | var db = DbHelper.GetDbClient(); |
| | | var cgDetail = db.Queryable<TN_CG_Detail, TN_Task>((d, t) => d.S_CNTR_CODE == t.S_CNTR_CODE) |
| | | .Where((d, t) => t.S_CODE == model.TaskNo).First(); |
| | | |
| | | if (cgDetail == null) { |
| | | return "找不到对应的物料信息"; |
| | | } |
| | | |
| | | cgDetail.F_QTY = model.Weight; |
| | | |
| | | try { |
| | | if (db.Updateable<TN_CG_Detail>(cgDetail).UpdateColumns(it => it.F_QTY) |
| | | .ExecuteCommand() <= 0 ) { |
| | | return "修改失败"; |
| | | } |
| | | return "修改成功"; |
| | | |
| | | } |
| | | catch (Exception ex) { |
| | | return $"Error reading CSV file: {ex.Message}"; |
| | | |
| | | return ex.Message; |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |