焊接材料管理修改
This commit is contained in:
@@ -0,0 +1,477 @@
|
||||
using EmitMapper;
|
||||
using FineUIPro;
|
||||
using Microsoft.Office.Interop.Word;
|
||||
using MiniExcelLibs;
|
||||
using Model;
|
||||
using NPOI.Util;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
|
||||
namespace BLL
|
||||
{
|
||||
|
||||
public static class TwInOutplanmasterService
|
||||
{
|
||||
|
||||
#region 获取列表
|
||||
/// <summary>
|
||||
/// 记录数
|
||||
/// </summary>
|
||||
public static int Count
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public static IQueryable<Model.Tw_InOutMasterOutput> GetModle(Model.Tw_InOutMasterOutput table)
|
||||
{
|
||||
var q = from x in Funs.DB.Tw_InOutPlanMaster
|
||||
join y in Funs.DB.HJGL_WeldTask on x.WeldTaskId equals y.WeldTaskId into yy
|
||||
from y in yy.DefaultIfEmpty()
|
||||
join person in Funs.DB.Person_Persons on x.CreateMan equals person.PersonId into persons
|
||||
from person in persons.DefaultIfEmpty()
|
||||
join unit in Funs.DB.Base_Unit on x.ReqUnitId equals unit.UnitId into units
|
||||
from unit in units.DefaultIfEmpty()
|
||||
where
|
||||
(string.IsNullOrEmpty(table.Id) || x.Id.Contains(table.Id)) &&
|
||||
(string.IsNullOrEmpty(table.ProjectId) || x.ProjectId.Contains(table.ProjectId)) &&
|
||||
(string.IsNullOrEmpty(table.CusBillCode) || x.CusBillCode.Contains(table.CusBillCode)) &&
|
||||
(string.IsNullOrEmpty(table.WarehouseCode) || x.WarehouseCode.Contains(table.WarehouseCode)) &&
|
||||
(string.IsNullOrEmpty(table.CreateMan) || x.CreateMan.Contains(table.CreateMan)) &&
|
||||
(string.IsNullOrEmpty(table.OutputMasterId) || x.OutputMasterId.Contains(table.OutputMasterId)) &&
|
||||
(string.IsNullOrEmpty(table.ReqUnitId) || x.ReqUnitId.Contains(table.ReqUnitId)) &&
|
||||
(string.IsNullOrEmpty(table.UnitWorkId) || x.WeldTaskId.Contains(table.UnitWorkId))&&
|
||||
(table.InOutType == null || x.InOutType == table.InOutType) &&
|
||||
(table.TypeInt == null || x.TypeInt == table.TypeInt) &&
|
||||
(table.Category == null || x.Category == table.Category) &&
|
||||
(table.State == null || x.State == table.State)
|
||||
select new Model.Tw_InOutMasterOutput
|
||||
{
|
||||
Id = x.Id,
|
||||
ProjectId = x.ProjectId,
|
||||
CusBillCode = x.CusBillCode,
|
||||
WarehouseCode = x.WarehouseCode,
|
||||
Source = x.Source,
|
||||
InOutType = x.InOutType,
|
||||
TypeInt = x.TypeInt,
|
||||
State = x.State,
|
||||
Category = x.Category,
|
||||
CreateMan = x.CreateMan,
|
||||
CreateManName = person.PersonName,
|
||||
CreateDate = x.CreateDate,
|
||||
OutputMasterId = x.OutputMasterId,
|
||||
WeldTaskId = x.WeldTaskId,
|
||||
ReqUnitId = x.ReqUnitId,
|
||||
ReqUnitName = unit.UnitName,
|
||||
UnitWorkId = y.UnitWorkId,
|
||||
WeldTaskCode = y.TaskCode
|
||||
}
|
||||
;
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取分页列表
|
||||
/// </summary>
|
||||
/// <param name="table"></param>
|
||||
/// <param name="grid1"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable GetListData(Model.Tw_InOutMasterOutput table, Grid grid1)
|
||||
{
|
||||
|
||||
var q = GetModle(table);
|
||||
Count = q.Count();
|
||||
if (Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var result = q.Skip(grid1.PageSize * grid1.PageIndex).Take(grid1.PageSize).ToList();
|
||||
// q = SortConditionHelper.SortingAndPaging(q, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize);
|
||||
return from x in result
|
||||
select new Model.Tw_InOutMasterOutput
|
||||
{
|
||||
Id = x.Id,
|
||||
ProjectId = x.ProjectId,
|
||||
CusBillCode = x.CusBillCode,
|
||||
WarehouseCode = x.WarehouseCode,
|
||||
Source = x.Source,
|
||||
InOutType = x.InOutType,
|
||||
TypeInt = x.TypeInt,
|
||||
Category = x.Category,
|
||||
State = x.State,
|
||||
CreateMan = x.CreateMan,
|
||||
CreateManName = x.CreateManName,
|
||||
CreateDate = x.CreateDate,
|
||||
OutputMasterId = x.OutputMasterId,
|
||||
WeldTaskId = x.WeldTaskId,
|
||||
ReqUnitId = x.ReqUnitId,
|
||||
ReqUnitName = x.ReqUnitName,
|
||||
UnitWorkId = x.UnitWorkId,
|
||||
WeldTaskCode= x.WeldTaskId!=null? x.WeldTaskId.Contains('|')? Funs.DB.HJGL_WeldTask.FirstOrDefault(e => e.UnitWorkId == x.WeldTaskId.Split('|')[0].ToString() && e.UnitId == x.WeldTaskId.Split('|')[1].ToString() && e.TaskDate.Value.Date == Convert.ToDateTime(x.WeldTaskId.Split('|')[2].ToString()).Date)?.TaskCode :"":"",
|
||||
CategoryString = TwConst.CategoryMap.FirstOrDefault(y => y.Value == x.Category).Key,
|
||||
TypeString = TwConst.TypeIntMap.FirstOrDefault(y => y.Value == x.TypeInt).Key,
|
||||
StateString = TwConst.StateMap.FirstOrDefault(y => y.Value == x.State).Key
|
||||
};
|
||||
}
|
||||
|
||||
public static List<Tw_InOutMasterOutput> GetListData(Model.Tw_InOutMasterOutput table)
|
||||
{
|
||||
|
||||
var q = GetModle(table);
|
||||
Count = q.Count();
|
||||
if (Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var result = q.ToList();
|
||||
// q = SortConditionHelper.SortingAndPaging(q, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize);
|
||||
return (from x in result
|
||||
select new Model.Tw_InOutMasterOutput
|
||||
{
|
||||
Id = x.Id,
|
||||
ProjectId = x.ProjectId,
|
||||
CusBillCode = x.CusBillCode,
|
||||
WarehouseCode = x.WarehouseCode,
|
||||
Source = x.Source,
|
||||
InOutType = x.InOutType,
|
||||
TypeInt = x.TypeInt,
|
||||
Category = x.Category,
|
||||
State = x.State,
|
||||
CreateMan = x.CreateMan,
|
||||
CreateManName = x.CreateManName,
|
||||
CreateDate = x.CreateDate,
|
||||
OutputMasterId = x.OutputMasterId,
|
||||
WeldTaskId = x.WeldTaskId,
|
||||
ReqUnitId = x.ReqUnitId,
|
||||
ReqUnitName = x.ReqUnitName,
|
||||
UnitWorkId = x.UnitWorkId,
|
||||
WeldTaskCode = x.WeldTaskId != null ? x.WeldTaskId.Contains('|') ? Funs.DB.HJGL_WeldTask.FirstOrDefault(e => e.UnitWorkId == x.WeldTaskId.Split('|')[0].ToString() && e.UnitId == x.WeldTaskId.Split('|')[1].ToString() && e.TaskDate.Value.Date == Convert.ToDateTime(x.WeldTaskId.Split('|')[2].ToString()).Date)?.TaskCode : "" : "",
|
||||
CategoryString = TwConst.CategoryMap.FirstOrDefault(y => y.Value == x.Category).Key,
|
||||
TypeString = TwConst.TypeIntMap.FirstOrDefault(y => y.Value == x.TypeInt).Key,
|
||||
StateString = TwConst.StateMap.FirstOrDefault(y => y.Value == x.State).Key
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 导入数据
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="projectid"></param>
|
||||
/// <param name="creatUserId"></param>
|
||||
/// <returns></returns>
|
||||
public static ResponeData ImportData(string path, string projectid, string creatUserId)
|
||||
{
|
||||
var responeData = new ResponeData();
|
||||
List<Tw_InputDataIn> temeplateDtoIns;
|
||||
try
|
||||
{
|
||||
temeplateDtoIns = MiniExcel.Query<Tw_InputDataIn>(path, startCell: "A1").ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
responeData.code = 0;
|
||||
responeData.message = "模板错误:" + ex.ToString();
|
||||
return responeData;
|
||||
}
|
||||
|
||||
#region 数据校验
|
||||
if (temeplateDtoIns.Count == 0)
|
||||
{
|
||||
responeData.code = 0;
|
||||
responeData.message = "导入数据为空!";
|
||||
return responeData;
|
||||
}
|
||||
var queryAll = new Tw_InOutMasterOutput()
|
||||
{
|
||||
ProjectId = projectid
|
||||
};
|
||||
var warehouseCodeList = temeplateDtoIns.Select(x => x.WarehouseCode).Distinct().ToList(); //获取导入文件的仓库编号
|
||||
string errorWarehouseCode = "";
|
||||
foreach (var item in warehouseCodeList)
|
||||
{
|
||||
if (!DropListService.HJGL_WarehouseCode().Select(x=>x.Value== item).Any())
|
||||
{
|
||||
errorWarehouseCode+=item+",";
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(errorWarehouseCode))
|
||||
{
|
||||
if (temeplateDtoIns.Count == 0)
|
||||
{
|
||||
responeData.code = 0;
|
||||
responeData.message = errorWarehouseCode+"仓库不存在!";
|
||||
return responeData;
|
||||
}
|
||||
}
|
||||
var materialCodeList = temeplateDtoIns.Select(x => x.MaterialCode).Distinct().ToList(); //获取导入文件的材料编码
|
||||
var IsExitMaterialCode=
|
||||
from x in Funs.DB.HJGL_MaterialCodeLib
|
||||
where materialCodeList.Contains(x.MaterialCode)
|
||||
select x.MaterialCode;
|
||||
if (IsExitMaterialCode.Count() < materialCodeList.Count)
|
||||
{
|
||||
var errorMaterialCode = materialCodeList.Except(IsExitMaterialCode.ToList());
|
||||
if (errorMaterialCode.Count() > 0)
|
||||
{
|
||||
responeData.code = 0;
|
||||
responeData.message = string.Join(",", errorMaterialCode) + "材料不存在!";
|
||||
return responeData;
|
||||
}
|
||||
}
|
||||
|
||||
var queryAllresult = GetModle(queryAll).Select(x => x.CusBillCode).Distinct().ToList();//查询所有的编号
|
||||
var CusBillCodeList = temeplateDtoIns.Select(x => x.CusBillCode).Distinct().ToList(); //获取导入文件的编号
|
||||
var IsContain = CusBillCodeList.Intersect(queryAllresult).ToList(); //判断导入文件中是有已存在的编号
|
||||
if (IsContain.Count>0)
|
||||
{
|
||||
responeData.code = 0;
|
||||
responeData.message = string.Join(",", IsContain)+ "编号已存在!";
|
||||
return responeData;
|
||||
}
|
||||
#endregion
|
||||
//根据申请单编号分组插入数据
|
||||
foreach (var CusBillCode in CusBillCodeList)
|
||||
{
|
||||
var CusBillCodeDtoIns = temeplateDtoIns.Where(x => x.CusBillCode == CusBillCode).ToList();
|
||||
|
||||
var mapper =
|
||||
ObjectMapperManager.DefaultInstance.GetMapper<List<Tw_InputDataIn>, List<Model.Tw_InOutPlanMaster>>();
|
||||
var mapperDetail =
|
||||
ObjectMapperManager.DefaultInstance.GetMapper<List<Tw_InputDataIn>, List<Tw_InOutPlanDetail>>();
|
||||
//通过映射实体赋值
|
||||
var twInOutPlanMaster = mapper.Map(CusBillCodeDtoIns).FirstOrDefault();
|
||||
var twInOutPlanDetails = mapperDetail.Map(CusBillCodeDtoIns.Where(x => !string.IsNullOrEmpty(x.MaterialCode) && !string.IsNullOrEmpty(x.PlanNum)).ToList());
|
||||
|
||||
twInOutPlanMaster.Id = SQLHelper.GetNewID();
|
||||
twInOutPlanMaster.InOutType= (int)TwConst.InOutType.入库;
|
||||
twInOutPlanMaster.State = (int)TwConst.State.待审核;
|
||||
twInOutPlanMaster.TypeInt= (int)TwConst.TypeInt.采购入库;
|
||||
twInOutPlanMaster.Category= (int)TwConst.Category.全部;
|
||||
twInOutPlanMaster.ProjectId = projectid;
|
||||
twInOutPlanMaster.CreateMan = creatUserId;
|
||||
twInOutPlanMaster.CreateDate = DateTime.Now;
|
||||
Add(twInOutPlanMaster);
|
||||
TwInOutplandetailService.AddList(twInOutPlanDetails, twInOutPlanMaster.Id); //插入入库明细
|
||||
|
||||
}
|
||||
return responeData;
|
||||
|
||||
}
|
||||
|
||||
public static Model.Tw_InOutPlanMaster GetById(string Id)
|
||||
{
|
||||
return Funs.DB.Tw_InOutPlanMaster.FirstOrDefault(x => x.Id == Id);
|
||||
}
|
||||
public static void Add(Model.Tw_InOutPlanMaster newtable)
|
||||
{
|
||||
|
||||
Model.Tw_InOutPlanMaster table = new Model.Tw_InOutPlanMaster
|
||||
{
|
||||
Id = newtable.Id,
|
||||
ProjectId = newtable.ProjectId,
|
||||
CusBillCode = newtable.CusBillCode,
|
||||
WarehouseCode = newtable.WarehouseCode,
|
||||
Source = newtable.Source,
|
||||
Category = newtable.Category,
|
||||
InOutType = newtable.InOutType,
|
||||
TypeInt = newtable.TypeInt,
|
||||
State = newtable.State,
|
||||
CreateMan = newtable.CreateMan,
|
||||
CreateDate = newtable.CreateDate,
|
||||
OutputMasterId = newtable.OutputMasterId,
|
||||
WeldTaskId = newtable.WeldTaskId,
|
||||
ReqUnitId = newtable.ReqUnitId,
|
||||
};
|
||||
Funs.DB.Tw_InOutPlanMaster.InsertOnSubmit(table);
|
||||
Funs.DB.SubmitChanges();
|
||||
}
|
||||
public static void Update(Model.Tw_InOutPlanMaster newtable)
|
||||
{
|
||||
|
||||
Model.Tw_InOutPlanMaster table = Funs.DB.Tw_InOutPlanMaster.FirstOrDefault(x => x.Id == newtable.Id);
|
||||
if (table != null)
|
||||
{
|
||||
table.Id = newtable.Id;
|
||||
table.ProjectId = newtable.ProjectId;
|
||||
table.CusBillCode = newtable.CusBillCode;
|
||||
table.WarehouseCode = newtable.WarehouseCode;
|
||||
table.Category = newtable.Category;
|
||||
table.Source = newtable.Source;
|
||||
table.InOutType = newtable.InOutType;
|
||||
table.TypeInt = newtable.TypeInt;
|
||||
table.State = newtable.State;
|
||||
table.CreateMan = newtable.CreateMan;
|
||||
table.CreateDate = newtable.CreateDate;
|
||||
table.OutputMasterId = newtable.OutputMasterId;
|
||||
table.WeldTaskId = newtable.WeldTaskId;
|
||||
table.ReqUnitId = newtable.ReqUnitId;
|
||||
Funs.DB.SubmitChanges();
|
||||
}
|
||||
|
||||
}
|
||||
public static void DeleteById(string Id)
|
||||
{
|
||||
|
||||
Model.Tw_InOutPlanMaster table = Funs.DB.Tw_InOutPlanMaster.FirstOrDefault(x => x.Id == Id);
|
||||
if (table != null)
|
||||
{
|
||||
TwInOutplandetailService.DeleteByInOutPlanMasterId(table.Id);
|
||||
|
||||
Funs.DB.Tw_InOutPlanMaster.DeleteOnSubmit(table);
|
||||
Funs.DB.SubmitChanges();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据出库单生成计划单
|
||||
/// </summary>
|
||||
/// <param name="outputMasterId"></param>
|
||||
/// <param name="typeInt"></param>
|
||||
/// <returns></returns>
|
||||
public static string GenPlanMasterByOutputMasterId(string outputMasterId,TwConst.TypeInt typeInt)
|
||||
{
|
||||
string message = "";
|
||||
|
||||
#region 数据校验
|
||||
|
||||
//获取出库单
|
||||
var outMasterQuery = new Tw_InOutMasterOutput();
|
||||
outMasterQuery.Id = outputMasterId;
|
||||
var outMaster = TwOutputmasterService.GetListData(outMasterQuery) .FirstOrDefault() ;
|
||||
if (outMaster == null || outMaster.State != (int)TwConst.State.已完成)
|
||||
{
|
||||
message = "出库单状态错误,无法生成计划单!";
|
||||
return message;
|
||||
}
|
||||
//判断是否已经生成过计划单
|
||||
var queryIsExitInMaster = new Tw_InOutMasterOutput();
|
||||
queryIsExitInMaster.OutputMasterId = outMaster.Id;
|
||||
queryIsExitInMaster.TypeInt= (int)typeInt;
|
||||
var IsExitInMaster = GetModle(queryIsExitInMaster).FirstOrDefault();
|
||||
if (IsExitInMaster != null)
|
||||
{
|
||||
message = "该出库单已生成过计划单";
|
||||
return message;
|
||||
}
|
||||
//明细校验
|
||||
Tw_InOutDetailOutput query = new Tw_InOutDetailOutput();
|
||||
query.OutputMasterId = outputMasterId;
|
||||
var details = TwOutputdetailService.GetByModle(query).ToList();
|
||||
switch (typeInt)
|
||||
{
|
||||
case TwConst.TypeInt.补料出库:
|
||||
details = details.Where(x => x.PlanNum > x.ActNum).ToList();
|
||||
foreach (var item in details)
|
||||
{
|
||||
item.PlanNum = (item.PlanNum - item.ActNum);
|
||||
}
|
||||
if (details.Count==0)
|
||||
{
|
||||
message = "该出库单无需补料";
|
||||
return message;
|
||||
}
|
||||
break;
|
||||
case TwConst.TypeInt.退料入库:
|
||||
details = details.Where(x => x.PlanNum < x.ActNum).ToList();
|
||||
foreach (var item in details)
|
||||
{
|
||||
item.PlanNum = (item.ActNum - item.PlanNum);
|
||||
}
|
||||
if (details.Count == 0)
|
||||
{
|
||||
message = "该出库单无需退料";
|
||||
return message;
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endregion
|
||||
//生成计划单
|
||||
var planMasterModel = new Model.Tw_InOutMasterOutput()
|
||||
{
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
OutputMasterId = outMaster.Id,
|
||||
ProjectId = outMaster.ProjectId,
|
||||
WarehouseCode = outMaster.WarehouseCode,
|
||||
Source = 2,
|
||||
Category = outMaster.Category,
|
||||
TypeInt = outMaster.TypeInt,
|
||||
State = (int)TwConst.State.待审核,
|
||||
CreateMan = outMaster.CreateMan,
|
||||
CreateDate = DateTime.Now,
|
||||
ReqUnitId = outMaster.ReqUnitId,
|
||||
WeldTaskId = GetById(outMaster.InOutPlanMasterId).WeldTaskId
|
||||
|
||||
};
|
||||
switch (typeInt)
|
||||
{
|
||||
case TwConst.TypeInt.补料出库:
|
||||
planMasterModel.CusBillCode = GetCusBillCodeByTaskCode(outMaster.WeldTaskCode,TwConst.TypeInt.补料出库,(BLL.TwConst.Category)planMasterModel.Category);
|
||||
planMasterModel.TypeInt= (int)TwConst.TypeInt.补料出库;
|
||||
planMasterModel.InOutType= (int)TwConst.InOutType.出库;
|
||||
break;
|
||||
case TwConst.TypeInt.退料入库:
|
||||
planMasterModel.CusBillCode = GetCusBillCodeByTaskCode(outMaster.WeldTaskCode, TwConst.TypeInt.退料入库, (BLL.TwConst.Category)planMasterModel.Category);
|
||||
planMasterModel.TypeInt = (int)TwConst.TypeInt.退料入库;
|
||||
planMasterModel.InOutType = (int)TwConst.InOutType.入库;
|
||||
;
|
||||
break;
|
||||
}
|
||||
Add(planMasterModel);
|
||||
//生成明细
|
||||
TwInOutplandetailService.AddList(details, planMasterModel.Id);
|
||||
return message;
|
||||
}
|
||||
|
||||
public static string GetCusBillCodeByTaskCode(string taskCode,TwConst.TypeInt typeInt,TwConst.Category category )
|
||||
{
|
||||
string cusBillCode = "";
|
||||
switch (typeInt )
|
||||
{
|
||||
case TwConst.TypeInt.领料出库:
|
||||
if (category== TwConst.Category.管段)
|
||||
{
|
||||
cusBillCode = taskCode + "-AP-P01";
|
||||
}
|
||||
else if (category == TwConst.Category.管件)
|
||||
{
|
||||
cusBillCode = taskCode + "-AP-PF01";
|
||||
}
|
||||
|
||||
break;
|
||||
case TwConst.TypeInt.补料出库:
|
||||
if (category == TwConst.Category.管段)
|
||||
{
|
||||
cusBillCode = taskCode + "-GI-P01-AP01";
|
||||
}
|
||||
else if (category == TwConst.Category.管件)
|
||||
{
|
||||
cusBillCode = taskCode + "-GI-PF01-AP01";
|
||||
}
|
||||
|
||||
break;
|
||||
case TwConst.TypeInt.退料入库:
|
||||
if (category == TwConst.Category.管段)
|
||||
{
|
||||
cusBillCode = taskCode + "-GI-P01-RE01";
|
||||
}
|
||||
else if (category == TwConst.Category.管件)
|
||||
{
|
||||
cusBillCode = taskCode + "-GI-PF01-RE01";
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
return cusBillCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user