执行代码清理,修复warning

This commit is contained in:
2023-11-06 19:59:12 +08:00
parent c6b8dfc861
commit 1dbb17f103
118 changed files with 5046 additions and 4111 deletions

View File

@@ -14,7 +14,7 @@ using Tnb.BasicData;
using Tnb.EquipMgr.Entities;
using Tnb.EquipMgr.Entities.Dto;
namespace Tnb.EquipMgr
namespace Tnb.EquipMgr.App
{
/// <summary>
/// app设备维修登记
@@ -45,12 +45,12 @@ namespace Tnb.EquipMgr
private async Task<dynamic> GetList(VisualDevModelListQueryInput input)
{
var db = _repository.AsSugarClient();
Dictionary<string, object> queryJson = !string.IsNullOrEmpty(input.queryJson) ? JsonConvert.DeserializeObject<Dictionary<string, object>>(input.queryJson) : new Dictionary<string, object>();
string code = queryJson != null && queryJson.ContainsKey("code") ? queryJson["code"].ToString() : "";
string name = queryJson != null && queryJson.ContainsKey("name") ? queryJson["name"].ToString() : "";
ISqlSugarClient db = _repository.AsSugarClient();
Dictionary<string, object>? queryJson = !string.IsNullOrEmpty(input.queryJson) ? JsonConvert.DeserializeObject<Dictionary<string, object>>(input.queryJson) : new Dictionary<string, object>();
string? code = queryJson != null && queryJson.ContainsKey("code") ? queryJson["code"].ToString() : "";
string? name = queryJson != null && queryJson.ContainsKey("name") ? queryJson["name"].ToString() : "";
string userId = _userManager.UserId;
var result = await db.Queryable<EqpRepairApply>()
SqlSugarPagedList<PdaRepairApplyListOutput> result = await db.Queryable<EqpRepairApply>()
.LeftJoin<EqpEquipment>((a, b) => a.equip_id == b.id)
.LeftJoin<UserEntity>((a, b, c) => a.apply_user_id == c.Id)
.LeftJoin<DictionaryTypeEntity>((a, b, c, d) => d.EnCode == DictConst.RepairStatus)
@@ -86,27 +86,31 @@ namespace Tnb.EquipMgr
/// <param name="dic"></param>
/// <returns></returns>
[HttpPost]
public async Task<dynamic> GetRepairInfoById(Dictionary<string, string> dic)
public async Task<dynamic?> GetRepairInfoById(Dictionary<string, string> dic)
{
string id = dic.ContainsKey("id") ? dic["id"] : "";
if (string.IsNullOrEmpty(id)) return null;
var db = _repository.AsSugarClient();
if (string.IsNullOrEmpty(id))
{
return null;
}
ISqlSugarClient db = _repository.AsSugarClient();
return await db.Queryable<EqpRepairApply>()
.LeftJoin<EqpEquipment>((a, b) => a.equip_id == b.id)
.Where((a, b) => a.id == id)
.Select((a, b) => new
{
id = a.id,
a.id,
a.code,
a.name,
equip_id = a.equip_id,
a.equip_id,
equip_code = b.code,
equip_name = b.name,
expect_complete_time = a.expect_complete_time == null ? "" : a.expect_complete_time.Value.ToString("yyyy-MM-dd"),
is_ugent = a.is_ugent,
description = a.description,
status = a.status,
repairer_id = a.repairer_id,
a.is_ugent,
a.description,
a.status,
a.repairer_id,
}).FirstAsync();
}

View File

@@ -30,28 +30,38 @@ namespace Tnb.EquipMgr
protected async Task Relevance<TSrc, TDest>(TSrc input, string mColumnName, string name, Expression<Func<TDest, bool>> deleleExp) where TDest : BaseEntity<string>, new()
where TSrc : BaseMoldMaintainInput
{
if (input == null) throw new ArgumentNullException(nameof(input));
await _db.Deleteable<TDest>().Where(deleleExp).ExecuteCommandAsync();
var entities = new List<TDest>();
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
_ = await _db.Deleteable<TDest>().Where(deleleExp).ExecuteCommandAsync();
List<TDest> entities = new();
if (input.ids?.Count > 0)
{
foreach (var id in input.ids)
foreach (string id in input.ids)
{
var pk = id;
string pk = id;
TDest entity = new();
entity.PropertySetValue(mColumnName, input.id);
entity.PropertySetValue(name, pk);
entities.Add(entity);
}
}
var row = await _db.Insertable(entities).ExecuteCommandAsync();
if (row < 1) throw Oops.Oh(ErrorCode.COM1000);
int row = await _db.Insertable(entities).ExecuteCommandAsync();
if (row < 1)
{
throw Oops.Oh(ErrorCode.COM1000);
}
}
protected async Task Delete<T>(Expression<Func<T, bool>> delFilter) where T : BaseEntity<string>, new()
{
var row = await _db.Deleteable<T>().Where(delFilter).ExecuteCommandAsync();
if (row < 1) throw Oops.Oh(ErrorCode.COM1002);
int row = await _db.Deleteable<T>().Where(delFilter).ExecuteCommandAsync();
if (row < 1)
{
throw Oops.Oh(ErrorCode.COM1002);
}
}
@@ -62,13 +72,13 @@ namespace Tnb.EquipMgr
Expression<Func<TOutput, object>> destMap
) where TDest : BaseEntity<string>, new()
{
var config = new TypeAdapterConfig();
config.ForType<TDest, TOutput>().Map(destMap, srcMap);
var list = new List<TOutput>();
var itemIds = await _db.Queryable<TRelaction>().Where(masterFilterExp).Select(masterSelector).ToListAsync();
TypeAdapterConfig config = new();
_ = config.ForType<TDest, TOutput>().Map(destMap, srcMap);
List<TOutput> list = new();
List<string> itemIds = await _db.Queryable<TRelaction>().Where(masterFilterExp).Select(masterSelector).ToListAsync();
if (itemIds?.Count > 0)
{
var items = await _db.Queryable<TDest>().Where(it => itemIds.Contains(it.id)).ToListAsync();
List<TDest> items = await _db.Queryable<TDest>().Where(it => itemIds.Contains(it.id)).ToListAsync();
list = items.Adapt<List<TOutput>>();
}
return list;

View File

@@ -32,13 +32,13 @@ namespace Tnb.EquipMgr
[HttpPost]
public async Task<dynamic> GetEquipDaqList(EquipQueryInput input)
{
var db = _repository.AsSugarClient();
Dictionary<string, string>? queryJson = new Dictionary<string, string>();
ISqlSugarClient db = _repository.AsSugarClient();
Dictionary<string, string>? queryJson = new();
if (input != null && !string.IsNullOrEmpty(input.queryJson))
{
queryJson = JsonConvert.DeserializeObject<Dictionary<string, string>>(input.queryJson);
}
var result = await db.Queryable<EqpDaq>()
SqlSugarPagedList<EquipDaqQueryOutput> result = await db.Queryable<EqpDaq>()
.LeftJoin<UserEntity>((a, b) => a.create_id == b.Id)
.WhereIF(input != null, a => a.equip_id == input!.equip_id)
.WhereIF(queryJson != null && queryJson.ContainsKey("data_source"), a => a.data_source == queryJson!["data_source"])
@@ -56,7 +56,7 @@ namespace Tnb.EquipMgr
label_name = a.label_name,
label_point = a.label_point,
remark = a.remark
}).ToPagedListAsync((input?.currentPage ?? 1), (input?.pageSize ?? 50));
}).ToPagedListAsync(input?.currentPage ?? 1, input?.pageSize ?? 50);
return PageResult<EquipDaqQueryOutput>.SqlSugarPageResult(result);
}

View File

@@ -40,12 +40,12 @@ namespace Tnb.EquipMgr
[HttpPost]
public async Task<string> Upload([FromForm] string equip_id, [FromForm] ChunkModel input)
{
string msg = "";
string msg;
try
{
var attachment = await _fileService.Uploader("annexpic", input);
dynamic attachment = await _fileService.Uploader("annexpic", input);
EqpEquipFile eqpEquipFile = new EqpEquipFile()
EqpEquipFile eqpEquipFile = new()
{
file_name = input.file.FileName,
equip_id = equip_id,
@@ -55,12 +55,11 @@ namespace Tnb.EquipMgr
org_id = _userManager.GetUserInfo().Result.organizeId,
};
await _repository.InsertAsync(eqpEquipFile);
_ = await _repository.InsertAsync(eqpEquipFile);
msg = "上传成功";
}
catch (Exception e)
{
msg = "上传失败";
Log.Error(e.Message);
throw Oops.Oh(ErrorCode.D8001);
}
@@ -71,13 +70,13 @@ namespace Tnb.EquipMgr
[HttpPost]
public async Task<dynamic> GetEquipFileList(EquipQueryInput input)
{
var db = _repository.AsSugarClient();
Dictionary<string, string>? queryJson = new Dictionary<string, string>();
ISqlSugarClient db = _repository.AsSugarClient();
Dictionary<string, string>? queryJson = new();
if (!string.IsNullOrEmpty(input.queryJson))
{
queryJson = JsonConvert.DeserializeObject<Dictionary<string, string>>(input.queryJson);
}
var result = await db.Queryable<EqpEquipFile>()
SqlSugarPagedList<EquipFileQueryOutput> result = await db.Queryable<EqpEquipFile>()
.LeftJoin<UserEntity>((a, b) => a.create_id == b.Id)
.LeftJoin<UserEntity>((a, b, c) => a.modify_id == c.Id)
.LeftJoin<EqpEquipment>((a, b, c, d) => a.equip_id == d.id)

View File

@@ -33,22 +33,19 @@ namespace Tnb.EquipMgr
[HttpPost]
public async Task<string> Scrap(EqpEquipScrap eqpEquipScrap)
{
var db = _repository.AsSugarClient();
ISqlSugarClient db = _repository.AsSugarClient();
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
{
eqpEquipScrap.id = SnowflakeIdHelper.NextId();
eqpEquipScrap.create_id = _userManager.UserId;
eqpEquipScrap.create_time = DateTime.Now;
await _repository.InsertAsync(eqpEquipScrap);
_ = await _repository.InsertAsync(eqpEquipScrap);
await db.Updateable<EqpEquipment>().SetColumns(x => x.life == EquipmentLife.SCRAP)
_ = await db.Updateable<EqpEquipment>().SetColumns(x => x.life == EquipmentLife.SCRAP)
.Where(x => x.id == eqpEquipScrap.equip_id).ExecuteCommandAsync();
});
if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
return result.IsSuccess ? "报废成功" : result.ErrorMessage;
return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : result.IsSuccess ? "报废成功" : result.ErrorMessage;
}
}
}

View File

@@ -33,14 +33,17 @@ namespace Tnb.EquipMgr
public async Task AddEquipSpareParts(EquipSparePartsInput input)
{
List<EqpEquipSpareParts> oldList = await _repository.GetListAsync(x => x.equip_id == input.equip_id);
List<EqpEquipSpareParts> list = new List<EqpEquipSpareParts>();
List<EqpEquipSpareParts> list = new();
string orgId = _userManager?.GetUserInfo().Result.organizeId ?? "";
if (input != null && input.spare_parts_ids != null)
{
foreach (var spare_parts_id in input.spare_parts_ids)
foreach (string spare_parts_id in input.spare_parts_ids)
{
if (oldList.Any(x => x.spare_parts_id == spare_parts_id))
{
continue;
}
list.Add(new EqpEquipSpareParts()
{
id = SnowflakeIdHelper.NextId(),
@@ -53,19 +56,19 @@ namespace Tnb.EquipMgr
}
}
await _repository.InsertRangeAsync(list);
_ = await _repository.InsertRangeAsync(list);
}
[HttpPost]
public async Task<dynamic> GetEquipSparePartsList(EquipQueryInput input)
{
var db = _repository.AsSugarClient();
Dictionary<string, string>? queryJson = new Dictionary<string, string>();
ISqlSugarClient db = _repository.AsSugarClient();
Dictionary<string, string>? queryJson = new();
if (!string.IsNullOrEmpty(input.queryJson))
{
queryJson = JsonConvert.DeserializeObject<Dictionary<string, string>>(input.queryJson);
}
var result = await db.Queryable<EqpEquipSpareParts>()
SqlSugarPagedList<EquipSparePartsQueryOutput> result = await db.Queryable<EqpEquipSpareParts>()
.LeftJoin<EqpSpareParts>((a, b) => a.spare_parts_id == b.id)
.LeftJoin<DictionaryTypeEntity>((a, b, c) => c.EnCode == Tnb.BasicData.DictConst.SparePartsType && c.DeleteMark == null)
.LeftJoin<DictionaryDataEntity>((a, b, c, d) => d.DictionaryTypeId == c.Id && b.type_id == d.EnCode)

View File

@@ -30,22 +30,25 @@ namespace Tnb.EquipMgr
string id = parameters["id"];
DbResult<bool> result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
{
await _repository.UpdateAsync(x => new EqpMaintainTemEquipH()
_ = await _repository.UpdateAsync(x => new EqpMaintainTemEquipH()
{
is_start = "0"
}, x => x.id == id);
List<string> ids = await _repository.AsSugarClient().Queryable<EqpMaintainRecordH>()
.Where(x => x.maintain_tem_equip_id == id && x.status == SpotInsRecordExecutionStatus.TOBEEXECUTED)
.Select(x => x.id).ToListAsync();
await _repository.AsSugarClient().Deleteable<EqpMaintainRecordH>()
_ = await _repository.AsSugarClient().Deleteable<EqpMaintainRecordH>()
.Where(x => x.maintain_tem_equip_id == id && x.status == SpotInsRecordExecutionStatus.TOBEEXECUTED).ExecuteCommandAsync();
await _repository.AsSugarClient().Deleteable<EqpMaintainRecordD>()
_ = await _repository.AsSugarClient().Deleteable<EqpMaintainRecordD>()
.Where(x => ids.Contains(x.maintain_record_id)).ExecuteCommandAsync();
});
if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
if (!result.IsSuccess)
{
throw Oops.Oh(ErrorCode.COM1008);
}
}
}
}

View File

@@ -36,7 +36,7 @@ namespace Tnb.EquipMgr
[HttpPost]
public async Task<string> Publish(SpotInsTemPublishInput input)
{
var db = _repository.AsSugarClient();
ISqlSugarClient db = _repository.AsSugarClient();
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
{
EqpMaintainTemH eqpMaintainTemH = await _repository.GetSingleAsync(x => x.id == input.id);
@@ -44,13 +44,13 @@ namespace Tnb.EquipMgr
if (input.equipIds != null && input.equipIds.Length > 0)
{
List<EqpMaintainTemEquipH> insertEqpMaintainTemEquipHs = new List<EqpMaintainTemEquipH>();
List<EqpMaintainTemEquipD> insertEqpMaintainTemEquipDs = new List<EqpMaintainTemEquipD>();
foreach (var equipId in input.equipIds)
List<EqpMaintainTemEquipH> insertEqpMaintainTemEquipHs = new();
List<EqpMaintainTemEquipD> insertEqpMaintainTemEquipDs = new();
foreach (string equipId in input.equipIds)
{
string id = SnowflakeIdHelper.NextId();
string code = $"{DateTime.Now.ToString("yyyyMMdd") + equipId}";
EqpMaintainTemEquipH eqpMaintainTemEquipH = new EqpMaintainTemEquipH()
EqpMaintainTemEquipH eqpMaintainTemEquipH = new()
{
id = id,
code = code,
@@ -79,9 +79,9 @@ namespace Tnb.EquipMgr
if (eqpMaintainTemDs != null && eqpMaintainTemDs.Count > 0)
{
foreach (var eqpMaintainTem in eqpMaintainTemDs)
foreach (EqpMaintainTemD eqpMaintainTem in eqpMaintainTemDs)
{
EqpMaintainTemEquipD eqpMaintainTemEquipD = new EqpMaintainTemEquipD()
EqpMaintainTemEquipD eqpMaintainTemEquipD = new()
{
id = SnowflakeIdHelper.NextId(),
maintain_item_id = eqpMaintainTem.maintain_item_id,
@@ -92,27 +92,28 @@ namespace Tnb.EquipMgr
}
EqpMaintainTemEquipH oldMaintainTemEquipH = await db.Queryable<EqpMaintainTemEquipH>().Where(x => x.maintain_tem_id == input.id && x.equip_id == equipId).FirstAsync();
await db.Deleteable<EqpMaintainTemEquipH>().Where(x => x.maintain_tem_id == input.id && x.equip_id == equipId).ExecuteCommandAsync();
_ = await db.Deleteable<EqpMaintainTemEquipH>().Where(x => x.maintain_tem_id == input.id && x.equip_id == equipId).ExecuteCommandAsync();
if (oldMaintainTemEquipH != null)
await db.Deleteable<EqpMaintainTemEquipD>().Where(x => x.maintain_tem_equip_id == oldMaintainTemEquipH.id).ExecuteCommandAsync();
{
_ = await db.Deleteable<EqpMaintainTemEquipD>().Where(x => x.maintain_tem_equip_id == oldMaintainTemEquipH.id).ExecuteCommandAsync();
}
}
if (insertEqpMaintainTemEquipHs != null && insertEqpMaintainTemEquipHs.Count > 0)
{
await db.Insertable(insertEqpMaintainTemEquipHs).ExecuteCommandAsync();
_ = await db.Insertable(insertEqpMaintainTemEquipHs).ExecuteCommandAsync();
}
if (insertEqpMaintainTemEquipDs != null && insertEqpMaintainTemEquipDs.Count > 0)
{
await db.Insertable(insertEqpMaintainTemEquipDs).ExecuteCommandAsync();
_ = await db.Insertable(insertEqpMaintainTemEquipDs).ExecuteCommandAsync();
}
}
});
if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
return result.IsSuccess ? "发布成功" : result.ErrorMessage;
return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : result.IsSuccess ? "发布成功" : result.ErrorMessage;
}
}
}

View File

@@ -97,21 +97,23 @@ namespace Tnb.EquipMgr
input.data["code"] = await _billRuleService.GetBillNumber(CodeTemplateConst.EQPREPAIR_CODE);
}
EqpRepairApply eqpRepairApply = new EqpRepairApply();
eqpRepairApply.code = (string)input.data["code"];
eqpRepairApply.name = (string)input.data["name"];
eqpRepairApply.equip_id = (string)input.data["equip_id"];
eqpRepairApply.expect_complete_time = input.data["expect_complete_time"] != null && input.data["expect_complete_time"].ToString() != "" ? Convert.ToDateTime(input.data["expect_complete_time"]) : null;
eqpRepairApply.is_ugent = (int?)(long)input.data["is_ugent"];
eqpRepairApply.attachment = input.data.ContainsKey("attachment") ? (string)input.data["attachment"] : null;
eqpRepairApply.apply_user_id = (string)input.data["apply_user_id"];
eqpRepairApply.create_id = (string)input.data["create_id"];
eqpRepairApply.create_time = DateTime.Now;
eqpRepairApply.org_id = (string)input.data["org_id"];
eqpRepairApply.remark = (string)input.data["remark"];
eqpRepairApply.description = (string)input.data["description"];
eqpRepairApply.status = RepairApplyStatus.TOBEEXECUTED;
await _repository.InsertAsync(eqpRepairApply);
EqpRepairApply eqpRepairApply = new()
{
code = (string)input.data["code"],
name = (string)input.data["name"],
equip_id = (string)input.data["equip_id"],
expect_complete_time = input.data["expect_complete_time"] != null && input.data["expect_complete_time"].ToString() != "" ? Convert.ToDateTime(input.data["expect_complete_time"]) : null,
is_ugent = (int?)(long)input.data["is_ugent"],
attachment = input.data.ContainsKey("attachment") ? (string)input.data["attachment"] : null,
apply_user_id = (string)input.data["apply_user_id"],
create_id = (string)input.data["create_id"],
create_time = DateTime.Now,
org_id = (string)input.data["org_id"],
remark = (string)input.data["remark"],
description = (string)input.data["description"],
status = RepairApplyStatus.TOBEEXECUTED
};
_ = await _repository.InsertAsync(eqpRepairApply);
// VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
// await _runService.Create(templateEntity, input);
@@ -122,7 +124,7 @@ namespace Tnb.EquipMgr
public async Task<string> Repeal(Dictionary<string, string> dic)
{
string id = dic["id"];
await _repository.UpdateAsync(x => new EqpRepairApply()
_ = await _repository.UpdateAsync(x => new EqpRepairApply()
{
status = RepairApplyStatus.REPEAL
}, x => x.id == id);
@@ -133,7 +135,7 @@ namespace Tnb.EquipMgr
public async Task<string> Close(Dictionary<string, string> dic)
{
string id = dic["id"];
await _repository.UpdateAsync(x => new EqpRepairApply()
_ = await _repository.UpdateAsync(x => new EqpRepairApply()
{
status = RepairApplyStatus.CLOSE,
}, x => x.id == id);
@@ -146,10 +148,10 @@ namespace Tnb.EquipMgr
string id = dic["id"];
string repairerId = dic["repairerId"];
EqpRepairApply eqpRepairApply = await _repository.GetSingleAsync(x => x.id == id);
if (eqpRepairApply.status == RepairApplyStatus.TOBEEXECUTED ||
eqpRepairApply.status == RepairApplyStatus.REFUSE)
if (eqpRepairApply.status is RepairApplyStatus.TOBEEXECUTED or
RepairApplyStatus.REFUSE)
{
await _repository.UpdateAsync(x => new EqpRepairApply()
_ = await _repository.UpdateAsync(x => new EqpRepairApply()
{
repairer_id = repairerId,
status = RepairApplyStatus.TOBERECEIVED,
@@ -172,7 +174,7 @@ namespace Tnb.EquipMgr
{
if (_userManager.UserId == eqpRepairApply.repairer_id)
{
await _repository.UpdateAsync(x => new EqpRepairApply()
_ = await _repository.UpdateAsync(x => new EqpRepairApply()
{
status = RepairApplyStatus.RECEIVED,
}, x => x.id == id);
@@ -194,7 +196,7 @@ namespace Tnb.EquipMgr
{
string id = dic["id"];
string reason = dic["reason"];
var db = _repository.AsSugarClient();
ISqlSugarClient db = _repository.AsSugarClient();
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
{
EqpRepairApply eqpRepairApply = await _repository.GetSingleAsync(x => x.id == id);
@@ -202,11 +204,11 @@ namespace Tnb.EquipMgr
{
if (_userManager.UserId == eqpRepairApply.repairer_id)
{
await _repository.UpdateAsync(x => new EqpRepairApply()
_ = await _repository.UpdateAsync(x => new EqpRepairApply()
{
status = RepairApplyStatus.REFUSE,
}, x => x.id == id);
EqpRepairRefuse eqpRepairRefuse = new EqpRepairRefuse()
EqpRepairRefuse eqpRepairRefuse = new()
{
repair_apply_id = id,
reason = reason,
@@ -214,7 +216,7 @@ namespace Tnb.EquipMgr
create_time = DateTime.Now,
org_id = _userManager.GetUserInfo().Result.organizeId
};
await db.Insertable<EqpRepairRefuse>(eqpRepairRefuse).ExecuteCommandAsync();
_ = await db.Insertable<EqpRepairRefuse>(eqpRepairRefuse).ExecuteCommandAsync();
}
else
{
@@ -227,8 +229,7 @@ namespace Tnb.EquipMgr
}
});
if (!result.IsSuccess) throw Oops.Oh(result.ErrorMessage);
return "拒绝成功";
return !result.IsSuccess ? throw Oops.Oh(result.ErrorMessage) : "拒绝成功";
}
[HttpPost]
@@ -248,7 +249,7 @@ namespace Tnb.EquipMgr
if (_userManager.UserId == eqpRepairApply.repairer_id)
{
string status = input.is_out_apply == 1 ? RepairApplyStatus.TOBEOUTAPPLY : RepairApplyStatus.COMPLETED;
await _repository.UpdateAsync(x => new EqpRepairApply()
_ = await _repository.UpdateAsync(x => new EqpRepairApply()
{
fault_id = input.fault_id,
is_complete = input.is_complete,
@@ -294,13 +295,13 @@ namespace Tnb.EquipMgr
[HttpPost]
public async Task<dynamic> GetRepairRecordList(EquipQueryInput input)
{
var db = _repository.AsSugarClient();
Dictionary<string, string>? queryJson = new Dictionary<string, string>();
ISqlSugarClient db = _repository.AsSugarClient();
Dictionary<string, string>? queryJson = new();
if (!string.IsNullOrEmpty(input.queryJson))
{
queryJson = JsonConvert.DeserializeObject<Dictionary<string, string>>(input.queryJson);
}
var result = await db.Queryable<EqpRepairApply>()
SqlSugarPagedList<EquipRepairRecordQueryOutput> result = await db.Queryable<EqpRepairApply>()
.LeftJoin<UserEntity>((a, b) => a.apply_user_id == b.Id)
.LeftJoin<UserEntity>((a, b, c) => a.repairer_id == c.Id)
.Where(a => a.equip_id == input.equip_id)
@@ -328,7 +329,7 @@ namespace Tnb.EquipMgr
DateTime? start_time = input.start_time;
DateTime? end_time = input.end_time;
List<string> statusList = new List<string>();
List<string> statusList = new();
if (!string.IsNullOrEmpty(input.status))
{
switch (input.status)
@@ -363,8 +364,8 @@ namespace Tnb.EquipMgr
input.sidx = "a." + input.sidx;
}
var db = _repository.AsSugarClient();
var result = await db.Queryable<EqpRepairApply>()
ISqlSugarClient db = _repository.AsSugarClient();
SqlSugarPagedList<PadRepairListOutput> result = await db.Queryable<EqpRepairApply>()
.LeftJoin<UserEntity>((a, b) => a.apply_user_id == b.Id)
.LeftJoin<UserEntity>((a, b, c) => a.repairer_id == c.Id)
.LeftJoin<EqpEquipment>((a, b, c, d) => a.equip_id == d.id)
@@ -393,7 +394,7 @@ namespace Tnb.EquipMgr
repairer_id_id = c.Id,
remark = a.remark,
status = f.FullName
}).ToPagedListAsync((input?.currentPage ?? 1), (input?.pageSize ?? 50));
}).ToPagedListAsync(input?.currentPage ?? 1, input?.pageSize ?? 50);
return PageResult<PadRepairListOutput>.SqlSugarPageResult(result);
}

View File

@@ -39,7 +39,7 @@ namespace Tnb.EquipMgr
DbResult<bool> result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
{
EqpRepairApply eqpRepairApply = await _repository.AsSugarClient().Queryable<EqpRepairApply>().SingleAsync(x => x.id == input.repair_apply_id);
EqpRepairDelay repairDelay = new EqpRepairDelay()
EqpRepairDelay repairDelay = new()
{
id = SnowflakeIdHelper.NextId(),
equip_id = eqpRepairApply?.equip_id ?? "",
@@ -52,15 +52,14 @@ namespace Tnb.EquipMgr
create_time = DateTime.Now,
};
await _repository.InsertAsync(repairDelay);
_ = await _repository.InsertAsync(repairDelay);
await _repository.AsSugarClient().Updateable<EqpRepairApply>()
_ = await _repository.AsSugarClient().Updateable<EqpRepairApply>()
.SetColumns(x => x.expect_complete_time == input.expected_time)
.Where(x => x.id == input.repair_apply_id).ExecuteCommandAsync();
});
if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
return result.IsSuccess ? "延期成功" : result.ErrorMessage;
return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : result.IsSuccess ? "延期成功" : result.ErrorMessage;
}
}

View File

@@ -51,10 +51,10 @@ namespace Tnb.EquipMgr
public async Task<string> OutApply(RepairOutApplyInput input)
{
EqpRepairApply eqpRepairApply = await _repository.AsSugarClient().Queryable<EqpRepairApply>().SingleAsync(x => x.id == input.repair_apply_id);
if (eqpRepairApply.status == RepairApplyStatus.TOBEOUTAPPLY ||
eqpRepairApply.status == RepairApplyStatus.APPROVENOTPASS)
if (eqpRepairApply.status is RepairApplyStatus.TOBEOUTAPPLY or
RepairApplyStatus.APPROVENOTPASS)
{
var db = _repository.AsSugarClient();
ISqlSugarClient db = _repository.AsSugarClient();
string id = string.IsNullOrEmpty(input.id) ? SnowflakeIdHelper.NextId() : input.id;
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
{
@@ -92,7 +92,7 @@ namespace Tnb.EquipMgr
// },x=>x.id==input.id);
}
await db.Updateable<EqpRepairApply>()
_ = await db.Updateable<EqpRepairApply>()
.SetColumns(x => x.status == RepairApplyStatus.OUTAPPLYAPPROVE)
.Where(x => x.id == input.repair_apply_id).ExecuteCommandAsync();
@@ -100,7 +100,10 @@ namespace Tnb.EquipMgr
});
if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
if (!result.IsSuccess)
{
throw Oops.Oh(ErrorCode.COM1008);
}
if (result.IsSuccess)
{
@@ -129,7 +132,7 @@ namespace Tnb.EquipMgr
}
else
{
var entity = await _repository.GetSingleAsync(x => x.id == input.id);
EqpRepairOutApply entity = await _repository.GetSingleAsync(x => x.id == input.id);
if (entity != null)
{
@@ -170,10 +173,10 @@ namespace Tnb.EquipMgr
public async Task<string> Register(RepairApplyOutRegisterInput input)
{
var db = _repository.AsSugarClient();
ISqlSugarClient db = _repository.AsSugarClient();
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
{
await _repository.UpdateAsync(x => new EqpRepairOutApply()
_ = await _repository.UpdateAsync(x => new EqpRepairOutApply()
{
real_supplier_id = input.real_supplier_id,
cost = input.cost,
@@ -183,12 +186,10 @@ namespace Tnb.EquipMgr
attachment = input.attachment,
}, x => x.id == input.id);
await db.Updateable<EqpRepairApply>().SetColumns(x => x.status == RepairApplyStatus.COMPLETED)
_ = await db.Updateable<EqpRepairApply>().SetColumns(x => x.status == RepairApplyStatus.COMPLETED)
.Where(x => x.id == input.repair_apply_id).ExecuteCommandAsync();
});
if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
return result.IsSuccess ? "登记成功" : result.ErrorMessage;
return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : result.IsSuccess ? "登记成功" : result.ErrorMessage;
}
}

View File

@@ -50,7 +50,7 @@ namespace Tnb.EquipMgr
entity.create_time = DateTime.Now;
entity.create_id = _userManager.UserId;
entity.org_id = _userManager.GetUserInfo().Result.organizeId;
await _repository.InsertAsync(entity);
_ = await _repository.InsertAsync(entity);
}
}

View File

@@ -47,13 +47,13 @@ namespace Tnb.EquipMgr
private async Task<dynamic> Create(VisualDevModelDataCrInput input)
{
var db = _repository.AsSugarClient();
ISqlSugarClient db = _repository.AsSugarClient();
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
{
// VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
// await _runService.Create(templateEntity, input);
var code = await _billRuleService.GetBillNumber(Tnb.BasicData.CodeTemplateConst.SPAREPARTSREQUISITION_CODE);
EqpSparePartsRequisitionH eqpSparePartsRequisitionH = new EqpSparePartsRequisitionH()
string code = await _billRuleService.GetBillNumber(Tnb.BasicData.CodeTemplateConst.SPAREPARTSREQUISITION_CODE);
EqpSparePartsRequisitionH eqpSparePartsRequisitionH = new()
{
code = code,
equip_id = input.data.ContainsKey("equip_id") ? input.data["equip_id"].ToString() : "",
@@ -65,14 +65,14 @@ namespace Tnb.EquipMgr
org_id = _userManager.GetUserInfo().Result.organizeId,
};
await db.Insertable<EqpSparePartsRequisitionH>(eqpSparePartsRequisitionH).ExecuteCommandAsync();
_ = await db.Insertable<EqpSparePartsRequisitionH>(eqpSparePartsRequisitionH).ExecuteCommandAsync();
if (input.data.TryGetValue("tablefield120", out var value))
if (input.data.TryGetValue("tablefield120", out object? value))
{
var details = value.ToObject<List<Dictionary<string, string>>>();
List<EqpEquipSpareParts> eqpSparePartsList = new List<EqpEquipSpareParts>();
List<EqpSparePartsRequisitionD> eqpSparePartsRequisitionDs = new List<EqpSparePartsRequisitionD>() { };
foreach (var detail in details)
List<Dictionary<string, string>> details = value.ToObject<List<Dictionary<string, string>>>();
List<EqpEquipSpareParts> eqpSparePartsList = new();
List<EqpSparePartsRequisitionD> eqpSparePartsRequisitionDs = new() { };
foreach (Dictionary<string, string> detail in details)
{
string instockDetailId = detail.ContainsKey("instock_detail_id") ? detail["instock_detail_id"] : "";
string sparePartsId = detail.ContainsKey("spare_parts_id") ? detail["spare_parts_id"] : "";
@@ -99,7 +99,7 @@ namespace Tnb.EquipMgr
org_id = _userManager.GetUserInfo().Result.organizeId
});
await db.Updateable<EqpSparePartsInstockD>()
_ = await db.Updateable<EqpSparePartsInstockD>()
.SetColumns(x => x.use_quantity == x.use_quantity + quantity)
.Where(x => x.id == instockDetailId).ExecuteCommandAsync();
}
@@ -112,19 +112,18 @@ namespace Tnb.EquipMgr
if (eqpSparePartsRequisitionDs.Count > 0)
{
await db.Insertable<EqpSparePartsRequisitionD>(eqpSparePartsRequisitionDs).ExecuteCommandAsync();
_ = await db.Insertable<EqpSparePartsRequisitionD>(eqpSparePartsRequisitionDs).ExecuteCommandAsync();
}
if (eqpSparePartsList.Count > 0)
{
await db.Insertable<EqpEquipSpareParts>(eqpSparePartsList).ExecuteCommandAsync();
_ = await db.Insertable<EqpEquipSpareParts>(eqpSparePartsList).ExecuteCommandAsync();
}
}
});
if (!result.IsSuccess) throw Oops.Bah(result.ErrorMessage);
return result.IsSuccess ? "保存成功" : result.ErrorMessage;
return !result.IsSuccess ? throw Oops.Bah(result.ErrorMessage) : (dynamic)(result.IsSuccess ? "保存成功" : result.ErrorMessage);
}
}
}

View File

@@ -36,7 +36,7 @@ namespace Tnb.EquipMgr
[HttpPost]
public async Task<string> Publish(SpotInsTemPublishInput input)
{
var db = _repository.AsSugarClient();
ISqlSugarClient db = _repository.AsSugarClient();
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
{
EqpSpotInsTemH eqpSpotInsTemH = await _repository.GetSingleAsync(x => x.id == input.id);
@@ -44,13 +44,13 @@ namespace Tnb.EquipMgr
if (input.equipIds != null && input.equipIds.Length > 0)
{
List<EqpSpotInsTemEquipH> insertEqpSpotInsTemEquipHs = new List<EqpSpotInsTemEquipH>();
List<EqpSpotInsTemEquipD> insertEqpSpotInsTemEquipDs = new List<EqpSpotInsTemEquipD>();
foreach (var equipId in input.equipIds)
List<EqpSpotInsTemEquipH> insertEqpSpotInsTemEquipHs = new();
List<EqpSpotInsTemEquipD> insertEqpSpotInsTemEquipDs = new();
foreach (string equipId in input.equipIds)
{
string id = SnowflakeIdHelper.NextId();
string code = $"{DateTime.Now.ToString("yyyyMMdd") + equipId}";
EqpSpotInsTemEquipH eqpSpotInsTemEquipH = new EqpSpotInsTemEquipH()
EqpSpotInsTemEquipH eqpSpotInsTemEquipH = new()
{
id = id,
code = code,
@@ -79,9 +79,9 @@ namespace Tnb.EquipMgr
if (eqpSpotInsTemDs != null && eqpSpotInsTemDs.Count > 0)
{
foreach (var eqpSpotInsTem in eqpSpotInsTemDs)
foreach (EqpSpotInsTemD eqpSpotInsTem in eqpSpotInsTemDs)
{
EqpSpotInsTemEquipD eqpSpotInsTemEquipD = new EqpSpotInsTemEquipD()
EqpSpotInsTemEquipD eqpSpotInsTemEquipD = new()
{
id = SnowflakeIdHelper.NextId(),
spot_ins_item_id = eqpSpotInsTem?.spot_ins_item_id ?? "",
@@ -92,27 +92,28 @@ namespace Tnb.EquipMgr
}
EqpSpotInsTemEquipH oldSpotInsTemEquipH = await db.Queryable<EqpSpotInsTemEquipH>().Where(x => x.spot_ins_tem_id == input.id && x.equip_id == equipId).FirstAsync();
await db.Deleteable<EqpSpotInsTemEquipH>().Where(x => x.spot_ins_tem_id == input.id && x.equip_id == equipId).ExecuteCommandAsync();
_ = await db.Deleteable<EqpSpotInsTemEquipH>().Where(x => x.spot_ins_tem_id == input.id && x.equip_id == equipId).ExecuteCommandAsync();
if (oldSpotInsTemEquipH != null)
await db.Deleteable<EqpSpotInsTemEquipD>().Where(x => x.spot_ins_tem_equip_id == oldSpotInsTemEquipH.id).ExecuteCommandAsync();
{
_ = await db.Deleteable<EqpSpotInsTemEquipD>().Where(x => x.spot_ins_tem_equip_id == oldSpotInsTemEquipH.id).ExecuteCommandAsync();
}
}
if (insertEqpSpotInsTemEquipHs != null && insertEqpSpotInsTemEquipHs.Count > 0)
{
await db.Insertable(insertEqpSpotInsTemEquipHs).ExecuteCommandAsync();
_ = await db.Insertable(insertEqpSpotInsTemEquipHs).ExecuteCommandAsync();
}
if (insertEqpSpotInsTemEquipDs != null && insertEqpSpotInsTemEquipDs.Count > 0)
{
await db.Insertable(insertEqpSpotInsTemEquipDs).ExecuteCommandAsync();
_ = await db.Insertable(insertEqpSpotInsTemEquipDs).ExecuteCommandAsync();
}
}
});
if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
return result.IsSuccess ? "发布成功" : result.ErrorMessage;
return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : result.IsSuccess ? "发布成功" : result.ErrorMessage;
}
}
}

View File

@@ -32,13 +32,13 @@ namespace Tnb.EquipMgr
[HttpPost]
public async Task<dynamic> GetSubEquipList(EquipQueryInput input)
{
var db = _repository.AsSugarClient();
Dictionary<string, string>? queryJson = new Dictionary<string, string>();
ISqlSugarClient db = _repository.AsSugarClient();
Dictionary<string, string>? queryJson = new();
if (!string.IsNullOrEmpty(input.queryJson))
{
queryJson = JsonConvert.DeserializeObject<Dictionary<string, string>>(input.queryJson);
}
var result = await db.Queryable<EqpSubEquip>()
SqlSugarPagedList<SubEquipQueryOutput> result = await db.Queryable<EqpSubEquip>()
.LeftJoin<UserEntity>((a, b) => a.create_id == b.Id)
.LeftJoin<UserEntity>((a, b, c) => a.modify_id == c.Id)
.LeftJoin<EqpEquipment>((a, b, c, d) => a.equip_id == d.id)

View File

@@ -30,13 +30,13 @@ namespace Tnb.EquipMgr
[HttpPost]
public async Task<dynamic> GetEquipTechnologyParameterList(EquipQueryInput input)
{
var db = _repository.AsSugarClient();
Dictionary<string, string>? queryJson = new Dictionary<string, string>();
ISqlSugarClient db = _repository.AsSugarClient();
Dictionary<string, string>? queryJson = new();
if (input != null && !string.IsNullOrEmpty(input.queryJson))
{
queryJson = JsonConvert.DeserializeObject<Dictionary<string, string>>(input?.queryJson ?? "");
}
var result = await db.Queryable<EqpTechnologyParameter>()
SqlSugarPagedList<EquipTechnologyParameterQueryOutput> result = await db.Queryable<EqpTechnologyParameter>()
.WhereIF(input != null, a => a.equip_id == input!.equip_id)
.WhereIF(queryJson != null && queryJson.ContainsKey("name"), a => a.name.Contains(queryJson!["name"]))
.Select(a => new EquipTechnologyParameterQueryOutput
@@ -45,7 +45,7 @@ namespace Tnb.EquipMgr
name = a.name,
definition = a.definition,
remark = a.remark
}).ToPagedListAsync((input?.currentPage ?? 1), (input?.pageSize ?? 50));
}).ToPagedListAsync(input?.currentPage ?? 1, input?.pageSize ?? 50);
return PageResult<EquipTechnologyParameterQueryOutput>.SqlSugarPageResult(result);
}

View File

@@ -32,13 +32,13 @@ namespace Tnb.EquipMgr
[HttpPost]
public async Task<dynamic> GetEquipWorkshopChangeList(EquipQueryInput input)
{
var db = _repository.AsSugarClient();
ISqlSugarClient db = _repository.AsSugarClient();
// Dictionary<string, string>? queryJson = new Dictionary<string, string>();
// if (input!=null && !string.IsNullOrEmpty(input.queryJson))
// {
// queryJson = JsonConvert.DeserializeObject<Dictionary<string, string>>(input?.queryJson ?? "");
// }
var result = await db.Queryable<EqpWorkshopChangeLog>()
SqlSugarPagedList<EquipWorkshopChangeQueryOutput> result = await db.Queryable<EqpWorkshopChangeLog>()
.LeftJoin<OrganizeEntity>((a, b) => a.old_workshop_id == b.Id)
.LeftJoin<OrganizeEntity>((a, b, c) => a.new_workshop_id == c.Id)
.WhereIF(input != null, a => a.equip_id == input!.equip_id)
@@ -52,7 +52,7 @@ namespace Tnb.EquipMgr
new_installation_location = a.new_installation_location,
remark = a.remark,
create_time = a.create_time == null ? null : a.create_time.Value.ToString("yyyy-MM-dd"),
}).ToPagedListAsync((input?.currentPage ?? 1), (input?.pageSize ?? 50));
}).ToPagedListAsync(input?.currentPage ?? 1, input?.pageSize ?? 50);
return PageResult<EquipWorkshopChangeQueryOutput>.SqlSugarPageResult(result);
}
@@ -60,12 +60,12 @@ namespace Tnb.EquipMgr
[HttpPost]
public async Task<dynamic> WorkshopChange(EquipWorkshopChangeInput input)
{
var db = _repository.AsSugarClient();
ISqlSugarClient db = _repository.AsSugarClient();
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
{
EqpEquipment eqpEquipment = await db.Queryable<EqpEquipment>().SingleAsync(x => x.id == input.equip_id);
EqpWorkshopChangeLog eqpWorkshopChangeLog = new EqpWorkshopChangeLog()
EqpWorkshopChangeLog eqpWorkshopChangeLog = new()
{
equip_id = input.equip_id,
old_workshop_id = eqpEquipment.use_department_id,
@@ -78,17 +78,16 @@ namespace Tnb.EquipMgr
org_id = _userManager.GetUserInfo().Result.organizeId
};
await _repository.InsertAsync(eqpWorkshopChangeLog);
_ = await _repository.InsertAsync(eqpWorkshopChangeLog);
await db.Updateable<EqpEquipment>()
_ = await db.Updateable<EqpEquipment>()
.SetColumns(x => x.use_department_id == input.new_workshop_id)
.SetColumns(x => x.installation_location == input.new_installation_location)
.Where(x => x.id == input.equip_id).ExecuteCommandAsync();
});
if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
return result.IsSuccess ? "迁移成功" : result.ErrorMessage;
return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : (dynamic)(result.IsSuccess ? "迁移成功" : result.ErrorMessage);
}
}
}

View File

@@ -50,7 +50,7 @@ namespace Tnb.EquipMgr
private async Task<object> GetList(VisualDevModelListQueryInput input)
{
var db = _repository.AsSugarClient();
ISqlSugarClient db = _repository.AsSugarClient();
Dictionary<string, object>? queryJson = (input == null || string.IsNullOrEmpty(input.queryJson)) ? new Dictionary<string, object>() : input.queryJson.ToObject<Dictionary<string, object>>();
string equioInfo = queryJson.ContainsKey("query_info") ? (queryJson["query_info"].ToString() ?? "") : "";
string status = queryJson.ContainsKey("status") ? (queryJson["status"].ToString() ?? "") : "";
@@ -67,7 +67,7 @@ namespace Tnb.EquipMgr
input.sidx = "a." + input.sidx;
}
var list = await db.Queryable<EqpMaintainRecordH, EqpEquipment, UserEntity, UserEntity>((a, b, c, d) => new object[]
SqlSugarPagedList<EqpMaintainRecordListOutput> list = await db.Queryable<EqpMaintainRecordH, EqpEquipment, UserEntity, UserEntity>((a, b, c, d) => new object[]
{
JoinType.Left, a.equip_id == b.id,
JoinType.Left, a.execute_user_id == c.Id,
@@ -105,7 +105,7 @@ namespace Tnb.EquipMgr
a.repeat_time = a.date_repeat_time == null ? "" : a.date_repeat_time.Value.ToString("yyyy-MM-dd HH:mm:ss");
a.last_execute_time = a.date_last_execute_time == null ? "" : a.date_last_execute_time.Value.ToString("yyyy-MM-dd HH:mm:ss");
})
.ToPagedListAsync((input?.currentPage ?? 1), (input?.pageSize ?? 50));
.ToPagedListAsync(input?.currentPage ?? 1, input?.pageSize ?? 50);
return PageResult<EqpMaintainRecordListOutput>.SqlSugarPageResult(list);
}
@@ -120,16 +120,8 @@ namespace Tnb.EquipMgr
DbResult<bool> result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
{
EqpMaintainRecordH eqpSpotInsRecordH = _repository.GetSingle(x => x.id == input.id);
string status = "";
if (eqpSpotInsRecordH.is_repeat == "1")
{
status = SpotInsRecordExecutionStatus.TOBECHECK;
}
else
{
status = SpotInsRecordExecutionStatus.COMPLETED;
}
await _repository.UpdateAsync(x => new EqpMaintainRecordH()
string status = eqpSpotInsRecordH.is_repeat == "1" ? SpotInsRecordExecutionStatus.TOBECHECK : SpotInsRecordExecutionStatus.COMPLETED;
_ = await _repository.UpdateAsync(x => new EqpMaintainRecordH()
{
result = input.result,
attachment = input.attachment,
@@ -141,9 +133,9 @@ namespace Tnb.EquipMgr
if (input != null && input.details != null)
{
foreach (var item in input.details)
foreach (Dictionary<string, string> item in input.details)
{
await _repository.AsSugarClient().Updateable<EqpMaintainRecordD>()
_ = await _repository.AsSugarClient().Updateable<EqpMaintainRecordD>()
.SetColumns(x => x.result == item["result"])
.SetColumnsIF(item.ContainsKey("maintain_descrip"), x => x.maintain_descrip == item["maintain_descrip"])
.Where(x => x.id == item["id"])
@@ -154,8 +146,7 @@ namespace Tnb.EquipMgr
});
if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
return result.IsSuccess ? "执行成功" : result.ErrorMessage;
return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : (dynamic)(result.IsSuccess ? "执行成功" : result.ErrorMessage);
}
/// <summary>
@@ -184,7 +175,7 @@ namespace Tnb.EquipMgr
{
x.maintain_type = typeDic.ContainsKey(x.maintain_type) ? typeDic[x.maintain_type] + "" : x.maintain_type;
});
MaintainRecordRepeatOutput output = new MaintainRecordRepeatOutput()
MaintainRecordRepeatOutput output = new()
{
model = eqpSpotInsRecordH,
details = eqpSpotInsRecordDs,
@@ -199,7 +190,7 @@ namespace Tnb.EquipMgr
[HttpPost]
public async Task<string> RepeatMaintain(MaintainRecordRepeatInput input)
{
var db = _repository.AsSugarClient();
ISqlSugarClient db = _repository.AsSugarClient();
EqpMaintainRecordH eqpMaintainRecordH = await _repository.GetSingleAsync(x => x.id == input.id);
if (eqpMaintainRecordH.status == "1")
{
@@ -210,9 +201,9 @@ namespace Tnb.EquipMgr
if (input != null && input.details != null)
{
foreach (var item in input.details)
foreach (Dictionary<string, string> item in input.details)
{
await db.Updateable<EqpMaintainRecordD>()
_ = await db.Updateable<EqpMaintainRecordD>()
.SetColumnsIF(item.ContainsKey("repeat_descrip"), x => x.repeat_descrip == item["repeat_descrip"])
.SetColumns(x => x.repeat_result == item["repeat_result"])
.Where(x => x.id == item["id"]).ExecuteCommandAsync();
@@ -221,7 +212,7 @@ namespace Tnb.EquipMgr
if (input != null)
{
await _repository.UpdateAsync(x => new EqpMaintainRecordH()
_ = await _repository.UpdateAsync(x => new EqpMaintainRecordH()
{
repeat_result = input.repeat_result,
repeat_remark = input.repeat_remark,
@@ -232,20 +223,19 @@ namespace Tnb.EquipMgr
}
});
if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
return result.IsSuccess ? "复核成功" : result.ErrorMessage;
return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : result.IsSuccess ? "复核成功" : result.ErrorMessage;
}
[HttpPost]
public async Task<dynamic> GetMaintainRecordList(EquipQueryInput input)
{
var db = _repository.AsSugarClient();
Dictionary<string, string>? queryJson = new Dictionary<string, string>();
ISqlSugarClient db = _repository.AsSugarClient();
Dictionary<string, string>? queryJson = new();
if (!string.IsNullOrEmpty(input.queryJson))
{
queryJson = JsonConvert.DeserializeObject<Dictionary<string, string>>(input.queryJson);
}
var result = await db.Queryable<EqpMaintainRecordH>()
SqlSugarPagedList<EquipMaintainRecordQueryOutput> result = await db.Queryable<EqpMaintainRecordH>()
.LeftJoin<EqpEquipment>((a, b) => a.equip_id == b.id)
.LeftJoin<UserEntity>((a, b, c) => a.execute_user_id == c.Id)
.LeftJoin<UserEntity>((a, b, c, d) => a.repeat_user_id == d.Id)
@@ -277,24 +267,28 @@ namespace Tnb.EquipMgr
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<dynamic> GetEqpMaintainRecordInfoById(Dictionary<string, string> dic)
public async Task<dynamic?> GetEqpMaintainRecordInfoById(Dictionary<string, string> dic)
{
string id = dic.ContainsKey("id") ? dic["id"] : "";
if (string.IsNullOrEmpty(id)) return null;
var db = _repository.AsSugarClient();
if (string.IsNullOrEmpty(id))
{
return null;
}
ISqlSugarClient db = _repository.AsSugarClient();
return await db.Queryable<EqpMaintainRecordH>()
.LeftJoin<EqpEquipment>((a, b) => a.equip_id == b.id)
.Where((a, b) => a.id == id)
.Select((a, b) => new
{
id = a.id,
equip_id = a.equip_id,
a.id,
a.equip_id,
equip_code = b.code,
equip_name = b.name,
create_time = a.create_time == null ? "" : a.create_time.Value.ToString(DbTimeFormat.SS),
result_remark = a.result_remark,
result = a.result,
status = a.status,
a.result_remark,
a.result,
a.status,
}).FirstAsync();
}

View File

@@ -49,7 +49,7 @@ namespace Tnb.EquipMgr
private async Task<object> GetList(VisualDevModelListQueryInput input)
{
var db = _repository.AsSugarClient();
ISqlSugarClient db = _repository.AsSugarClient();
Dictionary<string, object>? queryJson = (input == null || string.IsNullOrEmpty(input.queryJson)) ? new Dictionary<string, object>() : input.queryJson.ToObject<Dictionary<string, object>>();
string equioInfo = queryJson.ContainsKey("query_info") ? (queryJson["query_info"].ToString() ?? "") : "";
string status = queryJson.ContainsKey("status") ? (queryJson["status"].ToString() ?? "") : "";
@@ -66,7 +66,7 @@ namespace Tnb.EquipMgr
input.sidx = "a." + input.sidx;
}
var list = await db.Queryable<EqpSpotInsRecordH, EqpEquipment, UserEntity, UserEntity>((a, b, c, d) => new object[]
SqlSugarPagedList<EqpSpotInsRecordListOutput> list = await db.Queryable<EqpSpotInsRecordH, EqpEquipment, UserEntity, UserEntity>((a, b, c, d) => new object[]
{
JoinType.Left, a.equip_id == b.id,
JoinType.Left, a.spot_record_user_id == c.Id,
@@ -101,7 +101,7 @@ namespace Tnb.EquipMgr
a.spot_record_date_time = a.date_spot_record_date_time == null ? "" : a.date_spot_record_date_time.Value.ToString("yyyy-MM-dd HH:mm:ss");
a.repeat_time = a.date_repeat_time == null ? "" : a.date_repeat_time.Value.ToString("yyyy-MM-dd HH:mm:ss");
})
.ToPagedListAsync((input?.currentPage ?? 1), (input?.pageSize ?? 50));
.ToPagedListAsync(input?.currentPage ?? 1, input?.pageSize ?? 50);
return PageResult<EqpSpotInsRecordListOutput>.SqlSugarPageResult(list);
}
@@ -117,16 +117,8 @@ namespace Tnb.EquipMgr
{
EqpSpotInsRecordH eqpSpotInsRecordH = _repository.GetSingle(x => x.id == input.id);
string status = "";
if (eqpSpotInsRecordH.is_repeat == "1")
{
status = SpotInsRecordExecutionStatus.TOBECHECK;
}
else
{
status = SpotInsRecordExecutionStatus.COMPLETED;
}
await _repository.UpdateAsync(x => new EqpSpotInsRecordH()
string status = eqpSpotInsRecordH.is_repeat == "1" ? SpotInsRecordExecutionStatus.TOBECHECK : SpotInsRecordExecutionStatus.COMPLETED;
_ = await _repository.UpdateAsync(x => new EqpSpotInsRecordH()
{
result = input.result,
attachment = input.attachment,
@@ -138,9 +130,9 @@ namespace Tnb.EquipMgr
if (input != null && input.details != null)
{
foreach (var item in input.details)
foreach (Dictionary<string, string> item in input.details)
{
await _repository.AsSugarClient().Updateable<EqpSpotInsRecordD>().
_ = await _repository.AsSugarClient().Updateable<EqpSpotInsRecordD>().
SetColumns(x => x.result == item["result"])
.SetColumnsIF(item["judge_type"] == "1", x => x.real_value == Convert.ToDouble(item["real_value"]))
.Where(x => x.id == item["id"])
@@ -151,8 +143,7 @@ namespace Tnb.EquipMgr
});
if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
return result.IsSuccess ? "执行成功" : result.ErrorMessage;
return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : (dynamic)(result.IsSuccess ? "执行成功" : result.ErrorMessage);
}
/// <summary>
@@ -167,7 +158,7 @@ namespace Tnb.EquipMgr
EqpSpotInsRecordH eqpSpotInsRecordH = await _repository.GetSingleAsync(x => x.id == id);
List<EqpSpotInsRecordD> eqpSpotInsRecordDs = await _repository.AsSugarClient().Queryable<EqpSpotInsRecordD>()
.Where(x => x.spot_ins_record_id == id).ToListAsync();
SpotInsRecordRepeatOutput output = new SpotInsRecordRepeatOutput()
SpotInsRecordRepeatOutput output = new()
{
model = eqpSpotInsRecordH,
details = eqpSpotInsRecordDs,
@@ -187,7 +178,7 @@ namespace Tnb.EquipMgr
{
throw Oops.Bah("状态错误");
}
await _repository.UpdateAsync(x => new EqpSpotInsRecordH()
_ = await _repository.UpdateAsync(x => new EqpSpotInsRecordH()
{
repeat_result = input.repeat_result,
repeat_remark = input.repeat_remark,
@@ -200,13 +191,13 @@ namespace Tnb.EquipMgr
[HttpPost]
public async Task<dynamic> GetSpotInsRecordList(EquipQueryInput input)
{
var db = _repository.AsSugarClient();
Dictionary<string, string>? queryJson = new Dictionary<string, string>();
ISqlSugarClient db = _repository.AsSugarClient();
Dictionary<string, string>? queryJson = new();
if (!string.IsNullOrEmpty(input.queryJson))
{
queryJson = JsonConvert.DeserializeObject<Dictionary<string, string>>(input.queryJson);
}
var result = await db.Queryable<EqpSpotInsRecordH>()
SqlSugarPagedList<EquipSpotInsRecordQueryOutput> result = await db.Queryable<EqpSpotInsRecordH>()
.LeftJoin<UserEntity>((a, b) => a.repeat_user_id == b.Id)
.Where(a => a.equip_id == input.equip_id)
.Select((a, b) => new EquipSpotInsRecordQueryOutput
@@ -235,24 +226,28 @@ namespace Tnb.EquipMgr
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<dynamic> GetEqpSpotInsRecordInfoById(Dictionary<string, string> dic)
public async Task<dynamic?> GetEqpSpotInsRecordInfoById(Dictionary<string, string> dic)
{
string id = dic.ContainsKey("id") ? dic["id"] : "";
if (string.IsNullOrEmpty(id)) return null;
var db = _repository.AsSugarClient();
if (string.IsNullOrEmpty(id))
{
return null;
}
ISqlSugarClient db = _repository.AsSugarClient();
return await db.Queryable<EqpSpotInsRecordH>()
.LeftJoin<EqpEquipment>((a, b) => a.equip_id == b.id)
.Where((a, b) => a.id == id)
.Select((a, b) => new
{
id = a.id,
equip_id = a.equip_id,
a.id,
a.equip_id,
equip_code = b.code,
equip_name = b.name,
create_time = a.create_time == null ? "" : a.create_time.Value.ToString(DbTimeFormat.SS),
result_remark = a.result_remark,
result = a.result,
status = a.status,
a.result_remark,
a.result,
a.status,
}).FirstAsync();
}

View File

@@ -29,22 +29,25 @@ namespace Tnb.EquipMgr
string id = parameters["id"];
DbResult<bool> result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
{
await _repository.UpdateAsync(x => new EqpSpotInsTemEquipH()
_ = await _repository.UpdateAsync(x => new EqpSpotInsTemEquipH()
{
is_start = "0"
}, x => x.id == id);
List<string> ids = await _repository.AsSugarClient().Queryable<EqpSpotInsRecordH>()
.Where(x => x.spot_ins_tem_equip_id == id && x.status == SpotInsRecordExecutionStatus.TOBEEXECUTED)
.Select(x => x.id).ToListAsync();
await _repository.AsSugarClient().Deleteable<EqpSpotInsRecordH>()
_ = await _repository.AsSugarClient().Deleteable<EqpSpotInsRecordH>()
.Where(x => x.spot_ins_tem_equip_id == id && x.status == SpotInsRecordExecutionStatus.TOBEEXECUTED).ExecuteCommandAsync();
await _repository.AsSugarClient().Deleteable<EqpSpotInsRecordD>()
_ = await _repository.AsSugarClient().Deleteable<EqpSpotInsRecordD>()
.Where(x => ids.Contains(x.spot_ins_record_id)).ExecuteCommandAsync();
});
if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
if (!result.IsSuccess)
{
throw Oops.Oh(ErrorCode.COM1008);
}
}
}
}

View File

@@ -55,13 +55,13 @@ namespace Tnb.EquipMgr
/// <returns></returns>
private async Task<dynamic> GetList(VisualDevModelListQueryInput input)
{
var dic = new Dictionary<string, string>
Dictionary<string, string> dic = new()
{
{ "Qualified","合格"},
{ "Unqualified","不合格"},
};
var pagedList = await _repository.AsQueryable()
SqlSugarPagedList<EquipmentListOutput> pagedList = await _repository.AsQueryable()
//.Where(it => it.station_code == input.station_code || string.IsNullOrEmpty(input.station_code))
.Select(it => new EquipmentListOutput
{
@@ -82,7 +82,7 @@ namespace Tnb.EquipMgr
private async Task<dynamic> Create(VisualDevModelDataCrInput visualDevModelDataCrInput)
{
string qrcode = visualDevModelDataCrInput.data.ContainsKey("qrcode") ? visualDevModelDataCrInput.data["qrcode"]?.ToString() : "";
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("二维码总表中已存在该二维码");
@@ -96,7 +96,7 @@ namespace Tnb.EquipMgr
if (!string.IsNullOrEmpty(qrcode))
{
BasQrcode basQrcode = new BasQrcode()
BasQrcode basQrcode = new()
{
code = visualDevModelDataCrInput.data["qrcode"].ToString(),
source_id = equipId,
@@ -105,7 +105,7 @@ namespace Tnb.EquipMgr
create_time = DateTime.Now,
org_id = _userManager.GetUserInfo().Result.organizeId,
};
await _repository.AsSugarClient().Insertable<BasQrcode>(basQrcode).ExecuteCommandAsync();
_ = await _repository.AsSugarClient().Insertable<BasQrcode>(basQrcode).ExecuteCommandAsync();
}
}
return await Task.FromResult(true);
@@ -113,7 +113,7 @@ namespace Tnb.EquipMgr
private async Task<dynamic> Update(string id, VisualDevModelDataUpInput visualDevModelDataUpInput)
{
string qrcode = visualDevModelDataUpInput.data.ContainsKey("qrcode") ? visualDevModelDataUpInput.data["qrcode"]?.ToString() : "";
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("二维码总表中已存在该二维码");
@@ -127,13 +127,13 @@ namespace Tnb.EquipMgr
{
if (await _repository.AsSugarClient().Queryable<BasQrcode>().AnyAsync(x => x.source_id == id))
{
await _repository.AsSugarClient().Updateable<BasQrcode>()
_ = await _repository.AsSugarClient().Updateable<BasQrcode>()
.SetColumns(x => x.code == visualDevModelDataUpInput.data["qrcode"].ToString()).Where(x => x.source_id == id)
.ExecuteCommandAsync();
}
else
{
BasQrcode basQrcode = new BasQrcode()
BasQrcode basQrcode = new()
{
code = visualDevModelDataUpInput.data["qrcode"].ToString(),
source_id = id,
@@ -142,7 +142,7 @@ namespace Tnb.EquipMgr
create_time = DateTime.Now,
org_id = _userManager.GetUserInfo().Result.organizeId,
};
await _repository.AsSugarClient().Insertable<BasQrcode>(basQrcode).ExecuteCommandAsync();
_ = await _repository.AsSugarClient().Insertable<BasQrcode>(basQrcode).ExecuteCommandAsync();
}
}
}
@@ -169,8 +169,8 @@ namespace Tnb.EquipMgr
public async Task<dynamic> GetWorklineAndEquipTree(Dictionary<string, string> dic)
{
string equipTypes = dic.ContainsKey("equipTypes") ? dic["equipTypes"] : "";
var db = _repository.AsSugarClient();
var queryable1 = db.Queryable<OrganizeEntity>()
ISqlSugarClient db = _repository.AsSugarClient();
ISugarQueryable<WorklineAndEquipTreeOutput> queryable1 = db.Queryable<OrganizeEntity>()
.Where((a) => a.DeleteMark == null && a.Category == DictConst.RegionCategoryWorkshopCode)
.Select((a) => new WorklineAndEquipTreeOutput()
{
@@ -191,7 +191,7 @@ namespace Tnb.EquipMgr
})
});
List<WorklineAndEquipTreeOutput> list2 = new List<WorklineAndEquipTreeOutput>();
List<WorklineAndEquipTreeOutput> list2 = new();
if (!string.IsNullOrEmpty(equipTypes))
{
string[] equipTypeArr = equipTypes.Split(",");
@@ -219,7 +219,7 @@ namespace Tnb.EquipMgr
}
// var list = await db.UnionAll(queryable1, queryable2).ToListAsync();
var list1 = await queryable1.ToListAsync();
List<WorklineAndEquipTreeOutput> list1 = await queryable1.ToListAsync();
list1.AddRange(list2);
return new AuthResponse(200, "", new Dictionary<string, object>()
{

View File

@@ -47,7 +47,7 @@ namespace Tnb.EquipMgr
private async Task<dynamic> Create(VisualDevModelDataCrInput visualDevModelDataCrInput)
{
string qrcode = visualDevModelDataCrInput.data.ContainsKey("qrcode") ? visualDevModelDataCrInput.data["qrcode"].ToString() : "";
string? qrcode = visualDevModelDataCrInput.data.ContainsKey("qrcode") ? visualDevModelDataCrInput.data["qrcode"].ToString() : "";
if (!string.IsNullOrEmpty(qrcode) && await _db.Queryable<BasQrcode>().AnyAsync(x => x.code == qrcode))
{
throw Oops.Bah("二维码总表中已存在该二维码");
@@ -61,7 +61,7 @@ namespace Tnb.EquipMgr
if (!string.IsNullOrEmpty(qrcode))
{
BasQrcode basQrcode = new BasQrcode()
BasQrcode basQrcode = new()
{
code = visualDevModelDataCrInput.data["qrcode"].ToString(),
source_id = id,
@@ -70,7 +70,7 @@ namespace Tnb.EquipMgr
create_time = DateTime.Now,
org_id = _userManager.GetUserInfo().Result.organizeId,
};
await _db.Insertable<BasQrcode>(basQrcode).ExecuteCommandAsync();
_ = await _db.Insertable<BasQrcode>(basQrcode).ExecuteCommandAsync();
}
}
return await Task.FromResult(true);
@@ -78,7 +78,7 @@ namespace Tnb.EquipMgr
private async Task<dynamic> Update(string id, VisualDevModelDataUpInput visualDevModelDataUpInput)
{
string qrcode = visualDevModelDataUpInput.data.ContainsKey("qrcode") ? visualDevModelDataUpInput.data["qrcode"].ToString() : "";
string? qrcode = visualDevModelDataUpInput.data.ContainsKey("qrcode") ? visualDevModelDataUpInput.data["qrcode"].ToString() : "";
if (!string.IsNullOrEmpty(qrcode) && await _db.Queryable<BasQrcode>().AnyAsync(x => x.code == visualDevModelDataUpInput.data["qrcode"] && x.source_id != id))
{
throw Oops.Bah("二维码总表中已存在该二维码");
@@ -92,13 +92,13 @@ namespace Tnb.EquipMgr
{
if (await _db.Queryable<BasQrcode>().AnyAsync(x => x.source_id == id))
{
await _db.Updateable<BasQrcode>()
_ = await _db.Updateable<BasQrcode>()
.SetColumns(x => x.code == visualDevModelDataUpInput.data["qrcode"].ToString()).Where(x => x.source_id == id)
.ExecuteCommandAsync();
}
else
{
BasQrcode basQrcode = new BasQrcode()
BasQrcode basQrcode = new()
{
code = visualDevModelDataUpInput.data["qrcode"].ToString(),
source_id = id,
@@ -107,7 +107,7 @@ namespace Tnb.EquipMgr
create_time = DateTime.Now,
org_id = _userManager.GetUserInfo().Result.organizeId,
};
await _db.Insertable<BasQrcode>(basQrcode).ExecuteCommandAsync();
_ = await _db.Insertable<BasQrcode>(basQrcode).ExecuteCommandAsync();
}
}
}

View File

@@ -32,11 +32,11 @@ namespace Tnb.EquipMgr
[HttpGet("{itemGroupId}")]
public async Task<dynamic> GetMaintianItemListByGroupId(string itemGroupId)
{
var list = new List<MoldMaintainItemListOutput>();
var itemIds = await _db.Queryable<ToolMoldMaintainGroupItem>().Where(it => it.item_group_id == itemGroupId).Select(it => it.item_id).ToListAsync();
List<MoldMaintainItemListOutput> list = new();
List<string> itemIds = await _db.Queryable<ToolMoldMaintainGroupItem>().Where(it => it.item_group_id == itemGroupId).Select(it => it.item_id).ToListAsync();
if (itemIds?.Count > 0)
{
var items = await _db.Queryable<MoldMaintenance>().Where(it => itemIds.Contains(it.id)).ToListAsync();
List<MoldMaintenance> items = await _db.Queryable<MoldMaintenance>().Where(it => itemIds.Contains(it.id)).ToListAsync();
list = items.Adapt<List<MoldMaintainItemListOutput>>();
}
return list;
@@ -49,11 +49,11 @@ namespace Tnb.EquipMgr
[HttpGet("{itemGroupId}")]
public async Task<dynamic> GetMoldListByGroupId(string itemGroupId)
{
var list = new List<RelevanceMoldListOutput>();
var moldIds = await _db.Queryable<ToolMoldMaintainGroupRelation>().Where(it => it.item_group_id == itemGroupId).Select(it => it.mold_id).ToListAsync();
List<RelevanceMoldListOutput> list = new();
List<string> moldIds = await _db.Queryable<ToolMoldMaintainGroupRelation>().Where(it => it.item_group_id == itemGroupId).Select(it => it.mold_id).ToListAsync();
if (moldIds?.Count > 0)
{
var items = await _db.Queryable<ToolMolds>().Where(it => moldIds.Contains(it.id)).ToListAsync();
List<ToolMolds> items = await _db.Queryable<ToolMolds>().Where(it => moldIds.Contains(it.id)).ToListAsync();
list = items.Adapt<List<RelevanceMoldListOutput>>();
}
return list;
@@ -107,9 +107,9 @@ namespace Tnb.EquipMgr
#endregion
private async Task Delete<T>(Expression<Func<T, bool>> deleteExp) where T : BaseEntity<string>, new()
private new async Task Delete<T>(Expression<Func<T, bool>> deleteExp) where T : BaseEntity<string>, new()
{
await _db.Deleteable<T>().Where(deleteExp).ExecuteCommandAsync();
_ = await _db.Deleteable<T>().Where(deleteExp).ExecuteCommandAsync();
}
}

View File

@@ -30,8 +30,8 @@ namespace Tnb.EquipMgr
private readonly IToolMoldsService _moldService;
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
private static Dictionary<string, object> _dicHouse = new Dictionary<string, object>();
private static Dictionary<string, object> _dicLocation = new Dictionary<string, object>();
private static Dictionary<string, object> _dicHouse = new();
private static Dictionary<string, object> _dicLocation = new();
public ToolMoldMaintainPlanService(
ISqlSugarRepository<ToolMoldMaintainPlan> repository,
@@ -75,7 +75,7 @@ namespace Tnb.EquipMgr
[HttpGet]
public async Task<dynamic> GetMoldListByPlanId([FromRoute] string planId)
{
var result = new List<MaintainPlanMoldLstOutput>();
List<MaintainPlanMoldLstOutput> result = new();
if (_dicHouse.Count < 1)
{
_dicHouse = await _moldHouseService.GetHouseDictionary();
@@ -84,13 +84,13 @@ namespace Tnb.EquipMgr
{
_dicLocation = await _moldLocationService.GetLocationDictionary();
}
var list = await _db.Queryable<ToolMoldMaintainPlanRelation>().Where(it => it.maintain_plan_id == planId).ToListAsync();
List<ToolMoldMaintainPlanRelation> list = await _db.Queryable<ToolMoldMaintainPlanRelation>().Where(it => it.maintain_plan_id == planId).ToListAsync();
if (list?.Count > 0)
{
var ids = list.Select(it => it.mold_id).Distinct().ToList();
List<string> ids = list.Select(it => it.mold_id).Distinct().ToList();
if (ids?.Count > 0)
{
var items = await _moldService.GetListByIds(ids);
List<ToolMolds> items = await _moldService.GetListByIds(ids);
_db.ThenMapper(items, it =>
{
if (!it.warehosue_id!.IsNullOrEmpty())
@@ -114,16 +114,21 @@ namespace Tnb.EquipMgr
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task RelevanceMoldFromPlan(RelevanceMoldFromPlanInput input) =>
public async Task RelevanceMoldFromPlan(RelevanceMoldFromPlanInput input)
{
await Relevance<RelevanceMoldFromPlanInput, ToolMoldMaintainPlanRelation>(input, nameof(ToolMoldMaintainPlanRelation.maintain_plan_id), nameof(ToolMoldMaintainPlanRelation.mold_id), it => it.maintain_plan_id == input.id);
}
/// <summary>
/// 删除计划与模具关联关系
/// </summary>
/// <param name="input">输入参数</param>
/// <returns></returns>
[HttpPost]
public async Task DeleteMold(RelevanceMoldFromPlanInput input) =>
public async Task DeleteMold(RelevanceMoldFromPlanInput input)
{
await Delete<ToolMoldMaintainPlanRelation>(it => it.maintain_plan_id == input.id && input.ids.Contains(it.mold_id));
}
}
}

View File

@@ -38,6 +38,8 @@ namespace Tnb.EquipMgr
private readonly IVisualDevService _visualDevService;
private readonly IRunService _runService;
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
[Obsolete]
public ToolMoldMaintainRuleService(ISqlSugarRepository<ToolMoldMaintainRule> repository, IUserManager userManager, IDictionaryDataService dictionaryDataService, TimeTaskService timeTaskService, IVisualDevService visualDevService, IRunService runService)
{
_db = repository.AsSugarClient();
@@ -49,35 +51,41 @@ namespace Tnb.EquipMgr
OverideFuncs.DeleteAsync = Delete;
OverideFuncs.CreateAsync = Create;
}
[Obsolete]
private async Task<dynamic> Create(VisualDevModelDataCrInput input)
{
int cycle = int.Parse(input.data["cycle"].ToString()!);
var startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddMilliseconds(long.Parse(input.data["startandend_date"].ToString()!));
ToolMoldMaintainRule toolMoldMaintainRule = new ToolMoldMaintainRule();
toolMoldMaintainRule.id = SnowflakeIdHelper.NextId();
toolMoldMaintainRule.mode = input.data["mode"].ToString();
toolMoldMaintainRule.cycle = cycle;
toolMoldMaintainRule.startandend_date = startTime.ToString("yyyy-MM-dd HH:mm:ss");
toolMoldMaintainRule.create_id = _userManager.UserId;
toolMoldMaintainRule.create_time = DateTime.Now;
await _db.Insertable(toolMoldMaintainRule).ExecuteCommandAsync();
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddMilliseconds(long.Parse(input.data["startandend_date"].ToString()!));
ToolMoldMaintainRule toolMoldMaintainRule = new()
{
id = SnowflakeIdHelper.NextId(),
mode = input.data["mode"].ToString(),
cycle = cycle,
startandend_date = startTime.ToString("yyyy-MM-dd HH:mm:ss"),
create_id = _userManager.UserId,
create_time = DateTime.Now
};
_ = await _db.Insertable(toolMoldMaintainRule).ExecuteCommandAsync();
if (toolMoldMaintainRule.mode == "27118635748885")
{
string id = toolMoldMaintainRule.id;
var comtentModel = new ContentModel();
comtentModel.cron = "0 0 9 " + startTime.Day + "/" + toolMoldMaintainRule.cycle + " * ?";
comtentModel.interfaceId = "";
comtentModel.interfaceName = "";
comtentModel.parameter = new List<InterfaceParameter>();
ContentModel comtentModel = new()
{
cron = "0 0 9 " + startTime.Day + "/" + toolMoldMaintainRule.cycle + " * ?",
interfaceId = "",
interfaceName = "",
parameter = new List<InterfaceParameter>()
};
comtentModel.parameter!.Add(new InterfaceParameter() { field = "id", value = id, defaultValue = "" });
comtentModel.localHostTaskId = "MoldMaintainTask/CreateTask";
DateTimeOffset dateTimeOffset = new DateTimeOffset(startTime);
DateTimeOffset dateTimeOffset = new(startTime);
comtentModel.startTime = dateTimeOffset.ToUnixTimeMilliseconds();
comtentModel.TenantId = _userManager?.TenantId!;
comtentModel.TenantDbName = _userManager?.TenantDbName!;
comtentModel.ConnectionConfig = _userManager?.ConnectionConfig!;
comtentModel.Token = _userManager?.ToKen!;
TimeTaskCrInput timeTaskCrInput = new TimeTaskCrInput()
TimeTaskCrInput timeTaskCrInput = new()
{
enCode = DateTime.Now.ToString("yyyyMMddHHmmss"),
fullName = "生成模具保养任务" + id,
@@ -94,12 +102,12 @@ namespace Tnb.EquipMgr
}
private async Task Delete(string id)
{
var ToolMoldMaintainRule = await _db.Queryable<ToolMoldMaintainRule>().Where(p => p.id == id).FirstAsync();
var ToolMoldMaintainRuleRelations = await _db.Queryable<ToolMoldMaintainRuleRelation>().Where(p => p.rule_id == id).ToListAsync();
ToolMoldMaintainRule ToolMoldMaintainRule = await _db.Queryable<ToolMoldMaintainRule>().Where(p => p.id == id).FirstAsync();
List<ToolMoldMaintainRuleRelation> ToolMoldMaintainRuleRelations = await _db.Queryable<ToolMoldMaintainRuleRelation>().Where(p => p.rule_id == id).ToListAsync();
await _timeTaskService.DeleteByName("生成模具保养任务" + id);
await _db.Ado.BeginTranAsync();
await _db.Deleteable(ToolMoldMaintainRule).ExecuteCommandAsync();
await _db.Deleteable(ToolMoldMaintainRuleRelations).ExecuteCommandAsync();
_ = await _db.Deleteable(ToolMoldMaintainRule).ExecuteCommandAsync();
_ = await _db.Deleteable(ToolMoldMaintainRuleRelations).ExecuteCommandAsync();
await _db.Ado.CommitTranAsync();
}
/// <summary>
@@ -110,11 +118,11 @@ namespace Tnb.EquipMgr
[HttpGet]
public async Task<dynamic> GetListById([FromRoute] string ruleId)
{
var result = new List<MaintainRuleMoldListOutput>();
var list = await _db.Queryable<ToolMoldMaintainRuleRelation>().Where(it => it.rule_id == ruleId).ToListAsync();
List<MaintainRuleMoldListOutput> result = new();
List<ToolMoldMaintainRuleRelation> list = await _db.Queryable<ToolMoldMaintainRuleRelation>().Where(it => it.rule_id == ruleId).ToListAsync();
if (list?.Count > 0)
{
var ids = list.Select(it => it.mold_id).ToList();
List<string> ids = list.Select(it => it.mold_id).ToList();
result = await _db.Queryable<ToolMolds>().Where(it => ids.Contains(it.id))
.Select(it => new MaintainRuleMoldListOutput { mold_id = it.id, item_group_id = list.First().item_group_id }, true)
.Mapper
@@ -138,7 +146,7 @@ namespace Tnb.EquipMgr
}, true)
.Mapper(it =>
{
var itemGroupIds = _db.Queryable<ToolMoldMaintainGroupRelation>().Where(x => x.mold_id == it.mold_id).Select(x => x.item_group_id).Distinct().ToList();
List<string> itemGroupIds = _db.Queryable<ToolMoldMaintainGroupRelation>().Where(x => x.mold_id == it.mold_id).Select(x => x.item_group_id).Distinct().ToList();
it.groupItems = _db.Queryable<ToolMoldMaintainGroup>().Where(x => itemGroupIds.Contains(x.id)).Select(x => new MaintainItemGroupItem { item_group_id = x.id, name = x.name }).ToList();
})
.ToListAsync();
@@ -154,23 +162,32 @@ namespace Tnb.EquipMgr
[HttpPost]
public async Task RelevanceMold(RelevanceMoldInput input)
{
if (input == null) throw new ArgumentNullException(nameof(input));
await _db.Deleteable<ToolMoldMaintainRuleRelation>().Where(it => it.rule_id == input.rule_id).ExecuteCommandAsync();
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
_ = await _db.Deleteable<ToolMoldMaintainRuleRelation>().Where(it => it.rule_id == input.rule_id).ExecuteCommandAsync();
if (input.rowIds?.Count > 0)
{
List<ToolMoldMaintainRuleRelation> entities = new();
foreach (var item in input.rowIds)
foreach (RowIdItem item in input.rowIds)
{
ToolMoldMaintainRuleRelation entity = new();
entity.id = SnowflakeIdHelper.NextId();
entity.rule_id = input.rule_id;
entity.mold_id = item.mold_id;
entity.item_group_id = item.group_id;
ToolMoldMaintainRuleRelation entity = new()
{
id = SnowflakeIdHelper.NextId(),
rule_id = input.rule_id,
mold_id = item.mold_id,
item_group_id = item.group_id
};
entities.Add(entity);
}
var row = await _db.Insertable(entities).ExecuteCommandAsync();
if (row < 1) throw Oops.Oh(ErrorCode.COM1000);
int row = await _db.Insertable(entities).ExecuteCommandAsync();
if (row < 1)
{
throw Oops.Oh(ErrorCode.COM1000);
}
}
}
/// <summary>
@@ -183,8 +200,11 @@ namespace Tnb.EquipMgr
{
if (input.ids?.Count > 0)
{
var row = await _db.Deleteable<ToolMoldMaintainRuleRelation>().Where(it => it.rule_id == input.rule_id && input.ids.Contains(it.mold_id)).ExecuteCommandAsync();
if (row < 1) throw Oops.Oh(ErrorCode.COM1002);
int row = await _db.Deleteable<ToolMoldMaintainRuleRelation>().Where(it => it.rule_id == input.rule_id && input.ids.Contains(it.mold_id)).ExecuteCommandAsync();
if (row < 1)
{
throw Oops.Oh(ErrorCode.COM1002);
}
}
}
/// <summary>
@@ -194,41 +214,48 @@ namespace Tnb.EquipMgr
[HttpPost]
public async Task GenMaintainPlan(MaintainPlanCrInput input)
{
if (input == null) throw new ArgumentNullException("input");
if (input == null)
{
throw new ArgumentNullException("input");
}
try
{
await _db.Ado.BeginTranAsync();
var maintainRules = await _db.Queryable<ToolMoldMaintainRule>().Where(it => input.ruleIds.Contains(it.id)).ToListAsync();
var ruleMoldRelations = await _db.Queryable<ToolMoldMaintainRuleRelation>().Where(it => input.ruleIds.Contains(it.rule_id)).ToListAsync();
List<ToolMoldMaintainRule> maintainRules = await _db.Queryable<ToolMoldMaintainRule>().Where(it => input.ruleIds.Contains(it.id)).ToListAsync();
List<ToolMoldMaintainRuleRelation> ruleMoldRelations = await _db.Queryable<ToolMoldMaintainRuleRelation>().Where(it => input.ruleIds.Contains(it.rule_id)).ToListAsync();
if (ruleMoldRelations?.Count > 0)
{
List<ToolMoldMaintainPlan> maintainPlans = new();
List<ToolMoldMaintainPlanRelation> maintainPlanRelations = new();
foreach (var mrr in ruleMoldRelations)
foreach (ToolMoldMaintainRuleRelation mrr in ruleMoldRelations)
{
var rule = await _db.Queryable<ToolMoldMaintainRule>().FirstAsync(it => it.id == mrr.rule_id);
ToolMoldMaintainRule rule = await _db.Queryable<ToolMoldMaintainRule>().FirstAsync(it => it.id == mrr.rule_id);
if (rule != null && rule.cycle.HasValue && rule.cycle.Value > 0)
{
ToolMoldMaintainPlan maintainPlan = new();
maintainPlan.plan_code = $"JHDM{DateTime.Now:yyyyMMddmmss}";
maintainPlan.mode = rule.mode;
maintainPlan.status = DictConst.UnMaintainStatusCode;
maintainPlan.plan_start_date = DateTime.Now;
maintainPlan.plan_end_date = DateTime.Now.AddDays(rule.cycle.Value);
maintainPlan.create_id = _userManager.UserId;
maintainPlan.create_time = DateTime.Now;
ToolMoldMaintainPlan maintainPlan = new()
{
plan_code = $"JHDM{DateTime.Now:yyyyMMddmmss}",
mode = rule.mode,
status = DictConst.UnMaintainStatusCode,
plan_start_date = DateTime.Now,
plan_end_date = DateTime.Now.AddDays(rule.cycle.Value),
create_id = _userManager.UserId,
create_time = DateTime.Now
};
maintainPlans.Add(maintainPlan);
ToolMoldMaintainPlanRelation maintainPlanReation = new();
maintainPlanReation.maintain_plan_id = maintainPlan.id;
maintainPlanReation.mold_id = mrr.mold_id;
ToolMoldMaintainPlanRelation maintainPlanReation = new()
{
maintain_plan_id = maintainPlan.id,
mold_id = mrr.mold_id
};
maintainPlanRelations.Add(maintainPlanReation);
}
}
await _db.Insertable(maintainPlans).ExecuteCommandAsync();
await _db.Insertable(maintainPlanRelations).ExecuteCommandAsync();
_ = await _db.Insertable(maintainPlans).ExecuteCommandAsync();
_ = await _db.Insertable(maintainPlanRelations).ExecuteCommandAsync();
await _db.Ado.CommitTranAsync();
}
}

View File

@@ -55,17 +55,17 @@ namespace Tnb.EquipMgr
.Where(a => a.maintain_plan_id == planId)
.Select((a, b, c, d) => new
{
mold_id = a.mold_id,
plan_start_time = d.plan_start_time,
designer = d.designer
a.mold_id,
d.plan_start_time,
d.designer
})
.ToListAsync();
var moldids = planMoldRelations.Select(x => x.mold_id).ToList();
var molds = await _db.Queryable<ToolMolds>().Where(it => moldids.Contains(it.id)).ToListAsync();
List<string> moldids = planMoldRelations.Select(x => x.mold_id).ToList();
List<ToolMolds> molds = await _db.Queryable<ToolMolds>().Where(it => moldids.Contains(it.id)).ToListAsync();
foreach (var planMoldRelation in planMoldRelations)
{
var mold = molds.Where(p => p.id == planMoldRelation.mold_id).FirstOrDefault();
ToolMolds? mold = molds.Where(p => p.id == planMoldRelation.mold_id).FirstOrDefault();
if (mold != null)
{
dynamic info = new ExpandoObject();
@@ -74,12 +74,12 @@ namespace Tnb.EquipMgr
info.mold_name = mold.mold_name;
info.mold_status = (await _dictionaryDataService.GetInfo(mold.mold_status!))?.FullName;
info.maintain_qty = mold.maintain_qty;
info.designer = planMoldRelation.designer == null ? "" : planMoldRelation.designer;
info.designer = planMoldRelation.designer ?? "";
info.plan_start_time = planMoldRelation.plan_start_time == null ? "" : ((DateTime)planMoldRelation.plan_start_time).ToString("yyyy-MM-dd");
var moldEqpRelation = await _db.Queryable<ToolMoldsEquipment>().FirstAsync(it => it.mold_id == mold.id);
ToolMoldsEquipment moldEqpRelation = await _db.Queryable<ToolMoldsEquipment>().FirstAsync(it => it.mold_id == mold.id);
if (moldEqpRelation != null)
{
var eqp = await _db.Queryable<EqpEquipment>().FirstAsync(it => it.id == moldEqpRelation.equipment_id);
EqpEquipment eqp = await _db.Queryable<EqpEquipment>().FirstAsync(it => it.id == moldEqpRelation.equipment_id);
info.eqp_code = eqp.code;
info.eqp_name = eqp.name;
}
@@ -92,19 +92,21 @@ namespace Tnb.EquipMgr
[HttpGet]
public async Task<dynamic> GetMaintainInfo([FromQuery] MaintainInfoQueryinput input)
{
Dictionary<string, string> dicstatus = new Dictionary<string, string>();
dicstatus.Add("UnMaintain", "待保养");
dicstatus.Add("Completed", "已完成");
Dictionary<string, string> dicstatus = new()
{
{ "UnMaintain", "待保养" },
{ "Completed", "已完成" }
};
List<dynamic> result = new();
var plans = await _db.Queryable<ToolMoldMaintainPlan>().ToListAsync();
var ToolMolds = await _db.Queryable<ToolMolds>().ToListAsync();
var ToolMoldsEquipments = await _db.Queryable<ToolMoldsEquipment>().ToListAsync();
var EqpEquipments = await _db.Queryable<EqpEquipment>().ToListAsync();
var dic = await _db.Queryable<DictionaryDataEntity>().Where(p => p.DictionaryTypeId == "26149299883285").ToListAsync();
var users = await _db.Queryable<UserEntity>().ToListAsync();
var records = _db.Queryable<ToolMoldMaintainItemRecord>().ToList();
var runrecords = _db.Queryable<ToolMoldMaintainRunRecord>().ToList();
foreach (var plan in plans)
List<ToolMoldMaintainPlan> plans = await _db.Queryable<ToolMoldMaintainPlan>().ToListAsync();
List<ToolMolds> ToolMolds = await _db.Queryable<ToolMolds>().ToListAsync();
List<ToolMoldsEquipment> ToolMoldsEquipments = await _db.Queryable<ToolMoldsEquipment>().ToListAsync();
List<EqpEquipment> EqpEquipments = await _db.Queryable<EqpEquipment>().ToListAsync();
List<DictionaryDataEntity> dic = await _db.Queryable<DictionaryDataEntity>().Where(p => p.DictionaryTypeId == "26149299883285").ToListAsync();
List<UserEntity> users = await _db.Queryable<UserEntity>().ToListAsync();
List<ToolMoldMaintainItemRecord> records = _db.Queryable<ToolMoldMaintainItemRecord>().ToList();
List<ToolMoldMaintainRunRecord> runrecords = _db.Queryable<ToolMoldMaintainRunRecord>().ToList();
foreach (ToolMoldMaintainPlan plan in plans)
{
var planMoldRelations = await _db.Queryable<ToolMoldMaintainPlanRelation>()
.LeftJoin<ToolMoldMaintainPlan>((a, b) => a.maintain_plan_id == b.id)
@@ -112,25 +114,27 @@ namespace Tnb.EquipMgr
.Where(a => a.maintain_plan_id == plan.id)
.Select((a, b, c) => new
{
mold_id = a.mold_id,
plan_start_time = c.plan_start_time,
a.mold_id,
c.plan_start_time,
}).ToListAsync();
if (planMoldRelations?.Count > 0)
{
var mids = planMoldRelations.Select(x => x.mold_id).ToList();
var molds = ToolMolds.Where(it => mids.Contains(it.id))
List<string> mids = planMoldRelations.Select(x => x.mold_id).ToList();
List<ToolMolds> molds = ToolMolds.Where(it => mids.Contains(it.id))
.WhereIF(!string.IsNullOrEmpty(input.keyword), p => p.mold_code!.Contains(input.keyword!) || p.mold_name!.Contains(input.keyword!))
.ToList();
if (molds?.Count > 0)
{
for (int i = 0, cnt = molds.Count; i < cnt; i++)
{
var mold = molds[i];
ToolMolds mold = molds[i];
if (!string.IsNullOrEmpty(input.status))
{
var moldstatus = records.Where(p => p.mold_id == mold.id && p.plan_id == plan.id).Any() ? "已完成" : "待保养";
string moldstatus = records.Where(p => p.mold_id == mold.id && p.plan_id == plan.id).Any() ? "已完成" : "待保养";
if (input.status != moldstatus)
{
continue;
}
}
dynamic info = new ExpandoObject();
info.mold_id = mold.id;
@@ -146,13 +150,13 @@ namespace Tnb.EquipMgr
info.starttime = "";
if (runrecords.Where(p => p.mold_code == mold.mold_code && p.plan_code == plan.plan_code).Any())
{
var run = runrecords.Where(p => p.mold_code == mold.mold_code && p.plan_code == plan.plan_code).First();
ToolMoldMaintainRunRecord run = runrecords.Where(p => p.mold_code == mold.mold_code && p.plan_code == plan.plan_code).First();
info.starttime = run.plan_start_time != null ? ((DateTime)run.plan_start_time).ToString("yyyy-MM-dd") : "";
}
var moldEqpRelation = ToolMoldsEquipments.Where(it => it.mold_id == mold.id).FirstOrDefault();
ToolMoldsEquipment? moldEqpRelation = ToolMoldsEquipments.Where(it => it.mold_id == mold.id).FirstOrDefault();
if (moldEqpRelation != null)
{
var eqp = EqpEquipments.Where(it => it.id == moldEqpRelation.equipment_id).FirstOrDefault();
EqpEquipment? eqp = EqpEquipments.Where(it => it.id == moldEqpRelation.equipment_id).FirstOrDefault();
if (eqp != null)
{
info.eqp_code = eqp.code;
@@ -167,9 +171,14 @@ namespace Tnb.EquipMgr
if (!string.IsNullOrEmpty(input.sort))
{
if (input.sort == "createtime")
{
result = result.OrderByDescending(p => p.createtime).ToList();
}
if (input.sort == "plan_start_time")
result = result.OrderByDescending(p => p.plan_start_time).ToList(); ;
{
result = result.OrderByDescending(p => p.plan_start_time).ToList();
};
}
return result;
}
@@ -188,8 +197,8 @@ namespace Tnb.EquipMgr
{
input.sidx = "b." + input.sidx;
}
var records = await _db.Queryable<ToolMoldMaintainItemRecord>().Select(p => p.plan_id + p.mold_id).ToListAsync();
var result = await _db.Queryable<ToolMoldMaintainPlanRelation>()
List<string> records = await _db.Queryable<ToolMoldMaintainItemRecord>().Select(p => p.plan_id + p.mold_id).ToListAsync();
SqlSugarPagedList<PadMainListOutput> result = await _db.Queryable<ToolMoldMaintainPlanRelation>()
.LeftJoin<ToolMoldMaintainPlan>((a, b) => a.maintain_plan_id == b.id)
.LeftJoin<ToolMolds>((a, b, c) => a.mold_id == c.id)
.LeftJoin<ToolMoldMaintainRunRecord>((a, b, c, d) => b.plan_code == d.plan_code && c.mold_code == d.mold_code)
@@ -214,7 +223,7 @@ namespace Tnb.EquipMgr
createtime = b.create_time == null ? "" : b.create_time.Value.ToString(DbTimeFormat.SS),
plan_start_time = b.plan_start_date == null ? "" : b.plan_start_date.Value.ToString(DbTimeFormat.SS),
starttime = d.plan_start_time == null ? "" : d.plan_start_time.Value.ToString(DbTimeFormat.SS),
}).OrderBy($"{input.sidx} {input.sort}").ToPagedListAsync((input?.currentPage ?? 1), (input?.pageSize ?? 50));
}).OrderBy($"{input.sidx} {input.sort}").ToPagedListAsync(input?.currentPage ?? 1, input?.pageSize ?? 50);
return PageResult<PadMainListOutput>.SqlSugarPageResult(result);
}
@@ -244,8 +253,12 @@ namespace Tnb.EquipMgr
[HttpGet]
public async Task<dynamic> GetCheckItemAndGrpByMoldId([FromQuery] CheckItemQueryinput input)
{
if (input == null) throw new ArgumentNullException(nameof(input));
var items = await _db.Queryable<ToolMoldMaintainPlanRelation>()
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
List<CheckItemOutput>? items = await _db.Queryable<ToolMoldMaintainPlanRelation>()
.InnerJoin<ToolMoldMaintainGroupRelation>((a, b) => a.mold_id == b.mold_id)
.InnerJoin<ToolMoldMaintainGroupItem>((a, b, c) => b.item_group_id == c.item_group_id)
.InnerJoin<ToolMoldMaintainGroup>((a, b, c, d) => c.item_group_id == d.id)
@@ -262,22 +275,25 @@ namespace Tnb.EquipMgr
})
.ToListAsync();
//新增功能
var ToolMoldMaintainPlanRelation = _db.Queryable<ToolMoldMaintainPlanRelation>().Where((a) => a.maintain_plan_id == input.plan_id && a.mold_id == input.mold_id && !string.IsNullOrEmpty(a.group_id)).First();
ToolMoldMaintainPlanRelation ToolMoldMaintainPlanRelation = _db.Queryable<ToolMoldMaintainPlanRelation>().Where((a) => a.maintain_plan_id == input.plan_id && a.mold_id == input.mold_id && !string.IsNullOrEmpty(a.group_id)).First();
if (ToolMoldMaintainPlanRelation != null)
{
items = items.Where(a => a.item_group_id == ToolMoldMaintainPlanRelation.group_id).ToList();
}
var checkItems = await _db.Queryable<ToolMoldMaintainItemRecord>().Where(it => it.plan_id == input.plan_id && it.mold_id == input.mold_id).Select(it => new
{
plan_id = it.plan_id,
item_id = it.item_id,
item_group_id = it.item_group_id,
mold_id = it.mold_id,
it.plan_id,
it.item_id,
it.item_group_id,
it.mold_id,
}).ToListAsync();
var dicCheckItems = checkItems.GroupBy(g => $"{g.plan_id}{g.mold_id}{g.item_group_id}{g.item_id}").ToDictionary(x => x.Key, x => x.FirstOrDefault());
if (items?.Count > 0 && checkItems?.Count > 0)
{
foreach (var item in items)
foreach (CheckItemOutput? item in items)
{
var key = $"{item.plan_id}{item.mold_id}{item.item_group_id}{item.item_id}";
string key = $"{item.plan_id}{item.mold_id}{item.item_group_id}{item.item_id}";
if (dicCheckItems.ContainsKey(key) && dicCheckItems[key] != null)
{
item.status = 1;
@@ -300,8 +316,12 @@ namespace Tnb.EquipMgr
[HttpPost]
public async Task MaintainStart(MoldMaintainRunUpInput input)
{
if (input == null) throw new ArgumentNullException("input");
var flag = _db.Queryable<ToolMoldMaintainRunRecord>()
if (input == null)
{
throw new ArgumentNullException("input");
}
bool flag = _db.Queryable<ToolMoldMaintainRunRecord>()
.LeftJoin<ToolMoldMaintainPlan>((a, b) => a.plan_code == b.plan_code)
.LeftJoin<ToolMolds>((a, b, c) => a.mold_code == c.mold_code)
.Where((a, b, c) => b.id == input.plan_id && c.id == input.mold_id).Any();
@@ -313,33 +333,41 @@ namespace Tnb.EquipMgr
{
await _db.Ado.BeginTranAsync();
var dic = await _dictionaryDataService.GetDicByTypeId(DictConst.MaintainStatusTypeId);
var mold = await _db.Queryable<ToolMolds>().FirstAsync(it => it.id == input.mold_id);
Dictionary<string, object> dic = await _dictionaryDataService.GetDicByTypeId(DictConst.MaintainStatusTypeId);
ToolMolds mold = await _db.Queryable<ToolMolds>().FirstAsync(it => it.id == input.mold_id);
if (mold != null)
{
mold.mold_status = MoldUseStatus.MOLD_USE_STATUS_MAINTAIN_ID;
var isOk = await _db.Updateable<ToolMolds>(mold).Where(it => it.id == input.mold_id).ExecuteCommandHasChangeAsync();
if (!isOk) throw Oops.Oh(ErrorCode.COM1001);
var plan = await _db.Queryable<ToolMoldMaintainPlanRelation>().LeftJoin<ToolMoldMaintainPlan>((a, b) => a.maintain_plan_id == b.id)
bool isOk = await _db.Updateable<ToolMolds>(mold).Where(it => it.id == input.mold_id).ExecuteCommandHasChangeAsync();
if (!isOk)
{
throw Oops.Oh(ErrorCode.COM1001);
}
ToolMoldMaintainPlan? plan = await _db.Queryable<ToolMoldMaintainPlanRelation>().LeftJoin<ToolMoldMaintainPlan>((a, b) => a.maintain_plan_id == b.id)
.Where(a => a.mold_id == input.mold_id && a.maintain_plan_id == input.plan_id).Select((a, b) => b).FirstAsync();
if (plan is not null)
{
//插入保养计划记录
ToolMoldMaintainRunRecord record = new();
record.plan_code = plan.plan_code;
record.mode = plan.mode;
record.plan_status = dic.ContainsKey(plan.plan_code) ? dic[plan.plan_code].ToString() : "";
record.designer = _userManager.RealName;
record.designer_time = DateTime.Now;
record.mold_code = mold.mold_code;
record.mold_name = mold.mold_name;
record.plan_start_time = string.IsNullOrEmpty(input.starttime) ? DateTime.Now : DateTime.Parse(input.starttime);
var row = await _db.Insertable(record).ExecuteCommandAsync();
if (row < 1) throw Oops.Oh(ErrorCode.COM1001);
ToolMoldMaintainRunRecord record = new()
{
plan_code = plan.plan_code,
mode = plan.mode,
plan_status = dic.ContainsKey(plan.plan_code) ? dic[plan.plan_code].ToString() : "",
designer = _userManager.RealName,
designer_time = DateTime.Now,
mold_code = mold.mold_code,
mold_name = mold.mold_name,
plan_start_time = string.IsNullOrEmpty(input.starttime) ? DateTime.Now : DateTime.Parse(input.starttime)
};
int row = await _db.Insertable(record).ExecuteCommandAsync();
if (row < 1)
{
throw Oops.Oh(ErrorCode.COM1001);
}
var groupids = _db.Queryable<ToolMoldMaintainPlanRelation>().Where(a => !string.IsNullOrEmpty(a.group_id) && a.mold_id == input.mold_id && a.maintain_plan_id == input.plan_id).ToList().Select(p => p.group_id);
IEnumerable<string> groupids = _db.Queryable<ToolMoldMaintainPlanRelation>().Where(a => !string.IsNullOrEmpty(a.group_id) && a.mold_id == input.mold_id && a.maintain_plan_id == input.plan_id).ToList().Select(p => p.group_id);
/*
var maintainInfos = await _db.Queryable<ToolMoldMaintainGroupRelation>()
@@ -374,16 +402,21 @@ namespace Tnb.EquipMgr
List<ToolMoldMaintainRunRecordD> recordDs = new();
foreach (var info in maintainInfos)
{
ToolMoldMaintainRunRecordD record_d = new();
record_d.mainid = record.id;
record_d.group_id = info.group_id;
record_d.group_name = info.group_name;
record_d.check_item_id = info.check_item_id;
record_d.check_item_name = info.check_item_name;
ToolMoldMaintainRunRecordD record_d = new()
{
mainid = record.id,
group_id = info.group_id,
group_name = info.group_name,
check_item_id = info.check_item_id,
check_item_name = info.check_item_name
};
recordDs.Add(record_d);
}
row = await _db.Insertable(recordDs).ExecuteCommandAsync();
if (row < 1) throw Oops.Oh(ErrorCode.COM1001);
if (row < 1)
{
throw Oops.Oh(ErrorCode.COM1001);
}
}
}
}
@@ -405,47 +438,71 @@ namespace Tnb.EquipMgr
[HttpPost]
public async Task FinishMaintain(MoldMaintainRunUpInput input)
{
if (input == null) throw new ArgumentNullException("input");
if (input.items == null || input.items.Count == 0) throw new ArgumentException($"parameter {nameof(input.items)} not be null or empty");
List<ToolMoldMaintainItemRecord> records = new();
foreach (var item in input.items)
if (input == null)
{
ToolMoldMaintainItemRecord record = new();
record.plan_id = input.plan_id;
record.mold_id = input.mold_id;
record.item_group_id = item.item_group_id;
record.item_id = item.item_id;
record.status = 1;
record.result = item.result;
throw new ArgumentNullException("input");
}
if (input.items == null || input.items.Count == 0)
{
throw new ArgumentException($"parameter {nameof(input.items)} not be null or empty");
}
List<ToolMoldMaintainItemRecord> records = new();
foreach (MaintainItemInfo item in input.items)
{
ToolMoldMaintainItemRecord record = new()
{
plan_id = input.plan_id,
mold_id = input.mold_id,
item_group_id = item.item_group_id,
item_id = item.item_id,
status = 1,
result = item.result
};
records.Add(record);
}
await _db.Insertable(records).ExecuteCommandAsync();
await _db.Updateable<ToolMolds>().SetColumns(it => new ToolMolds { mold_status = MoldUseStatus.MOLD_USE_STATUS_ZK_ID }).Where(it => it.id == input.mold_id).ExecuteCommandAsync();
var count = await _db.Queryable<ToolMoldMaintainPlanRelation>().Where(p => p.maintain_plan_id == input.plan_id).Select(p => p.mold_id).Distinct().CountAsync();
var finish = await _db.Queryable<ToolMoldMaintainItemRecord>().Where(p => p.plan_id == input.plan_id).Select(p => p.mold_id).Distinct().CountAsync();
_ = await _db.Insertable(records).ExecuteCommandAsync();
_ = await _db.Updateable<ToolMolds>().SetColumns(it => new ToolMolds { mold_status = MoldUseStatus.MOLD_USE_STATUS_ZK_ID }).Where(it => it.id == input.mold_id).ExecuteCommandAsync();
int count = await _db.Queryable<ToolMoldMaintainPlanRelation>().Where(p => p.maintain_plan_id == input.plan_id).Select(p => p.mold_id).Distinct().CountAsync();
int finish = await _db.Queryable<ToolMoldMaintainItemRecord>().Where(p => p.plan_id == input.plan_id).Select(p => p.mold_id).Distinct().CountAsync();
if (count == finish)
await _db.Updateable<ToolMoldMaintainPlan>().SetColumns(it => new ToolMoldMaintainPlan { status = MoldPlanMaintainStatus.MOLDPLAN_MAINTAIN_STATUS_COMPLETED_CODE }).Where(it => it.id == input.plan_id).ExecuteCommandAsync();
{
_ = await _db.Updateable<ToolMoldMaintainPlan>().SetColumns(it => new ToolMoldMaintainPlan { status = MoldPlanMaintainStatus.MOLDPLAN_MAINTAIN_STATUS_COMPLETED_CODE }).Where(it => it.id == input.plan_id).ExecuteCommandAsync();
}
}
[HttpPost]
public async Task MaintainItemFinish(MoldMaintainRunUpInput input)
{
if (input == null) throw new ArgumentNullException("input");
if (input.items == null || input.items.Count == 0) throw new ArgumentException($"parameter {nameof(input.items)} not be null or empty");
List<ToolMoldMaintainItemRecord> records = new();
foreach (var item in input.items)
if (input == null)
{
ToolMoldMaintainItemRecord record = new();
record.plan_id = input.plan_id;
record.mold_id = input.mold_id;
record.item_group_id = item.item_group_id;
record.item_id = item.item_id;
record.status = 1;
throw new ArgumentNullException("input");
}
if (input.items == null || input.items.Count == 0)
{
throw new ArgumentException($"parameter {nameof(input.items)} not be null or empty");
}
List<ToolMoldMaintainItemRecord> records = new();
foreach (MaintainItemInfo item in input.items)
{
ToolMoldMaintainItemRecord record = new()
{
plan_id = input.plan_id,
mold_id = input.mold_id,
item_group_id = item.item_group_id,
item_id = item.item_id,
status = 1
};
records.Add(record);
}
var row = await _db.Insertable(records).ExecuteCommandAsync();
if (row < 1) throw Oops.Oh(ErrorCode.COM1001);
int row = await _db.Insertable(records).ExecuteCommandAsync();
if (row < 1)
{
throw Oops.Oh(ErrorCode.COM1001);
}
}
/// <summary>
@@ -456,7 +513,7 @@ namespace Tnb.EquipMgr
[HttpPost]
public async Task MaintainFinish(MoldMaintainRunUpInput input)
{
var items = await _db.Queryable<ToolMoldMaintainPlanRelation>()
List<CheckItemOutput>? items = await _db.Queryable<ToolMoldMaintainPlanRelation>()
.InnerJoin<ToolMoldMaintainGroupRelation>((a, b) => a.mold_id == b.mold_id)
.InnerJoin<ToolMoldMaintainGroupItem>((a, b, c) => b.item_group_id == c.item_group_id)
.InnerJoin<ToolMoldMaintainGroup>((a, b, c, d) => c.item_group_id == d.id)
@@ -473,28 +530,30 @@ namespace Tnb.EquipMgr
})
.ToListAsync();
//新增功能
var ToolMoldMaintainPlanRelation = _db.Queryable<ToolMoldMaintainPlanRelation>().Where((a) => a.maintain_plan_id == input.plan_id && a.mold_id == input.mold_id && !string.IsNullOrEmpty(a.group_id)).First();
ToolMoldMaintainPlanRelation ToolMoldMaintainPlanRelation = _db.Queryable<ToolMoldMaintainPlanRelation>().Where((a) => a.maintain_plan_id == input.plan_id && a.mold_id == input.mold_id && !string.IsNullOrEmpty(a.group_id)).First();
if (ToolMoldMaintainPlanRelation != null)
{
items = items.Where(a => a.item_group_id == ToolMoldMaintainPlanRelation.group_id).ToList();
}
var checkItems = await _db.Queryable<ToolMoldMaintainItemRecord>().Where(it => it.plan_id == input.plan_id && it.mold_id == input.mold_id).Select(it => new
{
plan_id = it.plan_id,
item_id = it.item_id,
item_group_id = it.item_group_id,
mold_id = it.mold_id,
it.plan_id,
it.item_id,
it.item_group_id,
it.mold_id,
}).ToListAsync();
var dicCheckItems = checkItems.GroupBy(g => $"{g.plan_id}{g.mold_id}{g.item_group_id}{g.item_id}").ToDictionary(x => x.Key, x => x.FirstOrDefault());
var maintainedItems = items.Where(it => dicCheckItems.ContainsKey($"{it.plan_id}{it.mold_id}{it.item_group_id}{it.item_id}") && dicCheckItems[$"{it.plan_id}{it.mold_id}{it.item_group_id}{it.item_id}"] != null).ToList();
if ((items?.Count > 0 && maintainedItems?.Count > 0) || (maintainedItems == null || maintainedItems.Count < 1))
List<CheckItemOutput>? maintainedItems = items.Where(it => dicCheckItems.ContainsKey($"{it.plan_id}{it.mold_id}{it.item_group_id}{it.item_id}") && dicCheckItems[$"{it.plan_id}{it.mold_id}{it.item_group_id}{it.item_id}"] != null).ToList();
if ((items?.Count > 0 && maintainedItems?.Count > 0) || maintainedItems == null || maintainedItems.Count < 1)
{
if (maintainedItems.Count < items.Count || (maintainedItems == null || maintainedItems.Count < 1))
if (maintainedItems.Count < items.Count || maintainedItems == null || maintainedItems.Count < 1)
{
throw new AppFriendlyException("当前模具有未完成的保养项目", 500);
}
}
var row = await _db.Updateable<ToolMolds>().SetColumns(it => new ToolMolds { mold_status = MoldUseStatus.MOLD_USE_STATUS_ZK_ID }).Where(it => it.id == input.mold_id).ExecuteCommandAsync();
var allMoldStatus = await _db.Queryable<ToolMoldMaintainPlanRelation>().InnerJoin<ToolMolds>((a, b) => a.mold_id == b.id)
int row = await _db.Updateable<ToolMolds>().SetColumns(it => new ToolMolds { mold_status = MoldUseStatus.MOLD_USE_STATUS_ZK_ID }).Where(it => it.id == input.mold_id).ExecuteCommandAsync();
List<string?> allMoldStatus = await _db.Queryable<ToolMoldMaintainPlanRelation>().InnerJoin<ToolMolds>((a, b) => a.mold_id == b.id)
.Where((a, b) => a.maintain_plan_id == input.plan_id)
.Select((a, b) => b.mold_status)
.ToListAsync();
@@ -502,8 +561,10 @@ namespace Tnb.EquipMgr
{
row = await _db.Updateable<ToolMoldMaintainPlan>().SetColumns(it => new ToolMoldMaintainPlan { status = MoldPlanMaintainStatus.MOLDPLAN_MAINTAIN_STATUS_COMPLETED_CODE }).Where(it => it.id == input.plan_id).ExecuteCommandAsync();
}
if (row < 1) throw Oops.Oh(ErrorCode.COM1001);
if (row < 1)
{
throw Oops.Oh(ErrorCode.COM1001);
}
}
}

View File

@@ -28,7 +28,7 @@ namespace Tnb.EquipMgr
private readonly ISqlSugarClient _db;
private readonly IRunService _runService;
private readonly IVisualDevService _visualDevService;
private static Dictionary<string, (string code, string name)> _dicMold = new Dictionary<string, (string code, string name)>();
private static Dictionary<string, (string code, string name)> _dicMold = new();
public ToolMoldMaintainTaskService(
ISqlSugarRepository<ToolMoldMaintainTask> repository,
IRunService runService,
@@ -48,19 +48,19 @@ namespace Tnb.EquipMgr
{
if (_dicMold.Count < 1)
{
var items = await _db.Queryable<ToolMolds>().ToListAsync();
List<ToolMolds> items = await _db.Queryable<ToolMolds>().ToListAsync();
_dicMold = items?.ToDictionary(x => x.id, x => (x.mold_code, x.mold_name))!;
}
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
var data = await _runService.GetListResult(templateEntity, input);
JNPF.Common.Filter.PageResult<Dictionary<string, object>> data = await _runService.GetListResult(templateEntity, input);
if (data?.list.Count > 0)
{
foreach (var row in data.list)
foreach (Dictionary<string, object> row in data.list)
{
var pair = row[nameof(ToolMoldMaintainTask.mold_id)];
object pair = row[nameof(ToolMoldMaintainTask.mold_id)];
if (pair.IsNotEmptyOrNull())
{
if (_dicMold.TryGetValue(pair.ToString(), out var multi))
if (_dicMold.TryGetValue(pair.ToString(), out (string code, string name) multi))
{
row[nameof(ToolMoldMaintainTask.mold_id)] = $"{multi.code}/{multi.name}";
}
@@ -73,8 +73,11 @@ namespace Tnb.EquipMgr
public async Task Create(ToolMoldMaintainTask entity)
{
var row = await _db.Insertable(entity).ExecuteCommandAsync();
if (row < 1) throw Oops.Oh(ErrorCode.COM1000);
int row = await _db.Insertable(entity).ExecuteCommandAsync();
if (row < 1)
{
throw Oops.Oh(ErrorCode.COM1000);
}
}
/// <summary>
/// 修改任务单状态
@@ -90,9 +93,12 @@ namespace Tnb.EquipMgr
{
endTime = DateTime.Now;
}
var row = await _db.Updateable<ToolMoldMaintainTask>().SetColumns(it => new ToolMoldMaintainTask { status = input.status, modify_strat_time = beginTiem, modify_end_time = endTime })
int row = await _db.Updateable<ToolMoldMaintainTask>().SetColumns(it => new ToolMoldMaintainTask { status = input.status, modify_strat_time = beginTiem, modify_end_time = endTime })
.Where(it => input.ids.Contains(it.id)).ExecuteCommandAsync();
if (row < 1) throw Oops.Oh(ErrorCode.COM1001);
if (row < 1)
{
throw Oops.Oh(ErrorCode.COM1001);
}
}
}
}

View File

@@ -51,29 +51,29 @@ namespace Tnb.EquipMgr
private async Task<dynamic> GetList(VisualDevModelListQueryInput input)
{
Dictionary<string, object>? queryJson = new Dictionary<string, object>();
Dictionary<string, object>? queryJson = new();
string? requisitionCode = "";
DateTime[] requisitionTimeArr = null;
DateTime[] estimatedReturnArr = null;
DateTime[]? requisitionTimeArr = null;
DateTime[]? estimatedReturnArr = null;
if (input != null && !string.IsNullOrEmpty(input.queryJson))
{
queryJson = JsonConvert.DeserializeObject<Dictionary<string, object>>(input?.queryJson ?? "");
}
if (queryJson!.TryGetValue("requisition_code", out var value))
if (queryJson!.TryGetValue("requisition_code", out object? value))
{
requisitionCode = value.ToString();
}
if (queryJson!.TryGetValue("requisition_time", out var value1))
if (queryJson!.TryGetValue("requisition_time", out object? value1))
{
requisitionTimeArr = value1.ToObject<long[]>().Select(x => DateTimeOffset.FromUnixTimeSeconds(x / 1000).ToLocalTime().DateTime).ToArray();
}
if (queryJson!.TryGetValue("estimated_return_time", out var value2))
if (queryJson!.TryGetValue("estimated_return_time", out object? value2))
{
estimatedReturnArr = value2.ToObject<long[]>().Select(x => DateTimeOffset.FromUnixTimeSeconds(x / 1000).ToLocalTime().DateTime).ToArray();
}
var result = await _db.Queryable<ToolMoldRequisition>()
SqlSugarPagedList<ToolMoldRequisitionListOutput> result = await _db.Queryable<ToolMoldRequisition>()
.LeftJoin<PrdMoTask>((a, b) => a.mo_task_id == b.id)
.LeftJoin<EqpEquipment>((a, b, c) => a.equip_id == c.id)
.LeftJoin<UserEntity>((a, b, c, d) => a.recipient_id == d.Id)
@@ -105,35 +105,38 @@ namespace Tnb.EquipMgr
await _runService.Create(templateEntity, input);
await _db.Updateable<ToolMolds>().SetColumns(x => x.mold_status == Tnb.BasicData.DictConst.SCTypeId)
_ = await _db.Updateable<ToolMolds>().SetColumns(x => x.mold_status == Tnb.BasicData.DictConst.SCTypeId)
.Where(X => X.id == input.data["mold_id"]).ExecuteCommandAsync();
});
if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
return result.IsSuccess ? "保存成功" : result.ErrorMessage;
return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : (dynamic)(result.IsSuccess ? "保存成功" : result.ErrorMessage);
}
[HttpPost]
public async Task<dynamic> GetTools(ToolInput toolinput)
{
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("26149307089941", "在库");
dic.Add("26149309121045", "生产");
dic.Add("26149311082005", "保养");
dic.Add("26149314425877", "报废");
dic.Add("26149312750101", "外协");
dic.Add("26149320818965", "维修");
Dictionary<string, string> dic = new()
{
{ "26149307089941", "在库" },
{ "26149309121045", "生产" },
{ "26149311082005", "保养" },
{ "26149314425877", "报废" },
{ "26149312750101", "外协" },
{ "26149320818965", "维修" }
};
List<dynamic> result = new();
var BasLocations = await _db.Queryable<ToolLocation>().ToListAsync();
var ToolMolds = await _db.Queryable<ToolMolds>()
List<ToolLocation> BasLocations = await _db.Queryable<ToolLocation>().ToListAsync();
List<ToolMolds> ToolMolds = await _db.Queryable<ToolMolds>()
.WhereIF(!string.IsNullOrEmpty(toolinput.keyword), p => p.mold_code!.Contains(toolinput.keyword!) || p.mold_name!.Contains(toolinput.keyword!))
.WhereIF(!string.IsNullOrEmpty(toolinput.status), p => p.mold_status == dic.Where(p => p.Value == toolinput.status).First().Key)
.ToListAsync();
if (string.IsNullOrEmpty(toolinput.sort))
{
if (toolinput.sort == "mold_code")
{
ToolMolds = ToolMolds.OrderByDescending(p => p.mold_code).ToList();
}
}
foreach (var tool in ToolMolds)
foreach (ToolMolds tool in ToolMolds)
{
dynamic info = new ExpandoObject();
info.id = tool.id;

View File

@@ -48,23 +48,22 @@ namespace Tnb.EquipMgr
string? locationId = "";
if (input.data.TryGetValue("location_id", out var value))
if (input.data.TryGetValue("location_id", out object? value))
{
locationId = value.ToString();
}
string moldId = input.data.ContainsKey("mold_id") ? input.data["mold_id"].ToString() : "";
string? moldId = input.data.ContainsKey("mold_id") ? input.data["mold_id"].ToString() : "";
if (!string.IsNullOrEmpty(moldId))
{
await _db.Updateable<ToolMolds>()
_ = await _db.Updateable<ToolMolds>()
.SetColumns(x => x.mold_status == Tnb.BasicData.DictConst.ZKTypeId)
.SetColumnsIF(!string.IsNullOrEmpty(locationId), x => x.location_id == locationId)
.Where(X => X.id == moldId).ExecuteCommandAsync();
}
});
if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
return result.IsSuccess ? "保存成功" : result.ErrorMessage;
return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : (dynamic)(result.IsSuccess ? "保存成功" : result.ErrorMessage);
}
}
}

View File

@@ -41,7 +41,7 @@ namespace Tnb.EquipMgr
}
private async Task<dynamic> Create(VisualDevModelDataCrInput visualDevModelDataCrInput)
{
string qrcode = visualDevModelDataCrInput.data.ContainsKey("qrcode") ? visualDevModelDataCrInput.data["qrcode"].ToString() : "";
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("二维码总表中已存在该二维码");
@@ -55,7 +55,7 @@ namespace Tnb.EquipMgr
if (!string.IsNullOrEmpty(qrcode))
{
BasQrcode basQrcode = new BasQrcode()
BasQrcode basQrcode = new()
{
code = visualDevModelDataCrInput.data["qrcode"].ToString(),
source_id = ToolId,
@@ -64,7 +64,7 @@ namespace Tnb.EquipMgr
create_time = DateTime.Now,
org_id = _userManager.GetUserInfo().Result.organizeId,
};
await _repository.AsSugarClient().Insertable<BasQrcode>(basQrcode).ExecuteCommandAsync();
_ = await _repository.AsSugarClient().Insertable<BasQrcode>(basQrcode).ExecuteCommandAsync();
}
}
return await Task.FromResult(true);
@@ -72,7 +72,7 @@ namespace Tnb.EquipMgr
private async Task<dynamic> Update(string id, VisualDevModelDataUpInput visualDevModelDataUpInput)
{
string qrcode = visualDevModelDataUpInput.data.ContainsKey("qrcode") ? visualDevModelDataUpInput.data["qrcode"].ToString() : "";
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("二维码总表中已存在该二维码");
@@ -86,13 +86,13 @@ namespace Tnb.EquipMgr
{
if (await _repository.AsSugarClient().Queryable<BasQrcode>().AnyAsync(x => x.source_id == id))
{
await _repository.AsSugarClient().Updateable<BasQrcode>()
_ = await _repository.AsSugarClient().Updateable<BasQrcode>()
.SetColumns(x => x.code == visualDevModelDataUpInput.data["qrcode"].ToString()).Where(x => x.source_id == id)
.ExecuteCommandAsync();
}
else
{
BasQrcode basQrcode = new BasQrcode()
BasQrcode basQrcode = new()
{
code = visualDevModelDataUpInput.data["qrcode"].ToString(),
source_id = id,
@@ -101,7 +101,7 @@ namespace Tnb.EquipMgr
create_time = DateTime.Now,
org_id = _userManager.GetUserInfo().Result.organizeId,
};
await _repository.AsSugarClient().Insertable<BasQrcode>(basQrcode).ExecuteCommandAsync();
_ = await _repository.AsSugarClient().Insertable<BasQrcode>(basQrcode).ExecuteCommandAsync();
}
}
}
@@ -126,8 +126,8 @@ namespace Tnb.EquipMgr
[HttpGet]
public async Task<List<ToolMolds>> GetListByEqpId([FromRoute] string eqpId)
{
var db = _repository.AsSugarClient();
var result = await db.Queryable<ToolMolds>().InnerJoin<ToolMoldsEquipment>((a, b) => a.id == b.mold_id)
ISqlSugarClient db = _repository.AsSugarClient();
List<ToolMolds> result = await db.Queryable<ToolMolds>().InnerJoin<ToolMoldsEquipment>((a, b) => a.id == b.mold_id)
.Where((a, b) => b.equipment_id == eqpId)
.Select((a, b) => a)
.ToListAsync();
@@ -137,13 +137,12 @@ namespace Tnb.EquipMgr
/// <summary>
/// 根据模具id获取设备集合
/// </summary>
/// <param name="mold"></param>
/// <returns></returns>
[HttpPost]
public async Task<List<Tnb.EquipMgr.Entities.Dto.EquipmentListOutput>> GetEquipmentLists(ToolMoldInput ToolMoldInput)
{
var db = _repository.AsSugarClient();
var list = await db.Queryable<EqpEquipment, ToolMoldsEquipment>((a, b) => new object[]
ISqlSugarClient db = _repository.AsSugarClient();
List<EquipmentListOutput> list = await db.Queryable<EqpEquipment, ToolMoldsEquipment>((a, b) => new object[]
{
JoinType.Inner, a.id == b.equipment_id,
})
@@ -160,50 +159,51 @@ namespace Tnb.EquipMgr
/// <summary>
/// 增加模具设备绑定
/// </summary>
/// <param name="mold"></param>
/// <param name="equipid"></param>
/// <param name="ToolMoldInput"></param>
/// <returns></returns>
[HttpPost]
public async Task<dynamic> SaveData(ToolMoldInput ToolMoldInput)
{
DbResult<bool> result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
{
var his = await _repository.AsSugarClient().Queryable<ToolMoldsEquipment>().ToListAsync();
var list = new List<ToolMoldsEquipment>();
foreach (var equip in ToolMoldInput.equipid)
List<ToolMoldsEquipment> his = await _repository.AsSugarClient().Queryable<ToolMoldsEquipment>().ToListAsync();
List<ToolMoldsEquipment> list = new();
foreach (string equip in ToolMoldInput.equipid)
{
if (his.Where(p => p.mold_id == ToolMoldInput.mold && p.equipment_id == equip).ToList().Count > 0)
{
continue;
var entity = new ToolMoldsEquipment();
entity.id = SnowflakeIdHelper.NextId();
entity.mold_id = ToolMoldInput.mold;
entity.equipment_id = equip;
entity.create_time = DateTime.Now;
entity.create_id = _userManager.UserId;
}
ToolMoldsEquipment entity = new()
{
id = SnowflakeIdHelper.NextId(),
mold_id = ToolMoldInput.mold,
equipment_id = equip,
create_time = DateTime.Now,
create_id = _userManager.UserId
};
list.Add(entity);
}
await _repository.AsSugarClient().Insertable<ToolMoldsEquipment>(list).ExecuteCommandAsync();
_ = await _repository.AsSugarClient().Insertable<ToolMoldsEquipment>(list).ExecuteCommandAsync();
});
if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
return result.IsSuccess ? "保存成功" : result.ErrorMessage;
return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : (dynamic)(result.IsSuccess ? "保存成功" : result.ErrorMessage);
}
/// <summary>
/// 批量删除模具设备绑定
/// </summary>
/// <param name="mold"></param>
/// <param name="equipid"></param>
/// <param name="ToolMoldInput"></param>
/// <returns></returns>
[HttpPost]
public async Task<dynamic> DetachData(ToolMoldInput ToolMoldInput)
{
DbResult<bool> result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
{
var arr = _repository.AsSugarClient().Queryable<ToolMoldsEquipment>().Where(x => x.mold_id == ToolMoldInput.mold && ToolMoldInput.equipid.Contains(x.equipment_id)).ToList();
await _repository.AsSugarClient().Deleteable<ToolMoldsEquipment>(arr).ExecuteCommandAsync();
List<ToolMoldsEquipment> arr = _repository.AsSugarClient().Queryable<ToolMoldsEquipment>().Where(x => x.mold_id == ToolMoldInput.mold && ToolMoldInput.equipid.Contains(x.equipment_id)).ToList();
_ = await _repository.AsSugarClient().Deleteable<ToolMoldsEquipment>(arr).ExecuteCommandAsync();
});
if (!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
return result.IsSuccess ? "操作成功" : result.ErrorMessage;
return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : (dynamic)(result.IsSuccess ? "操作成功" : result.ErrorMessage);
}
public Task<ToolMolds> GetListById(string moldId)