265 lines
12 KiB
C#
265 lines
12 KiB
C#
using JNPF;
|
|
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Enums;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.Extras.CollectiveOAuth.Models;
|
|
using JNPF.Extras.CollectiveOAuth.Utils;
|
|
using JNPF.FriendlyException;
|
|
using JNPF.Logging;
|
|
using JNPF.RemoteRequest;
|
|
using JNPF.Systems.Interfaces.System;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json;
|
|
using SqlSugar;
|
|
using Tnb.BasicData.Entities;
|
|
using Tnb.ProductionMgr.Entities;
|
|
using Tnb.ProductionMgr.Entities.Dto;
|
|
using Tnb.ProductionMgr.Interfaces;
|
|
using Tnb.WarehouseMgr;
|
|
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
|
using Tnb.BasicData;
|
|
using JNPF.VisualDev;
|
|
using JNPF.VisualDev.Entitys.Dto.VisualDevModelData;
|
|
using Tnb.EquipMgr.Entities;
|
|
using Tnb.ProductionMgr.Entities.Dto.PrdManage;
|
|
using JNPF.Common.Filter;
|
|
using JNPF.Common.Security;
|
|
using JNPF.Systems.Entitys.Permission;
|
|
using JNPF.Systems.Interfaces.Permission;
|
|
using SQLitePCL;
|
|
using SqlSugar.Extensions;
|
|
|
|
namespace Tnb.ProductionMgr
|
|
{
|
|
/// <summary>
|
|
/// mes生产入库申请
|
|
/// </summary>
|
|
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)]
|
|
[Route("api/[area]/[controller]/[action]")]
|
|
[OverideVisualDev(ModuleId)]
|
|
public class PrdInstockService : IPrdInstockService, IDynamicApiController, ITransient, IOverideVisualDevService
|
|
{
|
|
private readonly ISqlSugarRepository<PrdInstockH> _repository;
|
|
private readonly IUserManager _userManager;
|
|
private readonly IOrganizeService _organizeService;
|
|
private const string ModuleId = "25572529329173";
|
|
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
|
|
|
public PrdInstockService(
|
|
ISqlSugarRepository<PrdInstockH> repository,
|
|
IOrganizeService organizeService,
|
|
IUserManager userManager
|
|
)
|
|
{
|
|
_repository = repository;
|
|
_organizeService = organizeService;
|
|
_userManager = userManager;
|
|
OverideFuncs.GetListAsync = GetList;
|
|
}
|
|
|
|
private async Task<dynamic> GetList(VisualDevModelListQueryInput input)
|
|
{
|
|
Dictionary<string, string> queryJson = !string.IsNullOrEmpty(input.queryJson) ? Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(input.queryJson) : new Dictionary<string, string>();
|
|
string moCode = queryJson.ContainsKey("mo_task_code") ? queryJson["mo_task_code"].ToString() : "";
|
|
var list = await _repository.AsSugarClient().Queryable<PrdMoTask>()
|
|
.LeftJoin<BasMaterial>((a, b) => a.material_id == b.id)
|
|
.LeftJoin<ToolMolds>((a, b, c) => a.mold_id == c.id)
|
|
.LeftJoin<EqpEquipment>((a, b, c, d) => a.eqp_id == d.id)
|
|
.WhereIF(!string.IsNullOrEmpty(moCode), (a, b, c, d) => a.mo_task_code!.Contains(moCode))
|
|
.Select((a, b, c, d) => new PrdMoTaskTreeOutput()
|
|
{
|
|
id = a.id,
|
|
parentId = string.IsNullOrEmpty(a.parent_id) ? "0" : a.parent_id,
|
|
mo_task_code = a.mo_task_code,
|
|
material_id = b.name,
|
|
material_id_id = b.id,
|
|
mold_id = c.mold_name,
|
|
mold_id_id = c.id,
|
|
eqp_id = d.name,
|
|
eqp_id_id = d.id,
|
|
estimated_start_date = a.estimated_start_date!.ToString(),
|
|
estimated_end_date = a.estimated_end_date.ToString(),
|
|
create_time = a.create_time.ToString()
|
|
}).ToListAsync();
|
|
var treeList = list.ToTree();
|
|
treeList= treeList.Skip((input.currentPage-1)* input.pageSize).Take(input.pageSize).ToList();
|
|
SqlSugarPagedList<PrdMoTaskTreeOutput> pagedList = new()
|
|
{
|
|
list = treeList,
|
|
pagination = new Pagination
|
|
{
|
|
CurrentPage = input.currentPage,
|
|
PageSize = input.pageSize,
|
|
Total = treeList.Count
|
|
}
|
|
};
|
|
return PageResult<PrdMoTaskTreeOutput>.SqlSugarPageResult(pagedList);
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<dynamic> SaveData(PrdInstockInput input)
|
|
{
|
|
var db = _repository.AsSugarClient();
|
|
var location = await db.Queryable<BasLocation>().FirstAsync(x => x.location_code == input.location_code);
|
|
PrdInstockH prdInstockH = null;
|
|
List<PrdInstockD> prdInstockDs = new List<PrdInstockD>() { };
|
|
DbResult<bool> result2 = new DbResult<bool>();
|
|
|
|
if (string.IsNullOrEmpty(input.station_id))
|
|
{
|
|
throw Oops.Bah("请先选择工位");
|
|
}
|
|
|
|
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
|
|
{
|
|
OrganizeEntity workline = await _organizeService.GetAnyParentByWorkstationId(input.station_id, DictConst.RegionCategoryWorklineCode);
|
|
OrganizeEntity workshop = await _organizeService.GetAnyParentByWorkstationId(input.station_id, DictConst.RegionCategoryWorkshopCode);
|
|
|
|
|
|
prdInstockH = new PrdInstockH()
|
|
{
|
|
bill_type = input.bill_type,
|
|
bill_date = DateTime.Now,
|
|
create_id = _userManager.UserId,
|
|
location_code = input.location_code,
|
|
carry_code = input.carry_code,
|
|
is_check = input.is_check,
|
|
station_id = input.station_id,
|
|
workline_id = workline?.Id ?? "",
|
|
workshop_id = workshop?.Id ?? "",
|
|
org_id = _userManager.GetUserInfo().Result.organizeId,
|
|
warehouse_id = location?.wh_id,
|
|
status = 0,
|
|
};
|
|
|
|
foreach (var item in input.details)
|
|
{
|
|
prdInstockDs.Add(new PrdInstockD()
|
|
{
|
|
instock_id = prdInstockH.id,
|
|
report_id = item.ContainsKey("report_id") ? item["report_id"] : "",
|
|
material_id = item.ContainsKey("material_id") ? item["material_id"] : "",
|
|
material_code = item.ContainsKey("material_code") ? item["material_code"] : "",
|
|
unit_id = item.ContainsKey("unit_id") ? item["unit_id"] : "",
|
|
// code_batch = item.ContainsKey("batch") ? item["batch"] : "",
|
|
// barcode = item.ContainsKey("batch") ? item["batch"]+"0001" : "",
|
|
barcode = item.ContainsKey("barcode") ? item["barcode"] : "",
|
|
code_batch = item.ContainsKey("barcode") ? item["barcode"]+"0001" : "",
|
|
quantity = Convert.ToInt32(item.ContainsKey("quantity") ? item["quantity"] : "0"),
|
|
});
|
|
}
|
|
|
|
// await _repository.InsertAsync(prdInstockH);
|
|
//
|
|
// if (prdInstockDs.Count > 0)
|
|
// {
|
|
// await db.Insertable<PrdInstockD>(prdInstockDs).ExecuteCommandAsync();
|
|
// }
|
|
|
|
});
|
|
|
|
if (result.IsSuccess)
|
|
{
|
|
MESCreateInstockInput mesCreateInstockInput = new MESCreateInstockInput();
|
|
mesCreateInstockInput.instock = new MESWmsInstockHInput()
|
|
{
|
|
org_id = _userManager.GetUserInfo().Result.organizeId,
|
|
bill_date = DateTime.Now,
|
|
bill_type = input.bill_type,
|
|
warehouse_id = location?.wh_id,
|
|
source_id = prdInstockH.id,
|
|
create_id = _userManager.UserId,
|
|
carry_code = input.carry_code,
|
|
location_code = input.location_code,
|
|
is_check = input.is_check,
|
|
};
|
|
mesCreateInstockInput.instockds = new List<MESWmsInstockDInput>();
|
|
mesCreateInstockInput.instockcodes = new List<MESWmsInstockCodeInput>();
|
|
foreach (var item in input.details)
|
|
{
|
|
mesCreateInstockInput.instockds.Add(new MESWmsInstockDInput()
|
|
{
|
|
material_id = item.ContainsKey("material_id") ? item["material_id"] : "",
|
|
material_code = item.ContainsKey("material_code") ? item["material_code"] : "",
|
|
unit_id = item.ContainsKey("unit_id") ? item["unit_id"] : "",
|
|
code_batch = item.ContainsKey("barcode") ? item["barcode"]+"0001" : "",
|
|
pr_qty = Convert.ToInt32(item.ContainsKey("quantity") ? item["quantity"] : "0"),
|
|
});
|
|
|
|
mesCreateInstockInput.instockcodes.Add(new MESWmsInstockCodeInput()
|
|
{
|
|
material_id = item.ContainsKey("material_id") ? item["material_id"] : "",
|
|
material_code = item.ContainsKey("material_code") ? item["material_code"] : "",
|
|
unit_id = item.ContainsKey("unit_id") ? item["unit_id"] : "",
|
|
// code_batch = item.ContainsKey("batch") ? item["batch"] : "",
|
|
// barcode = item.ContainsKey("batch") ? item["batch"]+"0001" : "",
|
|
barcode = item.ContainsKey("barcode") ? item["barcode"] : "",
|
|
code_batch = item.ContainsKey("barcode") ? item["barcode"]+"0001" : "",
|
|
codeqty = Convert.ToInt32(item.ContainsKey("quantity") ? item["quantity"] : "0"),
|
|
});
|
|
}
|
|
string domain = (App.HttpContext.Request.IsHttps ? "https://" : "http://") + App.HttpContext.Request.Host;
|
|
Dictionary<string, object> header = new Dictionary<string, object>()
|
|
{
|
|
["Authorization"] = App.HttpContext.Request.Headers["Authorization"]
|
|
};
|
|
var sendResult = HttpUtils.RequestPost(domain + WebApiConst.MES_CREATE_INSTOCK,JsonConvert.SerializeObject(mesCreateInstockInput),header);
|
|
Log.Information(sendResult);
|
|
AuthResponse authResponse = JsonConvert.DeserializeObject<AuthResponse>(sendResult);
|
|
if (authResponse.code != 200 || !authResponse.data.ObjToBool())
|
|
{
|
|
throw Oops.Bah(authResponse.msg);
|
|
}
|
|
else
|
|
{
|
|
result2 = await db.Ado.UseTranAsync(async () =>
|
|
{
|
|
await _repository.InsertAsync(prdInstockH);
|
|
|
|
if (prdInstockDs.Count > 0)
|
|
{
|
|
await db.Insertable<PrdInstockD>(prdInstockDs).ExecuteCommandAsync();
|
|
}
|
|
});
|
|
|
|
}
|
|
}
|
|
|
|
if(!result2.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
|
|
return result2.IsSuccess ? "保存成功" : result2.ErrorMessage;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 入库申请同步
|
|
/// </summary>
|
|
/// <param name="dic">source_id</param>
|
|
/// <returns></returns>
|
|
public async Task<dynamic> SyncInstock(Dictionary<string, string> dic)
|
|
{
|
|
string sourceId = dic.ContainsKey("source_id") ? dic["source_id"] : "";
|
|
var db = _repository.AsSugarClient();
|
|
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
|
|
{
|
|
if (!string.IsNullOrEmpty(sourceId))
|
|
{
|
|
await _repository.UpdateAsync(x => new PrdInstockH()
|
|
{
|
|
status = 1
|
|
}, x => x.id == sourceId);
|
|
var details = await db.Queryable<PrdInstockD>().Where(x => x.instock_id == sourceId).ToListAsync();
|
|
|
|
foreach (var item in details)
|
|
{
|
|
await db.Updateable<PrdReport>().SetColumns(x => x.status == 1)
|
|
.Where(x => x.id == item.report_id).ExecuteCommandAsync();
|
|
}
|
|
}
|
|
});
|
|
|
|
return result.IsSuccess;
|
|
}
|
|
}
|
|
} |