| | |
| | | throw new NotImplementedException(status == "A" ? "启用失败" : "禁用失败"); |
| | | } |
| | | |
| | | // 插入或更新岗位的方法 |
| | | /// <summary> |
| | | /// 同步物料信息new_0/4 |
| | | /// </summary> |
| | | /// <param name="db"></param> |
| | | /// <param name="entity"></param> |
| | | /// <returns></returns> |
| | | private bool InsertOrUpdatePosition(SqlSugarScope db, MesPosition entity) |
| | | { |
| | | db.Deleteable<MesPosition>() |
| | | .Where(s => s.Id == entity.Id).ExecuteCommand(); |
| | | var insert = db.Insertable(entity).ExecuteCommand(); |
| | | return insert > 0; |
| | | if (entity.Id == 0) |
| | | { |
| | | // 新增情况:生成新ID并插入 |
| | | var newId = GenerateNewId(); |
| | | entity.Id = newId; |
| | | return db.Insertable(entity).ExecuteCommand() > 0; |
| | | } |
| | | else |
| | | { |
| | | // 更新情况:删除后重新插入,保持原有ID |
| | | var originalId = entity.Id; |
| | | |
| | | // 先删除原记录(如果存在) |
| | | db.Deleteable<MesPosition>().Where(s => s.Id == originalId).ExecuteCommand(); |
| | | |
| | | // 重新插入,保持原有ID |
| | | entity.Id = originalId; |
| | | return db.Insertable(entity).ExecuteCommand() > 0; |
| | | } |
| | | } |
| | | |
| | | // 插入或更新岗位的方法 |
| | | //private bool InsertOrUpdatePosition(SqlSugarScope db, MesPosition entity) |
| | | //{ |
| | | // db.Deleteable<MesPosition>() |
| | | // .Where(s => s.Id == entity.Id).ExecuteCommand(); |
| | | // var insert = db.Insertable(entity).ExecuteCommand(); |
| | | // return insert > 0; |
| | | //} |
| | | |
| | | // 删除岗位的方法 |
| | | private bool DeletePosition(SqlSugarScope db, decimal positionId) |
| | |
| | | throw new NotImplementedException("删除失败"); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 生成新的ID,确保不重复 |
| | | /// </summary> |
| | | private decimal GenerateNewId() |
| | | { |
| | | // 处理空表的情况,从1开始 |
| | | var maxId = Db.Queryable<MesPosition>().Max(x => (decimal?)x.Id) ?? 0; |
| | | var newId = maxId + 1; |
| | | |
| | | // 双重检查,确保生成的ID不存在 |
| | | while (Db.Queryable<MesPosition>().Where(x => x.Id == newId).Any()) |
| | | { |
| | | newId++; |
| | | } |
| | | |
| | | return newId; |
| | | } |
| | | |
| | | // 将 ErpPosition 对象转换为 MesPosition 对象的方法 |
| | | private MesPosition GetMesPosition(ErpPosition position) |
| | | { |
| | | return new MesPosition |
| | | { |
| | | Id = Convert.ToDecimal(position.Id), |
| | | // 查找是否已存在相同编码的记录。 |
| | | var existingCustomer = Db.Queryable<MesPosition>() |
| | | .Where(s => s.PositionId == position.FNumber) |
| | | .First(); |
| | | |
| | | var entity = new MesPosition |
| | | { |
| | | // 如果存在,使用现有的ID,后续将删除后重新插入 |
| | | // 如果不存在,设为0,InsertOrUpdate方法将生成新ID |
| | | Id = existingCustomer?.Id ?? 0, |
| | | //Id = Convert.ToDecimal(position.Id), |
| | | PositionId = position.FNumber, |
| | | PositionName = position.FName, |
| | | PositionDescription = position.FDESCRIPTIONS, |
| | |
| | | Fforbidstatus = position.FForbidStatus, |
| | | FUseOrgId = position.FUseOrgId, |
| | | FCreateOrgId = position.FCreateOrgId, |
| | | CreationDate = position.FCreateDate != null |
| | | ? DateTime.ParseExact(position.FCreateDate, |
| | | "yyyy-MM-dd HH:mm:ss", null) |
| | | : null, |
| | | //// 如果存在,使用现有的CreateDate,后续将删除后重新插入 |
| | | //// 如果不存在,设为当前时间 |
| | | //CreationDate = existingCustomer?.CreationDate ?? DateTime.Now, |
| | | |
| | | //如果存在,使用现有的CreateDate,后续将删除后重新插入 |
| | | // 如果不存在,设为当前时间(格式为 yyyy - MM - dd HH:mm: ss) |
| | | CreationDate = existingCustomer?.CreationDate |
| | | ?? DateTime.ParseExact(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd HH:mm:ss", null), |
| | | |
| | | //CreationDate = position.FCreateDate != null |
| | | // ? DateTime.ParseExact(position.FCreateDate, |
| | | // "yyyy-MM-dd HH:mm:ss", null) |
| | | // : null, |
| | | DisabledBy = position.FForbidderId, |
| | | DisabledDate = position.FForbidDate != null |
| | | ? DateTime.ParseExact(position.FForbidDate, |
| | | "yyyy-MM-dd HH:mm:ss", null) |
| | | : null |
| | | }; |
| | | |
| | | // ERP: 0=未禁用, 1=禁用 |
| | | // MES: A=未禁用, B=禁用 |
| | | if (string.IsNullOrEmpty(position.FForbidStatus)) |
| | | { |
| | | entity.Fforbidstatus = "A"; |
| | | } |
| | | else |
| | | { |
| | | //我期望的值是A=否,B=是 |
| | | //实际给我的值是0或1,我希望为我转换从A和B的方式 |
| | | entity.Fforbidstatus = position.FForbidStatus == "1" ? "B" : "A"; |
| | | } |
| | | |
| | | return entity; |
| | | } |
| | | |
| | | // SaveList 方法用于保存多个岗位记录,根据类型批量执行不同的操作 |