皮带秤的计量方式
董建刚
/// <summary>
/// 定时自动保存皮带秤数据,默认采取单一时间
/// <param name="hardwareInfo">硬件消息</param>
/// <param name="beltAutoBuffer">皮带秤的缓存信息</param>
public void AutoSaveBeltData(HardwareInfo hardwareInfo,
BeltAutoBuffer
beltAutoBuffer)
if (beltAutoBuffer.SaveStyle.ContainsKey(balanceName))
{
WeighBdForZKBelt beltBD = new WeighBdForZKBelt();
string startHour;
beltAutoBuffer.StartHour.TryGetValue(balanceName, out startHour);
DateTime startTime= Now.Date.AddHours(Convert.ToDouble(startHour));
TimeSpan startTs = DateTime.Now - startTime;
//处理是否是仪表清零的情况
if (beltAccumulateBuffer.ContainsKey(balanceName))
{
decimal preAccumulateNum = 0;
beltAccumulateBuffer.TryGetValue(balanceName,out preAccumulateNum);
if (preWeighDtos != null && preWeighDtos.Length > 0){
//先保存上一毛重
this.AddSecondBeltWeigh(balanceName, preAccumulateNum, preWeighDtos[0]);
//再保存下一皮重
this.AddFirstBeltWeigh(balanceName, hardwareInfo.BeltInfo.AccumulateNum);
//处理清零时间缓存
if (beltZeroList.ContainsKey(balanceName))
beltZeroList[balanceName] = DateTime.Now.Date;
else beltZeroList.Add(balanceName, DateTime.Now.Date);
//记录日志
BeltLogBD logBD = new BeltLogBD();
BeltLogDTO logDTO = new BeltLogDTO();
OrganizationBD organizationBD = new OrganizationBD();
QueryParams[] paras = new QueryParams[1];
paras[0] = new QueryParams("Name", balanceName, OperationType.Equal);
BalanceDTO[] balanceDtos = organizationBD.FindBalanceByCondition(paras, null, 0, 1);
logDTO.Balance = balanceDtos[0];
logDTO.Content = balanceName + "于" + DateTime.Now + "仪表清零;清零前重量:" + preAccumulateNum.ToString() + ",清零后重量:" + hardwareInfo.BeltInfo.AccumulateNum.ToString();
logDTO.LogType = BeltLogType.Clear;
logDTO.LogTime = DateTime.Now;
logBD.AddBeltLog(logDTO);
}
beltAccumulateBuffer[balanceName] = hardwareInfo.BeltInfo.AccumulateNum;
}
else beltAccumulateBuffer.Add(balanceName, hardwareInfo.BeltInfo.AccumulateNum);
if (startTs.TotalMinutes > 0 && startTs.TotalMinutes < 5)
{
WeighDTO[] weighDtos = null;
if (beltZeroList.ContainsKey(balanceName) &&
beltZeroList[balanceName].Equals(Now.Date))
weighDtos = beltBD.FindUnpairWeigh(balanceName, DateTime.Now.Date);
else
//查询昨日或之前的未匹配过皮重
//保存当日皮重
WeighDTO[] todayWeighDtos = beltBD.FindUnpairWeigh(balanceName, startTime);
if (todayWeighDtos == null || todayWeighDtos.Length <= 0)
this.AddFirstBeltWeigh(balanceName, hardwareInfo.BeltInfo.AccumulateNum);
}
}