天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

741 lines
27 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.BLL;
using QMAPP.Entity;
using QMAPP.FJC.Entity.ProduceManage;
using QMFrameWork.Data;
using QMFrameWork.Log;
using QMAPP.FJC.Entity;
using QMAPP.FJC.Entity.Operation;
using QMAPP.FJC.DAL.ProduceManage;
using QMAPP.FJC.BLL.Dict;
using QMAPP.FJC.DAL.Operation;
using System.Data;
using QMAPP.MD.BLL;
using QMAPP.MD.Entity;
using Resource = QMAPP.FJC.Entity.Resource;
namespace QMAPP.FJC.BLL.ProduceManage
{
public class ScrapRecordBLL : BaseBLL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public MendRecorder Get(MendRecorder model)
{
try
{
return new ScrapRecordDAL().Get(model);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public MendRecorder GetMendRecorderInfo(MendRecorder model)
{
try
{
MendRecorder entity = new MendRecorder();
entity = new ScrapRecordDAL().GetMendRecorderInfo(model);
entity.reasonList = new MenderReasonDAL().GetList(new MenderReason() { PPID = entity.PID });
return entity;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(MendRecorder condition, DataPage page)
{
try
{
DataPage dataPage = new ScrapRecordDAL().GetList(condition, page);
#region 转换零件类别、工序类别、返修结果、返修方式、返修原因显示类型
List<MendRecorder> mendRecorderList = dataPage.Result as List<MendRecorder>;
DictManageBLL dictProductTypeBll = new DictManageBLL(DictKind.PRODUCTTYPE);
DictManageBLL dictProcessTypeBll = new DictManageBLL(DictKind.PROCESSTYPE);
DictManageBLL dictMendResultBll = new DictManageBLL(DictKind.MENDRESULT);
DictManageBLL dictMendTypeBll = new DictManageBLL(DictKind.MENDTYPE);
DictManageBLL dictMendReasonBll = new DictManageBLL(DictKind.MENDREASON);
DictManageBLL dictRegisterStatusBll = new DictManageBLL(DictKind.REGISTERSTATUS);
foreach (MendRecorder m in mendRecorderList)
{
//零件类别
m.PRODUCTTYPETXT = dictProductTypeBll.GetDictValue(m.PRODUCTTYPE);
//工序类别
m.CURRENTPROCESSTXT = dictProcessTypeBll.GetDictValue(m.CURRENTPROCESS);
//返修结果
m.MENDRESULTTXT = dictMendResultBll.GetDictValue(m.MENDRESULT);
//返修方式
m.MENDTYPETXT = dictMendTypeBll.GetDictValue(m.MENDTYPE);
//返修原因
m.MENDREASONTXT = dictMendTypeBll.GetDictValue(m.MENDREASON);
//登记状态
m.REGISTERSTATUSTXT = dictRegisterStatusBll.GetDictValue(m.REGISTERSTATUS);
}
#endregion
return dataPage;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "返修记录-获取列表!"
});
throw ex;
}
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataResult<DataPage> GetLists(MendRecorder condition, DataPage page)
{
DataResult<DataPage> result = new DataResult<DataPage>();
try
{
DataPage dataPage = new ScrapRecordDAL().GetList(condition, page);
#region 转换零件类别、工序类别、返修结果、返修方式、返修原因显示类型
List<MendRecorder> mendRecorderList = dataPage.Result as List<MendRecorder>;
DictManageBLL dictProductTypeBll = new DictManageBLL(DictKind.PRODUCTTYPE);
DictManageBLL dictProcessTypeBll = new DictManageBLL(DictKind.PROCESSTYPE);
DictManageBLL dictMendResultBll = new DictManageBLL(DictKind.MENDRESULT);
DictManageBLL dictMendTypeBll = new DictManageBLL(DictKind.MENDTYPE);
DictManageBLL dictMendReasonBll = new DictManageBLL(DictKind.MENDREASON);
DictManageBLL dictMendStatusSBll = new DictManageBLL(DictKind.REGISTERSTATUS);
//转换零件号和类型
//var MaterialList = new MaterialBLL().GetAllList(new Material());
//var MaterialClassList = new MaterialBLL().GetAllMaterialClassList(new MaterialClass());
var erpCodes = new MendRecorderBLL().GetMFGCODES("");
foreach (MendRecorder m in mendRecorderList)
{
//零件类别
m.PRODUCTTYPE = dictProductTypeBll.GetDictValue(m.PRODUCTTYPE);
//工序类别
m.CURRENTPROCESS = dictProcessTypeBll.GetDictValue(m.CURRENTPROCESS);
//返修结果
m.MENDRESULT = dictMendResultBll.GetDictValue(m.MENDRESULT);
//返修方式
m.MENDTYPE = dictMendTypeBll.GetDictValue(m.MENDTYPE);
//返修原因
m.MENDREASON = dictMendReasonBll.GetDictValue(m.MENDREASON);
//返修状态
m.REGISTERSTATUS = dictMendStatusSBll.GetDictValue(m.REGISTERSTATUS);
//零件
m.OUTSOURCE = m.OUTSOURCE == "1" ? "采购件" : "生产件";
////零件
//var material = MaterialList.FirstOrDefault(x => x.MATERIAL_CODE == m.MATERIAL_CODE);
//if (material != null)
// m.MATERIAL_NAME = material.MATERIAL_NAME;
////零件类型
//var materialClass = MaterialClassList.FirstOrDefault(x => x.MATERIAL_TYPE_CODE == m.MATERIAL_TYPE_CODE);
//if (materialClass != null)
// m.MATERIAL_TYPE_NAME = materialClass.MATERIAL_TYPE_NAME;
//erp
var erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_MFGCODETYPE);
if (erpcode != null)
m.ERP_MFGCODETYPE = erpcode.ERP_NAME;
erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_CAR);
if (erpcode != null)
m.ERP_CAR = erpcode.ERP_NAME;
erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_WORKLINE);
if (erpcode != null)
m.ERP_WORKLINE = erpcode.ERP_NAME;
erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_SHIFT);
if (erpcode != null)
m.ERP_SHIFT = erpcode.ERP_NAME;
erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_WORKCELL);
if (erpcode != null)
m.ERP_WORKCELL = erpcode.ERP_NAME;
erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_DEFECTTO);
if (erpcode != null)
m.ERP_DEFECTTO = erpcode.ERP_NAME;
erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_PRODUCTTYPE);
if (erpcode != null)
m.ERP_PRODUCTTYPE = erpcode.ERP_NAME;
erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_DEFECTCODE);
if (erpcode != null)
m.ERP_DEFECTCODE = erpcode.ERP_NAME;
}
#endregion
result.Result = dataPage;
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "返修记录-获取列表!"
});
throw ex;
}
}
#endregion
#region 信息是否重复
/// <summary>
/// 判断名称是否存在
/// </summary>
/// <param name="info"></param>
/// <returns>true:已存在;fasel:不存在。</returns>
public bool ExistsMendRecorder(MendRecorder model)
{
try
{
return new ScrapRecordDAL().ExistsMendRecorder(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int Insert(MendRecorder model)
{
try
{
//基本信息
model.PID = Guid.NewGuid().ToString();
model.CREATEUSER = this.LoginUser.UserID;
model.CREATEDATE = DateTime.Now;
model.UPDATEUSER = model.CREATEUSER;
model.UPDATEDATE = model.CREATEDATE;
ScrapRecordDAL cmdDAL = new ScrapRecordDAL();
if (ExistsMendRecorder(model) == true)
return -1;
return new ScrapRecordDAL().Insert(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public int Update(MendRecorder model)
{
try
{
//if (ExistsMendRecorder(Model) == true)
//return -1;
//基本信息
model.UPDATEUSER = this.LoginUser.UserID;
return new ScrapRecordDAL().Update(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 删除
/// <summary>
/// 删除信息
/// </summary>
/// <param name=""></param>
/// <returns>删除个数</returns>
public int Delete(string strs)
{
int count = 0;
string[] list = strs.Split(":".ToCharArray());
try
{
foreach (string str in list)
{
count += this.DeleteMendRecorder(new MendRecorder { PID = str });
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 删除信息
/// </summary>
/// <param name="">信息</param>
/// <returns>删除个数</returns>
public int DeleteMendRecorder(MendRecorder model)
{
int count = 0;
try
{
count = new ScrapRecordDAL().Delete(model);
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 导出数据
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="user">查询条件</param>
/// <returns>数据</returns>
public DataResult<DataTable> GetExportData(MendRecorder model)
{
DataResult<DataTable> result = new DataResult<DataTable>();
try
{
DataTable dt = new ScrapRecordDAL().GetExportData(model);
#region 转换零件类别、工序类别、返修结果、返修方式、返修原因显示类型
DictManageBLL dictProductTypeBll = new DictManageBLL(DictKind.PRODUCTTYPE);
DictManageBLL dictProcessTypeBll = new DictManageBLL(DictKind.PROCESSTYPE);
DictManageBLL dictMendResultBll = new DictManageBLL(DictKind.MENDRESULT);
DictManageBLL dictMendTypeBll = new DictManageBLL(DictKind.MENDTYPE);
DictManageBLL dictMendReasonBll = new DictManageBLL(DictKind.MENDREASON);
DictManageBLL dictMendStatusSBll = new DictManageBLL(DictKind.REGISTERSTATUS);
foreach (DataRow item in dt.Rows)
{
//零件类别
item["PRODUCTTYPE"] = dictProductTypeBll.GetDictValue(item["PRODUCTTYPE"].ToString());
//工序类别
item["CURRENTPROCESS"] = dictProcessTypeBll.GetDictValue(item["CURRENTPROCESS"].ToString());
//返修结果
item["MENDRESULT"] = dictMendResultBll.GetDictValue(item["MENDRESULT"].ToString());
//返修方式
item["MENDTYPE"] = dictMendTypeBll.GetDictValue(item["MENDTYPE"].ToString());
//返修原因
item["MENDREASON"] = dictMendReasonBll.GetDictValue(item["MENDREASON"].ToString());
//返修状态
item["REGISTERSTATUS"] = dictMendStatusSBll.GetDictValue(item["REGISTERSTATUS"].ToString());
//ERP汇总
//item["ERPS"] = item["ERP_DEFECTCODE"];
}
#endregion
result.Result = dt;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "返修记录-导出数据!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 返修(工控机)
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public DataResult<int> InsertMendRecorder(MendRecorder model)
{
DataResult<int> result = new DataResult<int>();
try
{
//基本信息
model.PID = Guid.NewGuid().ToString();
model.CREATEUSER = this.LoginUser.UserID;
model.CREATEDATE = DateTime.Now;
model.UPDATEUSER = model.CREATEUSER;
model.UPDATEDATE = model.CREATEDATE;
if (ExistsMendRecorder(model) == true)
{
result.IsSuccess = false;
result.Msg = Resource.IsHaving;
}
else
{
result.Result = new ScrapRecordDAL().Insert(model);
if (result.Result > 0)
{
result.IsSuccess = true;
result.Msg = Resource.SaveMessge;
}
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "返修记录逻辑层-插入信息!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
public DataResult<int> InsertMendRecordItem(Product product, List<DefectType> defectTypeList)
{
DataResult<int> result = new DataResult<int>();
List<MenderReason> reasonList = new List<MenderReason>();
try
{
MendRecorder model = new MendRecorder();
//基本信息
model.PID = Guid.NewGuid().ToString();
model.PPID = product.PID;
model.PRODUCTCODE = product.PRODUCTCODE;
model.PRODUCTTYPE = product.PRODUCTTYPE;
model.CURRENTPROCESS = product.CURRENTPROCESS;
model.PRODUCELINE = product.PRODUCELINE;
model.MENDRESULT = product.STATUS;
model.CREATEUSER = this.LoginUser.UserID;
model.CREATEDATE = DateTime.Now;
model.UPDATEUSER = model.CREATEUSER;
model.UPDATEDATE = model.CREATEDATE;
model.PRODUCESHIFTTCODE = product.PRODUCESHIFTTCODE;
foreach (var defect in defectTypeList)
{
reasonList.Add(new MenderReason()
{
PID = Guid.NewGuid().ToString(),
PPID = model.PID,
DEFECTKEY = defect.DEFECTKEY,
DEFECTVALUE = defect.DEFECTVALUE,
POSITION = defect.POSITION,
CREATEUSER = this.LoginUser.UserID,
CREATEDATE = DateTime.Now,
UPDATEUSER = model.CREATEUSER,
UPDATEDATE = model.CREATEDATE
});
}
MainDAL maindal = new MainDAL();
ProductDAL productDal = new ProductDAL();
Main main = new Main();
Product entity = new Product();
//本体
if (product.PRODUCTTYPE == EnumGeter.ProductType.benti.GetHashCode().ToString())
{
main = maindal.Get(new Main() { PID = product.PID });
main.STATUS = product.STATUS;
MainOperationDAL modal = new MainOperationDAL();
MainOperation moEntity = modal.GetMainOperation(new MainOperation { PDID = main.PID, PROCESSTYPE = EnumGeter.ProcessType.jiaozhu.GetHashCode().ToString() });
if (moEntity != null && string.IsNullOrEmpty(moEntity.PID) == false)
{
model.MOLDNUMBER = moEntity.MOLDNUMBER;
}
}
else
{
//零部件
entity = productDal.Get(new Product() { PID = product.PID });
entity.STATUS = product.STATUS;
model.MOLDNUMBER = "1";
}
ScrapRecordDAL menderDal = new ScrapRecordDAL();
MenderReasonDAL reasonDal = new MenderReasonDAL();
//ScrapRecordDAL
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.OpenTs();
menderDal.BaseSession = session;
reasonDal.BaseSession = session;
menderDal.Insert(model);
if (product.PRODUCTTYPE == EnumGeter.ProductType.benti.GetHashCode().ToString())
{
maindal.BaseSession = session;
maindal.Update(main);
}
else
{
productDal.BaseSession = session;
productDal.Update(entity);
}
foreach (var r in reasonList)
{
reasonDal.Insert(r);
}
session.CommitTs();
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "返修记录逻辑层-插入信息!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public DataResult<int> UpdateMendRecorder(MendRecorder model)
{
DataResult<int> result = new DataResult<int>();
try
{
//基本信息
model.UPDATEUSER = this.LoginUser.UserID;
result.Result = new ScrapRecordDAL().Update(model);
if (result.Result > 0)
{
result.IsSuccess = true;
result.Msg = Resource.SaveMessge;
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "返修记录逻辑层-更新信息!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#endregion
#region 校验产品条码号是否存在
/// <summary>
///
/// </summary>
/// <param name="productCode"></param>
/// <returns></returns>
public DataResult<Product> CheckProductCode(string productCode)
{
DataResult<Product> result = new DataResult<Product>();
result.IsSuccess = true;
DictManageBLL dicStatus = new DictManageBLL(DictKind.STATUS);
DictManageBLL dicProcess = new DictManageBLL(DictKind.PROCESSTYPE);
DictManageBLL dicProductType = new DictManageBLL(DictKind.PRODUCTTYPE);
ProductDAL productDal = new ProductDAL();
Product product = productDal.GetProductInfo(new Product() { PRODUCTCODE = productCode });
//条码不存在
//提示
if (product == null)
{
result.IsSuccess = false;
result.Msg = "该条码不存在!";
result.Result = product;
return result;
}
if (product.USINGSTATE == EnumGeter.USINGSTATE.UNUSED.GetHashCode().ToString())
{
product.STATUSNAME = dicStatus.GetDictValue(product.STATUS);
product.CURRENTPROCESSNAME = dicProcess.GetDictValue(product.CURRENTPROCESS);
product.PRODUCTTYPENAME = dicProductType.GetDictValue(product.PRODUCTTYPE);
result.Result = product;
return result;
}
else
{
if (product.PRODUCTTYPE != EnumGeter.ProductType.biaopi.GetHashCode().ToString())
{
result.IsSuccess = false;
result.Msg = "该产品已使用,请对本体件进行返修操作!";
result.Result = product;
}
else
{
//本体件
MainDAL mainDal = new MainDAL();
Main main = mainDal.GetMain(new Main() { EPIDERMISCODE = product.PRODUCTCODE });
product.CURRENTPROCESS = main.CURRENTPROCESS;
product.STATUS = main.STATUS;
product.STATUSNAME = dicStatus.GetDictValue(product.STATUS);
product.CURRENTPROCESSNAME = dicProcess.GetDictValue(product.CURRENTPROCESS);
product.PRODUCTTYPE = EnumGeter.ProductType.benti.GetHashCode().ToString();
product.PRODUCTTYPENAME = dicProductType.GetDictValue(product.PRODUCTTYPE);
product.PID = main.PID;
result.Result = product;
}
}
return result;
}
public List<MenderReason> GetMenderReasonList(MenderReason condition)
{
List<MenderReason> list = new MenderReasonDAL().GetList(condition);
return list;
}
public DataResult<DataTable> GetListForstatistic(MendRecorder condition)
{
DataResult<DataTable> result = new DataResult<DataTable>();
result.IsSuccess = true;
DataTable dt = new DataTable();
dt = new ScrapRecordDAL().GetListForstatistic(condition);
result.Result = dt;
return result;
}
#endregion
#region 获取统计信息填充图表
/// <summary>
/// 获取统计信息填充图表
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public DataResult<List<MendRecorder>> GetMendRecorderStatistics(MendRecorder condition)
{
DataResult<List<MendRecorder>> result = new DataResult<List<MendRecorder>>();
ScrapRecordDAL dal = new ScrapRecordDAL();
List<MendRecorder> list = dal.GetMendRecorderStatistics(condition);
result.Result = list;
result.IsSuccess = true;
return result;
}
#endregion
#region 获取统计信息导出
/// <summary>
/// 获取统计信息填充图表
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public DataResult<DataTable> ExportMendRecorderStatistics(MendRecorder condition)
{
DataResult<DataTable> result = new DataResult<DataTable>();
ScrapRecordDAL dal = new ScrapRecordDAL();
DataTable dt = dal.ExportMendRecorderStatistics(condition);
result.Result = dt;
result.IsSuccess = true;
return result;
}
#endregion
}
}