|
|
|
|
using System.Data;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using Aspose.Cells;
|
|
|
|
|
using Estsh.Core.Models;
|
|
|
|
|
using Estsh.Core.Repository.IRepositories;
|
|
|
|
|
using Estsh.Core.Util;
|
|
|
|
|
using Estsh.Core.Services.IServices;
|
|
|
|
|
using Estsh.Core.Model.Result;
|
|
|
|
|
using Estsh.Core.Model.ExcelModel;
|
|
|
|
|
using Estsh.Core.Model.EnumUtil;
|
|
|
|
|
|
|
|
|
|
/***************************************************************************************************
|
|
|
|
|
*
|
|
|
|
|
* 更新人:sitong.dong
|
|
|
|
|
* 描述:BOM管理业务类
|
|
|
|
|
* 修改时间:2022.06.22
|
|
|
|
|
* 修改日志:系统迭代升级
|
|
|
|
|
*
|
|
|
|
|
**************************************************************************************************/
|
|
|
|
|
namespace Estsh.Core.Services
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// BOM管理业务类
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class BOMDefineService : BaseService<SysBom>, IBOMDefineService
|
|
|
|
|
{
|
|
|
|
|
private readonly IBOMDefineRepository repository;
|
|
|
|
|
public BOMDefineService(IBOMDefineRepository _repository) : base(_repository)
|
|
|
|
|
{
|
|
|
|
|
repository = _repository;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取车型配置列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<KeyValueResult> getSelectModel(String modelType)
|
|
|
|
|
{
|
|
|
|
|
return repository.getSelectModel(modelType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取BOM零件清单
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<KeyValueResult> getSelectPartNo(String bomType, String model)
|
|
|
|
|
{
|
|
|
|
|
return repository.getSelectPartNo(bomType, model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取获取工站数据列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="factoryId"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<KeyValueResult> getProcessData(int factoryId)
|
|
|
|
|
{
|
|
|
|
|
List<KeyValueResult> result = repository.getProcessData(factoryId);
|
|
|
|
|
KeyValueResult model = new KeyValueResult();
|
|
|
|
|
model.value = "0";
|
|
|
|
|
model.key = "--请选择工位--";
|
|
|
|
|
result.Insert(0, model);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取BOM数据列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bomType"></param>
|
|
|
|
|
/// <param name="part"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<SysBom> getBOMList(String bomType, String partId, String sort, String direction, string pdline, string enabled)
|
|
|
|
|
{
|
|
|
|
|
return repository.getBOMList(bomType, partId, sort, direction, pdline, enabled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据零件号和bom类型获取bomID
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="partNo"></param>
|
|
|
|
|
/// <param name="bomType"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int GetBOMID(string partNo, int bomType)
|
|
|
|
|
{
|
|
|
|
|
return repository.GetBOMID(partNo, bomType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据零件号 或 客户零件号 查询零件编号
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="partNo"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int GetPartID(string partNo)
|
|
|
|
|
{
|
|
|
|
|
return repository.GetPartID(partNo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 通过BomId获取bom类型
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bomID"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public string GetBOMType(int bomID)
|
|
|
|
|
{
|
|
|
|
|
return repository.GetBOMType(bomID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 通过BomId获取pratId
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bomID"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public string GetBOMPartId(string partNo)
|
|
|
|
|
{
|
|
|
|
|
return repository.GetBOMPartId(partNo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 通过零件Id判断零件号是否已经定义了 KPSN RULE
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="partID"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool ExistsPartSNRule(int partID)
|
|
|
|
|
{
|
|
|
|
|
return repository.ExistsPartSNRule(partID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 增加bom子零件清单
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="table"></param>
|
|
|
|
|
/// <param name="values"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool addBomItemPart(String table, SysBomDetail values)
|
|
|
|
|
{
|
|
|
|
|
return repository.insertBomDetail(table, values);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新BOM子零件清单
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="valuesString"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool UpdateBOMDetail(SysBomDetail values, String guid)
|
|
|
|
|
{
|
|
|
|
|
return repository.UpdateBOMDetail(values, guid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新 BOM 匹配表,用于车型匹配
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="values"></param>
|
|
|
|
|
/// <param name="guid"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool BuildBOMMatch(int bomId)
|
|
|
|
|
{
|
|
|
|
|
return repository.BuildBOMMatch(bomId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 为特征 BOM 产生匹配清单,用于发运绑定时的车型匹配
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bomId"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool BuildBOMMatchForTransBind(int bomId)
|
|
|
|
|
{
|
|
|
|
|
return repository.BuildBOMMatchForTransBind(bomId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据Guid删除BomDetail数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ids"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int deleteBOMDetail(String guid)
|
|
|
|
|
{
|
|
|
|
|
return repository.DeleteBOMDetial(guid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 启用
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ids"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int EnableData(String ids)
|
|
|
|
|
{
|
|
|
|
|
ids = ids.Substring(0, ids.Length - 1);
|
|
|
|
|
return this.repository.EnableData(ids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 禁用
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ids"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int DisableData(String ids)
|
|
|
|
|
{
|
|
|
|
|
ids = ids.Substring(0, ids.Length - 1);
|
|
|
|
|
return this.repository.DisableData(ids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 新增BOM
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Params"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool InsertBOM(SysBom Params)
|
|
|
|
|
{
|
|
|
|
|
return repository.InsertBOM(Params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除BOM
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Params"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool DeleteBOM(int bomId)
|
|
|
|
|
{
|
|
|
|
|
return repository.DeleteBOM(bomId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读取采购订单文件并更新至数据库
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="inputStream">文件全路径</param>
|
|
|
|
|
/// <param name="userInfo">登录用户信息</param>
|
|
|
|
|
public Hashtable ImportExcel(List<BOMDefine> inputStream, int userId)
|
|
|
|
|
{
|
|
|
|
|
Hashtable result = new Hashtable();
|
|
|
|
|
Hashtable Cache = new Hashtable();
|
|
|
|
|
|
|
|
|
|
if (inputStream == null || inputStream.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
result.Add("message", "导入数据为空,请重新导入");
|
|
|
|
|
result.Add("flag", "error");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StringBuilder ErrorMessage = new StringBuilder(1024);
|
|
|
|
|
|
|
|
|
|
// 验证数据
|
|
|
|
|
for (int i = 0; i < inputStream.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (i == 13207)
|
|
|
|
|
{
|
|
|
|
|
string a = i.ToString();
|
|
|
|
|
}
|
|
|
|
|
//父阶零件号
|
|
|
|
|
string partNo = inputStream[i].PartNoF.ToString();
|
|
|
|
|
int partNoId = repository.GetPartID(partNo);
|
|
|
|
|
//子阶零件号
|
|
|
|
|
string partNoItem = inputStream[i].PartNoZ.ToString();
|
|
|
|
|
int partNoItemId = repository.GetPartID(partNoItem);
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(partNoId.ToString()) || partNoId.ToString().Equals("0"))
|
|
|
|
|
{
|
|
|
|
|
ErrorMessage.Append("父阶零件号 " + partNo + " 不存在!" + Environment.NewLine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(partNoItemId.ToString()) || partNoItemId.ToString().Equals("0"))
|
|
|
|
|
{
|
|
|
|
|
ErrorMessage.Append("子阶零件号 " + partNoItem + " 不存在!" + Environment.NewLine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string BOMType = inputStream[i].BomType.ToString();
|
|
|
|
|
|
|
|
|
|
if (BOMType == "绑定")
|
|
|
|
|
{
|
|
|
|
|
if (!repository.ExistsPartSNRule(partNoItemId))
|
|
|
|
|
{
|
|
|
|
|
ErrorMessage.Append("第" + i + 1 + "行,子阶零件号 " + partNoItem + " 条码特征未定义!" + Environment.NewLine);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 校验数据时发生错误
|
|
|
|
|
if (ErrorMessage.Length != 0)
|
|
|
|
|
{
|
|
|
|
|
result.Add("message", ErrorMessage.ToString());
|
|
|
|
|
result.Add("flag", "error");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理表头数据 SYS_BOM
|
|
|
|
|
for (int i = 0; i < inputStream.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
string bomPartNo = inputStream[i].PartNoF.ToString();
|
|
|
|
|
int bomType = int.Parse(inputStream[i].BomType.ToString());
|
|
|
|
|
int PartID = repository.GetPartID(bomPartNo);
|
|
|
|
|
int BOMID = 0;
|
|
|
|
|
|
|
|
|
|
if (!Cache.ContainsKey(bomPartNo))
|
|
|
|
|
{
|
|
|
|
|
//获取sys_bom表中 bomid
|
|
|
|
|
BOMID = repository.GetBOMID(bomPartNo, bomType);
|
|
|
|
|
|
|
|
|
|
if (BOMID == 0)
|
|
|
|
|
{
|
|
|
|
|
SysBom model = new SysBom();
|
|
|
|
|
model.PartId = PartID;
|
|
|
|
|
model.BomType = bomType;
|
|
|
|
|
model.CreateUserId = userId;
|
|
|
|
|
|
|
|
|
|
repository.insertBom("sys_bom", model);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
repository.DeleteBOMDetail(BOMID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Cache.Add(bomPartNo, bomPartNo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bool IsBOMMatchByCPN = repository.BOMMatchByCPN();
|
|
|
|
|
|
|
|
|
|
// 处理表身数据 SYS_BOM_DETAIL, SYS_BOM_MATCH
|
|
|
|
|
if (repository.InsertData(inputStream, IsBOMMatchByCPN))
|
|
|
|
|
{
|
|
|
|
|
Cache.Clear();
|
|
|
|
|
|
|
|
|
|
foreach (BOMDefine dr in inputStream)
|
|
|
|
|
{
|
|
|
|
|
string bomPartNo = dr.PartNoF.ToString();
|
|
|
|
|
int bomType = int.Parse(dr.BomType.ToString());
|
|
|
|
|
|
|
|
|
|
if (!Cache.ContainsKey(bomPartNo))
|
|
|
|
|
{
|
|
|
|
|
int BOMID = repository.GetBOMID(bomPartNo, bomType);
|
|
|
|
|
|
|
|
|
|
if (BOMID != 0 && (bomType == (int)MesEnumUtil.BomType.PART || bomType == (int)MesEnumUtil.BomType.FEATURE))
|
|
|
|
|
{
|
|
|
|
|
if (!repository.BuildBOMMatch(BOMID))
|
|
|
|
|
{
|
|
|
|
|
result.Add("message", "导入失败,更新 BOM 匹配信息不成功!");
|
|
|
|
|
result.Add("flag", "error");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Cache.Add(bomPartNo, bomType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
result.Add("message", "导入成功");
|
|
|
|
|
result.Add("flag", "error");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result.Add("message", "导入失败");
|
|
|
|
|
result.Add("flag", "error");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 导出Bom信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bomType"></param>
|
|
|
|
|
/// <param name="partId"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<BOMDefine> exportBOMInfo(String bomType, String partId)
|
|
|
|
|
{
|
|
|
|
|
return this.repository.getExpotBOMList(bomType, partId, "", "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<BOMDefine> exportALL(String bomType)
|
|
|
|
|
{
|
|
|
|
|
return this.repository.exportALL(bomType, "", "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|