feat sap出差信息获取,海宁余额上传tenantId问题

This commit is contained in:
2024-07-03 16:24:46 +08:00
parent 3fa486cfb4
commit b376ec2387
9 changed files with 212 additions and 137 deletions

View File

@@ -523,20 +523,21 @@ public class BalanceService : IBalanceService
await _dbContext.InsertAsync(gainfoMeal);
}
var businessPlace = await _dbContext.Queryable<BusinessPlaceEntity>()
var businessPlaceInfo = await _dbContext.Queryable<BusinessPlaceEntity>()
.LeftJoin<BusinessPlaceShiftRelationshipEntity>((a, b) => a.Code == b.PlaceCode)
.LeftJoin<BusinessShiftEntity>((a, b, c) => b.ShiftCode == c.Code)
.Where((a, b, c) => a.CustomCode == request.BusinessPlaceCode)
.Select((a, b, c) => new
{
a.Code,
ShiftCode = c.Code
ShiftCode = c.Code,
a.TenantId
})
.SingleAsync();
if (request.Type == BalanceRecordTypeEnumType.Out)
{
businessPlace.ThrowIfNull($"营业点{request.BusinessPlaceCode}不存在");
businessPlaceInfo.ThrowIfNull($"营业点{request.BusinessPlaceCode}不存在");
}
await _dbContext.InsertAsync(new BalanceRecordEntity
@@ -544,8 +545,8 @@ public class BalanceService : IBalanceService
Amount = request.Amount,
ApplicationType = request.ApplicationType,
Type = request.Type,
BusinessPlaceCode = businessPlace?.Code,
BusinessShiftCode = businessPlace?.ShiftCode,
BusinessPlaceCode = businessPlaceInfo?.Code,
BusinessShiftCode = businessPlaceInfo?.ShiftCode,
ShiftType = request.ShiftType,
CostDate = request.CostDate,
CostDateTime = request.CostDateTime,
@@ -557,7 +558,7 @@ public class BalanceService : IBalanceService
Remark = request.Remark,
CostId = gainfo.CostId,
SubsidiesFromMonth = request.CostDate.ToString("yyyyMM"),
TenantId = request.Factory,
TenantId = businessPlaceInfo?.TenantId ?? request.Factory,
OriginTenantId = gainfo.Factory,
Werks = gainfo.Werks,
Name = gainfo.Name,

View File

@@ -9,6 +9,7 @@ public class BusinessTripEntity : SugarBaseEntity
/// <summary>
/// 工号
/// </summary>
[SugarColumn(IsNullable = false, UniqueGroupNameList = new[] { "unique_BusinessTrip_code_begin_end" })]
public string Code { get; set; }
/// <summary>
@@ -19,11 +20,13 @@ public class BusinessTripEntity : SugarBaseEntity
/// <summary>
/// 开始日期
/// </summary>
[SugarColumn(IsNullable = false, UniqueGroupNameList = new[] { "unique_BusinessTrip_code_begin_end" })]
public string BeginDate { get; set; }
/// <summary>
/// 结束日期
/// </summary>
[SugarColumn(IsNullable = false, UniqueGroupNameList = new[] { "unique_BusinessTrip_code_begin_end" })]
public string EndDate { get; set; }
/// <summary>
@@ -55,7 +58,7 @@ public class BusinessTripEntity : SugarBaseEntity
/// 出差天数
/// </summary>
public double Day { get; set; }
/// <summary>
/// 出差目的地
/// </summary>

View File

@@ -0,0 +1,87 @@
using Newtonsoft.Json;
namespace Dlhis.ScheduledTask.Common.Response;
public class SapBusinessTripInfoResponse
{
/// <summary>
/// 明细数据
/// </summary>
[JsonProperty("OT_2002")]
public List<SapBusinessTripInfoItem> Items { get; set; }
}
public class SapBusinessTripInfoItem
{
/// <summary>
/// 工号
/// </summary>
[JsonProperty("OV_GONGH")]
public string Code { get; set; }
/// <summary>
/// 姓名
/// </summary>
[JsonProperty("OV_ENAME")]
public string Name { get; set; }
/// <summary>
/// 开始日期
/// </summary>
[JsonProperty("OV_BEGDA")]
public string BeginDate { get; set; }
/// <summary>
/// 结束日期
/// </summary>
[JsonProperty("OV_ENDDA")]
public string EndDate { get; set; }
/// <summary>
/// 开始时间
/// </summary>
[JsonProperty("OV_BEGUZ")]
public DateTime BeginDateTime { get; set; }
/// <summary>
/// 结束时间
/// </summary>
[JsonProperty("OV_ENDUZ")]
public DateTime EndDateTime { get; set; }
/// <summary>
/// 出差类型
/// </summary>
[JsonProperty("OV_AWART")]
public string Type { get; set; }
/// <summary>
/// 出差类型描述
/// </summary>
[JsonProperty("OV_ATEXT")]
public string TypeDesc { get; set; }
/// <summary>
/// 出差时数
/// </summary>
[JsonProperty("OV_STDAZ")]
public int Hour { get; set; }
/// <summary>
/// 出差天数
/// </summary>
[JsonProperty("OV_ABWTG")]
public double Day { get; set; }
/// <summary>
/// 出差目的地
/// </summary>
[JsonProperty("OV_CCMDD")]
public string Destination { get; set; }
/// <summary>
/// 出差目的地描述
/// </summary>
[JsonProperty("OV_CCMDDM")]
public string DestinationDesc { get; set; }
}

View File

@@ -1,88 +0,0 @@
using Newtonsoft.Json;
namespace Dlhis.ScheduledTask.Common.Response
{
public class SapTravelInfoResponse
{
/// <summary>
/// 明细数据
/// </summary>
[JsonProperty("OT_2002")]
public List<SapTravelInfoItem> Items { get; set; }
}
public class SapTravelInfoItem
{
/// <summary>
/// 工号
/// </summary>
[JsonProperty("OV_GONGH")]
public string Code { get; set; }
/// <summary>
/// 姓名
/// </summary>
[JsonProperty("OV_ENAME")]
public string Name { get; set; }
/// <summary>
/// 开始日期
/// </summary>
[JsonProperty("OV_BEGDA")]
public string BeginDate { get; set; }
/// <summary>
/// 结束日期
/// </summary>
[JsonProperty("OV_ENDDA")]
public string EndDate { get; set; }
/// <summary>
/// 开始时间
/// </summary>
[JsonProperty("OV_BEGUZ")]
public DateTime BeginDateTime { get; set; }
/// <summary>
/// 结束时间
/// </summary>
[JsonProperty("OV_ENDUZ")]
public DateTime EndDateTime { get; set; }
/// <summary>
/// 出差类型
/// </summary>
[JsonProperty("OV_AWART")]
public string Type { get; set; }
/// <summary>
/// 出差类型描述
/// </summary>
[JsonProperty("OV_ATEXT")]
public string TypeDesc { get; set; }
/// <summary>
/// 出差时数
/// </summary>
[JsonProperty("OV_STDAZ")]
public int Hour { get; set; }
/// <summary>
/// 出差天数
/// </summary>
[JsonProperty("OV_ABWTG")]
public double Day { get; set; }
/// <summary>
/// 出差目的地
/// </summary>
[JsonProperty("OV_CCMDD")]
public string Destination { get; set; }
/// <summary>
/// 出差目的地描述
/// </summary>
[JsonProperty("OV_CCMDDM")]
public string DestinationDesc { get; set; }
}
}

View File

@@ -9,5 +9,15 @@ public interface IJinkoJIPService : ISingletonDependency
Task<string> SyncMealSupplementRecordsAsync(List<SyncMealSupplementRecordRequest> requests);
public string IssueToken();
}
/// <summary>
/// 获取出差信息
/// </summary>
/// <param name="begin"></param>
/// <param name="end"></param>
/// <param name="departmentNo"></param>
/// <returns></returns>
Task<SapBusinessTripInfoResponse> GetTravelInfosAsync(DateTime begin, DateTime end, string departmentNo);
string IssueToken();
}

View File

@@ -11,12 +11,4 @@ public interface IJinkoSapService : IScopeDependency
Task<SapPersonResponse> GetPersonsByWerkAsync(string werk);
Task<SapPersonResponse> GetPersonsByCodeAsync(string code);
/// <summary>
/// 获取出差信息
/// </summary>
/// <param name="begin"></param>
/// <param name="end"></param>
/// <returns></returns>
Task<SapTravelInfoResponse> GetTravelInfosAsync(DateTime begin, DateTime end);
}

View File

@@ -4,7 +4,6 @@ using System.Security.Claims;
using System.Text;
using Dlhis.ScheduledTask.Common.Request;
using Dlhis.ScheduledTask.Common.Response;
using Dlhis.ScheduledTask.Common.Services;
using Kurisu.AspNetCore.Utils.Extensions;
using Microsoft.IdentityModel.Tokens;
using Newtonsoft.Json.Linq;
@@ -85,6 +84,7 @@ public class JinkoJIPService : IJinkoJIPService
{
true.ThrowIfTrue(exp.Value<string>());
}
if (jobj.TryGetValue("message", out var message) && !jobj.ContainsKey("code"))
{
true.ThrowIfTrue(message.Value<string>());
@@ -95,6 +95,39 @@ public class JinkoJIPService : IJinkoJIPService
return responseJson;
}
public async Task<SapBusinessTripInfoResponse> GetTravelInfosAsync(DateTime begin, DateTime end, string departmentNo)
{
const string apiUrl = "/JIP/HCM/HCM_TRAVELINFO";
var beginDay = begin.ToString("yyyyMMdd");
var endDay = end.ToString("yyyyMMdd");
var obj = new
{
IV_BEGDA = beginDay,
IV_ENDDA = endDay,
IT_2002GH = new List<object>
{
new
{
//IV_GONGH = "" 工号,
IV_ORGID = departmentNo,
}
}
};
var body = obj.ToJson();
var content = new StringContent(body, Encoding.UTF8, "application/json");
var response = await GetHttpClient().PostAsync(apiUrl, content);
response.EnsureSuccessStatusCode();
var jsonResponse = await response.Content.ReadAsStringAsync();
return jsonResponse.ToObject<SapBusinessTripInfoResponse>();
}
public string IssueToken()
{
var jwtKey = _configuration.GetSection("JinkoOptions:Jip:Key").Value;
@@ -106,9 +139,9 @@ public class JinkoJIPService : IJinkoJIPService
var claims = new List<Claim>
{
new (JwtRegisteredClaimNames.Nbf,$"{new DateTimeOffset(now).ToUnixTimeSeconds()}"),
new (JwtRegisteredClaimNames.Exp,$"{new DateTimeOffset(expires).ToUnixTimeSeconds()}"),
new (JwtRegisteredClaimNames.Iss,jwtKey),
new(JwtRegisteredClaimNames.Nbf, $"{new DateTimeOffset(now).ToUnixTimeSeconds()}"),
new(JwtRegisteredClaimNames.Exp, $"{new DateTimeOffset(expires).ToUnixTimeSeconds()}"),
new(JwtRegisteredClaimNames.Iss, jwtKey),
};
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSecret));
@@ -126,4 +159,4 @@ public class JinkoJIPService : IJinkoJIPService
var securityToken = jwtHandler.CreateToken(descriptor);
return jwtHandler.WriteToken(securityToken);
}
}
}

View File

@@ -5,7 +5,6 @@ using Dlhis.Entity.Basic.Entity;
using Dlhis.ScheduledTask.Common.Dto;
using Dlhis.ScheduledTask.Common.Response;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
using Kurisu.AspNetCore.Utils.Extensions;
using Newtonsoft.Json;
namespace Dlhis.ScheduledTask.Common.Services.Implements;
@@ -153,7 +152,7 @@ public class JinkoSapService : IJinkoSapService
persons.AddRange(personResp.Person.Items);
}
return new SapPersonResponse()
return new SapPersonResponse
{
Person = new SapPerson<SapPersonItem>
{
@@ -161,29 +160,4 @@ public class JinkoSapService : IJinkoSapService
}
};
}
public async Task<SapTravelInfoResponse> GetTravelInfosAsync(DateTime begin, DateTime end)
{
const string apiUrl = "/JIP/HCM/HCM_TRAVELINFO";
var beginDay = begin.ToString("yyyyMMdd");
var endDay = end.ToString("yyyyMMdd");
var obj = new
{
IV_BEGDA = beginDay,
IV_ENDDA = endDay
};
var body = obj.ToJson();
var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
var response = await GetHttpClient().PostAsync(apiUrl, content);
response.EnsureSuccessStatusCode();
var jsonResponse = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<SapTravelInfoResponse>(jsonResponse);
}
}

View File

@@ -0,0 +1,63 @@
using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Visitor.Entity;
using Dlhis.ScheduledTask.Attributes;
using Dlhis.ScheduledTask.Common.Services;
using Mapster;
namespace Dlhis.ScheduledTask.Jobs;
[RecurringJob(nameof(SyncBusinessTripJob), "0 0 0/1 * * ? ", Name = "SAP同步出差信息")]
public class SyncBusinessTripJob : BaseJob
{
/// <inheritdoc />
public SyncBusinessTripJob(IServiceProvider serviceProvider) : base(serviceProvider)
{
}
/// <inheritdoc />
protected override async Task RunAsync(IServiceProvider serviceProvider)
{
var jipService = serviceProvider.GetService<IJinkoJIPService>();
var today = DateTime.Today;
var departments = await DbContext.Queryable<DepartmentEntity>().ToListAsync();
var tops = departments.Where(x => x.PNo == "00001000").ToList();
var validDepartments = tops.ToList();
tops.ForEach(x => RecursionGetNext(x, departments, validDepartments));
foreach (var department in validDepartments)
{
try
{
var tripResponse = await jipService.GetTravelInfosAsync(today, today, department.No);
foreach (var tripInfoItem in tripResponse.Items)
{
if (await DbContext.Queryable<BusinessTripEntity>().Where(x => x.Code == tripInfoItem.Code && x.BeginDate == tripInfoItem.BeginDate && x.EndDate == tripInfoItem.EndDate)
.AnyAsync())
{
continue;
}
var entity = tripInfoItem.Adapt<BusinessTripEntity>();
await DbContext.InsertAsync(entity);
}
}
catch (Exception e)
{
Logger.LogError(e, "获取部门{departmentNo}{departmentName}出差数据执行失败:{message}", department.No, department.Name, e.Message);
}
}
}
//************************************************************************************************************************************************
private static void RecursionGetNext(DepartmentEntity current, List<DepartmentEntity> data, List<DepartmentEntity> result)
{
var next = data.Where(x => x.PNo == current.No).ToList();
foreach (var item in next)
{
result.Add(item);
RecursionGetNext(item, data, result);
}
}
}