You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

664 lines
31 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using AUCMA.STORE.Business.Interface;
using AUCMA.STORE.Common;
using AUCMA.STORE.Entity.DAO;
using AUCMA.STORE.Entity.DTO;
using AUCMA.STORE.Entity.Enums;
using AUCMA.STORE.SqlSugar;
using AUCMA.STORE.SqlSugar.serviceImpl;
using AutoMapper;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace AUCMA.STORE.Business.Implements
{
/// <summary>
/// 出库业务逻辑
/// </summary>
public class OutStoreBusinessImpl : IOutStoreBusiness
{
private readonly IPlcBusinessService plcBusinessService = new PlcBusinessService();
private static String boxCodeNumber;
/// <summary>
/// 根据箱体码获取物料规格信息
/// </summary>
/// <param name="boxCode"></param>
/// <returns></returns>
public async Task<BaseMaterialInfo> GetMaterialInfo(string boxCode)
{
boxCodeNumber = boxCode;
//Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "收到机械手扫描箱体码:" + boxCode);
/*boxCode = boxCode.Substring(0, 10);
LogHelper.Info("箱体码截取后为:" + boxCode);
Console.WriteLine("箱体码截取后为:" + boxCode);
Expression<Func<ImosTeBom, bool>> exp = s1 => true;
exp = exp.And(s1 => s1.masterMaterialCode == boxCode && s1.detialTypeCodeD == ConfigHelper.GetConfig("detialTypeCodeD"));
List<ImosTeBom> imosTeBoms = await new BaseServices<ImosTeBom>().Query(exp);*/
//var imosTeBoms = await new BaseServices<ImosTeBom>().QueryBySql<ImosTeBom>("select A.Bar_Code,nvl(C.Detial_Material_Code,A.Order_Material_Code) Detial_Material_Code," +
//"nvl(C.Detial_Material_Name, A.Order_Material_Name) Detial_Material_Name, A.Order_No, A.material_name " +
//" from imos_pr_barcode_record A left join imos_te_bom C ON A.Order_Material_code = C.Master_Material_Code " +
//"where A.Bar_Code = @BarCode AND C.Detial_Type_Code_d = @DetialTypeCoded",
//new List<SugarParameter>(){
// new SugarParameter("@BarCode",boxCode),
// new SugarParameter("@DetialTypeCoded",ConfigHelper.GetConfig("detialTypeCodeD")) //执行sql语句
//});
SqlSugarClient sqlServerDB = SqlGenerator.GetOracleInstance();
var imosTeBoms = sqlServerDB.Ado.SqlQuery<ImosTeBom>("select A.Bar_Code,nvl(C.Detial_Material_Code,A.Order_Material_Code) Detial_Material_Code," +
"nvl(C.Detial_Material_Name, A.Order_Material_Name) Detial_Material_Name, A.Order_No, A.material_name " +
" from imos_pr_barcode_record A left join view_imos_bom_list C ON A.Order_Material_code = C.Master_Material_Code " +
"where A.Bar_Code = @BarCode AND C.Detial_Type_Code_d = @DetialTypeCoded",
new List<SugarParameter>(){
new SugarParameter("@BarCode",boxCode),
new SugarParameter("@DetialTypeCoded",ConfigHelper.GetConfig("detialTypeCodeD")) //执行sql语句
});
if (imosTeBoms.Count() > 0)
{
ImosTeBom imosTeBom = imosTeBoms.FirstOrDefault();
BaseMaterialInfo baseMaterialInfos = new BaseMaterialInfo();
baseMaterialInfos.materialCode = imosTeBom.detialMaterialCode;
baseMaterialInfos.materialType = imosTeBom.detialMaterialCode;
baseMaterialInfos.locationArea = LocationArea.Location_NoCare;
return baseMaterialInfos;
}
return new BaseMaterialInfo();
}
/// <summary>
/// 判断堆垛机状态
/// </summary>
/// <param name="baseMaterialInfo"></param>
/// <returns></returns>
public List<PilerStatusDTO> EstimatePilerStatus()
{
return plcBusinessService.GetPilerWorkState();
}
private INIFile iNIFile = new INIFile(System.Environment.CurrentDirectory + "/PlcAddress/PlcAddress.InI");
/// <summary>
/// 判断物料所在库位
/// </summary>
/// <param name="baseMaterialInfo"></param>
/// <returns></returns>
public async Task<List<BaseLocationInfo>> EstimateMaterialLocation(BaseMaterialInfo baseMaterialInfo)
{
try
{
Expression<Func<BaseLocationInfo, bool>> exp = s1 => true;
exp = exp.And(s1 => s1.materialType == baseMaterialInfo.materialCode && s1.locationStatus == LocationStatus.InUse && s1.deleteFlag == Entity.Enums.DeleteFlag.No && s1.storeCode == ConfigHelper.GetConfig("storeCode"));
var outStoreType = iNIFile.IniReadValue("系统设置", "出库方式");
if (outStoreType == "1")
{
LocationArea locationArea = (LocationArea)Convert.ToInt32(iNIFile.IniReadValue("系统设置", "初始出库区域"));
if (baseMaterialInfo.locationArea == LocationArea.Location_NoCare)
{
Console.WriteLine($"创建自动出库任务,初始出库区域:{locationArea}");
Task<int> count = GetLocationInfoCount(baseMaterialInfo.materialCode, locationArea);
Console.WriteLine($"创建自动出库任务,初始出库区域:{locationArea};当前库存:{count}");
if (count.Result < 8)
{
Console.WriteLine($"初始出库区域:{locationArea};当前库存:{count.Result}小于8判断是否切换出库区域");
if (locationArea == LocationArea.Location_Left)
{
Task<int> rightCount = GetLocationInfoCount(baseMaterialInfo.materialCode, LocationArea.Location_Right);
if (rightCount.Result < 8)
{
Console.WriteLine($"另一侧库存{rightCount.Result}小于8不满足切换条件继续使用原区域");
exp = exp.And(s1 => s1.locationArea == locationArea);
}
else
{
Console.WriteLine($"另一侧库存{rightCount.Result}满足切换条件");
iNIFile.IniWriteValue("系统设置", "初始出库区域", "2");
}
}
else
{
Task<int> leftCount = GetLocationInfoCount(baseMaterialInfo.materialCode, LocationArea.Location_Left);
if (leftCount.Result < 8)
{
Console.WriteLine($"另一侧库存{leftCount.Result}小于8不满足切换条件继续使用原区域");
exp = exp.And(s1 => s1.locationArea == locationArea);
}
else
{
Console.WriteLine($"另一侧库存{leftCount.Result}满足切换条件");
iNIFile.IniWriteValue("系统设置", "初始出库区域", "1");
}
}
}
else
{
exp = exp.And(s1 => s1.locationArea == locationArea);
}
}
else
{
exp = exp.And(s1 => s1.locationArea == baseMaterialInfo.locationArea);
}
}
List<BaseLocationInfo> result = await new BaseServices<BaseLocationInfo>().Query(exp);
if (baseMaterialInfo.locationArea != LocationArea.Location_NoCare)
{
result = result.Where(x => x.locationArea == baseMaterialInfo.locationArea).ToList();
}
//if (result.Count() > 0)
// return result;
return result;
}
catch (Exception ex)
{
LogHelper.Error("判断物料所在库位异常",ex);
return new List<BaseLocationInfo>();
}
}
private async Task<int> GetLocationInfoCount(string materialCode, LocationArea locationArea)
{
Expression<Func<BaseLocationInfo, bool>> exp = s1 => true;
exp = exp.And(s1 => s1.materialType == materialCode && s1.locationStatus == LocationStatus.InUse
&& s1.locationArea == locationArea
&& s1.deleteFlag == Entity.Enums.DeleteFlag.No && s1.storeCode == ConfigHelper.GetConfig("storeCode"));
List<BaseLocationInfo> result = await new BaseServices<BaseLocationInfo>().Query(exp);
return result.Count();
}
/// <summary>
/// 选取最优库位
/// 添加先入先出逻辑
/// </summary>
/// <param name="pilerStatusDTOs"></param>
/// <param name="baseMaterialStore"></param>
/// <returns></returns>
public BaseLocationInfo FiltrateLocation(List<PilerStatusDTO> pilerStatusDTOs, List<BaseLocationInfo> baseLocationInfos)
{
//判断库位区域
List<LocationArea> locationAreas = new List<LocationArea>();
List<IGrouping<LocationArea, BaseLocationInfo>> _group = baseLocationInfos.GroupBy(g => g.locationArea).ToList();
_group.ForEach(x => locationAreas.Add(x.Key));
if (locationAreas.Count() == 2)
{
if (pilerStatusDTOs.Count() == 2)
{
if (ConfigHelper.GetConfig("outStoreType") == "A")
{
return baseLocationInfos.OrderBy(x => x.recordTime).FirstOrDefault();
}
return baseLocationInfos.OrderByDescending(x => x.efficiency).FirstOrDefault();
}
if(pilerStatusDTOs.Count() == 1)
{
if (ConfigHelper.GetConfig("outStoreType") == "A")
{
return baseLocationInfos.Where(s1 => s1.locationArea == pilerStatusDTOs.FirstOrDefault().locationArea).OrderBy(x => x.recordTime).FirstOrDefault();
}
return baseLocationInfos.Where(s1 => s1.locationArea == pilerStatusDTOs.FirstOrDefault().locationArea).OrderByDescending(s2 => s2.efficiency).FirstOrDefault();
}
}
if (locationAreas.Count() == 1)
{
if (pilerStatusDTOs.Count() == 2)
{
if (ConfigHelper.GetConfig("outStoreType") == "A")
{
return baseLocationInfos.OrderBy(x => x.recordTime).FirstOrDefault();
}
return baseLocationInfos.OrderByDescending(x => x.efficiency).FirstOrDefault();
}
if (pilerStatusDTOs.Count() == 1)
{
if (locationAreas.FirstOrDefault() == pilerStatusDTOs.FirstOrDefault().locationArea)
{
if (ConfigHelper.GetConfig("outStoreType") == "A")
{
return baseLocationInfos.OrderBy(x => x.recordTime).FirstOrDefault();
}
return baseLocationInfos.OrderByDescending(x => x.efficiency).FirstOrDefault();
}
}
}
return new BaseLocationInfo();
}
public BaseLocationInfo FiltrateBestlocation(List<BaseLocationInfo> baseLocationInfos)
{
if (ConfigHelper.GetConfig("outStoreType") == "A")
{
return baseLocationInfos.OrderBy(x => x.recordTime).FirstOrDefault();
}
return baseLocationInfos.OrderByDescending(x => x.efficiency).FirstOrDefault();
}
/// <summary>
/// 创建出库任务
/// </summary>
/// <param name="baseLocationInfo"></param>
/// <param name="pilerStatusDTOs"></param>
/// <param name="baseMaterialInfo"></param>
/// <returns></returns>
public async Task<TaskDTO> CreateOutStoreTask(BaseLocationInfo baseLocationInfo, List<PilerStatusDTO> pilerStatusDTOs,BaseMaterialInfo baseMaterialInfo)
{
try
{
PilerStatusDTO pilerStatus = pilerStatusDTOs.Where(x => x.locationArea == baseLocationInfo.locationArea).FirstOrDefault();
string taskCode = "";
TaskDTO task = new TaskDTO();
Expression<Func<RecordTask, bool>> exp = s1 => true;
string code = DateTime.Now.ToString("yyMMdd");
exp = exp.And(s1 => s1.taskCode.Contains(code));
List<RecordTask> recordTasks = await new BaseServices<RecordTask>().Query(exp);
if (recordTasks.Count() == 0)
{
taskCode = DateTime.Now.ToString("yyMMdd").Trim() + "0001";
}
else
{
//var test = recordTasks.OrderByDescending(x => x.recordTime).FirstOrDefault();
var info = recordTasks.OrderByDescending(x => x.recordTime).FirstOrDefault().taskCode.Substring(6).ToInt() + 1;
taskCode = DateTime.Now.ToString("yyMMdd").Trim() + info.ToString().PadLeft(4, '0');
}
Expression<Func<RecordTask, bool>> taskexp = s1 => true;
taskexp = taskexp.And(s1 => s1.taskCode.Contains(taskCode));
List<RecordTask> recordTaskInfo = await new BaseServices<RecordTask>().Query(taskexp);
if (recordTaskInfo.Count() > 0)
{
Random random = new Random();
taskCode = random.Next(100000000, 999999999).ToString();
}
if (task.operationType == OperationType.Automatic)
{
task.boxCode = boxCodeNumber;
}
task.pilerCode = pilerStatus.pilerCode;
task.taskCode = taskCode;
task.locationCode = baseLocationInfo.locationCode;
task.locationArea = baseLocationInfo.locationArea;
task.row = baseLocationInfo.locationRow;
task.line = baseLocationInfo.locationLine;
task.tier = baseLocationInfo.locationTier;
task.taskType = TaskType.OutStore;
task.storeCode = baseLocationInfo.storeCode;
task.materialCode = baseMaterialInfo.materialCode;
task.materialType = baseMaterialInfo.materialType;
//task.operationType = OperationType.Automatic;
task.taskStatus = Entity.Enums.TaskStatus.Await;
task.beginTime = DateTime.Now;
task.recordTime = DateTime.Now;
task.locationIndex = baseLocationInfo.objid;
//PLC指令
task.pilerTaskCode = Convert.ToInt32(taskCode);
task.pilerTaskType = 2;
task.pilerClaimGoodsRows = baseLocationInfo.locationRow;
task.pilerClaimGoodsLine = baseLocationInfo.locationLine;
task.pilerClaimGoodsTier = baseLocationInfo.locationTier;
if (baseLocationInfo.locationArea == LocationArea.Location_Left)
{
if (ConfigHelper.GetConfig("storeCode") == "A") task.pilerUnloadRows = 2;
if (ConfigHelper.GetConfig("storeCode") == "B") task.pilerUnloadRows = 1;
}
if (baseLocationInfo.locationArea == LocationArea.Location_Right)
{
if (ConfigHelper.GetConfig("storeCode") == "A") task.pilerUnloadRows = 1;
if (ConfigHelper.GetConfig("storeCode") == "B") task.pilerUnloadRows = 2;
}
//task.pilerUnloadRows = Convert.ToInt32(baseLocationInfo.locationArea);
task.pilerUnloadLine = 1;
task.pilerUnloadTier = 2;
//创建出库任务
Mapper.Initialize(cret => cret.CreateMap<TaskDTO, RecordTask>());
RecordTask recordTask = Mapper.Map<RecordTask>(task);
recordTask.objid = System.Guid.NewGuid().ToString();
recordTask.storeCode = ConfigHelper.GetConfig("storeCode");
await new BaseServices<RecordTask>().Add(recordTask);
return task;
}catch(Exception ex)
{
LogHelper.Error("出库任务创建失败:" + ex.Message);
return new TaskDTO();
}
}
public async Task<TaskDTO> CreateTask(BaseLocationInfo baseLocationInfo, BaseMaterialInfo baseMaterialInfo, OperationType operationType)
{
try
{
string taskCode = "";
TaskDTO task = new TaskDTO();
Expression<Func<RecordTask, bool>> exp = s1 => true;
string code = DateTime.Now.ToString("yyMMdd").Substring(1);
exp = exp.And(s1 => s1.taskCode.Contains(code));
List<RecordTask> recordTasks = await new BaseServices<RecordTask>().Query(exp);
if (recordTasks.Count() == 0)
{
taskCode = DateTime.Now.ToString("yyMMdd").Substring(1).Trim() + "0001";
//taskCode = taskCode.Substring(1, 9);
}
else
{
//var test = recordTasks.OrderByDescending(x => x.recordTime).FirstOrDefault();
var info = recordTasks.OrderByDescending(x => x.recordTime).FirstOrDefault().taskCode.Substring(5).ToInt() + 1;
taskCode = DateTime.Now.ToString("yyMMdd").Substring(1).Trim() + info.ToString().PadLeft(4, '0');
//taskCode = taskCode.Substring(1, 9);
}
Expression<Func<RecordTask, bool>> taskexp = s1 => true;
taskexp = taskexp.And(s1 => s1.taskCode.Contains(taskCode));
List<RecordTask> recordTaskInfo = await new BaseServices<RecordTask>().Query(taskexp);
if(recordTaskInfo.Count() > 0)
{
Random random = new Random();
taskCode = random.Next(100000000, 999999999).ToString();
}
if (task.operationType == OperationType.Automatic)
{
task.boxCode = boxCodeNumber;
}
task.taskCode = taskCode;
task.taskType = TaskType.OutStore;
task.storeCode = baseLocationInfo.storeCode;
task.materialCode = baseMaterialInfo.materialCode;
task.materialType = baseMaterialInfo.materialType;
task.operationType = operationType;
task.taskStatus = Entity.Enums.TaskStatus.Await;
task.beginTime = DateTime.Now;
task.recordTime = DateTime.Now;
//PLC指令
task.pilerTaskCode = Convert.ToInt32(taskCode.Substring(0, 9));
task.pilerTaskType = 2;
if(operationType == OperationType.ManualOperation)
{
task.locationArea = baseLocationInfo.locationArea;
task.locationIndex = baseLocationInfo.objid;
task.locationCode = baseLocationInfo.locationCode;
task.row = baseLocationInfo.locationRow;
task.line = baseLocationInfo.locationLine;
task.tier = baseLocationInfo.locationTier;
task.plcCode = Convert.ToInt32(task.pilerCode);
task.pilerClaimGoodsRows = baseLocationInfo.locationRow;
task.pilerClaimGoodsLine = baseLocationInfo.locationLine;
task.pilerClaimGoodsTier = baseLocationInfo.locationTier;
if (baseLocationInfo.locationArea == LocationArea.Location_Left)
{
if (ConfigHelper.GetConfig("storeCode") == "A") task.pilerUnloadRows = 2;
if (ConfigHelper.GetConfig("storeCode") == "B") task.pilerUnloadRows = 1;
}
if (baseLocationInfo.locationArea == LocationArea.Location_Right)
{
if (ConfigHelper.GetConfig("storeCode") == "A") task.pilerUnloadRows = 1;
if (ConfigHelper.GetConfig("storeCode") == "B") task.pilerUnloadRows = 2;
}
}
task.pilerUnloadLine = 1;
task.pilerUnloadTier = 2;
//创建出库任务
Mapper.Initialize(cret => cret.CreateMap<TaskDTO, RecordTask>());
RecordTask recordTask = Mapper.Map<RecordTask>(task);
recordTask.objid = System.Guid.NewGuid().ToString();
recordTask.storeCode = ConfigHelper.GetConfig("storeCode");
await new BaseServices<RecordTask>().Add(recordTask);
boxCodeNumber = "";
return task;
}
catch (Exception ex)
{
LogHelper.Error("出库任务创建失败",ex );
return new TaskDTO();
}
}
/// <summary>
/// 创建待出库
/// </summary>
/// <param name="taskDTO"></param>
/// <returns></returns>
public async Task<int> CreatePrepareOutStore(TaskDTO taskDTO)
{
Mapper.Initialize(cret => cret.CreateMap<TaskDTO, PrepareOutStoreInfo>());
PrepareOutStoreInfo prepareOutStoreInfo = Mapper.Map<PrepareOutStoreInfo>(taskDTO);
prepareOutStoreInfo.objid = System.Guid.NewGuid().ToString();
prepareOutStoreInfo.outStoreStatus = OutStoreStatus.Being;
prepareOutStoreInfo.storeCode = ConfigHelper.GetConfig("storeCode");
return await new BaseServices<PrepareOutStoreInfo>().Add(prepareOutStoreInfo);
}
/// <summary>
/// 修改库位状态
/// </summary>
/// <param name="baseLocationInfo"></param>
/// <param name="locationStatus"></param>
/// <returns></returns>
public async Task<bool> updateLocationStatus(TaskDTO task, LocationStatus locationStatus)
{
Expression<Func<BaseLocationInfo, bool>> exp = s1 => true;
if (task.locationIndex != null)
{
exp = exp.And(x => x.objid == task.locationIndex);
}
exp = exp.And(x =>x.locationArea == task.locationArea && x.locationCode == task.locationCode && x.storeCode == ConfigHelper.GetConfig("storeCode"));
BaseLocationInfo baseLocationInfo = await new BaseServices<BaseLocationInfo>().QuerySingle(exp);
baseLocationInfo.locationStatus = locationStatus;
baseLocationInfo.recordTime = DateTime.Now;
if (baseLocationInfo.materialType != task.materialCode)
{
baseLocationInfo.materialType = task.materialCode;
}
return await new BaseServices<BaseLocationInfo>().Update(baseLocationInfo);
}
public async Task<bool> updateLocationStatus(string locationIndex,string locationCode,LocationArea locationArea, string materialCode, LocationStatus locationStatus)
{
Expression<Func<BaseLocationInfo, bool>> exp = s1 => true;
if (locationIndex != null)
{
exp = exp.And(x => x.objid == locationIndex);
}
exp = exp.And(x => x.locationArea == locationArea && x.locationCode == locationCode && x.storeCode == ConfigHelper.GetConfig("storeCode"));
BaseLocationInfo baseLocationInfo = await new BaseServices<BaseLocationInfo>().QuerySingle(exp);
baseLocationInfo.locationStatus = locationStatus;
baseLocationInfo.recordTime = DateTime.Now;
if (baseLocationInfo.materialType != materialCode)
{
baseLocationInfo.materialType = materialCode;
}
return await new BaseServices<BaseLocationInfo>().Update(baseLocationInfo);
}
/// <summary>
/// 修改出库任务状态
/// </summary>
/// <param name="prepareOutStoreInfo"></param>
/// <returns></returns>
public async Task<bool> UpdateOutStoreStatus(TaskDTO taskDTO)
{
//修改出库任务状态
Expression<Func<RecordTask, bool>> exp = s1 => true;
exp = exp.And(s1 => s1.taskCode == taskDTO.taskCode);
List<RecordTask> recordTask = await new BaseServices<RecordTask>().Query(exp);
if (recordTask.Count() == 0)
return false;
recordTask.ForEach(x => {
x.taskStatus = Entity.Enums.TaskStatus.Achieve;
x.endTime = DateTime.Now;
x.recordTime = DateTime.Now;
});
return await new BaseServices<RecordTask>().Update(recordTask);
}
/// <summary>
/// 修改待出库记录状态
/// </summary>
/// <param name="taskDTO"></param>
/// <returns></returns>
public async Task<bool> UpdatePrePareOutStoreStatus(TaskDTO taskDTO)
{
//修改待出库任务状态
Expression<Func<PrepareOutStoreInfo, bool>> expression = s1 => true;
expression = expression.And(s1 => s1.taskCode == taskDTO.taskCode);
//PrepareOutStoreInfo prepareOutStoreInfo = await new BaseServices<PrepareOutStoreInfo>().QuerySingle(expression);
//if (prepareOutStoreInfo.locationCode == null || prepareOutStoreInfo.locationCode == "")
// return false;
var prepareOutStoreInfo = await new BaseServices<PrepareOutStoreInfo>().Query(expression);
try
{
prepareOutStoreInfo.ForEach(async x =>
{
x.outStoreStatus = OutStoreStatus.Achieve;
x.endTime = DateTime.Now;
x.storeCode = ConfigHelper.GetConfig("storeCode");
x.recordTime = DateTime.Now;
await new BaseServices<PrepareOutStoreInfo>().Update(x);
});
return true;
}catch(Exception ex)
{
LogHelper.Error("修改待出库任务状态失败", ex);
return false;
}
}
/// <summary>
/// 保存出库记录
/// </summary>
/// <param name="recordOutStore"></param>
/// <returns></returns>
public async Task<int> SaveOutStoreRecord(TaskDTO taskDTO)
{
Mapper.Initialize(cret => cret.CreateMap<TaskDTO, RecordOutStore>());
RecordOutStore recordOutStore = Mapper.Map<RecordOutStore>(taskDTO);
recordOutStore.objid = System.Guid.NewGuid().ToString();
recordOutStore.outStoreStatus = OutStoreStatus.Achieve;
recordOutStore.endTime = DateTime.Now;
recordOutStore.recordTime = DateTime.Now;
recordOutStore.storeCode = ConfigHelper.GetConfig("storeCode");
return await new BaseServices<RecordOutStore>().Add(recordOutStore);
}
/// <summary>
/// 清楚物料与库位绑定记录
/// </summary>
/// <param name="taskDTO"></param>
/// <returns></returns>
public async Task<bool> DeleteMaterialLocation(TaskDTO taskDTO)
{
Mapper.Initialize(cret => cret.CreateMap<TaskDTO, BaseMaterialStore>());
BaseMaterialStore materialStore = Mapper.Map<BaseMaterialStore>(taskDTO);
Expression<Func<BaseMaterialStore, bool>> exp = s1 => true;
exp = exp.And(s1 => s1.materialCode == taskDTO.materialCode && s1.locationArea == taskDTO.locationArea && s1.locationCode == taskDTO.locationCode && s1.deleteFlag == DeleteFlag.No && s1.storeCode == ConfigHelper.GetConfig("storeCode"));
List<BaseMaterialStore> baseMaterialStores = await new BaseServices<BaseMaterialStore>().Query(exp);
if (baseMaterialStores.Count() == 0)
return false;
baseMaterialStores.ForEach(x => {
x.deleteFlag = DeleteFlag.Yes;
x.recordTime = DateTime.Now;
});
return await new BaseServices<BaseMaterialStore>().Update(baseMaterialStores);
}
/// <summary>
/// 更新库存
/// </summary>
/// <param name="baseMaterialInfo"></param>
public async Task<int> UpdateStock(BaseMaterialInfo baseMaterialInfo)
{
Expression<Func<BaseLocationInfo, bool>> exp = s1 => true;
exp = exp.And(s1 => s1.materialType == baseMaterialInfo.materialType && s1.locationStatus == LocationStatus.InUse && s1.storeCode == ConfigHelper.GetConfig("storeCode"));
List<BaseLocationInfo> baseLocationInfos = await new BaseServices<BaseLocationInfo>().Query(exp);
return baseLocationInfos.Count();
}
/// <summary>
/// 保存出库操作指令记录
/// </summary>
/// <param name="recordDirectiveOperation"></param>
/// <returns></returns>
public async Task<int> SaveOutStoreDirecticeOperation(RecordDirectiveOperation recordDirectiveOperation)
{
recordDirectiveOperation.objid = System.Guid.NewGuid().ToString();
recordDirectiveOperation.taskType = TaskType.OutStore;
recordDirectiveOperation.operationType = OperationType.Automatic;
recordDirectiveOperation.recordTime = DateTime.Now;
return await new BaseServices<RecordDirectiveOperation>().Add(recordDirectiveOperation);
}
public bool SaveBarCode(string P_Bar_Code,string P_Device_Code)
{
bool iFlag = false;
try
{
SqlSugarClient OracleDB = SqlGenerator.GetOracleInstance();
int P_ERR = 0;
string P_ERR_DESC = "";
SugarParameter[] pars = OracleDB.Ado.GetParameters(new { P_Bar_Code = P_Bar_Code, P_Device_Code = P_Device_Code, P_ERR, P_ERR_DESC });
var dt2 = OracleDB.Ado.UseStoredProcedure().GetDataTable("IMOS_UP_Prod_Exec2 ", pars);
iFlag = true;
}
catch (Exception ex)
{
return iFlag;
}
return iFlag;
}
}
}