339 lines
17 KiB
C#
339 lines
17 KiB
C#
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Dtos.VisualDev;
|
|
using JNPF.Common.Filter;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.Extras.CollectiveOAuth.Models;
|
|
using JNPF.FriendlyException;
|
|
using JNPF.Systems.Entitys.Permission;
|
|
using JNPF.Systems.Entitys.System;
|
|
using JNPF.VisualDev;
|
|
using JNPF.VisualDev.Entitys;
|
|
using JNPF.VisualDev.Entitys.Dto.VisualDevModelData;
|
|
using JNPF.VisualDev.Interfaces;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Org.BouncyCastle.Crypto;
|
|
using Spire.Doc.Documents;
|
|
using SqlSugar;
|
|
using Tnb.BasicData;
|
|
using Tnb.BasicData.Entities;
|
|
using Tnb.EquipMgr.Entities;
|
|
using Tnb.EquipMgr.Entities.Dto;
|
|
using Tnb.EquipMgr.Interfaces;
|
|
|
|
namespace Tnb.EquipMgr
|
|
{
|
|
/// <summary>
|
|
/// 设备管理
|
|
/// </summary>
|
|
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
|
[Route("api/[area]/[controller]/[action]")]
|
|
[OverideVisualDev(ModuleId)]
|
|
|
|
public class EquipmentService : IOverideVisualDevService, IEquipmentService, IDynamicApiController, ITransient
|
|
{
|
|
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
|
private const string ModuleId = "26012367560469";
|
|
private readonly ISqlSugarRepository<EqpEquipment> _repository;
|
|
private readonly IVisualDevService _visualDevService;
|
|
private readonly IRunService _runService;
|
|
private readonly IUserManager _userManager;
|
|
|
|
public EquipmentService(ISqlSugarRepository<EqpEquipment> repository,
|
|
IVisualDevService visualDevService,
|
|
IUserManager userManager,
|
|
IRunService runService
|
|
)
|
|
{
|
|
_repository = repository;
|
|
_visualDevService = visualDevService;
|
|
_runService = runService;
|
|
_userManager = userManager;
|
|
OverideFuncs.CreateAsync = Create;
|
|
OverideFuncs.UpdateAsync = Update;
|
|
OverideFuncs.GetListAsync = PageList;
|
|
}
|
|
|
|
private async Task<object> PageList(VisualDevModelListQueryInput input)
|
|
{
|
|
Dictionary<string, string>? queryJson = !string.IsNullOrEmpty(input.queryJson) ? Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(input.queryJson) : new Dictionary<string, string>();
|
|
string equip_type_id = queryJson.ContainsKey("equip_type_id") ? queryJson["equip_type_id"].ToString() : "";
|
|
string code = queryJson.ContainsKey("code") ? queryJson["code"].ToString() : "";
|
|
string name = queryJson.ContainsKey("name") ? queryJson["name"].ToString() : "";
|
|
string contract_no = queryJson.ContainsKey("contract_no") ? queryJson["contract_no"].ToString() : "";
|
|
|
|
var result = await _repository.AsSugarClient().Queryable<EqpEquipment, OrganizeEntity,OrganizeEntity,UserEntity,UserEntity,BasSupplier,UserEntity,BasLocation,DictionaryTypeEntity,DictionaryDataEntity>((a, b,c,d,e,f,g,h,i,j) =>
|
|
new JoinQueryInfos(
|
|
JoinType.Left, a.use_department_id == b.Id,
|
|
JoinType.Left, a.manage_department_id == c.Id,
|
|
JoinType.Left, a.create_id == d.Id,
|
|
JoinType.Left, a.modify_id == e.Id,
|
|
JoinType.Left, a.supplier_id == f.id,
|
|
JoinType.Left, a.responsibler_id == g.Id,
|
|
JoinType.Left, a.as_location_id == h.id,
|
|
JoinType.Left, i.EnCode==DictConst.EquipmentLife,
|
|
JoinType.Left, i.Id==j.DictionaryTypeId && a.life==j.EnCode
|
|
))
|
|
.WhereIF(!string.IsNullOrEmpty(equip_type_id),a=>a.equip_type_id==equip_type_id)
|
|
.WhereIF(!string.IsNullOrEmpty(code),a=>a.code.Contains(code))
|
|
.WhereIF(!string.IsNullOrEmpty(name),a=>a.name.Contains(name))
|
|
.WhereIF(!string.IsNullOrEmpty(contract_no),a=>a.contract_no.Contains(contract_no))
|
|
.Select((a, b,c,d,e,f,g,h,i,j) => new EquipListOuput()
|
|
{
|
|
id = a.id,
|
|
org_id = a.org_id,
|
|
code = a.code ,
|
|
name = a.name ,
|
|
equip_type_id = a.equip_type_id ,
|
|
product_date = a.product_date,
|
|
manufacturer = a.manufacturer,
|
|
use_department_id = b.FullName,
|
|
use_department_id_id = a.use_department_id,
|
|
install_date = a.install_date ,
|
|
use_date = a.use_date,
|
|
accept_date = a.accept_date,
|
|
manage_department_id = c.FullName,
|
|
manage_department_id_id = a.manage_department_id,
|
|
life = j.FullName,
|
|
techno_logy_code = a.techno_logy_code,
|
|
remark = a.remark ,
|
|
timestamp = a.timestamp,
|
|
create_id = d.RealName,
|
|
create_id_id = a.create_id,
|
|
create_time = a.create_time,
|
|
modify_id = e.RealName,
|
|
modify_id_id = a.modify_id,
|
|
modify_time = a.modify_time,
|
|
extras = a.extras,
|
|
supplier_id = f.supplier_name,
|
|
supplier_id_id = a.supplier_id,
|
|
factory_code = a.factory_code,
|
|
contract_no = a.contract_no,
|
|
maintenance_unit = a.maintenance_unit,
|
|
maintenance_phone = a.maintenance_phone,
|
|
specification = a.specification,
|
|
installation_location = a.installation_location,
|
|
is_complete_set = a.is_complete_set=="1" ? "是" : "否",
|
|
dcs_id = a.dcs_id,
|
|
technology_parameter = a.technology_parameter,
|
|
status = a.status,
|
|
tonnage = a.tonnage,
|
|
eqp_machine_num = a.eqp_machine_num,
|
|
mold_id = a.mold_id,
|
|
station_code = a.station_code,
|
|
warranty_start_time = a.warranty_start_time,
|
|
warranty_end_time = a.warranty_end_time,
|
|
responsibler_id = g.RealName,
|
|
responsibler_id_id = a.responsibler_id,
|
|
qrcode = a.qrcode,
|
|
as_location_id = h.location_name,
|
|
as_location_id_id = a.as_location_id,
|
|
is_send = a.is_send==1 ? "是" : "否",
|
|
}).ToPagedListAsync(input.currentPage,input.pageSize);
|
|
return PageResult<EquipListOuput>.SqlSugarPageResult(result);
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 在线开发-获取设备列表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
private async Task<dynamic> GetList(VisualDevModelListQueryInput input)
|
|
{
|
|
Dictionary<string, string> dic = new()
|
|
{
|
|
{ "Qualified","合格"},
|
|
{ "Unqualified","不合格"},
|
|
};
|
|
|
|
SqlSugarPagedList<EquipmentListOutput> pagedList = await _repository.AsQueryable()
|
|
//.Where(it => it.station_code == input.station_code || string.IsNullOrEmpty(input.station_code))
|
|
.Select(it => new EquipmentListOutput
|
|
{
|
|
id = it.id,
|
|
eqp_code = it.code,
|
|
eqp_name = it.name,
|
|
eqp_type_code = SqlFunc.Subqueryable<EqpEquipType>().Where(x => x.id == it.equip_type_id).Select(x => x.code),
|
|
//accept_status = it.accept_status,
|
|
//supplier_code = it.supplier_code,
|
|
install_date = it.install_date,
|
|
//use_department_code = it.use_department_code,
|
|
remark = it.remark,
|
|
})
|
|
//.Mapper(it => it.accept_status = dic.ContainsKey(it.accept_status) ? dic[it.accept_status] : "")
|
|
.ToPagedListAsync(input.currentPage, input.pageSize);
|
|
return pagedList;
|
|
}
|
|
|
|
private async Task<dynamic> Create(VisualDevModelDataCrInput visualDevModelDataCrInput)
|
|
{
|
|
string? qrcode = visualDevModelDataCrInput.data.ContainsKey("qrcode") ? visualDevModelDataCrInput.data["qrcode"]?.ToString() : "";
|
|
if (!string.IsNullOrEmpty(qrcode) && await _repository.AsSugarClient().Queryable<BasQrcode>().AnyAsync(x => x.code == qrcode))
|
|
{
|
|
throw Oops.Bah("二维码总表中已存在该二维码");
|
|
}
|
|
else
|
|
{
|
|
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
|
|
await _runService.Create(templateEntity, visualDevModelDataCrInput);
|
|
|
|
string equipId = visualDevModelDataCrInput.data["ReturnIdentity"].ToString() ?? "";
|
|
|
|
if (!string.IsNullOrEmpty(qrcode))
|
|
{
|
|
BasQrcode basQrcode = new()
|
|
{
|
|
code = visualDevModelDataCrInput.data["qrcode"].ToString(),
|
|
source_id = equipId,
|
|
source_name = "EQP_EQUIPMENT",
|
|
create_id = _userManager.UserId,
|
|
create_time = DateTime.Now,
|
|
org_id = _userManager.GetUserInfo().Result.organizeId,
|
|
};
|
|
_ = await _repository.AsSugarClient().Insertable<BasQrcode>(basQrcode).ExecuteCommandAsync();
|
|
}
|
|
}
|
|
return await Task.FromResult(true);
|
|
}
|
|
|
|
private async Task<dynamic> Update(string id, VisualDevModelDataUpInput visualDevModelDataUpInput)
|
|
{
|
|
string? qrcode = visualDevModelDataUpInput.data.ContainsKey("qrcode") ? visualDevModelDataUpInput.data["qrcode"]?.ToString() : "";
|
|
if (!string.IsNullOrEmpty(qrcode) && await _repository.AsSugarClient().Queryable<BasQrcode>().AnyAsync(x => x.code == visualDevModelDataUpInput.data["qrcode"] && x.source_id != id))
|
|
{
|
|
throw Oops.Bah("二维码总表中已存在该二维码");
|
|
}
|
|
else
|
|
{
|
|
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
|
|
await _runService.Update(id, templateEntity, visualDevModelDataUpInput);
|
|
|
|
if (!string.IsNullOrEmpty(qrcode))
|
|
{
|
|
if (await _repository.AsSugarClient().Queryable<BasQrcode>().AnyAsync(x => x.source_id == id))
|
|
{
|
|
_ = await _repository.AsSugarClient().Updateable<BasQrcode>()
|
|
.SetColumns(x => x.code == visualDevModelDataUpInput.data["qrcode"].ToString()).Where(x => x.source_id == id)
|
|
.ExecuteCommandAsync();
|
|
}
|
|
else
|
|
{
|
|
BasQrcode basQrcode = new()
|
|
{
|
|
code = visualDevModelDataUpInput.data["qrcode"].ToString(),
|
|
source_id = id,
|
|
source_name = "EQP_EQUIPMENT",
|
|
create_id = _userManager.UserId,
|
|
create_time = DateTime.Now,
|
|
org_id = _userManager.GetUserInfo().Result.organizeId,
|
|
};
|
|
_ = await _repository.AsSugarClient().Insertable<BasQrcode>(basQrcode).ExecuteCommandAsync();
|
|
}
|
|
}
|
|
}
|
|
return await Task.FromResult(true);
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<EqpEquipment> GetEntityById(Dictionary<string, string> dic)
|
|
{
|
|
string id = dic["id"];
|
|
return await _repository.GetSingleAsync(x => x.id == id);
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<dynamic> GetListByTypeId(Dictionary<string, string> dic)
|
|
{
|
|
string typeIds = dic["typeIds"];
|
|
string[] typeIdArr = typeIds.Split(",");
|
|
int currentPage = int.Parse(dic["currentPage"].ToString());
|
|
int pagesize = int.Parse(dic["pageSize"].ToString());
|
|
string queryJson = dic["queryJson"];
|
|
SqlSugarPagedList<EqpEquipment> result = await _repository.AsSugarClient().Queryable<EqpEquipment>()
|
|
.WhereIF(typeIdArr.Length > 0, a => typeIdArr.Contains(a.equip_type_id))
|
|
.WhereIF(!string.IsNullOrEmpty(queryJson), a => a.name.Contains(queryJson) || a.code.Contains(queryJson))
|
|
.Select(a => a).ToPagedListAsync(currentPage, pagesize);
|
|
return PageResult<EqpEquipment>.SqlSugarPageResult(result);
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<dynamic> GetWorklineAndEquipTree(Dictionary<string, string> dic)
|
|
{
|
|
string equipTypes = dic.ContainsKey("equipTypes") ? dic["equipTypes"] : "";
|
|
ISqlSugarClient db = _repository.AsSugarClient();
|
|
ISugarQueryable<WorklineAndEquipTreeOutput> queryable1 = db.Queryable<OrganizeEntity>()
|
|
.Where((a) => a.DeleteMark == null && a.Category == DictConst.RegionCategoryWorkshopCode)
|
|
.Select((a) => new WorklineAndEquipTreeOutput()
|
|
{
|
|
id = a.Id,
|
|
title = a.EnCode + "/" + a.FullName,
|
|
parentId = "0",
|
|
hasChildren = SqlFunc.Subqueryable<OrganizeEntity>().Where(b => b.ParentId == a.Id && b.DeleteMark == null && b.Category == DictConst.RegionCategoryWorklineCode).Any(),
|
|
num = SqlFunc.Subqueryable<OrganizeEntity>().Where(b => b.ParentId == a.Id && b.DeleteMark == null && b.Category == DictConst.RegionCategoryWorklineCode).Count(),
|
|
isLeaf = false,
|
|
children = SqlFunc.Subqueryable<OrganizeEntity>().Where(b => b.ParentId == a.Id && b.DeleteMark == null && b.Category == DictConst.RegionCategoryWorklineCode).ToList(b => new WorklineAndEquipTreeOutput()
|
|
{
|
|
id = b.Id,
|
|
title = b.EnCode + "/" + b.FullName,
|
|
parentId = b.ParentId,
|
|
hasChildren = false,
|
|
num = 0,
|
|
isLeaf = true,
|
|
})
|
|
});
|
|
|
|
List<WorklineAndEquipTreeOutput> list2 = new();
|
|
if (!string.IsNullOrEmpty(equipTypes))
|
|
{
|
|
string[] equipTypeArr = equipTypes.Split(",");
|
|
list2 = await db.Queryable<EqpEquipType>()
|
|
.Where((a) => equipTypeArr.Contains(a.code))
|
|
.Select((a) => new WorklineAndEquipTreeOutput()
|
|
{
|
|
id = a.id,
|
|
title = a.name,
|
|
parentId = "0",
|
|
hasChildren = SqlFunc.Subqueryable<EqpEquipment>().Where(b => b.equip_type_id == a.id).Any(),
|
|
num = SqlFunc.Subqueryable<EqpEquipment>().Where(b => b.equip_type_id == a.id).Count(),
|
|
isLeaf = false,
|
|
children = SqlFunc.Subqueryable<EqpEquipment>().Where(b => b.equip_type_id == a.id).ToList(b => new WorklineAndEquipTreeOutput()
|
|
{
|
|
id = b.id,
|
|
title = b.code + "/" + b.name,
|
|
parentId = b.equip_type_id,
|
|
hasChildren = false,
|
|
num = 0,
|
|
isLeaf = true,
|
|
})
|
|
}).ToListAsync();
|
|
|
|
}
|
|
|
|
// var list = await db.UnionAll(queryable1, queryable2).ToListAsync();
|
|
List<WorklineAndEquipTreeOutput> list1 = await queryable1.ToListAsync();
|
|
list1.AddRange(list2);
|
|
return new AuthResponse(200, "", new Dictionary<string, object>()
|
|
{
|
|
["list"] = list1,
|
|
});
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<EqpEquipment> GetEntityByQrcode(Dictionary<string, string> dic)
|
|
{
|
|
string qrcode = dic["qrcode"];
|
|
return await _repository.GetSingleAsync(x => x.qrcode == qrcode);
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<dynamic> SaveSend(string id)
|
|
{
|
|
await _repository.AsSugarClient().Updateable<EqpEquipment>()
|
|
.SetColumns(x => x.is_send == 1 - x.is_send)
|
|
.Where(x => x.id == id)
|
|
.ExecuteCommandAsync();
|
|
return "成功";
|
|
}
|
|
}
|
|
} |