@@ -1,10 +1,14 @@
using JNPF.Common.Core.Manager ;
using JNPF ;
using JNPF.Common.Core.Manager ;
using JNPF.Common.Extension ;
using JNPF.Common.Filter ;
using JNPF.Common.Security ;
using JNPF.DependencyInjection ;
using JNPF.DynamicApiController ;
using JNPF.Extras.CollectiveOAuth.Models ;
using JNPF.Extras.CollectiveOAuth.Utils ;
using JNPF.FriendlyException ;
using JNPF.Logging ;
using JNPF.Systems.Entitys.Permission ;
using JNPF.Systems.Entitys.System ;
using JNPF.Systems.Interfaces.System ;
@@ -12,6 +16,7 @@ using JNPF.VisualDev;
using JNPF.VisualDev.Entitys.Dto.VisualDevModelData ;
using JNPF.VisualDev.Interfaces ;
using Microsoft.AspNetCore.Mvc ;
using Newtonsoft.Json ;
using SqlSugar ;
using Tnb.BasicData ;
using Tnb.BasicData.Entities ;
@@ -21,6 +26,8 @@ using Tnb.ProductionMgr.Entities.Dto;
using Tnb.ProductionMgr.Entities.Dto.PrdManage ;
using Tnb.ProductionMgr.Entities.Enums ;
using Tnb.ProductionMgr.Interfaces ;
using AuthResponse = JNPF . Extras . CollectiveOAuth . Models . AuthResponse ;
using StringExtensions = JNPF . Common . Extension . StringExtensions ;
namespace Tnb.ProductionMgr
{
@@ -204,7 +211,7 @@ namespace Tnb.ProductionMgr
{
throw new ArgumentNullException ( nameof ( input ) ) ;
}
if ( input . Behavior . IsNullOrWhiteSpace ( ) )
if ( StringExtensions . IsNullOrWhiteSpace ( input . Behavior ) )
{
throw new ArgumentException ( $"{nameof(input.Behavior)},not be null or empty" ) ;
}
@@ -359,7 +366,7 @@ namespace Tnb.ProductionMgr
#endregion
#region 工 单 追 溯 相 关
#region 正 向 工单 追 溯 相 关
/// <summary>
/// 工单追溯一级列表
@@ -377,15 +384,15 @@ namespace Tnb.ProductionMgr
ids1 = await _db . Queryable < PrdMoTask > ( ) . Where ( x = > x . mo_task_code . Contains ( x . mo_task_code ) ) . Select ( x = > x . mo_id ) . ToListAsync ( ) ;
ids = ids1 ;
}
if ( ! string . IsNullOrEmpty ( input . batch ) )
if ( ! string . IsNullOrEmpty ( input . barcode ) )
{
ids2 = await _db . Queryable < PrdReport > ( )
. LeftJoin < PrdMoTask > ( ( a , b ) = > a . mo_task_id = = b . id )
. Where ( ( a , b ) = > a . batch . Contains ( input . batch ) ) . Select ( ( a , b ) = > b . mo_id ) . ToListAsync ( ) ;
. Where ( ( a , b ) = > a . barcode . Contains ( input . barcode ) ) . Select ( ( a , b ) = > b . mo_id ) . ToListAsync ( ) ;
ids = ids2 ;
}
if ( ! string . IsNullOrEmpty ( input . mo_task_code ) & & ! string . IsNullOrEmpty ( input . batch ) )
if ( ! string . IsNullOrEmpty ( input . mo_task_code ) & & ! string . IsNullOrEmpty ( input . barcode ) )
{
ids = ids1 . Intersect ( ids2 ) . ToList ( ) ;
}
@@ -419,11 +426,11 @@ namespace Tnb.ProductionMgr
{
string mo_id = dic . ContainsKey ( "mo_id" ) ? dic [ "mo_id" ] : "" ;
string mo_task_code = dic . ContainsKey ( "mo_task_code" ) ? dic [ "mo_task_code" ] : "" ;
string batch = dic . ContainsKey ( "batch " ) ? dic [ "batch " ] : "" ;
string barcode = dic . ContainsKey ( "barcode " ) ? dic [ "barcode " ] : "" ;
List < string > ids = new List < string > ( ) ;
if ( ! string . IsNullOrEmpty ( batch ) )
if ( ! string . IsNullOrEmpty ( barcode ) )
{
ids = await _db . Queryable < PrdReport > ( ) . Where ( x = > x . batch . Contains ( batch ) ) . Select ( x = > x . mo_task_id ) . ToListAsync ( ) ;
ids = await _db . Queryable < PrdReport > ( ) . Where ( x = > x . barcode . Contains ( barcode ) ) . Select ( x = > x . mo_task_id ) . ToListAsync ( ) ;
}
PrdMo prdMo = await _repository . GetSingleAsync ( x = > x . id = = mo_id ) ;
@@ -491,11 +498,11 @@ namespace Tnb.ProductionMgr
{
string mo_task_id = dic . ContainsKey ( "mo_task_id" ) ? dic [ "mo_task_id" ] : "" ;
string mo_task_code = dic . ContainsKey ( "mo_task_code" ) ? dic [ "mo_task_code" ] : "" ;
string batch = dic . ContainsKey ( "batch " ) ? dic [ "batch " ] : "" ;
string barcode = dic . ContainsKey ( "barcode " ) ? dic [ "barcode " ] : "" ;
List < string > ids = new List < string > ( ) ;
if ( ! string . IsNullOrEmpty ( batch ) )
if ( ! string . IsNullOrEmpty ( barcode ) )
{
ids = await _db . Queryable < PrdReport > ( ) . Where ( x = > x . batch . Contains ( batch ) ) . Select ( x = > x . mo_task_id ) . ToListAsync ( ) ;
ids = await _db . Queryable < PrdReport > ( ) . Where ( x = > x . barcode . Contains ( barcode ) ) . Select ( x = > x . mo_task_id ) . ToListAsync ( ) ;
}
PrdMoTask prdMoTask = await _db . Queryable < PrdMoTask > ( ) . SingleAsync ( x = > x . id = = mo_task_id ) ;
@@ -540,18 +547,18 @@ namespace Tnb.ProductionMgr
public async Task < dynamic > PrdMoFromManList ( Dictionary < string , string > dic )
{
string mo_task_id = dic . ContainsKey ( "mo_task_id" ) ? dic [ "mo_task_id" ] : "" ;
string batch = dic . ContainsKey ( "batch " ) ? dic [ "batch " ] : "" ;
string barcode = dic . ContainsKey ( "barcode " ) ? dic [ "barcode " ] : "" ;
List < string > ids = new List < string > ( ) ;
if ( ! string . IsNullOrEmpty ( batch ) )
if ( ! string . IsNullOrEmpty ( barcode ) )
{
ids = await _db . Queryable < PrdReport > ( ) . Where ( x = > x . batch . Contains ( batch ) ) . Select ( x = > x . mo_task_id ) . ToListAsync ( ) ;
ids = await _db . Queryable < PrdReport > ( ) . Where ( x = > x . barcode . Contains ( barcode ) ) . Select ( x = > x . mo_task_id ) . ToListAsync ( ) ;
}
return await _db . Queryable < PrdReport > ( )
. LeftJoin < UserEntity > ( ( a , b ) = > a . create_id = = b . Id )
. WhereIF ( ! string . IsNullOrEmpty ( mo_task_id ) , ( a , b ) = > a . mo_task_id = = mo_task_id )
// .WhereIF(ids!=null && ids.Count>0,(a,b)=>ids.Contains(a.mo_task_id))
. WhereIF ( ! string . IsNullOrEmpty ( batch ) , ( a , b ) = > a . batch . Contains ( batch ) )
. WhereIF ( ! string . IsNullOrEmpty ( barcode ) , ( a , b ) = > a . barcode . Contains ( barcode ) )
. GroupBy ( ( a , b ) = > new { a . create_id , employee_name = b . RealName } )
. Select ( ( a , b ) = > new PrdMoFromManListOutput ( )
{
@@ -575,11 +582,11 @@ namespace Tnb.ProductionMgr
public async Task < dynamic > PrdMoFromEquipList ( Dictionary < string , string > dic )
{
string mo_task_id = dic . ContainsKey ( "mo_task_id" ) ? dic [ "mo_task_id" ] : "" ;
string batch = dic . ContainsKey ( "batch " ) ? dic [ "batch " ] : "" ;
string barcode = dic . ContainsKey ( "barcode " ) ? dic [ "barcode " ] : "" ;
List < string > ids = new List < string > ( ) ;
if ( ! string . IsNullOrEmpty ( batch ) )
if ( ! string . IsNullOrEmpty ( barcode ) )
{
ids = await _db . Queryable < PrdReport > ( ) . Where ( x = > x . batch . Contains ( batch ) ) . Select ( x = > x . mo_task_id ) . ToListAsync ( ) ;
ids = await _db . Queryable < PrdReport > ( ) . Where ( x = > x . barcode . Contains ( barcode ) ) . Select ( x = > x . mo_task_id ) . ToListAsync ( ) ;
}
return await _db . Queryable < PrdMoTask > ( )
@@ -603,11 +610,11 @@ namespace Tnb.ProductionMgr
public async Task < dynamic > PrdMoFromMaterialList ( Dictionary < string , string > dic )
{
string mo_task_id = dic . ContainsKey ( "mo_task_id" ) ? dic [ "mo_task_id" ] : "" ;
string batch = dic . ContainsKey ( "batch " ) ? dic [ "batch " ] : "" ;
string barcode = dic . ContainsKey ( "barcode " ) ? dic [ "barcode " ] : "" ;
List < string > ids = new List < string > ( ) ;
if ( ! string . IsNullOrEmpty ( batch ) )
if ( ! string . IsNullOrEmpty ( barcode ) )
{
ids = await _db . Queryable < PrdReport > ( ) . Where ( x = > x . batch . Contains ( batch ) ) . Select ( x = > x . mo_task_id ) . ToListAsync ( ) ;
ids = await _db . Queryable < PrdReport > ( ) . Where ( x = > x . barcode . Contains ( barcode ) ) . Select ( x = > x . mo_task_id ) . ToListAsync ( ) ;
}
PrdMoTask prdMoTask = await _db . Queryable < PrdMoTask > ( ) . SingleAsync ( x = > x . id = = mo_task_id ) ;
PrdMo prdMo = await _db . Queryable < PrdMo > ( ) . SingleAsync ( x = > x . id = = prdMoTask . mo_id ) ;
@@ -617,7 +624,7 @@ namespace Tnb.ProductionMgr
* 3 物料二维码为精确搜索时 按照先进先出的规则计算投入物料
* 4 组装包装可投入物料组成 1)直接从生产线上流转下来的物料 2)投入的物料
*/
if ( string . IsNullOrEmpty ( batch ) )
if ( string . IsNullOrEmpty ( barcode ) )
{
if ( prdMoTask . schedule_type = = 1 )
{
@@ -645,8 +652,8 @@ namespace Tnb.ProductionMgr
}
else
{
PrdReport prdReport = await _db . Queryable < PrdReport > ( ) . Where ( x = > x . batch = = batch ) . FirstAsync ( ) ;
List < PrdReport > prdReports = await _db . Queryable < PrdReport > ( ) . Where ( x = > x . create_time < = prdReport . create_time & & x . batch ! = batch & & x . mo_task_id = = mo_task_id ) . ToListAsync ( ) ;
PrdReport prdReport = await _db . Queryable < PrdReport > ( ) . Where ( x = > x . barcode = = barcode ) . FirstAsync ( ) ;
List < PrdReport > prdReports = await _db . Queryable < PrdReport > ( ) . Where ( x = > x . create_time < = prdReport . create_time & & x . barcode ! = barcode & & x . mo_task_id = = mo_task_id ) . ToListAsync ( ) ;
int? beforeReportNum = prdReports . Sum ( x = > x . reported_qty ) ;
List < string > prdFeedingIds = new List < string > ( ) ;
if ( prdMoTask . schedule_type = = 1 )
@@ -813,6 +820,7 @@ namespace Tnb.ProductionMgr
material_code = b . code ,
material_name = b . name ,
batch = a . batch ,
supplier_name = "自制"
} ) ;
return await _db . UnionAll ( queryable1 , queryable2 ) . ToListAsync ( ) ;
@@ -825,13 +833,117 @@ namespace Tnb.ProductionMgr
}
}
return null ;
}
#endregion
#region 反 向 工 单 追 溯 相 关
/// <summary>
/// 物料反向追溯物料信息
/// </summary>
/// <param name="dic"></param>
/// <returns></returns>
[HttpPost]
public async Task < dynamic > PrdMoReverseFromMaterialInfo ( Dictionary < string , string > dic )
{
string barcode = dic . ContainsKey ( "barcode" ) ? dic [ "barcode" ] : "" ;
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" ]
} ;
Dictionary < string , object > postData = new Dictionary < string , object > ( )
{
["org_id"] = _userManager . GetUserInfo ( ) . Result . organizeId ,
["barcode"] = new List < string > ( ) { barcode } ,
["currentPage"] = 1 ,
["pageSize"] = int . MaxValue ,
} ;
var sendResult = HttpUtils . RequestPost ( domain + WebApiConst . MES_FETCH_IN_OUT_STOCK_INFO_BY_BAR_CODE , JsonConvert . SerializeObject ( postData ) , header ) ;
Log . Information ( sendResult ) ;
AuthResponse authResponse = JsonConvert . DeserializeObject < AuthResponse > ( sendResult ) ;
if ( authResponse . code ! = 200 )
{
throw Oops . Bah ( authResponse . msg ) ;
}
else
{
PageResult < PrdMoReverseFromMaterialOutput > output = JsonConvert . DeserializeObject < PageResult < PrdMoReverseFromMaterialOutput > > ( authResponse . data . ToString ( ) , new Tnb . Common . Utils . DateTimeJsonConverter ( ) ) ;
if ( output . list ! = null & & output . list . Count > 0 )
{
output . list [ 0 ] . feeding_num = await _db . Queryable < PrdMaterialReceiptD > ( )
. LeftJoin < PrdFeedingD > ( ( a , b ) = > a . id = = b . material_receipt_detail_id )
. Where ( ( a , b ) = > a . barcode = = barcode ) . SumAsync ( ( a , b ) = > b . num ) ;
return output . list [ 0 ] ;
}
}
return Array . Empty < string > ( ) ;
}
/// <summary>
/// 物料反向追溯投料信息
/// </summary>
/// <param name="dic"></param>
/// <returns></returns>
[HttpPost]
public async Task < dynamic > PrdMoReverseFromFeedingInfo ( Dictionary < string , string > dic )
{
string barcode = dic . ContainsKey ( "barcode" ) ? dic [ "barcode" ] : "" ;
List < string > ids = await _db . Queryable < PrdMaterialReceiptD > ( )
. LeftJoin < PrdFeedingD > ( ( a , b ) = > a . id = = b . material_receipt_detail_id )
. LeftJoin < PrdFeedingH > ( ( a , b , c ) = > b . feeding_id = = c . id )
. Where ( a = > a . barcode = = barcode )
. Select ( ( a , b , c ) = > c . mo_task_id ) . ToListAsync ( ) ;
return await _db . Queryable < PrdMoTask > ( )
. LeftJoin < PrdMo > ( ( a , b ) = > a . mo_id = = b . id )
. LeftJoin < BasMaterial > ( ( a , b , c ) = > a . material_id = = c . id )
. Where ( ( a , b , c ) = > ids . Contains ( a . id ) )
. Select ( ( a , b , c ) = > new PrdMoReverseFromFeedingOutput
{
mo_task_id = a . id ,
mo_task_code = a . mo_task_code ,
mo_code = b . mo_code ,
material_code = c . code ,
material_name = c . name ,
material_standard = c . material_standard ,
children = SqlFunc . Subqueryable < PrdFeedingD > ( )
. LeftJoin < PrdFeedingH > ( ( x , y ) = > x . feeding_id = = y . id )
. LeftJoin < UserEntity > ( ( x , y , z ) = > y . create_id = = z . Id )
. LeftJoin < OrganizeEntity > ( ( x , y , z , org ) = > y . station_id = = org . Id )
. LeftJoin < BasProcess > ( ( x , y , z , org , process ) = > y . process_id = = process . id )
. LeftJoin < PrdMaterialReceiptD > ( ( x , y , z , org , process , mp ) = > x . material_receipt_detail_id = = mp . id )
. Where ( ( x , y , z ) = > y . mo_task_id = = a . id ) . ToList ( ( x , y , z , org , process , mp ) = > new PrdMoReverseFromFeedingDetailOutput
{
feeding_detail_id = x . id ,
feeding_time = y . create_time = = null ? "" : y . create_time . Value . ToString ( "yyyy-MM-dd HH:mm:ss" ) ,
num = x . num ,
check_conclusion = mp . check_conclusion ,
feeding_name = z . RealName ,
station_name = org . FullName ,
process_name = process . process_name
} ) ,
} ) . ToListAsync ( ) ;
}
/// <summary>
/// 物料反向追溯查出信息
/// </summary>
/// <param name="dic"></param>
/// <returns></returns>
[HttpPost]
public async Task < dynamic > PrdMoReverseFromOutInfo ( Dictionary < string , string > dic )
{
string feeding_detail_id = dic . ContainsKey ( "feeding_detail_id" ) ? dic [ "feeding_detail_id" ] : "" ;
return null ;
}
#endregion
}
}