| | |
| | | throw new NotImplementedException(status == "A" ? "启用失败" : "禁用失败"); |
| | | } |
| | | |
| | | // 插入或更新员工的方法 |
| | | private bool InsertOrUpdateStaff(SqlSugarScope db, SysUser sysUser, |
| | | MesStaff entity) |
| | | /// <summary> |
| | | /// 同步物料信息new_0/4 |
| | | /// </summary> |
| | | /// <param name="db"></param> |
| | | /// <param name="entity"></param> |
| | | /// <returns></returns> |
| | | private bool InsertOrUpdateStaff(SqlSugarScope db, SysUser sysUser, MesStaff entity) |
| | | { |
| | | |
| | | // 先确保用户账号存在 |
| | | var exists = db.Queryable<SysUser>().Any(u => u.Account == sysUser.Account); |
| | | if (!exists) |
| | | { |
| | |
| | | if (insertUser <= 0) return false; |
| | | } |
| | | |
| | | //db.Deleteable<SysUser>() |
| | | // .Where(s => s.Account == sysUser.Account).ExecuteCommand(); |
| | | |
| | | db.Deleteable<MesStaff>() |
| | | .Where(s => s.Id == entity.Id).ExecuteCommand(); |
| | | |
| | | |
| | | |
| | | var insertStaff = db.Insertable(entity).ExecuteCommand(); |
| | | return insertStaff > 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<MesStaff>().Where(s => s.Id == originalId).ExecuteCommand(); |
| | | |
| | | // 重新插入,保持原有ID |
| | | entity.Id = originalId; |
| | | return db.Insertable(entity).ExecuteCommand() > 0; |
| | | } |
| | | } |
| | | |
| | | // 插入或更新员工的方法 |
| | | //private bool InsertOrUpdateStaff(SqlSugarScope db, SysUser sysUser,MesStaff entity) |
| | | //{ |
| | | |
| | | // var exists = db.Queryable<SysUser>().Any(u => u.Account == sysUser.Account); |
| | | // if (!exists) |
| | | // { |
| | | // var insertUser = db.Insertable(sysUser).ExecuteCommand(); |
| | | // if (insertUser <= 0) return false; |
| | | // } |
| | | |
| | | // //db.Deleteable<SysUser>() |
| | | // // .Where(s => s.Account == sysUser.Account).ExecuteCommand(); |
| | | |
| | | // db.Deleteable<MesStaff>() |
| | | // .Where(s => s.Id == entity.Id).ExecuteCommand(); |
| | | |
| | | |
| | | |
| | | // var insertStaff = db.Insertable(entity).ExecuteCommand(); |
| | | // return insertStaff > 0; |
| | | //} |
| | | |
| | | // 删除员工的方法 |
| | | private bool DeleteStaff(SqlSugarScope db, SysUser sysUser, decimal staffId) |
| | |
| | | throw new NotImplementedException("反审核失败"); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 生成新的ID,确保不重复 |
| | | /// </summary> |
| | | private decimal GenerateNewId() |
| | | { |
| | | // 处理空表的情况,从1开始 |
| | | var maxId = Db.Queryable<MesStaff>().Max(x => (decimal?)x.Id) ?? 0; |
| | | var newId = maxId + 1; |
| | | |
| | | // 双重检查,确保生成的ID不存在 |
| | | while (Db.Queryable<MesStaff>().Where(x => x.Id == newId).Any()) |
| | | { |
| | | newId++; |
| | | } |
| | | |
| | | return newId; |
| | | } |
| | | |
| | | // 将 ErpStaff 对象转换为 MesStaff 对象的方法 |
| | | private MesStaff GetMesStaff(ErpStaff staff) |
| | | { |
| | | // 查找是否已存在相同编码的记录。 |
| | | var existingCustomer = Db.Queryable<MesStaff>() |
| | | .Where(s => s.StaffNo == staff.FStaffNumber) |
| | | .First(); |
| | | |
| | | var entity = new MesStaff |
| | | { |
| | | Id = Convert.ToDecimal(staff.Id), |
| | | // 如果存在,使用现有的ID,后续将删除后重新插入 |
| | | // 如果不存在,设为0,InsertOrUpdate方法将生成新ID |
| | | Id = existingCustomer?.Id ?? 0, |
| | | //Id = Convert.ToDecimal(staff.Id), |
| | | StaffNo = staff.FStaffNumber, |
| | | StaffName = staff.FName, |
| | | DepartmentName = staff.FPostDept, |
| | | PositionCode = staff.FPostId, |
| | | DepartmentNo = staff.FPostDeptNo,//部门编码 |
| | | DepartmentName = staff.FPostDept,//部门名称 |
| | | PositionCode = staff.FPost,//岗位编码 |
| | | PositionName = staff.FPostId,//岗位名称 |
| | | PhoneNumber = staff.FMobile, |
| | | Remark = staff.FDescription, |
| | | FforbidStatus = staff.FForbidStatus, |
| | | FSubsidiary = staff.FUseOrgId, |
| | | Fumbrella = staff.FCreateOrgId, |
| | | CreateDate = DateTime.Now, |
| | | // 如果存在,使用现有的CreateDate,后续将删除后重新插入 |
| | | // 如果不存在,设为当前时间 |
| | | CreateDate = existingCustomer?.CreateDate ?? DateTime.Now, |
| | | //CreateDate = DateTime.Now, |
| | | LastupdateDate = DateTime.Now, |
| | | Type = staff.Type |
| | | }; |
| | |
| | | entity.StartDate = DateTime.ParseExact(staff.FStaffStartDate, |
| | | "yyyy-MM-dd HH:mm:ss", null); |
| | | |
| | | // ERP: 0=未禁用, 1=禁用 |
| | | // MES: A=未禁用, B=禁用 |
| | | if (string.IsNullOrEmpty(staff.FForbidStatus)) |
| | | { |
| | | entity.FforbidStatus = "A"; |
| | | } |
| | | else |
| | | { |
| | | //我期望的值是A=否,B=是 |
| | | //实际给我的值是0或1,我希望为我转换从A和B的方式 |
| | | entity.FforbidStatus = staff.FForbidStatus == "1" ? "B" : "A"; |
| | | } |
| | | |
| | | return entity; |
| | | } |
| | | |