362 lines
11 KiB
C#
362 lines
11 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Runtime.Serialization;
|
||
using System.ServiceModel;
|
||
using System.Text;
|
||
using DeiNiu.wms.Data.Model;
|
||
using DeiNiu.Utils;
|
||
using DeiNiu.wms.win.ServiceReferenceStockOutPickRequest;
|
||
using System.Data;
|
||
|
||
namespace DeiNiu.wms.win.epick
|
||
{
|
||
// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的类名“ServiceLight”。
|
||
|
||
public delegate void addNewLabelsToPool(List<SeedsLabel> labels);
|
||
public delegate void lightLable(List<SeedsLabel> lables,int portNo);
|
||
public delegate void turnoffLable(int portNo);
|
||
public delegate void clearOrder(int deskId );
|
||
public delegate bool turnOnLights(int portNo, List<ELight> lights);
|
||
public delegate bool turnOffLights(int portNo, List<ELight> lights);
|
||
|
||
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
|
||
public class ServiceLight : IServiceLight
|
||
{
|
||
static log4net.ILog log = log4net.LogManager.GetLogger("light");
|
||
public SeedsLabel getLabel(string Id)
|
||
{
|
||
SeedsLabel lb = new SeedsLabel();
|
||
lb.labelId = int.Parse(Id);
|
||
lb.color = 1;
|
||
lb.address = 11;
|
||
|
||
return lb;
|
||
|
||
}
|
||
|
||
public addNewLabelsToPool newLabels = null;
|
||
public string lightLabels(List<SeedsLabel> labels)
|
||
{
|
||
//labelPool.Concat(labels);
|
||
if (null != newLabels)
|
||
{
|
||
newLabels(labels);
|
||
return "succeed";
|
||
}
|
||
|
||
return "bad";
|
||
}
|
||
|
||
public string lightLabels2(String s)
|
||
{
|
||
return s;
|
||
}
|
||
|
||
public static List<SeedsLabel> labelPool = new List<SeedsLabel>();
|
||
|
||
public lightLable lightUp = null;
|
||
|
||
public string lightLabel(string Id)
|
||
{
|
||
List<SeedsLabel> lbs = new List<SeedsLabel>();
|
||
SeedsLabel lb = new SeedsLabel();
|
||
lb.labelId = int.Parse(Id);
|
||
lb.color = 1;
|
||
lb.address = 0;
|
||
lb.count = 11;
|
||
lb.port = 13;
|
||
lbs.Add(lb);
|
||
|
||
lb = new SeedsLabel();
|
||
lb.labelId = 2;
|
||
lb.color = 2;
|
||
lb.address = 0;
|
||
lb.count = 12;
|
||
lb.port = 13;
|
||
lbs.Add(lb);
|
||
|
||
if (lightUp != null)
|
||
{
|
||
lightUp(lbs,13);
|
||
return "success";
|
||
}
|
||
|
||
|
||
return "服务出错";
|
||
|
||
}
|
||
|
||
|
||
public turnoffLable turnOff = null;
|
||
public turnOffLights turnOffLts = null;
|
||
public turnOnLights turnOnLts = null;
|
||
public clearOrder clOrder = null;
|
||
/// <summary>
|
||
/// 开始新的一组
|
||
/// </summary>
|
||
/// <param name="deskId"></param>
|
||
/// <param name="seedsNo"></param>
|
||
/// <returns></returns>
|
||
public string startSeeds(int deskId, string seedsNo)
|
||
{
|
||
if (turnOff != null)
|
||
{
|
||
turnOff(deskId);
|
||
}
|
||
/*
|
||
if (seedsItem.startSeeds(deskId, seedsNo))
|
||
{
|
||
return "成功开始新播种";
|
||
}
|
||
*/
|
||
return "服务出错";
|
||
}
|
||
|
||
|
||
public FormatedResult lightDeskSeed( string seedsNo, string barcode, int userId, bool isValid)
|
||
{
|
||
string msg = "没有找到亮灯数据";
|
||
/*
|
||
List<ELabel> els = importSeeds.startNewDeskSeed( seedsNo, barcode, userId,5 ,isValid);
|
||
|
||
if (els.Count > 0)
|
||
{
|
||
|
||
// int deskId = els[0].port;
|
||
//int color = els[0].color;
|
||
#if DEBUG
|
||
// portNo = 13;
|
||
#endif
|
||
|
||
|
||
if (lightUp != null)
|
||
{
|
||
lightUp(els, userId);
|
||
msg = "已发送亮灯请求";
|
||
|
||
}
|
||
|
||
|
||
}
|
||
else
|
||
{
|
||
if (clOrder != null)
|
||
{
|
||
clOrder(0);
|
||
}
|
||
}
|
||
*/
|
||
return new FormatedResult(msg);
|
||
}
|
||
|
||
public FormatedResult lightSeed(int deskId, string flowNo, string barcode, int toTalpcs, int userId, bool isValid)
|
||
{
|
||
log.Debug(string.Format("start request.... deskId:{0} ,flowNo:{1} ,barcode:{2}, userId: {3}, isValid:{4},totalPcs {5} ",
|
||
deskId, flowNo, barcode, userId, isValid, toTalpcs));
|
||
List<SeedsLabel> els = new List<SeedsLabel>();
|
||
using (WmsOutPickRequestClient client = new WmsOutPickRequestClient("BasicHttpBinding_IWmsOutPickRequest",
|
||
string.Format("http://{0}/{1}", Park.svrUrl, "WmsOutPickRequestService.svc")))
|
||
{
|
||
log.Debug(" start to load light data.....");
|
||
DataTable dt= client.lightSeeds(deskId,flowNo,barcode, userId, isValid);
|
||
|
||
log.Debug("light items cnt: " + dt.Rows.Count);
|
||
|
||
|
||
int pcs = 0;
|
||
try
|
||
{
|
||
foreach (DataRow dr in dt.Rows)
|
||
{
|
||
if (toTalpcs <= 0)
|
||
{
|
||
break;
|
||
}
|
||
pcs = (int) Convert.ToDecimal(dr["wantCount"].ToString()) / (int)Convert.ToDecimal(dr["minOperateCount"].ToString());
|
||
if (pcs < toTalpcs)
|
||
{
|
||
toTalpcs -= pcs;
|
||
}
|
||
else
|
||
{
|
||
pcs = toTalpcs;
|
||
toTalpcs = 0;
|
||
}
|
||
log.Debug(string.Format("pcs {0}, totalPcs {1}", pcs, toTalpcs));
|
||
|
||
SeedsLabel el = new SeedsLabel();
|
||
// el.count = (int)Convert.ToDecimal(dr["wantCount"].ToString()) ;
|
||
el.count = Convert.ToDecimal(dr["wantCount"].ToString());
|
||
el.pcs = pcs;
|
||
el.color = 1;
|
||
el.barcode = barcode;
|
||
el.address = barcode.Length > 2 ? Convert.ToInt16(barcode.Substring(barcode.Length - 2)) : 0;
|
||
el.labelId = Convert.ToInt16(dr["lightId"].ToString());
|
||
el.deskId = deskId;
|
||
el.seedsNo = flowNo;
|
||
el.flowNo = flowNo;
|
||
el.toFlowNo = dr["toFlowNo"].ToString();
|
||
el.productDate = dr["productDate"].ToString();
|
||
el.skuId = Convert.ToInt16(dr["skuId"].ToString());
|
||
el.batch = dr["batch"].ToString();
|
||
el.outDetailId = Convert.ToInt32(dr["outDetailId"].ToString());
|
||
el.inDetailId = Convert.ToInt32(dr["inDetailId"].ToString());
|
||
el.userId = userId;
|
||
el.isValid = isValid;
|
||
el.name = dr["goodsName"].ToString();
|
||
els.Add(el);
|
||
}
|
||
|
||
}
|
||
catch (Exception er)
|
||
{
|
||
LogHelper.debug("serviceLights", "组织亮灯数据错误: " + er.Message);
|
||
log.Error(er);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
string msg = "没有找到亮灯数据";
|
||
if (els.Count > 0)
|
||
{
|
||
|
||
#if DEBUG
|
||
// portNo = 13;
|
||
#endif
|
||
|
||
if (lightUp != null)
|
||
{
|
||
lightUp(els, userId);
|
||
// msg= els[0].name;
|
||
|
||
decimal cnt = 0;
|
||
int pcs = 0;
|
||
foreach(SeedsLabel eLabel in els)
|
||
{
|
||
cnt += eLabel.count;
|
||
pcs += eLabel.pcs;
|
||
}
|
||
msg = string.Format("[{0}] 总数:{1}, 件数:{2}" , els[0].name ,cnt, pcs);
|
||
|
||
if (WmsConstants.WAVE_CURRENT_LIGHTS_PORT_STATUS.ContainsKey(deskId) &&
|
||
WmsConstants.WAVE_CURRENT_LIGHTS_PORT_STATUS[deskId])
|
||
{
|
||
//seedsItem.lightSeeds(seedsNo, enumSeedsState.已亮灯);
|
||
// importSeeds.lightSeeds(seedsNo, enumSeedsState.已亮灯);
|
||
msg = "亮灯成功 " + msg;
|
||
|
||
}
|
||
else
|
||
{
|
||
msg = "亮灯失败 " + msg;
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
else
|
||
{
|
||
if (clOrder != null)
|
||
{
|
||
clOrder(deskId);
|
||
}
|
||
}
|
||
|
||
log.Debug(msg);
|
||
return new FormatedResult(msg);
|
||
}
|
||
|
||
|
||
public string uploadSeeds(List<SeedsItem> seeds)
|
||
{
|
||
|
||
foreach (SeedsItem si in seeds)
|
||
{
|
||
// WmsOutSeeds dbObj = si.getDbObject();
|
||
|
||
/// dbObj.Add();
|
||
|
||
}
|
||
|
||
|
||
return "服务完成";
|
||
}
|
||
|
||
|
||
public string turnOnLight(int lightId, byte which, int portNo)
|
||
{
|
||
List<ELight> els = new List<ELight>();
|
||
ELight el = new ELight();
|
||
el.port = portNo;
|
||
el.which = which;
|
||
el.lightId = lightId;
|
||
els.Add(el);
|
||
bool rt = true;
|
||
if (turnOnLts != null)
|
||
{
|
||
rt = turnOnLts(portNo, els);
|
||
|
||
}
|
||
if (rt)
|
||
return "亮灯请求成功";
|
||
else
|
||
return "亮灯失败";
|
||
|
||
|
||
}
|
||
/*
|
||
public string turnOffLight(int lightId, int portNo)
|
||
{
|
||
List<ELight> els = new List<ELight>();
|
||
ELight el = new ELight();
|
||
el.port = portNo;
|
||
|
||
el.lightId = lightId;
|
||
els.Add(el);
|
||
|
||
if (turnOffLts != null)
|
||
{
|
||
turnOffLts(portNo, els);
|
||
|
||
}
|
||
return "灭灯成功";
|
||
}
|
||
*/
|
||
|
||
public string turnOffLight(int lightId, byte which, int portNo)
|
||
{
|
||
List<ELight> els = new List<ELight>();
|
||
ELight el = new ELight();
|
||
el.port = portNo;
|
||
el.which = which;
|
||
el.lightId = lightId;
|
||
els.Add(el);
|
||
|
||
bool rt = true;
|
||
if (turnOffLts != null)
|
||
{
|
||
rt = turnOffLts(portNo, els);
|
||
|
||
}
|
||
|
||
if (rt)
|
||
return "灭灯成功";
|
||
else
|
||
return "灭灯失败";
|
||
|
||
}
|
||
|
||
|
||
public string turnOnLightByScan(int deskId, string barcode)
|
||
{
|
||
//ELight el= lseeds.getLight(deskId, barcode);
|
||
|
||
// return turnOnLight(el.lightId, el.which, el.port);
|
||
return "";
|
||
}
|
||
|
||
}
|
||
}
|