119 lines
4.9 KiB
C#
119 lines
4.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Aspose.Cells.Drawing;
|
|
using JNPF.Common.Dtos.VisualDev;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.VisualDev;
|
|
using JNPF.VisualDev.Entitys.Dto.VisualDevModelData;
|
|
using JNPF.VisualDev.Entitys;
|
|
using JNPF.VisualDev.Interfaces;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using SqlSugar;
|
|
using Tnb.BasicData.Entities;
|
|
using Tnb.ProductionMgr.Entities;
|
|
using Tnb.ProductionMgr.Interfaces;
|
|
using JNPF.Systems.Interfaces.System;
|
|
using Tnb.BasicData;
|
|
using JNPF.Common.Extension;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace Tnb.ProductionMgr
|
|
{
|
|
/// <summary>
|
|
/// 生产提报记录
|
|
/// </summary>
|
|
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)]
|
|
[Route("api/[area]/[controller]/[action]")]
|
|
[OverideVisualDev(ModuleId)]
|
|
public class ProductionReportRecordService : IOverideVisualDevService, IProductionReportRecordService, IDynamicApiController, ITransient
|
|
{
|
|
private const string ModuleId = "25568191969061";
|
|
private readonly ISqlSugarRepository<PrdMoTask> _repository;
|
|
private readonly ISqlSugarClient _db;
|
|
private readonly IRunService _runService;
|
|
private readonly IVisualDevService _visualDevService;
|
|
private readonly IDictionaryDataService _dictionaryDataService;
|
|
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
|
public ProductionReportRecordService(ISqlSugarRepository<PrdMoTask> repository, IRunService runService, IVisualDevService visualDevService, IDictionaryDataService dictionaryDataService)
|
|
{
|
|
_db = repository.AsSugarClient();
|
|
_runService = runService;
|
|
_visualDevService = visualDevService;
|
|
OverideFuncs.GetListAsync = GetList;
|
|
OverideFuncs.UpdateAsync = AddRecord;
|
|
_dictionaryDataService = dictionaryDataService;
|
|
_repository = repository;
|
|
}
|
|
|
|
|
|
private async Task<dynamic> GetList(VisualDevModelListQueryInput input)
|
|
{
|
|
|
|
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
|
|
var data = await _runService.GetListResult(templateEntity, input);
|
|
//if (data?.list?.Count > 0)
|
|
//{
|
|
// var dicMoTaskStatus = await _dictionaryDataService.GetDicByTypeId(DictConst.PrdTaskStatusTypeId);
|
|
// foreach (var row in data.list)
|
|
// {
|
|
// var dic = row.ToDictionary(x => x.Key, x => x.Value);
|
|
// //if (dic.ContainsKey(nameof(PrdReportRecord.status)))
|
|
// //{
|
|
// // var statusCode = dic[nameof(PrdReportRecord.status)].ToString();
|
|
// // row[nameof(PrdReportRecord.status)] = dicMoTaskStatus[statusCode];
|
|
// //}
|
|
// if (dic.ContainsKey(nameof(PrdReportRecord.mo_task_type)))
|
|
// {
|
|
// var moTypeId = dic[nameof(PrdReportRecord.mo_task_type)].ToString();
|
|
// if (moTypeId.IsNotEmptyOrNull())
|
|
// {
|
|
// row[nameof(PrdReportRecord.mo_task_type)] = (await _dictionaryDataService.GetInfo(moTypeId)).FullName;
|
|
// }
|
|
|
|
// }
|
|
// }
|
|
//}
|
|
return data!;
|
|
}
|
|
|
|
private async Task<dynamic> AddRecord(string id,VisualDevModelDataUpInput input)
|
|
{
|
|
var db = _repository.AsSugarClient();
|
|
var result = await db.Ado.UseTranAsync(async () =>
|
|
{
|
|
List<PrdReport> prdReports = new List<PrdReport>();
|
|
foreach (var item in (JArray)input.data["tablefield107"])
|
|
{
|
|
if (item["id"] == null)
|
|
{
|
|
prdReports.Add(new PrdReport()
|
|
{
|
|
mo_task_id = input.data["mo_task_id"]?.ToString(),
|
|
mo_task_code = input.data["mo_task_code"]?.ToString(),
|
|
reported_qty = (int)item["reported_qty"],
|
|
create_id = item["create_id"]?.ToString(),
|
|
create_time = DateTime.Now,
|
|
});
|
|
}
|
|
}
|
|
|
|
await db.Insertable<PrdReport>(prdReports).ExecuteCommandAsync();
|
|
|
|
int? sum = prdReports.Sum(x => x.reported_qty);
|
|
await db.Updateable<PrdReportRecord>()
|
|
.SetColumns(x => x.completed_qty == x.completed_qty + sum)
|
|
.SetColumns(x => x.reported_work_qty == x.reported_work_qty + sum)
|
|
.Where(x => x.id == input.data["id"].ToString()).ExecuteCommandAsync();
|
|
|
|
});
|
|
|
|
return result.IsSuccess;
|
|
}
|
|
}
|
|
}
|