执行代码清理,修复warning
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user