ldj/WcfService1/Android.svc.cs

825 lines
28 KiB
C#
Raw Normal View History

2023-05-23 16:13:17 +08:00
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using DeiNiu.Utils;
using DeiNiu.wms.Data.Model;
using DeiNiu.wms.Data.Model.Wcf;
using DeiNiu.wms.Logical;
using Newtonsoft.Json;
using WcfServiceAuthentication;
namespace DeiNiu.Wcf
{
// 注意: 使用“重构”菜单上的“重命名”命令可以同时更改代码、svc 和配置文件中的类名“Android”。
// 注意: 为了启动 WCF 测试客户端以测试此服务,请在解决方案资源管理器中选择 Android.svc 或 Android.svc.cs然后开始调试。
[DataContract]
public class FormatedResult
{
private int code=0;
private Object data = null;
private string message = string.Empty;
public FormatedResult( string data,int code=0,string message ="")
{
this.data = data;
this.code = code;
this.message = message;
}
public FormatedResult(DataTable dt,int code= 0, string message = "")
{
this.data = JsonConvert.SerializeObject(Android.DataTableToDicList(dt));
this.code = code;
this.message = message;
}
[DataMember]
public int Code { get => code; set => code = value; }
[DataMember]
public Object Data { get => data; set => data = value; }
[DataMember]
public string Message { get => message; set => message = value; }
}
public class Android : basicService, IAndroid
{
private int operId = 0;
static internal List<Dictionary<string, string>> DataTableToDicList(DataTable dt)
{
List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
Dictionary<string, string> map = new Dictionary<string, string>();
for (int j = 0; j < dt.Columns.Count; j++)
{
map.Add((string)dt.Columns[j].ColumnName, dt.Rows[i][j].ToString().TrimEnd());
}
list.Add(map);
}
}
return list;
}
string DataTableToJson2(DataTable dt, string tableName = "table0")
{
StringBuilder Json = new StringBuilder();
Json.Append("{\"" + tableName + "\":[");
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
Json.Append("{");
for (int j = 0; j < dt.Columns.Count; j++)
{
Json.Append("\"" + dt.Columns[j].ColumnName.ToString() + "\":\"" + dt.Rows[i][j].ToString() + "\"");
if (j < dt.Columns.Count - 1)
{
Json.Append(",");
}
}
Json.Append("}");
if (i < dt.Rows.Count - 1)
{
Json.Append(",");
}
}
}
Json.Append("]}");
//var jsonObj= JsonConvert.DeserializeObject(Json.ToString());
return Json.ToString().Replace("\\", "");
}
string DataTableToJson1( DataTable dt,string tableName="table0")
{
StringBuilder Json = new StringBuilder();
Json.Append("{\"" + tableName + "\":[");
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
Json.Append("{");
for (int j = 0; j < dt.Columns.Count; j++)
{
Json.Append("\"" + dt.Columns[j].ColumnName.ToString().TrimEnd() + "\":\"" + dt.Rows[i][j].ToString().TrimEnd() + "\"");
if (j < dt.Columns.Count - 1)
{
Json.Append(",");
}
}
Json.Append("}");
if (i < dt.Rows.Count - 1)
{
Json.Append(",");
}
}
}
Json.Append("]}");
return Json.ToString();
}
//-------------------------user validation
public FormatedResult validUser(string userId, string passwd)
{
Employee emp = new Employee();
return new FormatedResult(emp.ValidUser(userId, passwd) + "");
}
public FormatedResult validRole(string account, string passwd, string role)
{
throw new NotImplementedException();
}
protected void validUser(int operId, string token)
{
bool isValid = AuthenticationInspector.validUser(operId, token);
if (!isValid)
{
// throw new Exception("非授权用户访问");
}
setOperId(operId, token);
}
protected void setOperId(int operId, string token)
{
this.operId = operId;
this.token = token;
}
List<string> getAuthLst(int userId,string type="")
{
Dictionary<String, List<Authority>> auths = new LAuthority().getMobileAuthorities(userId);
List<string> auth = new List<string>();
if (string.IsNullOrEmpty(type)){
if (auths.Keys.Contains("移动设备"))
{
List<Authority> portAuth = auths["移动设备"];
foreach (Authority au in portAuth)
{
auth.Add(au.auth_name);
}
}
if (auths.Keys.Contains("细分权限"))
{
List<Authority> portAuth = auths["细分权限"];
foreach (Authority au in portAuth)
{
auth.Add(au.auth_name);
}
}
} else {
if (auths.Keys.Contains(type))
{
List<Authority> portAuth = auths[type];
foreach (Authority au in portAuth)
{
auth.Add(au.auth_name);
}
}
}
return auth;
}
public FormatedResult getPortAuths(int userId, string token)
{
validUser(userId, token); //针对wince访问手动验证用户
return new FormatedResult(JsonConvert.SerializeObject(getAuthLst(userId)));
}
public FormatedResult login(string account, string passwd)
{
LAuthority auth = new LAuthority();
Employee em = auth.login(account, passwd);
AuthenticationInspector.authCach[em.ID] = em.token;
return new FormatedResult(JsonConvert.SerializeObject(em));
}
/*
public WcfEmployee login2(string account, string passwd)
{
Employee em = new Employee();
string token = null;
if (em.login(account, passwd))
{
token = em.token;
AuthenticationInspector.authCach[em.ID] = token;
}
WcfEmployee wcf = new WcfEmployee();
return wcf.getWcfObject(em);
}
*/
public FormatedResult getDictionary()
{
DataTable dt = new lNode().QueryByFlags();
return new FormatedResult(JsonConvert.SerializeObject(DataTableToDicList(dt)));
}
FormatedResult IAndroid.getNodesByFlag(int flag)
{
return new FormatedResult( new Node().queryChildsByFlag(flag));
}
//------------------------- stock location begin ------------------------------------------------------------------------------------------
private static lWmslocation _loc;
private static lWmsStock _stock;
private static lWmsStockPandian _pandian;
lWmsStockPandian pandian
{
get
{
if (_pandian == null || _pandian.operId != getOperId())
{
_pandian = new lWmsStockPandian(getOperId());
}
return _pandian;
}
}
lWmsStock lstock
{
get
{
if (_stock == null || _stock.operId != getOperId())
{
_stock = new lWmsStock(getOperId());
}
return _stock;
}
}
lWmslocation loc
{
get
{
if (_loc == null || _loc.operId != getOperId())
{
_loc = new lWmslocation(getOperId());
}
return _loc;
}
}
public FormatedResult getLines(string custName)
{
DataTable dt = new lTmsLineDetail().getAllLines(custName);
/*
List<string> lines = new List<string>();
foreach (DataRow dr in dt.Rows)
{
lines.Add(dr["id"].ToString() + WmsConstants.SPLIT + dr["name"].ToString());
}
*/
return new FormatedResult(JsonConvert.SerializeObject(DataTableToDicList(dt)));
}
/// <summary>
///取所属货区
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public FormatedResult getPartions(int userId)
{
/*
DataTable dt = lport.getPartions(userId);
List<string> partions = new List<string>();
foreach (DataRow dr in dt.Rows)
{
partions.Add(dr["partion"].ToString() + WmsConstants.SPLIT + dr["partName"].ToString());
}
return partions;
*/
return new FormatedResult(JsonConvert.SerializeObject(DataTableToDicList(lport.getPartions(userId))));
}
public FormatedResult getStockLocation(string locId)
{
/*
List<Dictionary<string, string >> list = DataTableToDicList(lstock.getStockLocation(locId));
string json = JsonConvert.SerializeObject(list);
return new FormatedResut(json);
*/
return new FormatedResult(JsonConvert.SerializeObject(DataTableToDicList(lstock.getStockLocation(locId))));
}
public FormatedResult getStockLocationsByBarcode(string barcode)
{
// return DataTableToJson1(lstock.wmsStock.queryByGoodsBarcode(barcode).Tables[0]);
/*DataTable dt = lstock.wmsStock.queryByGoodsBarcode(barcode).Tables[0];
List<WcfWmsLocation> list = new List<WcfWmsLocation>();
foreach (DataRow dr in dt.Rows)
{
list.Add( new WcfWmsLocation(dr));
}
return list;
*/
return new FormatedResult(JsonConvert.SerializeObject(DataTableToDicList(lstock.wmsStock.queryByGoodsBarcode(barcode).Tables[0])));
}
public FormatedResult updateStockLocation(string locId, string goodsId, int skuId, string batch, decimal count, string reason, int type)
{
bool result = lstock.updateStockLocation(locId, goodsId, skuId, batch, count, reason, (enumStockRecordType)type);
return new FormatedResult(JsonConvert.SerializeObject(result));
}
public FormatedResult initialStockIn(string goodsId, string locId, decimal batchCount, string prodDate, string validDate, string batch)
{
Dictionary<string, string> sku = new Dictionary<string, string>();
sku[WmsConstants.SKU_RESEVRED_PRDDATE_ATTNAME] = prodDate;
sku[WmsConstants.SKU_RESEVRED_EXPIREDATE_ATTNAME] = validDate;
sku[WmsConstants.SKU_RESEVRED_BATCH_ATTNAME] = batch;
// sku.Add(WmsConstants.SKU_RESEVRED_ENTI_ATTNAME, WmsConstants.enti);
enumRepResult result = lstock.initialStockIn(goodsId, locId, batchCount, sku);
return new FormatedResult(result.ToString());
}
public FormatedResult clearLocation(string locId, string reason)
{
bool result = lstock.clearLocation(locId, reason);
return new FormatedResult(JsonConvert.SerializeObject(result));
}
public FormatedResult upLocationStatus(string locId, int status)
{
bool result=lstock.updateLocationStatus(locId, status);
return new FormatedResult(JsonConvert.SerializeObject(result));
}
public FormatedResult updateGoodsLocationVolume(string goodsId, int volType, decimal volume)
{
bool result = lstock.updateGoodsLocationVolume(goodsId, volType, volume);
return new FormatedResult(JsonConvert.SerializeObject(result));
}
public FormatedResult getLocation(string locId)
{
var result = DataTableToDicList(loc.getWmslocation.getLocations(locId));
2023-05-23 23:33:56 +08:00
return new FormatedResult(JsonConvert.SerializeObject(result));
2023-05-23 16:13:17 +08:00
}
public FormatedResult getStockCompareErp(string goodsId, string barcode)
{
var result = DataTableToDicList(lstock.wmsStock.getStockLocationCompareErp(goodsId, barcode));
return new FormatedResult(JsonConvert.SerializeObject(result));
}
public FormatedResult upDownStockLocation(string locId, string goodsId, int skuId, string batch, decimal count, int type, int oldRecId)
{
var result =(int)lstock.upDownGoodsCountWithLocation(locId, goodsId, skuId, batch, count, "", (enumStockRecordType)type, oldRecId);
return new FormatedResult(JsonConvert.SerializeObject(result));
}
public FormatedResult getDownStockList4Up(int operId)
{
var result = DataTableToDicList(lstock.wmsStock.getLocationDownList4Up(operId));
return new FormatedResult(JsonConvert.SerializeObject(result));
}
public FormatedResult locationEleIdCombine(string locId, int eleId)
{
var result = loc.locationEleIdCombine(locId, eleId);
return new FormatedResult(JsonConvert.SerializeObject(result));
}
public FormatedResult repItemIn(string locId, string goodsId, int skuId, string batch, decimal count, int portId)
{
var result = (int)lstock.repItemIn(locId, goodsId, skuId, batch, count, portId);
return new FormatedResult(JsonConvert.SerializeObject(result));
}
public FormatedResult getLocations(int skuId, string skuCode, string goodsId, string batch, decimal count)
{
try
{
DataTable dt = lstock.getBulkLocations(skuId, skuCode, goodsId, batch, count);
var result = DataTableToDicList(dt);
return new FormatedResult(JsonConvert.SerializeObject(result));
}
catch (Exception e)
{
return new FormatedResult("",404,e.Message);
}
}
public FormatedResult getGoodsStockLocations(string barcode)
{
var result = DataTableToDicList(lstock.wmsStock.getGoodsStockLocations(barcode));
return new FormatedResult(JsonConvert.SerializeObject(result));
}
public FormatedResult getGoodsERPStoreByBarcode(string barcode)
{
var result = DataTableToDicList(lstock.wmsStock.getGoodsERPStoreByBarcode(barcode));
return new FormatedResult(JsonConvert.SerializeObject(result));
}
public FormatedResult getPandianOrders(int ownerId, int status)
{
var result = DataTableToDicList(pandian.getWmsStockPandian.getPandianOrders(ownerId, status));
return new FormatedResult(JsonConvert.SerializeObject(result));
}
public FormatedResult getPandianItem(string orderNo, string locationId)
{
var result = DataTableToDicList(pandian.getPandianItem(orderNo, locationId));
return new FormatedResult(JsonConvert.SerializeObject(result));
}
public FormatedResult newPandianItem(string orderNo, string locationId, int skuId, string barcode, string prdDate, string batch, decimal count)
{
var result = pandian.newPandianItem(orderNo, locationId, skuId, barcode, prdDate, batch, count);
return new FormatedResult(JsonConvert.SerializeObject(result));
}
//------------------------- stock In Request begin ------------------------------------------------------------------------------------------
static lWmsInRequest _lir;
lWmsInRequest lir
{
get
{
if (_lir == null || _lir.operId != getOperId())
{
_lir = new lWmsInRequest(getOperId());
}
return _lir;
}
}
FormatedResult IAndroid.getPreInDetail(string preInNo)
{
DataTable dt = lir.getPreInDetail(preInNo);
FormatedResult rs = new FormatedResult(dt );
return rs;
}
FormatedResult IAndroid.receiveDetail(string preInNo, string goodsId, decimal arriveNumber, decimal receiveNumber, int inType, string inRemark, decimal temperature, bool isCache, int cachePartion)
{
// return lir.receiveDetail(preInNo, id, arriveNumber, receiveNumber, inType, inRemark, shipId, isCache, cachePartion);
return new FormatedResult( lir.receivePreDetail(preInNo, goodsId, arriveNumber, receiveNumber, inType, inRemark, isCache, cachePartion, temperature)+"");
}
FormatedResult IAndroid.getGoodsPackByBarcode(string barcode)
{
return new FormatedResult(lir.getGoodsDetailByBarcode(barcode)) ;
}
FormatedResult IAndroid.getGoodsPacking(string goodsId)
{
return new FormatedResult(new WmsGoods().queryPacking(goodsId));
}
FormatedResult IAndroid.goodsMaintain(string goodsId, decimal bulkMax, decimal batch1Max, decimal batch2Max, decimal batch3Max, int ABC, int storeType)
{
WmsGoods goods = new WmsGoods(goodsId);
if(bulkMax > 0)
goods.bulkMax = bulkMax;
if(batch1Max > 0)
goods.batchMax1 = batch1Max;
if (batch2Max > 0)
goods.batchMax2 = batch2Max;
if (batch3Max > 0)
goods.batchMax3 = batch3Max;
if (ABC > 0)
goods.ABC = ABC;
if (storeType > 0)
goods.goodsType = storeType;
bool res = goods.Update()==1;
return new FormatedResult(res.ToString());
}
FormatedResult IAndroid.goodsPacking(int id, string goodsId, string barcode, string manufacturer2, string spec, decimal chang, decimal kuan, decimal gao, decimal weight, int statckLayers, int stackLayNums, bool isDelete)
{
Erp_packing packing = new Erp_packing(id);
if (isDelete)
{
return new FormatedResult((packing.Delete() > 0) + "");
}
packing.barcode = barcode;
packing.goodsId = goodsId;
packing.weight = weight;
packing.chang = chang;
packing.kuan = kuan;
packing.gao = gao;
packing.weight = weight;
packing.spec = spec;
packing.manufacturer2 = manufacturer2;
packing.stackLayers = statckLayers;
packing.stackLayNums = stackLayNums;
try {
if (id > 0)
{
return new FormatedResult((packing.Update()>0)+"");
}
else
{
return new FormatedResult((packing.Add() > 0) + "");
}
}catch(Exception er)
{
return new FormatedResult(false + "", 0, er.Message);
}
}
FormatedResult IAndroid.getReceiveDetailByBarcode(string preInOrder, string barcode)
{
return new FormatedResult(lir.getReceiveDetailByBarcode(preInOrder, barcode));
}
FormatedResult IAndroid.getValidSeedsCnt(string goodsId, decimal batchCount)
{
return new FormatedResult( lir.getValidSeedsCnt(goodsId, batchCount)+"");
}
FormatedResult IAndroid.isFlowNoValid(string preInOrder, string flowNo)
{
throw new NotImplementedException();
}
/// <summary>
/// 取消上架任务,重新验货入库
/// 同批次的,同托盘的其他任务一起取消
/// </summary>
/// <param name="flowNo"></param>
/// <param name="jobId"></param>
/// <returns></returns>
FormatedResult IAndroid.retrieveValidIn(int jobId)
{
return new FormatedResult(lir.retrieveValidByJobId( jobId)+"");
}
public FormatedResult retrieveValidByDetailId(int detailId)
{
return new FormatedResult(lir.retrieveValidByDetailId(detailId) + "");
}
public FormatedResult retrieveValidBySkuId(string preInNo, int skuId)
{
return new FormatedResult(lir.retrieveValidByPreNo(preInNo,skuId) + "");
}
FormatedResult IAndroid.validIn(string preInNo, string flowNo, string goodsId, decimal batchCount, decimal seedsCount,
string prdDate, string validDate, string batch, string entiId, bool isPass, bool isIsuLocations, int secondValidUserId, bool isFlowUni, bool isZhitong = false, string pickOrderNo = null, int zhitongPartion = 0)
{
// lir.receivePreDetail(preInNo, goodsId, batchCount, receiveNumber, inType, inRemark, isCache, cachePartion, temperature);
Dictionary<string, string> sku = new Dictionary<string, string>();
sku.Add(WmsConstants.SKU_RESEVRED_PRDDATE_ATTNAME, prdDate);
sku.Add(WmsConstants.SKU_RESEVRED_EXPIREDATE_ATTNAME, validDate);
sku.Add(WmsConstants.SKU_RESEVRED_BATCH_ATTNAME, batch);
sku.Add(WmsConstants.SKU_RESEVRED_ENTI_ATTNAME,entiId);
enumValidInResult result = lir.validIn(preInNo, flowNo, goodsId.Trim(), batchCount, seedsCount, sku, isPass, isIsuLocations, secondValidUserId,0,true,isFlowUni, isZhitong , pickOrderNo , zhitongPartion );
FormatedResult rs = new FormatedResult(result.ToString(),(int)result, result.ToString());
return rs;
}
FormatedResult IAndroid.getPreValidResult(string preInNo, string flowNo, bool showAllUsers)
{
return new FormatedResult( lir.getPreValidResult4Wince(preInNo, flowNo, showAllUsers));
}
FormatedResult IAndroid.getValidInDetail(string preInNo, string flowNo)
{
return new FormatedResult(lir.getValidInDetail(preInNo, flowNo));
}
FormatedResult IAndroid.finishUpShelfItem(string flowNo, int id, decimal count, string locationId, string reason)
{
enumRepResult result = lir.finishUpShelfItem(flowNo, id , count, locationId, reason);
DataTable dt = lir.getPortStockInDetailByPortId(id);
FormatedResult rs = new FormatedResult(dt, (int)result,result.ToString());
return rs;
//{"finishUpShelfItemResult":{"Code":0,"D1","Mata":"essage":""}}
}
FormatedResult IAndroid.getZhiTongOrderDetail(string flowNo)
{
return new FormatedResult(lir.getZhiTongOrderDetail(flowNo));
}
FormatedResult IAndroid.zhiTongSeedOut(int outDetailId, int inDetailId, decimal seedCnt)
{
enumRepResult result = lir.zhiTongSeedOut(outDetailId,inDetailId,seedCnt);
return new FormatedResult(result.ToString());
}
FormatedResult IAndroid.newPackBarcode(string goodsId, string barcode,decimal packingQty, decimal chang, decimal kuan, decimal gao, decimal weight)
{
enumRepResult result = lir.newBarcode(goodsId, barcode, packingQty, chang, kuan, gao, weight);
return new FormatedResult(result.ToString());
}
//stock out -------begin-----------
private static lWmsOutPickRequest _lop;
private static lWmsOutPickPort _lport;
lWmsOutPickRequest lop
{
get
{
if (_lop == null || _lop.operId != getOperId())
{
_lop = new lWmsOutPickRequest(getOperId());
}
return _lop;
}
}
lWmsOutPickPort lport
{
get
{
if (_lport == null || _lport.operId != getOperId())
{
_lport = new lWmsOutPickPort(getOperId());
}
return _lport;
}
}
FormatedResult IAndroid.getStockInPortDetail(int portId)
{
throw new NotImplementedException();
}
FormatedResult IAndroid.getStockInDetails(string flowNo)
{
throw new NotImplementedException();
}
FormatedResult IAndroid.getBatchPickOrders4Valid()
{
return new FormatedResult(lop.getBatchPickOrders4Validate());
}
FormatedResult IAndroid.getPickOrderDetails(string orderNo)
{
throw new NotImplementedException();
}
FormatedResult IAndroid.getPickDetail(int id)
{
return new FormatedResult(lop.getPortOutPickOrderDetail(id));
}
FormatedResult IAndroid.finishPickItem(string flowNo, string waveNo, string pickOrderNo, int id, decimal pickCount)
{
return new FormatedResult( lop.finishPickItem(flowNo, waveNo, pickOrderNo, id, pickCount)+"");
}
FormatedResult IAndroid.finishBatchValidateItem(string pickOrderNo, int id, int operId, int checkBy2, string token)
{
throw new NotImplementedException();
}
int IAndroid.batchPickCount4Valid(string pickOrderNo)
{
throw new NotImplementedException();
}
FormatedResult IAndroid.repTodayDetails4Pick(int userId)
{
throw new NotImplementedException();
}
FormatedResult IAndroid.repInDetailsByFlowNo(string flowNo)
{
throw new NotImplementedException();
}
FormatedResult IAndroid.getTaskAssigned(int operId, int partion, int lineId, bool batchOnly, int orderType)
{
return new FormatedResult(lport.getAssignedOutTasks(operId, partion, lineId, batchOnly, (enumOutOrderType)orderType));
}
FormatedResult IAndroid.taskAssign(int takeBy,int partion, int lineId, bool batchOnly, int orderType)
{
lport.taskAssign(takeBy, partion, lineId, 0, 0, WmsConstants.OUT_TASK_ASSIGN_BATCH_ONLY, (enumOutOrderType)orderType);
return new FormatedResult(lport.getAssignedOutTasks(takeBy, partion, lineId, batchOnly, (enumOutOrderType)orderType));
}
FormatedResult IAndroid.taskResign(int partion, int lineId, bool batchOnly, int orderType)
{
throw new NotImplementedException();
}
FormatedResult IAndroid.getSeedsPickDetail(string flowNo, bool isOrderByCust)
{
return new FormatedResult(lport.getSeedsPickDetail(flowNo, isOrderByCust));
}
FormatedResult IAndroid.seedsPickOut(string flowNo,string batch, int outDetailId, decimal seedCnt, string toFlowNo)
{
enumRepResult result = lport.seedsPickOut(flowNo,batch, outDetailId, seedCnt, toFlowNo);
return new FormatedResult(result.ToString());
}
}
}