321 lines
15 KiB
C#
321 lines
15 KiB
C#
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
|
//
|
|
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
|
//
|
|
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
|
|
|
using Admin.NET.Core;
|
|
using DocumentFormat.OpenXml.Drawing.Charts;
|
|
using Furion.DependencyInjection;
|
|
using Furion.DynamicApiController;
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Vistar.Application.Const;
|
|
using Vistar.Application.Entity;
|
|
using Vistar.Application.Service.OaOpenInterface.Dto;
|
|
using Vistar.Application.SolidWorksManageService.Dto;
|
|
|
|
namespace Vistar.Application.Service.OaOpenInterface;
|
|
/// <summary>
|
|
/// 开放接口给OA
|
|
/// </summary>
|
|
[ApiDescriptionSettings(ApplicationConst.GroupName, Name = "OaOpenInterfaceService", Order = 100)]
|
|
public class OaOpenInterfaceService : IDynamicApiController, ITransient
|
|
{
|
|
public SqlSugarRepository<Obj109> _obj109Rep;
|
|
public SqlSugarRepository<Obj140> _obj140Rep;
|
|
public SolidWorksManageService.SolidWorksManageService _solidWorksManageService;
|
|
public SqlSugarRepository<ObjectFieldsGroups> _objectFieldsGroupsRep;
|
|
public SqlSugarRepository<FieldGroupDefault> _fieldGroupDefaultRep;
|
|
public SqlSugarRepository<Obj81> _obj81Rep;
|
|
|
|
public OaOpenInterfaceService(
|
|
SqlSugarRepository<Obj109> obj109Rep,
|
|
SqlSugarRepository<Obj140> obj140Rep,
|
|
SqlSugarRepository<Obj81> obj81Rep,
|
|
SolidWorksManageService.SolidWorksManageService solidWorksManageService,
|
|
SqlSugarRepository<ObjectFieldsGroups> objectFieldsGroupsRep,
|
|
SqlSugarRepository<FieldGroupDefault> fieldGroupDefaultRep
|
|
|
|
)
|
|
{
|
|
_obj109Rep = obj109Rep;
|
|
_obj140Rep = obj140Rep;
|
|
_solidWorksManageService = solidWorksManageService;
|
|
_objectFieldsGroupsRep = objectFieldsGroupsRep;
|
|
_fieldGroupDefaultRep = fieldGroupDefaultRep;
|
|
_obj81Rep= obj81Rep;
|
|
}
|
|
|
|
/// <summary>
|
|
/// OA创建、修改项目
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)]
|
|
[ApiDescriptionSettings(Name = "OaCreateProject"), HttpPost]
|
|
[DisplayName("OA创建、修改项目")]
|
|
public async Task<ManageResponse> OaCreateProject(OaCreateProjectInput input)
|
|
{
|
|
var response = new ManageResponse();
|
|
|
|
if (string.IsNullOrWhiteSpace(input._System_objNBS) || string.IsNullOrWhiteSpace(input._System_objDescription))
|
|
{
|
|
response.Success = true;
|
|
response.Message = "请输入必填字段";
|
|
return response;
|
|
}
|
|
if (input._System_objDescription.Length > 40)
|
|
{
|
|
response.Success = true;
|
|
response.Message = "项目名称不能超过40字符";
|
|
return response;
|
|
}
|
|
//判断是否存在项目记录
|
|
var clientExists = await _obj109Rep.AsQueryable().AnyAsync(x => x._System_objNBS == input._System_objNBS && x.deleted == false);
|
|
|
|
if (clientExists == false)
|
|
{
|
|
var fieldList = new List<Field>();
|
|
if (input.fld004503 != null)
|
|
{
|
|
fieldList.Add(new Field { key = "fld004503", value = input.fld004503.ToString() });
|
|
}
|
|
if (input.fld004503 != null)
|
|
{
|
|
fieldList.Add(new Field { key = "fld004504", value = input.fld004504.ToString() });
|
|
}
|
|
|
|
fieldList.Add(new Field { key = "fld004684", value = input.fld004684 });
|
|
fieldList.Add(new Field { key = "_System_objNBS", value = input._System_objNBS });
|
|
fieldList.Add(new Field { key = "_System_objDescription", value = input._System_objDescription });
|
|
fieldList.Add(new Field { key = "fld004728", value = input.fld004728 });
|
|
fieldList.Add(new Field { key = "fld005299", value = input.fld005299 });
|
|
fieldList.Add(new Field { key = "fld005300", value = input.fld005300 });
|
|
fieldList.Add(new Field { key = "fld005281", value = "SET" });
|
|
fieldList.Add(new Field { key = "fld004521", value = "M" });
|
|
fieldList.Add(new Field { key = "fld004519", value = "FERT" });
|
|
fieldList.Add(new Field { key = "fld004522", value = "1000" });
|
|
fieldList.Add(new Field { key = "fld004928", value = "E" });
|
|
fieldList.Add(new Field { key = "fld004935", value = "X" });
|
|
fieldList.Add(new Field { key = "fld004510", value = "A" });
|
|
fieldList.Add(new Field { key = "fld004514", value = "A" });
|
|
fieldList.Add(new Field { key = "fld004517", value = "A" });
|
|
fieldList.Add(new Field { key = "fld005753", value = "OA" });
|
|
|
|
var fieldGroupValue = await _fieldGroupDefaultRep.AsQueryable().Where(x => x.GroupObjid == input.object_id).ToListAsync();
|
|
|
|
for (int i = 0; i < fieldGroupValue.Count; i++)
|
|
{
|
|
fieldList.Add(new Field { key = "fld00" + fieldGroupValue[i].ColumnId, value = fieldGroupValue[i].DefaultValue });
|
|
}
|
|
|
|
var fieldGroup = await _objectFieldsGroupsRep.AsQueryable().Where(x => x.GroupName == input.field_group).FirstAsync();
|
|
|
|
var data = new CreateProjectInput
|
|
{
|
|
object_id = input.object_id,
|
|
field_group_id = fieldGroup.GroupObjId,
|
|
fields = fieldList
|
|
};
|
|
response = await _solidWorksManageService.CreateProject(data);
|
|
var projectData = await _obj109Rep.AsQueryable().Where(x => x._System_objNBS == input._System_objNBS).FirstAsync();
|
|
|
|
var CheckData = new CheckDataInput()
|
|
{
|
|
object_id = input.object_id,
|
|
record_guid = projectData.RecordGuid,
|
|
bom_level = 1
|
|
};
|
|
await _solidWorksManageService.CheckOut(CheckData);
|
|
await _solidWorksManageService.CheckIn(CheckData);
|
|
}
|
|
else if (clientExists == true)
|
|
{
|
|
var updateable = await _obj109Rep.AsUpdateable()
|
|
.SetColumns(it => new Obj109
|
|
{
|
|
fld004684 = input.fld004684,
|
|
_System_ObjDescription = input._System_objDescription,
|
|
fld004728 = input.fld004728,
|
|
fld005299 = input.fld005299,
|
|
fld005300 = input.fld005300,
|
|
fld004503 = input.fld004503,
|
|
fld004504 = input.fld004504
|
|
|
|
})
|
|
.Where(x => x._System_objNBS == input._System_objNBS && x.deleted == false)
|
|
.ExecuteCommandHasChangeAsync();
|
|
response.Success = true;
|
|
response.Message = updateable ? "修改成功" : "修改失败";
|
|
}
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// OA创建问题报告
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)]
|
|
[ApiDescriptionSettings(Name = "OaCreateProcess"), HttpPost]
|
|
[DisplayName("OA创建流程")]
|
|
public async Task<ManageResponse> OaCreateProcess(OaCreateProcessInput input)
|
|
{
|
|
var response = new ManageResponse();
|
|
|
|
if (
|
|
string.IsNullOrWhiteSpace(input._System_objNBS) ||
|
|
string.IsNullOrWhiteSpace(input._System_objDescription) ||
|
|
string.IsNullOrWhiteSpace(input.fld005831) ||
|
|
string.IsNullOrWhiteSpace(input.fld005832) ||
|
|
string.IsNullOrWhiteSpace(input.fld005833) ||
|
|
string.IsNullOrWhiteSpace(input.fld005836) ||
|
|
string.IsNullOrWhiteSpace(input.fld005842) ||
|
|
string.IsNullOrWhiteSpace(input.fld005847) ||
|
|
input.fld005849 == default(DateTime) ||
|
|
//string.IsNullOrWhiteSpace(input.fld005849.ToString("yyyy-MM-dd HH:mm:ss")) ||
|
|
string.IsNullOrWhiteSpace(input.fld005850) ||
|
|
input.fld005852 == default(DateTime) ||
|
|
//string.IsNullOrWhiteSpace(input.fld005852.ToString("yyyy-MM-dd HH:mm:ss")) ||
|
|
string.IsNullOrWhiteSpace(input.fld005853) ||
|
|
string.IsNullOrWhiteSpace(input.fld005854)
|
|
)
|
|
{
|
|
response.Success = true;
|
|
response.Message = "请输入必填字段";
|
|
return response;
|
|
}
|
|
|
|
//判断是否存在项目记录
|
|
var clientExists = await _obj140Rep.AsQueryable().AnyAsync(x => x._System_objNBS == input._System_objNBS && x.deleted == false);
|
|
|
|
if (clientExists == false)
|
|
{
|
|
var fieldList = new List<Field>();
|
|
|
|
fieldList.Add(new Field { key = "_System_objNBS", value = input._System_objNBS });
|
|
fieldList.Add(new Field { key = "_System_objDescription", value = input._System_objDescription });
|
|
fieldList.Add(new Field { key = "fld005831", value = input.fld005831 });
|
|
fieldList.Add(new Field { key = "fld005832", value = input.fld005832 });
|
|
fieldList.Add(new Field { key = "fld005833", value = input.fld005833 });
|
|
var responsiblePersonOaData = await _obj81Rep.AsQueryable().Where(x=>x.fld004900==input.fld005836 && x.deleted==false).ToListAsync();
|
|
if (responsiblePersonOaData.Count!=0)
|
|
{
|
|
fieldList.Add(new Field { key = "fld005836", value = "81" });
|
|
fieldList.Add(new Field { key = "fld005836_Rec", value = responsiblePersonOaData[0].RecordGuid });
|
|
}
|
|
|
|
fieldList.Add(new Field { key = "fld005842", value = input.fld005842 });
|
|
var createPersonOaData=await _obj81Rep.AsQueryable().Where(x=>x.fld004900==input.fld005847 && x.deleted==false).ToListAsync();
|
|
if (createPersonOaData.Count!=0)
|
|
{
|
|
fieldList.Add(new Field { key = "fld005848", value = "81" });
|
|
fieldList.Add(new Field { key = "fld005848_Rec", value = createPersonOaData[0].RecordGuid });
|
|
}
|
|
|
|
|
|
fieldList.Add(new Field { key = "fld005849", value = input.fld005849.ToString("yyyy-MM-dd HH:mm:ss") });
|
|
var reviewerOaData = await _obj81Rep.AsQueryable().Where(x => x.fld004900 == input.fld005850 && x.deleted == false).ToListAsync();
|
|
if (reviewerOaData.Count != 0)
|
|
{
|
|
fieldList.Add(new Field { key = "fld005851", value = "81" });
|
|
fieldList.Add(new Field { key = "fld005851_Rec", value = reviewerOaData[0].RecordGuid });
|
|
}
|
|
|
|
fieldList.Add(new Field { key = "fld005852", value = input.fld005852.ToString("yyyy-MM-dd HH:mm:ss") });
|
|
fieldList.Add(new Field { key = "fld005853", value = input.fld005853 });
|
|
fieldList.Add(new Field { key = "fld005854", value = input.fld005854 });
|
|
fieldList.Add(new Field { key = "fld005855", value = "OA" });
|
|
|
|
if (!string.IsNullOrWhiteSpace(input.fld005838))
|
|
{
|
|
var mechanicalProblemHandlerOaId = await _obj81Rep.AsQueryable().Where(x => x.fld004900 == input.fld005838 && x.deleted == false).ToListAsync();
|
|
if (mechanicalProblemHandlerOaId.Count != 0)
|
|
{
|
|
fieldList.Add(new Field { key = "fld005837", value = "81" });
|
|
fieldList.Add(new Field { key = "fld005837_Rec", value = mechanicalProblemHandlerOaId[0].RecordGuid });
|
|
}
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(input.fld005841))
|
|
{
|
|
fieldList.Add(new Field { key = "fld005841", value = input.fld005841 });
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(input.fld005843))
|
|
{
|
|
fieldList.Add(new Field { key = "fld005843", value = input.fld005843 });
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(input.fld005846))
|
|
{
|
|
fieldList.Add(new Field { key = "fld005846", value = input.fld005846 });
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(input.fld005844))
|
|
{
|
|
fieldList.Add(new Field { key = "fld005844", value = input.fld005844 });
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(input.fld005845))
|
|
{
|
|
fieldList.Add(new Field { key = "fld005845", value = input.fld005845 });
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(input.fld006061))
|
|
{
|
|
var electricalProblemHandlerOaData = await _obj81Rep.AsQueryable().Where(x => x.fld004900 == input.fld006061 && x.deleted == false).ToListAsync();
|
|
if (electricalProblemHandlerOaData.Count != 0)
|
|
{
|
|
fieldList.Add(new Field { key = "fld006063", value = "81" });
|
|
fieldList.Add(new Field { key = "fld006063_Rec", value = electricalProblemHandlerOaData[0].RecordGuid });
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(input.fld006062))
|
|
{
|
|
var softwareProblemHandlerOaData = await _obj81Rep.AsQueryable().Where(x => x.fld004900 == input.fld006062 && x.deleted == false).ToListAsync();
|
|
if (softwareProblemHandlerOaData.Count != 0)
|
|
{
|
|
fieldList.Add(new Field { key = "fld006062", value = "81" });
|
|
fieldList.Add(new Field { key = "fld006062_Rec", value = softwareProblemHandlerOaData[0].RecordGuid });
|
|
}
|
|
}
|
|
|
|
var fieldGroup = await _objectFieldsGroupsRep.AsQueryable().Where(x => x.GroupName == input.field_group && x.ObjectId == 140).FirstAsync();
|
|
|
|
var data = new CreateProjectInput
|
|
{
|
|
object_id = input.object_id,
|
|
field_group_id = fieldGroup.GroupObjId,
|
|
fields = fieldList
|
|
};
|
|
response = await _solidWorksManageService.CreateProcess(data);
|
|
var projectData = await _obj140Rep.AsQueryable().Where(x => x._System_objNBS == input._System_objNBS && x.deleted == false).FirstAsync();
|
|
|
|
var CheckData = new CheckDataInput()
|
|
{
|
|
object_id = input.object_id,
|
|
record_guid = projectData.RecordGuid,
|
|
bom_level = 1
|
|
};
|
|
|
|
await _solidWorksManageService.CheckIn(CheckData);
|
|
}
|
|
else
|
|
{
|
|
response.Success = true;
|
|
response.Message = "编码已存在";
|
|
}
|
|
|
|
return response;
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|